blob: 100f63f04270c24a18c770d7998029809f11b5a2 [file] [log] [blame]
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002#include <linux/io.h>
Aaro Koskinend80aaa02011-02-17 23:29:14 +02003#include <linux/delay.h>
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004#include <linux/types.h>
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005#include "XGIfb.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007
8#include "vb_def.h"
9#include "vgatypes.h"
10#include "vb_struct.h"
11#include "vb_util.h"
12#include "vb_table.h"
Aaro Koskinen5e60b972011-03-08 22:16:14 +020013#include "vb_setmode.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020014
15
16#define IndexMask 0xff
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020017
Randy Dunlap89229672010-08-10 08:46:44 -070018static unsigned short XGINew_MDA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040019 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
21 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
22 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
23 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
25 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
26 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020027
Randy Dunlap89229672010-08-10 08:46:44 -070028static unsigned short XGINew_CGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040029 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
30 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
31 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
32 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
33 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
34 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
35 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
36 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020037
Randy Dunlap89229672010-08-10 08:46:44 -070038static unsigned short XGINew_EGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040039 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x05, 0x15,
40 0x20, 0x30, 0x24, 0x34, 0x21, 0x31, 0x25, 0x35,
41 0x08, 0x18, 0x0C, 0x1C, 0x09, 0x19, 0x0D, 0x1D,
42 0x28, 0x38, 0x2C, 0x3C, 0x29, 0x39, 0x2D, 0x3D,
43 0x02, 0x12, 0x06, 0x16, 0x03, 0x13, 0x07, 0x17,
44 0x22, 0x32, 0x26, 0x36, 0x23, 0x33, 0x27, 0x37,
45 0x0A, 0x1A, 0x0E, 0x1E, 0x0B, 0x1B, 0x0F, 0x1F,
46 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020047
Randy Dunlap89229672010-08-10 08:46:44 -070048static unsigned short XGINew_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040049 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
50 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
51 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
52 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
53 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
54 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
55 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
56 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
57 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
58 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020059
Bill Pemberton80adad82010-06-17 13:10:51 -040060void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020061{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053062 pVBInfo->SModeIDTable = (struct XGI_StStruct *) XGI330_SModeIDTable;
63 pVBInfo->StandTable = (struct XGI_StandTableStruct *) XGI330_StandTable;
64 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
65 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
66 pVBInfo->XGINEWUB_CRT1Table
67 = (struct XGI_CRT1TableStruct *) XGI_CRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020068
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053069 /* add for new UNIVGABIOS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +080070 /* XGINew_UBLCDDataTable =
71 * (struct XGI_LCDDataTablStruct *) XGI_LCDDataTable; */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053072 /* XGINew_UBTVDataTable = (XGI_TVDataTablStruct *) XGI_TVDataTable; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020073
Aaro Koskinen06587332011-03-13 12:26:10 +020074 pVBInfo->MCLKData = (struct XGI_MCLKDataStruct *) XGI340New_MCLKData;
75 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053076 pVBInfo->VCLKData = (struct XGI_VCLKDataStruct *) XGI_VCLKData;
77 pVBInfo->VBVCLKData = (struct XGI_VBVCLKDataStruct *) XGI_VBVCLKData;
78 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
79 pVBInfo->StResInfo = (struct XGI_StResInfoStruct *) XGI330_StResInfo;
80 pVBInfo->ModeResInfo
81 = (struct XGI_ModeResInfoStruct *) XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020082
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053083 pVBInfo->pOutputSelect = &XGI330_OutputSelect;
84 pVBInfo->pSoftSetting = &XGI330_SoftSetting;
85 pVBInfo->pSR07 = &XGI330_SR07;
86 pVBInfo->LCDResInfo = 0;
87 pVBInfo->LCDTypeInfo = 0;
88 pVBInfo->LCDInfo = 0;
89 pVBInfo->VBInfo = 0;
90 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053092 pVBInfo->SR15 = XGI340_SR13;
93 pVBInfo->CR40 = XGI340_cr41;
94 pVBInfo->SR25 = XGI330_sr25;
95 pVBInfo->pSR31 = &XGI330_sr31;
96 pVBInfo->pSR32 = &XGI330_sr32;
97 pVBInfo->CR6B = XGI340_CR6B;
98 pVBInfo->CR6E = XGI340_CR6E;
99 pVBInfo->CR6F = XGI340_CR6F;
100 pVBInfo->CR89 = XGI340_CR89;
101 pVBInfo->AGPReg = XGI340_AGPReg;
102 pVBInfo->SR16 = XGI340_SR16;
103 pVBInfo->pCRCF = &XG40_CRCF;
104 pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530106 pVBInfo->CR49 = XGI330_CR49;
107 pVBInfo->pSR1F = &XGI330_SR1F;
108 pVBInfo->pSR21 = &XGI330_SR21;
109 pVBInfo->pSR22 = &XGI330_SR22;
110 pVBInfo->pSR23 = &XGI330_SR23;
111 pVBInfo->pSR24 = &XGI330_SR24;
112 pVBInfo->pSR33 = &XGI330_SR33;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2;
115 pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D;
116 pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E;
117 pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10;
118 pVBInfo->pRGBSenseData = &XGI330_RGBSenseData;
119 pVBInfo->pVideoSenseData = &XGI330_VideoSenseData;
120 pVBInfo->pYCSenseData = &XGI330_YCSenseData;
121 pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2;
122 pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2;
123 pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530125 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
126 pVBInfo->PALTiming = XGI330_PALTiming;
127 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
128 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
129 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
130 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
131 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
132 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
133 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
134 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
135 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
136 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
137 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
138 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530140 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
141 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
142 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530144 /* 310 customization related */
145 if ((pVBInfo->VBType & VB_XGI301LV) || (pVBInfo->VBType & VB_XGI302LV))
146 pVBInfo->LCDCapList = XGI_LCDDLCapList;
147 else
148 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530150 if ((ChipType == XG21) || (ChipType == XG27))
151 pVBInfo->XG21_LVDSCapList = XGI21_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200152
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530153 pVBInfo->XGI_TVDelayList = XGI301TVDelayList;
154 pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200155
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530156 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530158 if (ChipType >= XG20)
159 pVBInfo->pXGINew_CR97 = &XG20_CR97;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530161 if (ChipType == XG27) {
162 pVBInfo->MCLKData
163 = (struct XGI_MCLKDataStruct *) XGI27New_MCLKData;
164 pVBInfo->CR40 = XGI27_cr41;
165 pVBInfo->pXGINew_CR97 = &XG27_CR97;
166 pVBInfo->pSR36 = &XG27_SR36;
167 pVBInfo->pCR8F = &XG27_CR8F;
168 pVBInfo->pCRD0 = XG27_CRD0;
169 pVBInfo->pCRDE = XG27_CRDE;
170 pVBInfo->pSR40 = &XG27_SR40;
171 pVBInfo->pSR41 = &XG27_SR41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530173 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530175 if (ChipType >= XG20) {
176 pVBInfo->pDVOSetting = &XG21_DVOSetting;
177 pVBInfo->pCR2E = &XG21_CR2E;
178 pVBInfo->pCR2F = &XG21_CR2F;
179 pVBInfo->pCR46 = &XG21_CR46;
180 pVBInfo->pCR47 = &XG21_CR47;
181 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200182
183}
184
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800185static unsigned char XGI_GetModePtr(unsigned short ModeNo,
186 unsigned short ModeIdIndex,
187 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200188{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530189 unsigned char index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530191 if (ModeNo <= 0x13)
192 index = pVBInfo->SModeIDTable[ModeIdIndex].St_StTableIndex;
193 else {
194 if (pVBInfo->ModeType <= 0x02)
195 index = 0x1B; /* 02 -> ModeEGA */
196 else
197 index = 0x0F;
198 }
199 return index; /* Get pVBInfo->StandTable index */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200200}
201
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800202static void XGI_SetSeqRegs(unsigned short ModeNo,
203 unsigned short StandTableIndex,
204 unsigned short ModeIdIndex,
205 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200206{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530207 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530208 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200209
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530210 if (ModeNo <= 0x13)
211 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
212 else
213 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200214
Aaro Koskinen8104e322011-03-13 12:26:22 +0200215 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530216 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530218 i = SetCRT2ToLCDA;
219 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
220 tempah |= 0x01;
221 } else {
222 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
223 if (pVBInfo->VBInfo & SetInSlaveMode)
224 tempah |= 0x01;
225 }
226 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530228 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200229 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200230
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530231 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800232 /* Get SR2,3,4 from file */
233 SRdata = pVBInfo->StandTable[StandTableIndex].SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200234 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530235 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200236}
237
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200238static void XGI_SetMiscRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800239 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200240{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530241 unsigned char Miscdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200242
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800243 /* Get Misc from file */
244 Miscdata = pVBInfo->StandTable[StandTableIndex].MISC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530245 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800246 if (pVBInfo->VBType & (VB_XGI301B |
247 VB_XGI302B |
248 VB_XGI301LV |
249 VB_XGI302LV |
250 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530251 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
252 Miscdata |= 0x0C;
253 }
254 }
255 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200256
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200257 outb(Miscdata, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200258}
259
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200260static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800261 unsigned short StandTableIndex,
262 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200263{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530264 unsigned char CRTCdata;
265 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200266
Aaro Koskinen58839b02011-03-13 12:26:23 +0200267 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530268 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200269 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200270
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530271 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800272 /* Get CRTC from file */
273 CRTCdata = pVBInfo->StandTable[StandTableIndex].CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200274 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530275 }
276 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800277 if ((HwDeviceExtension->jChipType == XGI_630) &&
278 (HwDeviceExtension->jChipRevision == 0x30)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530279 if (pVBInfo->VBInfo & SetInSlaveMode) {
280 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200281 xgifb_reg_set(pVBInfo->P3d4, 0x18, 0xFE);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530282 }
283 }
284 }
285 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200286}
287
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800288static void XGI_SetATTRegs(unsigned short ModeNo,
289 unsigned short StandTableIndex,
290 unsigned short ModeIdIndex,
291 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200292{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530293 unsigned char ARdata;
294 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200295
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530296 if (ModeNo <= 0x13)
297 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
298 else
299 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200300
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530301 for (i = 0; i <= 0x13; i++) {
302 ARdata = pVBInfo->StandTable[StandTableIndex].ATTR[i];
303 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
304 if (i == 0x13) {
305 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
306 ARdata = 0;
307 } else {
308 if (pVBInfo->VBInfo & (SetCRT2ToTV
309 | SetCRT2ToLCD)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800310 if (pVBInfo->VBInfo &
311 SetInSlaveMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530312 ARdata = 0;
313 }
314 }
315 }
316 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200317
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200318 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200319 outb(i, pVBInfo->P3c0); /* set index */
320 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530321 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200322
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200323 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200324 outb(0x14, pVBInfo->P3c0); /* set index */
325 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200326 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200327 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200328}
329
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200330static void XGI_SetGRCRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800331 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200332{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530333 unsigned char GRdata;
334 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530336 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800337 /* Get GR from file */
338 GRdata = pVBInfo->StandTable[StandTableIndex].GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200339 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530340 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200341
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530342 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200343 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530344 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200345 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530346 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200347}
348
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200349static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200350{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530351 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200352
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530353 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200354 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200355}
356
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200357static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200358{
359
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200360 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200361 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
362 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200363
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200364 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200365 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
366 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200367
Aaro Koskinendc505562011-03-13 12:26:26 +0200368 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530369 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200370}
371
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200372static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530373 unsigned short ModeIdIndex,
374 unsigned short RefreshRateTableIndex, unsigned short *i,
375 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200376{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530377 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200378
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530379 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800380 /* si+St_ModeFlag */
381 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530382 else
383 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200384
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530385 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
386 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
387 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200388
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530389 if (pVBInfo->IF_DEF_LVDS == 0) {
390 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
391 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530393 if (pVBInfo->VBType & VB_XGI301C)
394 tempax |= SupportCRT2in301C;
395 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200396
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800397 /* 301b */
398 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530399 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200400
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530401 if (pVBInfo->LCDResInfo != Panel1280x1024) {
402 if (pVBInfo->LCDResInfo != Panel1280x960) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800403 if (pVBInfo->LCDInfo &
404 LCDNonExpanding) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530405 if (resinfo >= 9) {
406 tempax = 0;
407 return 0;
408 }
409 }
410 }
411 }
412 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530414 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) { /* for HiTV */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800415 if ((pVBInfo->VBType & VB_XGI301LV) &&
416 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530417 tempax |= SupportYPbPr;
418 if (pVBInfo->VBInfo & SetInSlaveMode) {
419 if (resinfo == 4)
420 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200421
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530422 if (resinfo == 3)
423 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200424
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530425 if (resinfo > 7)
426 return 0;
427 }
428 } else {
429 tempax |= SupportHiVisionTV;
430 if (pVBInfo->VBInfo & SetInSlaveMode) {
431 if (resinfo == 4)
432 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200433
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530434 if (resinfo == 3) {
435 if (pVBInfo->SetFlag
436 & TVSimuMode)
437 return 0;
438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200439
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530440 if (resinfo > 7)
441 return 0;
442 }
443 }
444 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800445 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
446 SetCRT2ToSVIDEO |
447 SetCRT2ToSCART |
448 SetCRT2ToYPbPr |
449 SetCRT2ToHiVisionTV)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530450 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200451
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530452 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
453 | VB_XGI301LV | VB_XGI302LV
454 | VB_XGI301C)) {
455 tempax |= SupportTV1024;
456 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200457
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530458 if (!(pVBInfo->VBInfo & SetPALTV)) {
459 if (modeflag & NoSupportSimuTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800460 if (pVBInfo->VBInfo &
461 SetInSlaveMode) {
462 if (!(pVBInfo->VBInfo &
463 SetNotSimuMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530464 return 0;
465 }
466 }
467 }
468 }
469 }
470 }
471 } else { /* for LVDS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530472 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
473 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200474
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530475 if (resinfo > 0x08)
476 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200477
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530478 if (pVBInfo->LCDResInfo < Panel1024x768) {
479 if (resinfo > 0x07)
480 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200481
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530482 if (resinfo == 0x04)
483 return 0; /* 512x384 */
484 }
485 }
486 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200487
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800488 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
489 tempbx; (*i)--) {
490 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
491 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530492 if (infoflag & tempax)
493 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530495 if ((*i) == 0)
496 break;
497 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200498
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530499 for ((*i) = 0;; (*i)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800500 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
501 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530502 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
503 != tempbx) {
504 return 0;
505 }
506
507 if (infoflag & tempax)
508 return 1;
509 }
510 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200511}
512
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200513static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530514 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200515{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530516 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200517
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800518 /* di+0x00 */
519 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530520 sync &= 0xC0;
521 temp = 0x2F;
522 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200523 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200524}
525
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200526static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530527 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200528{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530529 unsigned char data, data1, pushax;
530 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200531
Aaro Koskinen8104e322011-03-13 12:26:22 +0200532 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
533 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200534 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200535
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800536 /* unlock cr0-7 */
537 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530538 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200539 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200540
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530541 data = pVBInfo->TimingH[0].data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200542 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200543
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530544 for (i = 0x01; i <= 0x04; i++) {
545 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200546 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530547 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200548
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530549 for (i = 0x05; i <= 0x06; i++) {
550 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200551 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530552 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200553
Aaro Koskinen58839b02011-03-13 12:26:23 +0200554 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530555 j &= 0x1F;
556 data = pVBInfo->TimingH[0].data[7];
557 data &= 0xE0;
558 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200559 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200560
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530561 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200562 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530563 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200564 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200565 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530566 data1 = data;
567 data1 &= 0xE0;
568 data &= 0x1F;
569 if (data == 0) {
570 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200571 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530572 0x0c);
573 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200574 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530575 data = pushax;
576 }
577 data = data - 1;
578 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200579 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200580 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530581 data = data >> 5;
582 data = data + 3;
583 if (data > 7)
584 data = data - 7;
585 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200586 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530587 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200588}
589
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800590static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
591 unsigned short ModeNo,
592 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200593{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530594 unsigned char data;
595 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200596
Aaro Koskinen8104e322011-03-13 12:26:22 +0200597 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
598 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200599 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200600
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530601 for (i = 0x00; i <= 0x01; i++) {
602 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200603 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530604 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200605
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530606 for (i = 0x02; i <= 0x03; i++) {
607 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200608 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530609 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200610
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530611 for (i = 0x04; i <= 0x05; i++) {
612 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200613 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530614 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200615
Aaro Koskinen58839b02011-03-13 12:26:23 +0200616 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530617 j &= 0xC0;
618 data = pVBInfo->TimingV[0].data[6];
619 data &= 0x3F;
620 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200621 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200622
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530623 data = pVBInfo->TimingV[0].data[6];
624 data &= 0x80;
625 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200626
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530627 if (ModeNo <= 0x13)
628 i = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
629 else
630 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200631
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530632 i &= DoubleScanMode;
633 if (i)
634 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200635
Aaro Koskinen58839b02011-03-13 12:26:23 +0200636 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530637 j &= 0x5F;
638 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200639 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200640}
641
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200642static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
643 unsigned short RefreshRateTableIndex,
644 struct vb_device_info *pVBInfo,
645 struct xgi_hw_device_info *HwDeviceExtension)
646{
647 unsigned char index, data;
648 unsigned short i;
649
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800650 /* Get index */
651 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200652 index = index & IndexMask;
653
Aaro Koskinen58839b02011-03-13 12:26:23 +0200654 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200655 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200656 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200657
658 for (i = 0; i < 8; i++)
659 pVBInfo->TimingH[0].data[i]
660 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
661
662 for (i = 0; i < 7; i++)
663 pVBInfo->TimingV[0].data[i]
664 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
665
666 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
667
668 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
669
670 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200671 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200672}
673
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200674/* --------------------------------------------------------------------- */
675/* Function : XGI_SetXG21CRTC */
676/* Input : Stand or enhance CRTC table */
677/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
678/* Description : Set LCD timing */
679/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200680static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530681 unsigned short RefreshRateTableIndex,
682 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200683{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530684 unsigned char StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
685 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200686
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530687 if (ModeNo <= 0x13) {
688 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800689 /* CR04 HRS */
690 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
691 /* SR2E [7:0]->HRS */
692 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
693 /* Tempbx: CR05 HRE */
694 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530695 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
696 Tempcx = Tempax;
697 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
698 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
699 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
700 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
701 Tempdx <<= 2; /* Tempdx << 2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800702 /* SR2F [7:2]->HRE */
703 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200704 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200705
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800706 /* Tempax: CR16 VRS */
707 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530708 Tempbx = Tempax; /* Tempbx=Tempax */
709 Tempax &= 0x01; /* Tempax: VRS[0] */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200710 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800711
712 /* Tempax: CR7 VRS */
713 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530714 Tempdx = Tempbx >> 1; /* Tempdx: VRS[7:1] */
715 Tempcx = Tempax & 0x04; /* Tempcx: CR7[2] */
716 Tempcx <<= 5; /* Tempcx[7]: VRS[8] */
717 Tempdx |= Tempcx; /* Tempdx: VRS[8:1] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800718 /* SR34[7:0]: VRS[8:1] */
719 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempdx);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200720
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800721 /* Temp1[8]: VRS[8] unsigned char -> unsigned short */
722 Temp1 = Tempcx << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530723 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
724 Tempax &= 0x80; /* Tempax[7]: CR7[7] */
725 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
726 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200727
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800728 /* CR16 VRE */
729 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530730 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
731 Temp2 = Temp1 & 0x3F0; /* Temp2[9:4]: VRS[9:4] */
732 Temp2 |= Tempax; /* Temp2[9:0]: VRE[9:0] */
733 Temp3 = Temp1 & 0x0F; /* Temp3[3:0]: VRS[3:0] */
734 if (Tempax < Temp3) /* VRE[3:0]<VRS[3:0] */
735 Temp2 |= 0x10; /* Temp2: VRE + 0x10 */
736 Temp2 &= 0xFF; /* Temp2[7:0]: VRE[7:0] */
737 Tempax = (unsigned char) Temp2; /* Tempax[7:0]: VRE[7:0] */
738 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
739 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
740 Temp1 >>= 9; /* [10:9]->[1:0] */
741 Tempbx = (unsigned char) Temp1; /* Tempbx[1:0]: VRS[10:9] */
742 Tempax |= Tempbx; /* VRE[5:0]VRS[10:9] */
743 Tempax &= 0x7F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800744 /* SR3F D[7:2]->VRE D[1:0]->VRS */
745 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530746 } else {
747 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800748 /* Tempax: CR4 HRS */
749 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530750 Tempcx = Tempax; /* Tempcx: HRS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800751 /* SR2E[7:0]->HRS */
752 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200753
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530754 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
755 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
756 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
757 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
758 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200759
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530760 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
761 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200762
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530763 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
764 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
765 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
766 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200767
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530768 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
769 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200770
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530771 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
772 if (Tempax < Tempcx) /* HRE < HRS */
773 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200774
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530775 Temp2 &= 0xFF;
776 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
777 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
778 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
779 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800780 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
781 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200782 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200783
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800784 /* CR10 VRS */
785 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530786 Tempbx = Tempax; /* Tempbx: VRS */
787 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200788 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800789 /* CR7[2][7] VRE */
790 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530791 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
792 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
793 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
794 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200795 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530797 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
798 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
799 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
800 Tempax &= 0x80;
801 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
802 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800803 /* Tempax: SRA */
804 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530805 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
806 Temp2 = Tempax;
807 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
808 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200809
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800810 /* Tempax: CR11 VRE */
811 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530812 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800813 /* Tempbx: SRA */
814 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530815 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
816 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
817 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
818 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
819 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530821 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
822 if (Tempax < Temp3) /* VRE < VRS */
823 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200824
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530825 Temp2 &= 0xFF;
826 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
827 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
828 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
829 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
830 Tempbx = (unsigned char) Temp1;
831 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
832 Tempax &= 0x7F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800833 /* SR3F D[7:2]->VRE D[1:0]->VRS */
834 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530835 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200836}
837
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800838static void XGI_SetXG27CRTC(unsigned short ModeNo,
839 unsigned short ModeIdIndex,
840 unsigned short RefreshRateTableIndex,
841 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200842{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400843 unsigned short StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200844
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530845 if (ModeNo <= 0x13) {
846 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800847 /* CR04 HRS */
848 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
849 /* SR2E [7:0]->HRS */
850 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
851 /* Tempbx: CR05 HRE */
852 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530853 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
854 Tempcx = Tempax;
855 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
856 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
857 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
858 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
859 Tempdx <<= 2; /* Tempdx << 2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800860 /* SR2F [7:2]->HRE */
861 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200862 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200863
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800864 /* Tempax: CR10 VRS */
865 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200866 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax); /* SR34[7:0]->VRS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530867 Tempcx = Tempax; /* Tempcx=Tempax=VRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800868 /* Tempax[7][2]: CR7[7][2] VRS[9][8] */
869 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530870 Tempbx = Tempax; /* Tempbx=CR07 */
871 Tempax &= 0x04; /* Tempax[2]: CR07[2] VRS[8] */
872 Tempax >>= 2;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800873 /* SR35 D[0]->VRS D[8] */
874 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530875 Tempcx |= (Tempax << 8); /* Tempcx[8] |= VRS[8] */
876 Tempcx |= (Tempbx & 0x80) << 2; /* Tempcx[9] |= VRS[9] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200877
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800878 /* CR11 VRE */
879 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530880 Tempax &= 0x0F; /* Tempax: VRE[3:0] */
881 Tempbx = Tempcx; /* Tempbx=Tempcx=VRS[9:0] */
882 Tempbx &= 0x3F0; /* Tempbx[9:4]: VRS[9:4] */
883 Tempbx |= Tempax; /* Tempbx[9:0]: VRE[9:0] */
884 if (Tempax <= (Tempcx & 0x0F)) /* VRE[3:0]<=VRS[3:0] */
885 Tempbx |= 0x10; /* Tempbx: VRE + 0x10 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800886 /* Tempax[7:0]: VRE[7:0] */
887 Tempax = (unsigned char) Tempbx & 0xFF;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530888 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
889 Tempcx = (Tempcx & 0x600) >> 8; /* Tempcx VRS[10:9] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800890 /* SR3F D[7:2]->VRE D[5:0] */
891 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
892 /* SR35 D[2:1]->VRS[10:9] */
893 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x06, Tempcx);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530894 } else {
895 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800896 /* Tempax: CR4 HRS */
897 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530898 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800899 /* SR2E[7:0]->HRS */
900 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200901
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800902 /* SR0B */
903 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530904 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
905 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200906
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530907 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
908 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
909 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200910
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530911 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
912 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
913 Tempax <<= 3; /* Tempax[5]: HRE[5] */
914 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530916 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
917 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200918
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800919 /* Tempax: CR4 HRS */
920 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530921 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
922 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
923 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200924
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530925 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
926 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
927 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
928 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800929 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
930 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200931 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200932
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800933 /* CR10 VRS */
934 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
935 /* SR34[7:0]->VRS[7:0] */
936 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200937
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530938 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800939 /* CR7[7][2] VRS[9][8] */
940 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530941 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
942 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
943 Tempax >>= 2; /* Tempax[0]: VRS[8] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800944 /* SR35[0]: VRS[8] */
945 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530946 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
947 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800948 /* Tempax: SR0A */
949 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530950 Tempax &= 0x08; /* SR0A[3] VRS[10] */
951 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200952
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800953 /* Tempax: CR11 VRE */
954 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530955 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800956 /* Tempbx: SR0A */
957 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530958 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
959 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
960 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
961 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
962 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
963 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200964
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530965 if (Tempbx <= Tempcx) /* VRE <= VRS */
966 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200967
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800968 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
969 Tempax = (Tempbx << 2) & 0xFF;
970 /* SR3F[7:2]:VRE[5:0] */
971 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530972 Tempax = Tempcx >> 8;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800973 /* SR35[2:0]:VRS[10:8] */
974 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530975 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200976}
977
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300978static void xgifb_set_lcd(int chip_id,
979 struct vb_device_info *pVBInfo,
980 unsigned short RefreshRateTableIndex,
981 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200982{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400983 unsigned short Data, Temp, b3CC;
984 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200985
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530986 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200987
Aaro Koskinen8104e322011-03-13 12:26:22 +0200988 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
989 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
990 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
991 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300992
993 if (chip_id == XG27) {
994 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
995 if ((Temp & 0x03) == 0) { /* dual 12 */
996 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
997 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
998 }
999 }
1000
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301001 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001002 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
1003 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
1004 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
1005 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301006 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001007
Aaro Koskinen105d8d02011-08-31 21:46:00 +03001008 if (chip_id == XG27) {
1009 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301010 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +03001011 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
1012 if (Temp & 0x01) {
1013 /* 18 bits FP */
1014 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
1015 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
1016 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301017 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001018
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001019 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001020
Aaro Koskinendc505562011-03-13 12:26:26 +02001021 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
1022 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301024 if (ModeNo <= 0x13) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001025 b3CC = (unsigned char) inb(XGI_P3cc);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301026 if (b3CC & 0x40)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001027 /* Hsync polarity */
1028 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301029 if (b3CC & 0x80)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001030 /* Vsync polarity */
1031 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301032 } else {
1033 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1034 if (Data & 0x4000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001035 /* Hsync polarity */
1036 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301037 if (Data & 0x8000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001038 /* Vsync polarity */
1039 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301040 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001041}
1042
1043/* --------------------------------------------------------------------- */
1044/* Function : XGI_UpdateXG21CRTC */
1045/* Input : */
1046/* Output : CRT1 CRTC */
1047/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
1048/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001049static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
1050 struct vb_device_info *pVBInfo,
1051 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001052{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301053 int i, index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001054
Aaro Koskinendc505562011-03-13 12:26:26 +02001055 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301056 if (ModeNo <= 0x13) {
1057 for (i = 0; i < 12; i++) {
1058 if (ModeNo == pVBInfo->UpdateCRT1[i].ModeID)
1059 index = i;
1060 }
1061 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001062 if (ModeNo == 0x2E &&
1063 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1064 RES640x480x60))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301065 index = 12;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001066 else if (ModeNo == 0x2E &&
1067 (pVBInfo->RefIndex[RefreshRateTableIndex].
1068 Ext_CRT1CRTC == RES640x480x72))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301069 index = 13;
1070 else if (ModeNo == 0x2F)
1071 index = 14;
1072 else if (ModeNo == 0x50)
1073 index = 15;
1074 else if (ModeNo == 0x59)
1075 index = 16;
1076 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301078 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001079 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301080 pVBInfo->UpdateCRT1[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001081 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301082 pVBInfo->UpdateCRT1[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001083 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301084 pVBInfo->UpdateCRT1[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001085 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301086 pVBInfo->UpdateCRT1[index].CR16);
1087 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001088}
1089
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001090static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301091 unsigned short ModeNo, unsigned short ModeIdIndex,
1092 unsigned short RefreshRateTableIndex,
1093 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001094{
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001095 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001096
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301097 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301099 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301101 if (ModeNo <= 0x13) {
1102 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1103 tempax = pVBInfo->StResInfo[resindex].HTotal;
1104 tempbx = pVBInfo->StResInfo[resindex].VTotal;
1105 } else {
1106 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1107 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
1108 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
1109 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301111 if (modeflag & HalfDCLK)
1112 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301114 if (ModeNo > 0x13) {
1115 if (modeflag & HalfDCLK)
1116 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301118 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301120 if (temp & InterlaceMode)
1121 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301123 if (modeflag & DoubleScanMode)
1124 tempbx = tempbx << 1;
1125 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301127 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301129 /* if (!(modeflag & Charx8Dot)) */
1130 /* tempcx = 9; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301132 tempax /= tempcx;
1133 tempax -= 1;
1134 tempbx -= 1;
1135 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001136 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1137 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301138 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001139 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
1140 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001141 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301142 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +02001143 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301144 tempax = 0;
1145 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301147 if (tempbx & 0x01)
1148 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301150 if (tempbx & 0x02)
1151 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001152
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001153 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001154 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301155 data &= 0xFF;
1156 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301158 if (tempbx & 0x04)
1159 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001160
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001161 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001162 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001163}
1164
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001165unsigned short XGI_GetResInfo(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301166 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001167{
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001168 unsigned short resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301170 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001171 /* si+St_ResInfo */
1172 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301173 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001174 /* si+Ext_ResInfo */
1175 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301176 return resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001177}
1178
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001179static void XGI_SetCRT1Offset(unsigned short ModeNo,
1180 unsigned short ModeIdIndex,
1181 unsigned short RefreshRateTableIndex,
1182 struct xgi_hw_device_info *HwDeviceExtension,
1183 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001184{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301185 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301187 /* GetOffset */
1188 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
1189 temp = temp >> 8;
1190 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301192 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1193 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001194
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301195 if (temp2)
1196 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001197
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301198 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001199
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301200 switch (temp2) {
1201 case 0:
1202 temp2 = 1;
1203 break;
1204 case 1:
1205 temp2 = 2;
1206 break;
1207 case 2:
1208 temp2 = 4;
1209 break;
1210 case 3:
1211 temp2 = 4;
1212 break;
1213 case 4:
1214 temp2 = 6;
1215 break;
1216 case 5:
1217 temp2 = 8;
1218 break;
1219 default:
1220 break;
1221 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301223 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1224 temp = temp * temp2 + temp2 / 2;
1225 else
1226 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301228 /* SetOffset */
1229 DisplayUnit = temp;
1230 temp2 = temp;
1231 temp = temp >> 8; /* ah */
1232 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001233 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301234 i &= 0xF0;
1235 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001236 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301238 temp = (unsigned char) temp2;
1239 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +02001240 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001241
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301242 /* SetDisplayUnit */
1243 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1244 temp2 &= InterlaceMode;
1245 if (temp2)
1246 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001247
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301248 DisplayUnit = DisplayUnit << 5;
1249 ah = (DisplayUnit & 0xff00) >> 8;
1250 al = DisplayUnit & 0x00ff;
1251 if (al == 0)
1252 ah += 1;
1253 else
1254 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301256 if (HwDeviceExtension->jChipType >= XG20)
1257 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1258 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001259
Aaro Koskinen8104e322011-03-13 12:26:22 +02001260 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001261}
1262
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001263static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1264 unsigned short ModeIdIndex,
1265 unsigned short RefreshRateTableIndex,
1266 struct xgi_hw_device_info *HwDeviceExtension,
1267 struct vb_device_info *pVBInfo)
1268{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001269 unsigned short LCDXlat1VCLK[4] = { VCLK65 + 2,
1270 VCLK65 + 2,
1271 VCLK65 + 2,
1272 VCLK65 + 2 };
1273 unsigned short LCDXlat2VCLK[4] = { VCLK108_2 + 5,
1274 VCLK108_2 + 5,
1275 VCLK108_2 + 5,
1276 VCLK108_2 + 5 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001277 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001278 unsigned short LVDSXlat2VCLK[4] = { VCLK65 + 2,
1279 VCLK65 + 2,
1280 VCLK65 + 2,
1281 VCLK65 + 2 };
1282 unsigned short LVDSXlat3VCLK[4] = { VCLK65 + 2,
1283 VCLK65 + 2,
1284 VCLK65 + 2,
1285 VCLK65 + 2 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001286
1287 unsigned short CRT2Index, VCLKIndex;
1288 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001289
1290 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001291 /* si+St_ResInfo */
1292 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001293 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1294 CRT2Index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1295 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001296 /* si+Ext_ResInfo */
1297 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001298 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001299 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].
1300 Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001301 }
1302
1303 if (pVBInfo->IF_DEF_LVDS == 0) {
1304 CRT2Index = CRT2Index >> 6; /* for LCD */
1305 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /*301b*/
1306 if (pVBInfo->LCDResInfo != Panel1024x768)
1307 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1308 else
1309 VCLKIndex = LCDXlat1VCLK[CRT2Index];
1310 } else { /* for TV */
1311 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1312 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
1313 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1314 VCLKIndex = HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001315 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001316 } else {
1317 VCLKIndex = HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001318 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001319 }
1320
1321 if (pVBInfo->SetFlag & TVSimuMode) {
1322 if (modeflag & Charx8Dot) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001323 VCLKIndex =
1324 HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001325 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001326 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001327 VCLKIndex =
1328 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001329 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001330 }
1331 }
1332
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001333 /* 301lv */
1334 if (pVBInfo->VBType & VB_XGI301LV) {
1335 if (!(pVBInfo->VBExtInfo ==
1336 VB_YPbPr1080i)) {
1337 VCLKIndex =
1338 YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001339 if (!(pVBInfo->VBExtInfo
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001340 ==
1341 VB_YPbPr750p)) {
1342 VCLKIndex =
1343 YPbPr525pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001344 if (!(pVBInfo->VBExtInfo
1345 == VB_YPbPr525p)) {
1346 VCLKIndex
1347 = YPbPr525iVCLK_2;
1348 if (!(pVBInfo->SetFlag
1349 & RPLLDIV2XO))
1350 VCLKIndex
1351 = YPbPr525iVCLK;
1352 }
1353 }
1354 }
1355 }
1356 } else {
1357 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001358 if (pVBInfo->SetFlag &
1359 RPLLDIV2XO) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001360 VCLKIndex = TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001361 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001362 } else {
1363 VCLKIndex = TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001364 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001365 }
1366 }
1367 }
1368 } else { /* for CRT2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001369 /* Port 3cch */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001370 VCLKIndex = (unsigned char) inb(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001371 (pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001372 VCLKIndex = ((VCLKIndex >> 2) & 0x03);
1373 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001374 /* di+Ext_CRTVCLK */
1375 VCLKIndex =
1376 pVBInfo->RefIndex[
1377 RefreshRateTableIndex].
1378 Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001379 VCLKIndex &= IndexMask;
1380 }
1381 }
1382 }
1383 } else { /* LVDS */
1384 if (ModeNo <= 0x13)
1385 VCLKIndex = CRT2Index;
1386 else
1387 VCLKIndex = CRT2Index;
1388
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001389 VCLKIndex = VCLKIndex >> 6;
1390 if ((pVBInfo->LCDResInfo == Panel800x600) ||
1391 (pVBInfo->LCDResInfo == Panel320x480))
1392 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
1393 else if ((pVBInfo->LCDResInfo == Panel1024x768) ||
1394 (pVBInfo->LCDResInfo == Panel1024x768x75))
1395 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1396 else
1397 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001398 }
1399 /* VCLKIndex = VCLKIndex&IndexMask; */
1400
1401 return VCLKIndex;
1402}
1403
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001404static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1405 unsigned short ModeIdIndex,
1406 struct xgi_hw_device_info *HwDeviceExtension,
1407 unsigned short RefreshRateTableIndex,
1408 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001409{
Bill Pemberton108afbf2010-06-17 13:10:47 -04001410 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301411 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001412
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301413 if (pVBInfo->IF_DEF_LVDS == 1) {
1414 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001415 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001416 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1417 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301418 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001419 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301420 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001421 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301422 } else if ((pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
1423 | VB_XGI302LV | VB_XGI301C)) && (pVBInfo->VBInfo
1424 & SetCRT2ToLCDA)) {
1425 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1426 RefreshRateTableIndex, HwDeviceExtension,
1427 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001428 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001429 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301430 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001431 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301432 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001433 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1434 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301435 } else {
1436 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001437 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001438 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1439 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301440 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001441 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301442 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001443 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301444 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001445
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301446 if (HwDeviceExtension->jChipType >= XG20) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001447 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1448 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001449 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001450 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001451 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301452 index = data;
1453 index &= 0xE0;
1454 data &= 0x1F;
1455 data = data << 1;
1456 data += 1;
1457 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001458 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301459 }
1460 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001461}
1462
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001463static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301464 struct xgi_hw_device_info *HwDeviceExtension,
1465 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001466{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301467 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001468
Aaro Koskinen58839b02011-03-13 12:26:23 +02001469 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301470 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001471 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001472
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301473 if (ModeNo > 0x13) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001474 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001475 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301476 data &= 0xC0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001477 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001478 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301479 data |= 0x01;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001480 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301481 } else {
1482 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001483 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x0E);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001484 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301485 data &= 0xC0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001486 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301487 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001488 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0xAE);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001489 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301490 data &= 0xF0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001491 xgifb_reg_set(pVBInfo->P3c4, 0x09, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301492 }
1493 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301495 if (HwDeviceExtension->jChipType == XG21)
1496 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001497}
1498
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001499static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1500 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1501 struct vb_device_info *pVBInfo)
1502{
1503 unsigned short data, data2 = 0;
1504 short VCLK;
1505
1506 unsigned char index;
1507
1508 if (ModeNo <= 0x13)
1509 VCLK = 0;
1510 else {
1511 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1512 index &= IndexMask;
1513 VCLK = pVBInfo->VCLKData[index].CLOCK;
1514 }
1515
Aaro Koskinen58839b02011-03-13 12:26:23 +02001516 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001517 data &= 0xf3;
1518 if (VCLK >= 200)
1519 data |= 0x0c; /* VCLK > 200 */
1520
1521 if (HwDeviceExtension->jChipType >= XG20)
1522 data &= ~0x04; /* 2 pixel mode */
1523
Aaro Koskinen8104e322011-03-13 12:26:22 +02001524 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001525
1526 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001527 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001528 data &= 0xE7;
1529 if (VCLK < 200)
1530 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001531 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001532 }
1533
1534 /* Jong for Adavantech LCD ripple issue
1535 if ((VCLK >= 0) && (VCLK < 135))
1536 data2 = 0x03;
1537 else if ((VCLK >= 135) && (VCLK < 160))
1538 data2 = 0x02;
1539 else if ((VCLK >= 160) && (VCLK < 260))
1540 data2 = 0x01;
1541 else if (VCLK > 260)
1542 data2 = 0x00;
1543 */
1544 data2 = 0x00;
1545
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001546 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001547 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001548 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001549
1550}
1551
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001552static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301553 unsigned short ModeNo, unsigned short ModeIdIndex,
1554 unsigned short RefreshRateTableIndex,
1555 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001556{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301557 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1558 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001559
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301560 if (ModeNo > 0x13) {
1561 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001562 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].
1563 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301564 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001565 /* si+St_ModeFlag */
1566 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001567
Aaro Koskinen58839b02011-03-13 12:26:23 +02001568 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001569 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001570
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301571 if (ModeNo > 0x13)
1572 data = infoflag;
1573 else
1574 data = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001575
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301576 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001577
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301578 if (ModeNo > 0x13) {
1579 if (pVBInfo->ModeType > 0x02) {
1580 data2 |= 0x02;
1581 data3 = pVBInfo->ModeType - ModeVGA;
1582 data3 = data3 << 2;
1583 data2 |= data3;
1584 }
1585 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001586
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301587 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001588
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301589 if (data)
1590 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001591
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001592 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001593 /* xgifb_reg_set(pVBInfo->P3c4,0x06,data2); */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301594 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1595 if (ModeNo <= 0x13)
1596 xres = pVBInfo->StResInfo[resindex].HTotal;
1597 else
1598 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001599
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301600 data = 0x0000;
1601 if (infoflag & InterlaceMode) {
1602 if (xres == 1024)
1603 data = 0x0035;
1604 else if (xres == 1280)
1605 data = 0x0048;
1606 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001607
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301608 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001609 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301610 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001611 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001612
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301613 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001614 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001615
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301616 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001617
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301618 if (modeflag & LineCompareOff)
1619 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001620
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301621 if (ModeNo > 0x13) {
1622 if (pVBInfo->ModeType == ModeEGA)
1623 data2 |= 0x40;
1624 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001625
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001626 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301627 data = 0x60;
1628 if (pVBInfo->ModeType != ModeText) {
1629 data = data ^ 0x60;
1630 if (pVBInfo->ModeType != ModeEGA)
1631 data = data ^ 0xA0;
1632 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001633 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001634
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301635 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1636 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301638 /* if (modeflag&HalfDCLK) //030305 fix lowresolution bug */
1639 /* if (XGINew_IF_DEF_NEW_LOWRES) */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001640 /* XGI_VesaLowResolution(ModeNo, ModeIdIndex);
1641 * //030305 fix lowresolution bug */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001642
Aaro Koskinen58839b02011-03-13 12:26:23 +02001643 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001644
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301645 if (HwDeviceExtension->jChipType == XG27) {
1646 if (data & 0x40)
1647 data = 0x2c;
1648 else
1649 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001650 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001651 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301652 } else if (HwDeviceExtension->jChipType >= XG20) {
1653 if (data & 0x40)
1654 data = 0x33;
1655 else
1656 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001657 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1658 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301659 } else {
1660 if (data & 0x40)
1661 data = 0x2c;
1662 else
1663 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001664 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301665 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001666
1667}
1668
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001669static void XGI_WriteDAC(unsigned short dl,
1670 unsigned short ah,
1671 unsigned short al,
1672 unsigned short dh,
1673 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001674{
1675 unsigned short temp, bh, bl;
1676
1677 bh = ah;
1678 bl = al;
1679
1680 if (dl != 0) {
1681 temp = bh;
1682 bh = dh;
1683 dh = temp;
1684 if (dl == 1) {
1685 temp = bl;
1686 bl = dh;
1687 dh = temp;
1688 } else {
1689 temp = bl;
1690 bl = bh;
1691 bh = temp;
1692 }
1693 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001694 outb((unsigned short) dh, pVBInfo->P3c9);
1695 outb((unsigned short) bh, pVBInfo->P3c9);
1696 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001697}
1698
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001699static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301700 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001701{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301702 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al,
1703 ah, dh, *table = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001704
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301705 if (ModeNo <= 0x13)
1706 data = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1707 else
1708 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001709
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301710 data &= DACInfoFlag;
1711 time = 64;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001712
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301713 if (data == 0x00)
1714 table = XGINew_MDA_DAC;
1715 else if (data == 0x08)
1716 table = XGINew_CGA_DAC;
1717 else if (data == 0x10)
1718 table = XGINew_EGA_DAC;
1719 else if (data == 0x18) {
1720 time = 256;
1721 table = XGINew_VGA_DAC;
1722 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001723
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301724 if (time == 256)
1725 j = 16;
1726 else
1727 j = time;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001728
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001729 outb(0xFF, pVBInfo->P3c6);
1730 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001731
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301732 for (i = 0; i < j; i++) {
1733 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001734
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301735 for (k = 0; k < 3; k++) {
1736 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001737
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301738 if (data & 0x01)
1739 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001740
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301741 if (data & 0x02)
1742 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001743
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001744 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301745 data = data >> 2;
1746 }
1747 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001748
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301749 if (time == 256) {
1750 for (i = 16; i < 32; i++) {
1751 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001752
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301753 for (k = 0; k < 3; k++)
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001754 outb(data, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301755 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001756
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301757 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001758
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301759 for (m = 0; m < 9; m++) {
1760 di = si;
1761 bx = si + 0x04;
1762 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001763
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301764 for (n = 0; n < 3; n++) {
1765 for (o = 0; o < 5; o++) {
1766 dh = table[si];
1767 ah = table[di];
1768 al = table[bx];
1769 si++;
1770 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1771 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001772
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301773 si -= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001774
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301775 for (o = 0; o < 3; o++) {
1776 dh = table[bx];
1777 ah = table[di];
1778 al = table[si];
1779 si--;
1780 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1781 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001782
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301783 dl++;
1784 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301786 si += 5;
1787 }
1788 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001789}
1790
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001791static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1792 unsigned short ModeIdIndex,
1793 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001794{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301795 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301797 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001798 /* si+St_ResInfo */
1799 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301800 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001801 /* si+Ext_ResInfo */
1802 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001803
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301804 /* if (ModeNo > 0x13) */
1805 /* modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag; */
1806 /* else */
1807 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001808
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301809 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001810 /* si+St_ResInfo */
1811 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301812 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001813 /* si+Ext_ResInfo */
1814 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301816 /* resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301818 if (ModeNo <= 0x13) {
1819 xres = pVBInfo->StResInfo[resindex].HTotal;
1820 yres = pVBInfo->StResInfo[resindex].VTotal;
1821 } else {
1822 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1823 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1824 }
1825 if (ModeNo > 0x13) {
1826 if (modeflag & HalfDCLK)
1827 xres = xres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001828
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301829 if (modeflag & DoubleScanMode)
1830 yres = yres << 1;
1831 }
1832 /* if (modeflag & Charx8Dot) */
1833 /* { */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001834
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301835 if (xres == 720)
1836 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001837
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301838 /* } */
1839 pVBInfo->VGAHDE = xres;
1840 pVBInfo->HDE = xres;
1841 pVBInfo->VGAVDE = yres;
1842 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001843}
1844
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001845static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1846 unsigned short ModeIdIndex,
1847 unsigned short RefreshRateTableIndex,
1848 struct vb_device_info *pVBInfo)
1849{
1850 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1851
1852 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1853
1854 tempbx = BX;
1855
1856 if (ModeNo <= 0x13) {
1857 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1858 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1859 } else {
1860 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1861 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1862 }
1863
1864 tempal = tempal & 0x0f;
1865
1866 if (tempbx <= 1) { /* ExpLink */
1867 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001868 /* find no Ext_CRT2CRTC2 */
1869 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001870 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001871 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1872 Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001873 }
1874
1875 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
1876 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001877 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
1878 St_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001879 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001880 tempal = pVBInfo->RefIndex[
1881 RefreshRateTableIndex].
1882 Ext_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001883 }
1884
1885 if (tempbx & 0x01)
1886 tempal = (tempal >> 4);
1887
1888 tempal = (tempal & 0x0f);
1889 }
1890
1891 tempcx = LCDLenList[tempbx]; /* mov cl,byte ptr cs:LCDLenList[bx] */
1892
1893 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1894 if ((tempbx == 5) || (tempbx) == 7)
1895 tempcx = LCDDesDataLen2;
1896 else if ((tempbx == 3) || (tempbx == 8))
1897 tempcx = LVDSDesDataLen2;
1898 }
1899 /* mov di, word ptr cs:LCDDataList[bx] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001900 /* tempdi = pVideoMemory[LCDDataList + tempbx * 2] |
1901 (pVideoMemory[LCDDataList + tempbx * 2 + 1] << 8); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001902
1903 switch (tempbx) {
1904 case 0:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001905 case 1:
Aaro Koskinencc5c2ae2011-08-31 21:46:08 +03001906 tempdi = xgifb_epllcd_crt1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001907 break;
1908 case 2:
1909 tempdi = XGI_EPLLCDDataPtr;
1910 break;
1911 case 3:
1912 tempdi = XGI_EPLLCDDesDataPtr;
1913 break;
1914 case 4:
1915 tempdi = XGI_LCDDataTable;
1916 break;
1917 case 5:
1918 tempdi = XGI_LCDDesDataTable;
1919 break;
1920 case 6:
1921 tempdi = XGI_EPLCHLCDRegPtr;
1922 break;
1923 case 7:
1924 case 8:
1925 case 9:
1926 tempdi = NULL;
1927 break;
1928 default:
1929 break;
1930 }
1931
1932 if (tempdi == NULL) /* OEMUtil */
1933 return NULL;
1934
1935 table = tempbx;
1936 i = 0;
1937
1938 while (tempdi[i].PANELID != 0xff) {
1939 tempdx = pVBInfo->LCDResInfo;
1940 if (tempbx & 0x0080) { /* OEMUtil */
1941 tempbx &= (~0x0080);
1942 tempdx = pVBInfo->LCDTypeInfo;
1943 }
1944
1945 if (pVBInfo->LCDInfo & EnableScalingLCD)
1946 tempdx &= (~PanelResInfo);
1947
1948 if (tempdi[i].PANELID == tempdx) {
1949 tempbx = tempdi[i].MASK;
1950 tempdx = pVBInfo->LCDInfo;
1951
1952 if (ModeNo <= 0x13) /* alan 09/10/2003 */
1953 tempdx |= SetLCDStdMode;
1954
1955 if (modeflag & HalfDCLK)
1956 tempdx |= SetLCDLowResolution;
1957
1958 tempbx &= tempdx;
1959 if (tempbx == tempdi[i].CAP)
1960 break;
1961 }
1962 i++;
1963 }
1964
1965 if (table == 0) {
1966 switch (tempdi[i].DATAPTR) {
1967 case 0:
1968 return &XGI_LVDSCRT11024x768_1_H[tempal];
1969 break;
1970 case 1:
1971 return &XGI_LVDSCRT11024x768_2_H[tempal];
1972 break;
1973 case 2:
1974 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1975 break;
1976 case 3:
1977 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1978 break;
1979 case 4:
1980 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1981 break;
1982 case 5:
1983 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1984 break;
1985 case 6:
1986 return &XGI_LVDSCRT11600x1200_1_H[tempal];
1987 break;
1988 case 7:
1989 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
1990 break;
1991 case 8:
1992 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
1993 break;
1994 case 9:
1995 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
1996 break;
1997 case 10:
1998 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
1999 break;
2000 default:
2001 break;
2002 }
2003 } else if (table == 1) {
2004 switch (tempdi[i].DATAPTR) {
2005 case 0:
2006 return &XGI_LVDSCRT11024x768_1_V[tempal];
2007 break;
2008 case 1:
2009 return &XGI_LVDSCRT11024x768_2_V[tempal];
2010 break;
2011 case 2:
2012 return &XGI_LVDSCRT11280x1024_1_V[tempal];
2013 break;
2014 case 3:
2015 return &XGI_LVDSCRT11280x1024_2_V[tempal];
2016 break;
2017 case 4:
2018 return &XGI_LVDSCRT11400x1050_1_V[tempal];
2019 break;
2020 case 5:
2021 return &XGI_LVDSCRT11400x1050_2_V[tempal];
2022 break;
2023 case 6:
2024 return &XGI_LVDSCRT11600x1200_1_V[tempal];
2025 break;
2026 case 7:
2027 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
2028 break;
2029 case 8:
2030 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
2031 break;
2032 case 9:
2033 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
2034 break;
2035 case 10:
2036 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
2037 break;
2038 default:
2039 break;
2040 }
2041 } else if (table == 2) {
2042 switch (tempdi[i].DATAPTR) {
2043 case 0:
2044 return &XGI_LVDS1024x768Data_1[tempal];
2045 break;
2046 case 1:
2047 return &XGI_LVDS1024x768Data_2[tempal];
2048 break;
2049 case 2:
2050 return &XGI_LVDS1280x1024Data_1[tempal];
2051 break;
2052 case 3:
2053 return &XGI_LVDS1280x1024Data_2[tempal];
2054 break;
2055 case 4:
2056 return &XGI_LVDS1400x1050Data_1[tempal];
2057 break;
2058 case 5:
2059 return &XGI_LVDS1400x1050Data_2[tempal];
2060 break;
2061 case 6:
2062 return &XGI_LVDS1600x1200Data_1[tempal];
2063 break;
2064 case 7:
2065 return &XGI_LVDSNoScalingData[tempal];
2066 break;
2067 case 8:
2068 return &XGI_LVDS1024x768Data_1x75[tempal];
2069 break;
2070 case 9:
2071 return &XGI_LVDS1024x768Data_2x75[tempal];
2072 break;
2073 case 10:
2074 return &XGI_LVDS1280x1024Data_1x75[tempal];
2075 break;
2076 case 11:
2077 return &XGI_LVDS1280x1024Data_2x75[tempal];
2078 break;
2079 case 12:
2080 return &XGI_LVDSNoScalingDatax75[tempal];
2081 break;
2082 default:
2083 break;
2084 }
2085 } else if (table == 3) {
2086 switch (tempdi[i].DATAPTR) {
2087 case 0:
2088 return &XGI_LVDS1024x768Des_1[tempal];
2089 break;
2090 case 1:
2091 return &XGI_LVDS1024x768Des_3[tempal];
2092 break;
2093 case 2:
2094 return &XGI_LVDS1024x768Des_2[tempal];
2095 break;
2096 case 3:
2097 return &XGI_LVDS1280x1024Des_1[tempal];
2098 break;
2099 case 4:
2100 return &XGI_LVDS1280x1024Des_2[tempal];
2101 break;
2102 case 5:
2103 return &XGI_LVDS1400x1050Des_1[tempal];
2104 break;
2105 case 6:
2106 return &XGI_LVDS1400x1050Des_2[tempal];
2107 break;
2108 case 7:
2109 return &XGI_LVDS1600x1200Des_1[tempal];
2110 break;
2111 case 8:
2112 return &XGI_LVDSNoScalingDesData[tempal];
2113 break;
2114 case 9:
2115 return &XGI_LVDS1024x768Des_1x75[tempal];
2116 break;
2117 case 10:
2118 return &XGI_LVDS1024x768Des_3x75[tempal];
2119 break;
2120 case 11:
2121 return &XGI_LVDS1024x768Des_2x75[tempal];
2122 break;
2123 case 12:
2124 return &XGI_LVDS1280x1024Des_1x75[tempal];
2125 break;
2126 case 13:
2127 return &XGI_LVDS1280x1024Des_2x75[tempal];
2128 break;
2129 case 14:
2130 return &XGI_LVDSNoScalingDesDatax75[tempal];
2131 break;
2132 default:
2133 break;
2134 }
2135 } else if (table == 4) {
2136 switch (tempdi[i].DATAPTR) {
2137 case 0:
2138 return &XGI_ExtLCD1024x768Data[tempal];
2139 break;
2140 case 1:
2141 return &XGI_StLCD1024x768Data[tempal];
2142 break;
2143 case 2:
2144 return &XGI_CetLCD1024x768Data[tempal];
2145 break;
2146 case 3:
2147 return &XGI_ExtLCD1280x1024Data[tempal];
2148 break;
2149 case 4:
2150 return &XGI_StLCD1280x1024Data[tempal];
2151 break;
2152 case 5:
2153 return &XGI_CetLCD1280x1024Data[tempal];
2154 break;
2155 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002156 case 7:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002157 return &xgifb_lcd_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002158 break;
2159 case 8:
2160 return &XGI_CetLCD1400x1050Data[tempal];
2161 break;
2162 case 9:
2163 return &XGI_ExtLCD1600x1200Data[tempal];
2164 break;
2165 case 10:
2166 return &XGI_StLCD1600x1200Data[tempal];
2167 break;
2168 case 11:
2169 return &XGI_NoScalingData[tempal];
2170 break;
2171 case 12:
2172 return &XGI_ExtLCD1024x768x75Data[tempal];
2173 break;
2174 case 13:
2175 return &XGI_ExtLCD1024x768x75Data[tempal];
2176 break;
2177 case 14:
2178 return &XGI_CetLCD1024x768x75Data[tempal];
2179 break;
2180 case 15:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002181 case 16:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002182 return &xgifb_lcd_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002183 break;
2184 case 17:
2185 return &XGI_CetLCD1280x1024x75Data[tempal];
2186 break;
2187 case 18:
2188 return &XGI_NoScalingDatax75[tempal];
2189 break;
2190 default:
2191 break;
2192 }
2193 } else if (table == 5) {
2194 switch (tempdi[i].DATAPTR) {
2195 case 0:
2196 return &XGI_ExtLCDDes1024x768Data[tempal];
2197 break;
2198 case 1:
2199 return &XGI_StLCDDes1024x768Data[tempal];
2200 break;
2201 case 2:
2202 return &XGI_CetLCDDes1024x768Data[tempal];
2203 break;
2204 case 3:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002205 if ((pVBInfo->VBType & VB_XGI301LV) ||
2206 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002207 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
2208 else
2209 return &XGI_ExtLCDDes1280x1024Data[tempal];
2210 break;
2211 case 4:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002212 if ((pVBInfo->VBType & VB_XGI301LV) ||
2213 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002214 return &XGI_StLCDDLDes1280x1024Data[tempal];
2215 else
2216 return &XGI_StLCDDes1280x1024Data[tempal];
2217 break;
2218 case 5:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002219 if ((pVBInfo->VBType & VB_XGI301LV) ||
2220 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002221 return &XGI_CetLCDDLDes1280x1024Data[tempal];
2222 else
2223 return &XGI_CetLCDDes1280x1024Data[tempal];
2224 break;
2225 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002226 case 7:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002227 if ((pVBInfo->VBType & VB_XGI301LV) ||
2228 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002229 return &xgifb_lcddldes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002230 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002231 return &xgifb_lcddes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002232 break;
2233 case 8:
2234 return &XGI_CetLCDDes1400x1050Data[tempal];
2235 break;
2236 case 9:
2237 return &XGI_CetLCDDes1400x1050Data2[tempal];
2238 break;
2239 case 10:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002240 if ((pVBInfo->VBType & VB_XGI301LV) ||
2241 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002242 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
2243 else
2244 return &XGI_ExtLCDDes1600x1200Data[tempal];
2245 break;
2246 case 11:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002247 if ((pVBInfo->VBType & VB_XGI301LV) ||
2248 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002249 return &XGI_StLCDDLDes1600x1200Data[tempal];
2250 else
2251 return &XGI_StLCDDes1600x1200Data[tempal];
2252 break;
2253 case 12:
2254 return &XGI_NoScalingDesData[tempal];
2255 break;
2256 case 13:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002257 case 14:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002258 return &xgifb_lcddes_1024x768x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002259 break;
2260 case 15:
2261 return &XGI_CetLCDDes1024x768x75Data[tempal];
2262 break;
2263 case 16:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002264 case 17:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002265 if ((pVBInfo->VBType & VB_XGI301LV) ||
2266 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002267 return &xgifb_lcddldes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002268 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002269 return &xgifb_lcddes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002270 break;
2271 case 18:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002272 if ((pVBInfo->VBType & VB_XGI301LV) ||
2273 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002274 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
2275 else
2276 return &XGI_CetLCDDes1280x1024x75Data[tempal];
2277 break;
2278 case 19:
2279 return &XGI_NoScalingDesDatax75[tempal];
2280 break;
2281 default:
2282 break;
2283 }
2284 } else if (table == 6) {
2285 switch (tempdi[i].DATAPTR) {
2286 case 0:
2287 return &XGI_CH7017LV1024x768[tempal];
2288 break;
2289 case 1:
2290 return &XGI_CH7017LV1400x1050[tempal];
2291 break;
2292 default:
2293 break;
2294 }
2295 }
2296 return NULL;
2297}
2298
2299static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
2300 unsigned short ModeIdIndex,
2301 unsigned short RefreshRateTableIndex,
2302 struct vb_device_info *pVBInfo)
2303{
2304 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
2305 struct XGI330_TVDataTablStruct *tempdi = NULL;
2306
2307 tempbx = BX;
2308
2309 if (ModeNo <= 0x13) {
2310 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2311 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2312 } else {
2313 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2314 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2315 }
2316
2317 tempal = tempal & 0x3f;
2318 table = tempbx;
2319
2320 switch (tempbx) {
2321 case 0:
2322 tempdi = NULL; /*EPLCHTVCRT1Ptr_H;*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002323 break;
2324 case 1:
2325 tempdi = NULL; /*EPLCHTVCRT1Ptr_V;*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002326 break;
2327 case 2:
Aaro Koskinen0c23b6d2011-08-31 21:46:09 +03002328 case 6:
2329 tempdi = xgifb_chrontel_tv;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002330 break;
2331 case 3:
2332 tempdi = NULL;
2333 break;
2334 case 4:
2335 tempdi = XGI_TVDataTable;
2336 break;
2337 case 5:
2338 tempdi = NULL;
2339 break;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002340 default:
2341 break;
2342 }
2343
2344 if (tempdi == NULL) /* OEMUtil */
2345 return NULL;
2346
2347 tempdx = pVBInfo->TVInfo;
2348
2349 if (pVBInfo->VBInfo & SetInSlaveMode)
2350 tempdx = tempdx | SetTVLockMode;
2351
2352 if (modeflag & HalfDCLK)
2353 tempdx = tempdx | SetTVLowResolution;
2354
2355 i = 0;
2356
2357 while (tempdi[i].MASK != 0xffff) {
2358 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2359 break;
2360 i++;
2361 }
2362
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002363 /* 07/05/22 */
2364 if (table == 0x00) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002365 } else if (table == 0x01) {
2366 } else if (table == 0x04) {
2367 switch (tempdi[i].DATAPTR) {
2368 case 0:
2369 return &XGI_ExtPALData[tempal];
2370 break;
2371 case 1:
2372 return &XGI_ExtNTSCData[tempal];
2373 break;
2374 case 2:
2375 return &XGI_StPALData[tempal];
2376 break;
2377 case 3:
2378 return &XGI_StNTSCData[tempal];
2379 break;
2380 case 4:
2381 return &XGI_ExtHiTVData[tempal];
2382 break;
2383 case 5:
2384 return &XGI_St2HiTVData[tempal];
2385 break;
2386 case 6:
2387 return &XGI_ExtYPbPr525iData[tempal];
2388 break;
2389 case 7:
2390 return &XGI_ExtYPbPr525pData[tempal];
2391 break;
2392 case 8:
2393 return &XGI_ExtYPbPr750pData[tempal];
2394 break;
2395 case 9:
2396 return &XGI_StYPbPr525iData[tempal];
2397 break;
2398 case 10:
2399 return &XGI_StYPbPr525pData[tempal];
2400 break;
2401 case 11:
2402 return &XGI_StYPbPr750pData[tempal];
2403 break;
2404 case 12: /* avoid system hang */
2405 return &XGI_ExtNTSCData[tempal];
2406 break;
2407 case 13:
2408 return &XGI_St1HiTVData[tempal];
2409 break;
2410 default:
2411 break;
2412 }
2413 } else if (table == 0x02) {
2414 switch (tempdi[i].DATAPTR) {
2415 case 0:
2416 return &XGI_CHTVUNTSCData[tempal];
2417 break;
2418 case 1:
2419 return &XGI_CHTVONTSCData[tempal];
2420 break;
2421 case 2:
2422 return &XGI_CHTVUPALData[tempal];
2423 break;
2424 case 3:
2425 return &XGI_CHTVOPALData[tempal];
2426 break;
2427 default:
2428 break;
2429 }
2430 } else if (table == 0x06) {
2431 }
2432 return NULL;
2433}
2434
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002435static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302436 unsigned short RefreshRateTableIndex,
2437 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002438{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302439 unsigned short tempbx;
2440 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002441
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302442 tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002443
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302444 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2445 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2446 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2447 pVBInfo);
2448 pVBInfo->VGAHT = LCDPtr->VGAHT;
2449 pVBInfo->VGAVT = LCDPtr->VGAVT;
2450 pVBInfo->HT = LCDPtr->LCDHT;
2451 pVBInfo->VT = LCDPtr->LCDVT;
2452 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002453
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302454 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2455 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2456 | EnableScalingLCD))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002457 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2458 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302459 pVBInfo->HDE = 1024;
2460 pVBInfo->VDE = 768;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002461 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2462 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302463 pVBInfo->HDE = 1280;
2464 pVBInfo->VDE = 1024;
2465 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2466 pVBInfo->HDE = 1400;
2467 pVBInfo->VDE = 1050;
2468 } else {
2469 pVBInfo->HDE = 1600;
2470 pVBInfo->VDE = 1200;
2471 }
2472 }
2473 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002474}
2475
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002476static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302477 unsigned short RefreshRateTableIndex,
2478 struct xgi_hw_device_info *HwDeviceExtension,
2479 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002480{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302481 unsigned char index;
2482 unsigned short tempbx, i;
2483 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2484 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002485
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302486 if (ModeNo <= 0x13)
2487 index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2488 else
2489 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002490
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302491 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002492
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002493 if ((pVBInfo->IF_DEF_ScaleLCD == 0) ||
2494 ((pVBInfo->IF_DEF_ScaleLCD == 1) &&
2495 (!(pVBInfo->LCDInfo & EnableScalingLCD)))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302496 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002497
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302498 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002499 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2500 XGI_GetLcdPtr(tempbx, ModeNo,
2501 ModeIdIndex,
2502 RefreshRateTableIndex,
2503 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002504
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302505 for (i = 0; i < 8; i++)
2506 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
2507 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002508
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302509 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002510
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302511 tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002512
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302513 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002514 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2515 XGI_GetLcdPtr(
2516 tempbx,
2517 ModeNo,
2518 ModeIdIndex,
2519 RefreshRateTableIndex,
2520 pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302521 for (i = 0; i < 7; i++)
2522 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2523 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002524
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302525 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302526 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002527}
2528
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002529static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2530{
2531 unsigned char tempal, tempah, tempbl, i;
2532
Aaro Koskinen58839b02011-03-13 12:26:23 +02002533 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002534 tempal = tempah & 0x0F;
2535 tempah = tempah & 0xF0;
2536 i = 0;
2537 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2538
2539 while (tempbl != 0xFF) {
2540 if (tempbl & 0x80) { /* OEMUtil */
2541 tempal = tempah;
2542 tempbl = tempbl & ~(0x80);
2543 }
2544
2545 if (tempal == tempbl)
2546 break;
2547
2548 i++;
2549
2550 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2551 }
2552
2553 return i;
2554}
2555
2556static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2557{
2558 unsigned short tempah, tempal, tempbl, i;
2559
2560 tempal = pVBInfo->LCDResInfo;
2561 tempah = pVBInfo->LCDTypeInfo;
2562
2563 i = 0;
2564 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2565
2566 while (tempbl != 0xFF) {
2567 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2568 tempal = tempah;
2569 tempbl &= ~0x80;
2570 }
2571
2572 if (tempal == tempbl)
2573 break;
2574
2575 i++;
2576 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2577 }
2578
2579 if (tempbl == 0xFF) {
2580 pVBInfo->LCDResInfo = Panel1024x768;
2581 pVBInfo->LCDTypeInfo = 0;
2582 i = 0;
2583 }
2584
2585 return i;
2586}
2587
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002588static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2589 unsigned short *VSyncWidth,
2590 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002591{
2592 unsigned short Index;
2593
2594 Index = XGI_GetLCDCapPtr(pVBInfo);
2595 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2596 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2597
2598 return;
2599}
2600
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002601static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302602 unsigned short RefreshRateTableIndex,
2603 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002604{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302605 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2606 unsigned long temp, temp1, temp2, temp3, push3;
2607 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2608 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002609
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302610 if (ModeNo > 0x13)
2611 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2612 else
2613 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002614
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302615 if (!(pVBInfo->SetFlag & Win9xDOSMode)) {
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002616 if (pVBInfo->IF_DEF_OEMUtil == 1) {
2617 tempbx = 8;
2618 LCDPtr = (struct XGI330_LCDDataDesStruct *)
2619 XGI_GetLcdPtr(tempbx,
2620 ModeNo,
2621 ModeIdIndex,
2622 RefreshRateTableIndex,
2623 pVBInfo);
2624 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002625
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002626 if ((pVBInfo->IF_DEF_OEMUtil == 0) ||
2627 (LCDPtr == NULL)) {
2628 tempbx = 3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302629 if (pVBInfo->LCDInfo & EnableScalingLCD)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002630 LCDPtr1 =
2631 (struct XGI330_LCDDataDesStruct2 *)
2632 XGI_GetLcdPtr(
2633 tempbx,
2634 ModeNo,
2635 ModeIdIndex,
2636 RefreshRateTableIndex,
2637 pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302638 else
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002639 LCDPtr =
2640 (struct XGI330_LCDDataDesStruct *)
2641 XGI_GetLcdPtr(
2642 tempbx,
2643 ModeNo,
2644 ModeIdIndex,
2645 RefreshRateTableIndex,
2646 pVBInfo);
2647 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002648
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002649 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2650 push1 = tempbx;
2651 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002652
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002653 /* GetLCDResInfo */
2654 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2655 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2656 tempax = 1024;
2657 tempbx = 768;
2658 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2659 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2660 tempax = 1280;
2661 tempbx = 1024;
2662 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2663 tempax = 1400;
2664 tempbx = 1050;
2665 } else {
2666 tempax = 1600;
2667 tempbx = 1200;
2668 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002669
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002670 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2671 pVBInfo->HDE = tempax;
2672 pVBInfo->VDE = tempbx;
2673 pVBInfo->VGAHDE = tempax;
2674 pVBInfo->VGAVDE = tempbx;
2675 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002676
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002677 if ((pVBInfo->IF_DEF_ScaleLCD == 1) &&
2678 (pVBInfo->LCDInfo & EnableScalingLCD)) {
2679 tempax = pVBInfo->HDE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302680 tempbx = pVBInfo->VDE;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002681 }
2682
2683 tempax = pVBInfo->HT;
2684
2685 if (pVBInfo->LCDInfo & EnableScalingLCD)
2686 tempbx = LCDPtr1->LCDHDES;
2687 else
2688 tempbx = LCDPtr->LCDHDES;
2689
2690 tempcx = pVBInfo->HDE;
2691 tempbx = tempbx & 0x0fff;
2692 tempcx += tempbx;
2693
2694 if (tempcx >= tempax)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302695 tempcx -= tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002696
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002697 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002698
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002699 tempcx = tempcx >> 3;
2700 tempbx = tempbx >> 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002701
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002702 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2703 (unsigned short) (tempbx & 0xff));
2704 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2705 (unsigned short) (tempcx & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002706
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002707 tempax = pVBInfo->HT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002708
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002709 if (pVBInfo->LCDInfo & EnableScalingLCD)
2710 tempbx = LCDPtr1->LCDHRS;
2711 else
2712 tempbx = LCDPtr->LCDHRS;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002713
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002714 tempcx = push2;
2715
2716 if (pVBInfo->LCDInfo & EnableScalingLCD)
2717 tempcx = LCDPtr1->LCDHSync;
2718
2719 tempcx += tempbx;
2720
2721 if (tempcx >= tempax)
2722 tempcx -= tempax;
2723
2724 tempax = tempbx & 0x07;
2725 tempax = tempax >> 5;
2726 tempcx = tempcx >> 3;
2727 tempbx = tempbx >> 3;
2728
2729 tempcx &= 0x1f;
2730 tempax |= tempcx;
2731
2732 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2733 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2734 (unsigned short) (tempbx & 0xff));
2735
2736 tempax = pVBInfo->VT;
2737 if (pVBInfo->LCDInfo & EnableScalingLCD)
2738 tempbx = LCDPtr1->LCDVDES;
2739 else
2740 tempbx = LCDPtr->LCDVDES;
2741 tempcx = pVBInfo->VDE;
2742
2743 tempbx = tempbx & 0x0fff;
2744 tempcx += tempbx;
2745 if (tempcx >= tempax)
2746 tempcx -= tempax;
2747
2748 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2749 (unsigned short) (tempbx & 0xff));
2750 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2751 (unsigned short) (tempcx & 0xff));
2752
2753 tempbx = (tempbx >> 8) & 0x07;
2754 tempcx = (tempcx >> 8) & 0x07;
2755
2756 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2757 (unsigned short) ((tempcx << 3)
2758 | tempbx));
2759
2760 tempax = pVBInfo->VT;
2761 if (pVBInfo->LCDInfo & EnableScalingLCD)
2762 tempbx = LCDPtr1->LCDVRS;
2763 else
2764 tempbx = LCDPtr->LCDVRS;
2765
2766 /* tempbx = tempbx >> 4; */
2767 tempcx = push1;
2768
2769 if (pVBInfo->LCDInfo & EnableScalingLCD)
2770 tempcx = LCDPtr1->LCDVSync;
2771
2772 tempcx += tempbx;
2773 if (tempcx >= tempax)
2774 tempcx -= tempax;
2775
2776 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2777 (unsigned short) (tempbx & 0xff));
2778 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2779 (unsigned short) (tempcx & 0x0f));
2780
2781 tempax = ((tempbx >> 8) & 0x07) << 3;
2782
2783 tempbx = pVBInfo->VGAVDE;
2784 if (tempbx != pVBInfo->VDE)
2785 tempax |= 0x40;
2786
2787 if (pVBInfo->LCDInfo & EnableLVDSDDA)
2788 tempax |= 0x40;
2789
2790 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2791 tempax);
2792
2793 tempcx = pVBInfo->VGAVT;
2794 tempbx = pVBInfo->VDE;
2795 tempax = pVBInfo->VGAVDE;
2796 tempcx -= tempax;
2797
2798 temp = tempax; /* 0430 ylshieh */
2799 temp1 = (temp << 18) / tempbx;
2800
2801 tempdx = (unsigned short) ((temp << 18) % tempbx);
2802
2803 if (tempdx != 0)
2804 temp1 += 1;
2805
2806 temp2 = temp1;
2807 push3 = temp2;
2808
2809 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2810 (unsigned short) (temp2 & 0xff));
2811 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2812 (unsigned short) ((temp2 >> 8) & 0xff));
2813
2814 tempbx = (unsigned short) (temp2 >> 16);
2815 tempax = tempbx & 0x03;
2816
2817 tempbx = pVBInfo->VGAVDE;
2818 if (tempbx == pVBInfo->VDE)
2819 tempax |= 0x04;
2820
2821 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2822
2823 if (pVBInfo->VBType & VB_XGI301C) {
2824 temp2 = push3;
2825 xgifb_reg_set(pVBInfo->Part4Port,
2826 0x3c,
2827 (unsigned short) (temp2 & 0xff));
2828 xgifb_reg_set(pVBInfo->Part4Port,
2829 0x3b,
2830 (unsigned short) ((temp2 >> 8) &
2831 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302832 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002833 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2834 ~0xc0,
2835 (unsigned short) ((tempbx &
2836 0xff) << 6));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002837
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002838 tempcx = pVBInfo->VGAVDE;
2839 if (tempcx == pVBInfo->VDE)
2840 xgifb_reg_and_or(pVBInfo->Part4Port,
2841 0x30, ~0x0c, 0x00);
2842 else
2843 xgifb_reg_and_or(pVBInfo->Part4Port,
2844 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302845 }
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002846
2847 tempcx = pVBInfo->VGAHDE;
2848 tempbx = pVBInfo->HDE;
2849
2850 temp1 = tempcx << 16;
2851
2852 tempax = (unsigned short) (temp1 / tempbx);
2853
2854 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2855 tempax = 65535;
2856
2857 temp3 = tempax;
2858 temp1 = pVBInfo->VGAHDE << 16;
2859
2860 temp1 /= temp3;
2861 temp3 = temp3 << 16;
2862 temp1 -= 1;
2863
2864 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2865
2866 tempax = (unsigned short) (temp3 & 0xff);
2867 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2868
2869 temp1 = pVBInfo->VGAVDE << 18;
2870 temp1 = temp1 / push3;
2871 tempbx = (unsigned short) (temp1 & 0xffff);
2872
2873 if (pVBInfo->LCDResInfo == Panel1024x768)
2874 tempbx -= 1;
2875
2876 tempax = ((tempbx >> 8) & 0xff) << 3;
2877 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2878 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2879 (unsigned short) (tempax & 0xff));
2880 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2881 (unsigned short) (tempbx & 0xff));
2882
2883 temp3 = temp3 >> 16;
2884
2885 if (modeflag & HalfDCLK)
2886 temp3 = temp3 >> 1;
2887
2888 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2889 (unsigned short) ((temp3 >> 8) & 0xff));
2890 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2891 (unsigned short) (temp3 & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302892 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002893}
2894
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002895/* --------------------------------------------------------------------- */
2896/* Function : XGI_GETLCDVCLKPtr */
2897/* Input : */
2898/* Output : al -> VCLK Index */
2899/* Description : */
2900/* --------------------------------------------------------------------- */
2901static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2902 struct vb_device_info *pVBInfo)
2903{
2904 unsigned short index;
2905
2906 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2907 if (pVBInfo->IF_DEF_ScaleLCD == 1) {
2908 if (pVBInfo->LCDInfo & EnableScalingLCD)
2909 return;
2910 }
2911
2912 /* index = XGI_GetLCDCapPtr(pVBInfo); */
2913 index = XGI_GetLCDCapPtr1(pVBInfo);
2914
2915 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2916 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2917 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2918 } else { /* LCDA */
2919 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2920 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2921 }
2922 }
2923 return;
2924}
2925
2926static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2927 unsigned short ModeNo, unsigned short ModeIdIndex,
2928 struct vb_device_info *pVBInfo)
2929{
2930
2931 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002932 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002933
2934 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002935 /* si+St_ResInfo */
2936 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002937 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002938 /* si+Ext_ResInfo */
2939 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002940
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002941 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2942 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002943 index = XGI_GetLCDCapPtr(pVBInfo);
2944 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2945
2946 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
2947 return tempal;
2948
2949 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002950 if (pVBInfo->VBType &
2951 (VB_XGI301B |
2952 VB_XGI302B |
2953 VB_XGI301LV |
2954 VB_XGI302LV |
2955 VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002956 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
2957 tempal = HiTVVCLKDIV2;
2958 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2959 tempal = HiTVVCLK;
2960 if (pVBInfo->TVInfo & TVSimuMode) {
2961 tempal = HiTVSimuVCLK;
2962 if (!(modeflag & Charx8Dot))
2963 tempal = HiTVTextVCLK;
2964
2965 }
2966 return tempal;
2967 }
2968
2969 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
2970 tempal = YPbPr750pVCLK;
2971 return tempal;
2972 }
2973
2974 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
2975 tempal = YPbPr525pVCLK;
2976 return tempal;
2977 }
2978
2979 tempal = NTSC1024VCLK;
2980
2981 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
2982 tempal = TVVCLKDIV2;
2983 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2984 tempal = TVVCLK;
2985 }
2986
2987 if (pVBInfo->VBInfo & SetCRT2ToTV)
2988 return tempal;
2989 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002990 } /* {End of VB} */
2991
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002992 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002993 tempal = tempal >> 2;
2994 tempal &= 0x03;
2995
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002996 /* for Dot8 Scaling LCD */
2997 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002998 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2999
3000 if (ModeNo <= 0x13)
3001 return tempal;
3002
3003 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
3004 return tempal;
3005}
3006
3007static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
3008 unsigned char *di_1, struct vb_device_info *pVBInfo)
3009{
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003010 if (pVBInfo->VBType & (VB_XGI301 | VB_XGI301B | VB_XGI302B
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003011 | VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
3012 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) && (pVBInfo->SetFlag
3013 & ProgrammingCRT2)) {
3014 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
3015 *di_1 = XGI_VBVCLKData[tempal].SR2C;
3016 }
3017 } else {
3018 *di_0 = XGI_VCLKData[tempal].SR2B;
3019 *di_1 = XGI_VCLKData[tempal].SR2C;
3020 }
3021}
3022
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003023static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303024 unsigned short RefreshRateTableIndex,
3025 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003026{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303027 unsigned char di_0, di_1, tempal;
3028 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303030 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3031 pVBInfo);
3032 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3033 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303035 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003036 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303037 (unsigned short) (0x10 * i));
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003038 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303039 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003040 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
3041 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303042 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003043 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
3044 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303045 }
3046 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003047}
3048
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003049static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303050 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003051{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303052 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303054 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
3055 | VB_XGI302LV | VB_XGI301C)) {
3056 tempcl = 0;
3057 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003058 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003059
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303060 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003061 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303062 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003063 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303064 if (!(temp & 0x40))
3065 tempcl |= ActiveCRT1;
3066 }
3067 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003068
Aaro Koskinen58839b02011-03-13 12:26:23 +02003069 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303070 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003071
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303072 if (!(temp == 0x08)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003073 /* Check ChannelA by Part1_13 [2003/10/03] */
3074 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303075 if (tempax & 0x04)
3076 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303078 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303080 if (!(tempcl & ActiveLCD))
3081 if (temp == 0x01)
3082 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303084 if (temp == 0x04)
3085 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003086
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303087 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003088 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303090 if (!(temp & 0x08))
3091 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303093 if (!(temp & 0x04))
3094 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003095
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303096 if (temp & 0x02)
3097 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303099 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3100 if (temp & 0x01)
3101 tempch |= ActiveHiTV;
3102 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303104 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003105 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303106 pVBInfo->Part2Port,
3107 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303109 if (temp & 0x10)
3110 tempch |= ActiveYPbPr;
3111 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303113 if (tempch != 0)
3114 tempcl |= ActiveTV;
3115 }
3116 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003117
Aaro Koskinen58839b02011-03-13 12:26:23 +02003118 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303119 if (tempcl & ActiveLCD) {
3120 if ((pVBInfo->SetFlag & ReserveTVOption)) {
3121 if (temp & ActiveTV)
3122 tempcl |= ActiveTV;
3123 }
3124 }
3125 temp = tempcl;
3126 tempbl = ~ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003127 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303129 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003130 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303131 } else {
3132 return;
3133 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003134}
3135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303136void XGI_GetVGAType(struct xgi_hw_device_info *HwDeviceExtension,
3137 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003138{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303139 /*
3140 if ( HwDeviceExtension->jChipType >= XG20 ) {
3141 pVBInfo->Set_VGAType = XG20;
Aaro Koskinen06587332011-03-13 12:26:10 +02003142 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303143 pVBInfo->Set_VGAType = VGA_XGI340;
3144 }
3145 */
3146 pVBInfo->Set_VGAType = HwDeviceExtension->jChipType;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003147}
3148
Bill Pemberton80adad82010-06-17 13:10:51 -04003149void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003150{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303151 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003152
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303153 if (pVBInfo->IF_DEF_LVDS == 0) {
3154 tempbx = VB_XGI302B;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003155 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303156 if (flag != 0x02) {
3157 tempbx = VB_XGI301;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003158 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303159 if (flag >= 0xB0) {
3160 tempbx = VB_XGI301B;
3161 if (flag >= 0xC0) {
3162 tempbx = VB_XGI301C;
3163 if (flag >= 0xD0) {
3164 tempbx = VB_XGI301LV;
3165 if (flag >= 0xE0) {
3166 tempbx = VB_XGI302LV;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003167 tempah = xgifb_reg_get(
3168 pVBInfo->Part4Port,
3169 0x39);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303170 if (tempah != 0xFF)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003171 tempbx =
3172 VB_XGI301C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303173 }
3174 }
3175 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003176
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303177 if (tempbx & (VB_XGI301B | VB_XGI302B)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003178 flag = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303179 pVBInfo->Part4Port,
3180 0x23);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003181
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303182 if (!(flag & 0x02))
3183 tempbx = tempbx | VB_NoLCD;
3184 }
3185 }
3186 }
3187 pVBInfo->VBType = tempbx;
3188 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003189}
3190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303191void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3192 struct xgi_hw_device_info *HwDeviceExtension,
3193 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003194{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303195 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003196
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303197 if (ModeNo <= 0x13)
3198 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3199 else
3200 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303202 pVBInfo->SetFlag = 0;
3203 pVBInfo->ModeType = modeflag & ModeInfoFlag;
3204 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003205
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303206 if (pVBInfo->VBType & 0xFFFF) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003207 /* Check Display Device */
3208 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303209 tempbx = tempbx | temp;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003210 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303211 push = temp;
3212 push = push << 8;
3213 tempax = temp << 8;
3214 tempbx = tempbx | tempax;
3215 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr | SetCRT2ToLCDA
3216 | SetInSlaveMode | DisableCRT2Display);
3217 temp = 0xFFFF ^ temp;
3218 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003219
Aaro Koskinen58839b02011-03-13 12:26:23 +02003220 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003221
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303222 if (pVBInfo->IF_DEF_LCDA == 1) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303224 if ((pVBInfo->Set_VGAType >= XG20)
3225 || (pVBInfo->Set_VGAType >= XG40)) {
3226 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003227 /* if ((pVBInfo->VBType & VB_XGI302B)
3228 || (pVBInfo->VBType & VB_XGI301LV)
3229 || (pVBInfo->VBType & VB_XGI302LV)
3230 || (pVBInfo->VBType & VB_XGI301C))
3231 */
3232 if (pVBInfo->VBType &
3233 (VB_XGI302B |
3234 VB_XGI301LV |
3235 VB_XGI302LV |
3236 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303237 if (temp & EnableDualEdge) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003238 tempbx |=
3239 SetCRT2ToDualEdge;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003240
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303241 if (temp & SetToLCDA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003242 tempbx |=
3243 SetCRT2ToLCDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303244 }
3245 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303246 }
3247 }
3248 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003249
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303250 if (pVBInfo->IF_DEF_YPbPr == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003251 /* [Billy] 07/05/04 */
3252 if (((pVBInfo->IF_DEF_LVDS == 0) &&
3253 ((pVBInfo->VBType & VB_XGI301LV) ||
3254 (pVBInfo->VBType & VB_XGI302LV) ||
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003255 (pVBInfo->VBType & VB_XGI301C)))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303256 if (temp & SetYPbPr) { /* temp = CR38 */
3257 if (pVBInfo->IF_DEF_HiVision == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003258 /* shampoo add for new
3259 * scratch */
Aaro Koskinen58839b02011-03-13 12:26:23 +02003260 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303261 pVBInfo->P3d4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003262 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303263 temp &= YPbPrMode;
3264 tempbx |= SetCRT2ToHiVisionTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003265
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303266 if (temp != YPbPrMode1080i) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003267 tempbx &=
3268 (~SetCRT2ToHiVisionTV);
3269 tempbx |=
3270 SetCRT2ToYPbPr;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303271 }
3272 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303274 /* tempbx |= SetCRT2ToYPbPr; */
3275 }
3276 }
3277 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003278
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303279 tempax = push; /* restore CR31 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003280
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303281 if (pVBInfo->IF_DEF_LVDS == 0) {
3282 if (pVBInfo->IF_DEF_YPbPr == 1) {
3283 if (pVBInfo->IF_DEF_HiVision == 1)
3284 temp = 0x09FC;
3285 else
3286 temp = 0x097C;
3287 } else {
3288 if (pVBInfo->IF_DEF_HiVision == 1)
3289 temp = 0x01FC;
3290 else
3291 temp = 0x017C;
3292 }
3293 } else { /* 3nd party chip */
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003294 temp = SetCRT2ToLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303295 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303297 if (!(tempbx & temp)) {
3298 tempax |= DisableCRT2Display;
3299 tempbx = 0;
3300 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003301
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303302 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
3303 if (!(pVBInfo->VBType & VB_NoLCD)) {
3304 if (tempbx & SetCRT2ToLCDA) {
3305 if (tempbx & SetSimuScanMode)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003306 tempbx &= (~(SetCRT2ToLCD |
3307 SetCRT2ToRAMDAC |
3308 SwitchToCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303309 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003310 tempbx &= (~(SetCRT2ToLCD |
3311 SetCRT2ToRAMDAC |
3312 SetCRT2ToTV |
3313 SwitchToCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303314 }
3315 }
3316 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003317
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303318 /* shampoo add */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003319 /* for driver abnormal */
3320 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303321 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
3322 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003323 tempbx &= (0xFF00 |
3324 SetCRT2ToRAMDAC |
3325 SwitchToCRT2 |
3326 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303327 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3328 }
3329 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003330 tempbx &= (~(SetCRT2ToRAMDAC |
3331 SetCRT2ToLCD |
3332 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303333 }
3334 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303336 if (!(pVBInfo->VBType & VB_NoLCD)) {
3337 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003338 tempbx &= (0xFF00 |
3339 SetCRT2ToLCD |
3340 SwitchToCRT2 |
3341 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303342 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3343 }
3344 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303346 if (tempbx & SetCRT2ToSCART) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003347 tempbx &= (0xFF00 |
3348 SetCRT2ToSCART |
3349 SwitchToCRT2 |
3350 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303351 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3352 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303354 if (pVBInfo->IF_DEF_YPbPr == 1) {
3355 if (tempbx & SetCRT2ToYPbPr)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003356 tempbx &= (0xFF00 |
3357 SwitchToCRT2 |
3358 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303359 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003360
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303361 if (pVBInfo->IF_DEF_HiVision == 1) {
3362 if (tempbx & SetCRT2ToHiVisionTV)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003363 tempbx &= (0xFF00 |
3364 SetCRT2ToHiVisionTV |
3365 SwitchToCRT2 |
3366 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303367 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003368
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303369 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
3370 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode)))
3371 tempbx = DisableCRT2Display;
3372 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003373
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303374 if (!(tempbx & DisableCRT2Display)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003375 if ((!(tempbx & DriverMode)) ||
3376 (!(modeflag & CRT2Mode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303377 if (pVBInfo->IF_DEF_LCDA == 1) {
3378 if (!(tempbx & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003379 tempbx |= (SetInSlaveMode |
3380 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303381 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303383 if (pVBInfo->IF_DEF_VideoCapture == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003384 if (((HwDeviceExtension->jChipType ==
3385 XG40) &&
3386 (pVBInfo->Set_VGAType == XG40)) ||
3387 ((HwDeviceExtension->jChipType ==
3388 XG41) &&
3389 (pVBInfo->Set_VGAType == XG41)) ||
3390 ((HwDeviceExtension->jChipType ==
3391 XG42) &&
3392 (pVBInfo->Set_VGAType == XG42)) ||
3393 ((HwDeviceExtension->jChipType ==
3394 XG45) &&
3395 (pVBInfo->Set_VGAType == XG45))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303396 if (ModeNo <= 13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003397 if (!(tempbx &
3398 SetCRT2ToRAMDAC)) {
3399 /*CRT2 not need
3400 * to support*/
3401 tempbx &=
3402 (0x00FF |
3403 (~SetInSlaveMode));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303404 pVBInfo->SetFlag
3405 |= EnableVCMode;
3406 }
3407 }
3408 }
3409 }
3410 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003411
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003412 /* LCD+TV can't support in slave mode
3413 * (Force LCDA+TV->LCDB) */
3414 if ((tempbx & SetInSlaveMode) &&
3415 (tempbx & SetCRT2ToLCDA)) {
3416 tempbx ^= (SetCRT2ToLCD |
3417 SetCRT2ToLCDA |
3418 SetCRT2ToDualEdge);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303419 pVBInfo->SetFlag |= ReserveTVOption;
3420 }
3421 }
3422 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003423
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303424 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003425}
3426
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303427void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3428 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003429{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303430 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003431
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303432 tempbx = 0;
3433 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003434
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303435 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3436 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003437 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].
3438 St_ModeFlag; /* si+St_ModeFlag */
3439 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].
3440 St_ResInfo; /* si+St_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303441 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003442 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].
3443 Ext_ModeFlag;
3444 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].
3445 Ext_RESINFO; /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303446 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003447
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303448 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003449 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303450 tempbx = temp;
3451 if (tempbx & SetPALTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003452 tempbx &= (SetCHTVOverScan |
3453 SetPALMTV |
3454 SetPALNTV |
3455 SetPALTV);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303456 if (tempbx & SetPALMTV)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003457 /* set to NTSC if PAL-M */
3458 tempbx &= ~SetPALTV;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303459 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003460 tempbx &= (SetCHTVOverScan |
3461 SetNTSCJ |
3462 SetPALTV);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303463 /*
3464 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003465 //PAL-M/PAL-N Info
3466 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3467 //00:PAL, 01:PAL-M, 10:PAL-N
3468 temp2 = (index1 & 0xC0) >> 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303469 tempbx |= temp2;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003470 if (temp2 & 0x02) //PAL-M
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303471 tempbx &= (~SetPALTV);
3472 }
3473 */
3474 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003475
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303476 if (pVBInfo->IF_DEF_LVDS == 0) {
3477 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3478 tempbx |= SetPALTV;
3479 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003480
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303481 if (pVBInfo->IF_DEF_YPbPr == 1) {
3482 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003483 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303484 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003485
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303486 if (index1 == YPbPrMode525i)
3487 tempbx |= SetYPbPrMode525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003488
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303489 if (index1 == YPbPrMode525p)
3490 tempbx = tempbx | SetYPbPrMode525p;
3491 if (index1 == YPbPrMode750p)
3492 tempbx = tempbx | SetYPbPrMode750p;
3493 }
3494 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003495
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303496 if (pVBInfo->IF_DEF_HiVision == 1) {
3497 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
3498 tempbx = tempbx | SetYPbPrMode1080i | SetPALTV;
3499 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003500
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303501 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003502 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3503 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303504 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003505
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003506 if (!(tempbx & SetPALTV) &&
3507 (modeflag > 13) &&
3508 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303509 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003510
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303511 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003512
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303513 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3514 if (pVBInfo->VBInfo & SetInSlaveMode)
3515 tempbx &= (~RPLLDIV2XO);
3516 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003517 if (tempbx &
3518 (SetYPbPrMode525p | SetYPbPrMode750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303519 tempbx &= (~RPLLDIV2XO);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003520 else if (!(pVBInfo->VBType &
3521 (VB_XGI301B |
3522 VB_XGI302B |
3523 VB_XGI301LV |
3524 VB_XGI302LV |
3525 VB_XGI301C))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303526 if (tempbx & TVSimuMode)
3527 tempbx &= (~RPLLDIV2XO);
3528 }
3529 }
3530 }
3531 }
3532 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003533}
3534
Bill Pemberton108afbf2010-06-17 13:10:47 -04003535unsigned char XGI_GetLCDInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303536 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003537{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303538 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003539
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303540 pVBInfo->LCDResInfo = 0;
3541 pVBInfo->LCDTypeInfo = 0;
3542 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003543
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303544 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003545 /* si+St_ModeFlag // */
3546 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303547 } else {
3548 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003549 /* si+Ext_ResInfo // */
3550 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303551 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003552
Aaro Koskinen58839b02011-03-13 12:26:23 +02003553 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303554 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003555
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303556 if (tempbx == 0)
3557 tempbx = Panel1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003558
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303559 /* LCD75 [2003/8/22] Vicent */
3560 if ((tempbx == Panel1024x768) || (tempbx == Panel1280x1024)) {
3561 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003562 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303563 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
3564 tempax &= 0x0F;
3565 else
3566 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003567
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303568 if ((resinfo == 6) || (resinfo == 9)) {
3569 if (tempax >= 3)
3570 tempbx |= PanelRef75Hz;
3571 } else if ((resinfo == 7) || (resinfo == 8)) {
3572 if (tempax >= 4)
3573 tempbx |= PanelRef75Hz;
3574 }
3575 }
3576 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003577
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303578 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003579
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303580 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003581
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303582 if (pVBInfo->IF_DEF_OEMUtil == 1)
3583 pVBInfo->LCDTypeInfo = (temp & 0xf0) >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003584
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303585 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
3586 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003587
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303588 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003589
Aaro Koskinen58839b02011-03-13 12:26:23 +02003590 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003591
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303592 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003593
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303594 if ((pVBInfo->IF_DEF_ScaleLCD == 1) && (temp & LCDNonExpanding))
3595 temp &= ~EnableScalingLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003596
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303597 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003598
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303599 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003600
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303601 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003602
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303603 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3604 if (((pVBInfo->VBType & VB_XGI302LV) || (pVBInfo->VBType
3605 & VB_XGI301C)) && (tempax & LCDDualLink)) {
3606 tempbx |= SetLCDDualLink;
3607 }
3608 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003609
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303610 if (pVBInfo->IF_DEF_LVDS == 0) {
3611 if ((pVBInfo->LCDResInfo == Panel1400x1050) && (pVBInfo->VBInfo
3612 & SetCRT2ToLCD) && (ModeNo > 0x13) && (resinfo
3613 == 9) && (!(tempbx & EnableScalingLCD)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003614 /* set to center in 1280x1024 LCDB for Panel1400x1050 */
3615 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303616 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003617
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303618 /*
3619 if (tempax & LCDBToA) {
3620 tempbx |= SetLCDBToA;
3621 }
3622 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003623
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303624 if (pVBInfo->IF_DEF_ExpLink == 1) {
3625 if (modeflag & HalfDCLK) {
3626 /* if (!(pVBInfo->LCDInfo&LCDNonExpanding)) */
3627 if (!(tempbx & SetLCDtoNonExpanding)) {
3628 tempbx |= EnableLVDSDDA;
3629 } else {
3630 if (ModeNo > 0x13) {
3631 if (pVBInfo->LCDResInfo
3632 == Panel1024x768) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003633 if (resinfo == 4) {/* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303634 tempbx |= EnableLVDSDDA;
3635 }
3636 }
3637 }
3638 }
3639 }
3640 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003641
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303642 if (pVBInfo->VBInfo & SetInSlaveMode) {
3643 if (pVBInfo->VBInfo & SetNotSimuMode)
3644 tempbx |= LCDVESATiming;
3645 } else {
3646 tempbx |= LCDVESATiming;
3647 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003648
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303649 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003650
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303651 if (pVBInfo->IF_DEF_PWD == 1) {
3652 if (pVBInfo->LCDInfo & SetPWDEnable) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003653 if ((pVBInfo->VBType & VB_XGI302LV) ||
3654 (pVBInfo->VBType & VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303655 if (!(tempax & PWDEnable))
3656 pVBInfo->LCDInfo &= ~SetPWDEnable;
3657 }
3658 }
3659 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003660
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303661 if (pVBInfo->IF_DEF_LVDS == 0) {
3662 if (tempax & (LockLCDBToA | StLCDBToA)) {
3663 if (pVBInfo->VBInfo & SetInSlaveMode) {
3664 if (!(tempax & LockLCDBToA)) {
3665 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003666 pVBInfo->VBInfo &=
3667 ~(SetSimuScanMode |
3668 SetInSlaveMode |
3669 SetCRT2ToLCD);
3670 pVBInfo->VBInfo |=
3671 SetCRT2ToLCDA |
3672 SetCRT2ToDualEdge;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303673 }
3674 }
3675 }
3676 }
3677 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003678
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303679 /*
3680 if (pVBInfo->IF_DEF_LVDS == 0) {
3681 if (tempax & (LockLCDBToA | StLCDBToA)) {
3682 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003683 if (!((!(tempax & LockLCDBToA)) &&
3684 (ModeNo > 0x13))) {
3685 pVBInfo->VBInfo &=
3686 ~(SetSimuScanMode |
3687 SetInSlaveMode |
3688 SetCRT2ToLCD);
3689 pVBInfo->VBInfo |=
3690 SetCRT2ToLCDA |
3691 SetCRT2ToDualEdge;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303692 }
3693 }
3694 }
3695 }
3696 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003697
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303698 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003699}
3700
Bill Pemberton108afbf2010-06-17 13:10:47 -04003701unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303702 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003703{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303704 if (ModeNo <= 5)
3705 ModeNo |= 1;
3706 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003707 /* for (*ModeIdIndex=0;
3708 *ModeIdIndex < sizeof(pVBInfo->SModeIDTable)
3709 / sizeof(struct XGI_StStruct);
3710 (*ModeIdIndex)++) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303711 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003712 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3713 ModeNo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303714 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003715 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3716 0xFF)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303717 return 0;
3718 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003719
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303720 if (ModeNo == 0x07)
3721 (*ModeIdIndex)++; /* 400 lines */
3722 if (ModeNo <= 3)
3723 (*ModeIdIndex) += 2; /* 400 lines */
3724 /* else 350 lines */
3725 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003726 /* for (*ModeIdIndex=0;
3727 *ModeIdIndex < sizeof(pVBInfo->EModeIDTable)
3728 / sizeof(struct XGI_ExtStruct);
3729 (*ModeIdIndex)++) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303730 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003731 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3732 ModeNo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303733 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003734 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3735 0xFF)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303736 return 0;
3737 }
3738 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003739
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303740 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003741}
3742
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003743static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3744{
3745 unsigned char ujRet = 0;
3746 unsigned char i = 0;
3747
3748 for (i = 0; i < 8; i++) {
3749 ujRet = ujRet << 1;
3750 /* ujRet |= GETBITS(ujDate >> i, 0:0); */
3751 ujRet |= (ujDate >> i) & 1;
3752 }
3753
3754 return ujRet;
3755}
3756
3757/*----------------------------------------------------------------------------*/
3758/* output */
3759/* bl[5] : LVDS signal */
3760/* bl[1] : LVDS backlight */
3761/* bl[0] : LVDS VDD */
3762/*----------------------------------------------------------------------------*/
3763static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3764{
3765 unsigned char CR4A, temp;
3766
Aaro Koskinen58839b02011-03-13 12:26:23 +02003767 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003768 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003769
Aaro Koskinen58839b02011-03-13 12:26:23 +02003770 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003771
3772 temp = XG21GPIODataTransfer(temp);
3773 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003774 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003775 return temp;
3776}
3777
3778/*----------------------------------------------------------------------------*/
3779/* output */
3780/* bl[5] : LVDS signal */
3781/* bl[1] : LVDS backlight */
3782/* bl[0] : LVDS VDD */
3783/*----------------------------------------------------------------------------*/
3784static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3785{
3786 unsigned char CR4A, CRB4, temp;
3787
Aaro Koskinen58839b02011-03-13 12:26:23 +02003788 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003789 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003790
Aaro Koskinen58839b02011-03-13 12:26:23 +02003791 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003792
3793 temp &= 0x0C;
3794 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003795 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003796 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003797 temp |= ((CRB4 & 0x04) << 3);
3798 return temp;
3799}
3800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303801void XGI_DisplayOn(struct xgi_hw_device_info *pXGIHWDE,
3802 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003803{
3804
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003805 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303806 if (pXGIHWDE->jChipType == XG21) {
3807 if (pVBInfo->IF_DEF_LVDS == 1) {
3808 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003809 /* LVDS VDD on */
3810 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303811 XGI_XG21SetPanelDelay(2, pVBInfo);
3812 }
3813 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003814 /* LVDS signal on */
3815 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303816 XGI_XG21SetPanelDelay(3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003817 /* LVDS backlight on */
3818 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303819 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003820 /* DVO/DVI signal on */
3821 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303822 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003823
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303824 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303826 if (pXGIHWDE->jChipType == XG27) {
3827 if (pVBInfo->IF_DEF_LVDS == 1) {
3828 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003829 /* LVDS VDD on */
3830 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303831 XGI_XG21SetPanelDelay(2, pVBInfo);
3832 }
3833 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003834 /* LVDS signal on */
3835 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303836 XGI_XG21SetPanelDelay(3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003837 /* LVDS backlight on */
3838 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303839 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003840 /* DVO/DVI signal on */
3841 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303842 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003843
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303844 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003845}
3846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303847void XGI_DisplayOff(struct xgi_hw_device_info *pXGIHWDE,
3848 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003849{
3850
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303851 if (pXGIHWDE->jChipType == XG21) {
3852 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003853 /* LVDS backlight off */
3854 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303855 XGI_XG21SetPanelDelay(3, pVBInfo);
3856 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003857 /* DVO/DVI signal off */
3858 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303859 }
3860 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003861
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303862 if (pXGIHWDE->jChipType == XG27) {
3863 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003864 /* LVDS backlight off */
3865 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303866 XGI_XG21SetPanelDelay(3, pVBInfo);
3867 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003868
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303869 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003870 /* DVO/DVI signal off */
3871 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303872 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003873
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003874 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003875}
3876
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003877static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003878{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003879 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303880 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003881
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003882 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303883 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003884}
3885
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003886static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003887{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303888 if (!(pVBInfo->SetFlag & Win9xDOSMode))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02003889 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003890}
3891
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003892static void XGI_SaveCRT2Info(unsigned short ModeNo,
3893 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003894{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303895 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003896
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003897 /* reserve CR34 for CRT1 Mode No */
3898 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303899 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3900 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003901 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003902}
3903
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003904static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3905 unsigned short ModeIdIndex,
3906 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003907{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303908 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003909
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303910 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
3911 if (ModeNo <= 0x13) {
3912 xres = pVBInfo->StResInfo[resindex].HTotal;
3913 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003914 /* si+St_ResInfo */
3915 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;*/
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303916 } else {
3917 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3918 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003919 /* si+St_ModeFlag */
3920 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003921
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303922 /*
3923 if (pVBInfo->IF_DEF_FSTN) {
3924 xres *= 2;
3925 yres *= 2;
3926 } else {
3927 */
3928 if (modeflag & HalfDCLK)
3929 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003930
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303931 if (modeflag & DoubleScanMode)
3932 yres *= 2;
3933 /* } */
3934 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003935
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303936 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3937 if (pVBInfo->IF_DEF_LVDS == 0) {
3938 if (pVBInfo->LCDResInfo == Panel1600x1200) {
3939 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3940 if (yres == 1024)
3941 yres = 1056;
3942 }
3943 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003944
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303945 if (pVBInfo->LCDResInfo == Panel1280x1024) {
3946 if (yres == 400)
3947 yres = 405;
3948 else if (yres == 350)
3949 yres = 360;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003950
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303951 if (pVBInfo->LCDInfo & LCDVESATiming) {
3952 if (yres == 360)
3953 yres = 375;
3954 }
3955 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003956
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303957 if (pVBInfo->LCDResInfo == Panel1024x768) {
3958 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3959 if (!(pVBInfo->LCDInfo
3960 & LCDNonExpanding)) {
3961 if (yres == 350)
3962 yres = 357;
3963 else if (yres == 400)
3964 yres = 420;
3965 else if (yres == 480)
3966 yres = 525;
3967 }
3968 }
3969 }
3970 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003971
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303972 if (xres == 720)
3973 xres = 640;
3974 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003975
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303976 pVBInfo->VGAHDE = xres;
3977 pVBInfo->HDE = xres;
3978 pVBInfo->VGAVDE = yres;
3979 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003980}
3981
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003982static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003983{
3984
Dan Carpentera65fd092011-01-04 09:02:27 +03003985 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
3986 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303987 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003988
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303989 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003990}
3991
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003992static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3993 unsigned short ModeIdIndex,
3994 unsigned short RefreshRateTableIndex,
3995 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003996{
3997 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
3998 StandTableIndex, CRT1Index;
3999
4000 pVBInfo->RVBHCMAX = 1;
4001 pVBInfo->RVBHCFACT = 1;
4002
4003 if (ModeNo <= 0x13) {
4004 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4005 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
4006 tempax = pVBInfo->StandTable[StandTableIndex].CRTC[0];
4007 tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[6];
4008 temp1 = pVBInfo->StandTable[StandTableIndex].CRTC[7];
4009 } else {
4010 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004011 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
4012 Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004013 CRT1Index &= IndexMask;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004014 temp1 = (unsigned short) pVBInfo->
4015 XGINEWUB_CRT1Table[CRT1Index].CR[0];
4016 temp2 = (unsigned short) pVBInfo->
4017 XGINEWUB_CRT1Table[CRT1Index].CR[5];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004018 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004019 tempbx = (unsigned short) pVBInfo->
4020 XGINEWUB_CRT1Table[CRT1Index].CR[8];
4021 tempcx = (unsigned short) pVBInfo->
4022 XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004023 tempcx &= 0x0100;
4024 tempcx = tempcx << 2;
4025 tempbx |= tempcx;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004026 temp1 = (unsigned short) pVBInfo->
4027 XGINEWUB_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004028 }
4029
4030 if (temp1 & 0x01)
4031 tempbx |= 0x0100;
4032
4033 if (temp1 & 0x20)
4034 tempbx |= 0x0200;
4035 tempax += 5;
4036
4037 if (modeflag & Charx8Dot)
4038 tempax *= 8;
4039 else
4040 tempax *= 9;
4041
4042 pVBInfo->VGAHT = tempax;
4043 pVBInfo->HT = tempax;
4044 tempbx++;
4045 pVBInfo->VGAVT = tempbx;
4046 pVBInfo->VT = tempbx;
4047}
4048
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004049static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304050 unsigned short RefreshRateTableIndex,
4051 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004052{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304053 unsigned short tempax = 0, tempbx, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304055 struct XGI_LCDDataStruct *LCDPtr = NULL;
4056 struct XGI_TVDataStruct *TVPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004057
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304058 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004059 /* si+St_ResInfo */
4060 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304061 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4062 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004063 /* si+Ext_ResInfo */
4064 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304065 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4066 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004067
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304068 pVBInfo->NewFlickerMode = 0;
4069 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304071 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4072 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4073 pVBInfo);
4074 return;
4075 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004076
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304077 tempbx = 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004078
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304079 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
4080 LCDPtr = (struct XGI_LCDDataStruct *) XGI_GetLcdPtr(tempbx,
4081 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4082 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304084 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
4085 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
4086 pVBInfo->VGAHT = LCDPtr->VGAHT;
4087 pVBInfo->VGAVT = LCDPtr->VGAVT;
4088 pVBInfo->HT = LCDPtr->LCDHT;
4089 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004090
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304091 if (pVBInfo->LCDResInfo == Panel1024x768) {
4092 tempax = 1024;
4093 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004094
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304095 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4096 if (pVBInfo->VGAVDE == 357)
4097 tempbx = 527;
4098 else if (pVBInfo->VGAVDE == 420)
4099 tempbx = 620;
4100 else if (pVBInfo->VGAVDE == 525)
4101 tempbx = 775;
4102 else if (pVBInfo->VGAVDE == 600)
4103 tempbx = 775;
4104 /* else if (pVBInfo->VGAVDE==350) tempbx=560; */
4105 /* else if (pVBInfo->VGAVDE==400) tempbx=640; */
4106 else
4107 tempbx = 768;
4108 } else
4109 tempbx = 768;
4110 } else if (pVBInfo->LCDResInfo == Panel1024x768x75) {
4111 tempax = 1024;
4112 tempbx = 768;
4113 } else if (pVBInfo->LCDResInfo == Panel1280x1024) {
4114 tempax = 1280;
4115 if (pVBInfo->VGAVDE == 360)
4116 tempbx = 768;
4117 else if (pVBInfo->VGAVDE == 375)
4118 tempbx = 800;
4119 else if (pVBInfo->VGAVDE == 405)
4120 tempbx = 864;
4121 else
4122 tempbx = 1024;
4123 } else if (pVBInfo->LCDResInfo == Panel1280x1024x75) {
4124 tempax = 1280;
4125 tempbx = 1024;
4126 } else if (pVBInfo->LCDResInfo == Panel1280x960) {
4127 tempax = 1280;
4128 if (pVBInfo->VGAVDE == 350)
4129 tempbx = 700;
4130 else if (pVBInfo->VGAVDE == 400)
4131 tempbx = 800;
4132 else if (pVBInfo->VGAVDE == 1024)
4133 tempbx = 960;
4134 else
4135 tempbx = 960;
4136 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
4137 tempax = 1400;
4138 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304140 if (pVBInfo->VGAVDE == 1024) {
4141 tempax = 1280;
4142 tempbx = 1024;
4143 }
4144 } else if (pVBInfo->LCDResInfo == Panel1600x1200) {
4145 tempax = 1600;
4146 tempbx = 1200; /* alan 10/14/2003 */
4147 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4148 if (pVBInfo->VGAVDE == 350)
4149 tempbx = 875;
4150 else if (pVBInfo->VGAVDE == 400)
4151 tempbx = 1000;
4152 }
4153 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004154
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304155 if (pVBInfo->LCDInfo & LCDNonExpanding) {
4156 tempax = pVBInfo->VGAHDE;
4157 tempbx = pVBInfo->VGAVDE;
4158 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004159
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304160 pVBInfo->HDE = tempax;
4161 pVBInfo->VDE = tempbx;
4162 return;
4163 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304165 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
4166 tempbx = 4;
4167 TVPtr = (struct XGI_TVDataStruct *) XGI_GetTVPtr(tempbx,
4168 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4169 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004170
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304171 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
4172 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
4173 pVBInfo->VGAHT = TVPtr->VGAHT;
4174 pVBInfo->VGAVT = TVPtr->VGAVT;
4175 pVBInfo->HDE = TVPtr->TVHDE;
4176 pVBInfo->VDE = TVPtr->TVVDE;
4177 pVBInfo->RVBHRS = TVPtr->RVBHRS;
4178 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304180 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4181 if (resinfo == 0x08)
4182 pVBInfo->NewFlickerMode = 0x40;
4183 else if (resinfo == 0x09)
4184 pVBInfo->NewFlickerMode = 0x40;
4185 else if (resinfo == 0x12)
4186 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304188 if (pVBInfo->VGAVDE == 350)
4189 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304191 tempax = ExtHiTVHT;
4192 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004193
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304194 if (pVBInfo->VBInfo & SetInSlaveMode) {
4195 if (pVBInfo->TVInfo & TVSimuMode) {
4196 tempax = StHiTVHT;
4197 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304199 if (!(modeflag & Charx8Dot)) {
4200 tempax = StHiTextTVHT;
4201 tempbx = StHiTextTVVT;
4202 }
4203 }
4204 }
4205 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4206 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
4207 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
4208 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
4209 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304211 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
4212 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
4213 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
4214 } else if (pVBInfo->TVInfo & SetYPbPrMode525i) {
4215 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
4216 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
4217 if (pVBInfo->TVInfo & NTSC1024x768)
4218 tempax = NTSC1024x768HT;
4219 }
4220 } else {
4221 tempax = PALHT;
4222 tempbx = PALVT;
4223 if (!(pVBInfo->TVInfo & SetPALTV)) {
4224 tempax = NTSCHT;
4225 tempbx = NTSCVT;
4226 if (pVBInfo->TVInfo & NTSC1024x768)
4227 tempax = NTSC1024x768HT;
4228 }
4229 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004230
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304231 pVBInfo->HT = tempax;
4232 pVBInfo->VT = tempbx;
4233 return;
4234 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004235}
4236
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004237static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304238 unsigned short RefreshRateTableIndex,
4239 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004240{
Bill Pemberton108afbf2010-06-17 13:10:47 -04004241 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004242
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304243 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
4244 pVBInfo);
4245 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
4246 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004247
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304248 if (pVBInfo->VBType & VB_XGI301) { /* shampoo 0129 */
4249 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004250 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
4251 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4252 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304253 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004254 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4255 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304256 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004257
Aaro Koskinen8104e322011-03-13 12:26:22 +02004258 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004259
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304260 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004261 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304262 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004263 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004264}
4265
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004266static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
4267 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004268{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004269 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
4270 short index;
4271 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304272
4273 if (ModeNo <= 0x13)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004274 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304275 else
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004276 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304277
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004278 index = (modeflag & ModeInfoFlag) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304279
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004280 if (index < 0)
4281 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304282
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004283 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304284}
4285
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004286static unsigned short XGI_GetOffset(unsigned short ModeNo,
4287 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304288 unsigned short RefreshRateTableIndex,
4289 struct xgi_hw_device_info *HwDeviceExtension,
4290 struct vb_device_info *pVBInfo)
4291{
4292 unsigned short temp, colordepth, modeinfo, index, infoflag,
4293 ColorDepth[] = { 0x01, 0x02, 0x04 };
4294
4295 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
4296 if (ModeNo <= 0x14)
4297 infoflag = 0;
4298 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004299 infoflag = pVBInfo->
4300 RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304301
4302 index = (modeinfo >> 8) & 0xFF;
4303
4304 temp = pVBInfo->ScreenOffset[index];
4305
4306 if (infoflag & InterlaceMode)
4307 temp = temp << 1;
4308
4309 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4310
4311 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
4312 temp = ModeNo - 0x7C;
4313 colordepth = ColorDepth[temp];
4314 temp = 0x6B;
4315 if (infoflag & InterlaceMode)
4316 temp = temp << 1;
4317 return temp * colordepth;
4318 } else {
4319 return temp * colordepth;
4320 }
4321}
4322
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004323static void XGI_SetCRT2Offset(unsigned short ModeNo,
4324 unsigned short ModeIdIndex,
4325 unsigned short RefreshRateTableIndex,
4326 struct xgi_hw_device_info *HwDeviceExtension,
4327 struct vb_device_info *pVBInfo)
4328{
4329 unsigned short offset;
4330 unsigned char temp;
4331
4332 if (pVBInfo->VBInfo & SetInSlaveMode)
4333 return;
4334
4335 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4336 HwDeviceExtension, pVBInfo);
4337 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004338 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004339 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004340 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004341 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004342 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004343}
4344
Randy Dunlap89229672010-08-10 08:46:44 -07004345static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004346{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004347 /* threshold high ,disable auto threshold */
4348 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
4349 /* threshold low default 04h */
4350 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004351}
4352
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004353static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304354 struct xgi_hw_device_info *HwDeviceExtension,
4355 unsigned short RefreshRateTableIndex,
4356 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004357{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304358 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004359
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304360 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004361 CRT1Index = pVBInfo->
4362 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304363 CRT1Index &= IndexMask;
4364 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4365 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004366
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304367 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4368 HwDeviceExtension, pVBInfo);
4369 XGI_SetCRT2FIFO(pVBInfo);
4370 /* XGI_SetCRT2Sync(ModeNo,RefreshRateTableIndex); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004371
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304372 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004373 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004374
Aaro Koskinen8104e322011-03-13 12:26:22 +02004375 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
4376 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004377}
4378
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004379static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304380 struct xgi_hw_device_info *HwDeviceExtension,
4381 unsigned short RefreshRateTableIndex,
4382 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004383{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304384 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
4385 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004386
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304387 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004388 CRT1Index = pVBInfo->
4389 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304390 CRT1Index &= IndexMask;
4391 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004392 }
4393
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304394 if (ModeNo <= 0x13)
4395 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4396 else
4397 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004398
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304399 /* bainy change table name */
4400 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004401 /* BTVGA2HT 0x08,0x09 */
4402 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004403 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304404 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004405 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004406 /* BTVGA2HDEE 0x0A,0x0C */
4407 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004408 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304409 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
4410 pushbx = pVBInfo->VGAHDE / 2 + 16;
4411 tempcx = tempcx >> 1;
4412 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4413 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004414
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304415 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4416 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004417 tempbx |= ((pVBInfo->
4418 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
4419 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304420 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4421 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
4422 tempcx &= 0x1F;
4423 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
4424 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4425 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4426 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004427
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304428 tempbx += 4;
4429 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004430
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304431 if (tempcx > (pVBInfo->VGAHT / 2))
4432 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004433
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304434 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004435
Aaro Koskinen8104e322011-03-13 12:26:22 +02004436 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304437 } else {
4438 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004439 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304440 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004441 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004442 /* BTVGA2HDEE 0x0A,0x0C */
4443 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004444 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304445 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
4446 pushbx = pVBInfo->VGAHDE + 16;
4447 tempcx = tempcx >> 1;
4448 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4449 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004450
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304451 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4452 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004453 tempbx |= ((pVBInfo->
4454 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
4455 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304456 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4457 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4458 tempcx &= 0x1F;
4459 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
4460 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4461 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4462 tempbx += 16;
4463 tempcx += 16;
4464 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004465
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304466 if (tempcx > pVBInfo->VGAHT)
4467 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004468
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304469 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004470 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304471 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004472
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304473 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
4474 tempbx = pushbx;
4475 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
4476 tempax |= (tempbx & 0xFF00);
4477 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004478 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304479 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004480 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304481 tempcx = (pVBInfo->VGAVT - 1);
4482 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004483
Aaro Koskinen8104e322011-03-13 12:26:22 +02004484 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304485 tempbx = pVBInfo->VGAVDE - 1;
4486 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004487 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304488 temp = ((tempbx & 0xFF00) << 3) >> 8;
4489 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004490 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004491
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304492 tempax = pVBInfo->VGAVDE;
4493 tempbx = pVBInfo->VGAVDE;
4494 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004495 /* BTVGA2VRS 0x10,0x11 */
4496 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
4497 /* BTVGA2VRE 0x11 */
4498 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004499
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304500 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4501 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
4502 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004503
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304504 if (temp & 0x04)
4505 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004506
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304507 if (temp & 0x080)
4508 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004509
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304510 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004511
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304512 if (temp & 0x08)
4513 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004514
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304515 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
4516 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
4517 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004518
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304519 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004520 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304521 temp = ((tempbx & 0xFF00) >> 8) << 4;
4522 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004523 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304524 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004525
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304526 if (modeflag & DoubleScanMode)
4527 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004528
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304529 if (modeflag & HalfDCLK)
4530 tempax |= 0x40;
4531
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004532 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004533}
4534
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004535static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4536{
4537 unsigned long tempax, tempbx;
4538
4539 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4540 & 0xFFFF;
4541 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4542 tempax = (tempax * pVBInfo->HT) / tempbx;
4543
4544 return (unsigned short) tempax;
4545}
4546
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004547static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304548 struct xgi_hw_device_info *HwDeviceExtension,
4549 unsigned short RefreshRateTableIndex,
4550 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004551{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304552 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4553 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004554
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304555 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004556 /* si+St_ResInfo */
4557 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304558 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4559 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004560 /* si+Ext_ResInfo */
4561 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304562 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004563 CRT1Index = pVBInfo->
4564 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304565 CRT1Index &= IndexMask;
4566 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004567
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304568 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4569 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004570
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304571 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004572 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304573 /* if (modeflag & Charx8Dot) */
4574 /* tempcx = 0x08; */
4575 /* else */
4576 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004577
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304578 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4579 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004580
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304581 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004582
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304583 if (modeflag & HalfDCLK)
4584 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004585
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304586 tempax = (tempax / tempcx) - 1;
4587 tempbx |= ((tempax & 0x00FF) << 8);
4588 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004589 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004590
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304591 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004592
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304593 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4594 if (!(pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4595 | VB_XGI302LV | VB_XGI301C)))
4596 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004597
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304598 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4599 if (pVBInfo->VBType & VB_XGI301LV) {
4600 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4601 if (resinfo == 7)
4602 temp -= 2;
4603 }
4604 } else if (resinfo == 7) {
4605 temp -= 2;
4606 }
4607 }
4608 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004609
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004610 /* 0x05 Horizontal Display Start */
4611 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4612 /* 0x06 Horizontal Blank end */
4613 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004614
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304615 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4616 if (pVBInfo->VBInfo & SetCRT2ToTV)
4617 tempax = pVBInfo->VGAHT;
4618 else
4619 tempax = XGI_GetVGAHT2(pVBInfo);
4620 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004621
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304622 if (tempax >= pVBInfo->VGAHT)
4623 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304625 if (modeflag & HalfDCLK)
4626 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004627
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304628 tempax = (tempax / tempcx) - 5;
4629 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
4630 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4631 temp = (tempbx & 0x00FF) - 1;
4632 if (!(modeflag & HalfDCLK)) {
4633 temp -= 6;
4634 if (pVBInfo->TVInfo & TVSimuMode) {
4635 temp -= 4;
4636 if (ModeNo > 0x13)
4637 temp -= 10;
4638 }
4639 }
4640 } else {
4641 /* tempcx = tempbx & 0x00FF ; */
4642 tempbx = (tempbx & 0xFF00) >> 8;
4643 tempcx = (tempcx + tempbx) >> 1;
4644 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304646 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4647 temp -= 1;
4648 if (!(modeflag & HalfDCLK)) {
4649 if ((modeflag & Charx8Dot)) {
4650 temp += 4;
4651 if (pVBInfo->VGAHDE >= 800)
4652 temp -= 6;
4653 }
4654 }
4655 } else {
4656 if (!(modeflag & HalfDCLK)) {
4657 temp -= 4;
4658 if (pVBInfo->LCDResInfo != Panel1280x960) {
4659 if (pVBInfo->VGAHDE >= 800) {
4660 temp -= 7;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004661 if (pVBInfo->ModeType ==
4662 ModeEGA) {
4663 if (pVBInfo->VGAVDE ==
4664 1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304665 temp += 15;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004666 if (pVBInfo->LCDResInfo != Panel1280x1024) {
4667 temp +=
4668 7;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304669 }
4670 }
4671 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004672
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304673 if (pVBInfo->VGAHDE >= 1280) {
4674 if (pVBInfo->LCDResInfo
4675 != Panel1280x960) {
4676 if (pVBInfo->LCDInfo
4677 & LCDNonExpanding) {
4678 temp
4679 += 28;
4680 }
4681 }
4682 }
4683 }
4684 }
4685 }
4686 }
4687 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004688
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004689 /* 0x07 Horizontal Retrace Start */
4690 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4691 /* 0x08 Horizontal Retrace End */
4692 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004693
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304694 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4695 if (pVBInfo->TVInfo & TVSimuMode) {
4696 if ((ModeNo == 0x06) || (ModeNo == 0x10) || (ModeNo
4697 == 0x11) || (ModeNo == 0x13) || (ModeNo
4698 == 0x0F)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004699 xgifb_reg_set(pVBInfo->Part1Port, 0x07, 0x5b);
4700 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0x03);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304701 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004702
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304703 if ((ModeNo == 0x00) || (ModeNo == 0x01)) {
4704 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004705 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304706 0x07, 0x2A);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004707 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304708 0x08, 0x61);
4709 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004710 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304711 0x07, 0x2A);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004712 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304713 0x08, 0x41);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004714 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304715 0x0C, 0xF0);
4716 }
4717 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004718
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304719 if ((ModeNo == 0x02) || (ModeNo == 0x03) || (ModeNo
4720 == 0x07)) {
4721 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004722 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304723 0x07, 0x54);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004724 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304725 0x08, 0x00);
4726 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004727 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304728 0x07, 0x55);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004729 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304730 0x08, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004731 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304732 0x0C, 0xF0);
4733 }
4734 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004735
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304736 if ((ModeNo == 0x04) || (ModeNo == 0x05) || (ModeNo
4737 == 0x0D) || (ModeNo == 0x50)) {
4738 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004739 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304740 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004741 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304742 0x08, 0x03);
4743 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004744 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304745 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004746 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304747 0x08, 0x02);
4748 }
4749 }
4750 }
4751 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004752
Aaro Koskinen8104e322011-03-13 12:26:22 +02004753 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004754 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004755 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004756
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304757 tempbx = pVBInfo->VGAVT;
4758 push1 = tempbx;
4759 tempcx = 0x121;
4760 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004761
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304762 if (tempbx == 357)
4763 tempbx = 350;
4764 if (tempbx == 360)
4765 tempbx = 350;
4766 if (tempbx == 375)
4767 tempbx = 350;
4768 if (tempbx == 405)
4769 tempbx = 400;
4770 if (tempbx == 525)
4771 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004772
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304773 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004774
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304775 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4776 if (pVBInfo->LCDResInfo == Panel1024x768) {
4777 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4778 if (tempbx == 350)
4779 tempbx += 5;
4780 if (tempbx == 480)
4781 tempbx += 5;
4782 }
4783 }
4784 }
4785 tempbx--;
4786 temp = tempbx & 0x00FF;
4787 tempbx--;
4788 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004789 /* 0x10 vertical Blank Start */
4790 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304791 tempbx = push2;
4792 tempbx--;
4793 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004794 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004795
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304796 if (tempbx & 0x0100)
4797 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004798
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304799 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304801 if (modeflag & DoubleScanMode)
4802 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004803
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304804 if (tempbx & 0x0200)
4805 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004806
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304807 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004808 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004809
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304810 if (tempbx & 0x0400)
4811 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004812
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004813 /* 0x11 Vertival Blank End */
4814 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304815
4816 tempax = push1;
4817 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4818 tempax = tempax >> 2;
4819 push1 = tempax; /* push ax */
4820
4821 if (resinfo != 0x09) {
4822 tempax = tempax << 1;
4823 tempbx += tempax;
4824 }
4825
4826 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4827 if (pVBInfo->VBType & VB_XGI301LV) {
4828 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
4829 tempbx -= 10;
4830 } else {
4831 if (pVBInfo->TVInfo & TVSimuMode) {
4832 if (pVBInfo->TVInfo & SetPALTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004833 if (pVBInfo->VBType &
4834 VB_XGI301LV) {
4835 if (!(pVBInfo->TVInfo &
4836 (SetYPbPrMode525p |
4837 SetYPbPrMode750p |
4838 SetYPbPrMode1080i)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304839 tempbx += 40;
4840 } else {
4841 tempbx += 40;
4842 }
4843 }
4844 }
4845 }
4846 } else {
4847 tempbx -= 10;
4848 }
4849 } else {
4850 if (pVBInfo->TVInfo & TVSimuMode) {
4851 if (pVBInfo->TVInfo & SetPALTV) {
4852 if (pVBInfo->VBType & VB_XGI301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004853 if (!(pVBInfo->TVInfo &
4854 (SetYPbPrMode525p |
4855 SetYPbPrMode750p |
4856 SetYPbPrMode1080i)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304857 tempbx += 40;
4858 } else {
4859 tempbx += 40;
4860 }
4861 }
4862 }
4863 }
4864 tempax = push1;
4865 tempax = tempax >> 2;
4866 tempax++;
4867 tempax += tempbx;
4868 push1 = tempax; /* push ax */
4869
4870 if ((pVBInfo->TVInfo & SetPALTV)) {
4871 if (tempbx <= 513) {
4872 if (tempax >= 513)
4873 tempbx = 513;
4874 }
4875 }
4876
4877 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004878 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304879 tempbx--;
4880 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004881 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304882
4883 if (tempbx & 0x0100)
4884 tempcx |= 0x0008;
4885
4886 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004887 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304888
4889 tempbx++;
4890
4891 if (tempbx & 0x0100)
4892 tempcx |= 0x0004;
4893
4894 if (tempbx & 0x0200)
4895 tempcx |= 0x0080;
4896
4897 if (tempbx & 0x0400)
4898 tempcx |= 0x0C00;
4899
4900 tempbx = push1; /* pop ax */
4901 temp = tempbx & 0x00FF;
4902 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004903 /* 0x0D vertical Retrace End */
4904 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304905
4906 if (tempbx & 0x0010)
4907 tempcx |= 0x2000;
4908
4909 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004910 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304911 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004912 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304913 tempax = modeflag;
4914 temp = (tempax & 0xFF00) >> 8;
4915
4916 temp = (temp >> 1) & 0x09;
4917
4918 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4919 temp |= 0x01;
4920
Aaro Koskinen8104e322011-03-13 12:26:22 +02004921 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4922 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4923 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304924
4925 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4926 temp = 0x80;
4927 else
4928 temp = 0x00;
4929
Aaro Koskinen8104e322011-03-13 12:26:22 +02004930 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304931
4932 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004933}
4934
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004935static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304936 unsigned short RefreshRateTableIndex,
4937 struct xgi_hw_device_info *HwDeviceExtension,
4938 struct vb_device_info *pVBInfo)
4939{
4940 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4941 modeflag, resinfo, crt2crtc;
4942 unsigned char *TimingPoint;
4943
4944 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4945
4946 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004947 /* si+St_ResInfo */
4948 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304949 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4950 crt2crtc = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
4951 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004952 /* si+Ext_ResInfo */
4953 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304954 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004955 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].
4956 Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304957 }
4958
4959 tempax = 0;
4960
4961 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4962 tempax |= 0x0800;
4963
4964 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4965 tempax |= 0x0400;
4966
4967 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4968 tempax |= 0x0200;
4969
4970 if (!(pVBInfo->TVInfo & SetPALTV))
4971 tempax |= 0x1000;
4972
4973 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4974 tempax |= 0x0100;
4975
4976 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
4977 tempax &= 0xfe00;
4978
4979 tempax = (tempax & 0xff00) >> 8;
4980
Aaro Koskinen8104e322011-03-13 12:26:22 +02004981 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304982 TimingPoint = pVBInfo->NTSCTiming;
4983
4984 if (pVBInfo->TVInfo & SetPALTV)
4985 TimingPoint = pVBInfo->PALTiming;
4986
4987 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4988 TimingPoint = pVBInfo->HiTVExtTiming;
4989
4990 if (pVBInfo->VBInfo & SetInSlaveMode)
4991 TimingPoint = pVBInfo->HiTVSt2Timing;
4992
4993 if (pVBInfo->SetFlag & TVSimuMode)
4994 TimingPoint = pVBInfo->HiTVSt1Timing;
4995
4996 if (!(modeflag & Charx8Dot))
4997 TimingPoint = pVBInfo->HiTVTextTiming;
4998 }
4999
5000 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5001 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5002 TimingPoint = pVBInfo->YPbPr525iTiming;
5003
5004 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5005 TimingPoint = pVBInfo->YPbPr525pTiming;
5006
5007 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5008 TimingPoint = pVBInfo->YPbPr750pTiming;
5009 }
5010
5011 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005012 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305013
5014 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005015 /* di->temp2[j] */
5016 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305017
5018 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005019 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305020
5021 temp = pVBInfo->NewFlickerMode;
5022 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005023 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305024
5025 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5026 tempax = 950;
5027
5028 if (pVBInfo->TVInfo & SetPALTV)
5029 tempax = 520;
5030 else
5031 tempax = 440;
5032
5033 if (pVBInfo->VDE <= tempax) {
5034 tempax -= pVBInfo->VDE;
5035 tempax = tempax >> 2;
5036 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
5037 push1 = tempax;
5038 temp = (tempax & 0xFF00) >> 8;
5039 temp += (unsigned short) TimingPoint[0];
5040
5041 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5042 | VB_XGI302LV | VB_XGI301C)) {
5043 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
5044 | SetCRT2ToSVIDEO | SetCRT2ToSCART
5045 | SetCRT2ToYPbPr)) {
5046 tempcx = pVBInfo->VGAHDE;
5047 if (tempcx >= 1024) {
5048 temp = 0x17; /* NTSC */
5049 if (pVBInfo->TVInfo & SetPALTV)
5050 temp = 0x19; /* PAL */
5051 }
5052 }
5053 }
5054
Aaro Koskinen8104e322011-03-13 12:26:22 +02005055 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305056 tempax = push1;
5057 temp = (tempax & 0xFF00) >> 8;
5058 temp += TimingPoint[1];
5059
5060 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5061 | VB_XGI302LV | VB_XGI301C)) {
5062 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
5063 | SetCRT2ToSVIDEO | SetCRT2ToSCART
5064 | SetCRT2ToYPbPr))) {
5065 tempcx = pVBInfo->VGAHDE;
5066 if (tempcx >= 1024) {
5067 temp = 0x1D; /* NTSC */
5068 if (pVBInfo->TVInfo & SetPALTV)
5069 temp = 0x52; /* PAL */
5070 }
5071 }
5072 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005073 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305074 }
5075
5076 /* 301b */
5077 tempcx = pVBInfo->HT;
5078
5079 if (XGI_IsLCDDualLink(pVBInfo))
5080 tempcx = tempcx >> 1;
5081
5082 tempcx -= 2;
5083 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005084 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305085
5086 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005087 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305088
5089 tempcx = pVBInfo->HT >> 1;
5090 push1 = tempcx; /* push cx */
5091 tempcx += 7;
5092
5093 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5094 tempcx -= 4;
5095
5096 temp = tempcx & 0x00FF;
5097 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005098 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305099
5100 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5101 tempbx += tempcx;
5102 push2 = tempbx;
5103 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005104 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305105 temp = (tempbx & 0xFF00) >> 8;
5106 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005107 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305108
5109 tempbx = push2;
5110 tempbx = tempbx + 8;
5111 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5112 tempbx = tempbx - 4;
5113 tempcx = tempbx;
5114 }
5115
5116 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005117 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305118
5119 j += 2;
5120 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
5121 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005122 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305123 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005124 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305125
5126 tempcx += 8;
5127 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5128 tempcx -= 4;
5129
5130 temp = tempcx & 0xFF;
5131 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005132 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305133
5134 tempcx = push1; /* pop cx */
5135 j += 2;
5136 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5137 tempcx -= temp;
5138 temp = tempcx & 0x00FF;
5139 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005140 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305141
5142 tempcx -= 11;
5143
5144 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
5145 tempax = XGI_GetVGAHT2(pVBInfo);
5146 tempcx = tempax - 1;
5147 }
5148 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005149 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305150
5151 tempbx = pVBInfo->VDE;
5152
5153 if (pVBInfo->VGAVDE == 360)
5154 tempbx = 746;
5155 if (pVBInfo->VGAVDE == 375)
5156 tempbx = 746;
5157 if (pVBInfo->VGAVDE == 405)
5158 tempbx = 853;
5159
5160 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005161 if (pVBInfo->VBType &
5162 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
5163 if (!(pVBInfo->TVInfo &
5164 (SetYPbPrMode525p | SetYPbPrMode750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305165 tempbx = tempbx >> 1;
5166 } else
5167 tempbx = tempbx >> 1;
5168 }
5169
5170 tempbx -= 2;
5171 temp = tempbx & 0x00FF;
5172
5173 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5174 if (pVBInfo->VBType & VB_XGI301LV) {
5175 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5176 if (pVBInfo->VBInfo & SetInSlaveMode) {
5177 if (ModeNo == 0x2f)
5178 temp += 1;
5179 }
5180 }
5181 } else {
5182 if (pVBInfo->VBInfo & SetInSlaveMode) {
5183 if (ModeNo == 0x2f)
5184 temp += 1;
5185 }
5186 }
5187 }
5188
Aaro Koskinen8104e322011-03-13 12:26:22 +02005189 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305190
5191 temp = (tempcx & 0xFF00) >> 8;
5192 temp |= ((tempbx & 0xFF00) >> 8) << 6;
5193
5194 if (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) {
5195 if (pVBInfo->VBType & VB_XGI301LV) {
5196 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5197 temp |= 0x10;
5198
5199 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5200 temp |= 0x20;
5201 }
5202 } else {
5203 temp |= 0x10;
5204 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5205 temp |= 0x20;
5206 }
5207 }
5208
Aaro Koskinen8104e322011-03-13 12:26:22 +02005209 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305210
5211 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5212 | VB_XGI302LV | VB_XGI301C)) { /* TV gatingno */
5213 tempbx = pVBInfo->VDE;
5214 tempcx = tempbx - 2;
5215
5216 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5217 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p
5218 | SetYPbPrMode750p)))
5219 tempbx = tempbx >> 1;
5220 }
5221
5222 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
5223 temp = 0;
5224 if (tempcx & 0x0400)
5225 temp |= 0x20;
5226
5227 if (tempbx & 0x0400)
5228 temp |= 0x40;
5229
Aaro Koskinen8104e322011-03-13 12:26:22 +02005230 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305231 }
5232
5233 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005234 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305235 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005236 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305237 }
5238
5239 tempbx = tempbx & 0x00FF;
5240
5241 if (!(modeflag & HalfDCLK)) {
5242 tempcx = pVBInfo->VGAHDE;
5243 if (tempcx >= pVBInfo->HDE) {
5244 tempbx |= 0x2000;
5245 tempax &= 0x00FF;
5246 }
5247 }
5248
5249 tempcx = 0x0101;
5250
5251 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
5252 if (pVBInfo->VGAHDE >= 1024) {
5253 tempcx = 0x1920;
5254 if (pVBInfo->VGAHDE >= 1280) {
5255 tempcx = 0x1420;
5256 tempbx = tempbx & 0xDFFF;
5257 }
5258 }
5259 }
5260
5261 if (!(tempbx & 0x2000)) {
5262 if (modeflag & HalfDCLK)
5263 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
5264
5265 push1 = tempbx;
5266 tempeax = pVBInfo->VGAHDE;
5267 tempebx = (tempcx & 0xFF00) >> 8;
5268 longtemp = tempeax * tempebx;
5269 tempecx = tempcx & 0x00FF;
5270 longtemp = longtemp / tempecx;
5271
5272 /* 301b */
5273 tempecx = 8 * 1024;
5274
5275 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5276 | VB_XGI302LV | VB_XGI301C)) {
5277 tempecx = tempecx * 8;
5278 }
5279
5280 longtemp = longtemp * tempecx;
5281 tempecx = pVBInfo->HDE;
5282 temp2 = longtemp % tempecx;
5283 tempeax = longtemp / tempecx;
5284 if (temp2 != 0)
5285 tempeax += 1;
5286
5287 tempax = (unsigned short) tempeax;
5288
5289 /* 301b */
5290 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5291 | VB_XGI302LV | VB_XGI301C)) {
5292 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
5293 }
5294 /* end 301b */
5295
5296 tempbx = push1;
5297 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
5298 | (tempbx & 0x00FF));
5299 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
5300 | (tempax & 0x00FF));
5301 temp = (tempax & 0xFF00) >> 8;
5302 } else {
5303 temp = (tempax & 0x00FF) >> 8;
5304 }
5305
Aaro Koskinen8104e322011-03-13 12:26:22 +02005306 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305307 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005308 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305309 temp = tempcx & 0x00FF;
5310
5311 if (tempbx & 0x2000)
5312 temp = 0;
5313
5314 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5315 temp |= 0x18;
5316
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005317 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305318 if (pVBInfo->TVInfo & SetPALTV) {
5319 tempbx = 0x0382;
5320 tempcx = 0x007e;
5321 } else {
5322 tempbx = 0x0369;
5323 tempcx = 0x0061;
5324 }
5325
5326 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005327 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305328 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005329 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305330
5331 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
5332 temp = temp << 2;
5333 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
5334
5335 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5336 temp |= 0x10;
5337
5338 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5339 temp |= 0x20;
5340
5341 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5342 temp |= 0x60;
5343 }
5344
Aaro Koskinen8104e322011-03-13 12:26:22 +02005345 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005346 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005347 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305348
5349 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))) {
5350 if (pVBInfo->TVInfo & NTSC1024x768) {
5351 TimingPoint = XGI_NTSC1024AdjTime;
5352 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005353 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305354 TimingPoint[j]);
5355 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005356 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305357 }
5358 }
5359
5360 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
5361 if (pVBInfo->VBType & VB_XGI301C) {
5362 if (pVBInfo->TVInfo & SetPALMTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005363 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305364 0x08); /* PALM Mode */
5365 }
5366
5367 if (pVBInfo->TVInfo & SetPALMTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005368 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305369 0x01);
5370 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02005371 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305372
5373 /* if ( !( pVBInfo->VBType & VB_XGI301C ) ) */
Aaro Koskinendc505562011-03-13 12:26:26 +02005374 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305375 }
5376
5377 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5378 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02005379 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305380 }
5381
5382 if (pVBInfo->VBInfo & SetCRT2ToTV)
5383 return;
5384}
5385
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005386static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305387 struct xgi_hw_device_info *HwDeviceExtension,
5388 unsigned short RefreshRateTableIndex,
5389 struct vb_device_info *pVBInfo)
5390{
5391 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
5392 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
5393
5394 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
5395
5396 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005397 /* si+St_ResInfo */
5398 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305399 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
5400 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005401 /* si+Ext_ResInfo */
5402 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305403 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005404 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
5405 Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305406 CRT1Index &= IndexMask;
5407 }
5408
5409 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5410 return;
5411
5412 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
5413
5414 if (XGI_IsLCDDualLink(pVBInfo))
5415 tempbx = tempbx >> 1;
5416
5417 tempbx -= 1;
5418 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005419 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305420 temp = (tempbx & 0xFF00) >> 8;
5421 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005422 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305423 temp = 0x01;
5424
5425 if (pVBInfo->LCDResInfo == Panel1280x1024) {
5426 if (pVBInfo->ModeType == ModeEGA) {
5427 if (pVBInfo->VGAHDE >= 1024) {
5428 temp = 0x02;
5429 if (pVBInfo->LCDInfo & LCDVESATiming)
5430 temp = 0x01;
5431 }
5432 }
5433 }
5434
Aaro Koskinen8104e322011-03-13 12:26:22 +02005435 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305436 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
5437 push1 = tempbx;
5438 tempbx--;
5439 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005440 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305441 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005442 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305443
5444 tempcx = pVBInfo->VT - 1;
5445 push2 = tempcx + 1;
5446 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005447 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305448 temp = (tempcx & 0xFF00) >> 8;
5449 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005450 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005451 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
5452 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
5453 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
5454 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305455
5456 /* Customized LCDB Des no add */
5457 tempbx = 5;
5458 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
5459 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5460 tempah = pVBInfo->LCDResInfo;
5461 tempah &= PanelResInfo;
5462
5463 if ((tempah == Panel1024x768) || (tempah == Panel1024x768x75)) {
5464 tempbx = 1024;
5465 tempcx = 768;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005466 } else if ((tempah == Panel1280x1024) ||
5467 (tempah == Panel1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305468 tempbx = 1280;
5469 tempcx = 1024;
5470 } else if (tempah == Panel1400x1050) {
5471 tempbx = 1400;
5472 tempcx = 1050;
5473 } else {
5474 tempbx = 1600;
5475 tempcx = 1200;
5476 }
5477
5478 if (pVBInfo->LCDInfo & EnableScalingLCD) {
5479 tempbx = pVBInfo->HDE;
5480 tempcx = pVBInfo->VDE;
5481 }
5482
5483 pushbx = tempbx;
5484 tempax = pVBInfo->VT;
5485 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
5486 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
5487 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
5488 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
5489 tempbx = pVBInfo->LCDVDES;
5490 tempcx += tempbx;
5491
5492 if (tempcx >= tempax)
5493 tempcx -= tempax; /* lcdvdes */
5494
5495 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005496 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305497 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005498 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305499 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
5500 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
5501 tempah = tempch;
5502 tempah = tempah << 3;
5503 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005504 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305505
5506 /* getlcdsync() */
5507 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5508 tempcx = tempbx;
5509 tempax = pVBInfo->VT;
5510 tempbx = pVBInfo->LCDVRS;
5511
5512 /* if (SetLCD_Info & EnableScalingLCD) */
5513 tempcx += tempbx;
5514 if (tempcx >= tempax)
5515 tempcx -= tempax;
5516
5517 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005518 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305519 temp = (tempbx & 0xFF00) >> 8;
5520 temp = temp << 4;
5521 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005522 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305523 tempcx = pushbx;
5524 tempax = pVBInfo->HT;
5525 tempbx = pVBInfo->LCDHDES;
5526 tempbx &= 0x0FFF;
5527
5528 if (XGI_IsLCDDualLink(pVBInfo)) {
5529 tempax = tempax >> 1;
5530 tempbx = tempbx >> 1;
5531 tempcx = tempcx >> 1;
5532 }
5533
5534 if (pVBInfo->VBType & VB_XGI302LV)
5535 tempbx += 1;
5536
5537 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
5538 tempbx += 1;
5539
5540 tempcx += tempbx;
5541
5542 if (tempcx >= tempax)
5543 tempcx -= tempax;
5544
5545 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005546 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305547 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005548 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305549 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005550 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305551 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005552 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305553
5554 /* getlcdsync() */
5555 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5556 tempcx = tempax;
5557 tempax = pVBInfo->HT;
5558 tempbx = pVBInfo->LCDHRS;
5559 /* if ( SetLCD_Info & EnableScalingLCD) */
5560 if (XGI_IsLCDDualLink(pVBInfo)) {
5561 tempax = tempax >> 1;
5562 tempbx = tempbx >> 1;
5563 tempcx = tempcx >> 1;
5564 }
5565
5566 if (pVBInfo->VBType & VB_XGI302LV)
5567 tempbx += 1;
5568
5569 tempcx += tempbx;
5570
5571 if (tempcx >= tempax)
5572 tempcx -= tempax;
5573
5574 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005575 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305576
5577 temp = (tempbx & 0xFF00) >> 8;
5578 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005579 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305580 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005581 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305582
5583 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
5584 if (pVBInfo->VGAVDE == 525) {
5585 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5586 | VB_XGI301LV | VB_XGI302LV
5587 | VB_XGI301C)) {
5588 temp = 0xC6;
5589 } else
5590 temp = 0xC4;
5591
Aaro Koskinen8104e322011-03-13 12:26:22 +02005592 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5593 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305594 }
5595
5596 if (pVBInfo->VGAVDE == 420) {
5597 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5598 | VB_XGI301LV | VB_XGI302LV
5599 | VB_XGI301C)) {
5600 temp = 0x4F;
5601 } else
5602 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005603 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305604 }
5605 }
5606}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005607
5608/* --------------------------------------------------------------------- */
5609/* Function : XGI_GetTap4Ptr */
5610/* Input : */
5611/* Output : di -> Tap4 Reg. Setting Pointer */
5612/* Description : */
5613/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005614static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305615 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005616{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305617 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305619 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005620
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305621 if (tempcx == 0) {
5622 tempax = pVBInfo->VGAHDE;
5623 tempbx = pVBInfo->HDE;
5624 } else {
5625 tempax = pVBInfo->VGAVDE;
5626 tempbx = pVBInfo->VDE;
5627 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005628
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005629 if (tempax <= tempbx)
5630 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305631 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005632 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005633
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305634 if (pVBInfo->TVInfo & SetPALTV)
5635 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005636
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305637 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005638 if ((pVBInfo->TVInfo & SetYPbPrMode525i) ||
5639 (pVBInfo->TVInfo & SetYPbPrMode525p))
5640 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305641 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5642 Tap4TimingPtr = YPbPr750pTap4Timing;
5643 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005644
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305645 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005646 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305648 i = 0;
5649 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5650 if (Tap4TimingPtr[i].DE == tempax)
5651 break;
5652 i++;
5653 }
5654 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005655}
5656
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005657static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005658{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305659 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005660
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305661 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005662
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305663 if (!(pVBInfo->VBType & VB_XGI301C))
5664 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005665
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305666 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5667 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005668 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005669
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005670 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5671 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV))) {
5672 /* Set Vertical Scaling */
5673 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305674 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005675 xgifb_reg_set(pVBInfo->Part2Port,
5676 i,
5677 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305678 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005679
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005680 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5681 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)))
5682 /* Enable V.Scaling */
5683 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305684 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005685 /* Enable H.Scaling */
5686 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005687}
5688
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005689static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305690 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005691{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305692 unsigned short i;
5693 unsigned char *tempdi;
5694 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005695
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305696 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005697 /* si+St_ResInfo */
5698 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305699 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005700 /* si+Ext_ResInfo */
5701 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005702
Aaro Koskinen8104e322011-03-13 12:26:22 +02005703 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305704 if (pVBInfo->TVInfo & SetPALTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005705 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5706 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305707 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005708 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5709 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305710 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305712 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5713 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005714
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305715 if (pVBInfo->TVInfo & SetPALMTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005716 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5717 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5718 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305719 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005720
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305721 if ((pVBInfo->VBInfo & SetCRT2ToHiVisionTV) || (pVBInfo->VBInfo
5722 & SetCRT2ToYPbPr)) {
5723 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5724 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005725
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305726 tempdi = pVBInfo->HiTVGroup3Data;
5727 if (pVBInfo->SetFlag & TVSimuMode) {
5728 tempdi = pVBInfo->HiTVGroup3Simu;
5729 if (!(modeflag & Charx8Dot))
5730 tempdi = pVBInfo->HiTVGroup3Text;
5731 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005732
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305733 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5734 tempdi = pVBInfo->Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005735
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305736 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5737 tempdi = pVBInfo->Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005738
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305739 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005740 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005741
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305742 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
5743 if (pVBInfo->TVInfo & SetYPbPrMode525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005744 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305745 }
5746 }
5747 return;
5748} /* {end of XGI_SetGroup3} */
5749
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005750static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305751 unsigned short RefreshRateTableIndex,
5752 struct xgi_hw_device_info *HwDeviceExtension,
5753 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005754{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305755 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005756
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305757 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005758
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305759 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005760 /* si+St_ResInfo */
5761 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305762 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005763 /* si+Ext_ResInfo */
5764 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005765
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305766 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005767 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005768
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305769 tempbx = pVBInfo->RVBHCMAX;
5770 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005771 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305772 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5773 tempcx = pVBInfo->VGAHT - 1;
5774 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005775 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005776
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305777 temp = ((tempcx & 0xFF00) >> 8) << 3;
5778 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005779
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305780 tempcx = pVBInfo->VGAVT - 1;
5781 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5782 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305784 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005785 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305786 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005787 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005788 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305789 tempcx = pVBInfo->VBInfo;
5790 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005791
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305792 if (modeflag & HalfDCLK)
5793 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005794
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305795 if (XGI_IsLCDDualLink(pVBInfo))
5796 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305798 if (tempcx & SetCRT2ToHiVisionTV) {
5799 temp = 0;
5800 if (tempbx <= 1024)
5801 temp = 0xA0;
5802 if (tempbx == 1280)
5803 temp = 0xC0;
5804 } else if (tempcx & SetCRT2ToTV) {
5805 temp = 0xA0;
5806 if (tempbx <= 800)
5807 temp = 0x80;
5808 } else {
5809 temp = 0x80;
5810 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5811 temp = 0;
5812 if (tempbx > 800)
5813 temp = 0x60;
5814 }
5815 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305817 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p)) {
5818 temp = 0x00;
5819 if (pVBInfo->VGAHDE == 1280)
5820 temp = 0x40;
5821 if (pVBInfo->VGAHDE == 1024)
5822 temp = 0x20;
5823 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005824 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305826 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005827
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305828 if (tempcx & SetCRT2ToHiVisionTV) {
5829 if (!(temp & 0xE000))
5830 tempbx = tempbx >> 1;
5831 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305833 tempcx = pVBInfo->RVBHRS;
5834 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005835 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005836
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305837 tempeax = pVBInfo->VGAVDE;
5838 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005839
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305840 if (tempeax <= tempebx) {
5841 tempcx = (tempcx & (~0x4000));
5842 tempeax = pVBInfo->VGAVDE;
5843 } else {
5844 tempeax -= tempebx;
5845 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305847 templong = (tempeax * 256 * 1024) % tempebx;
5848 tempeax = (tempeax * 256 * 1024) / tempebx;
5849 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005850
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305851 if (templong != 0)
5852 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305854 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005855 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005856
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305857 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005858 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305859 tempbx = (unsigned short) (tempebx >> 16);
5860 temp = tempbx & 0x00FF;
5861 temp = temp << 4;
5862 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005863 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005864
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305865 /* 301b */
5866 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5867 | VB_XGI302LV | VB_XGI301C)) {
5868 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005869 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305870 tempax = pVBInfo->VGAHDE;
5871 if (modeflag & HalfDCLK)
5872 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005873
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305874 if (XGI_IsLCDDualLink(pVBInfo))
5875 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005876
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005877 /* if((pVBInfo->VBInfo&(SetCRT2ToLCD)) ||
5878 ((pVBInfo->TVInfo&SetYPbPrMode525p) ||
5879 (pVBInfo->TVInfo&SetYPbPrMode750p))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305880 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5881 if (tempax > 800)
5882 tempax -= 800;
5883 } else {
5884 if (pVBInfo->VGAHDE > 800) {
5885 if (pVBInfo->VGAHDE == 1024)
5886 tempax = (tempax * 25 / 32) - 1;
5887 else
5888 tempax = (tempax * 20 / 32) - 1;
5889 }
5890 }
5891 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005892
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305893 /*
5894 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5895 if (pVBInfo->VBType & VB_XGI301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005896 if (!(pVBInfo->TVInfo &
5897 (SetYPbPrMode525p |
5898 SetYPbPrMode750p |
5899 SetYPbPrMode1080i))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305900 if (pVBInfo->VGAHDE > 800) {
5901 if (pVBInfo->VGAHDE == 1024)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005902 tempax =(tempax * 25 /
5903 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305904 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005905 tempax = (tempax * 20 /
5906 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305907 }
5908 }
5909 } else {
5910 if (pVBInfo->VGAHDE > 800) {
5911 if (pVBInfo->VGAHDE == 1024)
5912 tempax = (tempax * 25 / 32) - 1;
5913 else
5914 tempax = (tempax * 20 / 32) - 1;
5915 }
5916 }
5917 }
5918 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005919
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305920 temp = (tempax & 0xFF00) >> 8;
5921 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005922 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305923 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005924 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005925
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305926 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5927 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005928 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005929
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305930 }
5931 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005932
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305933 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5934 if (!(pVBInfo->TVInfo & (NTSC1024x768
5935 | SetYPbPrMode525p | SetYPbPrMode750p
5936 | SetYPbPrMode1080i))) {
5937 temp |= 0x0001;
5938 if ((pVBInfo->VBInfo & SetInSlaveMode)
5939 && (!(pVBInfo->TVInfo
5940 & TVSimuMode)))
5941 temp &= (~0x0001);
5942 }
5943 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005944
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005945 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305946 tempbx = pVBInfo->HT;
5947 if (XGI_IsLCDDualLink(pVBInfo))
5948 tempbx = tempbx >> 1;
5949 tempbx = (tempbx >> 1) - 2;
5950 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005951 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305952 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005953 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305954 }
5955 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005956
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305957 if (pVBInfo->ISXPDOS == 0)
5958 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5959 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005960}
5961
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005962static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5963{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005964 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005965}
5966
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005967static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305968 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005969{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305970 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005971
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305972 Pindex = pVBInfo->Part5Port;
5973 Pdata = pVBInfo->Part5Port + 1;
5974 if (pVBInfo->ModeType == ModeVGA) {
5975 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
5976 | CRT2DisplayFlag))) {
5977 XGINew_EnableCRT2(pVBInfo);
5978 /* LoadDAC2(pVBInfo->Part5Port, ModeNo, ModeIdIndex); */
5979 }
5980 }
5981 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005982}
5983
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005984static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305985 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005986{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005987 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005988}
5989
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005990static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305991 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005992{
5993
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005994 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005995}
5996
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005997/*----------------------------------------------------------------------------*/
5998/* input */
5999/* bl[5] : 1;LVDS signal on */
6000/* bl[1] : 1;LVDS backlight on */
6001/* bl[0] : 1:LVDS VDD on */
6002/* bh: 100000b : clear bit 5, to set bit5 */
6003/* 000010b : clear bit 1, to set bit1 */
6004/* 000001b : clear bit 0, to set bit0 */
6005/*----------------------------------------------------------------------------*/
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306006void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
6007 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006008{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306009 unsigned char CR4A, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006010
Aaro Koskinen58839b02011-03-13 12:26:23 +02006011 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306012 tempbh &= 0x23;
6013 tempbl &= 0x23;
Aaro Koskinendc505562011-03-13 12:26:26 +02006014 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306016 if (tempbh & 0x20) {
6017 temp = (tempbl >> 4) & 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006018
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006019 /* CR B4[1] */
6020 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006021
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306022 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006023
Aaro Koskinen58839b02011-03-13 12:26:23 +02006024 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006025
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306026 temp = XG21GPIODataTransfer(temp);
6027 temp &= ~tempbh;
6028 temp |= tempbl;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006029 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006030}
6031
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306032void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
6033 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006034{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306035 unsigned char CR4A, temp;
6036 unsigned short tempbh0, tempbl0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306038 tempbh0 = tempbh;
6039 tempbl0 = tempbl;
6040 tempbh0 &= 0x20;
6041 tempbl0 &= 0x20;
6042 tempbh0 >>= 3;
6043 tempbl0 >>= 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306045 if (tempbh & 0x20) {
6046 temp = (tempbl >> 4) & 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006047
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006048 /* CR B4[1] */
6049 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006050
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306051 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006052 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006053
Aaro Koskinen58839b02011-03-13 12:26:23 +02006054 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306055 tempbh &= 0x03;
6056 tempbl &= 0x03;
6057 tempbh <<= 2;
6058 tempbl <<= 2; /* GPIOC,GPIOD */
Aaro Koskinendc505562011-03-13 12:26:26 +02006059 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006060 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006061}
6062
6063/* --------------------------------------------------------------------- */
Bill Pemberton80adad82010-06-17 13:10:51 -04006064unsigned short XGI_GetLVDSOEMTableIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006065{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306066 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006067
Aaro Koskinen58839b02011-03-13 12:26:23 +02006068 index = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306069 if (index < sizeof(XGI21_LCDCapList)
6070 / sizeof(struct XGI21_LVDSCapStruct))
6071 return index;
6072 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006073}
6074
6075/* --------------------------------------------------------------------- */
6076/* Function : XGI_XG21SetPanelDelay */
6077/* Input : */
6078/* Output : */
6079/* Description : */
6080/* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
6081/* : bl : 2 ; T2 : the duration signal on and Vdd on */
6082/* : bl : 3 ; T3 : the duration between CPL off and signal off */
6083/* : bl : 4 ; T4 : the duration signal off and Vdd off */
6084/* --------------------------------------------------------------------- */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306085void XGI_XG21SetPanelDelay(unsigned short tempbl,
6086 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006087{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306088 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306090 index = XGI_GetLVDSOEMTableIndex(pVBInfo);
6091 if (tempbl == 1)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006092 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006093
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306094 if (tempbl == 2)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006095 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006096
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306097 if (tempbl == 3)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006098 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S3);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306100 if (tempbl == 4)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006101 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S4);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006102}
6103
Bill Pemberton82d6eb52010-06-17 13:10:46 -04006104unsigned char XGI_XG21CheckLVDSMode(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306105 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006106{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306107 unsigned short xres, yres, colordepth, modeflag, resindex,
6108 lvdstableindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006109
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306110 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6111 if (ModeNo <= 0x13) {
6112 xres = pVBInfo->StResInfo[resindex].HTotal;
6113 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006114 /* si+St_ResInfo */
6115 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306116 } else {
6117 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6118 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006119 /* si+St_ModeFlag */
6120 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306123 if (!(modeflag & Charx8Dot)) {
6124 xres /= 9;
6125 xres *= 8;
6126 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306128 if (ModeNo > 0x13) {
6129 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
6130 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306132 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6133 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306135 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306137 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6138 if (xres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE))
6139 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04006140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306141 if (yres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE))
6142 return 0;
6143
6144 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006145 if ((xres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6146 LVDSHDE)) ||
6147 (yres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6148 LVDSVDE))) {
6149 colordepth = XGI_GetColorDepth(ModeNo,
6150 ModeIdIndex,
6151 pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306152 if (colordepth > 2)
6153 return 0;
6154
6155 }
6156 }
6157 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006158}
6159
Bill Pemberton80adad82010-06-17 13:10:51 -04006160void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006161{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306162 unsigned char temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006163
Aaro Koskinen58839b02011-03-13 12:26:23 +02006164 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306165 temp = (temp & 1) << 6;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006166 /* SR06[6] 18bit Dither */
6167 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
6168 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
6169 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006170
6171}
6172
Bill Pemberton80adad82010-06-17 13:10:51 -04006173void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006174{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306175 unsigned char temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006176
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006177 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
6178 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306179 temp = (temp & 3) << 6;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006180 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
6181 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
6182 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
6183 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006184
6185}
6186
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006187static void xgifb_set_lvds(int chip_id,
6188 unsigned short ModeNo,
6189 unsigned short ModeIdIndex,
6190 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006191{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306192 unsigned char temp, Miscdata;
6193 unsigned short xres, yres, modeflag, resindex, lvdstableindex;
6194 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
6195 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
6196 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006197
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306198 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006199 temp = (unsigned char) ((pVBInfo->XG21_LVDSCapList[lvdstableindex].
6200 LVDS_Capability &
6201 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306202 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006203 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006204
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006205 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006206
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006207 temp = (unsigned char) (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6208 LVDS_Capability & LCDPolarity);
6209 /* SR35[7] FP VSync polarity */
6210 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
6211 /* SR30[5] FP HSync polarity */
6212 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006213
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006214 if (chip_id == XG27)
6215 XGI_SetXG27FPBits(pVBInfo);
6216 else
6217 XGI_SetXG21FPBits(pVBInfo);
6218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306219 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6220 if (ModeNo <= 0x13) {
6221 xres = pVBInfo->StResInfo[resindex].HTotal;
6222 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006223 /* si+St_ResInfo */
6224 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306225 } else {
6226 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6227 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006228 /* si+St_ModeFlag */
6229 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306230 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006231
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306232 if (!(modeflag & Charx8Dot))
6233 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006234
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306235 LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306237 LVDSHBS = xres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE
6238 - xres) / 2;
6239 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
6240 LVDSHBS -= xres / 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006241
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306242 if (LVDSHBS > LVDSHT)
6243 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006244
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306245 LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP;
6246 if (LVDSHRS > LVDSHT)
6247 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306249 LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC;
6250 if (LVDSHRE > LVDSHT)
6251 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006252
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306253 LVDSHBE = LVDSHBS + LVDSHT
6254 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306256 LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006257
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306258 LVDSVBS = yres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE
6259 - yres) / 2;
6260 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6261 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006262
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306263 if (LVDSVBS > LVDSVT)
6264 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006265
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306266 LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP;
6267 if (LVDSVRS > LVDSVT)
6268 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006269
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006270 LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].
6271 LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306272 if (LVDSVRE > LVDSVT)
6273 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006274
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306275 LVDSVBE = LVDSVBS + LVDSVT
6276 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006277
Aaro Koskinen58839b02011-03-13 12:26:23 +02006278 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006279 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006280
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306281 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006282 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006283
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306284 /* HT SR0B[1:0] CR00 */
6285 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006286 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006287 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006288
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306289 /* HBS SR0B[5:4] CR02 */
6290 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006291 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006292 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006293
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306294 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
6295 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006296 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
6297 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
6298 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006299
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306300 /* HRS SR0B[7:6] CR04 */
6301 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006302 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006303 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006304
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306305 /* Panel HRS SR2F[1:0] SR2E[7:0] */
6306 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006307 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006308 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006309
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306310 /* HRE SR0C[2] CR05[4:0] */
6311 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006312 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
6313 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006314
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306315 /* Panel HRE SR2F[7:2] */
6316 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006317 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006318
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306319 /* VT SR0A[0] CR07[5][0] CR06 */
6320 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006321 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
6322 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
6323 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006324 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006325
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306326 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
6327 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006328 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
6329 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
6330 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006331 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006332
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306333 /* VBE SR0A[4] CR16 */
6334 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006335 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006336 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006337
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306338 /* VRS SR0A[3] CR7[7][2] CR10 */
6339 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006340 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
6341 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
6342 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006343 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006344
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006345 if (chip_id == XG27) {
6346 /* Panel VRS SR35[2:0] SR34[7:0] */
6347 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
6348 (value & 0x700) >> 8);
6349 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
6350 } else {
6351 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
6352 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
6353 (value & 0x600) >> 9);
6354 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
6355 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
6356 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006357
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306358 /* VRE SR0A[5] CR11[3:0] */
6359 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006360 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
6361 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006362
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306363 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006364 if (chip_id == XG27)
6365 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6366 (value << 2) & 0xFC);
6367 else
6368 /* SR3F[7] has to be 0, h/w bug */
6369 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6370 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006371
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306372 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006373
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006374 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006375 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006376 0x2B,
6377 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6378 VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006379 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006380 0x2C,
6381 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6382 VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306383 value += 0x10;
6384 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006385
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306386 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006387 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006388 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006389 /* set data, panning = 0, shift left 1 dot*/
6390 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006391
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006392 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006393 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306394
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006395 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306396 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006397
6398}
6399
6400/* --------------------------------------------------------------------- */
6401/* Function : XGI_IsLCDON */
6402/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04006403/* Output : 0 : Skip PSC Control */
6404/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006405/* Description : */
6406/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006407static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006408{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306409 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006410
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306411 tempax = pVBInfo->VBInfo;
6412 if (tempax & SetCRT2ToDualEdge)
6413 return 0;
6414 else if (tempax & (DisableCRT2Display | SwitchToCRT2 | SetSimuScanMode))
6415 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006416
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306417 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006418}
6419
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006420/* --------------------------------------------------------------------- */
6421/* Function : XGI_DisableChISLCD */
6422/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04006423/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006424/* Description : */
6425/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006426static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006427{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306428 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006429
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306430 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006431 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006432
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306433 if (tempbx & (EnableChA | DisableChA)) {
6434 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6435 return 0;
6436 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006437
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306438 if (!(tempbx & (EnableChB | DisableChB)))
6439 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006440
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306441 if (tempah & 0x01) /* Chk LCDB Mode */
6442 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006443
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306444 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006445}
6446
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006447/* --------------------------------------------------------------------- */
6448/* Function : XGI_EnableChISLCD */
6449/* Input : */
6450/* Output : 0 -> Not LCD mode */
6451/* Description : */
6452/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006453static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006454{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306455 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006456
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306457 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006458 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006459
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306460 if (tempbx & (EnableChA | DisableChA)) {
6461 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6462 return 0;
6463 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006464
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306465 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04006466 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006467
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306468 if (tempah & 0x01) /* Chk LCDB Mode */
6469 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006470
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306471 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006472}
6473
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306474void XGI_DisableBridge(struct xgi_hw_device_info *HwDeviceExtension,
6475 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006476{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02006477 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006478
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306479 if (pVBInfo->SetFlag == Win9xDOSMode)
6480 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006481
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306482 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6483 | VB_XGI302LV | VB_XGI301C)) {
6484 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006485 if (!(pVBInfo->VBInfo &
6486 (DisableCRT2Display | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306487 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6488 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6489 tempah = 0x7F; /* Disable Channel A */
6490 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006491 /* Disable Channel B */
6492 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006493
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306494 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006495 /* force to disable Cahnnel */
6496 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006497
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306498 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006499 /* Force to disable Channel B */
6500 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306501 }
6502 }
6503 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006504
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006505 /* disable part4_1f */
6506 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006507
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306508 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6509 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
6510 || (XGI_DisableChISLCD(pVBInfo))
6511 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006512 /* LVDS Driver power down */
6513 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306514 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006515
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306516 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6517 & (DisableCRT2Display | SetCRT2ToLCDA
6518 | SetSimuScanMode))) {
6519 if (pVBInfo->SetFlag & GatingCRT)
6520 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
6521 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6522 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006523
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306524 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6525 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6526 & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006527 /* Power down */
6528 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306529 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006530
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006531 /* disable TV as primary VGA swap */
6532 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006533
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306534 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02006535 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006536
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006537 if ((pVBInfo->SetFlag & DisableChB) ||
6538 (pVBInfo->VBInfo &
6539 (DisableCRT2Display | SetSimuScanMode)) ||
6540 ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) &&
6541 (pVBInfo->VBInfo &
6542 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
6543 /* BScreenOff=1 */
6544 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006545
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006546 if ((pVBInfo->SetFlag & DisableChB) ||
6547 (pVBInfo->VBInfo &
6548 (DisableCRT2Display | SetSimuScanMode)) ||
6549 (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) ||
6550 (pVBInfo->VBInfo &
6551 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
6552 /* save Part1 index 0 */
6553 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6554 /* BTDAC = 1, avoid VB reset */
6555 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
6556 /* disable CRT2 */
6557 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6558 /* restore Part1 index 0 */
6559 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306560 }
6561 } else { /* {301} */
6562 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006563 /* BScreenOff=1 */
6564 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6565 /* Disable CRT2 */
6566 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6567 /* Disable TV asPrimary VGA swap */
6568 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306569 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006570
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306571 if (pVBInfo->VBInfo & (DisableCRT2Display | SetCRT2ToLCDA
6572 | SetSimuScanMode))
6573 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6574 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006575}
6576
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006577/* --------------------------------------------------------------------- */
6578/* Function : XGI_GetTVPtrIndex */
6579/* Input : */
6580/* Output : */
6581/* Description : bx 0 : ExtNTSC */
6582/* 1 : StNTSC */
6583/* 2 : ExtPAL */
6584/* 3 : StPAL */
6585/* 4 : ExtHiTV */
6586/* 5 : StHiTV */
6587/* 6 : Ext525i */
6588/* 7 : St525i */
6589/* 8 : Ext525p */
6590/* 9 : St525p */
6591/* A : Ext750p */
6592/* B : St750p */
6593/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006594static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006595{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306596 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006597
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306598 if (pVBInfo->TVInfo & SetPALTV)
6599 tempbx = 2;
6600 if (pVBInfo->TVInfo & SetYPbPrMode1080i)
6601 tempbx = 4;
6602 if (pVBInfo->TVInfo & SetYPbPrMode525i)
6603 tempbx = 6;
6604 if (pVBInfo->TVInfo & SetYPbPrMode525p)
6605 tempbx = 8;
6606 if (pVBInfo->TVInfo & SetYPbPrMode750p)
6607 tempbx = 10;
6608 if (pVBInfo->TVInfo & TVSimuMode)
6609 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006610
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306611 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006612}
6613
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006614/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006615/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006616/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006617/* Output : bx 0 : NTSC */
6618/* 1 : PAL */
6619/* 2 : PALM */
6620/* 3 : PALN */
6621/* 4 : NTSC1024x768 */
6622/* 5 : PAL-M 1024x768 */
6623/* 6-7: reserved */
6624/* cl 0 : YFilter1 */
6625/* 1 : YFilter2 */
6626/* ch 0 : 301A */
6627/* 1 : 301B/302B/301LV/302LV */
6628/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006629/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006630static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
6631 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006632{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006633 *tempbx = 0;
6634 *tempcl = 0;
6635 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006636
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006637 if (pVBInfo->TVInfo & SetPALTV)
6638 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006639
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006640 if (pVBInfo->TVInfo & SetPALMTV)
6641 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006642
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006643 if (pVBInfo->TVInfo & SetPALNTV)
6644 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006645
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006646 if (pVBInfo->TVInfo & NTSC1024x768) {
6647 *tempbx = 4;
6648 if (pVBInfo->TVInfo & SetPALMTV)
6649 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306650 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006651
6652 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6653 | VB_XGI302LV | VB_XGI301C)) {
6654 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
6655 & TVSimuMode)) {
6656 *tempbx += 8;
6657 *tempcl += 1;
6658 }
6659 }
6660
6661 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6662 | VB_XGI302LV | VB_XGI301C))
6663 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006664}
6665
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006666static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006667{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306668 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006669
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306670 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006671
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306672 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6673 | VB_XGI302LV | VB_XGI301C)) {
6674 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA
6675 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
6676 tempbl = 0;
6677 tempbh = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006678
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306679 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
6680 tempbl = pVBInfo->XGI_TVDelayList[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006681
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306682 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
6683 | VB_XGI301LV | VB_XGI302LV
6684 | VB_XGI301C))
6685 tempbl = pVBInfo->XGI_TVDelayList2[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006686
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306687 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6688 tempbl = tempbl >> 4;
6689 /*
6690 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
6691 tempbl = CRT2Delay1; // Get CRT2 Delay
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006692 if (pVBInfo->VBType &
6693 (VB_XGI301B |
6694 VB_XGI302B |
6695 VB_XGI301LV |
6696 VB_XGI302LV |
6697 VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306698 tempbl = CRT2Delay2;
6699 */
6700 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006701 /* Get LCD Delay */
6702 index = XGI_GetLCDCapPtr(pVBInfo);
6703 tempbh = pVBInfo->LCDCapList[index].
6704 LCD_DelayCompensation;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006705
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306706 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6707 tempbl = tempbh;
6708 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006709
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306710 tempbl &= 0x0F;
6711 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02006712 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006713
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306714 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
6715 | SetCRT2ToTV)) { /* Channel B */
6716 tempah &= 0xF0;
6717 tempah |= tempbl;
6718 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006719
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306720 if (pVBInfo->VBInfo & SetCRT2ToLCDA) { /* Channel A */
6721 tempah &= 0x0F;
6722 tempah |= tempbh;
6723 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02006724 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306725 }
6726 } else if (pVBInfo->IF_DEF_LVDS == 1) {
6727 tempbl = 0;
6728 tempbh = 0;
6729 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006730 /* / Get LCD Delay */
6731 tempah = pVBInfo->LCDCapList[
6732 XGI_GetLCDCapPtr(pVBInfo)].
6733 LCD_DelayCompensation;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306734 tempah &= 0x0f;
6735 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006736 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306737 tempah);
6738 }
6739 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006740}
6741
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006742static void XGI_SetLCDCap_A(unsigned short tempcx,
6743 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006744{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306745 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006746
Aaro Koskinen58839b02011-03-13 12:26:23 +02006747 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006748
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306749 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006750 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006751 /* Enable Dither */
6752 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006753 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306754 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006755 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306756 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006757 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306758 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006759
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306760 /*
6761 if (tempcx & EnableLCD24bpp) { // 24bits
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006762 xgifb_reg_and_or(pVBInfo->Part1Port,
6763 0x19,
6764 0x0F,
6765 (unsigned short)(0x30 | (tempcx&0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006766 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306767 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006768 xgifb_reg_and_or(pVBInfo->Part1Port,
6769 0x19,
6770 0x0F,
6771 // Enable Dither
6772 (unsigned short)(0x20 | (tempcx&0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006773 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306774 }
6775 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006776}
6777
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006778/* --------------------------------------------------------------------- */
6779/* Function : XGI_SetLCDCap_B */
6780/* Input : cx -> LCD Capability */
6781/* Output : */
6782/* Description : */
6783/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006784static void XGI_SetLCDCap_B(unsigned short tempcx,
6785 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006786{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306787 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006788 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306789 (unsigned short) (((tempcx & 0x00ff) >> 6)
6790 | 0x0c));
6791 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006792 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306793 (unsigned short) (((tempcx & 0x00ff) >> 6)
6794 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006795}
6796
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006797static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006798{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306799 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306801 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006802
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006803 /* disable down spectrum D[4] */
6804 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306805 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006806 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306807 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006808
Aaro Koskinen8104e322011-03-13 12:26:22 +02006809 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306810 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006811 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306812 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006813 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306814 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006815 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306816 pVBInfo->LCDCapList[index].Spectrum_34);
6817 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006818 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006819}
6820
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006821static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
6822{
6823 unsigned short tempcx;
6824
6825 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
6826
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006827 if (pVBInfo->VBType &
6828 (VB_XGI301B |
6829 VB_XGI302B |
6830 VB_XGI301LV |
6831 VB_XGI302LV |
6832 VB_XGI301C)) { /* 301LV/302LV only */
6833 if (pVBInfo->VBType &
6834 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006835 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006836 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006837 (unsigned char) (tempcx & 0x1F));
6838 }
6839 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006840 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006841 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
6842 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
6843 | EnablePLLSPLOW)) >> 8));
6844 }
6845
6846 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6847 | VB_XGI302LV | VB_XGI301C)) {
6848 if (pVBInfo->VBInfo & SetCRT2ToLCD)
6849 XGI_SetLCDCap_B(tempcx, pVBInfo);
6850 else if (pVBInfo->VBInfo & SetCRT2ToLCDA)
6851 XGI_SetLCDCap_A(tempcx, pVBInfo);
6852
6853 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6854 if (tempcx & EnableSpectrum)
6855 SetSpectrum(pVBInfo);
6856 }
6857 } else {
6858 /* LVDS,CH7017 */
6859 XGI_SetLCDCap_A(tempcx, pVBInfo);
6860 }
6861}
6862
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006863/* --------------------------------------------------------------------- */
6864/* Function : XGI_SetAntiFlicker */
6865/* Input : */
6866/* Output : */
6867/* Description : Set TV Customized Param. */
6868/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006869static void XGI_SetAntiFlicker(unsigned short ModeNo,
6870 unsigned short ModeIdIndex,
6871 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006872{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306873 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306875 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006876
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306877 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
6878 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006879
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306880 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6881 tempbx &= 0xFE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006882
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306883 if (ModeNo <= 0x13)
6884 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
6885 else
6886 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006887
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306888 tempbx += index;
6889 tempah = TVAntiFlickList[tempbx];
6890 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006891
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006892 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006893}
6894
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006895static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6896 unsigned short ModeIdIndex,
6897 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006898{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306899 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006900
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306901 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006902
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306903 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6904 tempbx &= 0xFE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006905
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306906 if (ModeNo <= 0x13)
6907 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
6908 else
6909 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006910
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306911 tempbx += index;
6912 tempah = TVEdgeList[tempbx];
6913 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006914
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006915 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006916}
6917
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006918static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006919{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306920 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006921
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306922 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006923
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306924 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006925
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306926 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6927 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006928
Aaro Koskinen8104e322011-03-13 12:26:22 +02006929 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306930 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006931 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306932 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006933 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306934 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006935 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306936 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006937}
6938
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006939static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306940 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006941{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306942 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306944 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006945
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306946 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006947
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306948 switch (tempbx) {
6949 case 0x00:
6950 case 0x04:
6951 filterPtr = NTSCYFilter1;
6952 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006953
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306954 case 0x01:
6955 filterPtr = PALYFilter1;
6956 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306958 case 0x02:
6959 case 0x05:
6960 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306961 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03006962 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306963 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006964
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306965 case 0x08:
6966 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306967 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306968 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306969 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03006970 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306971 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306973 default:
6974 return;
6975 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006976
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306977 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006978 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
6979 VB_StTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306980 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006981 tempal = pVBInfo->EModeIDTable[ModeIdIndex].
6982 VB_ExtTVYFilterIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006983
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306984 if (tempcl == 0)
6985 index = tempal * 4;
6986 else
6987 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006988
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306989 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006990 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
6991 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
6992 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
6993 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306994 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006995 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
6996 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
6997 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
6998 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306999 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007000
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307001 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7002 | VB_XGI302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007003 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
7004 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
7005 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307006 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007007}
7008
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007009/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007010/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007011/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007012/* Output : */
7013/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007014/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007015static void XGI_OEM310Setting(unsigned short ModeNo,
7016 unsigned short ModeIdIndex,
7017 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007018{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007019 if (pVBInfo->SetFlag & Win9xDOSMode)
7020 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007021
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007022 /* GetPart1IO(); */
7023 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007024
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007025 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
7026 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007027
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007028 if (pVBInfo->VBInfo & SetCRT2ToTV) {
7029 /* GetPart2IO() */
7030 XGI_SetPhaseIncr(pVBInfo);
7031 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
7032 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007033
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007034 if (pVBInfo->VBType & VB_XGI301)
7035 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307036 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007037}
7038
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007039/* --------------------------------------------------------------------- */
7040/* Function : XGI_SetCRT2ModeRegs */
7041/* Input : */
7042/* Output : */
7043/* Description : Origin code for crt2group */
7044/* --------------------------------------------------------------------- */
Bill Pemberton82d6eb52010-06-17 13:10:46 -04007045void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307046 struct xgi_hw_device_info *HwDeviceExtension,
7047 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007048{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307049 unsigned short tempbl;
7050 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307052 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007053
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007054 /* // fix write part1 index 0 BTDRAM bit Bug
7055 * xgifb_reg_set(pVBInfo->Part1Port, 0x03, 0x00); */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307056 tempah = 0;
7057 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007058 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307059 tempah &= ~0x10; /* BTRAMDAC */
7060 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007061
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307062 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7063 | SetCRT2ToLCD)) {
7064 tempah = 0x40; /* BTDRAM */
7065 if (ModeNo > 0x13) {
7066 tempcl = pVBInfo->ModeType;
7067 tempcl -= ModeVGA;
7068 if (tempcl >= 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007069 /* BT Color */
7070 tempah = (0x008 >> tempcl);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307071 if (tempah == 0)
7072 tempah = 1;
7073 tempah |= 0x040;
7074 }
7075 }
7076 if (pVBInfo->VBInfo & SetInSlaveMode)
7077 tempah ^= 0x50; /* BTDAC */
7078 }
7079 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007080
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307081 /* 0210 shampoo
7082 if (pVBInfo->VBInfo & DisableCRT2Display) {
7083 tempah = 0;
7084 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007085
Aaro Koskinen8104e322011-03-13 12:26:22 +02007086 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307087 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)) {
7088 tempcl = pVBInfo->ModeType;
7089 if (ModeNo > 0x13) {
7090 tempcl -= ModeVGA;
7091 if ((tempcl > 0) || (tempcl == 0)) {
7092 tempah=(0x008>>tempcl) ;
7093 if (tempah == 0)
7094 tempah = 1;
7095 tempah |= 0x040;
7096 }
7097 } else {
7098 tempah = 0x040;
7099 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307101 if (pVBInfo->VBInfo & SetInSlaveMode) {
7102 tempah = (tempah ^ 0x050);
7103 }
7104 }
7105 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007106
Aaro Koskinen8104e322011-03-13 12:26:22 +02007107 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307108 tempah = 0x08;
7109 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307111 if (pVBInfo->VBInfo & DisableCRT2Display) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007112 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307113 } else {
7114 tempah = 0x00;
7115 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007116
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307117 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7118 | SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007119 if ((pVBInfo->VBInfo & SetCRT2ToLCDA) &&
7120 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307121 tempbl &= 0xf7;
7122 tempah |= 0x01;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007123 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307124 tempbl, tempah);
7125 } else {
7126 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7127 tempbl &= 0xf7;
7128 tempah |= 0x01;
7129 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007130
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007131 if (pVBInfo->VBInfo &
7132 (SetCRT2ToRAMDAC |
7133 SetCRT2ToTV |
7134 SetCRT2ToLCD)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307135 tempbl &= 0xf8;
7136 tempah = 0x01;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307138 if (!(pVBInfo->VBInfo & SetInSlaveMode))
7139 tempah |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007140
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007141 if (!(pVBInfo->VBInfo &
7142 SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307143 tempah = tempah ^ 0x05;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007144 if (!(pVBInfo->VBInfo &
7145 SetCRT2ToLCD))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307146 tempah = tempah ^ 0x01;
7147 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007148
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007149 if (!(pVBInfo->VBInfo &
7150 SetCRT2ToDualEdge))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307151 tempah |= 0x08;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007152 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307153 0x2e, tempbl, tempah);
7154 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007155 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307156 0x2e, tempbl, tempah);
7157 }
7158 }
7159 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007160 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307161 tempah);
7162 }
7163 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307165 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
7166 | SetCRT2ToLCDA)) {
7167 tempah &= (~0x08);
7168 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
7169 & SetInSlaveMode))) {
7170 tempah |= 0x010;
7171 }
7172 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307174 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007175 /* if (!(pVBInfo->TVInfo &
7176 (SetYPbPrMode525p | SetYPbPrMode750p))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307177 tempah |= 0x020;
7178 if (ModeNo > 0x13) {
7179 if (pVBInfo->VBInfo & DriverMode)
7180 tempah = tempah ^ 0x20;
7181 }
7182 /* } */
7183 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007184
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007185 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307186 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307188 if (pVBInfo->LCDInfo & SetLCDDualLink)
7189 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307191 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007192 /* if ((!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) &&
7193 (!(pVBInfo->TVInfo &
7194 (SetYPbPrMode525p | SetYPbPrMode750p)))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307195 if (pVBInfo->TVInfo & RPLLDIV2XO)
7196 tempah |= 0x40;
7197 /* } */
7198 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007199
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307200 if ((pVBInfo->LCDResInfo == Panel1280x1024)
7201 || (pVBInfo->LCDResInfo == Panel1280x1024x75))
7202 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307204 if (pVBInfo->LCDResInfo == Panel1280x960)
7205 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007206
Aaro Koskinen8104e322011-03-13 12:26:22 +02007207 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307208 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007209
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307210 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7211 | VB_XGI302LV | VB_XGI301C)) {
7212 tempah = 0;
7213 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307215 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7216 tempbl = 0xff;
7217 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7218 tempah |= 0x04; /* shampoo 0129 */
7219 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007220
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007221 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307222 tempah = 0x00;
7223 tempbl = 0xcf;
7224 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7225 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7226 tempah |= 0x30;
7227 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007228
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007229 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307230 tempah = 0;
7231 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307233 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7234 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7235 tempah |= 0xc0;
7236 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007237 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307238 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307240 tempah = 0;
7241 tempbl = 0x7f;
7242 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) {
7243 tempbl = 0xff;
7244 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
7245 tempah |= 0x80;
7246 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007247
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007248 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007249
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307250 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7251 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007252 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
7253 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307254 }
7255 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007256}
7257
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007258static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307259 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007260{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307261 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007262
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307263 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007264
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307265 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7266 tempbx = 0x08A0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007267
7268}
7269
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307270void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7271 struct vb_device_info *pVBInfo)
7272{
7273
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007274 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007275
7276}
7277
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307278void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7279 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007280{
7281
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007282 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007283
7284}
7285
Bill Pemberton80adad82010-06-17 13:10:51 -04007286unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007287{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307288 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307290 if (pVBInfo->IF_DEF_LVDS == 1) {
7291 return 1;
7292 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007293 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307294 if ((flag == 1) || (flag == 2))
7295 return 1; /* 301b */
7296 else
7297 return 0;
7298 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007299}
7300
Bill Pemberton80adad82010-06-17 13:10:51 -04007301void XGI_LongWait(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007302{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307303 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007304
Aaro Koskinen58839b02011-03-13 12:26:23 +02007305 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007306
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307307 if (!(i & 0xC0)) {
7308 for (i = 0; i < 0xFFFF; i++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007309 if (!(inb(pVBInfo->P3da) & 0x08))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307310 break;
7311 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007312
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307313 for (i = 0; i < 0xFFFF; i++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007314 if ((inb(pVBInfo->P3da) & 0x08))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307315 break;
7316 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007317 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007318}
7319
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007320static void XGI_VBLongWait(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007321{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307322 unsigned short tempal, temp, i, j;
7323 return;
7324 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
7325 temp = 0;
7326 for (i = 0; i < 3; i++) {
7327 for (j = 0; j < 100; j++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007328 tempal = inb(pVBInfo->P3da);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307329 if (temp & 0x01) { /* VBWaitMode2 */
7330 if ((tempal & 0x08))
7331 continue;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007332
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307333 if (!(tempal & 0x08))
7334 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307336 } else { /* VBWaitMode1 */
7337 if (!(tempal & 0x08))
7338 continue;
7339
7340 if ((tempal & 0x08))
7341 break;
7342 }
7343 }
7344 temp = temp ^ 0x01;
7345 }
7346 } else {
7347 XGI_LongWait(pVBInfo);
7348 }
7349 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007350}
7351
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007352unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
7353 unsigned short ModeNo, unsigned short ModeIdIndex,
7354 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007355{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007356 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
7357 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
7358 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007359
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007360 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007361
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007362 if (ModeNo <= 0x13)
7363 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7364 else
7365 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7366
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007367 if (ModeNo < 0x14)
7368 return 0xFFFF;
7369
Aaro Koskinen58839b02011-03-13 12:26:23 +02007370 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007371 index = index >> pVBInfo->SelectCRT2Rate;
7372 index &= 0x0F;
7373
7374 if (pVBInfo->LCDInfo & LCDNonExpanding)
7375 index = 0;
7376
7377 if (index > 0)
7378 index--;
7379
7380 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007381 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
7382 if (pVBInfo->IF_DEF_LVDS == 0) {
7383 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
7384 | VB_XGI301LV | VB_XGI302LV
7385 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007386 /* 301b */
7387 temp = LCDARefreshIndex[
7388 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007389 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007390 temp = LCDRefreshIndex[
7391 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007392
7393 if (index > temp)
7394 index = temp;
7395 } else {
7396 index = 0;
7397 }
7398 }
7399 }
7400
7401 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
7402 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
7403 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
7404 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007405 if (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag &
7406 XG2xNotSupport) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007407 index++;
7408 }
7409 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007410 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
7411 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007412 index++;
7413 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007414 /* Alan 10/19/2007;
7415 * do the similar adjustment like XGISearchCRT1Rate() */
7416 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
7417 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007418 index++;
7419 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007420 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
7421 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007422 index++;
7423 }
7424 }
7425
7426 i = 0;
7427 do {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007428 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
7429 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007430 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007431 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
7432 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007433 temp &= ModeInfoFlag;
7434 if (temp < pVBInfo->ModeType)
7435 break;
7436 i++;
7437 index--;
7438
7439 } while (index != 0xFFFF);
7440 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
7441 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007442 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
7443 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007444 if (temp & InterlaceMode)
7445 i++;
7446 }
7447 }
7448 i--;
7449 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
7450 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
7451 RefreshRateTableIndex, &i, pVBInfo);
7452 }
7453 return RefreshRateTableIndex + i; /* return (0x01 | (temp1<<1)); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007454}
7455
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007456static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307457 struct xgi_hw_device_info *HwDeviceExtension,
7458 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007459{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007460 unsigned short RefreshRateTableIndex;
7461 /* unsigned short temp ; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007462
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007463 /* pVBInfo->SelectCRT2Rate = 0; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007464
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007465 pVBInfo->SetFlag |= ProgrammingCRT2;
7466 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7467 ModeIdIndex, pVBInfo);
7468 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
7469 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7470 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7471 HwDeviceExtension, pVBInfo);
7472 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7473 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007474}
7475
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007476unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
7477 struct xgi_hw_device_info *HwDeviceExtension,
7478 struct vb_device_info *pVBInfo)
7479{
7480 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
7481
7482 tempbx = pVBInfo->VBInfo;
7483 pVBInfo->SetFlag |= ProgrammingCRT2;
7484 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7485 pVBInfo->SelectCRT2Rate = 4;
7486 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7487 ModeIdIndex, pVBInfo);
7488 XGI_SaveCRT2Info(ModeNo, pVBInfo);
7489 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
7490 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7491 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7492 RefreshRateTableIndex, pVBInfo);
7493 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7494 RefreshRateTableIndex, pVBInfo);
7495 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7496 RefreshRateTableIndex, pVBInfo);
7497 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7498 HwDeviceExtension, pVBInfo);
7499 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7500 RefreshRateTableIndex, pVBInfo);
7501 XGI_SetTap4Regs(pVBInfo);
7502 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
7503 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7504 HwDeviceExtension, pVBInfo);
7505 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7506 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
7507 XGI_AutoThreshold(pVBInfo);
7508 return 1;
7509}
7510
7511void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
7512{
7513 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
7514 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
7515 0x05, 0x00 };
7516
7517 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
7518
7519 unsigned char CR17, CR63, SR31;
7520 unsigned short temp;
7521 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
7522
7523 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02007524 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007525
7526 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007527 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02007528 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007529 pVBInfo->P3d4, 0x53) | 0x02));
7530
Aaro Koskinen58839b02011-03-13 12:26:23 +02007531 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
7532 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
7533 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007534
Aaro Koskinen8104e322011-03-13 12:26:22 +02007535 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
7536 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007537
Aaro Koskinen58839b02011-03-13 12:26:23 +02007538 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007539 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007540
Aaro Koskinen58839b02011-03-13 12:26:23 +02007541 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007542 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007543
Aaro Koskinen58839b02011-03-13 12:26:23 +02007544 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007545 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02007546 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007547 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007548
Aaro Koskinen8104e322011-03-13 12:26:22 +02007549 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007550
7551 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007552 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007553
7554 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007555 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007556 CRTCData[i]);
7557
7558 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007559 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007560 CRTCData[i]);
7561
7562 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007563 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007564 CRTCData[i]);
7565
Aaro Koskinen8104e322011-03-13 12:26:22 +02007566 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007567 & 0xE0));
7568
Aaro Koskinen8104e322011-03-13 12:26:22 +02007569 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
7570 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7571 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007572
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007573 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007574
7575 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007576 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
7577 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
7578 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007579 }
7580
7581 XGI_VBLongWait(pVBInfo);
7582 XGI_VBLongWait(pVBInfo);
7583 XGI_VBLongWait(pVBInfo);
7584
7585 mdelay(1);
7586
7587 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007588 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007589
7590 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007591 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007592 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007593 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007594
7595 /* alan, avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007596 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007597
7598 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007599 outb(0, (pVBInfo->P3c8 + 1));
7600 outb(0, (pVBInfo->P3c8 + 1));
7601 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007602 }
7603
Aaro Koskinen8104e322011-03-13 12:26:22 +02007604 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
7605 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
7606 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007607
7608 /* [2004/05/11] Vicent */
Aaro Koskinen58839b02011-03-13 12:26:23 +02007609 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007610 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02007611 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007612}
7613
7614void XGI_EnableBridge(struct xgi_hw_device_info *HwDeviceExtension,
7615 struct vb_device_info *pVBInfo)
7616{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02007617 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007618
7619 if (pVBInfo->SetFlag == Win9xDOSMode) {
7620 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7621 | VB_XGI302LV | VB_XGI301C)) {
7622 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7623 return;
7624 } else
7625 /* LVDS or CH7017 */
7626 return;
7627 }
7628
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007629 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7630 | VB_XGI302LV | VB_XGI301C)) {
7631 if (!(pVBInfo->SetFlag & DisableChA)) {
7632 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007633 /* Power on */
7634 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007635 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007636 /* SetCRT2ToLCDA ) */
7637 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7638 /* Power on */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007639 xgifb_reg_set(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007640 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007641 }
7642 }
7643 }
7644
7645 if (!(pVBInfo->SetFlag & DisableChB)) {
7646 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
7647 & (SetCRT2ToLCD | SetCRT2ToTV
7648 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007649 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007650 pVBInfo->P3c4, 0x32);
7651 tempah &= 0xDF;
7652 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007653 if (!(pVBInfo->VBInfo &
7654 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007655 tempah |= 0x20;
7656 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02007657 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007658 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007659
Aaro Koskinen58839b02011-03-13 12:26:23 +02007660 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007661 pVBInfo->Part1Port, 0x2E);
7662
7663 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007664 /* BVBDOENABLE = 1 */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007665 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007666 0x2E, 0x80);
7667 /* BScreenOFF = 0 */
7668 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007669 }
7670 }
7671
7672 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
7673 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007674 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007675 0x20); /* shampoo 0129 */
7676 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7677 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007678 if (XGI_EnableChISLCD(pVBInfo) ||
7679 (pVBInfo->VBInfo &
7680 (SetCRT2ToLCD | SetCRT2ToLCDA)))
7681 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02007682 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007683 pVBInfo->Part4Port,
7684 0x2A,
7685 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007686 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007687 /* LVDS Driver power on */
7688 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007689 }
7690 }
7691
7692 tempah = 0x00;
7693
7694 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7695 tempah = 0xc0;
7696
7697 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
7698 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007699 if (pVBInfo->VBInfo &
7700 SetCRT2ToDualEdge) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007701 tempah = tempah & 0x40;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007702 if (pVBInfo->VBInfo &
7703 SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007704 tempah = tempah ^ 0xC0;
7705
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007706 if (pVBInfo->SetFlag &
7707 DisableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007708 tempah &= 0xBF;
7709
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007710 if (pVBInfo->SetFlag &
7711 DisableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007712 tempah &= 0x7F;
7713
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007714 if (pVBInfo->SetFlag &
7715 EnableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007716 tempah |= 0x40;
7717
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007718 if (pVBInfo->SetFlag &
7719 EnableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007720 tempah |= 0x80;
7721 }
7722 }
7723 }
7724 }
7725
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007726 /* EnablePart4_1F */
7727 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007728
7729 if (pVBInfo->SetFlag & Win9xDOSMode) {
7730 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7731 return;
7732 }
7733
7734 if (!(pVBInfo->SetFlag & DisableChA)) {
7735 XGI_VBLongWait(pVBInfo);
7736 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007737 XGI_DisableGatingCRT(HwDeviceExtension,
7738 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007739 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7740 XGI_VBLongWait(pVBInfo);
7741 }
7742 }
7743 } /* 301 */
7744 else { /* LVDS */
7745 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
7746 | SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007747 /* enable CRT2 */
7748 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007749
Aaro Koskinen58839b02011-03-13 12:26:23 +02007750 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007751 0x2E);
7752 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007753 /* BVBDOENABLE = 1 */
7754 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007755
Aaro Koskinendc505562011-03-13 12:26:26 +02007756 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007757 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7758 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007759}
7760
7761static void XGI_SetCRT1Group(struct xgi_hw_device_info *HwDeviceExtension,
7762 unsigned short ModeNo, unsigned short ModeIdIndex,
7763 struct vb_device_info *pVBInfo)
7764{
7765 unsigned short StandTableIndex, RefreshRateTableIndex, b3CC, temp;
7766
7767 unsigned short XGINew_P3cc = pVBInfo->P3cc;
7768
7769 /* XGINew_CRT1Mode = ModeNo; // SaveModeID */
7770 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
7771 /* XGI_SetBIOSData(ModeNo, ModeIdIndex); */
7772 /* XGI_ClearBankRegs(ModeNo, ModeIdIndex); */
7773 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7774 XGI_SetMiscRegs(StandTableIndex, pVBInfo);
7775 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
7776 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7777 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
7778 XGI_ClearExt1Regs(pVBInfo);
7779
7780 /* if (pVBInfo->IF_DEF_ExpLink) */
7781 if (HwDeviceExtension->jChipType == XG27) {
7782 if (pVBInfo->IF_DEF_LVDS == 0)
7783 XGI_SetDefaultVCLK(pVBInfo);
7784 }
7785
7786 temp = ~ProgrammingCRT2;
7787 pVBInfo->SetFlag &= temp;
7788 pVBInfo->SelectCRT2Rate = 0;
7789
7790 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7791 | VB_XGI302LV | VB_XGI301C)) {
7792 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA
7793 | SetInSlaveMode)) {
7794 pVBInfo->SetFlag |= ProgrammingCRT2;
7795 }
7796 }
7797
7798 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7799 ModeIdIndex, pVBInfo);
7800 if (RefreshRateTableIndex != 0xFFFF) {
7801 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
7802 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7803 pVBInfo, HwDeviceExtension);
7804 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
7805 RefreshRateTableIndex, pVBInfo);
7806 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7807 HwDeviceExtension, pVBInfo);
7808 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
7809 RefreshRateTableIndex, pVBInfo);
7810 }
7811
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007812 if ((HwDeviceExtension->jChipType >= XG20) &&
7813 (HwDeviceExtension->jChipType < XG27)) { /* fix H/W DCLK/2 bug */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007814 if ((ModeNo == 0x00) | (ModeNo == 0x01)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007815 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x4E);
7816 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE9);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007817 b3CC = (unsigned char) inb(XGINew_P3cc);
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007818 outb((b3CC |= 0x0C), XGINew_P3cc);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007819 } else if ((ModeNo == 0x04) | (ModeNo == 0x05) | (ModeNo
7820 == 0x0D)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007821 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7822 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE3);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007823 b3CC = (unsigned char) inb(XGINew_P3cc);
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007824 outb((b3CC |= 0x0C), XGINew_P3cc);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007825 }
7826 }
7827
7828 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007829 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007830 if (temp & 0xA0) {
7831
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007832 /* Enable write GPIOF */
7833 /* xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x20); */
7834 /* P. DWN */
7835 /* xgifb_reg_and(pVBInfo->P3d4, 0x48, ~0x20); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007836 /* XG21 CRT1 Timing */
7837 if (HwDeviceExtension->jChipType == XG27)
7838 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
7839 RefreshRateTableIndex, pVBInfo);
7840 else
7841 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
7842 RefreshRateTableIndex, pVBInfo);
7843
7844 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
7845 RefreshRateTableIndex);
7846
Aaro Koskinen105d8d02011-08-31 21:46:00 +03007847 xgifb_set_lcd(HwDeviceExtension->jChipType,
7848 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007849
Aaro Koskinen64db29f2011-08-31 21:46:01 +03007850 if (pVBInfo->IF_DEF_LVDS == 1)
7851 xgifb_set_lvds(HwDeviceExtension->jChipType,
7852 ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007853 /* P. ON */
7854 /* xgifb_reg_or(pVBInfo->P3d4, 0x48, 0x20); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007855 }
7856 }
7857
7858 pVBInfo->SetFlag &= (~ProgrammingCRT2);
7859 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
7860 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
7861 RefreshRateTableIndex, pVBInfo);
7862
7863 /* XGI_LoadCharacter(); //dif ifdef TVFont */
7864
7865 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
7866 /* XGI_ClearBuffer(HwDeviceExtension, ModeNo, pVBInfo); */
7867}
7868
7869unsigned char XGISetModeNew(struct xgi_hw_device_info *HwDeviceExtension,
7870 unsigned short ModeNo)
7871{
7872 unsigned short ModeIdIndex;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007873 /* unsigned char *pVBInfo->FBAddr =
7874 HwDeviceExtension->pjVideoMemoryAddress; */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007875 struct vb_device_info VBINF;
7876 struct vb_device_info *pVBInfo = &VBINF;
7877 pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase;
7878 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;
7879 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007880 pVBInfo->IF_DEF_LCDA = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007881 pVBInfo->IF_DEF_VideoCapture = 0;
7882 pVBInfo->IF_DEF_ScaleLCD = 0;
7883 pVBInfo->IF_DEF_OEMUtil = 0;
7884 pVBInfo->IF_DEF_PWD = 0;
7885
7886 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
7887 pVBInfo->IF_DEF_YPbPr = 0;
7888 pVBInfo->IF_DEF_HiVision = 0;
7889 pVBInfo->IF_DEF_CRT2Monitor = 0;
7890 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007891 } else {
7892 pVBInfo->IF_DEF_YPbPr = 1;
7893 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02007894 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007895 }
7896
7897 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
7898 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
7899 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
7900 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
7901 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
7902 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
7903 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
7904 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
7905 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
7906 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
7907 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
7908 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
7909 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
7910 pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04;
7911 pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10;
7912 pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12;
7913 pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14;
7914 pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2;
7915
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007916 /* for x86 Linux, XG21 LVDS */
7917 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007918 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007919 pVBInfo->IF_DEF_LVDS = 1;
7920 }
7921 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007922 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
7923 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007924 pVBInfo->IF_DEF_LVDS = 1;
7925 }
7926 }
7927
7928 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
7929 XGI_GetVBType(pVBInfo);
7930
7931 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
7932 if (ModeNo & 0x80) {
7933 ModeNo = ModeNo & 0x7F;
7934 /* XGINew_flag_clearbuffer = 0; */
7935 }
7936 /* else {
7937 XGINew_flag_clearbuffer = 1;
7938 }
7939 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007940 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007941
7942 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
7943 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
7944
7945 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7946
7947 XGI_GetVGAType(HwDeviceExtension, pVBInfo);
7948
7949 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7950 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
7951 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
7952 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
7953 XGI_DisableBridge(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007954
7955 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) {
7956 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7957 ModeIdIndex, pVBInfo);
7958
7959 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7960 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7961 HwDeviceExtension, pVBInfo);
7962 }
7963 } else {
7964 if (!(pVBInfo->VBInfo & SwitchToCRT2)) {
7965 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7966 ModeIdIndex, pVBInfo);
7967 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7968 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7969 HwDeviceExtension,
7970 pVBInfo);
7971 }
7972 }
7973 }
7974
7975 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchToCRT2)) {
7976 switch (HwDeviceExtension->ujVBChipID) {
7977 case VB_CHIP_301:
7978 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7979 pVBInfo); /*add for CRT2 */
7980 break;
7981
7982 case VB_CHIP_302:
7983 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7984 pVBInfo); /*add for CRT2 */
7985 break;
7986
7987 default:
7988 break;
7989 }
7990 }
7991
7992 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
7993 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
7994 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
7995 XGI_EnableBridge(HwDeviceExtension, pVBInfo);
7996 } /* !XG20 */
7997 else {
7998 if (pVBInfo->IF_DEF_LVDS == 1)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007999 if (!XGI_XG21CheckLVDSMode(ModeNo,
8000 ModeIdIndex,
8001 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008002 return 0;
8003
8004 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008005 pVBInfo->ModeType = pVBInfo->SModeIDTable[ModeIdIndex].
8006 St_ModeFlag & ModeInfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008007 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008008 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
8009 Ext_ModeFlag & ModeInfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008010 }
8011
8012 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03008013 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008014
8015 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
8016
8017 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex,
8018 pVBInfo);
8019
8020 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
8021 /*
8022 if (HwDeviceExtension->jChipType == XG21)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02008023 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0x80, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008024 */
8025 }
8026
8027 /*
8028 if (ModeNo <= 0x13) {
8029 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
8030 } else {
8031 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
8032 }
8033 pVBInfo->ModeType = modeflag&ModeInfoFlag;
8034 pVBInfo->SetFlag = 0x00;
8035 pVBInfo->VBInfo = DisableCRT2Display;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008036 temp = XGINew_CheckMemorySize(HwDeviceExtension,
8037 ModeNo,
8038 ModeIdIndex,
8039 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008040
8041 if (temp == 0)
8042 return (0);
8043
8044 XGI_DisplayOff(HwDeviceExtension, pVBInfo) ;
8045 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex, pVBInfo);
8046 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
8047 */
8048
8049 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
8050
8051 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
8052 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
8053 }
8054
8055 return 1;
8056}