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