staging: xgifb: vb_setmode: eliminate GetVGAType/Set_VGAType
[deliverable/linux.git] / drivers / staging / xgifb / vb_setmode.c
1
2 #include <linux/io.h>
3 #include <linux/delay.h>
4 #include <linux/types.h>
5 #include "XGIfb.h"
6
7
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"
15
16
17 #define IndexMask 0xff
18
19 static const unsigned short XGINew_MDA_DAC[] = {
20 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
22 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
23 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
26 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
27 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
28
29 static const unsigned short XGINew_CGA_DAC[] = {
30 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
31 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
32 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
33 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
34 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
35 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
36 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
37 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
38
39 static const unsigned short XGINew_EGA_DAC[] = {
40 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x05, 0x15,
41 0x20, 0x30, 0x24, 0x34, 0x21, 0x31, 0x25, 0x35,
42 0x08, 0x18, 0x0C, 0x1C, 0x09, 0x19, 0x0D, 0x1D,
43 0x28, 0x38, 0x2C, 0x3C, 0x29, 0x39, 0x2D, 0x3D,
44 0x02, 0x12, 0x06, 0x16, 0x03, 0x13, 0x07, 0x17,
45 0x22, 0x32, 0x26, 0x36, 0x23, 0x33, 0x27, 0x37,
46 0x0A, 0x1A, 0x0E, 0x1E, 0x0B, 0x1B, 0x0F, 0x1F,
47 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
48
49 static const unsigned short XGINew_VGA_DAC[] = {
50 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
51 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
52 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
53 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
54 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
55 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
56 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
57 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
58 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
59 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
60
61 void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
62 {
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;
69
70 /* add for new UNIVGABIOS */
71 /* XGINew_UBLCDDataTable =
72 * (struct XGI_LCDDataTablStruct *) XGI_LCDDataTable; */
73 /* XGINew_UBTVDataTable = (XGI_TVDataTablStruct *) XGI_TVDataTable; */
74
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;
83
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;
92
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;
106
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;
114
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;
125
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;
140
141 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
142 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
143 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
144
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;
150
151 if ((ChipType == XG21) || (ChipType == XG27))
152 pVBInfo->XG21_LVDSCapList = XGI21_LCDCapList;
153
154 pVBInfo->XGI_TVDelayList = XGI301TVDelayList;
155 pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2;
156
157 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
158
159 if (ChipType >= XG20)
160 pVBInfo->pXGINew_CR97 = &XG20_CR97;
161
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;
173
174 }
175
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;
182 }
183
184 }
185
186 static unsigned char XGI_GetModePtr(unsigned short ModeNo,
187 unsigned short ModeIdIndex,
188 struct vb_device_info *pVBInfo)
189 {
190 unsigned char index;
191
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;
199 }
200 return index; /* Get pVBInfo->StandTable index */
201 }
202
203 static void XGI_SetSeqRegs(unsigned short ModeNo,
204 unsigned short StandTableIndex,
205 unsigned short ModeIdIndex,
206 struct vb_device_info *pVBInfo)
207 {
208 unsigned char tempah, SRdata;
209 unsigned short i, modeflag;
210
211 if (ModeNo <= 0x13)
212 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
213 else
214 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
215
216 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
217 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
218
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;
226 }
227 }
228
229 tempah |= 0x20; /* screen off */
230 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
231
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 */
236 }
237 }
238
239 static void XGI_SetMiscRegs(unsigned short StandTableIndex,
240 struct vb_device_info *pVBInfo)
241 {
242 unsigned char Miscdata;
243
244 /* Get Misc from file */
245 Miscdata = pVBInfo->StandTable[StandTableIndex].MISC;
246 /*
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;
254 }
255 }
256 */
257
258 outb(Miscdata, pVBInfo->P3c2); /* Set Misc(3c2) */
259 }
260
261 static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
262 unsigned short StandTableIndex,
263 struct vb_device_info *pVBInfo)
264 {
265 unsigned char CRTCdata;
266 unsigned short i;
267
268 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
269 CRTCdata &= 0x7f;
270 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
271
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) */
276 }
277 /*
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);
283 }
284 }
285 }
286 */
287 }
288
289 static void XGI_SetATTRegs(unsigned short ModeNo,
290 unsigned short StandTableIndex,
291 unsigned short ModeIdIndex,
292 struct vb_device_info *pVBInfo)
293 {
294 unsigned char ARdata;
295 unsigned short i, modeflag;
296
297 if (ModeNo <= 0x13)
298 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
299 else
300 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
301
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;
314 }
315 }
316 }
317 }
318
319 inb(pVBInfo->P3da); /* reset 3da */
320 outb(i, pVBInfo->P3c0); /* set index */
321 outb(ARdata, pVBInfo->P3c0); /* set data */
322 }
323
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);
329 }
330
331 static void XGI_SetGRCRegs(unsigned short StandTableIndex,
332 struct vb_device_info *pVBInfo)
333 {
334 unsigned char GRdata;
335 unsigned short i;
336
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) */
341 }
342
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);
347 }
348 }
349
350 static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
351 {
352 unsigned short i;
353
354 for (i = 0x0A; i <= 0x0E; i++)
355 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
356 }
357
358 static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
359 {
360
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);
364
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);
368
369 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
370 return 0;
371 }
372
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)
377 {
378 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
379
380 if (ModeNo <= 0x13)
381 /* si+St_ModeFlag */
382 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
383 else
384 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
385
386 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
387 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
388 tempax = 0;
389
390 if (pVBInfo->IF_DEF_LVDS == 0) {
391 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
392 tempax |= SupportRAMDAC2;
393
394 if (pVBInfo->VBType & VB_XGI301C)
395 tempax |= SupportCRT2in301C;
396 }
397
398 /* 301b */
399 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
400 tempax |= SupportLCD;
401
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;
409 }
410 }
411 }
412 }
413 }
414
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;
422
423 if (resinfo == 3)
424 return 0;
425
426 if (resinfo > 7)
427 return 0;
428 }
429 } else {
430 tempax |= SupportHiVisionTV;
431 if (pVBInfo->VBInfo & SetInSlaveMode) {
432 if (resinfo == 4)
433 return 0;
434
435 if (resinfo == 3) {
436 if (pVBInfo->SetFlag
437 & TVSimuMode)
438 return 0;
439 }
440
441 if (resinfo > 7)
442 return 0;
443 }
444 }
445 } else {
446 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
447 SetCRT2ToSVIDEO |
448 SetCRT2ToSCART |
449 SetCRT2ToYPbPr |
450 SetCRT2ToHiVisionTV)) {
451 tempax |= SupportTV;
452
453 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
454 | VB_XGI301LV | VB_XGI302LV
455 | VB_XGI301C)) {
456 tempax |= SupportTV1024;
457 }
458
459 if (!(pVBInfo->VBInfo & SetPALTV)) {
460 if (modeflag & NoSupportSimuTV) {
461 if (pVBInfo->VBInfo &
462 SetInSlaveMode) {
463 if (!(pVBInfo->VBInfo &
464 SetNotSimuMode)) {
465 return 0;
466 }
467 }
468 }
469 }
470 }
471 }
472 } else { /* for LVDS */
473 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
474 tempax |= SupportLCD;
475
476 if (resinfo > 0x08)
477 return 0; /* 1024x768 */
478
479 if (pVBInfo->LCDResInfo < Panel1024x768) {
480 if (resinfo > 0x07)
481 return 0; /* 800x600 */
482
483 if (resinfo == 0x04)
484 return 0; /* 512x384 */
485 }
486 }
487 }
488
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;
495
496 if ((*i) == 0)
497 break;
498 }
499
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;
506 }
507
508 if (infoflag & tempax)
509 return 1;
510 }
511 return 1;
512 }
513
514 static void XGI_SetSync(unsigned short RefreshRateTableIndex,
515 struct vb_device_info *pVBInfo)
516 {
517 unsigned short sync, temp;
518
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) */
525 }
526
527 static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
528 struct xgi_hw_device_info *HwDeviceExtension)
529 {
530 unsigned char data, data1, pushax;
531 unsigned short i, j;
532
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); */
536
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);
541
542 data = pVBInfo->TimingH[0].data[0];
543 xgifb_reg_set(pVBInfo->P3d4, 0, data);
544
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);
548 }
549
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);
553 }
554
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);
561
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;
577 }
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);
588 }
589 }
590
591 static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
592 unsigned short ModeNo,
593 struct vb_device_info *pVBInfo)
594 {
595 unsigned char data;
596 unsigned short i, j;
597
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); */
601
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);
605 }
606
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);
610 }
611
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);
615 }
616
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);
623
624 data = pVBInfo->TimingV[0].data[6];
625 data &= 0x80;
626 data = data >> 2;
627
628 if (ModeNo <= 0x13)
629 i = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
630 else
631 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
632
633 i &= DoubleScanMode;
634 if (i)
635 data |= 0x80;
636
637 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
638 j &= 0x5F;
639 data |= j;
640 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
641 }
642
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)
647 {
648 unsigned char index, data;
649 unsigned short i;
650
651 /* Get index */
652 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
653 index = index & IndexMask;
654
655 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
656 data &= 0x7F;
657 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
658
659 for (i = 0; i < 8; i++)
660 pVBInfo->TimingH[0].data[i]
661 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
662
663 for (i = 0; i < 7; i++)
664 pVBInfo->TimingV[0].data[i]
665 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
666
667 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
668
669 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
670
671 if (pVBInfo->ModeType > 0x03)
672 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
673 }
674
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)
684 {
685 unsigned char StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
686 unsigned short Temp1, Temp2, Temp3;
687
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);
706
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 */
712
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);
721
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] */
728
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);
754
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] */
760
761 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
762 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
763
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] */
768
769 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
770 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
771
772 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
773 if (Tempax < Tempcx) /* HRE < HRS */
774 Temp2 |= 0x40; /* Temp2 + 0x40 */
775
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);
784
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 */
797
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] */
810
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] */
821
822 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
823 if (Tempax < Temp3) /* VRE < VRS */
824 Temp2 |= 0x20; /* VRE + 0x20 */
825
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);
836 }
837 }
838
839 static void XGI_SetXG27CRTC(unsigned short ModeNo,
840 unsigned short ModeIdIndex,
841 unsigned short RefreshRateTableIndex,
842 struct vb_device_info *pVBInfo)
843 {
844 unsigned short StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
845
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);
864
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] */
878
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);
902
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] */
907
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] */
911
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] */
916
917 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
918 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
919
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]*/
925
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);
933
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);
938
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] */
953
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] */
965
966 if (Tempbx <= Tempcx) /* VRE <= VRS */
967 Tempbx |= 0x20; /* VRE + 0x20 */
968
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);
976 }
977 }
978
979 static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
980 {
981 unsigned char temp;
982
983 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
984 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
985 temp = (temp & 3) << 6;
986 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
987 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
988 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
989 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
990
991 }
992
993 static void xgifb_set_lcd(int chip_id,
994 struct vb_device_info *pVBInfo,
995 unsigned short RefreshRateTableIndex,
996 unsigned short ModeNo)
997 {
998 unsigned short Data, Temp, b3CC;
999 unsigned short XGI_P3cc;
1000
1001 XGI_P3cc = pVBInfo->P3cc;
1002
1003 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
1004 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
1005 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
1006 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
1007
1008 if (chip_id == XG27) {
1009 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
1010 if ((Temp & 0x03) == 0) { /* dual 12 */
1011 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
1012 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
1013 }
1014 }
1015
1016 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
1017 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
1018 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
1019 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
1020 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
1021 }
1022
1023 if (chip_id == XG27) {
1024 XGI_SetXG27FPBits(pVBInfo);
1025 } else {
1026 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
1027 if (Temp & 0x01) {
1028 /* 18 bits FP */
1029 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
1030 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
1031 }
1032 }
1033
1034 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
1035
1036 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
1037 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
1038
1039 if (ModeNo <= 0x13) {
1040 b3CC = (unsigned char) inb(XGI_P3cc);
1041 if (b3CC & 0x40)
1042 /* Hsync polarity */
1043 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
1044 if (b3CC & 0x80)
1045 /* Vsync polarity */
1046 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
1047 } else {
1048 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1049 if (Data & 0x4000)
1050 /* Hsync polarity */
1051 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
1052 if (Data & 0x8000)
1053 /* Vsync polarity */
1054 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
1055 }
1056 }
1057
1058 /* --------------------------------------------------------------------- */
1059 /* Function : XGI_UpdateXG21CRTC */
1060 /* Input : */
1061 /* Output : CRT1 CRTC */
1062 /* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
1063 /* --------------------------------------------------------------------- */
1064 static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
1065 struct vb_device_info *pVBInfo,
1066 unsigned short RefreshRateTableIndex)
1067 {
1068 int i, index = -1;
1069
1070 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
1071 if (ModeNo <= 0x13) {
1072 for (i = 0; i < 12; i++) {
1073 if (ModeNo == pVBInfo->UpdateCRT1[i].ModeID)
1074 index = i;
1075 }
1076 } else {
1077 if (ModeNo == 0x2E &&
1078 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1079 RES640x480x60))
1080 index = 12;
1081 else if (ModeNo == 0x2E &&
1082 (pVBInfo->RefIndex[RefreshRateTableIndex].
1083 Ext_CRT1CRTC == RES640x480x72))
1084 index = 13;
1085 else if (ModeNo == 0x2F)
1086 index = 14;
1087 else if (ModeNo == 0x50)
1088 index = 15;
1089 else if (ModeNo == 0x59)
1090 index = 16;
1091 }
1092
1093 if (index != -1) {
1094 xgifb_reg_set(pVBInfo->P3d4, 0x02,
1095 pVBInfo->UpdateCRT1[index].CR02);
1096 xgifb_reg_set(pVBInfo->P3d4, 0x03,
1097 pVBInfo->UpdateCRT1[index].CR03);
1098 xgifb_reg_set(pVBInfo->P3d4, 0x15,
1099 pVBInfo->UpdateCRT1[index].CR15);
1100 xgifb_reg_set(pVBInfo->P3d4, 0x16,
1101 pVBInfo->UpdateCRT1[index].CR16);
1102 }
1103 }
1104
1105 static unsigned short XGI_GetResInfo(unsigned short ModeNo,
1106 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
1107 {
1108 unsigned short resindex;
1109
1110 if (ModeNo <= 0x13)
1111 /* si+St_ResInfo */
1112 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1113 else
1114 /* si+Ext_ResInfo */
1115 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1116 return resindex;
1117 }
1118
1119 static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
1120 unsigned short ModeNo, unsigned short ModeIdIndex,
1121 unsigned short RefreshRateTableIndex,
1122 struct vb_device_info *pVBInfo)
1123 {
1124 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
1125
1126 unsigned char data;
1127
1128 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1129
1130 if (ModeNo <= 0x13) {
1131 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1132 tempax = pVBInfo->StResInfo[resindex].HTotal;
1133 tempbx = pVBInfo->StResInfo[resindex].VTotal;
1134 } else {
1135 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1136 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
1137 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
1138 }
1139
1140 if (modeflag & HalfDCLK)
1141 tempax = tempax >> 1;
1142
1143 if (ModeNo > 0x13) {
1144 if (modeflag & HalfDCLK)
1145 tempax = tempax << 1;
1146
1147 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1148
1149 if (temp & InterlaceMode)
1150 tempbx = tempbx >> 1;
1151
1152 if (modeflag & DoubleScanMode)
1153 tempbx = tempbx << 1;
1154 }
1155
1156 tempcx = 8;
1157
1158 /* if (!(modeflag & Charx8Dot)) */
1159 /* tempcx = 9; */
1160
1161 tempax /= tempcx;
1162 tempax -= 1;
1163 tempbx -= 1;
1164 tempcx = tempax;
1165 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1166 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1167 data &= 0x7F;
1168 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
1169 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
1170 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
1171 (unsigned short) ((tempcx & 0x0ff00) >> 10));
1172 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
1173 tempax = 0;
1174 tempbx = tempbx >> 8;
1175
1176 if (tempbx & 0x01)
1177 tempax |= 0x02;
1178
1179 if (tempbx & 0x02)
1180 tempax |= 0x40;
1181
1182 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
1183 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
1184 data &= 0xFF;
1185 tempax = 0;
1186
1187 if (tempbx & 0x04)
1188 tempax |= 0x02;
1189
1190 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
1191 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
1192 }
1193
1194 static void XGI_SetCRT1Offset(unsigned short ModeNo,
1195 unsigned short ModeIdIndex,
1196 unsigned short RefreshRateTableIndex,
1197 struct xgi_hw_device_info *HwDeviceExtension,
1198 struct vb_device_info *pVBInfo)
1199 {
1200 unsigned short temp, ah, al, temp2, i, DisplayUnit;
1201
1202 /* GetOffset */
1203 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
1204 temp = temp >> 8;
1205 temp = pVBInfo->ScreenOffset[temp];
1206
1207 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1208 temp2 &= InterlaceMode;
1209
1210 if (temp2)
1211 temp = temp << 1;
1212
1213 temp2 = pVBInfo->ModeType - ModeEGA;
1214
1215 switch (temp2) {
1216 case 0:
1217 temp2 = 1;
1218 break;
1219 case 1:
1220 temp2 = 2;
1221 break;
1222 case 2:
1223 temp2 = 4;
1224 break;
1225 case 3:
1226 temp2 = 4;
1227 break;
1228 case 4:
1229 temp2 = 6;
1230 break;
1231 case 5:
1232 temp2 = 8;
1233 break;
1234 default:
1235 break;
1236 }
1237
1238 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1239 temp = temp * temp2 + temp2 / 2;
1240 else
1241 temp *= temp2;
1242
1243 /* SetOffset */
1244 DisplayUnit = temp;
1245 temp2 = temp;
1246 temp = temp >> 8; /* ah */
1247 temp &= 0x0F;
1248 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
1249 i &= 0xF0;
1250 i |= temp;
1251 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
1252
1253 temp = (unsigned char) temp2;
1254 temp &= 0xFF; /* al */
1255 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
1256
1257 /* SetDisplayUnit */
1258 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1259 temp2 &= InterlaceMode;
1260 if (temp2)
1261 DisplayUnit >>= 1;
1262
1263 DisplayUnit = DisplayUnit << 5;
1264 ah = (DisplayUnit & 0xff00) >> 8;
1265 al = DisplayUnit & 0x00ff;
1266 if (al == 0)
1267 ah += 1;
1268 else
1269 ah += 2;
1270
1271 if (HwDeviceExtension->jChipType >= XG20)
1272 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1273 ah -= 1;
1274
1275 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
1276 }
1277
1278 static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1279 unsigned short ModeIdIndex,
1280 unsigned short RefreshRateTableIndex,
1281 struct xgi_hw_device_info *HwDeviceExtension,
1282 struct vb_device_info *pVBInfo)
1283 {
1284 unsigned short LCDXlat1VCLK[4] = { VCLK65 + 2,
1285 VCLK65 + 2,
1286 VCLK65 + 2,
1287 VCLK65 + 2 };
1288 unsigned short LCDXlat2VCLK[4] = { VCLK108_2 + 5,
1289 VCLK108_2 + 5,
1290 VCLK108_2 + 5,
1291 VCLK108_2 + 5 };
1292 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
1293 unsigned short LVDSXlat2VCLK[4] = { VCLK65 + 2,
1294 VCLK65 + 2,
1295 VCLK65 + 2,
1296 VCLK65 + 2 };
1297 unsigned short LVDSXlat3VCLK[4] = { VCLK65 + 2,
1298 VCLK65 + 2,
1299 VCLK65 + 2,
1300 VCLK65 + 2 };
1301
1302 unsigned short CRT2Index, VCLKIndex;
1303 unsigned short modeflag, resinfo;
1304
1305 if (ModeNo <= 0x13) {
1306 /* si+St_ResInfo */
1307 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1308 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1309 CRT2Index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1310 } else {
1311 /* si+Ext_ResInfo */
1312 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1313 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1314 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].
1315 Ext_CRT2CRTC;
1316 }
1317
1318 if (pVBInfo->IF_DEF_LVDS == 0) {
1319 CRT2Index = CRT2Index >> 6; /* for LCD */
1320 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /*301b*/
1321 if (pVBInfo->LCDResInfo != Panel1024x768)
1322 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1323 else
1324 VCLKIndex = LCDXlat1VCLK[CRT2Index];
1325 } else { /* for TV */
1326 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1327 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
1328 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1329 VCLKIndex = HiTVVCLKDIV2;
1330 VCLKIndex += 25;
1331 } else {
1332 VCLKIndex = HiTVVCLK;
1333 VCLKIndex += 25;
1334 }
1335
1336 if (pVBInfo->SetFlag & TVSimuMode) {
1337 if (modeflag & Charx8Dot) {
1338 VCLKIndex =
1339 HiTVSimuVCLK;
1340 VCLKIndex += 25;
1341 } else {
1342 VCLKIndex =
1343 HiTVTextVCLK;
1344 VCLKIndex += 25;
1345 }
1346 }
1347
1348 /* 301lv */
1349 if (pVBInfo->VBType & VB_XGI301LV) {
1350 if (!(pVBInfo->VBExtInfo ==
1351 VB_YPbPr1080i)) {
1352 VCLKIndex =
1353 YPbPr750pVCLK;
1354 if (!(pVBInfo->VBExtInfo
1355 ==
1356 VB_YPbPr750p)) {
1357 VCLKIndex =
1358 YPbPr525pVCLK;
1359 if (!(pVBInfo->VBExtInfo
1360 == VB_YPbPr525p)) {
1361 VCLKIndex
1362 = YPbPr525iVCLK_2;
1363 if (!(pVBInfo->SetFlag
1364 & RPLLDIV2XO))
1365 VCLKIndex
1366 = YPbPr525iVCLK;
1367 }
1368 }
1369 }
1370 }
1371 } else {
1372 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1373 if (pVBInfo->SetFlag &
1374 RPLLDIV2XO) {
1375 VCLKIndex = TVVCLKDIV2;
1376 VCLKIndex += 25;
1377 } else {
1378 VCLKIndex = TVVCLK;
1379 VCLKIndex += 25;
1380 }
1381 }
1382 }
1383 } else { /* for CRT2 */
1384 /* Port 3cch */
1385 VCLKIndex = (unsigned char) inb(
1386 (pVBInfo->P3ca + 0x02));
1387 VCLKIndex = ((VCLKIndex >> 2) & 0x03);
1388 if (ModeNo > 0x13) {
1389 /* di+Ext_CRTVCLK */
1390 VCLKIndex =
1391 pVBInfo->RefIndex[
1392 RefreshRateTableIndex].
1393 Ext_CRTVCLK;
1394 VCLKIndex &= IndexMask;
1395 }
1396 }
1397 }
1398 } else { /* LVDS */
1399 if (ModeNo <= 0x13)
1400 VCLKIndex = CRT2Index;
1401 else
1402 VCLKIndex = CRT2Index;
1403
1404 VCLKIndex = VCLKIndex >> 6;
1405 if ((pVBInfo->LCDResInfo == Panel800x600) ||
1406 (pVBInfo->LCDResInfo == Panel320x480))
1407 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
1408 else if ((pVBInfo->LCDResInfo == Panel1024x768) ||
1409 (pVBInfo->LCDResInfo == Panel1024x768x75))
1410 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1411 else
1412 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
1413 }
1414 /* VCLKIndex = VCLKIndex&IndexMask; */
1415
1416 return VCLKIndex;
1417 }
1418
1419 static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1420 unsigned short ModeIdIndex,
1421 struct xgi_hw_device_info *HwDeviceExtension,
1422 unsigned short RefreshRateTableIndex,
1423 struct vb_device_info *pVBInfo)
1424 {
1425 unsigned char index, data;
1426 unsigned short vclkindex;
1427
1428 if (pVBInfo->IF_DEF_LVDS == 1) {
1429 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1430 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1431 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1432 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
1433 pVBInfo->VCLKData[index].SR2B);
1434 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
1435 pVBInfo->VCLKData[index].SR2C);
1436 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1437 } else if ((pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
1438 | VB_XGI302LV | VB_XGI301C)) && (pVBInfo->VBInfo
1439 & SetCRT2ToLCDA)) {
1440 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1441 RefreshRateTableIndex, HwDeviceExtension,
1442 pVBInfo);
1443 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1444 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1445 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
1446 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
1447 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
1448 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1449 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1450 } else {
1451 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1452 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
1453 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1454 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
1455 pVBInfo->VCLKData[index].SR2B);
1456 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
1457 pVBInfo->VCLKData[index].SR2C);
1458 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
1459 }
1460
1461 if (HwDeviceExtension->jChipType >= XG20) {
1462 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1463 HalfDCLK) {
1464 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
1465 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
1466 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
1467 index = data;
1468 index &= 0xE0;
1469 data &= 0x1F;
1470 data = data << 1;
1471 data += 1;
1472 data |= index;
1473 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1474 }
1475 }
1476 }
1477
1478 static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1479 {
1480 unsigned char temp;
1481
1482 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1483 temp = (temp & 1) << 6;
1484 /* SR06[6] 18bit Dither */
1485 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1486 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1487 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1488
1489 }
1490
1491 static void XGI_SetCRT1FIFO(unsigned short ModeNo,
1492 struct xgi_hw_device_info *HwDeviceExtension,
1493 struct vb_device_info *pVBInfo)
1494 {
1495 unsigned short data;
1496
1497 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1498 data &= 0xfe;
1499 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
1500
1501 if (ModeNo > 0x13) {
1502 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1503 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1504 data &= 0xC0;
1505 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1506 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1507 data |= 0x01;
1508 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
1509 } else {
1510 if (HwDeviceExtension->jChipType == XG27) {
1511 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x0E);
1512 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1513 data &= 0xC0;
1514 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x20);
1515 } else {
1516 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0xAE);
1517 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1518 data &= 0xF0;
1519 xgifb_reg_set(pVBInfo->P3c4, 0x09, data);
1520 }
1521 }
1522
1523 if (HwDeviceExtension->jChipType == XG21)
1524 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
1525 }
1526
1527 static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1528 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1529 struct vb_device_info *pVBInfo)
1530 {
1531 unsigned short data, data2 = 0;
1532 short VCLK;
1533
1534 unsigned char index;
1535
1536 if (ModeNo <= 0x13)
1537 VCLK = 0;
1538 else {
1539 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1540 index &= IndexMask;
1541 VCLK = pVBInfo->VCLKData[index].CLOCK;
1542 }
1543
1544 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
1545 data &= 0xf3;
1546 if (VCLK >= 200)
1547 data |= 0x0c; /* VCLK > 200 */
1548
1549 if (HwDeviceExtension->jChipType >= XG20)
1550 data &= ~0x04; /* 2 pixel mode */
1551
1552 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
1553
1554 if (HwDeviceExtension->jChipType < XG20) {
1555 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
1556 data &= 0xE7;
1557 if (VCLK < 200)
1558 data |= 0x10;
1559 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
1560 }
1561
1562 /* Jong for Adavantech LCD ripple issue
1563 if ((VCLK >= 0) && (VCLK < 135))
1564 data2 = 0x03;
1565 else if ((VCLK >= 135) && (VCLK < 160))
1566 data2 = 0x02;
1567 else if ((VCLK >= 160) && (VCLK < 260))
1568 data2 = 0x01;
1569 else if (VCLK > 260)
1570 data2 = 0x00;
1571 */
1572 data2 = 0x00;
1573
1574 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
1575 if (HwDeviceExtension->jChipType >= XG27)
1576 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
1577
1578 }
1579
1580 static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
1581 unsigned short ModeNo, unsigned short ModeIdIndex,
1582 unsigned short RefreshRateTableIndex,
1583 struct vb_device_info *pVBInfo)
1584 {
1585 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1586 xres;
1587
1588 if (ModeNo > 0x13) {
1589 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1590 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].
1591 Ext_InfoFlag;
1592 } else
1593 /* si+St_ModeFlag */
1594 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1595
1596 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
1597 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
1598
1599 if (ModeNo > 0x13)
1600 data = infoflag;
1601 else
1602 data = 0;
1603
1604 data2 = 0;
1605
1606 if (ModeNo > 0x13) {
1607 if (pVBInfo->ModeType > 0x02) {
1608 data2 |= 0x02;
1609 data3 = pVBInfo->ModeType - ModeVGA;
1610 data3 = data3 << 2;
1611 data2 |= data3;
1612 }
1613 }
1614
1615 data &= InterlaceMode;
1616
1617 if (data)
1618 data2 |= 0x20;
1619
1620 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
1621 /* xgifb_reg_set(pVBInfo->P3c4,0x06,data2); */
1622 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1623 if (ModeNo <= 0x13)
1624 xres = pVBInfo->StResInfo[resindex].HTotal;
1625 else
1626 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
1627
1628 data = 0x0000;
1629 if (infoflag & InterlaceMode) {
1630 if (xres == 1024)
1631 data = 0x0035;
1632 else if (xres == 1280)
1633 data = 0x0048;
1634 }
1635
1636 data2 = data & 0x00FF;
1637 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
1638 data2 = (data & 0xFF00) >> 8;
1639 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
1640
1641 if (modeflag & HalfDCLK)
1642 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
1643
1644 data2 = 0;
1645
1646 if (modeflag & LineCompareOff)
1647 data2 |= 0x08;
1648
1649 if (ModeNo > 0x13) {
1650 if (pVBInfo->ModeType == ModeEGA)
1651 data2 |= 0x40;
1652 }
1653
1654 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
1655 data = 0x60;
1656 if (pVBInfo->ModeType != ModeText) {
1657 data = data ^ 0x60;
1658 if (pVBInfo->ModeType != ModeEGA)
1659 data = data ^ 0xA0;
1660 }
1661 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
1662
1663 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1664 pVBInfo);
1665
1666 /* if (modeflag&HalfDCLK) //030305 fix lowresolution bug */
1667 /* if (XGINew_IF_DEF_NEW_LOWRES) */
1668 /* XGI_VesaLowResolution(ModeNo, ModeIdIndex);
1669 * //030305 fix lowresolution bug */
1670
1671 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1672
1673 if (HwDeviceExtension->jChipType == XG27) {
1674 if (data & 0x40)
1675 data = 0x2c;
1676 else
1677 data = 0x6c;
1678 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1679 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
1680 } else if (HwDeviceExtension->jChipType >= XG20) {
1681 if (data & 0x40)
1682 data = 0x33;
1683 else
1684 data = 0x73;
1685 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1686 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
1687 } else {
1688 if (data & 0x40)
1689 data = 0x2c;
1690 else
1691 data = 0x6c;
1692 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1693 }
1694
1695 }
1696
1697 static void XGI_WriteDAC(unsigned short dl,
1698 unsigned short ah,
1699 unsigned short al,
1700 unsigned short dh,
1701 struct vb_device_info *pVBInfo)
1702 {
1703 unsigned short temp, bh, bl;
1704
1705 bh = ah;
1706 bl = al;
1707
1708 if (dl != 0) {
1709 temp = bh;
1710 bh = dh;
1711 dh = temp;
1712 if (dl == 1) {
1713 temp = bl;
1714 bl = dh;
1715 dh = temp;
1716 } else {
1717 temp = bl;
1718 bl = bh;
1719 bh = temp;
1720 }
1721 }
1722 outb((unsigned short) dh, pVBInfo->P3c9);
1723 outb((unsigned short) bh, pVBInfo->P3c9);
1724 outb((unsigned short) bl, pVBInfo->P3c9);
1725 }
1726
1727 static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
1728 struct vb_device_info *pVBInfo)
1729 {
1730 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al,
1731 ah, dh;
1732 const unsigned short *table = NULL;
1733
1734 if (ModeNo <= 0x13)
1735 data = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1736 else
1737 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1738
1739 data &= DACInfoFlag;
1740 time = 64;
1741
1742 if (data == 0x00)
1743 table = XGINew_MDA_DAC;
1744 else if (data == 0x08)
1745 table = XGINew_CGA_DAC;
1746 else if (data == 0x10)
1747 table = XGINew_EGA_DAC;
1748 else if (data == 0x18) {
1749 time = 256;
1750 table = XGINew_VGA_DAC;
1751 }
1752
1753 if (time == 256)
1754 j = 16;
1755 else
1756 j = time;
1757
1758 outb(0xFF, pVBInfo->P3c6);
1759 outb(0x00, pVBInfo->P3c8);
1760
1761 for (i = 0; i < j; i++) {
1762 data = table[i];
1763
1764 for (k = 0; k < 3; k++) {
1765 data2 = 0;
1766
1767 if (data & 0x01)
1768 data2 = 0x2A;
1769
1770 if (data & 0x02)
1771 data2 += 0x15;
1772
1773 outb(data2, pVBInfo->P3c9);
1774 data = data >> 2;
1775 }
1776 }
1777
1778 if (time == 256) {
1779 for (i = 16; i < 32; i++) {
1780 data = table[i];
1781
1782 for (k = 0; k < 3; k++)
1783 outb(data, pVBInfo->P3c9);
1784 }
1785
1786 si = 32;
1787
1788 for (m = 0; m < 9; m++) {
1789 di = si;
1790 bx = si + 0x04;
1791 dl = 0;
1792
1793 for (n = 0; n < 3; n++) {
1794 for (o = 0; o < 5; o++) {
1795 dh = table[si];
1796 ah = table[di];
1797 al = table[bx];
1798 si++;
1799 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1800 }
1801
1802 si -= 2;
1803
1804 for (o = 0; o < 3; o++) {
1805 dh = table[bx];
1806 ah = table[di];
1807 al = table[si];
1808 si--;
1809 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1810 }
1811
1812 dl++;
1813 }
1814
1815 si += 5;
1816 }
1817 }
1818 }
1819
1820 static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1821 unsigned short ModeIdIndex,
1822 struct vb_device_info *pVBInfo)
1823 {
1824 unsigned short resindex, xres, yres, modeflag;
1825
1826 if (ModeNo <= 0x13)
1827 /* si+St_ResInfo */
1828 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1829 else
1830 /* si+Ext_ResInfo */
1831 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1832
1833 /* if (ModeNo > 0x13) */
1834 /* modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag; */
1835 /* else */
1836 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; */
1837
1838 if (ModeNo <= 0x13)
1839 /* si+St_ResInfo */
1840 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1841 else
1842 /* si+Ext_ResInfo */
1843 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1844
1845 /* resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); */
1846
1847 if (ModeNo <= 0x13) {
1848 xres = pVBInfo->StResInfo[resindex].HTotal;
1849 yres = pVBInfo->StResInfo[resindex].VTotal;
1850 } else {
1851 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1852 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1853 }
1854 if (ModeNo > 0x13) {
1855 if (modeflag & HalfDCLK)
1856 xres = xres << 1;
1857
1858 if (modeflag & DoubleScanMode)
1859 yres = yres << 1;
1860 }
1861 /* if (modeflag & Charx8Dot) */
1862 /* { */
1863
1864 if (xres == 720)
1865 xres = 640;
1866
1867 /* } */
1868 pVBInfo->VGAHDE = xres;
1869 pVBInfo->HDE = xres;
1870 pVBInfo->VGAVDE = yres;
1871 pVBInfo->VDE = yres;
1872 }
1873
1874 static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1875 unsigned short ModeIdIndex,
1876 unsigned short RefreshRateTableIndex,
1877 struct vb_device_info *pVBInfo)
1878 {
1879 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1880
1881 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1882
1883 tempbx = BX;
1884
1885 if (ModeNo <= 0x13) {
1886 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1887 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1888 } else {
1889 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1890 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1891 }
1892
1893 tempal = tempal & 0x0f;
1894
1895 if (tempbx <= 1) { /* ExpLink */
1896 if (ModeNo <= 0x13) {
1897 /* find no Ext_CRT2CRTC2 */
1898 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1899 } else {
1900 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1901 Ext_CRT2CRTC;
1902 }
1903
1904 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
1905 if (ModeNo <= 0x13)
1906 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
1907 St_CRT2CRTC2;
1908 else
1909 tempal = pVBInfo->RefIndex[
1910 RefreshRateTableIndex].
1911 Ext_CRT2CRTC2;
1912 }
1913
1914 if (tempbx & 0x01)
1915 tempal = (tempal >> 4);
1916
1917 tempal = (tempal & 0x0f);
1918 }
1919
1920 tempcx = LCDLenList[tempbx]; /* mov cl,byte ptr cs:LCDLenList[bx] */
1921
1922 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1923 if ((tempbx == 5) || (tempbx) == 7)
1924 tempcx = LCDDesDataLen2;
1925 else if ((tempbx == 3) || (tempbx == 8))
1926 tempcx = LVDSDesDataLen2;
1927 }
1928 /* mov di, word ptr cs:LCDDataList[bx] */
1929 /* tempdi = pVideoMemory[LCDDataList + tempbx * 2] |
1930 (pVideoMemory[LCDDataList + tempbx * 2 + 1] << 8); */
1931
1932 switch (tempbx) {
1933 case 0:
1934 case 1:
1935 tempdi = xgifb_epllcd_crt1;
1936 break;
1937 case 2:
1938 tempdi = XGI_EPLLCDDataPtr;
1939 break;
1940 case 3:
1941 tempdi = XGI_EPLLCDDesDataPtr;
1942 break;
1943 case 4:
1944 tempdi = XGI_LCDDataTable;
1945 break;
1946 case 5:
1947 tempdi = XGI_LCDDesDataTable;
1948 break;
1949 case 6:
1950 tempdi = XGI_EPLCHLCDRegPtr;
1951 break;
1952 case 7:
1953 case 8:
1954 case 9:
1955 tempdi = NULL;
1956 break;
1957 default:
1958 break;
1959 }
1960
1961 if (tempdi == NULL) /* OEMUtil */
1962 return NULL;
1963
1964 table = tempbx;
1965 i = 0;
1966
1967 while (tempdi[i].PANELID != 0xff) {
1968 tempdx = pVBInfo->LCDResInfo;
1969 if (tempbx & 0x0080) { /* OEMUtil */
1970 tempbx &= (~0x0080);
1971 tempdx = pVBInfo->LCDTypeInfo;
1972 }
1973
1974 if (pVBInfo->LCDInfo & EnableScalingLCD)
1975 tempdx &= (~PanelResInfo);
1976
1977 if (tempdi[i].PANELID == tempdx) {
1978 tempbx = tempdi[i].MASK;
1979 tempdx = pVBInfo->LCDInfo;
1980
1981 if (ModeNo <= 0x13) /* alan 09/10/2003 */
1982 tempdx |= SetLCDStdMode;
1983
1984 if (modeflag & HalfDCLK)
1985 tempdx |= SetLCDLowResolution;
1986
1987 tempbx &= tempdx;
1988 if (tempbx == tempdi[i].CAP)
1989 break;
1990 }
1991 i++;
1992 }
1993
1994 if (table == 0) {
1995 switch (tempdi[i].DATAPTR) {
1996 case 0:
1997 return &XGI_LVDSCRT11024x768_1_H[tempal];
1998 break;
1999 case 1:
2000 return &XGI_LVDSCRT11024x768_2_H[tempal];
2001 break;
2002 case 2:
2003 return &XGI_LVDSCRT11280x1024_1_H[tempal];
2004 break;
2005 case 3:
2006 return &XGI_LVDSCRT11280x1024_2_H[tempal];
2007 break;
2008 case 4:
2009 return &XGI_LVDSCRT11400x1050_1_H[tempal];
2010 break;
2011 case 5:
2012 return &XGI_LVDSCRT11400x1050_2_H[tempal];
2013 break;
2014 case 6:
2015 return &XGI_LVDSCRT11600x1200_1_H[tempal];
2016 break;
2017 case 7:
2018 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
2019 break;
2020 case 8:
2021 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
2022 break;
2023 case 9:
2024 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
2025 break;
2026 case 10:
2027 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
2028 break;
2029 default:
2030 break;
2031 }
2032 } else if (table == 1) {
2033 switch (tempdi[i].DATAPTR) {
2034 case 0:
2035 return &XGI_LVDSCRT11024x768_1_V[tempal];
2036 break;
2037 case 1:
2038 return &XGI_LVDSCRT11024x768_2_V[tempal];
2039 break;
2040 case 2:
2041 return &XGI_LVDSCRT11280x1024_1_V[tempal];
2042 break;
2043 case 3:
2044 return &XGI_LVDSCRT11280x1024_2_V[tempal];
2045 break;
2046 case 4:
2047 return &XGI_LVDSCRT11400x1050_1_V[tempal];
2048 break;
2049 case 5:
2050 return &XGI_LVDSCRT11400x1050_2_V[tempal];
2051 break;
2052 case 6:
2053 return &XGI_LVDSCRT11600x1200_1_V[tempal];
2054 break;
2055 case 7:
2056 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
2057 break;
2058 case 8:
2059 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
2060 break;
2061 case 9:
2062 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
2063 break;
2064 case 10:
2065 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
2066 break;
2067 default:
2068 break;
2069 }
2070 } else if (table == 2) {
2071 switch (tempdi[i].DATAPTR) {
2072 case 0:
2073 return &XGI_LVDS1024x768Data_1[tempal];
2074 break;
2075 case 1:
2076 return &XGI_LVDS1024x768Data_2[tempal];
2077 break;
2078 case 2:
2079 return &XGI_LVDS1280x1024Data_1[tempal];
2080 break;
2081 case 3:
2082 return &XGI_LVDS1280x1024Data_2[tempal];
2083 break;
2084 case 4:
2085 return &XGI_LVDS1400x1050Data_1[tempal];
2086 break;
2087 case 5:
2088 return &XGI_LVDS1400x1050Data_2[tempal];
2089 break;
2090 case 6:
2091 return &XGI_LVDS1600x1200Data_1[tempal];
2092 break;
2093 case 7:
2094 return &XGI_LVDSNoScalingData[tempal];
2095 break;
2096 case 8:
2097 return &XGI_LVDS1024x768Data_1x75[tempal];
2098 break;
2099 case 9:
2100 return &XGI_LVDS1024x768Data_2x75[tempal];
2101 break;
2102 case 10:
2103 return &XGI_LVDS1280x1024Data_1x75[tempal];
2104 break;
2105 case 11:
2106 return &XGI_LVDS1280x1024Data_2x75[tempal];
2107 break;
2108 case 12:
2109 return &XGI_LVDSNoScalingDatax75[tempal];
2110 break;
2111 default:
2112 break;
2113 }
2114 } else if (table == 3) {
2115 switch (tempdi[i].DATAPTR) {
2116 case 0:
2117 return &XGI_LVDS1024x768Des_1[tempal];
2118 break;
2119 case 1:
2120 return &XGI_LVDS1024x768Des_3[tempal];
2121 break;
2122 case 2:
2123 return &XGI_LVDS1024x768Des_2[tempal];
2124 break;
2125 case 3:
2126 return &XGI_LVDS1280x1024Des_1[tempal];
2127 break;
2128 case 4:
2129 return &XGI_LVDS1280x1024Des_2[tempal];
2130 break;
2131 case 5:
2132 return &XGI_LVDS1400x1050Des_1[tempal];
2133 break;
2134 case 6:
2135 return &XGI_LVDS1400x1050Des_2[tempal];
2136 break;
2137 case 7:
2138 return &XGI_LVDS1600x1200Des_1[tempal];
2139 break;
2140 case 8:
2141 return &XGI_LVDSNoScalingDesData[tempal];
2142 break;
2143 case 9:
2144 return &XGI_LVDS1024x768Des_1x75[tempal];
2145 break;
2146 case 10:
2147 return &XGI_LVDS1024x768Des_3x75[tempal];
2148 break;
2149 case 11:
2150 return &XGI_LVDS1024x768Des_2x75[tempal];
2151 break;
2152 case 12:
2153 return &XGI_LVDS1280x1024Des_1x75[tempal];
2154 break;
2155 case 13:
2156 return &XGI_LVDS1280x1024Des_2x75[tempal];
2157 break;
2158 case 14:
2159 return &XGI_LVDSNoScalingDesDatax75[tempal];
2160 break;
2161 default:
2162 break;
2163 }
2164 } else if (table == 4) {
2165 switch (tempdi[i].DATAPTR) {
2166 case 0:
2167 return &XGI_ExtLCD1024x768Data[tempal];
2168 break;
2169 case 1:
2170 return &XGI_StLCD1024x768Data[tempal];
2171 break;
2172 case 2:
2173 return &XGI_CetLCD1024x768Data[tempal];
2174 break;
2175 case 3:
2176 return &XGI_ExtLCD1280x1024Data[tempal];
2177 break;
2178 case 4:
2179 return &XGI_StLCD1280x1024Data[tempal];
2180 break;
2181 case 5:
2182 return &XGI_CetLCD1280x1024Data[tempal];
2183 break;
2184 case 6:
2185 case 7:
2186 return &xgifb_lcd_1400x1050[tempal];
2187 break;
2188 case 8:
2189 return &XGI_CetLCD1400x1050Data[tempal];
2190 break;
2191 case 9:
2192 return &XGI_ExtLCD1600x1200Data[tempal];
2193 break;
2194 case 10:
2195 return &XGI_StLCD1600x1200Data[tempal];
2196 break;
2197 case 11:
2198 return &XGI_NoScalingData[tempal];
2199 break;
2200 case 12:
2201 return &XGI_ExtLCD1024x768x75Data[tempal];
2202 break;
2203 case 13:
2204 return &XGI_ExtLCD1024x768x75Data[tempal];
2205 break;
2206 case 14:
2207 return &XGI_CetLCD1024x768x75Data[tempal];
2208 break;
2209 case 15:
2210 case 16:
2211 return &xgifb_lcd_1280x1024x75[tempal];
2212 break;
2213 case 17:
2214 return &XGI_CetLCD1280x1024x75Data[tempal];
2215 break;
2216 case 18:
2217 return &XGI_NoScalingDatax75[tempal];
2218 break;
2219 default:
2220 break;
2221 }
2222 } else if (table == 5) {
2223 switch (tempdi[i].DATAPTR) {
2224 case 0:
2225 return &XGI_ExtLCDDes1024x768Data[tempal];
2226 break;
2227 case 1:
2228 return &XGI_StLCDDes1024x768Data[tempal];
2229 break;
2230 case 2:
2231 return &XGI_CetLCDDes1024x768Data[tempal];
2232 break;
2233 case 3:
2234 if ((pVBInfo->VBType & VB_XGI301LV) ||
2235 (pVBInfo->VBType & VB_XGI302LV))
2236 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
2237 else
2238 return &XGI_ExtLCDDes1280x1024Data[tempal];
2239 break;
2240 case 4:
2241 if ((pVBInfo->VBType & VB_XGI301LV) ||
2242 (pVBInfo->VBType & VB_XGI302LV))
2243 return &XGI_StLCDDLDes1280x1024Data[tempal];
2244 else
2245 return &XGI_StLCDDes1280x1024Data[tempal];
2246 break;
2247 case 5:
2248 if ((pVBInfo->VBType & VB_XGI301LV) ||
2249 (pVBInfo->VBType & VB_XGI302LV))
2250 return &XGI_CetLCDDLDes1280x1024Data[tempal];
2251 else
2252 return &XGI_CetLCDDes1280x1024Data[tempal];
2253 break;
2254 case 6:
2255 case 7:
2256 if ((pVBInfo->VBType & VB_XGI301LV) ||
2257 (pVBInfo->VBType & VB_XGI302LV))
2258 return &xgifb_lcddldes_1400x1050[tempal];
2259 else
2260 return &xgifb_lcddes_1400x1050[tempal];
2261 break;
2262 case 8:
2263 return &XGI_CetLCDDes1400x1050Data[tempal];
2264 break;
2265 case 9:
2266 return &XGI_CetLCDDes1400x1050Data2[tempal];
2267 break;
2268 case 10:
2269 if ((pVBInfo->VBType & VB_XGI301LV) ||
2270 (pVBInfo->VBType & VB_XGI302LV))
2271 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
2272 else
2273 return &XGI_ExtLCDDes1600x1200Data[tempal];
2274 break;
2275 case 11:
2276 if ((pVBInfo->VBType & VB_XGI301LV) ||
2277 (pVBInfo->VBType & VB_XGI302LV))
2278 return &XGI_StLCDDLDes1600x1200Data[tempal];
2279 else
2280 return &XGI_StLCDDes1600x1200Data[tempal];
2281 break;
2282 case 12:
2283 return &XGI_NoScalingDesData[tempal];
2284 break;
2285 case 13:
2286 case 14:
2287 return &xgifb_lcddes_1024x768x75[tempal];
2288 break;
2289 case 15:
2290 return &XGI_CetLCDDes1024x768x75Data[tempal];
2291 break;
2292 case 16:
2293 case 17:
2294 if ((pVBInfo->VBType & VB_XGI301LV) ||
2295 (pVBInfo->VBType & VB_XGI302LV))
2296 return &xgifb_lcddldes_1280x1024x75[tempal];
2297 else
2298 return &xgifb_lcddes_1280x1024x75[tempal];
2299 break;
2300 case 18:
2301 if ((pVBInfo->VBType & VB_XGI301LV) ||
2302 (pVBInfo->VBType & VB_XGI302LV))
2303 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
2304 else
2305 return &XGI_CetLCDDes1280x1024x75Data[tempal];
2306 break;
2307 case 19:
2308 return &XGI_NoScalingDesDatax75[tempal];
2309 break;
2310 default:
2311 break;
2312 }
2313 } else if (table == 6) {
2314 switch (tempdi[i].DATAPTR) {
2315 case 0:
2316 return &XGI_CH7017LV1024x768[tempal];
2317 break;
2318 case 1:
2319 return &XGI_CH7017LV1400x1050[tempal];
2320 break;
2321 default:
2322 break;
2323 }
2324 }
2325 return NULL;
2326 }
2327
2328 static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
2329 unsigned short ModeIdIndex,
2330 unsigned short RefreshRateTableIndex,
2331 struct vb_device_info *pVBInfo)
2332 {
2333 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
2334 struct XGI330_TVDataTablStruct *tempdi = NULL;
2335
2336 tempbx = BX;
2337
2338 if (ModeNo <= 0x13) {
2339 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2340 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2341 } else {
2342 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2343 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2344 }
2345
2346 tempal = tempal & 0x3f;
2347 table = tempbx;
2348
2349 switch (tempbx) {
2350 case 0:
2351 tempdi = NULL; /*EPLCHTVCRT1Ptr_H;*/
2352 break;
2353 case 1:
2354 tempdi = NULL; /*EPLCHTVCRT1Ptr_V;*/
2355 break;
2356 case 2:
2357 case 6:
2358 tempdi = xgifb_chrontel_tv;
2359 break;
2360 case 3:
2361 tempdi = NULL;
2362 break;
2363 case 4:
2364 tempdi = XGI_TVDataTable;
2365 break;
2366 case 5:
2367 tempdi = NULL;
2368 break;
2369 default:
2370 break;
2371 }
2372
2373 if (tempdi == NULL) /* OEMUtil */
2374 return NULL;
2375
2376 tempdx = pVBInfo->TVInfo;
2377
2378 if (pVBInfo->VBInfo & SetInSlaveMode)
2379 tempdx = tempdx | SetTVLockMode;
2380
2381 if (modeflag & HalfDCLK)
2382 tempdx = tempdx | SetTVLowResolution;
2383
2384 i = 0;
2385
2386 while (tempdi[i].MASK != 0xffff) {
2387 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2388 break;
2389 i++;
2390 }
2391
2392 /* 07/05/22 */
2393 if (table == 0x00) {
2394 } else if (table == 0x01) {
2395 } else if (table == 0x04) {
2396 switch (tempdi[i].DATAPTR) {
2397 case 0:
2398 return &XGI_ExtPALData[tempal];
2399 break;
2400 case 1:
2401 return &XGI_ExtNTSCData[tempal];
2402 break;
2403 case 2:
2404 return &XGI_StPALData[tempal];
2405 break;
2406 case 3:
2407 return &XGI_StNTSCData[tempal];
2408 break;
2409 case 4:
2410 return &XGI_ExtHiTVData[tempal];
2411 break;
2412 case 5:
2413 return &XGI_St2HiTVData[tempal];
2414 break;
2415 case 6:
2416 return &XGI_ExtYPbPr525iData[tempal];
2417 break;
2418 case 7:
2419 return &XGI_ExtYPbPr525pData[tempal];
2420 break;
2421 case 8:
2422 return &XGI_ExtYPbPr750pData[tempal];
2423 break;
2424 case 9:
2425 return &XGI_StYPbPr525iData[tempal];
2426 break;
2427 case 10:
2428 return &XGI_StYPbPr525pData[tempal];
2429 break;
2430 case 11:
2431 return &XGI_StYPbPr750pData[tempal];
2432 break;
2433 case 12: /* avoid system hang */
2434 return &XGI_ExtNTSCData[tempal];
2435 break;
2436 case 13:
2437 return &XGI_St1HiTVData[tempal];
2438 break;
2439 default:
2440 break;
2441 }
2442 } else if (table == 0x02) {
2443 switch (tempdi[i].DATAPTR) {
2444 case 0:
2445 return &XGI_CHTVUNTSCData[tempal];
2446 break;
2447 case 1:
2448 return &XGI_CHTVONTSCData[tempal];
2449 break;
2450 case 2:
2451 return &XGI_CHTVUPALData[tempal];
2452 break;
2453 case 3:
2454 return &XGI_CHTVOPALData[tempal];
2455 break;
2456 default:
2457 break;
2458 }
2459 } else if (table == 0x06) {
2460 }
2461 return NULL;
2462 }
2463
2464 static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
2465 unsigned short RefreshRateTableIndex,
2466 struct vb_device_info *pVBInfo)
2467 {
2468 unsigned short tempbx;
2469 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
2470
2471 tempbx = 2;
2472
2473 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2474 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2475 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2476 pVBInfo);
2477 pVBInfo->VGAHT = LCDPtr->VGAHT;
2478 pVBInfo->VGAVT = LCDPtr->VGAVT;
2479 pVBInfo->HT = LCDPtr->LCDHT;
2480 pVBInfo->VT = LCDPtr->LCDVT;
2481 }
2482
2483 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2484 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2485 | EnableScalingLCD))) {
2486 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2487 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2488 pVBInfo->HDE = 1024;
2489 pVBInfo->VDE = 768;
2490 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2491 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2492 pVBInfo->HDE = 1280;
2493 pVBInfo->VDE = 1024;
2494 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2495 pVBInfo->HDE = 1400;
2496 pVBInfo->VDE = 1050;
2497 } else {
2498 pVBInfo->HDE = 1600;
2499 pVBInfo->VDE = 1200;
2500 }
2501 }
2502 }
2503 }
2504
2505 static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
2506 unsigned short RefreshRateTableIndex,
2507 struct xgi_hw_device_info *HwDeviceExtension,
2508 struct vb_device_info *pVBInfo)
2509 {
2510 unsigned char index;
2511 unsigned short tempbx, i;
2512 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2513 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
2514
2515 if (ModeNo <= 0x13)
2516 index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2517 else
2518 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2519
2520 index = index & IndexMask;
2521
2522 tempbx = 0;
2523
2524 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2525 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2526 XGI_GetLcdPtr(tempbx, ModeNo,
2527 ModeIdIndex,
2528 RefreshRateTableIndex,
2529 pVBInfo);
2530
2531 for (i = 0; i < 8; i++)
2532 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
2533 }
2534
2535 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
2536
2537 tempbx = 1;
2538
2539 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2540 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2541 XGI_GetLcdPtr(
2542 tempbx,
2543 ModeNo,
2544 ModeIdIndex,
2545 RefreshRateTableIndex,
2546 pVBInfo);
2547 for (i = 0; i < 7; i++)
2548 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2549 }
2550
2551 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
2552 }
2553
2554 static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2555 {
2556 unsigned char tempal, tempah, tempbl, i;
2557
2558 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
2559 tempal = tempah & 0x0F;
2560 tempah = tempah & 0xF0;
2561 i = 0;
2562 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2563
2564 while (tempbl != 0xFF) {
2565 if (tempbl & 0x80) { /* OEMUtil */
2566 tempal = tempah;
2567 tempbl = tempbl & ~(0x80);
2568 }
2569
2570 if (tempal == tempbl)
2571 break;
2572
2573 i++;
2574
2575 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2576 }
2577
2578 return i;
2579 }
2580
2581 static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2582 {
2583 unsigned short tempah, tempal, tempbl, i;
2584
2585 tempal = pVBInfo->LCDResInfo;
2586 tempah = pVBInfo->LCDTypeInfo;
2587
2588 i = 0;
2589 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2590
2591 while (tempbl != 0xFF) {
2592 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2593 tempal = tempah;
2594 tempbl &= ~0x80;
2595 }
2596
2597 if (tempal == tempbl)
2598 break;
2599
2600 i++;
2601 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2602 }
2603
2604 if (tempbl == 0xFF) {
2605 pVBInfo->LCDResInfo = Panel1024x768;
2606 pVBInfo->LCDTypeInfo = 0;
2607 i = 0;
2608 }
2609
2610 return i;
2611 }
2612
2613 static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2614 unsigned short *VSyncWidth,
2615 struct vb_device_info *pVBInfo)
2616 {
2617 unsigned short Index;
2618
2619 Index = XGI_GetLCDCapPtr(pVBInfo);
2620 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2621 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2622
2623 return;
2624 }
2625
2626 static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
2627 unsigned short RefreshRateTableIndex,
2628 struct vb_device_info *pVBInfo)
2629 {
2630 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2631 unsigned long temp, temp1, temp2, temp3, push3;
2632 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2633 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
2634
2635 if (ModeNo > 0x13)
2636 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2637 else
2638 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2639
2640 tempbx = 3;
2641 if (pVBInfo->LCDInfo & EnableScalingLCD)
2642 LCDPtr1 =
2643 (struct XGI330_LCDDataDesStruct2 *)
2644 XGI_GetLcdPtr(
2645 tempbx,
2646 ModeNo,
2647 ModeIdIndex,
2648 RefreshRateTableIndex,
2649 pVBInfo);
2650 else
2651 LCDPtr =
2652 (struct XGI330_LCDDataDesStruct *)
2653 XGI_GetLcdPtr(
2654 tempbx,
2655 ModeNo,
2656 ModeIdIndex,
2657 RefreshRateTableIndex,
2658 pVBInfo);
2659
2660 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2661 push1 = tempbx;
2662 push2 = tempax;
2663
2664 /* GetLCDResInfo */
2665 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2666 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2667 tempax = 1024;
2668 tempbx = 768;
2669 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2670 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2671 tempax = 1280;
2672 tempbx = 1024;
2673 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2674 tempax = 1400;
2675 tempbx = 1050;
2676 } else {
2677 tempax = 1600;
2678 tempbx = 1200;
2679 }
2680
2681 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2682 pVBInfo->HDE = tempax;
2683 pVBInfo->VDE = tempbx;
2684 pVBInfo->VGAHDE = tempax;
2685 pVBInfo->VGAVDE = tempbx;
2686 }
2687
2688 tempax = pVBInfo->HT;
2689
2690 if (pVBInfo->LCDInfo & EnableScalingLCD)
2691 tempbx = LCDPtr1->LCDHDES;
2692 else
2693 tempbx = LCDPtr->LCDHDES;
2694
2695 tempcx = pVBInfo->HDE;
2696 tempbx = tempbx & 0x0fff;
2697 tempcx += tempbx;
2698
2699 if (tempcx >= tempax)
2700 tempcx -= tempax;
2701
2702 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
2703
2704 tempcx = tempcx >> 3;
2705 tempbx = tempbx >> 3;
2706
2707 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2708 (unsigned short) (tempbx & 0xff));
2709 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2710 (unsigned short) (tempcx & 0xff));
2711
2712 tempax = pVBInfo->HT;
2713
2714 if (pVBInfo->LCDInfo & EnableScalingLCD)
2715 tempbx = LCDPtr1->LCDHRS;
2716 else
2717 tempbx = LCDPtr->LCDHRS;
2718
2719 tempcx = push2;
2720
2721 if (pVBInfo->LCDInfo & EnableScalingLCD)
2722 tempcx = LCDPtr1->LCDHSync;
2723
2724 tempcx += tempbx;
2725
2726 if (tempcx >= tempax)
2727 tempcx -= tempax;
2728
2729 tempax = tempbx & 0x07;
2730 tempax = tempax >> 5;
2731 tempcx = tempcx >> 3;
2732 tempbx = tempbx >> 3;
2733
2734 tempcx &= 0x1f;
2735 tempax |= tempcx;
2736
2737 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2738 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2739 (unsigned short) (tempbx & 0xff));
2740
2741 tempax = pVBInfo->VT;
2742 if (pVBInfo->LCDInfo & EnableScalingLCD)
2743 tempbx = LCDPtr1->LCDVDES;
2744 else
2745 tempbx = LCDPtr->LCDVDES;
2746 tempcx = pVBInfo->VDE;
2747
2748 tempbx = tempbx & 0x0fff;
2749 tempcx += tempbx;
2750 if (tempcx >= tempax)
2751 tempcx -= tempax;
2752
2753 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2754 (unsigned short) (tempbx & 0xff));
2755 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2756 (unsigned short) (tempcx & 0xff));
2757
2758 tempbx = (tempbx >> 8) & 0x07;
2759 tempcx = (tempcx >> 8) & 0x07;
2760
2761 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2762 (unsigned short) ((tempcx << 3)
2763 | tempbx));
2764
2765 tempax = pVBInfo->VT;
2766 if (pVBInfo->LCDInfo & EnableScalingLCD)
2767 tempbx = LCDPtr1->LCDVRS;
2768 else
2769 tempbx = LCDPtr->LCDVRS;
2770
2771 /* tempbx = tempbx >> 4; */
2772 tempcx = push1;
2773
2774 if (pVBInfo->LCDInfo & EnableScalingLCD)
2775 tempcx = LCDPtr1->LCDVSync;
2776
2777 tempcx += tempbx;
2778 if (tempcx >= tempax)
2779 tempcx -= tempax;
2780
2781 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2782 (unsigned short) (tempbx & 0xff));
2783 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2784 (unsigned short) (tempcx & 0x0f));
2785
2786 tempax = ((tempbx >> 8) & 0x07) << 3;
2787
2788 tempbx = pVBInfo->VGAVDE;
2789 if (tempbx != pVBInfo->VDE)
2790 tempax |= 0x40;
2791
2792 if (pVBInfo->LCDInfo & EnableLVDSDDA)
2793 tempax |= 0x40;
2794
2795 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2796 tempax);
2797
2798 tempcx = pVBInfo->VGAVT;
2799 tempbx = pVBInfo->VDE;
2800 tempax = pVBInfo->VGAVDE;
2801 tempcx -= tempax;
2802
2803 temp = tempax; /* 0430 ylshieh */
2804 temp1 = (temp << 18) / tempbx;
2805
2806 tempdx = (unsigned short) ((temp << 18) % tempbx);
2807
2808 if (tempdx != 0)
2809 temp1 += 1;
2810
2811 temp2 = temp1;
2812 push3 = temp2;
2813
2814 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2815 (unsigned short) (temp2 & 0xff));
2816 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2817 (unsigned short) ((temp2 >> 8) & 0xff));
2818
2819 tempbx = (unsigned short) (temp2 >> 16);
2820 tempax = tempbx & 0x03;
2821
2822 tempbx = pVBInfo->VGAVDE;
2823 if (tempbx == pVBInfo->VDE)
2824 tempax |= 0x04;
2825
2826 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2827
2828 if (pVBInfo->VBType & VB_XGI301C) {
2829 temp2 = push3;
2830 xgifb_reg_set(pVBInfo->Part4Port,
2831 0x3c,
2832 (unsigned short) (temp2 & 0xff));
2833 xgifb_reg_set(pVBInfo->Part4Port,
2834 0x3b,
2835 (unsigned short) ((temp2 >> 8) &
2836 0xff));
2837 tempbx = (unsigned short) (temp2 >> 16);
2838 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2839 ~0xc0,
2840 (unsigned short) ((tempbx &
2841 0xff) << 6));
2842
2843 tempcx = pVBInfo->VGAVDE;
2844 if (tempcx == pVBInfo->VDE)
2845 xgifb_reg_and_or(pVBInfo->Part4Port,
2846 0x30, ~0x0c, 0x00);
2847 else
2848 xgifb_reg_and_or(pVBInfo->Part4Port,
2849 0x30, ~0x0c, 0x08);
2850 }
2851
2852 tempcx = pVBInfo->VGAHDE;
2853 tempbx = pVBInfo->HDE;
2854
2855 temp1 = tempcx << 16;
2856
2857 tempax = (unsigned short) (temp1 / tempbx);
2858
2859 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2860 tempax = 65535;
2861
2862 temp3 = tempax;
2863 temp1 = pVBInfo->VGAHDE << 16;
2864
2865 temp1 /= temp3;
2866 temp3 = temp3 << 16;
2867 temp1 -= 1;
2868
2869 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2870
2871 tempax = (unsigned short) (temp3 & 0xff);
2872 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2873
2874 temp1 = pVBInfo->VGAVDE << 18;
2875 temp1 = temp1 / push3;
2876 tempbx = (unsigned short) (temp1 & 0xffff);
2877
2878 if (pVBInfo->LCDResInfo == Panel1024x768)
2879 tempbx -= 1;
2880
2881 tempax = ((tempbx >> 8) & 0xff) << 3;
2882 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2883 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2884 (unsigned short) (tempax & 0xff));
2885 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2886 (unsigned short) (tempbx & 0xff));
2887
2888 temp3 = temp3 >> 16;
2889
2890 if (modeflag & HalfDCLK)
2891 temp3 = temp3 >> 1;
2892
2893 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2894 (unsigned short) ((temp3 >> 8) & 0xff));
2895 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2896 (unsigned short) (temp3 & 0xff));
2897 }
2898
2899 /* --------------------------------------------------------------------- */
2900 /* Function : XGI_GETLCDVCLKPtr */
2901 /* Input : */
2902 /* Output : al -> VCLK Index */
2903 /* Description : */
2904 /* --------------------------------------------------------------------- */
2905 static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2906 struct vb_device_info *pVBInfo)
2907 {
2908 unsigned short index;
2909
2910 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2911 /* index = XGI_GetLCDCapPtr(pVBInfo); */
2912 index = XGI_GetLCDCapPtr1(pVBInfo);
2913
2914 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2915 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2916 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2917 } else { /* LCDA */
2918 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2919 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2920 }
2921 }
2922 return;
2923 }
2924
2925 static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2926 unsigned short ModeNo, unsigned short ModeIdIndex,
2927 struct vb_device_info *pVBInfo)
2928 {
2929
2930 unsigned short index, modeflag;
2931 unsigned char tempal;
2932
2933 if (ModeNo <= 0x13)
2934 /* si+St_ResInfo */
2935 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2936 else
2937 /* si+Ext_ResInfo */
2938 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2939
2940 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2941 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
2942 index = XGI_GetLCDCapPtr(pVBInfo);
2943 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2944
2945 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
2946 return tempal;
2947
2948 /* {TV} */
2949 if (pVBInfo->VBType &
2950 (VB_XGI301B |
2951 VB_XGI302B |
2952 VB_XGI301LV |
2953 VB_XGI302LV |
2954 VB_XGI301C)) {
2955 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
2956 tempal = HiTVVCLKDIV2;
2957 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2958 tempal = HiTVVCLK;
2959 if (pVBInfo->TVInfo & TVSimuMode) {
2960 tempal = HiTVSimuVCLK;
2961 if (!(modeflag & Charx8Dot))
2962 tempal = HiTVTextVCLK;
2963
2964 }
2965 return tempal;
2966 }
2967
2968 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
2969 tempal = YPbPr750pVCLK;
2970 return tempal;
2971 }
2972
2973 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
2974 tempal = YPbPr525pVCLK;
2975 return tempal;
2976 }
2977
2978 tempal = NTSC1024VCLK;
2979
2980 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
2981 tempal = TVVCLKDIV2;
2982 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2983 tempal = TVVCLK;
2984 }
2985
2986 if (pVBInfo->VBInfo & SetCRT2ToTV)
2987 return tempal;
2988 }
2989 } /* {End of VB} */
2990
2991 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
2992 tempal = tempal >> 2;
2993 tempal &= 0x03;
2994
2995 /* for Dot8 Scaling LCD */
2996 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
2997 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2998
2999 if (ModeNo <= 0x13)
3000 return tempal;
3001
3002 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
3003 return tempal;
3004 }
3005
3006 static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
3007 unsigned char *di_1, struct vb_device_info *pVBInfo)
3008 {
3009 if (pVBInfo->VBType & (VB_XGI301 | VB_XGI301B | VB_XGI302B
3010 | VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
3011 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) && (pVBInfo->SetFlag
3012 & ProgrammingCRT2)) {
3013 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
3014 *di_1 = XGI_VBVCLKData[tempal].SR2C;
3015 }
3016 } else {
3017 *di_0 = XGI_VCLKData[tempal].SR2B;
3018 *di_1 = XGI_VCLKData[tempal].SR2C;
3019 }
3020 }
3021
3022 static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
3023 unsigned short RefreshRateTableIndex,
3024 struct vb_device_info *pVBInfo)
3025 {
3026 unsigned char di_0, di_1, tempal;
3027 int i;
3028
3029 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3030 pVBInfo);
3031 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3032 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
3033
3034 for (i = 0; i < 4; i++) {
3035 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
3036 (unsigned short) (0x10 * i));
3037 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA))
3038 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
3039 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
3040 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
3041 } else {
3042 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
3043 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
3044 }
3045 }
3046 }
3047
3048 static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
3049 struct vb_device_info *pVBInfo)
3050 {
3051 unsigned short tempcl, tempch, temp, tempbl, tempax;
3052
3053 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
3054 | VB_XGI302LV | VB_XGI301C)) {
3055 tempcl = 0;
3056 tempch = 0;
3057 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
3058
3059 if (!(temp & 0x20)) {
3060 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
3061 if (temp & 0x80) {
3062 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
3063 if (!(temp & 0x40))
3064 tempcl |= ActiveCRT1;
3065 }
3066 }
3067
3068 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
3069 temp &= 0x0f;
3070
3071 if (!(temp == 0x08)) {
3072 /* Check ChannelA by Part1_13 [2003/10/03] */
3073 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
3074 if (tempax & 0x04)
3075 tempcl = tempcl | ActiveLCD;
3076
3077 temp &= 0x05;
3078
3079 if (!(tempcl & ActiveLCD))
3080 if (temp == 0x01)
3081 tempcl |= ActiveCRT2;
3082
3083 if (temp == 0x04)
3084 tempcl |= ActiveLCD;
3085
3086 if (temp == 0x05) {
3087 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
3088
3089 if (!(temp & 0x08))
3090 tempch |= ActiveAVideo;
3091
3092 if (!(temp & 0x04))
3093 tempch |= ActiveSVideo;
3094
3095 if (temp & 0x02)
3096 tempch |= ActiveSCART;
3097
3098 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3099 if (temp & 0x01)
3100 tempch |= ActiveHiTV;
3101 }
3102
3103 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
3104 temp = xgifb_reg_get(
3105 pVBInfo->Part2Port,
3106 0x4d);
3107
3108 if (temp & 0x10)
3109 tempch |= ActiveYPbPr;
3110 }
3111
3112 if (tempch != 0)
3113 tempcl |= ActiveTV;
3114 }
3115 }
3116
3117 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
3118 if (tempcl & ActiveLCD) {
3119 if ((pVBInfo->SetFlag & ReserveTVOption)) {
3120 if (temp & ActiveTV)
3121 tempcl |= ActiveTV;
3122 }
3123 }
3124 temp = tempcl;
3125 tempbl = ~ModeSwitchStatus;
3126 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
3127
3128 if (!(pVBInfo->SetFlag & ReserveTVOption))
3129 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
3130 } else {
3131 return;
3132 }
3133 }
3134
3135 void XGI_GetVBType(struct vb_device_info *pVBInfo)
3136 {
3137 unsigned short flag, tempbx, tempah;
3138
3139 if (pVBInfo->IF_DEF_LVDS == 0) {
3140 tempbx = VB_XGI302B;
3141 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
3142 if (flag != 0x02) {
3143 tempbx = VB_XGI301;
3144 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
3145 if (flag >= 0xB0) {
3146 tempbx = VB_XGI301B;
3147 if (flag >= 0xC0) {
3148 tempbx = VB_XGI301C;
3149 if (flag >= 0xD0) {
3150 tempbx = VB_XGI301LV;
3151 if (flag >= 0xE0) {
3152 tempbx = VB_XGI302LV;
3153 tempah = xgifb_reg_get(
3154 pVBInfo->Part4Port,
3155 0x39);
3156 if (tempah != 0xFF)
3157 tempbx =
3158 VB_XGI301C;
3159 }
3160 }
3161 }
3162
3163 if (tempbx & (VB_XGI301B | VB_XGI302B)) {
3164 flag = xgifb_reg_get(
3165 pVBInfo->Part4Port,
3166 0x23);
3167
3168 if (!(flag & 0x02))
3169 tempbx = tempbx | VB_NoLCD;
3170 }
3171 }
3172 }
3173 pVBInfo->VBType = tempbx;
3174 }
3175 }
3176
3177 static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3178 struct xgi_hw_device_info *HwDeviceExtension,
3179 struct vb_device_info *pVBInfo)
3180 {
3181 unsigned short tempax, push, tempbx, temp, modeflag;
3182
3183 if (ModeNo <= 0x13)
3184 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3185 else
3186 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3187
3188 pVBInfo->SetFlag = 0;
3189 pVBInfo->ModeType = modeflag & ModeInfoFlag;
3190 tempbx = 0;
3191
3192 if (pVBInfo->VBType & 0xFFFF) {
3193 /* Check Display Device */
3194 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
3195 tempbx = tempbx | temp;
3196 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
3197 push = temp;
3198 push = push << 8;
3199 tempax = temp << 8;
3200 tempbx = tempbx | tempax;
3201 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr | SetCRT2ToLCDA
3202 | SetInSlaveMode | DisableCRT2Display);
3203 temp = 0xFFFF ^ temp;
3204 tempbx &= temp;
3205
3206 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3207
3208 if (pVBInfo->IF_DEF_LCDA == 1) {
3209
3210 if ((HwDeviceExtension->jChipType >= XG20) ||
3211 (HwDeviceExtension->jChipType >= XG40)) {
3212 if (pVBInfo->IF_DEF_LVDS == 0) {
3213 /* if ((pVBInfo->VBType & VB_XGI302B)
3214 || (pVBInfo->VBType & VB_XGI301LV)
3215 || (pVBInfo->VBType & VB_XGI302LV)
3216 || (pVBInfo->VBType & VB_XGI301C))
3217 */
3218 if (pVBInfo->VBType &
3219 (VB_XGI302B |
3220 VB_XGI301LV |
3221 VB_XGI302LV |
3222 VB_XGI301C)) {
3223 if (temp & EnableDualEdge) {
3224 tempbx |=
3225 SetCRT2ToDualEdge;
3226
3227 if (temp & SetToLCDA)
3228 tempbx |=
3229 SetCRT2ToLCDA;
3230 }
3231 }
3232 }
3233 }
3234 }
3235
3236 if (pVBInfo->IF_DEF_YPbPr == 1) {
3237 /* [Billy] 07/05/04 */
3238 if (((pVBInfo->IF_DEF_LVDS == 0) &&
3239 ((pVBInfo->VBType & VB_XGI301LV) ||
3240 (pVBInfo->VBType & VB_XGI302LV) ||
3241 (pVBInfo->VBType & VB_XGI301C)))) {
3242 if (temp & SetYPbPr) { /* temp = CR38 */
3243 if (pVBInfo->IF_DEF_HiVision == 1) {
3244 /* shampoo add for new
3245 * scratch */
3246 temp = xgifb_reg_get(
3247 pVBInfo->P3d4,
3248 0x35);
3249 temp &= YPbPrMode;
3250 tempbx |= SetCRT2ToHiVisionTV;
3251
3252 if (temp != YPbPrMode1080i) {
3253 tempbx &=
3254 (~SetCRT2ToHiVisionTV);
3255 tempbx |=
3256 SetCRT2ToYPbPr;
3257 }
3258 }
3259
3260 /* tempbx |= SetCRT2ToYPbPr; */
3261 }
3262 }
3263 }
3264
3265 tempax = push; /* restore CR31 */
3266
3267 if (pVBInfo->IF_DEF_LVDS == 0) {
3268 if (pVBInfo->IF_DEF_YPbPr == 1) {
3269 if (pVBInfo->IF_DEF_HiVision == 1)
3270 temp = 0x09FC;
3271 else
3272 temp = 0x097C;
3273 } else {
3274 if (pVBInfo->IF_DEF_HiVision == 1)
3275 temp = 0x01FC;
3276 else
3277 temp = 0x017C;
3278 }
3279 } else { /* 3nd party chip */
3280 temp = SetCRT2ToLCD;
3281 }
3282
3283 if (!(tempbx & temp)) {
3284 tempax |= DisableCRT2Display;
3285 tempbx = 0;
3286 }
3287
3288 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
3289 if (!(pVBInfo->VBType & VB_NoLCD)) {
3290 if (tempbx & SetCRT2ToLCDA) {
3291 if (tempbx & SetSimuScanMode)
3292 tempbx &= (~(SetCRT2ToLCD |
3293 SetCRT2ToRAMDAC |
3294 SwitchToCRT2));
3295 else
3296 tempbx &= (~(SetCRT2ToLCD |
3297 SetCRT2ToRAMDAC |
3298 SetCRT2ToTV |
3299 SwitchToCRT2));
3300 }
3301 }
3302 }
3303
3304 /* shampoo add */
3305 /* for driver abnormal */
3306 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode))) {
3307 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
3308 if (tempbx & SetCRT2ToRAMDAC) {
3309 tempbx &= (0xFF00 |
3310 SetCRT2ToRAMDAC |
3311 SwitchToCRT2 |
3312 SetSimuScanMode);
3313 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3314 }
3315 } else {
3316 tempbx &= (~(SetCRT2ToRAMDAC |
3317 SetCRT2ToLCD |
3318 SetCRT2ToTV));
3319 }
3320 }
3321
3322 if (!(pVBInfo->VBType & VB_NoLCD)) {
3323 if (tempbx & SetCRT2ToLCD) {
3324 tempbx &= (0xFF00 |
3325 SetCRT2ToLCD |
3326 SwitchToCRT2 |
3327 SetSimuScanMode);
3328 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3329 }
3330 }
3331
3332 if (tempbx & SetCRT2ToSCART) {
3333 tempbx &= (0xFF00 |
3334 SetCRT2ToSCART |
3335 SwitchToCRT2 |
3336 SetSimuScanMode);
3337 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3338 }
3339
3340 if (pVBInfo->IF_DEF_YPbPr == 1) {
3341 if (tempbx & SetCRT2ToYPbPr)
3342 tempbx &= (0xFF00 |
3343 SwitchToCRT2 |
3344 SetSimuScanMode);
3345 }
3346
3347 if (pVBInfo->IF_DEF_HiVision == 1) {
3348 if (tempbx & SetCRT2ToHiVisionTV)
3349 tempbx &= (0xFF00 |
3350 SetCRT2ToHiVisionTV |
3351 SwitchToCRT2 |
3352 SetSimuScanMode);
3353 }
3354
3355 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
3356 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode)))
3357 tempbx = DisableCRT2Display;
3358 }
3359
3360 if (!(tempbx & DisableCRT2Display)) {
3361 if ((!(tempbx & DriverMode)) ||
3362 (!(modeflag & CRT2Mode))) {
3363 if (pVBInfo->IF_DEF_LCDA == 1) {
3364 if (!(tempbx & SetCRT2ToLCDA))
3365 tempbx |= (SetInSlaveMode |
3366 SetSimuScanMode);
3367 }
3368 }
3369
3370 /* LCD+TV can't support in slave mode
3371 * (Force LCDA+TV->LCDB) */
3372 if ((tempbx & SetInSlaveMode) &&
3373 (tempbx & SetCRT2ToLCDA)) {
3374 tempbx ^= (SetCRT2ToLCD |
3375 SetCRT2ToLCDA |
3376 SetCRT2ToDualEdge);
3377 pVBInfo->SetFlag |= ReserveTVOption;
3378 }
3379 }
3380 }
3381
3382 pVBInfo->VBInfo = tempbx;
3383 }
3384
3385 static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3386 struct vb_device_info *pVBInfo)
3387 {
3388 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
3389
3390 tempbx = 0;
3391 resinfo = 0;
3392
3393 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3394 if (ModeNo <= 0x13) {
3395 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].
3396 St_ModeFlag; /* si+St_ModeFlag */
3397 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].
3398 St_ResInfo; /* si+St_ResInfo */
3399 } else {
3400 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].
3401 Ext_ModeFlag;
3402 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].
3403 Ext_RESINFO; /* si+Ext_ResInfo */
3404 }
3405
3406 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3407 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
3408 tempbx = temp;
3409 if (tempbx & SetPALTV) {
3410 tempbx &= (SetCHTVOverScan |
3411 SetPALMTV |
3412 SetPALNTV |
3413 SetPALTV);
3414 if (tempbx & SetPALMTV)
3415 /* set to NTSC if PAL-M */
3416 tempbx &= ~SetPALTV;
3417 } else
3418 tempbx &= (SetCHTVOverScan |
3419 SetNTSCJ |
3420 SetPALTV);
3421 /*
3422 if (pVBInfo->IF_DEF_LVDS == 0) {
3423 //PAL-M/PAL-N Info
3424 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3425 //00:PAL, 01:PAL-M, 10:PAL-N
3426 temp2 = (index1 & 0xC0) >> 5;
3427 tempbx |= temp2;
3428 if (temp2 & 0x02) //PAL-M
3429 tempbx &= (~SetPALTV);
3430 }
3431 */
3432 }
3433
3434 if (pVBInfo->IF_DEF_LVDS == 0) {
3435 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3436 tempbx |= SetPALTV;
3437 }
3438
3439 if (pVBInfo->IF_DEF_YPbPr == 1) {
3440 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
3441 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
3442 index1 &= YPbPrMode;
3443
3444 if (index1 == YPbPrMode525i)
3445 tempbx |= SetYPbPrMode525i;
3446
3447 if (index1 == YPbPrMode525p)
3448 tempbx = tempbx | SetYPbPrMode525p;
3449 if (index1 == YPbPrMode750p)
3450 tempbx = tempbx | SetYPbPrMode750p;
3451 }
3452 }
3453
3454 if (pVBInfo->IF_DEF_HiVision == 1) {
3455 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
3456 tempbx = tempbx | SetYPbPrMode1080i | SetPALTV;
3457 }
3458
3459 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3460 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3461 (!(pVBInfo->VBInfo & SetNotSimuMode)))
3462 tempbx |= TVSimuMode;
3463
3464 if (!(tempbx & SetPALTV) &&
3465 (modeflag > 13) &&
3466 (resinfo == 8)) /* NTSC 1024x768, */
3467 tempbx |= NTSC1024x768;
3468
3469 tempbx |= RPLLDIV2XO;
3470
3471 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3472 if (pVBInfo->VBInfo & SetInSlaveMode)
3473 tempbx &= (~RPLLDIV2XO);
3474 } else {
3475 if (tempbx &
3476 (SetYPbPrMode525p | SetYPbPrMode750p))
3477 tempbx &= (~RPLLDIV2XO);
3478 else if (!(pVBInfo->VBType &
3479 (VB_XGI301B |
3480 VB_XGI302B |
3481 VB_XGI301LV |
3482 VB_XGI302LV |
3483 VB_XGI301C))) {
3484 if (tempbx & TVSimuMode)
3485 tempbx &= (~RPLLDIV2XO);
3486 }
3487 }
3488 }
3489 }
3490 pVBInfo->TVInfo = tempbx;
3491 }
3492
3493 static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
3494 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
3495 {
3496 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
3497
3498 pVBInfo->LCDResInfo = 0;
3499 pVBInfo->LCDTypeInfo = 0;
3500 pVBInfo->LCDInfo = 0;
3501
3502 if (ModeNo <= 0x13) {
3503 /* si+St_ModeFlag // */
3504 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3505 } else {
3506 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3507 /* si+Ext_ResInfo // */
3508 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3509 }
3510
3511 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
3512 tempbx = temp & 0x0F;
3513
3514 if (tempbx == 0)
3515 tempbx = Panel1024x768; /* default */
3516
3517 /* LCD75 [2003/8/22] Vicent */
3518 if ((tempbx == Panel1024x768) || (tempbx == Panel1280x1024)) {
3519 if (pVBInfo->VBInfo & DriverMode) {
3520 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
3521 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
3522 tempax &= 0x0F;
3523 else
3524 tempax = tempax >> 4;
3525
3526 if ((resinfo == 6) || (resinfo == 9)) {
3527 if (tempax >= 3)
3528 tempbx |= PanelRef75Hz;
3529 } else if ((resinfo == 7) || (resinfo == 8)) {
3530 if (tempax >= 4)
3531 tempbx |= PanelRef75Hz;
3532 }
3533 }
3534 }
3535
3536 pVBInfo->LCDResInfo = tempbx;
3537
3538 /* End of LCD75 */
3539
3540 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
3541 return 0;
3542
3543 tempbx = 0;
3544
3545 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
3546
3547 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
3548
3549 tempbx |= temp;
3550
3551 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
3552
3553 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
3554
3555 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3556 if (((pVBInfo->VBType & VB_XGI302LV) || (pVBInfo->VBType
3557 & VB_XGI301C)) && (tempax & LCDDualLink)) {
3558 tempbx |= SetLCDDualLink;
3559 }
3560 }
3561
3562 if (pVBInfo->IF_DEF_LVDS == 0) {
3563 if ((pVBInfo->LCDResInfo == Panel1400x1050) && (pVBInfo->VBInfo
3564 & SetCRT2ToLCD) && (ModeNo > 0x13) && (resinfo
3565 == 9) && (!(tempbx & EnableScalingLCD)))
3566 /* set to center in 1280x1024 LCDB for Panel1400x1050 */
3567 tempbx |= SetLCDtoNonExpanding;
3568 }
3569
3570 /*
3571 if (tempax & LCDBToA) {
3572 tempbx |= SetLCDBToA;
3573 }
3574 */
3575
3576 if (pVBInfo->IF_DEF_ExpLink == 1) {
3577 if (modeflag & HalfDCLK) {
3578 /* if (!(pVBInfo->LCDInfo&LCDNonExpanding)) */
3579 if (!(tempbx & SetLCDtoNonExpanding)) {
3580 tempbx |= EnableLVDSDDA;
3581 } else {
3582 if (ModeNo > 0x13) {
3583 if (pVBInfo->LCDResInfo
3584 == Panel1024x768) {
3585 if (resinfo == 4) {/* 512x384 */
3586 tempbx |= EnableLVDSDDA;
3587 }
3588 }
3589 }
3590 }
3591 }
3592 }
3593
3594 if (pVBInfo->VBInfo & SetInSlaveMode) {
3595 if (pVBInfo->VBInfo & SetNotSimuMode)
3596 tempbx |= LCDVESATiming;
3597 } else {
3598 tempbx |= LCDVESATiming;
3599 }
3600
3601 pVBInfo->LCDInfo = tempbx;
3602
3603 if (pVBInfo->IF_DEF_LVDS == 0) {
3604 if (tempax & (LockLCDBToA | StLCDBToA)) {
3605 if (pVBInfo->VBInfo & SetInSlaveMode) {
3606 if (!(tempax & LockLCDBToA)) {
3607 if (ModeNo <= 0x13) {
3608 pVBInfo->VBInfo &=
3609 ~(SetSimuScanMode |
3610 SetInSlaveMode |
3611 SetCRT2ToLCD);
3612 pVBInfo->VBInfo |=
3613 SetCRT2ToLCDA |
3614 SetCRT2ToDualEdge;
3615 }
3616 }
3617 }
3618 }
3619 }
3620
3621 /*
3622 if (pVBInfo->IF_DEF_LVDS == 0) {
3623 if (tempax & (LockLCDBToA | StLCDBToA)) {
3624 if (pVBInfo->VBInfo & SetInSlaveMode) {
3625 if (!((!(tempax & LockLCDBToA)) &&
3626 (ModeNo > 0x13))) {
3627 pVBInfo->VBInfo &=
3628 ~(SetSimuScanMode |
3629 SetInSlaveMode |
3630 SetCRT2ToLCD);
3631 pVBInfo->VBInfo |=
3632 SetCRT2ToLCDA |
3633 SetCRT2ToDualEdge;
3634 }
3635 }
3636 }
3637 }
3638 */
3639
3640 return 1;
3641 }
3642
3643 unsigned char XGI_SearchModeID(unsigned short ModeNo,
3644 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
3645 {
3646 if (ModeNo <= 5)
3647 ModeNo |= 1;
3648 if (ModeNo <= 0x13) {
3649 /* for (*ModeIdIndex=0;
3650 *ModeIdIndex < sizeof(pVBInfo->SModeIDTable)
3651 / sizeof(struct XGI_StStruct);
3652 (*ModeIdIndex)++) */
3653 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3654 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3655 ModeNo)
3656 break;
3657 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3658 0xFF)
3659 return 0;
3660 }
3661
3662 if (ModeNo == 0x07)
3663 (*ModeIdIndex)++; /* 400 lines */
3664 if (ModeNo <= 3)
3665 (*ModeIdIndex) += 2; /* 400 lines */
3666 /* else 350 lines */
3667 } else {
3668 /* for (*ModeIdIndex=0;
3669 *ModeIdIndex < sizeof(pVBInfo->EModeIDTable)
3670 / sizeof(struct XGI_ExtStruct);
3671 (*ModeIdIndex)++) */
3672 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3673 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3674 ModeNo)
3675 break;
3676 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3677 0xFF)
3678 return 0;
3679 }
3680 }
3681
3682 return 1;
3683 }
3684
3685 static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3686 {
3687 unsigned char ujRet = 0;
3688 unsigned char i = 0;
3689
3690 for (i = 0; i < 8; i++) {
3691 ujRet = ujRet << 1;
3692 /* ujRet |= GETBITS(ujDate >> i, 0:0); */
3693 ujRet |= (ujDate >> i) & 1;
3694 }
3695
3696 return ujRet;
3697 }
3698
3699 /*----------------------------------------------------------------------------*/
3700 /* output */
3701 /* bl[5] : LVDS signal */
3702 /* bl[1] : LVDS backlight */
3703 /* bl[0] : LVDS VDD */
3704 /*----------------------------------------------------------------------------*/
3705 static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3706 {
3707 unsigned char CR4A, temp;
3708
3709 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3710 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
3711
3712 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3713
3714 temp = XG21GPIODataTransfer(temp);
3715 temp &= 0x23;
3716 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
3717 return temp;
3718 }
3719
3720 /*----------------------------------------------------------------------------*/
3721 /* output */
3722 /* bl[5] : LVDS signal */
3723 /* bl[1] : LVDS backlight */
3724 /* bl[0] : LVDS VDD */
3725 /*----------------------------------------------------------------------------*/
3726 static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3727 {
3728 unsigned char CR4A, CRB4, temp;
3729
3730 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3731 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
3732
3733 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3734
3735 temp &= 0x0C;
3736 temp >>= 2;
3737 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
3738 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
3739 temp |= ((CRB4 & 0x04) << 3);
3740 return temp;
3741 }
3742
3743 /*----------------------------------------------------------------------------*/
3744 /* input */
3745 /* bl[5] : 1;LVDS signal on */
3746 /* bl[1] : 1;LVDS backlight on */
3747 /* bl[0] : 1:LVDS VDD on */
3748 /* bh: 100000b : clear bit 5, to set bit5 */
3749 /* 000010b : clear bit 1, to set bit1 */
3750 /* 000001b : clear bit 0, to set bit0 */
3751 /*----------------------------------------------------------------------------*/
3752 static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3753 struct vb_device_info *pVBInfo)
3754 {
3755 unsigned char CR4A, temp;
3756
3757 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3758 tempbh &= 0x23;
3759 tempbl &= 0x23;
3760 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3761
3762 if (tempbh & 0x20) {
3763 temp = (tempbl >> 4) & 0x02;
3764
3765 /* CR B4[1] */
3766 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3767
3768 }
3769
3770 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3771
3772 temp = XG21GPIODataTransfer(temp);
3773 temp &= ~tempbh;
3774 temp |= tempbl;
3775 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
3776 }
3777
3778 static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3779 struct vb_device_info *pVBInfo)
3780 {
3781 unsigned char CR4A, temp;
3782 unsigned short tempbh0, tempbl0;
3783
3784 tempbh0 = tempbh;
3785 tempbl0 = tempbl;
3786 tempbh0 &= 0x20;
3787 tempbl0 &= 0x20;
3788 tempbh0 >>= 3;
3789 tempbl0 >>= 3;
3790
3791 if (tempbh & 0x20) {
3792 temp = (tempbl >> 4) & 0x02;
3793
3794 /* CR B4[1] */
3795 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3796
3797 }
3798 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
3799
3800 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3801 tempbh &= 0x03;
3802 tempbl &= 0x03;
3803 tempbh <<= 2;
3804 tempbl <<= 2; /* GPIOC,GPIOD */
3805 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3806 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
3807 }
3808
3809 static unsigned short XGI_GetLVDSOEMTableIndex(struct vb_device_info *pVBInfo)
3810 {
3811 unsigned short index;
3812
3813 index = xgifb_reg_get(pVBInfo->P3d4, 0x36);
3814 if (index < sizeof(XGI21_LCDCapList)
3815 / sizeof(struct XGI21_LVDSCapStruct))
3816 return index;
3817 return 0;
3818 }
3819
3820 /* --------------------------------------------------------------------- */
3821 /* Function : XGI_XG21SetPanelDelay */
3822 /* Input : */
3823 /* Output : */
3824 /* Description : */
3825 /* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
3826 /* : bl : 2 ; T2 : the duration signal on and Vdd on */
3827 /* : bl : 3 ; T3 : the duration between CPL off and signal off */
3828 /* : bl : 4 ; T4 : the duration signal off and Vdd off */
3829 /* --------------------------------------------------------------------- */
3830 static void XGI_XG21SetPanelDelay(unsigned short tempbl,
3831 struct vb_device_info *pVBInfo)
3832 {
3833 unsigned short index;
3834
3835 index = XGI_GetLVDSOEMTableIndex(pVBInfo);
3836 if (tempbl == 1)
3837 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S1);
3838
3839 if (tempbl == 2)
3840 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S2);
3841
3842 if (tempbl == 3)
3843 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S3);
3844
3845 if (tempbl == 4)
3846 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S4);
3847 }
3848
3849 static void XGI_DisplayOn(struct xgi_hw_device_info *pXGIHWDE,
3850 struct vb_device_info *pVBInfo)
3851 {
3852
3853 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
3854 if (pXGIHWDE->jChipType == XG21) {
3855 if (pVBInfo->IF_DEF_LVDS == 1) {
3856 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
3857 /* LVDS VDD on */
3858 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
3859 XGI_XG21SetPanelDelay(2, pVBInfo);
3860 }
3861 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
3862 /* LVDS signal on */
3863 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
3864 XGI_XG21SetPanelDelay(3, pVBInfo);
3865 /* LVDS backlight on */
3866 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
3867 } else {
3868 /* DVO/DVI signal on */
3869 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
3870 }
3871
3872 }
3873
3874 if (pXGIHWDE->jChipType == XG27) {
3875 if (pVBInfo->IF_DEF_LVDS == 1) {
3876 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
3877 /* LVDS VDD on */
3878 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
3879 XGI_XG21SetPanelDelay(2, pVBInfo);
3880 }
3881 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
3882 /* LVDS signal on */
3883 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
3884 XGI_XG21SetPanelDelay(3, pVBInfo);
3885 /* LVDS backlight on */
3886 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
3887 } else {
3888 /* DVO/DVI signal on */
3889 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
3890 }
3891
3892 }
3893 }
3894
3895 void XGI_DisplayOff(struct xgi_hw_device_info *pXGIHWDE,
3896 struct vb_device_info *pVBInfo)
3897 {
3898
3899 if (pXGIHWDE->jChipType == XG21) {
3900 if (pVBInfo->IF_DEF_LVDS == 1) {
3901 /* LVDS backlight off */
3902 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
3903 XGI_XG21SetPanelDelay(3, pVBInfo);
3904 } else {
3905 /* DVO/DVI signal off */
3906 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
3907 }
3908 }
3909
3910 if (pXGIHWDE->jChipType == XG27) {
3911 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
3912 /* LVDS backlight off */
3913 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
3914 XGI_XG21SetPanelDelay(3, pVBInfo);
3915 }
3916
3917 if (pVBInfo->IF_DEF_LVDS == 0)
3918 /* DVO/DVI signal off */
3919 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
3920 }
3921
3922 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
3923 }
3924
3925 static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
3926 {
3927 while ((inb(pVBInfo->P3da) & 0x01))
3928 break;
3929
3930 while (!(inb(pVBInfo->P3da) & 0x01))
3931 break;
3932 }
3933
3934 static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
3935 {
3936 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
3937 }
3938
3939 static void XGI_SaveCRT2Info(unsigned short ModeNo,
3940 struct vb_device_info *pVBInfo)
3941 {
3942 unsigned short temp1, temp2;
3943
3944 /* reserve CR34 for CRT1 Mode No */
3945 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
3946 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3947 temp2 = ~(SetInSlaveMode >> 8);
3948 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
3949 }
3950
3951 static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3952 unsigned short ModeIdIndex,
3953 struct vb_device_info *pVBInfo)
3954 {
3955 unsigned short xres, yres, modeflag, resindex;
3956
3957 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
3958 if (ModeNo <= 0x13) {
3959 xres = pVBInfo->StResInfo[resindex].HTotal;
3960 yres = pVBInfo->StResInfo[resindex].VTotal;
3961 /* si+St_ResInfo */
3962 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;*/
3963 } else {
3964 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3965 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
3966 /* si+St_ModeFlag */
3967 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3968
3969 /*
3970 if (pVBInfo->IF_DEF_FSTN) {
3971 xres *= 2;
3972 yres *= 2;
3973 } else {
3974 */
3975 if (modeflag & HalfDCLK)
3976 xres *= 2;
3977
3978 if (modeflag & DoubleScanMode)
3979 yres *= 2;
3980 /* } */
3981 }
3982
3983 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3984 if (pVBInfo->IF_DEF_LVDS == 0) {
3985 if (pVBInfo->LCDResInfo == Panel1600x1200) {
3986 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3987 if (yres == 1024)
3988 yres = 1056;
3989 }
3990 }
3991
3992 if (pVBInfo->LCDResInfo == Panel1280x1024) {
3993 if (yres == 400)
3994 yres = 405;
3995 else if (yres == 350)
3996 yres = 360;
3997
3998 if (pVBInfo->LCDInfo & LCDVESATiming) {
3999 if (yres == 360)
4000 yres = 375;
4001 }
4002 }
4003
4004 if (pVBInfo->LCDResInfo == Panel1024x768) {
4005 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4006 if (!(pVBInfo->LCDInfo
4007 & LCDNonExpanding)) {
4008 if (yres == 350)
4009 yres = 357;
4010 else if (yres == 400)
4011 yres = 420;
4012 else if (yres == 480)
4013 yres = 525;
4014 }
4015 }
4016 }
4017 }
4018
4019 if (xres == 720)
4020 xres = 640;
4021 }
4022
4023 pVBInfo->VGAHDE = xres;
4024 pVBInfo->HDE = xres;
4025 pVBInfo->VGAVDE = yres;
4026 pVBInfo->VDE = yres;
4027 }
4028
4029 static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
4030 {
4031
4032 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
4033 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
4034 return 1;
4035
4036 return 0;
4037 }
4038
4039 static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
4040 unsigned short ModeIdIndex,
4041 unsigned short RefreshRateTableIndex,
4042 struct vb_device_info *pVBInfo)
4043 {
4044 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
4045 StandTableIndex, CRT1Index;
4046
4047 pVBInfo->RVBHCMAX = 1;
4048 pVBInfo->RVBHCFACT = 1;
4049
4050 if (ModeNo <= 0x13) {
4051 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4052 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
4053 tempax = pVBInfo->StandTable[StandTableIndex].CRTC[0];
4054 tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[6];
4055 temp1 = pVBInfo->StandTable[StandTableIndex].CRTC[7];
4056 } else {
4057 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4058 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
4059 Ext_CRT1CRTC;
4060 CRT1Index &= IndexMask;
4061 temp1 = (unsigned short) pVBInfo->
4062 XGINEWUB_CRT1Table[CRT1Index].CR[0];
4063 temp2 = (unsigned short) pVBInfo->
4064 XGINEWUB_CRT1Table[CRT1Index].CR[5];
4065 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
4066 tempbx = (unsigned short) pVBInfo->
4067 XGINEWUB_CRT1Table[CRT1Index].CR[8];
4068 tempcx = (unsigned short) pVBInfo->
4069 XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
4070 tempcx &= 0x0100;
4071 tempcx = tempcx << 2;
4072 tempbx |= tempcx;
4073 temp1 = (unsigned short) pVBInfo->
4074 XGINEWUB_CRT1Table[CRT1Index].CR[9];
4075 }
4076
4077 if (temp1 & 0x01)
4078 tempbx |= 0x0100;
4079
4080 if (temp1 & 0x20)
4081 tempbx |= 0x0200;
4082 tempax += 5;
4083
4084 if (modeflag & Charx8Dot)
4085 tempax *= 8;
4086 else
4087 tempax *= 9;
4088
4089 pVBInfo->VGAHT = tempax;
4090 pVBInfo->HT = tempax;
4091 tempbx++;
4092 pVBInfo->VGAVT = tempbx;
4093 pVBInfo->VT = tempbx;
4094 }
4095
4096 static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
4097 unsigned short RefreshRateTableIndex,
4098 struct vb_device_info *pVBInfo)
4099 {
4100 unsigned short tempax = 0, tempbx, modeflag, resinfo;
4101
4102 struct XGI_LCDDataStruct *LCDPtr = NULL;
4103 struct XGI_TVDataStruct *TVPtr = NULL;
4104
4105 if (ModeNo <= 0x13) {
4106 /* si+St_ResInfo */
4107 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4108 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4109 } else {
4110 /* si+Ext_ResInfo */
4111 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4112 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4113 }
4114
4115 pVBInfo->NewFlickerMode = 0;
4116 pVBInfo->RVBHRS = 50;
4117
4118 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4119 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4120 pVBInfo);
4121 return;
4122 }
4123
4124 tempbx = 4;
4125
4126 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
4127 LCDPtr = (struct XGI_LCDDataStruct *) XGI_GetLcdPtr(tempbx,
4128 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4129 pVBInfo);
4130
4131 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
4132 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
4133 pVBInfo->VGAHT = LCDPtr->VGAHT;
4134 pVBInfo->VGAVT = LCDPtr->VGAVT;
4135 pVBInfo->HT = LCDPtr->LCDHT;
4136 pVBInfo->VT = LCDPtr->LCDVT;
4137
4138 if (pVBInfo->LCDResInfo == Panel1024x768) {
4139 tempax = 1024;
4140 tempbx = 768;
4141
4142 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4143 if (pVBInfo->VGAVDE == 357)
4144 tempbx = 527;
4145 else if (pVBInfo->VGAVDE == 420)
4146 tempbx = 620;
4147 else if (pVBInfo->VGAVDE == 525)
4148 tempbx = 775;
4149 else if (pVBInfo->VGAVDE == 600)
4150 tempbx = 775;
4151 /* else if (pVBInfo->VGAVDE==350) tempbx=560; */
4152 /* else if (pVBInfo->VGAVDE==400) tempbx=640; */
4153 else
4154 tempbx = 768;
4155 } else
4156 tempbx = 768;
4157 } else if (pVBInfo->LCDResInfo == Panel1024x768x75) {
4158 tempax = 1024;
4159 tempbx = 768;
4160 } else if (pVBInfo->LCDResInfo == Panel1280x1024) {
4161 tempax = 1280;
4162 if (pVBInfo->VGAVDE == 360)
4163 tempbx = 768;
4164 else if (pVBInfo->VGAVDE == 375)
4165 tempbx = 800;
4166 else if (pVBInfo->VGAVDE == 405)
4167 tempbx = 864;
4168 else
4169 tempbx = 1024;
4170 } else if (pVBInfo->LCDResInfo == Panel1280x1024x75) {
4171 tempax = 1280;
4172 tempbx = 1024;
4173 } else if (pVBInfo->LCDResInfo == Panel1280x960) {
4174 tempax = 1280;
4175 if (pVBInfo->VGAVDE == 350)
4176 tempbx = 700;
4177 else if (pVBInfo->VGAVDE == 400)
4178 tempbx = 800;
4179 else if (pVBInfo->VGAVDE == 1024)
4180 tempbx = 960;
4181 else
4182 tempbx = 960;
4183 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
4184 tempax = 1400;
4185 tempbx = 1050;
4186
4187 if (pVBInfo->VGAVDE == 1024) {
4188 tempax = 1280;
4189 tempbx = 1024;
4190 }
4191 } else if (pVBInfo->LCDResInfo == Panel1600x1200) {
4192 tempax = 1600;
4193 tempbx = 1200; /* alan 10/14/2003 */
4194 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4195 if (pVBInfo->VGAVDE == 350)
4196 tempbx = 875;
4197 else if (pVBInfo->VGAVDE == 400)
4198 tempbx = 1000;
4199 }
4200 }
4201
4202 if (pVBInfo->LCDInfo & LCDNonExpanding) {
4203 tempax = pVBInfo->VGAHDE;
4204 tempbx = pVBInfo->VGAVDE;
4205 }
4206
4207 pVBInfo->HDE = tempax;
4208 pVBInfo->VDE = tempbx;
4209 return;
4210 }
4211
4212 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
4213 tempbx = 4;
4214 TVPtr = (struct XGI_TVDataStruct *) XGI_GetTVPtr(tempbx,
4215 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4216 pVBInfo);
4217
4218 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
4219 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
4220 pVBInfo->VGAHT = TVPtr->VGAHT;
4221 pVBInfo->VGAVT = TVPtr->VGAVT;
4222 pVBInfo->HDE = TVPtr->TVHDE;
4223 pVBInfo->VDE = TVPtr->TVVDE;
4224 pVBInfo->RVBHRS = TVPtr->RVBHRS;
4225 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
4226
4227 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4228 if (resinfo == 0x08)
4229 pVBInfo->NewFlickerMode = 0x40;
4230 else if (resinfo == 0x09)
4231 pVBInfo->NewFlickerMode = 0x40;
4232 else if (resinfo == 0x12)
4233 pVBInfo->NewFlickerMode = 0x40;
4234
4235 if (pVBInfo->VGAVDE == 350)
4236 pVBInfo->TVInfo |= TVSimuMode;
4237
4238 tempax = ExtHiTVHT;
4239 tempbx = ExtHiTVVT;
4240
4241 if (pVBInfo->VBInfo & SetInSlaveMode) {
4242 if (pVBInfo->TVInfo & TVSimuMode) {
4243 tempax = StHiTVHT;
4244 tempbx = StHiTVVT;
4245
4246 if (!(modeflag & Charx8Dot)) {
4247 tempax = StHiTextTVHT;
4248 tempbx = StHiTextTVVT;
4249 }
4250 }
4251 }
4252 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4253 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
4254 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
4255 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
4256 }
4257
4258 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
4259 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
4260 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
4261 } else if (pVBInfo->TVInfo & SetYPbPrMode525i) {
4262 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
4263 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
4264 if (pVBInfo->TVInfo & NTSC1024x768)
4265 tempax = NTSC1024x768HT;
4266 }
4267 } else {
4268 tempax = PALHT;
4269 tempbx = PALVT;
4270 if (!(pVBInfo->TVInfo & SetPALTV)) {
4271 tempax = NTSCHT;
4272 tempbx = NTSCVT;
4273 if (pVBInfo->TVInfo & NTSC1024x768)
4274 tempax = NTSC1024x768HT;
4275 }
4276 }
4277
4278 pVBInfo->HT = tempax;
4279 pVBInfo->VT = tempbx;
4280 return;
4281 }
4282 }
4283
4284 static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
4285 unsigned short RefreshRateTableIndex,
4286 struct vb_device_info *pVBInfo)
4287 {
4288 unsigned char di_0, di_1, tempal;
4289
4290 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
4291 pVBInfo);
4292 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
4293 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
4294
4295 if (pVBInfo->VBType & VB_XGI301) { /* shampoo 0129 */
4296 /* 301 */
4297 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
4298 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4299 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4300 } else { /* 301b/302b/301lv/302lv */
4301 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4302 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4303 }
4304
4305 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
4306
4307 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
4308 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
4309 else
4310 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
4311 }
4312
4313 static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
4314 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
4315 {
4316 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
4317 short index;
4318 unsigned short modeflag;
4319
4320 if (ModeNo <= 0x13)
4321 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4322 else
4323 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4324
4325 index = (modeflag & ModeInfoFlag) - ModeEGA;
4326
4327 if (index < 0)
4328 index = 0;
4329
4330 return ColorDepth[index];
4331 }
4332
4333 static unsigned short XGI_GetOffset(unsigned short ModeNo,
4334 unsigned short ModeIdIndex,
4335 unsigned short RefreshRateTableIndex,
4336 struct xgi_hw_device_info *HwDeviceExtension,
4337 struct vb_device_info *pVBInfo)
4338 {
4339 unsigned short temp, colordepth, modeinfo, index, infoflag,
4340 ColorDepth[] = { 0x01, 0x02, 0x04 };
4341
4342 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
4343 if (ModeNo <= 0x14)
4344 infoflag = 0;
4345 else
4346 infoflag = pVBInfo->
4347 RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
4348
4349 index = (modeinfo >> 8) & 0xFF;
4350
4351 temp = pVBInfo->ScreenOffset[index];
4352
4353 if (infoflag & InterlaceMode)
4354 temp = temp << 1;
4355
4356 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4357
4358 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
4359 temp = ModeNo - 0x7C;
4360 colordepth = ColorDepth[temp];
4361 temp = 0x6B;
4362 if (infoflag & InterlaceMode)
4363 temp = temp << 1;
4364 return temp * colordepth;
4365 } else {
4366 return temp * colordepth;
4367 }
4368 }
4369
4370 static void XGI_SetCRT2Offset(unsigned short ModeNo,
4371 unsigned short ModeIdIndex,
4372 unsigned short RefreshRateTableIndex,
4373 struct xgi_hw_device_info *HwDeviceExtension,
4374 struct vb_device_info *pVBInfo)
4375 {
4376 unsigned short offset;
4377 unsigned char temp;
4378
4379 if (pVBInfo->VBInfo & SetInSlaveMode)
4380 return;
4381
4382 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4383 HwDeviceExtension, pVBInfo);
4384 temp = (unsigned char) (offset & 0xFF);
4385 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4386 temp = (unsigned char) ((offset & 0xFF00) >> 8);
4387 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
4388 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
4389 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
4390 }
4391
4392 static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
4393 {
4394 /* threshold high ,disable auto threshold */
4395 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
4396 /* threshold low default 04h */
4397 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
4398 }
4399
4400 static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4401 struct xgi_hw_device_info *HwDeviceExtension,
4402 unsigned short RefreshRateTableIndex,
4403 struct vb_device_info *pVBInfo)
4404 {
4405 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
4406
4407 if (ModeNo > 0x13) {
4408 CRT1Index = pVBInfo->
4409 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4410 CRT1Index &= IndexMask;
4411 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4412 }
4413
4414 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4415 HwDeviceExtension, pVBInfo);
4416 XGI_SetCRT2FIFO(pVBInfo);
4417 /* XGI_SetCRT2Sync(ModeNo,RefreshRateTableIndex); */
4418
4419 for (tempcx = 4; tempcx < 7; tempcx++)
4420 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
4421
4422 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
4423 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
4424 }
4425
4426 static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4427 struct xgi_hw_device_info *HwDeviceExtension,
4428 unsigned short RefreshRateTableIndex,
4429 struct vb_device_info *pVBInfo)
4430 {
4431 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
4432 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
4433
4434 if (ModeNo > 0x13) {
4435 CRT1Index = pVBInfo->
4436 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4437 CRT1Index &= IndexMask;
4438 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4439 }
4440
4441 if (ModeNo <= 0x13)
4442 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4443 else
4444 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4445
4446 /* bainy change table name */
4447 if (modeflag & HalfDCLK) {
4448 /* BTVGA2HT 0x08,0x09 */
4449 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
4450 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
4451 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
4452 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
4453 /* BTVGA2HDEE 0x0A,0x0C */
4454 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
4455 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
4456 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
4457 pushbx = pVBInfo->VGAHDE / 2 + 16;
4458 tempcx = tempcx >> 1;
4459 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4460 tempcx += tempbx;
4461
4462 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4463 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4464 tempbx |= ((pVBInfo->
4465 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
4466 0xC0) << 2);
4467 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4468 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
4469 tempcx &= 0x1F;
4470 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
4471 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4472 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4473 }
4474
4475 tempbx += 4;
4476 tempcx += 4;
4477
4478 if (tempcx > (pVBInfo->VGAHT / 2))
4479 tempcx = pVBInfo->VGAHT / 2;
4480
4481 temp = tempbx & 0x00FF;
4482
4483 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4484 } else {
4485 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
4486 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
4487 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
4488 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
4489 /* BTVGA2HDEE 0x0A,0x0C */
4490 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
4491 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
4492 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
4493 pushbx = pVBInfo->VGAHDE + 16;
4494 tempcx = tempcx >> 1;
4495 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4496 tempcx += tempbx;
4497
4498 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4499 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
4500 tempbx |= ((pVBInfo->
4501 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
4502 0xC0) << 2);
4503 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4504 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4505 tempcx &= 0x1F;
4506 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
4507 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4508 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4509 tempbx += 16;
4510 tempcx += 16;
4511 }
4512
4513 if (tempcx > pVBInfo->VGAHT)
4514 tempcx = pVBInfo->VGAHT;
4515
4516 temp = tempbx & 0x00FF;
4517 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4518 }
4519
4520 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
4521 tempbx = pushbx;
4522 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
4523 tempax |= (tempbx & 0xFF00);
4524 temp = (tempax & 0xFF00) >> 8;
4525 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
4526 temp = tempcx & 0x00FF;
4527 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
4528 tempcx = (pVBInfo->VGAVT - 1);
4529 temp = tempcx & 0x00FF;
4530
4531 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
4532 tempbx = pVBInfo->VGAVDE - 1;
4533 temp = tempbx & 0x00FF;
4534 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
4535 temp = ((tempbx & 0xFF00) << 3) >> 8;
4536 temp |= ((tempcx & 0xFF00) >> 8);
4537 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
4538
4539 tempax = pVBInfo->VGAVDE;
4540 tempbx = pVBInfo->VGAVDE;
4541 tempcx = pVBInfo->VGAVT;
4542 /* BTVGA2VRS 0x10,0x11 */
4543 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
4544 /* BTVGA2VRE 0x11 */
4545 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
4546
4547 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4548 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
4549 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
4550
4551 if (temp & 0x04)
4552 tempbx |= 0x0100;
4553
4554 if (temp & 0x080)
4555 tempbx |= 0x0200;
4556
4557 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
4558
4559 if (temp & 0x08)
4560 tempbx |= 0x0400;
4561
4562 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
4563 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
4564 }
4565
4566 temp = tempbx & 0x00FF;
4567 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4568 temp = ((tempbx & 0xFF00) >> 8) << 4;
4569 temp = ((tempcx & 0x000F) | (temp));
4570 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
4571 tempax = 0;
4572
4573 if (modeflag & DoubleScanMode)
4574 tempax |= 0x80;
4575
4576 if (modeflag & HalfDCLK)
4577 tempax |= 0x40;
4578
4579 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
4580 }
4581
4582 static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4583 {
4584 unsigned long tempax, tempbx;
4585
4586 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4587 & 0xFFFF;
4588 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4589 tempax = (tempax * pVBInfo->HT) / tempbx;
4590
4591 return (unsigned short) tempax;
4592 }
4593
4594 static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
4595 struct xgi_hw_device_info *HwDeviceExtension,
4596 unsigned short RefreshRateTableIndex,
4597 struct vb_device_info *pVBInfo)
4598 {
4599 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4600 modeflag, CRT1Index;
4601
4602 if (ModeNo <= 0x13) {
4603 /* si+St_ResInfo */
4604 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4605 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4606 } else {
4607 /* si+Ext_ResInfo */
4608 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4609 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4610 CRT1Index = pVBInfo->
4611 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4612 CRT1Index &= IndexMask;
4613 }
4614
4615 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4616 return;
4617
4618 temp = 0xFF; /* set MAX HT */
4619 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
4620 /* if (modeflag & Charx8Dot) */
4621 /* tempcx = 0x08; */
4622 /* else */
4623 tempcx = 0x08;
4624
4625 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4626 modeflag |= Charx8Dot;
4627
4628 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
4629
4630 if (modeflag & HalfDCLK)
4631 tempax = tempax >> 1;
4632
4633 tempax = (tempax / tempcx) - 1;
4634 tempbx |= ((tempax & 0x00FF) << 8);
4635 temp = tempax & 0x00FF;
4636 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
4637
4638 temp = (tempbx & 0xFF00) >> 8;
4639
4640 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4641 if (!(pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4642 | VB_XGI302LV | VB_XGI301C)))
4643 temp += 2;
4644
4645 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4646 if (pVBInfo->VBType & VB_XGI301LV) {
4647 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4648 if (resinfo == 7)
4649 temp -= 2;
4650 }
4651 } else if (resinfo == 7) {
4652 temp -= 2;
4653 }
4654 }
4655 }
4656
4657 /* 0x05 Horizontal Display Start */
4658 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4659 /* 0x06 Horizontal Blank end */
4660 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
4661
4662 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4663 if (pVBInfo->VBInfo & SetCRT2ToTV)
4664 tempax = pVBInfo->VGAHT;
4665 else
4666 tempax = XGI_GetVGAHT2(pVBInfo);
4667 }
4668
4669 if (tempax >= pVBInfo->VGAHT)
4670 tempax = pVBInfo->VGAHT;
4671
4672 if (modeflag & HalfDCLK)
4673 tempax = tempax >> 1;
4674
4675 tempax = (tempax / tempcx) - 5;
4676 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
4677 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4678 temp = (tempbx & 0x00FF) - 1;
4679 if (!(modeflag & HalfDCLK)) {
4680 temp -= 6;
4681 if (pVBInfo->TVInfo & TVSimuMode) {
4682 temp -= 4;
4683 if (ModeNo > 0x13)
4684 temp -= 10;
4685 }
4686 }
4687 } else {
4688 /* tempcx = tempbx & 0x00FF ; */
4689 tempbx = (tempbx & 0xFF00) >> 8;
4690 tempcx = (tempcx + tempbx) >> 1;
4691 temp = (tempcx & 0x00FF) + 2;
4692
4693 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4694 temp -= 1;
4695 if (!(modeflag & HalfDCLK)) {
4696 if ((modeflag & Charx8Dot)) {
4697 temp += 4;
4698 if (pVBInfo->VGAHDE >= 800)
4699 temp -= 6;
4700 }
4701 }
4702 } else {
4703 if (!(modeflag & HalfDCLK)) {
4704 temp -= 4;
4705 if (pVBInfo->LCDResInfo != Panel1280x960) {
4706 if (pVBInfo->VGAHDE >= 800) {
4707 temp -= 7;
4708 if (pVBInfo->ModeType ==
4709 ModeEGA) {
4710 if (pVBInfo->VGAVDE ==
4711 1024) {
4712 temp += 15;
4713 if (pVBInfo->LCDResInfo != Panel1280x1024) {
4714 temp +=
4715 7;
4716 }
4717 }
4718 }
4719
4720 if (pVBInfo->VGAHDE >= 1280) {
4721 if (pVBInfo->LCDResInfo
4722 != Panel1280x960) {
4723 if (pVBInfo->LCDInfo
4724 & LCDNonExpanding) {
4725 temp
4726 += 28;
4727 }
4728 }
4729 }
4730 }
4731 }
4732 }
4733 }
4734 }
4735
4736 /* 0x07 Horizontal Retrace Start */
4737 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4738 /* 0x08 Horizontal Retrace End */
4739 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
4740
4741 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4742 if (pVBInfo->TVInfo & TVSimuMode) {
4743 if ((ModeNo == 0x06) || (ModeNo == 0x10) || (ModeNo
4744 == 0x11) || (ModeNo == 0x13) || (ModeNo
4745 == 0x0F)) {
4746 xgifb_reg_set(pVBInfo->Part1Port, 0x07, 0x5b);
4747 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0x03);
4748 }
4749
4750 if ((ModeNo == 0x00) || (ModeNo == 0x01)) {
4751 if (pVBInfo->TVInfo & SetNTSCTV) {
4752 xgifb_reg_set(pVBInfo->Part1Port,
4753 0x07, 0x2A);
4754 xgifb_reg_set(pVBInfo->Part1Port,
4755 0x08, 0x61);
4756 } else {
4757 xgifb_reg_set(pVBInfo->Part1Port,
4758 0x07, 0x2A);
4759 xgifb_reg_set(pVBInfo->Part1Port,
4760 0x08, 0x41);
4761 xgifb_reg_set(pVBInfo->Part1Port,
4762 0x0C, 0xF0);
4763 }
4764 }
4765
4766 if ((ModeNo == 0x02) || (ModeNo == 0x03) || (ModeNo
4767 == 0x07)) {
4768 if (pVBInfo->TVInfo & SetNTSCTV) {
4769 xgifb_reg_set(pVBInfo->Part1Port,
4770 0x07, 0x54);
4771 xgifb_reg_set(pVBInfo->Part1Port,
4772 0x08, 0x00);
4773 } else {
4774 xgifb_reg_set(pVBInfo->Part1Port,
4775 0x07, 0x55);
4776 xgifb_reg_set(pVBInfo->Part1Port,
4777 0x08, 0x00);
4778 xgifb_reg_set(pVBInfo->Part1Port,
4779 0x0C, 0xF0);
4780 }
4781 }
4782
4783 if ((ModeNo == 0x04) || (ModeNo == 0x05) || (ModeNo
4784 == 0x0D) || (ModeNo == 0x50)) {
4785 if (pVBInfo->TVInfo & SetNTSCTV) {
4786 xgifb_reg_set(pVBInfo->Part1Port,
4787 0x07, 0x30);
4788 xgifb_reg_set(pVBInfo->Part1Port,
4789 0x08, 0x03);
4790 } else {
4791 xgifb_reg_set(pVBInfo->Part1Port,
4792 0x07, 0x2f);
4793 xgifb_reg_set(pVBInfo->Part1Port,
4794 0x08, 0x02);
4795 }
4796 }
4797 }
4798 }
4799
4800 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
4801 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
4802 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
4803
4804 tempbx = pVBInfo->VGAVT;
4805 push1 = tempbx;
4806 tempcx = 0x121;
4807 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
4808
4809 if (tempbx == 357)
4810 tempbx = 350;
4811 if (tempbx == 360)
4812 tempbx = 350;
4813 if (tempbx == 375)
4814 tempbx = 350;
4815 if (tempbx == 405)
4816 tempbx = 400;
4817 if (tempbx == 525)
4818 tempbx = 480;
4819
4820 push2 = tempbx;
4821
4822 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4823 if (pVBInfo->LCDResInfo == Panel1024x768) {
4824 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4825 if (tempbx == 350)
4826 tempbx += 5;
4827 if (tempbx == 480)
4828 tempbx += 5;
4829 }
4830 }
4831 }
4832 tempbx--;
4833 temp = tempbx & 0x00FF;
4834 tempbx--;
4835 temp = tempbx & 0x00FF;
4836 /* 0x10 vertical Blank Start */
4837 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4838 tempbx = push2;
4839 tempbx--;
4840 temp = tempbx & 0x00FF;
4841 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
4842
4843 if (tempbx & 0x0100)
4844 tempcx |= 0x0002;
4845
4846 tempax = 0x000B;
4847
4848 if (modeflag & DoubleScanMode)
4849 tempax |= 0x08000;
4850
4851 if (tempbx & 0x0200)
4852 tempcx |= 0x0040;
4853
4854 temp = (tempax & 0xFF00) >> 8;
4855 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
4856
4857 if (tempbx & 0x0400)
4858 tempcx |= 0x0600;
4859
4860 /* 0x11 Vertival Blank End */
4861 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
4862
4863 tempax = push1;
4864 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4865 tempax = tempax >> 2;
4866 push1 = tempax; /* push ax */
4867
4868 if (resinfo != 0x09) {
4869 tempax = tempax << 1;
4870 tempbx += tempax;
4871 }
4872
4873 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4874 if (pVBInfo->VBType & VB_XGI301LV) {
4875 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
4876 tempbx -= 10;
4877 } else {
4878 if (pVBInfo->TVInfo & TVSimuMode) {
4879 if (pVBInfo->TVInfo & SetPALTV) {
4880 if (pVBInfo->VBType &
4881 VB_XGI301LV) {
4882 if (!(pVBInfo->TVInfo &
4883 (SetYPbPrMode525p |
4884 SetYPbPrMode750p |
4885 SetYPbPrMode1080i)))
4886 tempbx += 40;
4887 } else {
4888 tempbx += 40;
4889 }
4890 }
4891 }
4892 }
4893 } else {
4894 tempbx -= 10;
4895 }
4896 } else {
4897 if (pVBInfo->TVInfo & TVSimuMode) {
4898 if (pVBInfo->TVInfo & SetPALTV) {
4899 if (pVBInfo->VBType & VB_XGI301LV) {
4900 if (!(pVBInfo->TVInfo &
4901 (SetYPbPrMode525p |
4902 SetYPbPrMode750p |
4903 SetYPbPrMode1080i)))
4904 tempbx += 40;
4905 } else {
4906 tempbx += 40;
4907 }
4908 }
4909 }
4910 }
4911 tempax = push1;
4912 tempax = tempax >> 2;
4913 tempax++;
4914 tempax += tempbx;
4915 push1 = tempax; /* push ax */
4916
4917 if ((pVBInfo->TVInfo & SetPALTV)) {
4918 if (tempbx <= 513) {
4919 if (tempax >= 513)
4920 tempbx = 513;
4921 }
4922 }
4923
4924 temp = tempbx & 0x00FF;
4925 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
4926 tempbx--;
4927 temp = tempbx & 0x00FF;
4928 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
4929
4930 if (tempbx & 0x0100)
4931 tempcx |= 0x0008;
4932
4933 if (tempbx & 0x0200)
4934 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
4935
4936 tempbx++;
4937
4938 if (tempbx & 0x0100)
4939 tempcx |= 0x0004;
4940
4941 if (tempbx & 0x0200)
4942 tempcx |= 0x0080;
4943
4944 if (tempbx & 0x0400)
4945 tempcx |= 0x0C00;
4946
4947 tempbx = push1; /* pop ax */
4948 temp = tempbx & 0x00FF;
4949 temp &= 0x0F;
4950 /* 0x0D vertical Retrace End */
4951 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
4952
4953 if (tempbx & 0x0010)
4954 tempcx |= 0x2000;
4955
4956 temp = tempcx & 0x00FF;
4957 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
4958 temp = (tempcx & 0x0FF00) >> 8;
4959 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
4960 tempax = modeflag;
4961 temp = (tempax & 0xFF00) >> 8;
4962
4963 temp = (temp >> 1) & 0x09;
4964
4965 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4966 temp |= 0x01;
4967
4968 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4969 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4970 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
4971
4972 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4973 temp = 0x80;
4974 else
4975 temp = 0x00;
4976
4977 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
4978
4979 return;
4980 }
4981
4982 static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
4983 unsigned short RefreshRateTableIndex,
4984 struct xgi_hw_device_info *HwDeviceExtension,
4985 struct vb_device_info *pVBInfo)
4986 {
4987 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4988 modeflag, resinfo, crt2crtc;
4989 unsigned char *TimingPoint;
4990
4991 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4992
4993 if (ModeNo <= 0x13) {
4994 /* si+St_ResInfo */
4995 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4996 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4997 crt2crtc = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
4998 } else {
4999 /* si+Ext_ResInfo */
5000 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5001 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
5002 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].
5003 Ext_CRT2CRTC;
5004 }
5005
5006 tempax = 0;
5007
5008 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
5009 tempax |= 0x0800;
5010
5011 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5012 tempax |= 0x0400;
5013
5014 if (pVBInfo->VBInfo & SetCRT2ToSCART)
5015 tempax |= 0x0200;
5016
5017 if (!(pVBInfo->TVInfo & SetPALTV))
5018 tempax |= 0x1000;
5019
5020 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5021 tempax |= 0x0100;
5022
5023 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
5024 tempax &= 0xfe00;
5025
5026 tempax = (tempax & 0xff00) >> 8;
5027
5028 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
5029 TimingPoint = pVBInfo->NTSCTiming;
5030
5031 if (pVBInfo->TVInfo & SetPALTV)
5032 TimingPoint = pVBInfo->PALTiming;
5033
5034 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5035 TimingPoint = pVBInfo->HiTVExtTiming;
5036
5037 if (pVBInfo->VBInfo & SetInSlaveMode)
5038 TimingPoint = pVBInfo->HiTVSt2Timing;
5039
5040 if (pVBInfo->SetFlag & TVSimuMode)
5041 TimingPoint = pVBInfo->HiTVSt1Timing;
5042
5043 if (!(modeflag & Charx8Dot))
5044 TimingPoint = pVBInfo->HiTVTextTiming;
5045 }
5046
5047 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5048 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5049 TimingPoint = pVBInfo->YPbPr525iTiming;
5050
5051 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5052 TimingPoint = pVBInfo->YPbPr525pTiming;
5053
5054 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5055 TimingPoint = pVBInfo->YPbPr750pTiming;
5056 }
5057
5058 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
5059 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
5060
5061 for (i = 0x39; i <= 0x45; i++, j++)
5062 /* di->temp2[j] */
5063 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
5064
5065 if (pVBInfo->VBInfo & SetCRT2ToTV)
5066 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
5067
5068 temp = pVBInfo->NewFlickerMode;
5069 temp &= 0x80;
5070 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
5071
5072 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5073 tempax = 950;
5074
5075 if (pVBInfo->TVInfo & SetPALTV)
5076 tempax = 520;
5077 else
5078 tempax = 440;
5079
5080 if (pVBInfo->VDE <= tempax) {
5081 tempax -= pVBInfo->VDE;
5082 tempax = tempax >> 2;
5083 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
5084 push1 = tempax;
5085 temp = (tempax & 0xFF00) >> 8;
5086 temp += (unsigned short) TimingPoint[0];
5087
5088 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5089 | VB_XGI302LV | VB_XGI301C)) {
5090 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
5091 | SetCRT2ToSVIDEO | SetCRT2ToSCART
5092 | SetCRT2ToYPbPr)) {
5093 tempcx = pVBInfo->VGAHDE;
5094 if (tempcx >= 1024) {
5095 temp = 0x17; /* NTSC */
5096 if (pVBInfo->TVInfo & SetPALTV)
5097 temp = 0x19; /* PAL */
5098 }
5099 }
5100 }
5101
5102 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
5103 tempax = push1;
5104 temp = (tempax & 0xFF00) >> 8;
5105 temp += TimingPoint[1];
5106
5107 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5108 | VB_XGI302LV | VB_XGI301C)) {
5109 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
5110 | SetCRT2ToSVIDEO | SetCRT2ToSCART
5111 | SetCRT2ToYPbPr))) {
5112 tempcx = pVBInfo->VGAHDE;
5113 if (tempcx >= 1024) {
5114 temp = 0x1D; /* NTSC */
5115 if (pVBInfo->TVInfo & SetPALTV)
5116 temp = 0x52; /* PAL */
5117 }
5118 }
5119 }
5120 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
5121 }
5122
5123 /* 301b */
5124 tempcx = pVBInfo->HT;
5125
5126 if (XGI_IsLCDDualLink(pVBInfo))
5127 tempcx = tempcx >> 1;
5128
5129 tempcx -= 2;
5130 temp = tempcx & 0x00FF;
5131 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
5132
5133 temp = (tempcx & 0xFF00) >> 8;
5134 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
5135
5136 tempcx = pVBInfo->HT >> 1;
5137 push1 = tempcx; /* push cx */
5138 tempcx += 7;
5139
5140 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5141 tempcx -= 4;
5142
5143 temp = tempcx & 0x00FF;
5144 temp = temp << 4;
5145 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
5146
5147 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5148 tempbx += tempcx;
5149 push2 = tempbx;
5150 temp = tempbx & 0x00FF;
5151 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
5152 temp = (tempbx & 0xFF00) >> 8;
5153 temp = temp << 4;
5154 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
5155
5156 tempbx = push2;
5157 tempbx = tempbx + 8;
5158 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5159 tempbx = tempbx - 4;
5160 tempcx = tempbx;
5161 }
5162
5163 temp = (tempbx & 0x00FF) << 4;
5164 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
5165
5166 j += 2;
5167 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
5168 temp = tempcx & 0x00FF;
5169 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
5170 temp = ((tempcx & 0xFF00) >> 8) << 4;
5171 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
5172
5173 tempcx += 8;
5174 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5175 tempcx -= 4;
5176
5177 temp = tempcx & 0xFF;
5178 temp = temp << 4;
5179 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
5180
5181 tempcx = push1; /* pop cx */
5182 j += 2;
5183 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5184 tempcx -= temp;
5185 temp = tempcx & 0x00FF;
5186 temp = temp << 4;
5187 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
5188
5189 tempcx -= 11;
5190
5191 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
5192 tempax = XGI_GetVGAHT2(pVBInfo);
5193 tempcx = tempax - 1;
5194 }
5195 temp = tempcx & 0x00FF;
5196 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
5197
5198 tempbx = pVBInfo->VDE;
5199
5200 if (pVBInfo->VGAVDE == 360)
5201 tempbx = 746;
5202 if (pVBInfo->VGAVDE == 375)
5203 tempbx = 746;
5204 if (pVBInfo->VGAVDE == 405)
5205 tempbx = 853;
5206
5207 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5208 if (pVBInfo->VBType &
5209 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
5210 if (!(pVBInfo->TVInfo &
5211 (SetYPbPrMode525p | SetYPbPrMode750p)))
5212 tempbx = tempbx >> 1;
5213 } else
5214 tempbx = tempbx >> 1;
5215 }
5216
5217 tempbx -= 2;
5218 temp = tempbx & 0x00FF;
5219
5220 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5221 if (pVBInfo->VBType & VB_XGI301LV) {
5222 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5223 if (pVBInfo->VBInfo & SetInSlaveMode) {
5224 if (ModeNo == 0x2f)
5225 temp += 1;
5226 }
5227 }
5228 } else {
5229 if (pVBInfo->VBInfo & SetInSlaveMode) {
5230 if (ModeNo == 0x2f)
5231 temp += 1;
5232 }
5233 }
5234 }
5235
5236 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
5237
5238 temp = (tempcx & 0xFF00) >> 8;
5239 temp |= ((tempbx & 0xFF00) >> 8) << 6;
5240
5241 if (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) {
5242 if (pVBInfo->VBType & VB_XGI301LV) {
5243 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5244 temp |= 0x10;
5245
5246 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5247 temp |= 0x20;
5248 }
5249 } else {
5250 temp |= 0x10;
5251 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5252 temp |= 0x20;
5253 }
5254 }
5255
5256 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
5257
5258 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5259 | VB_XGI302LV | VB_XGI301C)) { /* TV gatingno */
5260 tempbx = pVBInfo->VDE;
5261 tempcx = tempbx - 2;
5262
5263 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5264 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p
5265 | SetYPbPrMode750p)))
5266 tempbx = tempbx >> 1;
5267 }
5268
5269 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
5270 temp = 0;
5271 if (tempcx & 0x0400)
5272 temp |= 0x20;
5273
5274 if (tempbx & 0x0400)
5275 temp |= 0x40;
5276
5277 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
5278 }
5279
5280 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
5281 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
5282 temp = (tempbx - 3) & 0x00FF;
5283 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
5284 }
5285
5286 tempbx = tempbx & 0x00FF;
5287
5288 if (!(modeflag & HalfDCLK)) {
5289 tempcx = pVBInfo->VGAHDE;
5290 if (tempcx >= pVBInfo->HDE) {
5291 tempbx |= 0x2000;
5292 tempax &= 0x00FF;
5293 }
5294 }
5295
5296 tempcx = 0x0101;
5297
5298 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
5299 if (pVBInfo->VGAHDE >= 1024) {
5300 tempcx = 0x1920;
5301 if (pVBInfo->VGAHDE >= 1280) {
5302 tempcx = 0x1420;
5303 tempbx = tempbx & 0xDFFF;
5304 }
5305 }
5306 }
5307
5308 if (!(tempbx & 0x2000)) {
5309 if (modeflag & HalfDCLK)
5310 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
5311
5312 push1 = tempbx;
5313 tempeax = pVBInfo->VGAHDE;
5314 tempebx = (tempcx & 0xFF00) >> 8;
5315 longtemp = tempeax * tempebx;
5316 tempecx = tempcx & 0x00FF;
5317 longtemp = longtemp / tempecx;
5318
5319 /* 301b */
5320 tempecx = 8 * 1024;
5321
5322 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5323 | VB_XGI302LV | VB_XGI301C)) {
5324 tempecx = tempecx * 8;
5325 }
5326
5327 longtemp = longtemp * tempecx;
5328 tempecx = pVBInfo->HDE;
5329 temp2 = longtemp % tempecx;
5330 tempeax = longtemp / tempecx;
5331 if (temp2 != 0)
5332 tempeax += 1;
5333
5334 tempax = (unsigned short) tempeax;
5335
5336 /* 301b */
5337 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5338 | VB_XGI302LV | VB_XGI301C)) {
5339 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
5340 }
5341 /* end 301b */
5342
5343 tempbx = push1;
5344 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
5345 | (tempbx & 0x00FF));
5346 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
5347 | (tempax & 0x00FF));
5348 temp = (tempax & 0xFF00) >> 8;
5349 } else {
5350 temp = (tempax & 0x00FF) >> 8;
5351 }
5352
5353 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
5354 temp = (tempbx & 0xFF00) >> 8;
5355 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
5356 temp = tempcx & 0x00FF;
5357
5358 if (tempbx & 0x2000)
5359 temp = 0;
5360
5361 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5362 temp |= 0x18;
5363
5364 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
5365 if (pVBInfo->TVInfo & SetPALTV) {
5366 tempbx = 0x0382;
5367 tempcx = 0x007e;
5368 } else {
5369 tempbx = 0x0369;
5370 tempcx = 0x0061;
5371 }
5372
5373 temp = tempbx & 0x00FF;
5374 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
5375 temp = tempcx & 0x00FF;
5376 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
5377
5378 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
5379 temp = temp << 2;
5380 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
5381
5382 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5383 temp |= 0x10;
5384
5385 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5386 temp |= 0x20;
5387
5388 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5389 temp |= 0x60;
5390 }
5391
5392 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
5393 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
5394 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
5395
5396 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))) {
5397 if (pVBInfo->TVInfo & NTSC1024x768) {
5398 TimingPoint = XGI_NTSC1024AdjTime;
5399 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
5400 xgifb_reg_set(pVBInfo->Part2Port, i,
5401 TimingPoint[j]);
5402 }
5403 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
5404 }
5405 }
5406
5407 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
5408 if (pVBInfo->VBType & VB_XGI301C) {
5409 if (pVBInfo->TVInfo & SetPALMTV)
5410 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
5411 0x08); /* PALM Mode */
5412 }
5413
5414 if (pVBInfo->TVInfo & SetPALMTV) {
5415 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
5416 0x01);
5417 tempax--;
5418 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
5419
5420 /* if ( !( pVBInfo->VBType & VB_XGI301C ) ) */
5421 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
5422 }
5423
5424 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5425 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5426 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
5427 }
5428
5429 if (pVBInfo->VBInfo & SetCRT2ToTV)
5430 return;
5431 }
5432
5433 static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
5434 struct xgi_hw_device_info *HwDeviceExtension,
5435 unsigned short RefreshRateTableIndex,
5436 struct vb_device_info *pVBInfo)
5437 {
5438 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
5439 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
5440
5441 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
5442
5443 if (ModeNo <= 0x13) {
5444 /* si+St_ResInfo */
5445 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5446 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
5447 } else {
5448 /* si+Ext_ResInfo */
5449 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5450 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
5451 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
5452 Ext_CRT1CRTC;
5453 CRT1Index &= IndexMask;
5454 }
5455
5456 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5457 return;
5458
5459 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
5460
5461 if (XGI_IsLCDDualLink(pVBInfo))
5462 tempbx = tempbx >> 1;
5463
5464 tempbx -= 1;
5465 temp = tempbx & 0x00FF;
5466 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
5467 temp = (tempbx & 0xFF00) >> 8;
5468 temp = temp << 4;
5469 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
5470 temp = 0x01;
5471
5472 if (pVBInfo->LCDResInfo == Panel1280x1024) {
5473 if (pVBInfo->ModeType == ModeEGA) {
5474 if (pVBInfo->VGAHDE >= 1024) {
5475 temp = 0x02;
5476 if (pVBInfo->LCDInfo & LCDVESATiming)
5477 temp = 0x01;
5478 }
5479 }
5480 }
5481
5482 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
5483 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
5484 push1 = tempbx;
5485 tempbx--;
5486 temp = tempbx & 0x00FF;
5487 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
5488 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
5489 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
5490
5491 tempcx = pVBInfo->VT - 1;
5492 push2 = tempcx + 1;
5493 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
5494 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
5495 temp = (tempcx & 0xFF00) >> 8;
5496 temp = temp << 5;
5497 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
5498 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
5499 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
5500 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
5501 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
5502
5503 /* Customized LCDB Des no add */
5504 tempbx = 5;
5505 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
5506 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5507 tempah = pVBInfo->LCDResInfo;
5508 tempah &= PanelResInfo;
5509
5510 if ((tempah == Panel1024x768) || (tempah == Panel1024x768x75)) {
5511 tempbx = 1024;
5512 tempcx = 768;
5513 } else if ((tempah == Panel1280x1024) ||
5514 (tempah == Panel1280x1024x75)) {
5515 tempbx = 1280;
5516 tempcx = 1024;
5517 } else if (tempah == Panel1400x1050) {
5518 tempbx = 1400;
5519 tempcx = 1050;
5520 } else {
5521 tempbx = 1600;
5522 tempcx = 1200;
5523 }
5524
5525 if (pVBInfo->LCDInfo & EnableScalingLCD) {
5526 tempbx = pVBInfo->HDE;
5527 tempcx = pVBInfo->VDE;
5528 }
5529
5530 pushbx = tempbx;
5531 tempax = pVBInfo->VT;
5532 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
5533 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
5534 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
5535 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
5536 tempbx = pVBInfo->LCDVDES;
5537 tempcx += tempbx;
5538
5539 if (tempcx >= tempax)
5540 tempcx -= tempax; /* lcdvdes */
5541
5542 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
5543 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
5544 temp = tempcx & 0x00FF;
5545 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
5546 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
5547 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
5548 tempah = tempch;
5549 tempah = tempah << 3;
5550 tempah |= tempbh;
5551 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
5552
5553 /* getlcdsync() */
5554 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5555 tempcx = tempbx;
5556 tempax = pVBInfo->VT;
5557 tempbx = pVBInfo->LCDVRS;
5558
5559 /* if (SetLCD_Info & EnableScalingLCD) */
5560 tempcx += tempbx;
5561 if (tempcx >= tempax)
5562 tempcx -= tempax;
5563
5564 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
5565 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
5566 temp = (tempbx & 0xFF00) >> 8;
5567 temp = temp << 4;
5568 temp |= (tempcx & 0x000F);
5569 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
5570 tempcx = pushbx;
5571 tempax = pVBInfo->HT;
5572 tempbx = pVBInfo->LCDHDES;
5573 tempbx &= 0x0FFF;
5574
5575 if (XGI_IsLCDDualLink(pVBInfo)) {
5576 tempax = tempax >> 1;
5577 tempbx = tempbx >> 1;
5578 tempcx = tempcx >> 1;
5579 }
5580
5581 if (pVBInfo->VBType & VB_XGI302LV)
5582 tempbx += 1;
5583
5584 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
5585 tempbx += 1;
5586
5587 tempcx += tempbx;
5588
5589 if (tempcx >= tempax)
5590 tempcx -= tempax;
5591
5592 temp = tempbx & 0x00FF;
5593 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
5594 temp = ((tempbx & 0xFF00) >> 8) << 4;
5595 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
5596 temp = tempcx & 0x00FF;
5597 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
5598 temp = (tempcx & 0xFF00) >> 8;
5599 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
5600
5601 /* getlcdsync() */
5602 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5603 tempcx = tempax;
5604 tempax = pVBInfo->HT;
5605 tempbx = pVBInfo->LCDHRS;
5606 /* if ( SetLCD_Info & EnableScalingLCD) */
5607 if (XGI_IsLCDDualLink(pVBInfo)) {
5608 tempax = tempax >> 1;
5609 tempbx = tempbx >> 1;
5610 tempcx = tempcx >> 1;
5611 }
5612
5613 if (pVBInfo->VBType & VB_XGI302LV)
5614 tempbx += 1;
5615
5616 tempcx += tempbx;
5617
5618 if (tempcx >= tempax)
5619 tempcx -= tempax;
5620
5621 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
5622 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
5623
5624 temp = (tempbx & 0xFF00) >> 8;
5625 temp = temp << 4;
5626 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
5627 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
5628 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
5629
5630 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
5631 if (pVBInfo->VGAVDE == 525) {
5632 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5633 | VB_XGI301LV | VB_XGI302LV
5634 | VB_XGI301C)) {
5635 temp = 0xC6;
5636 } else
5637 temp = 0xC4;
5638
5639 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5640 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
5641 }
5642
5643 if (pVBInfo->VGAVDE == 420) {
5644 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5645 | VB_XGI301LV | VB_XGI302LV
5646 | VB_XGI301C)) {
5647 temp = 0x4F;
5648 } else
5649 temp = 0x4E;
5650 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5651 }
5652 }
5653 }
5654
5655 /* --------------------------------------------------------------------- */
5656 /* Function : XGI_GetTap4Ptr */
5657 /* Input : */
5658 /* Output : di -> Tap4 Reg. Setting Pointer */
5659 /* Description : */
5660 /* --------------------------------------------------------------------- */
5661 static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
5662 struct vb_device_info *pVBInfo)
5663 {
5664 unsigned short tempax, tempbx, i;
5665
5666 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
5667
5668 if (tempcx == 0) {
5669 tempax = pVBInfo->VGAHDE;
5670 tempbx = pVBInfo->HDE;
5671 } else {
5672 tempax = pVBInfo->VGAVDE;
5673 tempbx = pVBInfo->VDE;
5674 }
5675
5676 if (tempax <= tempbx)
5677 return &xgifb_tap4_timing[0];
5678 else
5679 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
5680
5681 if (pVBInfo->TVInfo & SetPALTV)
5682 Tap4TimingPtr = PALTap4Timing;
5683
5684 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5685 if ((pVBInfo->TVInfo & SetYPbPrMode525i) ||
5686 (pVBInfo->TVInfo & SetYPbPrMode525p))
5687 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
5688 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5689 Tap4TimingPtr = YPbPr750pTap4Timing;
5690 }
5691
5692 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5693 Tap4TimingPtr = xgifb_tap4_timing;
5694
5695 i = 0;
5696 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5697 if (Tap4TimingPtr[i].DE == tempax)
5698 break;
5699 i++;
5700 }
5701 return &Tap4TimingPtr[i];
5702 }
5703
5704 static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
5705 {
5706 unsigned short i, j;
5707
5708 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
5709
5710 if (!(pVBInfo->VBType & VB_XGI301C))
5711 return;
5712
5713 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5714 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
5715 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
5716
5717 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5718 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV))) {
5719 /* Set Vertical Scaling */
5720 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
5721 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
5722 xgifb_reg_set(pVBInfo->Part2Port,
5723 i,
5724 Tap4TimingPtr->Reg[j]);
5725 }
5726
5727 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5728 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)))
5729 /* Enable V.Scaling */
5730 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
5731 else
5732 /* Enable H.Scaling */
5733 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
5734 }
5735
5736 static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
5737 struct vb_device_info *pVBInfo)
5738 {
5739 unsigned short i;
5740 unsigned char *tempdi;
5741 unsigned short modeflag;
5742
5743 if (ModeNo <= 0x13)
5744 /* si+St_ResInfo */
5745 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5746 else
5747 /* si+Ext_ResInfo */
5748 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5749
5750 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
5751 if (pVBInfo->TVInfo & SetPALTV) {
5752 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5753 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5754 } else {
5755 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5756 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
5757 }
5758
5759 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5760 return;
5761
5762 if (pVBInfo->TVInfo & SetPALMTV) {
5763 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5764 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5765 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
5766 }
5767
5768 if ((pVBInfo->VBInfo & SetCRT2ToHiVisionTV) || (pVBInfo->VBInfo
5769 & SetCRT2ToYPbPr)) {
5770 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5771 return;
5772
5773 tempdi = pVBInfo->HiTVGroup3Data;
5774 if (pVBInfo->SetFlag & TVSimuMode) {
5775 tempdi = pVBInfo->HiTVGroup3Simu;
5776 if (!(modeflag & Charx8Dot))
5777 tempdi = pVBInfo->HiTVGroup3Text;
5778 }
5779
5780 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5781 tempdi = pVBInfo->Ren525pGroup3;
5782
5783 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5784 tempdi = pVBInfo->Ren750pGroup3;
5785
5786 for (i = 0; i <= 0x3E; i++)
5787 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
5788
5789 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
5790 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5791 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
5792 }
5793 }
5794 return;
5795 } /* {end of XGI_SetGroup3} */
5796
5797 static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
5798 unsigned short RefreshRateTableIndex,
5799 struct xgi_hw_device_info *HwDeviceExtension,
5800 struct vb_device_info *pVBInfo)
5801 {
5802 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
5803
5804 unsigned long tempebx, tempeax, templong;
5805
5806 if (ModeNo <= 0x13)
5807 /* si+St_ResInfo */
5808 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
5809 else
5810 /* si+Ext_ResInfo */
5811 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5812
5813 temp = pVBInfo->RVBHCFACT;
5814 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
5815
5816 tempbx = pVBInfo->RVBHCMAX;
5817 temp = tempbx & 0x00FF;
5818 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
5819 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5820 tempcx = pVBInfo->VGAHT - 1;
5821 temp = tempcx & 0x00FF;
5822 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
5823
5824 temp = ((tempcx & 0xFF00) >> 8) << 3;
5825 temp2 |= temp;
5826
5827 tempcx = pVBInfo->VGAVT - 1;
5828 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5829 tempcx -= 5;
5830
5831 temp = tempcx & 0x00FF;
5832 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
5833 temp = temp2 | ((tempcx & 0xFF00) >> 8);
5834 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
5835 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
5836 tempcx = pVBInfo->VBInfo;
5837 tempbx = pVBInfo->VGAHDE;
5838
5839 if (modeflag & HalfDCLK)
5840 tempbx = tempbx >> 1;
5841
5842 if (XGI_IsLCDDualLink(pVBInfo))
5843 tempbx = tempbx >> 1;
5844
5845 if (tempcx & SetCRT2ToHiVisionTV) {
5846 temp = 0;
5847 if (tempbx <= 1024)
5848 temp = 0xA0;
5849 if (tempbx == 1280)
5850 temp = 0xC0;
5851 } else if (tempcx & SetCRT2ToTV) {
5852 temp = 0xA0;
5853 if (tempbx <= 800)
5854 temp = 0x80;
5855 } else {
5856 temp = 0x80;
5857 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5858 temp = 0;
5859 if (tempbx > 800)
5860 temp = 0x60;
5861 }
5862 }
5863
5864 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p)) {
5865 temp = 0x00;
5866 if (pVBInfo->VGAHDE == 1280)
5867 temp = 0x40;
5868 if (pVBInfo->VGAHDE == 1024)
5869 temp = 0x20;
5870 }
5871 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
5872
5873 tempebx = pVBInfo->VDE;
5874
5875 if (tempcx & SetCRT2ToHiVisionTV) {
5876 if (!(temp & 0xE000))
5877 tempbx = tempbx >> 1;
5878 }
5879
5880 tempcx = pVBInfo->RVBHRS;
5881 temp = tempcx & 0x00FF;
5882 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
5883
5884 tempeax = pVBInfo->VGAVDE;
5885 tempcx |= 0x04000;
5886
5887 if (tempeax <= tempebx) {
5888 tempcx = (tempcx & (~0x4000));
5889 tempeax = pVBInfo->VGAVDE;
5890 } else {
5891 tempeax -= tempebx;
5892 }
5893
5894 templong = (tempeax * 256 * 1024) % tempebx;
5895 tempeax = (tempeax * 256 * 1024) / tempebx;
5896 tempebx = tempeax;
5897
5898 if (templong != 0)
5899 tempebx++;
5900
5901 temp = (unsigned short) (tempebx & 0x000000FF);
5902 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
5903
5904 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
5905 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
5906 tempbx = (unsigned short) (tempebx >> 16);
5907 temp = tempbx & 0x00FF;
5908 temp = temp << 4;
5909 temp |= ((tempcx & 0xFF00) >> 8);
5910 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
5911
5912 /* 301b */
5913 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5914 | VB_XGI302LV | VB_XGI301C)) {
5915 temp = 0x0028;
5916 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
5917 tempax = pVBInfo->VGAHDE;
5918 if (modeflag & HalfDCLK)
5919 tempax = tempax >> 1;
5920
5921 if (XGI_IsLCDDualLink(pVBInfo))
5922 tempax = tempax >> 1;
5923
5924 /* if((pVBInfo->VBInfo&(SetCRT2ToLCD)) ||
5925 ((pVBInfo->TVInfo&SetYPbPrMode525p) ||
5926 (pVBInfo->TVInfo&SetYPbPrMode750p))) { */
5927 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5928 if (tempax > 800)
5929 tempax -= 800;
5930 } else {
5931 if (pVBInfo->VGAHDE > 800) {
5932 if (pVBInfo->VGAHDE == 1024)
5933 tempax = (tempax * 25 / 32) - 1;
5934 else
5935 tempax = (tempax * 20 / 32) - 1;
5936 }
5937 }
5938 tempax -= 1;
5939
5940 /*
5941 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5942 if (pVBInfo->VBType & VB_XGI301LV) {
5943 if (!(pVBInfo->TVInfo &
5944 (SetYPbPrMode525p |
5945 SetYPbPrMode750p |
5946 SetYPbPrMode1080i))) {
5947 if (pVBInfo->VGAHDE > 800) {
5948 if (pVBInfo->VGAHDE == 1024)
5949 tempax =(tempax * 25 /
5950 32) - 1;
5951 else
5952 tempax = (tempax * 20 /
5953 32) - 1;
5954 }
5955 }
5956 } else {
5957 if (pVBInfo->VGAHDE > 800) {
5958 if (pVBInfo->VGAHDE == 1024)
5959 tempax = (tempax * 25 / 32) - 1;
5960 else
5961 tempax = (tempax * 20 / 32) - 1;
5962 }
5963 }
5964 }
5965 */
5966
5967 temp = (tempax & 0xFF00) >> 8;
5968 temp = ((temp & 0x0003) << 4);
5969 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
5970 temp = (tempax & 0x00FF);
5971 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
5972
5973 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5974 if (pVBInfo->VGAHDE > 800)
5975 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
5976
5977 }
5978 temp = 0x0036;
5979
5980 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5981 if (!(pVBInfo->TVInfo & (NTSC1024x768
5982 | SetYPbPrMode525p | SetYPbPrMode750p
5983 | SetYPbPrMode1080i))) {
5984 temp |= 0x0001;
5985 if ((pVBInfo->VBInfo & SetInSlaveMode)
5986 && (!(pVBInfo->TVInfo
5987 & TVSimuMode)))
5988 temp &= (~0x0001);
5989 }
5990 }
5991
5992 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
5993 tempbx = pVBInfo->HT;
5994 if (XGI_IsLCDDualLink(pVBInfo))
5995 tempbx = tempbx >> 1;
5996 tempbx = (tempbx >> 1) - 2;
5997 temp = ((tempbx & 0x0700) >> 8) << 3;
5998 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
5999 temp = tempbx & 0x00FF;
6000 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
6001 }
6002 /* end 301b */
6003
6004 if (pVBInfo->ISXPDOS == 0)
6005 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6006 pVBInfo);
6007 }
6008
6009 static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
6010 {
6011 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
6012 }
6013
6014 static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
6015 struct vb_device_info *pVBInfo)
6016 {
6017 unsigned short Pindex, Pdata;
6018
6019 Pindex = pVBInfo->Part5Port;
6020 Pdata = pVBInfo->Part5Port + 1;
6021 if (pVBInfo->ModeType == ModeVGA) {
6022 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
6023 | CRT2DisplayFlag))) {
6024 XGINew_EnableCRT2(pVBInfo);
6025 /* LoadDAC2(pVBInfo->Part5Port, ModeNo, ModeIdIndex); */
6026 }
6027 }
6028 return;
6029 }
6030
6031 static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
6032 struct vb_device_info *pVBInfo)
6033 {
6034 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
6035 }
6036
6037 static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
6038 struct vb_device_info *pVBInfo)
6039 {
6040
6041 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
6042 }
6043
6044 static unsigned char XGI_XG21CheckLVDSMode(unsigned short ModeNo,
6045 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
6046 {
6047 unsigned short xres, yres, colordepth, modeflag, resindex,
6048 lvdstableindex;
6049
6050 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6051 if (ModeNo <= 0x13) {
6052 xres = pVBInfo->StResInfo[resindex].HTotal;
6053 yres = pVBInfo->StResInfo[resindex].VTotal;
6054 /* si+St_ResInfo */
6055 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
6056 } else {
6057 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6058 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
6059 /* si+St_ModeFlag */
6060 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
6061 }
6062
6063 if (!(modeflag & Charx8Dot)) {
6064 xres /= 9;
6065 xres *= 8;
6066 }
6067
6068 if (ModeNo > 0x13) {
6069 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
6070 xres *= 2;
6071
6072 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6073 yres *= 2;
6074
6075 }
6076
6077 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6078 if (xres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE))
6079 return 0;
6080
6081 if (yres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE))
6082 return 0;
6083
6084 if (ModeNo > 0x13) {
6085 if ((xres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6086 LVDSHDE)) ||
6087 (yres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6088 LVDSVDE))) {
6089 colordepth = XGI_GetColorDepth(ModeNo,
6090 ModeIdIndex,
6091 pVBInfo);
6092 if (colordepth > 2)
6093 return 0;
6094
6095 }
6096 }
6097 return 1;
6098 }
6099
6100 static void xgifb_set_lvds(int chip_id,
6101 unsigned short ModeNo,
6102 unsigned short ModeIdIndex,
6103 struct vb_device_info *pVBInfo)
6104 {
6105 unsigned char temp, Miscdata;
6106 unsigned short xres, yres, modeflag, resindex, lvdstableindex;
6107 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
6108 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
6109 unsigned short value;
6110
6111 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6112 temp = (unsigned char) ((pVBInfo->XG21_LVDSCapList[lvdstableindex].
6113 LVDS_Capability &
6114 (LCDPolarity << 8)) >> 8);
6115 temp &= LCDPolarity;
6116 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
6117
6118 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
6119
6120 temp = (unsigned char) (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6121 LVDS_Capability & LCDPolarity);
6122 /* SR35[7] FP VSync polarity */
6123 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
6124 /* SR30[5] FP HSync polarity */
6125 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
6126
6127 if (chip_id == XG27)
6128 XGI_SetXG27FPBits(pVBInfo);
6129 else
6130 XGI_SetXG21FPBits(pVBInfo);
6131
6132 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6133 if (ModeNo <= 0x13) {
6134 xres = pVBInfo->StResInfo[resindex].HTotal;
6135 yres = pVBInfo->StResInfo[resindex].VTotal;
6136 /* si+St_ResInfo */
6137 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
6138 } else {
6139 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6140 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
6141 /* si+St_ModeFlag */
6142 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
6143 }
6144
6145 if (!(modeflag & Charx8Dot))
6146 xres = xres * 8 / 9;
6147
6148 LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
6149
6150 LVDSHBS = xres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE
6151 - xres) / 2;
6152 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
6153 LVDSHBS -= xres / 4;
6154
6155 if (LVDSHBS > LVDSHT)
6156 LVDSHBS -= LVDSHT;
6157
6158 LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP;
6159 if (LVDSHRS > LVDSHT)
6160 LVDSHRS -= LVDSHT;
6161
6162 LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC;
6163 if (LVDSHRE > LVDSHT)
6164 LVDSHRE -= LVDSHT;
6165
6166 LVDSHBE = LVDSHBS + LVDSHT
6167 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE;
6168
6169 LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
6170
6171 LVDSVBS = yres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE
6172 - yres) / 2;
6173 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6174 LVDSVBS += yres / 2;
6175
6176 if (LVDSVBS > LVDSVT)
6177 LVDSVBS -= LVDSVT;
6178
6179 LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP;
6180 if (LVDSVRS > LVDSVT)
6181 LVDSVRS -= LVDSVT;
6182
6183 LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].
6184 LVDSVSYNC;
6185 if (LVDSVRE > LVDSVT)
6186 LVDSVRE -= LVDSVT;
6187
6188 LVDSVBE = LVDSVBS + LVDSVT
6189 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE;
6190
6191 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
6192 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
6193
6194 if (!(modeflag & Charx8Dot))
6195 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
6196
6197 /* HT SR0B[1:0] CR00 */
6198 value = (LVDSHT >> 3) - 5;
6199 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
6200 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
6201
6202 /* HBS SR0B[5:4] CR02 */
6203 value = (LVDSHBS >> 3) - 1;
6204 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
6205 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
6206
6207 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
6208 value = (LVDSHBE >> 3) - 1;
6209 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
6210 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
6211 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
6212
6213 /* HRS SR0B[7:6] CR04 */
6214 value = (LVDSHRS >> 3) + 2;
6215 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
6216 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
6217
6218 /* Panel HRS SR2F[1:0] SR2E[7:0] */
6219 value--;
6220 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
6221 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
6222
6223 /* HRE SR0C[2] CR05[4:0] */
6224 value = (LVDSHRE >> 3) + 2;
6225 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
6226 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
6227
6228 /* Panel HRE SR2F[7:2] */
6229 value--;
6230 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
6231
6232 /* VT SR0A[0] CR07[5][0] CR06 */
6233 value = LVDSVT - 2;
6234 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
6235 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
6236 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
6237 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
6238
6239 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
6240 value = LVDSVBS - 1;
6241 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
6242 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
6243 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
6244 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
6245
6246 /* VBE SR0A[4] CR16 */
6247 value = LVDSVBE - 1;
6248 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
6249 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
6250
6251 /* VRS SR0A[3] CR7[7][2] CR10 */
6252 value = LVDSVRS - 1;
6253 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
6254 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
6255 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
6256 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
6257
6258 if (chip_id == XG27) {
6259 /* Panel VRS SR35[2:0] SR34[7:0] */
6260 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
6261 (value & 0x700) >> 8);
6262 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
6263 } else {
6264 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
6265 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
6266 (value & 0x600) >> 9);
6267 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
6268 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
6269 }
6270
6271 /* VRE SR0A[5] CR11[3:0] */
6272 value = LVDSVRE - 1;
6273 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
6274 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
6275
6276 /* Panel VRE SR3F[7:2] */
6277 if (chip_id == XG27)
6278 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6279 (value << 2) & 0xFC);
6280 else
6281 /* SR3F[7] has to be 0, h/w bug */
6282 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6283 (value << 2) & 0x7C);
6284
6285 for (temp = 0, value = 0; temp < 3; temp++) {
6286
6287 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
6288 xgifb_reg_set(pVBInfo->P3c4,
6289 0x2B,
6290 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6291 VCLKData1);
6292 xgifb_reg_set(pVBInfo->P3c4,
6293 0x2C,
6294 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6295 VCLKData2);
6296 value += 0x10;
6297 }
6298
6299 if (!(modeflag & Charx8Dot)) {
6300 inb(pVBInfo->P3da); /* reset 3da */
6301 outb(0x13, pVBInfo->P3c0); /* set index */
6302 /* set data, panning = 0, shift left 1 dot*/
6303 outb(0x00, pVBInfo->P3c0);
6304
6305 inb(pVBInfo->P3da); /* Enable Attribute */
6306 outb(0x20, pVBInfo->P3c0);
6307
6308 inb(pVBInfo->P3da); /* reset 3da */
6309 }
6310
6311 }
6312
6313 /* --------------------------------------------------------------------- */
6314 /* Function : XGI_IsLCDON */
6315 /* Input : */
6316 /* Output : 0 : Skip PSC Control */
6317 /* 1: Disable PSC */
6318 /* Description : */
6319 /* --------------------------------------------------------------------- */
6320 static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
6321 {
6322 unsigned short tempax;
6323
6324 tempax = pVBInfo->VBInfo;
6325 if (tempax & SetCRT2ToDualEdge)
6326 return 0;
6327 else if (tempax & (DisableCRT2Display | SwitchToCRT2 | SetSimuScanMode))
6328 return 1;
6329
6330 return 0;
6331 }
6332
6333 /* --------------------------------------------------------------------- */
6334 /* Function : XGI_DisableChISLCD */
6335 /* Input : */
6336 /* Output : 0 -> Not LCD Mode */
6337 /* Description : */
6338 /* --------------------------------------------------------------------- */
6339 static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
6340 {
6341 unsigned short tempbx, tempah;
6342
6343 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
6344 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
6345
6346 if (tempbx & (EnableChA | DisableChA)) {
6347 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6348 return 0;
6349 }
6350
6351 if (!(tempbx & (EnableChB | DisableChB)))
6352 return 0;
6353
6354 if (tempah & 0x01) /* Chk LCDB Mode */
6355 return 1;
6356
6357 return 0;
6358 }
6359
6360 /* --------------------------------------------------------------------- */
6361 /* Function : XGI_EnableChISLCD */
6362 /* Input : */
6363 /* Output : 0 -> Not LCD mode */
6364 /* Description : */
6365 /* --------------------------------------------------------------------- */
6366 static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
6367 {
6368 unsigned short tempbx, tempah;
6369
6370 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
6371 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
6372
6373 if (tempbx & (EnableChA | DisableChA)) {
6374 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6375 return 0;
6376 }
6377
6378 if (!(tempbx & (EnableChB | DisableChB)))
6379 return 0;
6380
6381 if (tempah & 0x01) /* Chk LCDB Mode */
6382 return 1;
6383
6384 return 0;
6385 }
6386
6387 static void XGI_DisableBridge(struct xgi_hw_device_info *HwDeviceExtension,
6388 struct vb_device_info *pVBInfo)
6389 {
6390 unsigned short tempah = 0;
6391
6392 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6393 | VB_XGI302LV | VB_XGI301C)) {
6394 tempah = 0x3F;
6395 if (!(pVBInfo->VBInfo &
6396 (DisableCRT2Display | SetSimuScanMode))) {
6397 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6398 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6399 tempah = 0x7F; /* Disable Channel A */
6400 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6401 /* Disable Channel B */
6402 tempah = 0xBF;
6403
6404 if (pVBInfo->SetFlag & DisableChB)
6405 /* force to disable Cahnnel */
6406 tempah &= 0xBF;
6407
6408 if (pVBInfo->SetFlag & DisableChA)
6409 /* Force to disable Channel B */
6410 tempah &= 0x7F;
6411 }
6412 }
6413 }
6414
6415 /* disable part4_1f */
6416 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
6417
6418 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6419 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
6420 || (XGI_DisableChISLCD(pVBInfo))
6421 || (XGI_IsLCDON(pVBInfo)))
6422 /* LVDS Driver power down */
6423 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
6424 }
6425
6426 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6427 & (DisableCRT2Display | SetCRT2ToLCDA
6428 | SetSimuScanMode))) {
6429 if (pVBInfo->SetFlag & GatingCRT)
6430 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
6431 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6432 }
6433
6434 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6435 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6436 & SetCRT2ToLCDA))
6437 /* Power down */
6438 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
6439 }
6440
6441 /* disable TV as primary VGA swap */
6442 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
6443
6444 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
6445 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
6446
6447 if ((pVBInfo->SetFlag & DisableChB) ||
6448 (pVBInfo->VBInfo &
6449 (DisableCRT2Display | SetSimuScanMode)) ||
6450 ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) &&
6451 (pVBInfo->VBInfo &
6452 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
6453 /* BScreenOff=1 */
6454 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6455
6456 if ((pVBInfo->SetFlag & DisableChB) ||
6457 (pVBInfo->VBInfo &
6458 (DisableCRT2Display | SetSimuScanMode)) ||
6459 (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) ||
6460 (pVBInfo->VBInfo &
6461 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
6462 /* save Part1 index 0 */
6463 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6464 /* BTDAC = 1, avoid VB reset */
6465 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
6466 /* disable CRT2 */
6467 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6468 /* restore Part1 index 0 */
6469 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
6470 }
6471 } else { /* {301} */
6472 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
6473 /* BScreenOff=1 */
6474 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6475 /* Disable CRT2 */
6476 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6477 /* Disable TV asPrimary VGA swap */
6478 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
6479 }
6480
6481 if (pVBInfo->VBInfo & (DisableCRT2Display | SetCRT2ToLCDA
6482 | SetSimuScanMode))
6483 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6484 }
6485 }
6486
6487 /* --------------------------------------------------------------------- */
6488 /* Function : XGI_GetTVPtrIndex */
6489 /* Input : */
6490 /* Output : */
6491 /* Description : bx 0 : ExtNTSC */
6492 /* 1 : StNTSC */
6493 /* 2 : ExtPAL */
6494 /* 3 : StPAL */
6495 /* 4 : ExtHiTV */
6496 /* 5 : StHiTV */
6497 /* 6 : Ext525i */
6498 /* 7 : St525i */
6499 /* 8 : Ext525p */
6500 /* 9 : St525p */
6501 /* A : Ext750p */
6502 /* B : St750p */
6503 /* --------------------------------------------------------------------- */
6504 static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
6505 {
6506 unsigned short tempbx = 0;
6507
6508 if (pVBInfo->TVInfo & SetPALTV)
6509 tempbx = 2;
6510 if (pVBInfo->TVInfo & SetYPbPrMode1080i)
6511 tempbx = 4;
6512 if (pVBInfo->TVInfo & SetYPbPrMode525i)
6513 tempbx = 6;
6514 if (pVBInfo->TVInfo & SetYPbPrMode525p)
6515 tempbx = 8;
6516 if (pVBInfo->TVInfo & SetYPbPrMode750p)
6517 tempbx = 10;
6518 if (pVBInfo->TVInfo & TVSimuMode)
6519 tempbx++;
6520
6521 return tempbx;
6522 }
6523
6524 /* --------------------------------------------------------------------- */
6525 /* Function : XGI_GetTVPtrIndex2 */
6526 /* Input : */
6527 /* Output : bx 0 : NTSC */
6528 /* 1 : PAL */
6529 /* 2 : PALM */
6530 /* 3 : PALN */
6531 /* 4 : NTSC1024x768 */
6532 /* 5 : PAL-M 1024x768 */
6533 /* 6-7: reserved */
6534 /* cl 0 : YFilter1 */
6535 /* 1 : YFilter2 */
6536 /* ch 0 : 301A */
6537 /* 1 : 301B/302B/301LV/302LV */
6538 /* Description : */
6539 /* --------------------------------------------------------------------- */
6540 static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
6541 unsigned char *tempch, struct vb_device_info *pVBInfo)
6542 {
6543 *tempbx = 0;
6544 *tempcl = 0;
6545 *tempch = 0;
6546
6547 if (pVBInfo->TVInfo & SetPALTV)
6548 *tempbx = 1;
6549
6550 if (pVBInfo->TVInfo & SetPALMTV)
6551 *tempbx = 2;
6552
6553 if (pVBInfo->TVInfo & SetPALNTV)
6554 *tempbx = 3;
6555
6556 if (pVBInfo->TVInfo & NTSC1024x768) {
6557 *tempbx = 4;
6558 if (pVBInfo->TVInfo & SetPALMTV)
6559 *tempbx = 5;
6560 }
6561
6562 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6563 | VB_XGI302LV | VB_XGI301C)) {
6564 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
6565 & TVSimuMode)) {
6566 *tempbx += 8;
6567 *tempcl += 1;
6568 }
6569 }
6570
6571 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6572 | VB_XGI302LV | VB_XGI301C))
6573 (*tempch)++;
6574 }
6575
6576 static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
6577 {
6578 unsigned short index;
6579
6580 unsigned char tempah, tempbl, tempbh;
6581
6582 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6583 | VB_XGI302LV | VB_XGI301C)) {
6584 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA
6585 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
6586 tempbl = 0;
6587 tempbh = 0;
6588
6589 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
6590 tempbl = pVBInfo->XGI_TVDelayList[index];
6591
6592 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
6593 | VB_XGI301LV | VB_XGI302LV
6594 | VB_XGI301C))
6595 tempbl = pVBInfo->XGI_TVDelayList2[index];
6596
6597 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6598 tempbl = tempbl >> 4;
6599 /*
6600 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
6601 tempbl = CRT2Delay1; // Get CRT2 Delay
6602 if (pVBInfo->VBType &
6603 (VB_XGI301B |
6604 VB_XGI302B |
6605 VB_XGI301LV |
6606 VB_XGI302LV |
6607 VB_XGI301C))
6608 tempbl = CRT2Delay2;
6609 */
6610 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
6611 /* Get LCD Delay */
6612 index = XGI_GetLCDCapPtr(pVBInfo);
6613 tempbh = pVBInfo->LCDCapList[index].
6614 LCD_DelayCompensation;
6615
6616 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6617 tempbl = tempbh;
6618 }
6619
6620 tempbl &= 0x0F;
6621 tempbh &= 0xF0;
6622 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
6623
6624 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
6625 | SetCRT2ToTV)) { /* Channel B */
6626 tempah &= 0xF0;
6627 tempah |= tempbl;
6628 }
6629
6630 if (pVBInfo->VBInfo & SetCRT2ToLCDA) { /* Channel A */
6631 tempah &= 0x0F;
6632 tempah |= tempbh;
6633 }
6634 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
6635 }
6636 } else if (pVBInfo->IF_DEF_LVDS == 1) {
6637 tempbl = 0;
6638 tempbh = 0;
6639 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
6640 /* / Get LCD Delay */
6641 tempah = pVBInfo->LCDCapList[
6642 XGI_GetLCDCapPtr(pVBInfo)].
6643 LCD_DelayCompensation;
6644 tempah &= 0x0f;
6645 tempah = tempah << 4;
6646 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
6647 tempah);
6648 }
6649 }
6650 }
6651
6652 static void XGI_SetLCDCap_A(unsigned short tempcx,
6653 struct vb_device_info *pVBInfo)
6654 {
6655 unsigned short temp;
6656
6657 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
6658
6659 if (temp & LCDRGB18Bit) {
6660 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
6661 /* Enable Dither */
6662 (unsigned short) (0x20 | (tempcx & 0x00C0)));
6663 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
6664 } else {
6665 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
6666 (unsigned short) (0x30 | (tempcx & 0x00C0)));
6667 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
6668 }
6669
6670 /*
6671 if (tempcx & EnableLCD24bpp) { // 24bits
6672 xgifb_reg_and_or(pVBInfo->Part1Port,
6673 0x19,
6674 0x0F,
6675 (unsigned short)(0x30 | (tempcx&0x00C0)));
6676 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
6677 } else {
6678 xgifb_reg_and_or(pVBInfo->Part1Port,
6679 0x19,
6680 0x0F,
6681 // Enable Dither
6682 (unsigned short)(0x20 | (tempcx&0x00C0)));
6683 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
6684 }
6685 */
6686 }
6687
6688 /* --------------------------------------------------------------------- */
6689 /* Function : XGI_SetLCDCap_B */
6690 /* Input : cx -> LCD Capability */
6691 /* Output : */
6692 /* Description : */
6693 /* --------------------------------------------------------------------- */
6694 static void XGI_SetLCDCap_B(unsigned short tempcx,
6695 struct vb_device_info *pVBInfo)
6696 {
6697 if (tempcx & EnableLCD24bpp) /* 24bits */
6698 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
6699 (unsigned short) (((tempcx & 0x00ff) >> 6)
6700 | 0x0c));
6701 else
6702 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
6703 (unsigned short) (((tempcx & 0x00ff) >> 6)
6704 | 0x18)); /* Enable Dither */
6705 }
6706
6707 static void XGI_LongWait(struct vb_device_info *pVBInfo)
6708 {
6709 unsigned short i;
6710
6711 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
6712
6713 if (!(i & 0xC0)) {
6714 for (i = 0; i < 0xFFFF; i++) {
6715 if (!(inb(pVBInfo->P3da) & 0x08))
6716 break;
6717 }
6718
6719 for (i = 0; i < 0xFFFF; i++) {
6720 if ((inb(pVBInfo->P3da) & 0x08))
6721 break;
6722 }
6723 }
6724 }
6725
6726 static void SetSpectrum(struct vb_device_info *pVBInfo)
6727 {
6728 unsigned short index;
6729
6730 index = XGI_GetLCDCapPtr(pVBInfo);
6731
6732 /* disable down spectrum D[4] */
6733 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
6734 XGI_LongWait(pVBInfo);
6735 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
6736 XGI_LongWait(pVBInfo);
6737
6738 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
6739 pVBInfo->LCDCapList[index].Spectrum_31);
6740 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
6741 pVBInfo->LCDCapList[index].Spectrum_32);
6742 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
6743 pVBInfo->LCDCapList[index].Spectrum_33);
6744 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
6745 pVBInfo->LCDCapList[index].Spectrum_34);
6746 XGI_LongWait(pVBInfo);
6747 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
6748 }
6749
6750 static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
6751 {
6752 unsigned short tempcx;
6753
6754 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
6755
6756 if (pVBInfo->VBType &
6757 (VB_XGI301B |
6758 VB_XGI302B |
6759 VB_XGI301LV |
6760 VB_XGI302LV |
6761 VB_XGI301C)) { /* 301LV/302LV only */
6762 if (pVBInfo->VBType &
6763 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
6764 /* Set 301LV Capability */
6765 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
6766 (unsigned char) (tempcx & 0x1F));
6767 }
6768 /* VB Driving */
6769 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
6770 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
6771 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
6772 | EnablePLLSPLOW)) >> 8));
6773 }
6774
6775 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6776 | VB_XGI302LV | VB_XGI301C)) {
6777 if (pVBInfo->VBInfo & SetCRT2ToLCD)
6778 XGI_SetLCDCap_B(tempcx, pVBInfo);
6779 else if (pVBInfo->VBInfo & SetCRT2ToLCDA)
6780 XGI_SetLCDCap_A(tempcx, pVBInfo);
6781
6782 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6783 if (tempcx & EnableSpectrum)
6784 SetSpectrum(pVBInfo);
6785 }
6786 } else {
6787 /* LVDS,CH7017 */
6788 XGI_SetLCDCap_A(tempcx, pVBInfo);
6789 }
6790 }
6791
6792 /* --------------------------------------------------------------------- */
6793 /* Function : XGI_SetAntiFlicker */
6794 /* Input : */
6795 /* Output : */
6796 /* Description : Set TV Customized Param. */
6797 /* --------------------------------------------------------------------- */
6798 static void XGI_SetAntiFlicker(unsigned short ModeNo,
6799 unsigned short ModeIdIndex,
6800 struct vb_device_info *pVBInfo)
6801 {
6802 unsigned short tempbx, index;
6803
6804 unsigned char tempah;
6805
6806 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
6807 return;
6808
6809 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6810 tempbx &= 0xFE;
6811
6812 if (ModeNo <= 0x13)
6813 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
6814 else
6815 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
6816
6817 tempbx += index;
6818 tempah = TVAntiFlickList[tempbx];
6819 tempah = tempah << 4;
6820
6821 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
6822 }
6823
6824 static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6825 unsigned short ModeIdIndex,
6826 struct vb_device_info *pVBInfo)
6827 {
6828 unsigned short tempbx, index;
6829
6830 unsigned char tempah;
6831
6832 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6833 tempbx &= 0xFE;
6834
6835 if (ModeNo <= 0x13)
6836 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
6837 else
6838 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
6839
6840 tempbx += index;
6841 tempah = TVEdgeList[tempbx];
6842 tempah = tempah << 5;
6843
6844 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
6845 }
6846
6847 static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
6848 {
6849 unsigned short tempbx;
6850
6851 unsigned char tempcl, tempch;
6852
6853 unsigned long tempData;
6854
6855 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6856 tempData = TVPhaseList[tempbx];
6857
6858 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
6859 & 0x000000FF));
6860 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
6861 & 0x0000FF00) >> 8));
6862 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
6863 & 0x00FF0000) >> 16));
6864 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
6865 & 0xFF000000) >> 24));
6866 }
6867
6868 static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
6869 struct vb_device_info *pVBInfo)
6870 {
6871 unsigned short tempbx, index;
6872
6873 unsigned char tempcl, tempch, tempal, *filterPtr;
6874
6875 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6876
6877 switch (tempbx) {
6878 case 0x00:
6879 case 0x04:
6880 filterPtr = NTSCYFilter1;
6881 break;
6882
6883 case 0x01:
6884 filterPtr = PALYFilter1;
6885 break;
6886
6887 case 0x02:
6888 case 0x05:
6889 case 0x0D:
6890 case 0x03:
6891 filterPtr = xgifb_palmn_yfilter1;
6892 break;
6893
6894 case 0x08:
6895 case 0x0C:
6896 case 0x0A:
6897 case 0x0B:
6898 case 0x09:
6899 filterPtr = xgifb_yfilter2;
6900 break;
6901
6902 default:
6903 return;
6904 }
6905
6906 if (ModeNo <= 0x13)
6907 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
6908 VB_StTVYFilterIndex;
6909 else
6910 tempal = pVBInfo->EModeIDTable[ModeIdIndex].
6911 VB_ExtTVYFilterIndex;
6912
6913 if (tempcl == 0)
6914 index = tempal * 4;
6915 else
6916 index = tempal * 7;
6917
6918 if ((tempcl == 0) && (tempch == 1)) {
6919 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
6920 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
6921 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
6922 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
6923 } else {
6924 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
6925 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
6926 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
6927 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
6928 }
6929
6930 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6931 | VB_XGI302LV | VB_XGI301C)) {
6932 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
6933 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
6934 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
6935 }
6936 }
6937
6938 /* --------------------------------------------------------------------- */
6939 /* Function : XGI_OEM310Setting */
6940 /* Input : */
6941 /* Output : */
6942 /* Description : Customized Param. for 301 */
6943 /* --------------------------------------------------------------------- */
6944 static void XGI_OEM310Setting(unsigned short ModeNo,
6945 unsigned short ModeIdIndex,
6946 struct vb_device_info *pVBInfo)
6947 {
6948 /* GetPart1IO(); */
6949 XGI_SetDelayComp(pVBInfo);
6950
6951 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
6952 XGI_SetLCDCap(pVBInfo);
6953
6954 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6955 /* GetPart2IO() */
6956 XGI_SetPhaseIncr(pVBInfo);
6957 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
6958 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
6959
6960 if (pVBInfo->VBType & VB_XGI301)
6961 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
6962 }
6963 }
6964
6965 /* --------------------------------------------------------------------- */
6966 /* Function : XGI_SetCRT2ModeRegs */
6967 /* Input : */
6968 /* Output : */
6969 /* Description : Origin code for crt2group */
6970 /* --------------------------------------------------------------------- */
6971 static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
6972 struct xgi_hw_device_info *HwDeviceExtension,
6973 struct vb_device_info *pVBInfo)
6974 {
6975 unsigned short tempbl;
6976 short tempcl;
6977
6978 unsigned char tempah;
6979
6980 /* // fix write part1 index 0 BTDRAM bit Bug
6981 * xgifb_reg_set(pVBInfo->Part1Port, 0x03, 0x00); */
6982 tempah = 0;
6983 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6984 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6985 tempah &= ~0x10; /* BTRAMDAC */
6986 tempah |= 0x40; /* BTRAM */
6987
6988 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6989 | SetCRT2ToLCD)) {
6990 tempah = 0x40; /* BTDRAM */
6991 if (ModeNo > 0x13) {
6992 tempcl = pVBInfo->ModeType;
6993 tempcl -= ModeVGA;
6994 if (tempcl >= 0) {
6995 /* BT Color */
6996 tempah = (0x008 >> tempcl);
6997 if (tempah == 0)
6998 tempah = 1;
6999 tempah |= 0x040;
7000 }
7001 }
7002 if (pVBInfo->VBInfo & SetInSlaveMode)
7003 tempah ^= 0x50; /* BTDAC */
7004 }
7005 }
7006
7007 /* 0210 shampoo
7008 if (pVBInfo->VBInfo & DisableCRT2Display) {
7009 tempah = 0;
7010 }
7011
7012 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
7013 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)) {
7014 tempcl = pVBInfo->ModeType;
7015 if (ModeNo > 0x13) {
7016 tempcl -= ModeVGA;
7017 if ((tempcl > 0) || (tempcl == 0)) {
7018 tempah=(0x008>>tempcl) ;
7019 if (tempah == 0)
7020 tempah = 1;
7021 tempah |= 0x040;
7022 }
7023 } else {
7024 tempah = 0x040;
7025 }
7026
7027 if (pVBInfo->VBInfo & SetInSlaveMode) {
7028 tempah = (tempah ^ 0x050);
7029 }
7030 }
7031 */
7032
7033 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
7034 tempah = 0x08;
7035 tempbl = 0xf0;
7036
7037 if (pVBInfo->VBInfo & DisableCRT2Display) {
7038 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
7039 } else {
7040 tempah = 0x00;
7041 tempbl = 0xff;
7042
7043 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7044 | SetCRT2ToLCD | SetCRT2ToLCDA)) {
7045 if ((pVBInfo->VBInfo & SetCRT2ToLCDA) &&
7046 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
7047 tempbl &= 0xf7;
7048 tempah |= 0x01;
7049 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
7050 tempbl, tempah);
7051 } else {
7052 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7053 tempbl &= 0xf7;
7054 tempah |= 0x01;
7055 }
7056
7057 if (pVBInfo->VBInfo &
7058 (SetCRT2ToRAMDAC |
7059 SetCRT2ToTV |
7060 SetCRT2ToLCD)) {
7061 tempbl &= 0xf8;
7062 tempah = 0x01;
7063
7064 if (!(pVBInfo->VBInfo & SetInSlaveMode))
7065 tempah |= 0x02;
7066
7067 if (!(pVBInfo->VBInfo &
7068 SetCRT2ToRAMDAC)) {
7069 tempah = tempah ^ 0x05;
7070 if (!(pVBInfo->VBInfo &
7071 SetCRT2ToLCD))
7072 tempah = tempah ^ 0x01;
7073 }
7074
7075 if (!(pVBInfo->VBInfo &
7076 SetCRT2ToDualEdge))
7077 tempah |= 0x08;
7078 xgifb_reg_and_or(pVBInfo->Part1Port,
7079 0x2e, tempbl, tempah);
7080 } else {
7081 xgifb_reg_and_or(pVBInfo->Part1Port,
7082 0x2e, tempbl, tempah);
7083 }
7084 }
7085 } else {
7086 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
7087 tempah);
7088 }
7089 }
7090
7091 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
7092 | SetCRT2ToLCDA)) {
7093 tempah &= (~0x08);
7094 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
7095 & SetInSlaveMode))) {
7096 tempah |= 0x010;
7097 }
7098 tempah |= 0x080;
7099
7100 if (pVBInfo->VBInfo & SetCRT2ToTV) {
7101 /* if (!(pVBInfo->TVInfo &
7102 (SetYPbPrMode525p | SetYPbPrMode750p))) { */
7103 tempah |= 0x020;
7104 if (ModeNo > 0x13) {
7105 if (pVBInfo->VBInfo & DriverMode)
7106 tempah = tempah ^ 0x20;
7107 }
7108 /* } */
7109 }
7110
7111 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
7112 tempah = 0;
7113
7114 if (pVBInfo->LCDInfo & SetLCDDualLink)
7115 tempah |= 0x40;
7116
7117 if (pVBInfo->VBInfo & SetCRT2ToTV) {
7118 /* if ((!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) &&
7119 (!(pVBInfo->TVInfo &
7120 (SetYPbPrMode525p | SetYPbPrMode750p)))) { */
7121 if (pVBInfo->TVInfo & RPLLDIV2XO)
7122 tempah |= 0x40;
7123 /* } */
7124 }
7125
7126 if ((pVBInfo->LCDResInfo == Panel1280x1024)
7127 || (pVBInfo->LCDResInfo == Panel1280x1024x75))
7128 tempah |= 0x80;
7129
7130 if (pVBInfo->LCDResInfo == Panel1280x960)
7131 tempah |= 0x80;
7132
7133 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
7134 }
7135
7136 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7137 | VB_XGI302LV | VB_XGI301C)) {
7138 tempah = 0;
7139 tempbl = 0xfb;
7140
7141 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7142 tempbl = 0xff;
7143 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7144 tempah |= 0x04; /* shampoo 0129 */
7145 }
7146
7147 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
7148 tempah = 0x00;
7149 tempbl = 0xcf;
7150 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7151 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7152 tempah |= 0x30;
7153 }
7154
7155 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
7156 tempah = 0;
7157 tempbl = 0x3f;
7158
7159 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7160 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7161 tempah |= 0xc0;
7162 }
7163 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
7164 }
7165
7166 tempah = 0;
7167 tempbl = 0x7f;
7168 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) {
7169 tempbl = 0xff;
7170 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
7171 tempah |= 0x80;
7172 }
7173
7174 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
7175
7176 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7177 if (pVBInfo->LCDInfo & SetLCDDualLink) {
7178 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
7179 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
7180 }
7181 }
7182 }
7183
7184 static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
7185 struct vb_device_info *pVBInfo)
7186 {
7187 unsigned short tempbx;
7188
7189 tempbx = 0;
7190
7191 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7192 tempbx = 0x08A0;
7193
7194 }
7195
7196 void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7197 struct vb_device_info *pVBInfo)
7198 {
7199
7200 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
7201
7202 }
7203
7204 void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7205 struct vb_device_info *pVBInfo)
7206 {
7207
7208 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
7209
7210 }
7211
7212 unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
7213 {
7214 unsigned short flag;
7215
7216 if (pVBInfo->IF_DEF_LVDS == 1) {
7217 return 1;
7218 } else {
7219 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
7220 if ((flag == 1) || (flag == 2))
7221 return 1; /* 301b */
7222 else
7223 return 0;
7224 }
7225 }
7226
7227 static void XGI_VBLongWait(struct vb_device_info *pVBInfo)
7228 {
7229 unsigned short tempal, temp, i, j;
7230 return;
7231 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
7232 temp = 0;
7233 for (i = 0; i < 3; i++) {
7234 for (j = 0; j < 100; j++) {
7235 tempal = inb(pVBInfo->P3da);
7236 if (temp & 0x01) { /* VBWaitMode2 */
7237 if ((tempal & 0x08))
7238 continue;
7239
7240 if (!(tempal & 0x08))
7241 break;
7242
7243 } else { /* VBWaitMode1 */
7244 if (!(tempal & 0x08))
7245 continue;
7246
7247 if ((tempal & 0x08))
7248 break;
7249 }
7250 }
7251 temp = temp ^ 0x01;
7252 }
7253 } else {
7254 XGI_LongWait(pVBInfo);
7255 }
7256 return;
7257 }
7258
7259 unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
7260 unsigned short ModeNo, unsigned short ModeIdIndex,
7261 struct vb_device_info *pVBInfo)
7262 {
7263 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
7264 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
7265 0x01, 0x01 };
7266
7267 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
7268
7269 if (ModeNo <= 0x13)
7270 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7271 else
7272 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7273
7274 if (ModeNo < 0x14)
7275 return 0xFFFF;
7276
7277 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
7278 index = index >> pVBInfo->SelectCRT2Rate;
7279 index &= 0x0F;
7280
7281 if (pVBInfo->LCDInfo & LCDNonExpanding)
7282 index = 0;
7283
7284 if (index > 0)
7285 index--;
7286
7287 if (pVBInfo->SetFlag & ProgrammingCRT2) {
7288 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
7289 if (pVBInfo->IF_DEF_LVDS == 0) {
7290 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
7291 | VB_XGI301LV | VB_XGI302LV
7292 | VB_XGI301C))
7293 /* 301b */
7294 temp = LCDARefreshIndex[
7295 pVBInfo->LCDResInfo & 0x0F];
7296 else
7297 temp = LCDRefreshIndex[
7298 pVBInfo->LCDResInfo & 0x0F];
7299
7300 if (index > temp)
7301 index = temp;
7302 } else {
7303 index = 0;
7304 }
7305 }
7306 }
7307
7308 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
7309 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
7310 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
7311 /*
7312 if (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag &
7313 XG2xNotSupport) {
7314 index++;
7315 }
7316 */
7317 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
7318 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
7319 index++;
7320 }
7321 /* Alan 10/19/2007;
7322 * do the similar adjustment like XGISearchCRT1Rate() */
7323 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
7324 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
7325 index++;
7326 }
7327 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
7328 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
7329 index++;
7330 }
7331 }
7332
7333 i = 0;
7334 do {
7335 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
7336 ModeID != ModeNo)
7337 break;
7338 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
7339 Ext_InfoFlag;
7340 temp &= ModeInfoFlag;
7341 if (temp < pVBInfo->ModeType)
7342 break;
7343 i++;
7344 index--;
7345
7346 } while (index != 0xFFFF);
7347 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
7348 if (pVBInfo->VBInfo & SetInSlaveMode) {
7349 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
7350 Ext_InfoFlag;
7351 if (temp & InterlaceMode)
7352 i++;
7353 }
7354 }
7355 i--;
7356 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
7357 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
7358 RefreshRateTableIndex, &i, pVBInfo);
7359 }
7360 return RefreshRateTableIndex + i; /* return (0x01 | (temp1<<1)); */
7361 }
7362
7363 static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
7364 struct xgi_hw_device_info *HwDeviceExtension,
7365 struct vb_device_info *pVBInfo)
7366 {
7367 unsigned short RefreshRateTableIndex;
7368 /* unsigned short temp ; */
7369
7370 /* pVBInfo->SelectCRT2Rate = 0; */
7371
7372 pVBInfo->SetFlag |= ProgrammingCRT2;
7373 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7374 ModeIdIndex, pVBInfo);
7375 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
7376 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7377 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7378 HwDeviceExtension, pVBInfo);
7379 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7380 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7381 }
7382
7383 static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
7384 struct xgi_hw_device_info *HwDeviceExtension,
7385 struct vb_device_info *pVBInfo)
7386 {
7387 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
7388
7389 tempbx = pVBInfo->VBInfo;
7390 pVBInfo->SetFlag |= ProgrammingCRT2;
7391 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7392 pVBInfo->SelectCRT2Rate = 4;
7393 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7394 ModeIdIndex, pVBInfo);
7395 XGI_SaveCRT2Info(ModeNo, pVBInfo);
7396 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
7397 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7398 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7399 RefreshRateTableIndex, pVBInfo);
7400 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7401 RefreshRateTableIndex, pVBInfo);
7402 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7403 RefreshRateTableIndex, pVBInfo);
7404 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7405 HwDeviceExtension, pVBInfo);
7406 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7407 RefreshRateTableIndex, pVBInfo);
7408 XGI_SetTap4Regs(pVBInfo);
7409 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
7410 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7411 HwDeviceExtension, pVBInfo);
7412 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7413 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
7414 XGI_AutoThreshold(pVBInfo);
7415 return 1;
7416 }
7417
7418 void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
7419 {
7420 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
7421 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
7422 0x05, 0x00 };
7423
7424 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
7425
7426 unsigned char CR17, CR63, SR31;
7427 unsigned short temp;
7428 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
7429
7430 int i;
7431 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
7432
7433 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
7434 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
7435 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
7436 pVBInfo->P3d4, 0x53) | 0x02));
7437
7438 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
7439 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
7440 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
7441
7442 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
7443 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
7444
7445 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
7446 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
7447
7448 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
7449 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
7450
7451 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
7452 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
7453 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
7454 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
7455
7456 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
7457
7458 for (i = 0; i < 8; i++)
7459 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
7460
7461 for (i = 8; i < 11; i++)
7462 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
7463 CRTCData[i]);
7464
7465 for (i = 11; i < 13; i++)
7466 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
7467 CRTCData[i]);
7468
7469 for (i = 13; i < 16; i++)
7470 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
7471 CRTCData[i]);
7472
7473 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
7474 & 0xE0));
7475
7476 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
7477 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7478 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
7479
7480 outb(0x00, pVBInfo->P3c8);
7481
7482 for (i = 0; i < 256; i++) {
7483 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
7484 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
7485 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
7486 }
7487
7488 XGI_VBLongWait(pVBInfo);
7489 XGI_VBLongWait(pVBInfo);
7490 XGI_VBLongWait(pVBInfo);
7491
7492 mdelay(1);
7493
7494 XGI_WaitDisply(pVBInfo);
7495 temp = inb(pVBInfo->P3c2);
7496
7497 if (temp & 0x10)
7498 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
7499 else
7500 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
7501
7502 /* alan, avoid display something, set BLACK DAC if not restore DAC */
7503 outb(0x00, pVBInfo->P3c8);
7504
7505 for (i = 0; i < 256; i++) {
7506 outb(0, (pVBInfo->P3c8 + 1));
7507 outb(0, (pVBInfo->P3c8 + 1));
7508 outb(0, (pVBInfo->P3c8 + 1));
7509 }
7510
7511 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
7512 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
7513 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
7514
7515 /* [2004/05/11] Vicent */
7516 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
7517 pVBInfo->P3d4, 0x53) & 0xFD));
7518 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
7519 }
7520
7521 static void XGI_EnableBridge(struct xgi_hw_device_info *HwDeviceExtension,
7522 struct vb_device_info *pVBInfo)
7523 {
7524 unsigned short tempah;
7525
7526 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7527 | VB_XGI302LV | VB_XGI301C)) {
7528 if (!(pVBInfo->SetFlag & DisableChA)) {
7529 if (pVBInfo->SetFlag & EnableChA) {
7530 /* Power on */
7531 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
7532 } else {
7533 /* SetCRT2ToLCDA ) */
7534 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7535 /* Power on */
7536 xgifb_reg_set(pVBInfo->Part1Port,
7537 0x1E, 0x20);
7538 }
7539 }
7540 }
7541
7542 if (!(pVBInfo->SetFlag & DisableChB)) {
7543 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
7544 & (SetCRT2ToLCD | SetCRT2ToTV
7545 | SetCRT2ToRAMDAC))) {
7546 tempah = (unsigned char) xgifb_reg_get(
7547 pVBInfo->P3c4, 0x32);
7548 tempah &= 0xDF;
7549 if (pVBInfo->VBInfo & SetInSlaveMode) {
7550 if (!(pVBInfo->VBInfo &
7551 SetCRT2ToRAMDAC))
7552 tempah |= 0x20;
7553 }
7554 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
7555 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
7556
7557 tempah = (unsigned char) xgifb_reg_get(
7558 pVBInfo->Part1Port, 0x2E);
7559
7560 if (!(tempah & 0x80))
7561 /* BVBDOENABLE = 1 */
7562 xgifb_reg_or(pVBInfo->Part1Port,
7563 0x2E, 0x80);
7564 /* BScreenOFF = 0 */
7565 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
7566 }
7567 }
7568
7569 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
7570 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
7571 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
7572 0x20); /* shampoo 0129 */
7573 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7574 if (!XGI_DisableChISLCD(pVBInfo)) {
7575 if (XGI_EnableChISLCD(pVBInfo) ||
7576 (pVBInfo->VBInfo &
7577 (SetCRT2ToLCD | SetCRT2ToLCDA)))
7578 /* LVDS PLL power on */
7579 xgifb_reg_and(
7580 pVBInfo->Part4Port,
7581 0x2A,
7582 0x7F);
7583 }
7584 /* LVDS Driver power on */
7585 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
7586 }
7587 }
7588
7589 tempah = 0x00;
7590
7591 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7592 tempah = 0xc0;
7593
7594 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
7595 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7596 if (pVBInfo->VBInfo &
7597 SetCRT2ToDualEdge) {
7598 tempah = tempah & 0x40;
7599 if (pVBInfo->VBInfo &
7600 SetCRT2ToLCDA)
7601 tempah = tempah ^ 0xC0;
7602
7603 if (pVBInfo->SetFlag &
7604 DisableChB)
7605 tempah &= 0xBF;
7606
7607 if (pVBInfo->SetFlag &
7608 DisableChA)
7609 tempah &= 0x7F;
7610
7611 if (pVBInfo->SetFlag &
7612 EnableChB)
7613 tempah |= 0x40;
7614
7615 if (pVBInfo->SetFlag &
7616 EnableChA)
7617 tempah |= 0x80;
7618 }
7619 }
7620 }
7621 }
7622
7623 /* EnablePart4_1F */
7624 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
7625
7626 if (!(pVBInfo->SetFlag & DisableChA)) {
7627 XGI_VBLongWait(pVBInfo);
7628 if (!(pVBInfo->SetFlag & GatingCRT)) {
7629 XGI_DisableGatingCRT(HwDeviceExtension,
7630 pVBInfo);
7631 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7632 XGI_VBLongWait(pVBInfo);
7633 }
7634 }
7635 } /* 301 */
7636 else { /* LVDS */
7637 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
7638 | SetCRT2ToLCDA))
7639 /* enable CRT2 */
7640 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
7641
7642 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
7643 0x2E);
7644 if (!(tempah & 0x80))
7645 /* BVBDOENABLE = 1 */
7646 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
7647
7648 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
7649 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7650 } /* End of VB */
7651 }
7652
7653 static void XGI_SetCRT1Group(struct xgi_hw_device_info *HwDeviceExtension,
7654 unsigned short ModeNo, unsigned short ModeIdIndex,
7655 struct vb_device_info *pVBInfo)
7656 {
7657 unsigned short StandTableIndex, RefreshRateTableIndex, b3CC, temp;
7658
7659 unsigned short XGINew_P3cc = pVBInfo->P3cc;
7660
7661 /* XGINew_CRT1Mode = ModeNo; // SaveModeID */
7662 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
7663 /* XGI_SetBIOSData(ModeNo, ModeIdIndex); */
7664 /* XGI_ClearBankRegs(ModeNo, ModeIdIndex); */
7665 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7666 XGI_SetMiscRegs(StandTableIndex, pVBInfo);
7667 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
7668 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7669 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
7670 XGI_ClearExt1Regs(pVBInfo);
7671
7672 /* if (pVBInfo->IF_DEF_ExpLink) */
7673 if (HwDeviceExtension->jChipType == XG27) {
7674 if (pVBInfo->IF_DEF_LVDS == 0)
7675 XGI_SetDefaultVCLK(pVBInfo);
7676 }
7677
7678 temp = ~ProgrammingCRT2;
7679 pVBInfo->SetFlag &= temp;
7680 pVBInfo->SelectCRT2Rate = 0;
7681
7682 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7683 | VB_XGI302LV | VB_XGI301C)) {
7684 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA
7685 | SetInSlaveMode)) {
7686 pVBInfo->SetFlag |= ProgrammingCRT2;
7687 }
7688 }
7689
7690 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7691 ModeIdIndex, pVBInfo);
7692 if (RefreshRateTableIndex != 0xFFFF) {
7693 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
7694 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7695 pVBInfo, HwDeviceExtension);
7696 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
7697 RefreshRateTableIndex, pVBInfo);
7698 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7699 HwDeviceExtension, pVBInfo);
7700 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
7701 RefreshRateTableIndex, pVBInfo);
7702 }
7703
7704 if ((HwDeviceExtension->jChipType >= XG20) &&
7705 (HwDeviceExtension->jChipType < XG27)) { /* fix H/W DCLK/2 bug */
7706 if ((ModeNo == 0x00) | (ModeNo == 0x01)) {
7707 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x4E);
7708 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE9);
7709 b3CC = (unsigned char) inb(XGINew_P3cc);
7710 outb((b3CC |= 0x0C), XGINew_P3cc);
7711 } else if ((ModeNo == 0x04) | (ModeNo == 0x05) | (ModeNo
7712 == 0x0D)) {
7713 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7714 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE3);
7715 b3CC = (unsigned char) inb(XGINew_P3cc);
7716 outb((b3CC |= 0x0C), XGINew_P3cc);
7717 }
7718 }
7719
7720 if (HwDeviceExtension->jChipType >= XG21) {
7721 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
7722 if (temp & 0xA0) {
7723
7724 /* Enable write GPIOF */
7725 /* xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x20); */
7726 /* P. DWN */
7727 /* xgifb_reg_and(pVBInfo->P3d4, 0x48, ~0x20); */
7728 /* XG21 CRT1 Timing */
7729 if (HwDeviceExtension->jChipType == XG27)
7730 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
7731 RefreshRateTableIndex, pVBInfo);
7732 else
7733 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
7734 RefreshRateTableIndex, pVBInfo);
7735
7736 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
7737 RefreshRateTableIndex);
7738
7739 xgifb_set_lcd(HwDeviceExtension->jChipType,
7740 pVBInfo, RefreshRateTableIndex, ModeNo);
7741
7742 if (pVBInfo->IF_DEF_LVDS == 1)
7743 xgifb_set_lvds(HwDeviceExtension->jChipType,
7744 ModeNo, ModeIdIndex, pVBInfo);
7745 /* P. ON */
7746 /* xgifb_reg_or(pVBInfo->P3d4, 0x48, 0x20); */
7747 }
7748 }
7749
7750 pVBInfo->SetFlag &= (~ProgrammingCRT2);
7751 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
7752 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
7753 RefreshRateTableIndex, pVBInfo);
7754
7755 /* XGI_LoadCharacter(); //dif ifdef TVFont */
7756
7757 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
7758 /* XGI_ClearBuffer(HwDeviceExtension, ModeNo, pVBInfo); */
7759 }
7760
7761 unsigned char XGISetModeNew(struct xgi_hw_device_info *HwDeviceExtension,
7762 unsigned short ModeNo)
7763 {
7764 unsigned short ModeIdIndex;
7765 /* unsigned char *pVBInfo->FBAddr =
7766 HwDeviceExtension->pjVideoMemoryAddress; */
7767 struct vb_device_info VBINF;
7768 struct vb_device_info *pVBInfo = &VBINF;
7769 pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase;
7770 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;
7771 pVBInfo->IF_DEF_LVDS = 0;
7772 pVBInfo->IF_DEF_LCDA = 1;
7773
7774 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
7775 pVBInfo->IF_DEF_YPbPr = 0;
7776 pVBInfo->IF_DEF_HiVision = 0;
7777 pVBInfo->IF_DEF_CRT2Monitor = 0;
7778 pVBInfo->VBType = 0; /*set VBType default 0*/
7779 } else {
7780 pVBInfo->IF_DEF_YPbPr = 1;
7781 pVBInfo->IF_DEF_HiVision = 1;
7782 pVBInfo->IF_DEF_CRT2Monitor = 1;
7783 }
7784
7785 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
7786 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
7787 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
7788 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
7789 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
7790 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
7791 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
7792 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
7793 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
7794 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
7795 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
7796 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
7797 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
7798 pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04;
7799 pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10;
7800 pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12;
7801 pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14;
7802 pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2;
7803
7804 /* for x86 Linux, XG21 LVDS */
7805 if (HwDeviceExtension->jChipType == XG21) {
7806 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
7807 pVBInfo->IF_DEF_LVDS = 1;
7808 }
7809 if (HwDeviceExtension->jChipType == XG27) {
7810 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
7811 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
7812 pVBInfo->IF_DEF_LVDS = 1;
7813 }
7814 }
7815
7816 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
7817 XGI_GetVBType(pVBInfo);
7818
7819 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
7820 if (ModeNo & 0x80) {
7821 ModeNo = ModeNo & 0x7F;
7822 /* XGINew_flag_clearbuffer = 0; */
7823 }
7824 /* else {
7825 XGINew_flag_clearbuffer = 1;
7826 }
7827 */
7828 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
7829
7830 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
7831 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
7832
7833 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7834
7835 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7836 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
7837 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
7838 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
7839 XGI_DisableBridge(HwDeviceExtension, pVBInfo);
7840
7841 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) {
7842 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7843 ModeIdIndex, pVBInfo);
7844
7845 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7846 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7847 HwDeviceExtension, pVBInfo);
7848 }
7849 } else {
7850 if (!(pVBInfo->VBInfo & SwitchToCRT2)) {
7851 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7852 ModeIdIndex, pVBInfo);
7853 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7854 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7855 HwDeviceExtension,
7856 pVBInfo);
7857 }
7858 }
7859 }
7860
7861 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchToCRT2)) {
7862 switch (HwDeviceExtension->ujVBChipID) {
7863 case VB_CHIP_301:
7864 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7865 pVBInfo); /*add for CRT2 */
7866 break;
7867
7868 case VB_CHIP_302:
7869 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7870 pVBInfo); /*add for CRT2 */
7871 break;
7872
7873 default:
7874 break;
7875 }
7876 }
7877
7878 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
7879 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
7880 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
7881 XGI_EnableBridge(HwDeviceExtension, pVBInfo);
7882 } /* !XG20 */
7883 else {
7884 if (pVBInfo->IF_DEF_LVDS == 1)
7885 if (!XGI_XG21CheckLVDSMode(ModeNo,
7886 ModeIdIndex,
7887 pVBInfo))
7888 return 0;
7889
7890 if (ModeNo <= 0x13) {
7891 pVBInfo->ModeType = pVBInfo->SModeIDTable[ModeIdIndex].
7892 St_ModeFlag & ModeInfoFlag;
7893 } else {
7894 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
7895 Ext_ModeFlag & ModeInfoFlag;
7896 }
7897
7898 pVBInfo->SetFlag = 0;
7899 pVBInfo->VBInfo = DisableCRT2Display;
7900
7901 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
7902
7903 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex,
7904 pVBInfo);
7905
7906 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7907 /*
7908 if (HwDeviceExtension->jChipType == XG21)
7909 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0x80, 0x80);
7910 */
7911 }
7912
7913 /*
7914 if (ModeNo <= 0x13) {
7915 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7916 } else {
7917 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7918 }
7919 pVBInfo->ModeType = modeflag&ModeInfoFlag;
7920 pVBInfo->SetFlag = 0x00;
7921 pVBInfo->VBInfo = DisableCRT2Display;
7922 temp = XGINew_CheckMemorySize(HwDeviceExtension,
7923 ModeNo,
7924 ModeIdIndex,
7925 pVBInfo);
7926
7927 if (temp == 0)
7928 return (0);
7929
7930 XGI_DisplayOff(HwDeviceExtension, pVBInfo) ;
7931 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex, pVBInfo);
7932 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7933 */
7934
7935 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
7936
7937 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7938 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
7939 }
7940
7941 return 1;
7942 }
This page took 0.191418 seconds and 6 git commands to generate.