blob: 9b6d995766bad3068f6c87932c97f179ee2092de [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"
Aaro Koskinen09d1cad2011-09-13 22:49:34 +030011#include "vb_init.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020012#include "vb_util.h"
13#include "vb_table.h"
Aaro Koskinen5e60b972011-03-08 22:16:14 +020014#include "vb_setmode.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020015
16
17#define IndexMask 0xff
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020018
Aaro Koskinen624554d2011-10-11 21:47:35 +030019static const unsigned short XGINew_MDA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040020 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
22 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
23 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
26 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
27 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020028
Aaro Koskinen624554d2011-10-11 21:47:35 +030029static const unsigned short XGINew_CGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040030 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
31 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
32 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
33 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
34 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
35 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
36 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
37 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020038
Aaro Koskinen624554d2011-10-11 21:47:35 +030039static const unsigned short XGINew_EGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040040 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x05, 0x15,
41 0x20, 0x30, 0x24, 0x34, 0x21, 0x31, 0x25, 0x35,
42 0x08, 0x18, 0x0C, 0x1C, 0x09, 0x19, 0x0D, 0x1D,
43 0x28, 0x38, 0x2C, 0x3C, 0x29, 0x39, 0x2D, 0x3D,
44 0x02, 0x12, 0x06, 0x16, 0x03, 0x13, 0x07, 0x17,
45 0x22, 0x32, 0x26, 0x36, 0x23, 0x33, 0x27, 0x37,
46 0x0A, 0x1A, 0x0E, 0x1E, 0x0B, 0x1B, 0x0F, 0x1F,
47 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020048
Aaro Koskinen624554d2011-10-11 21:47:35 +030049static const unsigned short XGINew_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040050 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
51 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
52 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
53 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
54 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
55 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
56 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
57 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
58 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
59 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020060
Bill Pemberton80adad82010-06-17 13:10:51 -040061void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020062{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053063 pVBInfo->SModeIDTable = (struct XGI_StStruct *) XGI330_SModeIDTable;
64 pVBInfo->StandTable = (struct XGI_StandTableStruct *) XGI330_StandTable;
65 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
66 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
67 pVBInfo->XGINEWUB_CRT1Table
68 = (struct XGI_CRT1TableStruct *) XGI_CRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020069
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053070 /* add for new UNIVGABIOS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +080071 /* XGINew_UBLCDDataTable =
72 * (struct XGI_LCDDataTablStruct *) XGI_LCDDataTable; */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053073 /* XGINew_UBTVDataTable = (XGI_TVDataTablStruct *) XGI_TVDataTable; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020074
Aaro Koskinen06587332011-03-13 12:26:10 +020075 pVBInfo->MCLKData = (struct XGI_MCLKDataStruct *) XGI340New_MCLKData;
76 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053077 pVBInfo->VCLKData = (struct XGI_VCLKDataStruct *) XGI_VCLKData;
78 pVBInfo->VBVCLKData = (struct XGI_VBVCLKDataStruct *) XGI_VBVCLKData;
79 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
80 pVBInfo->StResInfo = (struct XGI_StResInfoStruct *) XGI330_StResInfo;
81 pVBInfo->ModeResInfo
82 = (struct XGI_ModeResInfoStruct *) XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053084 pVBInfo->pOutputSelect = &XGI330_OutputSelect;
85 pVBInfo->pSoftSetting = &XGI330_SoftSetting;
86 pVBInfo->pSR07 = &XGI330_SR07;
87 pVBInfo->LCDResInfo = 0;
88 pVBInfo->LCDTypeInfo = 0;
89 pVBInfo->LCDInfo = 0;
90 pVBInfo->VBInfo = 0;
91 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053093 pVBInfo->SR15 = XGI340_SR13;
94 pVBInfo->CR40 = XGI340_cr41;
95 pVBInfo->SR25 = XGI330_sr25;
96 pVBInfo->pSR31 = &XGI330_sr31;
97 pVBInfo->pSR32 = &XGI330_sr32;
98 pVBInfo->CR6B = XGI340_CR6B;
99 pVBInfo->CR6E = XGI340_CR6E;
100 pVBInfo->CR6F = XGI340_CR6F;
101 pVBInfo->CR89 = XGI340_CR89;
102 pVBInfo->AGPReg = XGI340_AGPReg;
103 pVBInfo->SR16 = XGI340_SR16;
104 pVBInfo->pCRCF = &XG40_CRCF;
105 pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530107 pVBInfo->CR49 = XGI330_CR49;
108 pVBInfo->pSR1F = &XGI330_SR1F;
109 pVBInfo->pSR21 = &XGI330_SR21;
110 pVBInfo->pSR22 = &XGI330_SR22;
111 pVBInfo->pSR23 = &XGI330_SR23;
112 pVBInfo->pSR24 = &XGI330_SR24;
113 pVBInfo->pSR33 = &XGI330_SR33;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530115 pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2;
116 pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D;
117 pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E;
118 pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10;
119 pVBInfo->pRGBSenseData = &XGI330_RGBSenseData;
120 pVBInfo->pVideoSenseData = &XGI330_VideoSenseData;
121 pVBInfo->pYCSenseData = &XGI330_YCSenseData;
122 pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2;
123 pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2;
124 pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530126 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
127 pVBInfo->PALTiming = XGI330_PALTiming;
128 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
129 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
130 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
131 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
132 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
133 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
134 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
135 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
136 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
137 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
138 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
139 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530141 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
142 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
143 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200144
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530145 /* 310 customization related */
146 if ((pVBInfo->VBType & VB_XGI301LV) || (pVBInfo->VBType & VB_XGI302LV))
147 pVBInfo->LCDCapList = XGI_LCDDLCapList;
148 else
149 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530151 if ((ChipType == XG21) || (ChipType == XG27))
152 pVBInfo->XG21_LVDSCapList = XGI21_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530154 pVBInfo->XGI_TVDelayList = XGI301TVDelayList;
155 pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200156
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530157 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200158
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530159 if (ChipType >= XG20)
160 pVBInfo->pXGINew_CR97 = &XG20_CR97;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530162 if (ChipType == XG27) {
163 pVBInfo->MCLKData
164 = (struct XGI_MCLKDataStruct *) XGI27New_MCLKData;
165 pVBInfo->CR40 = XGI27_cr41;
166 pVBInfo->pXGINew_CR97 = &XG27_CR97;
167 pVBInfo->pSR36 = &XG27_SR36;
168 pVBInfo->pCR8F = &XG27_CR8F;
169 pVBInfo->pCRD0 = XG27_CRD0;
170 pVBInfo->pCRDE = XG27_CRDE;
171 pVBInfo->pSR40 = &XG27_SR40;
172 pVBInfo->pSR41 = &XG27_SR41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530174 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200175
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530176 if (ChipType >= XG20) {
177 pVBInfo->pDVOSetting = &XG21_DVOSetting;
178 pVBInfo->pCR2E = &XG21_CR2E;
179 pVBInfo->pCR2F = &XG21_CR2F;
180 pVBInfo->pCR46 = &XG21_CR46;
181 pVBInfo->pCR47 = &XG21_CR47;
182 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200183
184}
185
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800186static unsigned char XGI_GetModePtr(unsigned short ModeNo,
187 unsigned short ModeIdIndex,
188 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200189{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530190 unsigned char index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530192 if (ModeNo <= 0x13)
193 index = pVBInfo->SModeIDTable[ModeIdIndex].St_StTableIndex;
194 else {
195 if (pVBInfo->ModeType <= 0x02)
196 index = 0x1B; /* 02 -> ModeEGA */
197 else
198 index = 0x0F;
199 }
200 return index; /* Get pVBInfo->StandTable index */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200201}
202
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800203static void XGI_SetSeqRegs(unsigned short ModeNo,
204 unsigned short StandTableIndex,
205 unsigned short ModeIdIndex,
206 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200207{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530208 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530209 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530211 if (ModeNo <= 0x13)
212 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
213 else
214 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200215
Aaro Koskinen8104e322011-03-13 12:26:22 +0200216 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530217 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530219 i = SetCRT2ToLCDA;
220 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
221 tempah |= 0x01;
222 } else {
223 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
224 if (pVBInfo->VBInfo & SetInSlaveMode)
225 tempah |= 0x01;
226 }
227 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530229 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200230 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200231
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530232 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800233 /* Get SR2,3,4 from file */
234 SRdata = pVBInfo->StandTable[StandTableIndex].SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200235 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530236 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200237}
238
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200239static void XGI_SetMiscRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800240 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200241{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530242 unsigned char Miscdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200243
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800244 /* Get Misc from file */
245 Miscdata = pVBInfo->StandTable[StandTableIndex].MISC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530246 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800247 if (pVBInfo->VBType & (VB_XGI301B |
248 VB_XGI302B |
249 VB_XGI301LV |
250 VB_XGI302LV |
251 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530252 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
253 Miscdata |= 0x0C;
254 }
255 }
256 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200257
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200258 outb(Miscdata, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200259}
260
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200261static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800262 unsigned short StandTableIndex,
263 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200264{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530265 unsigned char CRTCdata;
266 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200267
Aaro Koskinen58839b02011-03-13 12:26:23 +0200268 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530269 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200270 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200271
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530272 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800273 /* Get CRTC from file */
274 CRTCdata = pVBInfo->StandTable[StandTableIndex].CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200275 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530276 }
277 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800278 if ((HwDeviceExtension->jChipType == XGI_630) &&
279 (HwDeviceExtension->jChipRevision == 0x30)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530280 if (pVBInfo->VBInfo & SetInSlaveMode) {
281 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200282 xgifb_reg_set(pVBInfo->P3d4, 0x18, 0xFE);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530283 }
284 }
285 }
286 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200287}
288
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800289static void XGI_SetATTRegs(unsigned short ModeNo,
290 unsigned short StandTableIndex,
291 unsigned short ModeIdIndex,
292 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200293{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530294 unsigned char ARdata;
295 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530297 if (ModeNo <= 0x13)
298 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
299 else
300 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200301
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530302 for (i = 0; i <= 0x13; i++) {
303 ARdata = pVBInfo->StandTable[StandTableIndex].ATTR[i];
304 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
305 if (i == 0x13) {
306 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
307 ARdata = 0;
308 } else {
309 if (pVBInfo->VBInfo & (SetCRT2ToTV
310 | SetCRT2ToLCD)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800311 if (pVBInfo->VBInfo &
312 SetInSlaveMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530313 ARdata = 0;
314 }
315 }
316 }
317 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200318
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200319 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200320 outb(i, pVBInfo->P3c0); /* set index */
321 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530322 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200323
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200324 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200325 outb(0x14, pVBInfo->P3c0); /* set index */
326 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200327 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200328 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200329}
330
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200331static void XGI_SetGRCRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800332 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200333{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530334 unsigned char GRdata;
335 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200336
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530337 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800338 /* Get GR from file */
339 GRdata = pVBInfo->StandTable[StandTableIndex].GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200340 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530341 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200342
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530343 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200344 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530345 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200346 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530347 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200348}
349
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200350static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200351{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530352 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530354 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200355 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200356}
357
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200358static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200359{
360
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200361 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200362 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
363 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200364
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200365 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200366 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
367 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200368
Aaro Koskinendc505562011-03-13 12:26:26 +0200369 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530370 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200371}
372
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200373static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530374 unsigned short ModeIdIndex,
375 unsigned short RefreshRateTableIndex, unsigned short *i,
376 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200377{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530378 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530380 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800381 /* si+St_ModeFlag */
382 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530383 else
384 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200385
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530386 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
387 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
388 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200389
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530390 if (pVBInfo->IF_DEF_LVDS == 0) {
391 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
392 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200393
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530394 if (pVBInfo->VBType & VB_XGI301C)
395 tempax |= SupportCRT2in301C;
396 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200397
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800398 /* 301b */
399 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530400 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200401
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530402 if (pVBInfo->LCDResInfo != Panel1280x1024) {
403 if (pVBInfo->LCDResInfo != Panel1280x960) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800404 if (pVBInfo->LCDInfo &
405 LCDNonExpanding) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530406 if (resinfo >= 9) {
407 tempax = 0;
408 return 0;
409 }
410 }
411 }
412 }
413 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200414
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530415 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) { /* for HiTV */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800416 if ((pVBInfo->VBType & VB_XGI301LV) &&
417 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530418 tempax |= SupportYPbPr;
419 if (pVBInfo->VBInfo & SetInSlaveMode) {
420 if (resinfo == 4)
421 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200422
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530423 if (resinfo == 3)
424 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200425
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530426 if (resinfo > 7)
427 return 0;
428 }
429 } else {
430 tempax |= SupportHiVisionTV;
431 if (pVBInfo->VBInfo & SetInSlaveMode) {
432 if (resinfo == 4)
433 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200434
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530435 if (resinfo == 3) {
436 if (pVBInfo->SetFlag
437 & TVSimuMode)
438 return 0;
439 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200440
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530441 if (resinfo > 7)
442 return 0;
443 }
444 }
445 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800446 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
447 SetCRT2ToSVIDEO |
448 SetCRT2ToSCART |
449 SetCRT2ToYPbPr |
450 SetCRT2ToHiVisionTV)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530451 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200452
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530453 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
454 | VB_XGI301LV | VB_XGI302LV
455 | VB_XGI301C)) {
456 tempax |= SupportTV1024;
457 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200458
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530459 if (!(pVBInfo->VBInfo & SetPALTV)) {
460 if (modeflag & NoSupportSimuTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800461 if (pVBInfo->VBInfo &
462 SetInSlaveMode) {
463 if (!(pVBInfo->VBInfo &
464 SetNotSimuMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530465 return 0;
466 }
467 }
468 }
469 }
470 }
471 }
472 } else { /* for LVDS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530473 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
474 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200475
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530476 if (resinfo > 0x08)
477 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200478
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530479 if (pVBInfo->LCDResInfo < Panel1024x768) {
480 if (resinfo > 0x07)
481 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200482
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530483 if (resinfo == 0x04)
484 return 0; /* 512x384 */
485 }
486 }
487 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200488
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800489 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
490 tempbx; (*i)--) {
491 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
492 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530493 if (infoflag & tempax)
494 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200495
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530496 if ((*i) == 0)
497 break;
498 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200499
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530500 for ((*i) = 0;; (*i)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800501 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
502 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530503 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
504 != tempbx) {
505 return 0;
506 }
507
508 if (infoflag & tempax)
509 return 1;
510 }
511 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200512}
513
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200514static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530515 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200516{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530517 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200518
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800519 /* di+0x00 */
520 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530521 sync &= 0xC0;
522 temp = 0x2F;
523 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200524 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200525}
526
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200527static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530528 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200529{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530530 unsigned char data, data1, pushax;
531 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200532
Aaro Koskinen8104e322011-03-13 12:26:22 +0200533 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
534 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200535 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200536
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800537 /* unlock cr0-7 */
538 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530539 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200540 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200541
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530542 data = pVBInfo->TimingH[0].data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200543 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200544
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530545 for (i = 0x01; i <= 0x04; i++) {
546 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200547 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530548 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200549
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530550 for (i = 0x05; i <= 0x06; i++) {
551 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200552 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530553 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200554
Aaro Koskinen58839b02011-03-13 12:26:23 +0200555 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530556 j &= 0x1F;
557 data = pVBInfo->TimingH[0].data[7];
558 data &= 0xE0;
559 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200560 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200561
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530562 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200563 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530564 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200565 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200566 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530567 data1 = data;
568 data1 &= 0xE0;
569 data &= 0x1F;
570 if (data == 0) {
571 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200572 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530573 0x0c);
574 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200575 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530576 data = pushax;
577 }
578 data = data - 1;
579 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200580 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200581 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530582 data = data >> 5;
583 data = data + 3;
584 if (data > 7)
585 data = data - 7;
586 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200587 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530588 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200589}
590
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800591static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
592 unsigned short ModeNo,
593 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200594{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530595 unsigned char data;
596 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200597
Aaro Koskinen8104e322011-03-13 12:26:22 +0200598 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
599 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200600 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200601
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530602 for (i = 0x00; i <= 0x01; i++) {
603 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200604 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530605 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200606
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530607 for (i = 0x02; i <= 0x03; i++) {
608 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200609 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530610 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200611
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530612 for (i = 0x04; i <= 0x05; i++) {
613 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200614 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530615 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200616
Aaro Koskinen58839b02011-03-13 12:26:23 +0200617 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530618 j &= 0xC0;
619 data = pVBInfo->TimingV[0].data[6];
620 data &= 0x3F;
621 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200622 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200623
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530624 data = pVBInfo->TimingV[0].data[6];
625 data &= 0x80;
626 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200627
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530628 if (ModeNo <= 0x13)
629 i = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
630 else
631 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200632
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530633 i &= DoubleScanMode;
634 if (i)
635 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200636
Aaro Koskinen58839b02011-03-13 12:26:23 +0200637 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530638 j &= 0x5F;
639 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200640 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200641}
642
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200643static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
644 unsigned short RefreshRateTableIndex,
645 struct vb_device_info *pVBInfo,
646 struct xgi_hw_device_info *HwDeviceExtension)
647{
648 unsigned char index, data;
649 unsigned short i;
650
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800651 /* Get index */
652 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200653 index = index & IndexMask;
654
Aaro Koskinen58839b02011-03-13 12:26:23 +0200655 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200656 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200657 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200658
659 for (i = 0; i < 8; i++)
660 pVBInfo->TimingH[0].data[i]
661 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
662
663 for (i = 0; i < 7; i++)
664 pVBInfo->TimingV[0].data[i]
665 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
666
667 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
668
669 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
670
671 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200672 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200673}
674
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200675/* --------------------------------------------------------------------- */
676/* Function : XGI_SetXG21CRTC */
677/* Input : Stand or enhance CRTC table */
678/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
679/* Description : Set LCD timing */
680/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200681static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530682 unsigned short RefreshRateTableIndex,
683 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200684{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530685 unsigned char StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
686 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200687
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530688 if (ModeNo <= 0x13) {
689 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800690 /* CR04 HRS */
691 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
692 /* SR2E [7:0]->HRS */
693 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
694 /* Tempbx: CR05 HRE */
695 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530696 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
697 Tempcx = Tempax;
698 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
699 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
700 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
701 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
702 Tempdx <<= 2; /* Tempdx << 2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800703 /* SR2F [7:2]->HRE */
704 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200705 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200706
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800707 /* Tempax: CR16 VRS */
708 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530709 Tempbx = Tempax; /* Tempbx=Tempax */
710 Tempax &= 0x01; /* Tempax: VRS[0] */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200711 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800712
713 /* Tempax: CR7 VRS */
714 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530715 Tempdx = Tempbx >> 1; /* Tempdx: VRS[7:1] */
716 Tempcx = Tempax & 0x04; /* Tempcx: CR7[2] */
717 Tempcx <<= 5; /* Tempcx[7]: VRS[8] */
718 Tempdx |= Tempcx; /* Tempdx: VRS[8:1] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800719 /* SR34[7:0]: VRS[8:1] */
720 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempdx);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200721
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800722 /* Temp1[8]: VRS[8] unsigned char -> unsigned short */
723 Temp1 = Tempcx << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530724 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
725 Tempax &= 0x80; /* Tempax[7]: CR7[7] */
726 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
727 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200728
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800729 /* CR16 VRE */
730 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530731 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
732 Temp2 = Temp1 & 0x3F0; /* Temp2[9:4]: VRS[9:4] */
733 Temp2 |= Tempax; /* Temp2[9:0]: VRE[9:0] */
734 Temp3 = Temp1 & 0x0F; /* Temp3[3:0]: VRS[3:0] */
735 if (Tempax < Temp3) /* VRE[3:0]<VRS[3:0] */
736 Temp2 |= 0x10; /* Temp2: VRE + 0x10 */
737 Temp2 &= 0xFF; /* Temp2[7:0]: VRE[7:0] */
738 Tempax = (unsigned char) Temp2; /* Tempax[7:0]: VRE[7:0] */
739 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
740 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
741 Temp1 >>= 9; /* [10:9]->[1:0] */
742 Tempbx = (unsigned char) Temp1; /* Tempbx[1:0]: VRS[10:9] */
743 Tempax |= Tempbx; /* VRE[5:0]VRS[10:9] */
744 Tempax &= 0x7F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800745 /* SR3F D[7:2]->VRE D[1:0]->VRS */
746 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530747 } else {
748 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800749 /* Tempax: CR4 HRS */
750 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530751 Tempcx = Tempax; /* Tempcx: HRS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800752 /* SR2E[7:0]->HRS */
753 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200754
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530755 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
756 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
757 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
758 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
759 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200760
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530761 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
762 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200763
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530764 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
765 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
766 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
767 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200768
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530769 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
770 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200771
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530772 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
773 if (Tempax < Tempcx) /* HRE < HRS */
774 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200775
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530776 Temp2 &= 0xFF;
777 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
778 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
779 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
780 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800781 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
782 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200783 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200784
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800785 /* CR10 VRS */
786 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530787 Tempbx = Tempax; /* Tempbx: VRS */
788 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200789 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800790 /* CR7[2][7] VRE */
791 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530792 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
793 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
794 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
795 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200796 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530798 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
799 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
800 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
801 Tempax &= 0x80;
802 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
803 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800804 /* Tempax: SRA */
805 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530806 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
807 Temp2 = Tempax;
808 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
809 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200810
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800811 /* Tempax: CR11 VRE */
812 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530813 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800814 /* Tempbx: SRA */
815 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530816 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
817 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
818 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
819 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
820 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530822 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
823 if (Tempax < Temp3) /* VRE < VRS */
824 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530826 Temp2 &= 0xFF;
827 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
828 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
829 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
830 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
831 Tempbx = (unsigned char) Temp1;
832 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
833 Tempax &= 0x7F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800834 /* SR3F D[7:2]->VRE D[1:0]->VRS */
835 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530836 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200837}
838
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800839static void XGI_SetXG27CRTC(unsigned short ModeNo,
840 unsigned short ModeIdIndex,
841 unsigned short RefreshRateTableIndex,
842 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200843{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400844 unsigned short StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530846 if (ModeNo <= 0x13) {
847 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800848 /* CR04 HRS */
849 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
850 /* SR2E [7:0]->HRS */
851 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
852 /* Tempbx: CR05 HRE */
853 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530854 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
855 Tempcx = Tempax;
856 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
857 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
858 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
859 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
860 Tempdx <<= 2; /* Tempdx << 2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800861 /* SR2F [7:2]->HRE */
862 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200863 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200864
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800865 /* Tempax: CR10 VRS */
866 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200867 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax); /* SR34[7:0]->VRS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530868 Tempcx = Tempax; /* Tempcx=Tempax=VRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800869 /* Tempax[7][2]: CR7[7][2] VRS[9][8] */
870 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530871 Tempbx = Tempax; /* Tempbx=CR07 */
872 Tempax &= 0x04; /* Tempax[2]: CR07[2] VRS[8] */
873 Tempax >>= 2;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800874 /* SR35 D[0]->VRS D[8] */
875 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530876 Tempcx |= (Tempax << 8); /* Tempcx[8] |= VRS[8] */
877 Tempcx |= (Tempbx & 0x80) << 2; /* Tempcx[9] |= VRS[9] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200878
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800879 /* CR11 VRE */
880 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530881 Tempax &= 0x0F; /* Tempax: VRE[3:0] */
882 Tempbx = Tempcx; /* Tempbx=Tempcx=VRS[9:0] */
883 Tempbx &= 0x3F0; /* Tempbx[9:4]: VRS[9:4] */
884 Tempbx |= Tempax; /* Tempbx[9:0]: VRE[9:0] */
885 if (Tempax <= (Tempcx & 0x0F)) /* VRE[3:0]<=VRS[3:0] */
886 Tempbx |= 0x10; /* Tempbx: VRE + 0x10 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800887 /* Tempax[7:0]: VRE[7:0] */
888 Tempax = (unsigned char) Tempbx & 0xFF;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530889 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
890 Tempcx = (Tempcx & 0x600) >> 8; /* Tempcx VRS[10:9] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800891 /* SR3F D[7:2]->VRE D[5:0] */
892 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
893 /* SR35 D[2:1]->VRS[10:9] */
894 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x06, Tempcx);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530895 } else {
896 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800897 /* Tempax: CR4 HRS */
898 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530899 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800900 /* SR2E[7:0]->HRS */
901 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200902
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800903 /* SR0B */
904 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530905 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
906 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200907
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530908 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
909 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
910 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200911
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530912 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
913 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
914 Tempax <<= 3; /* Tempax[5]: HRE[5] */
915 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200916
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530917 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
918 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200919
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800920 /* Tempax: CR4 HRS */
921 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530922 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
923 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
924 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200925
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530926 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
927 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
928 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
929 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800930 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
931 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200932 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200933
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800934 /* CR10 VRS */
935 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
936 /* SR34[7:0]->VRS[7:0] */
937 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530939 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800940 /* CR7[7][2] VRS[9][8] */
941 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530942 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
943 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
944 Tempax >>= 2; /* Tempax[0]: VRS[8] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800945 /* SR35[0]: VRS[8] */
946 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530947 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
948 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800949 /* Tempax: SR0A */
950 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530951 Tempax &= 0x08; /* SR0A[3] VRS[10] */
952 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200953
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800954 /* Tempax: CR11 VRE */
955 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530956 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800957 /* Tempbx: SR0A */
958 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530959 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
960 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
961 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
962 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
963 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
964 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530966 if (Tempbx <= Tempcx) /* VRE <= VRS */
967 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200968
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800969 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
970 Tempax = (Tempbx << 2) & 0xFF;
971 /* SR3F[7:2]:VRE[5:0] */
972 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530973 Tempax = Tempcx >> 8;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800974 /* SR35[2:0]:VRS[10:8] */
975 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530976 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200977}
978
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300979static void xgifb_set_lcd(int chip_id,
980 struct vb_device_info *pVBInfo,
981 unsigned short RefreshRateTableIndex,
982 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200983{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400984 unsigned short Data, Temp, b3CC;
985 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200986
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530987 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200988
Aaro Koskinen8104e322011-03-13 12:26:22 +0200989 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
990 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
991 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
992 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300993
994 if (chip_id == XG27) {
995 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
996 if ((Temp & 0x03) == 0) { /* dual 12 */
997 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
998 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
999 }
1000 }
1001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301002 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001003 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
1004 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
1005 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
1006 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301007 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001008
Aaro Koskinen105d8d02011-08-31 21:46:00 +03001009 if (chip_id == XG27) {
1010 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301011 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +03001012 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
1013 if (Temp & 0x01) {
1014 /* 18 bits FP */
1015 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
1016 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
1017 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301018 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001019
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001020 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001021
Aaro Koskinendc505562011-03-13 12:26:26 +02001022 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
1023 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301025 if (ModeNo <= 0x13) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001026 b3CC = (unsigned char) inb(XGI_P3cc);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301027 if (b3CC & 0x40)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001028 /* Hsync polarity */
1029 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301030 if (b3CC & 0x80)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001031 /* Vsync polarity */
1032 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301033 } else {
1034 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1035 if (Data & 0x4000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001036 /* Hsync polarity */
1037 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301038 if (Data & 0x8000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001039 /* Vsync polarity */
1040 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301041 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001042}
1043
1044/* --------------------------------------------------------------------- */
1045/* Function : XGI_UpdateXG21CRTC */
1046/* Input : */
1047/* Output : CRT1 CRTC */
1048/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
1049/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001050static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
1051 struct vb_device_info *pVBInfo,
1052 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001053{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301054 int i, index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001055
Aaro Koskinendc505562011-03-13 12:26:26 +02001056 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301057 if (ModeNo <= 0x13) {
1058 for (i = 0; i < 12; i++) {
1059 if (ModeNo == pVBInfo->UpdateCRT1[i].ModeID)
1060 index = i;
1061 }
1062 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001063 if (ModeNo == 0x2E &&
1064 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1065 RES640x480x60))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301066 index = 12;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001067 else if (ModeNo == 0x2E &&
1068 (pVBInfo->RefIndex[RefreshRateTableIndex].
1069 Ext_CRT1CRTC == RES640x480x72))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301070 index = 13;
1071 else if (ModeNo == 0x2F)
1072 index = 14;
1073 else if (ModeNo == 0x50)
1074 index = 15;
1075 else if (ModeNo == 0x59)
1076 index = 16;
1077 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001078
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301079 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001080 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301081 pVBInfo->UpdateCRT1[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001082 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301083 pVBInfo->UpdateCRT1[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001084 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301085 pVBInfo->UpdateCRT1[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001086 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301087 pVBInfo->UpdateCRT1[index].CR16);
1088 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001089}
1090
Aaro Koskinen06465962011-11-27 23:03:06 +02001091static unsigned short XGI_GetResInfo(unsigned short ModeNo,
1092 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
1093{
1094 unsigned short resindex;
1095
1096 if (ModeNo <= 0x13)
1097 /* si+St_ResInfo */
1098 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1099 else
1100 /* si+Ext_ResInfo */
1101 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1102 return resindex;
1103}
1104
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001105static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301106 unsigned short ModeNo, unsigned short ModeIdIndex,
1107 unsigned short RefreshRateTableIndex,
1108 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001109{
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001110 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301112 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301114 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301116 if (ModeNo <= 0x13) {
1117 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1118 tempax = pVBInfo->StResInfo[resindex].HTotal;
1119 tempbx = pVBInfo->StResInfo[resindex].VTotal;
1120 } else {
1121 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1122 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
1123 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
1124 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301126 if (modeflag & HalfDCLK)
1127 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301129 if (ModeNo > 0x13) {
1130 if (modeflag & HalfDCLK)
1131 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301133 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301135 if (temp & InterlaceMode)
1136 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301138 if (modeflag & DoubleScanMode)
1139 tempbx = tempbx << 1;
1140 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301142 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301144 /* if (!(modeflag & Charx8Dot)) */
1145 /* tempcx = 9; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301147 tempax /= tempcx;
1148 tempax -= 1;
1149 tempbx -= 1;
1150 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001151 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1152 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301153 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001154 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
1155 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001156 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301157 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +02001158 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301159 tempax = 0;
1160 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301162 if (tempbx & 0x01)
1163 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301165 if (tempbx & 0x02)
1166 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001167
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001168 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001169 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301170 data &= 0xFF;
1171 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301173 if (tempbx & 0x04)
1174 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001175
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001176 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001177 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001178}
1179
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001180static void XGI_SetCRT1Offset(unsigned short ModeNo,
1181 unsigned short ModeIdIndex,
1182 unsigned short RefreshRateTableIndex,
1183 struct xgi_hw_device_info *HwDeviceExtension,
1184 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001185{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301186 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301188 /* GetOffset */
1189 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
1190 temp = temp >> 8;
1191 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301193 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1194 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301196 if (temp2)
1197 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301199 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001200
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301201 switch (temp2) {
1202 case 0:
1203 temp2 = 1;
1204 break;
1205 case 1:
1206 temp2 = 2;
1207 break;
1208 case 2:
1209 temp2 = 4;
1210 break;
1211 case 3:
1212 temp2 = 4;
1213 break;
1214 case 4:
1215 temp2 = 6;
1216 break;
1217 case 5:
1218 temp2 = 8;
1219 break;
1220 default:
1221 break;
1222 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301224 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1225 temp = temp * temp2 + temp2 / 2;
1226 else
1227 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301229 /* SetOffset */
1230 DisplayUnit = temp;
1231 temp2 = temp;
1232 temp = temp >> 8; /* ah */
1233 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001234 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301235 i &= 0xF0;
1236 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001237 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301239 temp = (unsigned char) temp2;
1240 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +02001241 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001242
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301243 /* SetDisplayUnit */
1244 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1245 temp2 &= InterlaceMode;
1246 if (temp2)
1247 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301249 DisplayUnit = DisplayUnit << 5;
1250 ah = (DisplayUnit & 0xff00) >> 8;
1251 al = DisplayUnit & 0x00ff;
1252 if (al == 0)
1253 ah += 1;
1254 else
1255 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301257 if (HwDeviceExtension->jChipType >= XG20)
1258 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1259 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001260
Aaro Koskinen8104e322011-03-13 12:26:22 +02001261 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001262}
1263
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001264static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1265 unsigned short ModeIdIndex,
1266 unsigned short RefreshRateTableIndex,
1267 struct xgi_hw_device_info *HwDeviceExtension,
1268 struct vb_device_info *pVBInfo)
1269{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001270 unsigned short LCDXlat1VCLK[4] = { VCLK65 + 2,
1271 VCLK65 + 2,
1272 VCLK65 + 2,
1273 VCLK65 + 2 };
1274 unsigned short LCDXlat2VCLK[4] = { VCLK108_2 + 5,
1275 VCLK108_2 + 5,
1276 VCLK108_2 + 5,
1277 VCLK108_2 + 5 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001278 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001279 unsigned short LVDSXlat2VCLK[4] = { VCLK65 + 2,
1280 VCLK65 + 2,
1281 VCLK65 + 2,
1282 VCLK65 + 2 };
1283 unsigned short LVDSXlat3VCLK[4] = { VCLK65 + 2,
1284 VCLK65 + 2,
1285 VCLK65 + 2,
1286 VCLK65 + 2 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001287
1288 unsigned short CRT2Index, VCLKIndex;
1289 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001290
1291 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001292 /* si+St_ResInfo */
1293 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001294 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1295 CRT2Index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1296 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001297 /* si+Ext_ResInfo */
1298 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001299 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001300 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].
1301 Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001302 }
1303
1304 if (pVBInfo->IF_DEF_LVDS == 0) {
1305 CRT2Index = CRT2Index >> 6; /* for LCD */
1306 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /*301b*/
1307 if (pVBInfo->LCDResInfo != Panel1024x768)
1308 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1309 else
1310 VCLKIndex = LCDXlat1VCLK[CRT2Index];
1311 } else { /* for TV */
1312 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1313 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
1314 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1315 VCLKIndex = HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001316 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001317 } else {
1318 VCLKIndex = HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001319 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001320 }
1321
1322 if (pVBInfo->SetFlag & TVSimuMode) {
1323 if (modeflag & Charx8Dot) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001324 VCLKIndex =
1325 HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001326 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001327 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001328 VCLKIndex =
1329 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001330 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001331 }
1332 }
1333
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001334 /* 301lv */
1335 if (pVBInfo->VBType & VB_XGI301LV) {
1336 if (!(pVBInfo->VBExtInfo ==
1337 VB_YPbPr1080i)) {
1338 VCLKIndex =
1339 YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001340 if (!(pVBInfo->VBExtInfo
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001341 ==
1342 VB_YPbPr750p)) {
1343 VCLKIndex =
1344 YPbPr525pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001345 if (!(pVBInfo->VBExtInfo
1346 == VB_YPbPr525p)) {
1347 VCLKIndex
1348 = YPbPr525iVCLK_2;
1349 if (!(pVBInfo->SetFlag
1350 & RPLLDIV2XO))
1351 VCLKIndex
1352 = YPbPr525iVCLK;
1353 }
1354 }
1355 }
1356 }
1357 } else {
1358 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001359 if (pVBInfo->SetFlag &
1360 RPLLDIV2XO) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001361 VCLKIndex = TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001362 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001363 } else {
1364 VCLKIndex = TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001365 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001366 }
1367 }
1368 }
1369 } else { /* for CRT2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001370 /* Port 3cch */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001371 VCLKIndex = (unsigned char) inb(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001372 (pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001373 VCLKIndex = ((VCLKIndex >> 2) & 0x03);
1374 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001375 /* di+Ext_CRTVCLK */
1376 VCLKIndex =
1377 pVBInfo->RefIndex[
1378 RefreshRateTableIndex].
1379 Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001380 VCLKIndex &= IndexMask;
1381 }
1382 }
1383 }
1384 } else { /* LVDS */
1385 if (ModeNo <= 0x13)
1386 VCLKIndex = CRT2Index;
1387 else
1388 VCLKIndex = CRT2Index;
1389
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001390 VCLKIndex = VCLKIndex >> 6;
1391 if ((pVBInfo->LCDResInfo == Panel800x600) ||
1392 (pVBInfo->LCDResInfo == Panel320x480))
1393 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
1394 else if ((pVBInfo->LCDResInfo == Panel1024x768) ||
1395 (pVBInfo->LCDResInfo == Panel1024x768x75))
1396 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1397 else
1398 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001399 }
1400 /* VCLKIndex = VCLKIndex&IndexMask; */
1401
1402 return VCLKIndex;
1403}
1404
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001405static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1406 unsigned short ModeIdIndex,
1407 struct xgi_hw_device_info *HwDeviceExtension,
1408 unsigned short RefreshRateTableIndex,
1409 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001410{
Bill Pemberton108afbf2010-06-17 13:10:47 -04001411 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301412 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301414 if (pVBInfo->IF_DEF_LVDS == 1) {
1415 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001416 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001417 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1418 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301419 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001420 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301421 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001422 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301423 } else if ((pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
1424 | VB_XGI302LV | VB_XGI301C)) && (pVBInfo->VBInfo
1425 & SetCRT2ToLCDA)) {
1426 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1427 RefreshRateTableIndex, HwDeviceExtension,
1428 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001429 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001430 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301431 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001432 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301433 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001434 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1435 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301436 } else {
1437 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001438 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001439 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1440 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301441 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001442 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301443 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001444 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301445 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001446
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301447 if (HwDeviceExtension->jChipType >= XG20) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001448 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1449 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001450 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001451 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001452 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301453 index = data;
1454 index &= 0xE0;
1455 data &= 0x1F;
1456 data = data << 1;
1457 data += 1;
1458 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001459 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301460 }
1461 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001462}
1463
Aaro Koskinene85f2032011-11-27 23:03:07 +02001464static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1465{
1466 unsigned char temp;
1467
1468 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1469 temp = (temp & 1) << 6;
1470 /* SR06[6] 18bit Dither */
1471 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1472 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1473 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1474
1475}
1476
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001477static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301478 struct xgi_hw_device_info *HwDeviceExtension,
1479 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001480{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301481 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001482
Aaro Koskinen58839b02011-03-13 12:26:23 +02001483 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301484 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001485 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001486
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301487 if (ModeNo > 0x13) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001488 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
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 &= 0xC0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001491 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001492 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301493 data |= 0x01;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001494 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301495 } else {
1496 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001497 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x0E);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001498 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301499 data &= 0xC0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001500 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301501 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001502 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0xAE);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001503 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301504 data &= 0xF0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001505 xgifb_reg_set(pVBInfo->P3c4, 0x09, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301506 }
1507 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001508
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301509 if (HwDeviceExtension->jChipType == XG21)
1510 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001511}
1512
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001513static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1514 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1515 struct vb_device_info *pVBInfo)
1516{
1517 unsigned short data, data2 = 0;
1518 short VCLK;
1519
1520 unsigned char index;
1521
1522 if (ModeNo <= 0x13)
1523 VCLK = 0;
1524 else {
1525 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1526 index &= IndexMask;
1527 VCLK = pVBInfo->VCLKData[index].CLOCK;
1528 }
1529
Aaro Koskinen58839b02011-03-13 12:26:23 +02001530 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001531 data &= 0xf3;
1532 if (VCLK >= 200)
1533 data |= 0x0c; /* VCLK > 200 */
1534
1535 if (HwDeviceExtension->jChipType >= XG20)
1536 data &= ~0x04; /* 2 pixel mode */
1537
Aaro Koskinen8104e322011-03-13 12:26:22 +02001538 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001539
1540 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001541 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001542 data &= 0xE7;
1543 if (VCLK < 200)
1544 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001545 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001546 }
1547
1548 /* Jong for Adavantech LCD ripple issue
1549 if ((VCLK >= 0) && (VCLK < 135))
1550 data2 = 0x03;
1551 else if ((VCLK >= 135) && (VCLK < 160))
1552 data2 = 0x02;
1553 else if ((VCLK >= 160) && (VCLK < 260))
1554 data2 = 0x01;
1555 else if (VCLK > 260)
1556 data2 = 0x00;
1557 */
1558 data2 = 0x00;
1559
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001560 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001561 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001562 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001563
1564}
1565
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001566static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301567 unsigned short ModeNo, unsigned short ModeIdIndex,
1568 unsigned short RefreshRateTableIndex,
1569 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001570{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301571 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1572 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001573
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301574 if (ModeNo > 0x13) {
1575 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001576 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].
1577 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301578 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001579 /* si+St_ModeFlag */
1580 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001581
Aaro Koskinen58839b02011-03-13 12:26:23 +02001582 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001583 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001584
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301585 if (ModeNo > 0x13)
1586 data = infoflag;
1587 else
1588 data = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001589
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301590 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001591
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301592 if (ModeNo > 0x13) {
1593 if (pVBInfo->ModeType > 0x02) {
1594 data2 |= 0x02;
1595 data3 = pVBInfo->ModeType - ModeVGA;
1596 data3 = data3 << 2;
1597 data2 |= data3;
1598 }
1599 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001600
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301601 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001602
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301603 if (data)
1604 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001605
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001606 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001607 /* xgifb_reg_set(pVBInfo->P3c4,0x06,data2); */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301608 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1609 if (ModeNo <= 0x13)
1610 xres = pVBInfo->StResInfo[resindex].HTotal;
1611 else
1612 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001613
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301614 data = 0x0000;
1615 if (infoflag & InterlaceMode) {
1616 if (xres == 1024)
1617 data = 0x0035;
1618 else if (xres == 1280)
1619 data = 0x0048;
1620 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001621
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301622 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001623 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301624 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001625 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001626
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301627 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001628 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001629
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301630 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001631
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301632 if (modeflag & LineCompareOff)
1633 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001634
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301635 if (ModeNo > 0x13) {
1636 if (pVBInfo->ModeType == ModeEGA)
1637 data2 |= 0x40;
1638 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001639
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001640 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301641 data = 0x60;
1642 if (pVBInfo->ModeType != ModeText) {
1643 data = data ^ 0x60;
1644 if (pVBInfo->ModeType != ModeEGA)
1645 data = data ^ 0xA0;
1646 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001647 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001648
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301649 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1650 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001651
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301652 /* if (modeflag&HalfDCLK) //030305 fix lowresolution bug */
1653 /* if (XGINew_IF_DEF_NEW_LOWRES) */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001654 /* XGI_VesaLowResolution(ModeNo, ModeIdIndex);
1655 * //030305 fix lowresolution bug */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001656
Aaro Koskinen58839b02011-03-13 12:26:23 +02001657 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001658
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301659 if (HwDeviceExtension->jChipType == XG27) {
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);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001665 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301666 } else if (HwDeviceExtension->jChipType >= XG20) {
1667 if (data & 0x40)
1668 data = 0x33;
1669 else
1670 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001671 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1672 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301673 } else {
1674 if (data & 0x40)
1675 data = 0x2c;
1676 else
1677 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001678 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301679 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001680
1681}
1682
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001683static void XGI_WriteDAC(unsigned short dl,
1684 unsigned short ah,
1685 unsigned short al,
1686 unsigned short dh,
1687 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001688{
1689 unsigned short temp, bh, bl;
1690
1691 bh = ah;
1692 bl = al;
1693
1694 if (dl != 0) {
1695 temp = bh;
1696 bh = dh;
1697 dh = temp;
1698 if (dl == 1) {
1699 temp = bl;
1700 bl = dh;
1701 dh = temp;
1702 } else {
1703 temp = bl;
1704 bl = bh;
1705 bh = temp;
1706 }
1707 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001708 outb((unsigned short) dh, pVBInfo->P3c9);
1709 outb((unsigned short) bh, pVBInfo->P3c9);
1710 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001711}
1712
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001713static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301714 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001715{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301716 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al,
Aaro Koskinen624554d2011-10-11 21:47:35 +03001717 ah, dh;
1718 const unsigned short *table = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001719
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301720 if (ModeNo <= 0x13)
1721 data = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1722 else
1723 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001724
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301725 data &= DACInfoFlag;
1726 time = 64;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001727
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301728 if (data == 0x00)
1729 table = XGINew_MDA_DAC;
1730 else if (data == 0x08)
1731 table = XGINew_CGA_DAC;
1732 else if (data == 0x10)
1733 table = XGINew_EGA_DAC;
1734 else if (data == 0x18) {
1735 time = 256;
1736 table = XGINew_VGA_DAC;
1737 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001738
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301739 if (time == 256)
1740 j = 16;
1741 else
1742 j = time;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001743
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001744 outb(0xFF, pVBInfo->P3c6);
1745 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001746
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301747 for (i = 0; i < j; i++) {
1748 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001749
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301750 for (k = 0; k < 3; k++) {
1751 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001752
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301753 if (data & 0x01)
1754 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001755
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301756 if (data & 0x02)
1757 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001758
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001759 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301760 data = data >> 2;
1761 }
1762 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001763
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301764 if (time == 256) {
1765 for (i = 16; i < 32; i++) {
1766 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001767
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301768 for (k = 0; k < 3; k++)
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001769 outb(data, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301770 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001771
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301772 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001773
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301774 for (m = 0; m < 9; m++) {
1775 di = si;
1776 bx = si + 0x04;
1777 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001778
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301779 for (n = 0; n < 3; n++) {
1780 for (o = 0; o < 5; o++) {
1781 dh = table[si];
1782 ah = table[di];
1783 al = table[bx];
1784 si++;
1785 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1786 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001787
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301788 si -= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001789
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301790 for (o = 0; o < 3; o++) {
1791 dh = table[bx];
1792 ah = table[di];
1793 al = table[si];
1794 si--;
1795 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1796 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301798 dl++;
1799 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301801 si += 5;
1802 }
1803 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001804}
1805
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001806static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1807 unsigned short ModeIdIndex,
1808 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001809{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301810 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001811
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301812 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001813 /* si+St_ResInfo */
1814 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301815 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001816 /* si+Ext_ResInfo */
1817 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001818
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301819 /* if (ModeNo > 0x13) */
1820 /* modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag; */
1821 /* else */
1822 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001823
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301824 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001825 /* si+St_ResInfo */
1826 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301827 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001828 /* si+Ext_ResInfo */
1829 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001830
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301831 /* resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301833 if (ModeNo <= 0x13) {
1834 xres = pVBInfo->StResInfo[resindex].HTotal;
1835 yres = pVBInfo->StResInfo[resindex].VTotal;
1836 } else {
1837 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1838 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1839 }
1840 if (ModeNo > 0x13) {
1841 if (modeflag & HalfDCLK)
1842 xres = xres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001843
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301844 if (modeflag & DoubleScanMode)
1845 yres = yres << 1;
1846 }
1847 /* if (modeflag & Charx8Dot) */
1848 /* { */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001849
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301850 if (xres == 720)
1851 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001852
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301853 /* } */
1854 pVBInfo->VGAHDE = xres;
1855 pVBInfo->HDE = xres;
1856 pVBInfo->VGAVDE = yres;
1857 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001858}
1859
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001860static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1861 unsigned short ModeIdIndex,
1862 unsigned short RefreshRateTableIndex,
1863 struct vb_device_info *pVBInfo)
1864{
1865 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1866
1867 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1868
1869 tempbx = BX;
1870
1871 if (ModeNo <= 0x13) {
1872 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1873 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1874 } else {
1875 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1876 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1877 }
1878
1879 tempal = tempal & 0x0f;
1880
1881 if (tempbx <= 1) { /* ExpLink */
1882 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001883 /* find no Ext_CRT2CRTC2 */
1884 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001885 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001886 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1887 Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001888 }
1889
1890 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
1891 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001892 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
1893 St_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001894 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001895 tempal = pVBInfo->RefIndex[
1896 RefreshRateTableIndex].
1897 Ext_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001898 }
1899
1900 if (tempbx & 0x01)
1901 tempal = (tempal >> 4);
1902
1903 tempal = (tempal & 0x0f);
1904 }
1905
1906 tempcx = LCDLenList[tempbx]; /* mov cl,byte ptr cs:LCDLenList[bx] */
1907
1908 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1909 if ((tempbx == 5) || (tempbx) == 7)
1910 tempcx = LCDDesDataLen2;
1911 else if ((tempbx == 3) || (tempbx == 8))
1912 tempcx = LVDSDesDataLen2;
1913 }
1914 /* mov di, word ptr cs:LCDDataList[bx] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001915 /* tempdi = pVideoMemory[LCDDataList + tempbx * 2] |
1916 (pVideoMemory[LCDDataList + tempbx * 2 + 1] << 8); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001917
1918 switch (tempbx) {
1919 case 0:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001920 case 1:
Aaro Koskinencc5c2ae2011-08-31 21:46:08 +03001921 tempdi = xgifb_epllcd_crt1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001922 break;
1923 case 2:
1924 tempdi = XGI_EPLLCDDataPtr;
1925 break;
1926 case 3:
1927 tempdi = XGI_EPLLCDDesDataPtr;
1928 break;
1929 case 4:
1930 tempdi = XGI_LCDDataTable;
1931 break;
1932 case 5:
1933 tempdi = XGI_LCDDesDataTable;
1934 break;
1935 case 6:
1936 tempdi = XGI_EPLCHLCDRegPtr;
1937 break;
1938 case 7:
1939 case 8:
1940 case 9:
1941 tempdi = NULL;
1942 break;
1943 default:
1944 break;
1945 }
1946
1947 if (tempdi == NULL) /* OEMUtil */
1948 return NULL;
1949
1950 table = tempbx;
1951 i = 0;
1952
1953 while (tempdi[i].PANELID != 0xff) {
1954 tempdx = pVBInfo->LCDResInfo;
1955 if (tempbx & 0x0080) { /* OEMUtil */
1956 tempbx &= (~0x0080);
1957 tempdx = pVBInfo->LCDTypeInfo;
1958 }
1959
1960 if (pVBInfo->LCDInfo & EnableScalingLCD)
1961 tempdx &= (~PanelResInfo);
1962
1963 if (tempdi[i].PANELID == tempdx) {
1964 tempbx = tempdi[i].MASK;
1965 tempdx = pVBInfo->LCDInfo;
1966
1967 if (ModeNo <= 0x13) /* alan 09/10/2003 */
1968 tempdx |= SetLCDStdMode;
1969
1970 if (modeflag & HalfDCLK)
1971 tempdx |= SetLCDLowResolution;
1972
1973 tempbx &= tempdx;
1974 if (tempbx == tempdi[i].CAP)
1975 break;
1976 }
1977 i++;
1978 }
1979
1980 if (table == 0) {
1981 switch (tempdi[i].DATAPTR) {
1982 case 0:
1983 return &XGI_LVDSCRT11024x768_1_H[tempal];
1984 break;
1985 case 1:
1986 return &XGI_LVDSCRT11024x768_2_H[tempal];
1987 break;
1988 case 2:
1989 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1990 break;
1991 case 3:
1992 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1993 break;
1994 case 4:
1995 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1996 break;
1997 case 5:
1998 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1999 break;
2000 case 6:
2001 return &XGI_LVDSCRT11600x1200_1_H[tempal];
2002 break;
2003 case 7:
2004 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
2005 break;
2006 case 8:
2007 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
2008 break;
2009 case 9:
2010 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
2011 break;
2012 case 10:
2013 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
2014 break;
2015 default:
2016 break;
2017 }
2018 } else if (table == 1) {
2019 switch (tempdi[i].DATAPTR) {
2020 case 0:
2021 return &XGI_LVDSCRT11024x768_1_V[tempal];
2022 break;
2023 case 1:
2024 return &XGI_LVDSCRT11024x768_2_V[tempal];
2025 break;
2026 case 2:
2027 return &XGI_LVDSCRT11280x1024_1_V[tempal];
2028 break;
2029 case 3:
2030 return &XGI_LVDSCRT11280x1024_2_V[tempal];
2031 break;
2032 case 4:
2033 return &XGI_LVDSCRT11400x1050_1_V[tempal];
2034 break;
2035 case 5:
2036 return &XGI_LVDSCRT11400x1050_2_V[tempal];
2037 break;
2038 case 6:
2039 return &XGI_LVDSCRT11600x1200_1_V[tempal];
2040 break;
2041 case 7:
2042 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
2043 break;
2044 case 8:
2045 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
2046 break;
2047 case 9:
2048 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
2049 break;
2050 case 10:
2051 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
2052 break;
2053 default:
2054 break;
2055 }
2056 } else if (table == 2) {
2057 switch (tempdi[i].DATAPTR) {
2058 case 0:
2059 return &XGI_LVDS1024x768Data_1[tempal];
2060 break;
2061 case 1:
2062 return &XGI_LVDS1024x768Data_2[tempal];
2063 break;
2064 case 2:
2065 return &XGI_LVDS1280x1024Data_1[tempal];
2066 break;
2067 case 3:
2068 return &XGI_LVDS1280x1024Data_2[tempal];
2069 break;
2070 case 4:
2071 return &XGI_LVDS1400x1050Data_1[tempal];
2072 break;
2073 case 5:
2074 return &XGI_LVDS1400x1050Data_2[tempal];
2075 break;
2076 case 6:
2077 return &XGI_LVDS1600x1200Data_1[tempal];
2078 break;
2079 case 7:
2080 return &XGI_LVDSNoScalingData[tempal];
2081 break;
2082 case 8:
2083 return &XGI_LVDS1024x768Data_1x75[tempal];
2084 break;
2085 case 9:
2086 return &XGI_LVDS1024x768Data_2x75[tempal];
2087 break;
2088 case 10:
2089 return &XGI_LVDS1280x1024Data_1x75[tempal];
2090 break;
2091 case 11:
2092 return &XGI_LVDS1280x1024Data_2x75[tempal];
2093 break;
2094 case 12:
2095 return &XGI_LVDSNoScalingDatax75[tempal];
2096 break;
2097 default:
2098 break;
2099 }
2100 } else if (table == 3) {
2101 switch (tempdi[i].DATAPTR) {
2102 case 0:
2103 return &XGI_LVDS1024x768Des_1[tempal];
2104 break;
2105 case 1:
2106 return &XGI_LVDS1024x768Des_3[tempal];
2107 break;
2108 case 2:
2109 return &XGI_LVDS1024x768Des_2[tempal];
2110 break;
2111 case 3:
2112 return &XGI_LVDS1280x1024Des_1[tempal];
2113 break;
2114 case 4:
2115 return &XGI_LVDS1280x1024Des_2[tempal];
2116 break;
2117 case 5:
2118 return &XGI_LVDS1400x1050Des_1[tempal];
2119 break;
2120 case 6:
2121 return &XGI_LVDS1400x1050Des_2[tempal];
2122 break;
2123 case 7:
2124 return &XGI_LVDS1600x1200Des_1[tempal];
2125 break;
2126 case 8:
2127 return &XGI_LVDSNoScalingDesData[tempal];
2128 break;
2129 case 9:
2130 return &XGI_LVDS1024x768Des_1x75[tempal];
2131 break;
2132 case 10:
2133 return &XGI_LVDS1024x768Des_3x75[tempal];
2134 break;
2135 case 11:
2136 return &XGI_LVDS1024x768Des_2x75[tempal];
2137 break;
2138 case 12:
2139 return &XGI_LVDS1280x1024Des_1x75[tempal];
2140 break;
2141 case 13:
2142 return &XGI_LVDS1280x1024Des_2x75[tempal];
2143 break;
2144 case 14:
2145 return &XGI_LVDSNoScalingDesDatax75[tempal];
2146 break;
2147 default:
2148 break;
2149 }
2150 } else if (table == 4) {
2151 switch (tempdi[i].DATAPTR) {
2152 case 0:
2153 return &XGI_ExtLCD1024x768Data[tempal];
2154 break;
2155 case 1:
2156 return &XGI_StLCD1024x768Data[tempal];
2157 break;
2158 case 2:
2159 return &XGI_CetLCD1024x768Data[tempal];
2160 break;
2161 case 3:
2162 return &XGI_ExtLCD1280x1024Data[tempal];
2163 break;
2164 case 4:
2165 return &XGI_StLCD1280x1024Data[tempal];
2166 break;
2167 case 5:
2168 return &XGI_CetLCD1280x1024Data[tempal];
2169 break;
2170 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002171 case 7:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002172 return &xgifb_lcd_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002173 break;
2174 case 8:
2175 return &XGI_CetLCD1400x1050Data[tempal];
2176 break;
2177 case 9:
2178 return &XGI_ExtLCD1600x1200Data[tempal];
2179 break;
2180 case 10:
2181 return &XGI_StLCD1600x1200Data[tempal];
2182 break;
2183 case 11:
2184 return &XGI_NoScalingData[tempal];
2185 break;
2186 case 12:
2187 return &XGI_ExtLCD1024x768x75Data[tempal];
2188 break;
2189 case 13:
2190 return &XGI_ExtLCD1024x768x75Data[tempal];
2191 break;
2192 case 14:
2193 return &XGI_CetLCD1024x768x75Data[tempal];
2194 break;
2195 case 15:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002196 case 16:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002197 return &xgifb_lcd_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002198 break;
2199 case 17:
2200 return &XGI_CetLCD1280x1024x75Data[tempal];
2201 break;
2202 case 18:
2203 return &XGI_NoScalingDatax75[tempal];
2204 break;
2205 default:
2206 break;
2207 }
2208 } else if (table == 5) {
2209 switch (tempdi[i].DATAPTR) {
2210 case 0:
2211 return &XGI_ExtLCDDes1024x768Data[tempal];
2212 break;
2213 case 1:
2214 return &XGI_StLCDDes1024x768Data[tempal];
2215 break;
2216 case 2:
2217 return &XGI_CetLCDDes1024x768Data[tempal];
2218 break;
2219 case 3:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002220 if ((pVBInfo->VBType & VB_XGI301LV) ||
2221 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002222 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
2223 else
2224 return &XGI_ExtLCDDes1280x1024Data[tempal];
2225 break;
2226 case 4:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002227 if ((pVBInfo->VBType & VB_XGI301LV) ||
2228 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002229 return &XGI_StLCDDLDes1280x1024Data[tempal];
2230 else
2231 return &XGI_StLCDDes1280x1024Data[tempal];
2232 break;
2233 case 5:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002234 if ((pVBInfo->VBType & VB_XGI301LV) ||
2235 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002236 return &XGI_CetLCDDLDes1280x1024Data[tempal];
2237 else
2238 return &XGI_CetLCDDes1280x1024Data[tempal];
2239 break;
2240 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002241 case 7:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002242 if ((pVBInfo->VBType & VB_XGI301LV) ||
2243 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002244 return &xgifb_lcddldes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002245 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002246 return &xgifb_lcddes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002247 break;
2248 case 8:
2249 return &XGI_CetLCDDes1400x1050Data[tempal];
2250 break;
2251 case 9:
2252 return &XGI_CetLCDDes1400x1050Data2[tempal];
2253 break;
2254 case 10:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002255 if ((pVBInfo->VBType & VB_XGI301LV) ||
2256 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002257 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
2258 else
2259 return &XGI_ExtLCDDes1600x1200Data[tempal];
2260 break;
2261 case 11:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002262 if ((pVBInfo->VBType & VB_XGI301LV) ||
2263 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002264 return &XGI_StLCDDLDes1600x1200Data[tempal];
2265 else
2266 return &XGI_StLCDDes1600x1200Data[tempal];
2267 break;
2268 case 12:
2269 return &XGI_NoScalingDesData[tempal];
2270 break;
2271 case 13:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002272 case 14:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002273 return &xgifb_lcddes_1024x768x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002274 break;
2275 case 15:
2276 return &XGI_CetLCDDes1024x768x75Data[tempal];
2277 break;
2278 case 16:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002279 case 17:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002280 if ((pVBInfo->VBType & VB_XGI301LV) ||
2281 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002282 return &xgifb_lcddldes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002283 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002284 return &xgifb_lcddes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002285 break;
2286 case 18:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002287 if ((pVBInfo->VBType & VB_XGI301LV) ||
2288 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002289 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
2290 else
2291 return &XGI_CetLCDDes1280x1024x75Data[tempal];
2292 break;
2293 case 19:
2294 return &XGI_NoScalingDesDatax75[tempal];
2295 break;
2296 default:
2297 break;
2298 }
2299 } else if (table == 6) {
2300 switch (tempdi[i].DATAPTR) {
2301 case 0:
2302 return &XGI_CH7017LV1024x768[tempal];
2303 break;
2304 case 1:
2305 return &XGI_CH7017LV1400x1050[tempal];
2306 break;
2307 default:
2308 break;
2309 }
2310 }
2311 return NULL;
2312}
2313
2314static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
2315 unsigned short ModeIdIndex,
2316 unsigned short RefreshRateTableIndex,
2317 struct vb_device_info *pVBInfo)
2318{
2319 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
2320 struct XGI330_TVDataTablStruct *tempdi = NULL;
2321
2322 tempbx = BX;
2323
2324 if (ModeNo <= 0x13) {
2325 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2326 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2327 } else {
2328 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2329 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2330 }
2331
2332 tempal = tempal & 0x3f;
2333 table = tempbx;
2334
2335 switch (tempbx) {
2336 case 0:
2337 tempdi = NULL; /*EPLCHTVCRT1Ptr_H;*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002338 break;
2339 case 1:
2340 tempdi = NULL; /*EPLCHTVCRT1Ptr_V;*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002341 break;
2342 case 2:
Aaro Koskinen0c23b6d2011-08-31 21:46:09 +03002343 case 6:
2344 tempdi = xgifb_chrontel_tv;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002345 break;
2346 case 3:
2347 tempdi = NULL;
2348 break;
2349 case 4:
2350 tempdi = XGI_TVDataTable;
2351 break;
2352 case 5:
2353 tempdi = NULL;
2354 break;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002355 default:
2356 break;
2357 }
2358
2359 if (tempdi == NULL) /* OEMUtil */
2360 return NULL;
2361
2362 tempdx = pVBInfo->TVInfo;
2363
2364 if (pVBInfo->VBInfo & SetInSlaveMode)
2365 tempdx = tempdx | SetTVLockMode;
2366
2367 if (modeflag & HalfDCLK)
2368 tempdx = tempdx | SetTVLowResolution;
2369
2370 i = 0;
2371
2372 while (tempdi[i].MASK != 0xffff) {
2373 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2374 break;
2375 i++;
2376 }
2377
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002378 /* 07/05/22 */
2379 if (table == 0x00) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002380 } else if (table == 0x01) {
2381 } else if (table == 0x04) {
2382 switch (tempdi[i].DATAPTR) {
2383 case 0:
2384 return &XGI_ExtPALData[tempal];
2385 break;
2386 case 1:
2387 return &XGI_ExtNTSCData[tempal];
2388 break;
2389 case 2:
2390 return &XGI_StPALData[tempal];
2391 break;
2392 case 3:
2393 return &XGI_StNTSCData[tempal];
2394 break;
2395 case 4:
2396 return &XGI_ExtHiTVData[tempal];
2397 break;
2398 case 5:
2399 return &XGI_St2HiTVData[tempal];
2400 break;
2401 case 6:
2402 return &XGI_ExtYPbPr525iData[tempal];
2403 break;
2404 case 7:
2405 return &XGI_ExtYPbPr525pData[tempal];
2406 break;
2407 case 8:
2408 return &XGI_ExtYPbPr750pData[tempal];
2409 break;
2410 case 9:
2411 return &XGI_StYPbPr525iData[tempal];
2412 break;
2413 case 10:
2414 return &XGI_StYPbPr525pData[tempal];
2415 break;
2416 case 11:
2417 return &XGI_StYPbPr750pData[tempal];
2418 break;
2419 case 12: /* avoid system hang */
2420 return &XGI_ExtNTSCData[tempal];
2421 break;
2422 case 13:
2423 return &XGI_St1HiTVData[tempal];
2424 break;
2425 default:
2426 break;
2427 }
2428 } else if (table == 0x02) {
2429 switch (tempdi[i].DATAPTR) {
2430 case 0:
2431 return &XGI_CHTVUNTSCData[tempal];
2432 break;
2433 case 1:
2434 return &XGI_CHTVONTSCData[tempal];
2435 break;
2436 case 2:
2437 return &XGI_CHTVUPALData[tempal];
2438 break;
2439 case 3:
2440 return &XGI_CHTVOPALData[tempal];
2441 break;
2442 default:
2443 break;
2444 }
2445 } else if (table == 0x06) {
2446 }
2447 return NULL;
2448}
2449
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002450static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302451 unsigned short RefreshRateTableIndex,
2452 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002453{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302454 unsigned short tempbx;
2455 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002456
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302457 tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002458
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302459 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2460 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2461 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2462 pVBInfo);
2463 pVBInfo->VGAHT = LCDPtr->VGAHT;
2464 pVBInfo->VGAVT = LCDPtr->VGAVT;
2465 pVBInfo->HT = LCDPtr->LCDHT;
2466 pVBInfo->VT = LCDPtr->LCDVT;
2467 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002468
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302469 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2470 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2471 | EnableScalingLCD))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002472 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2473 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302474 pVBInfo->HDE = 1024;
2475 pVBInfo->VDE = 768;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002476 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2477 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302478 pVBInfo->HDE = 1280;
2479 pVBInfo->VDE = 1024;
2480 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2481 pVBInfo->HDE = 1400;
2482 pVBInfo->VDE = 1050;
2483 } else {
2484 pVBInfo->HDE = 1600;
2485 pVBInfo->VDE = 1200;
2486 }
2487 }
2488 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002489}
2490
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002491static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302492 unsigned short RefreshRateTableIndex,
2493 struct xgi_hw_device_info *HwDeviceExtension,
2494 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002495{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302496 unsigned char index;
2497 unsigned short tempbx, i;
2498 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2499 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002500
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302501 if (ModeNo <= 0x13)
2502 index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2503 else
2504 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002505
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302506 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002507
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002508 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002509
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002510 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2511 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2512 XGI_GetLcdPtr(tempbx, ModeNo,
2513 ModeIdIndex,
2514 RefreshRateTableIndex,
2515 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002516
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002517 for (i = 0; i < 8; i++)
2518 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302519 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002520
2521 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
2522
2523 tempbx = 1;
2524
2525 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2526 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2527 XGI_GetLcdPtr(
2528 tempbx,
2529 ModeNo,
2530 ModeIdIndex,
2531 RefreshRateTableIndex,
2532 pVBInfo);
2533 for (i = 0; i < 7; i++)
2534 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2535 }
2536
2537 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002538}
2539
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002540static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2541{
2542 unsigned char tempal, tempah, tempbl, i;
2543
Aaro Koskinen58839b02011-03-13 12:26:23 +02002544 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002545 tempal = tempah & 0x0F;
2546 tempah = tempah & 0xF0;
2547 i = 0;
2548 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2549
2550 while (tempbl != 0xFF) {
2551 if (tempbl & 0x80) { /* OEMUtil */
2552 tempal = tempah;
2553 tempbl = tempbl & ~(0x80);
2554 }
2555
2556 if (tempal == tempbl)
2557 break;
2558
2559 i++;
2560
2561 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2562 }
2563
2564 return i;
2565}
2566
2567static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2568{
2569 unsigned short tempah, tempal, tempbl, i;
2570
2571 tempal = pVBInfo->LCDResInfo;
2572 tempah = pVBInfo->LCDTypeInfo;
2573
2574 i = 0;
2575 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2576
2577 while (tempbl != 0xFF) {
2578 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2579 tempal = tempah;
2580 tempbl &= ~0x80;
2581 }
2582
2583 if (tempal == tempbl)
2584 break;
2585
2586 i++;
2587 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2588 }
2589
2590 if (tempbl == 0xFF) {
2591 pVBInfo->LCDResInfo = Panel1024x768;
2592 pVBInfo->LCDTypeInfo = 0;
2593 i = 0;
2594 }
2595
2596 return i;
2597}
2598
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002599static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2600 unsigned short *VSyncWidth,
2601 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002602{
2603 unsigned short Index;
2604
2605 Index = XGI_GetLCDCapPtr(pVBInfo);
2606 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2607 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2608
2609 return;
2610}
2611
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002612static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302613 unsigned short RefreshRateTableIndex,
2614 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002615{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302616 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2617 unsigned long temp, temp1, temp2, temp3, push3;
2618 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2619 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002620
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302621 if (ModeNo > 0x13)
2622 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2623 else
2624 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002625
Aaro Koskinen66cface2011-08-31 21:46:13 +03002626 tempbx = 3;
2627 if (pVBInfo->LCDInfo & EnableScalingLCD)
2628 LCDPtr1 =
2629 (struct XGI330_LCDDataDesStruct2 *)
2630 XGI_GetLcdPtr(
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002631 tempbx,
2632 ModeNo,
2633 ModeIdIndex,
2634 RefreshRateTableIndex,
2635 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03002636 else
2637 LCDPtr =
2638 (struct XGI330_LCDDataDesStruct *)
2639 XGI_GetLcdPtr(
2640 tempbx,
2641 ModeNo,
2642 ModeIdIndex,
2643 RefreshRateTableIndex,
2644 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002645
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002646 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2647 push1 = tempbx;
2648 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002649
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002650 /* GetLCDResInfo */
2651 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2652 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2653 tempax = 1024;
2654 tempbx = 768;
2655 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2656 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2657 tempax = 1280;
2658 tempbx = 1024;
2659 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2660 tempax = 1400;
2661 tempbx = 1050;
2662 } else {
2663 tempax = 1600;
2664 tempbx = 1200;
2665 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002666
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002667 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2668 pVBInfo->HDE = tempax;
2669 pVBInfo->VDE = tempbx;
2670 pVBInfo->VGAHDE = tempax;
2671 pVBInfo->VGAVDE = tempbx;
2672 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002673
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002674 tempax = pVBInfo->HT;
2675
2676 if (pVBInfo->LCDInfo & EnableScalingLCD)
2677 tempbx = LCDPtr1->LCDHDES;
2678 else
2679 tempbx = LCDPtr->LCDHDES;
2680
2681 tempcx = pVBInfo->HDE;
2682 tempbx = tempbx & 0x0fff;
2683 tempcx += tempbx;
2684
2685 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002686 tempcx -= tempax;
2687
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002688 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002689
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002690 tempcx = tempcx >> 3;
2691 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002692
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002693 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2694 (unsigned short) (tempbx & 0xff));
2695 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2696 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002697
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002698 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002699
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002700 if (pVBInfo->LCDInfo & EnableScalingLCD)
2701 tempbx = LCDPtr1->LCDHRS;
2702 else
2703 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002704
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002705 tempcx = push2;
2706
2707 if (pVBInfo->LCDInfo & EnableScalingLCD)
2708 tempcx = LCDPtr1->LCDHSync;
2709
2710 tempcx += tempbx;
2711
2712 if (tempcx >= tempax)
2713 tempcx -= tempax;
2714
2715 tempax = tempbx & 0x07;
2716 tempax = tempax >> 5;
2717 tempcx = tempcx >> 3;
2718 tempbx = tempbx >> 3;
2719
2720 tempcx &= 0x1f;
2721 tempax |= tempcx;
2722
2723 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2724 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2725 (unsigned short) (tempbx & 0xff));
2726
2727 tempax = pVBInfo->VT;
2728 if (pVBInfo->LCDInfo & EnableScalingLCD)
2729 tempbx = LCDPtr1->LCDVDES;
2730 else
2731 tempbx = LCDPtr->LCDVDES;
2732 tempcx = pVBInfo->VDE;
2733
2734 tempbx = tempbx & 0x0fff;
2735 tempcx += tempbx;
2736 if (tempcx >= tempax)
2737 tempcx -= tempax;
2738
2739 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2740 (unsigned short) (tempbx & 0xff));
2741 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2742 (unsigned short) (tempcx & 0xff));
2743
2744 tempbx = (tempbx >> 8) & 0x07;
2745 tempcx = (tempcx >> 8) & 0x07;
2746
2747 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2748 (unsigned short) ((tempcx << 3)
2749 | tempbx));
2750
2751 tempax = pVBInfo->VT;
2752 if (pVBInfo->LCDInfo & EnableScalingLCD)
2753 tempbx = LCDPtr1->LCDVRS;
2754 else
2755 tempbx = LCDPtr->LCDVRS;
2756
2757 /* tempbx = tempbx >> 4; */
2758 tempcx = push1;
2759
2760 if (pVBInfo->LCDInfo & EnableScalingLCD)
2761 tempcx = LCDPtr1->LCDVSync;
2762
2763 tempcx += tempbx;
2764 if (tempcx >= tempax)
2765 tempcx -= tempax;
2766
2767 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2768 (unsigned short) (tempbx & 0xff));
2769 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2770 (unsigned short) (tempcx & 0x0f));
2771
2772 tempax = ((tempbx >> 8) & 0x07) << 3;
2773
2774 tempbx = pVBInfo->VGAVDE;
2775 if (tempbx != pVBInfo->VDE)
2776 tempax |= 0x40;
2777
2778 if (pVBInfo->LCDInfo & EnableLVDSDDA)
2779 tempax |= 0x40;
2780
2781 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2782 tempax);
2783
2784 tempcx = pVBInfo->VGAVT;
2785 tempbx = pVBInfo->VDE;
2786 tempax = pVBInfo->VGAVDE;
2787 tempcx -= tempax;
2788
2789 temp = tempax; /* 0430 ylshieh */
2790 temp1 = (temp << 18) / tempbx;
2791
2792 tempdx = (unsigned short) ((temp << 18) % tempbx);
2793
2794 if (tempdx != 0)
2795 temp1 += 1;
2796
2797 temp2 = temp1;
2798 push3 = temp2;
2799
2800 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2801 (unsigned short) (temp2 & 0xff));
2802 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2803 (unsigned short) ((temp2 >> 8) & 0xff));
2804
2805 tempbx = (unsigned short) (temp2 >> 16);
2806 tempax = tempbx & 0x03;
2807
2808 tempbx = pVBInfo->VGAVDE;
2809 if (tempbx == pVBInfo->VDE)
2810 tempax |= 0x04;
2811
2812 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2813
2814 if (pVBInfo->VBType & VB_XGI301C) {
2815 temp2 = push3;
2816 xgifb_reg_set(pVBInfo->Part4Port,
2817 0x3c,
2818 (unsigned short) (temp2 & 0xff));
2819 xgifb_reg_set(pVBInfo->Part4Port,
2820 0x3b,
2821 (unsigned short) ((temp2 >> 8) &
2822 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002823 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002824 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2825 ~0xc0,
2826 (unsigned short) ((tempbx &
2827 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002828
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002829 tempcx = pVBInfo->VGAVDE;
2830 if (tempcx == pVBInfo->VDE)
2831 xgifb_reg_and_or(pVBInfo->Part4Port,
2832 0x30, ~0x0c, 0x00);
2833 else
2834 xgifb_reg_and_or(pVBInfo->Part4Port,
2835 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302836 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002837
2838 tempcx = pVBInfo->VGAHDE;
2839 tempbx = pVBInfo->HDE;
2840
2841 temp1 = tempcx << 16;
2842
2843 tempax = (unsigned short) (temp1 / tempbx);
2844
2845 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2846 tempax = 65535;
2847
2848 temp3 = tempax;
2849 temp1 = pVBInfo->VGAHDE << 16;
2850
2851 temp1 /= temp3;
2852 temp3 = temp3 << 16;
2853 temp1 -= 1;
2854
2855 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2856
2857 tempax = (unsigned short) (temp3 & 0xff);
2858 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2859
2860 temp1 = pVBInfo->VGAVDE << 18;
2861 temp1 = temp1 / push3;
2862 tempbx = (unsigned short) (temp1 & 0xffff);
2863
2864 if (pVBInfo->LCDResInfo == Panel1024x768)
2865 tempbx -= 1;
2866
2867 tempax = ((tempbx >> 8) & 0xff) << 3;
2868 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2869 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2870 (unsigned short) (tempax & 0xff));
2871 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2872 (unsigned short) (tempbx & 0xff));
2873
2874 temp3 = temp3 >> 16;
2875
2876 if (modeflag & HalfDCLK)
2877 temp3 = temp3 >> 1;
2878
2879 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2880 (unsigned short) ((temp3 >> 8) & 0xff));
2881 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2882 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002883}
2884
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002885/* --------------------------------------------------------------------- */
2886/* Function : XGI_GETLCDVCLKPtr */
2887/* Input : */
2888/* Output : al -> VCLK Index */
2889/* Description : */
2890/* --------------------------------------------------------------------- */
2891static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2892 struct vb_device_info *pVBInfo)
2893{
2894 unsigned short index;
2895
2896 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002897 /* index = XGI_GetLCDCapPtr(pVBInfo); */
2898 index = XGI_GetLCDCapPtr1(pVBInfo);
2899
2900 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2901 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2902 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2903 } else { /* LCDA */
2904 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2905 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2906 }
2907 }
2908 return;
2909}
2910
2911static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2912 unsigned short ModeNo, unsigned short ModeIdIndex,
2913 struct vb_device_info *pVBInfo)
2914{
2915
2916 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002917 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002918
2919 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002920 /* si+St_ResInfo */
2921 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002922 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002923 /* si+Ext_ResInfo */
2924 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002925
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002926 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2927 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002928 index = XGI_GetLCDCapPtr(pVBInfo);
2929 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2930
2931 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
2932 return tempal;
2933
2934 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002935 if (pVBInfo->VBType &
2936 (VB_XGI301B |
2937 VB_XGI302B |
2938 VB_XGI301LV |
2939 VB_XGI302LV |
2940 VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002941 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
2942 tempal = HiTVVCLKDIV2;
2943 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2944 tempal = HiTVVCLK;
2945 if (pVBInfo->TVInfo & TVSimuMode) {
2946 tempal = HiTVSimuVCLK;
2947 if (!(modeflag & Charx8Dot))
2948 tempal = HiTVTextVCLK;
2949
2950 }
2951 return tempal;
2952 }
2953
2954 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
2955 tempal = YPbPr750pVCLK;
2956 return tempal;
2957 }
2958
2959 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
2960 tempal = YPbPr525pVCLK;
2961 return tempal;
2962 }
2963
2964 tempal = NTSC1024VCLK;
2965
2966 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
2967 tempal = TVVCLKDIV2;
2968 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2969 tempal = TVVCLK;
2970 }
2971
2972 if (pVBInfo->VBInfo & SetCRT2ToTV)
2973 return tempal;
2974 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002975 } /* {End of VB} */
2976
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002977 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002978 tempal = tempal >> 2;
2979 tempal &= 0x03;
2980
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002981 /* for Dot8 Scaling LCD */
2982 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002983 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2984
2985 if (ModeNo <= 0x13)
2986 return tempal;
2987
2988 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2989 return tempal;
2990}
2991
2992static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
2993 unsigned char *di_1, struct vb_device_info *pVBInfo)
2994{
Aaro Koskinen83f76a92011-08-31 21:45:58 +03002995 if (pVBInfo->VBType & (VB_XGI301 | VB_XGI301B | VB_XGI302B
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002996 | VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
2997 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) && (pVBInfo->SetFlag
2998 & ProgrammingCRT2)) {
2999 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
3000 *di_1 = XGI_VBVCLKData[tempal].SR2C;
3001 }
3002 } else {
3003 *di_0 = XGI_VCLKData[tempal].SR2B;
3004 *di_1 = XGI_VCLKData[tempal].SR2C;
3005 }
3006}
3007
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003008static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303009 unsigned short RefreshRateTableIndex,
3010 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003011{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303012 unsigned char di_0, di_1, tempal;
3013 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003014
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303015 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3016 pVBInfo);
3017 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3018 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003019
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303020 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003021 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303022 (unsigned short) (0x10 * i));
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003023 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303024 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003025 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
3026 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303027 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003028 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
3029 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303030 }
3031 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003032}
3033
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003034static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303035 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003036{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303037 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303039 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
3040 | VB_XGI302LV | VB_XGI301C)) {
3041 tempcl = 0;
3042 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003043 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303045 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003046 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303047 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003048 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303049 if (!(temp & 0x40))
3050 tempcl |= ActiveCRT1;
3051 }
3052 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003053
Aaro Koskinen58839b02011-03-13 12:26:23 +02003054 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303055 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003056
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303057 if (!(temp == 0x08)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003058 /* Check ChannelA by Part1_13 [2003/10/03] */
3059 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303060 if (tempax & 0x04)
3061 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003062
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303063 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003064
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303065 if (!(tempcl & ActiveLCD))
3066 if (temp == 0x01)
3067 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003068
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303069 if (temp == 0x04)
3070 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003071
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303072 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003073 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003074
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303075 if (!(temp & 0x08))
3076 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303078 if (!(temp & 0x04))
3079 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003080
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303081 if (temp & 0x02)
3082 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303084 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3085 if (temp & 0x01)
3086 tempch |= ActiveHiTV;
3087 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303089 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003090 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303091 pVBInfo->Part2Port,
3092 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003093
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303094 if (temp & 0x10)
3095 tempch |= ActiveYPbPr;
3096 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303098 if (tempch != 0)
3099 tempcl |= ActiveTV;
3100 }
3101 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003102
Aaro Koskinen58839b02011-03-13 12:26:23 +02003103 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303104 if (tempcl & ActiveLCD) {
3105 if ((pVBInfo->SetFlag & ReserveTVOption)) {
3106 if (temp & ActiveTV)
3107 tempcl |= ActiveTV;
3108 }
3109 }
3110 temp = tempcl;
3111 tempbl = ~ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003112 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303114 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003115 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303116 } else {
3117 return;
3118 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003119}
3120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303121void XGI_GetVGAType(struct xgi_hw_device_info *HwDeviceExtension,
3122 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003123{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303124 /*
3125 if ( HwDeviceExtension->jChipType >= XG20 ) {
3126 pVBInfo->Set_VGAType = XG20;
Aaro Koskinen06587332011-03-13 12:26:10 +02003127 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303128 pVBInfo->Set_VGAType = VGA_XGI340;
3129 }
3130 */
3131 pVBInfo->Set_VGAType = HwDeviceExtension->jChipType;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003132}
3133
Bill Pemberton80adad82010-06-17 13:10:51 -04003134void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003135{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303136 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303138 if (pVBInfo->IF_DEF_LVDS == 0) {
3139 tempbx = VB_XGI302B;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003140 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303141 if (flag != 0x02) {
3142 tempbx = VB_XGI301;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003143 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303144 if (flag >= 0xB0) {
3145 tempbx = VB_XGI301B;
3146 if (flag >= 0xC0) {
3147 tempbx = VB_XGI301C;
3148 if (flag >= 0xD0) {
3149 tempbx = VB_XGI301LV;
3150 if (flag >= 0xE0) {
3151 tempbx = VB_XGI302LV;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003152 tempah = xgifb_reg_get(
3153 pVBInfo->Part4Port,
3154 0x39);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303155 if (tempah != 0xFF)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003156 tempbx =
3157 VB_XGI301C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303158 }
3159 }
3160 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303162 if (tempbx & (VB_XGI301B | VB_XGI302B)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003163 flag = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303164 pVBInfo->Part4Port,
3165 0x23);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303167 if (!(flag & 0x02))
3168 tempbx = tempbx | VB_NoLCD;
3169 }
3170 }
3171 }
3172 pVBInfo->VBType = tempbx;
3173 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003174}
3175
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303176void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3177 struct xgi_hw_device_info *HwDeviceExtension,
3178 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003179{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303180 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003181
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303182 if (ModeNo <= 0x13)
3183 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3184 else
3185 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303187 pVBInfo->SetFlag = 0;
3188 pVBInfo->ModeType = modeflag & ModeInfoFlag;
3189 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303191 if (pVBInfo->VBType & 0xFFFF) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003192 /* Check Display Device */
3193 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303194 tempbx = tempbx | temp;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003195 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303196 push = temp;
3197 push = push << 8;
3198 tempax = temp << 8;
3199 tempbx = tempbx | tempax;
3200 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr | SetCRT2ToLCDA
3201 | SetInSlaveMode | DisableCRT2Display);
3202 temp = 0xFFFF ^ temp;
3203 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003204
Aaro Koskinen58839b02011-03-13 12:26:23 +02003205 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003206
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303207 if (pVBInfo->IF_DEF_LCDA == 1) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003208
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303209 if ((pVBInfo->Set_VGAType >= XG20)
3210 || (pVBInfo->Set_VGAType >= XG40)) {
3211 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003212 /* if ((pVBInfo->VBType & VB_XGI302B)
3213 || (pVBInfo->VBType & VB_XGI301LV)
3214 || (pVBInfo->VBType & VB_XGI302LV)
3215 || (pVBInfo->VBType & VB_XGI301C))
3216 */
3217 if (pVBInfo->VBType &
3218 (VB_XGI302B |
3219 VB_XGI301LV |
3220 VB_XGI302LV |
3221 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303222 if (temp & EnableDualEdge) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003223 tempbx |=
3224 SetCRT2ToDualEdge;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003225
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303226 if (temp & SetToLCDA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003227 tempbx |=
3228 SetCRT2ToLCDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303229 }
3230 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303231 }
3232 }
3233 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003234
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303235 if (pVBInfo->IF_DEF_YPbPr == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003236 /* [Billy] 07/05/04 */
3237 if (((pVBInfo->IF_DEF_LVDS == 0) &&
3238 ((pVBInfo->VBType & VB_XGI301LV) ||
3239 (pVBInfo->VBType & VB_XGI302LV) ||
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003240 (pVBInfo->VBType & VB_XGI301C)))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303241 if (temp & SetYPbPr) { /* temp = CR38 */
3242 if (pVBInfo->IF_DEF_HiVision == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003243 /* shampoo add for new
3244 * scratch */
Aaro Koskinen58839b02011-03-13 12:26:23 +02003245 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303246 pVBInfo->P3d4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003247 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303248 temp &= YPbPrMode;
3249 tempbx |= SetCRT2ToHiVisionTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003250
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303251 if (temp != YPbPrMode1080i) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003252 tempbx &=
3253 (~SetCRT2ToHiVisionTV);
3254 tempbx |=
3255 SetCRT2ToYPbPr;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303256 }
3257 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003258
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303259 /* tempbx |= SetCRT2ToYPbPr; */
3260 }
3261 }
3262 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003263
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303264 tempax = push; /* restore CR31 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003265
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303266 if (pVBInfo->IF_DEF_LVDS == 0) {
3267 if (pVBInfo->IF_DEF_YPbPr == 1) {
3268 if (pVBInfo->IF_DEF_HiVision == 1)
3269 temp = 0x09FC;
3270 else
3271 temp = 0x097C;
3272 } else {
3273 if (pVBInfo->IF_DEF_HiVision == 1)
3274 temp = 0x01FC;
3275 else
3276 temp = 0x017C;
3277 }
3278 } else { /* 3nd party chip */
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003279 temp = SetCRT2ToLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303280 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003281
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303282 if (!(tempbx & temp)) {
3283 tempax |= DisableCRT2Display;
3284 tempbx = 0;
3285 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003286
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303287 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
3288 if (!(pVBInfo->VBType & VB_NoLCD)) {
3289 if (tempbx & SetCRT2ToLCDA) {
3290 if (tempbx & SetSimuScanMode)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003291 tempbx &= (~(SetCRT2ToLCD |
3292 SetCRT2ToRAMDAC |
3293 SwitchToCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303294 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003295 tempbx &= (~(SetCRT2ToLCD |
3296 SetCRT2ToRAMDAC |
3297 SetCRT2ToTV |
3298 SwitchToCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303299 }
3300 }
3301 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003302
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303303 /* shampoo add */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003304 /* for driver abnormal */
3305 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303306 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
3307 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003308 tempbx &= (0xFF00 |
3309 SetCRT2ToRAMDAC |
3310 SwitchToCRT2 |
3311 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303312 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3313 }
3314 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003315 tempbx &= (~(SetCRT2ToRAMDAC |
3316 SetCRT2ToLCD |
3317 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303318 }
3319 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003320
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303321 if (!(pVBInfo->VBType & VB_NoLCD)) {
3322 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003323 tempbx &= (0xFF00 |
3324 SetCRT2ToLCD |
3325 SwitchToCRT2 |
3326 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303327 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3328 }
3329 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303331 if (tempbx & SetCRT2ToSCART) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003332 tempbx &= (0xFF00 |
3333 SetCRT2ToSCART |
3334 SwitchToCRT2 |
3335 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303336 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3337 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003338
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303339 if (pVBInfo->IF_DEF_YPbPr == 1) {
3340 if (tempbx & SetCRT2ToYPbPr)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003341 tempbx &= (0xFF00 |
3342 SwitchToCRT2 |
3343 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303344 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303346 if (pVBInfo->IF_DEF_HiVision == 1) {
3347 if (tempbx & SetCRT2ToHiVisionTV)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003348 tempbx &= (0xFF00 |
3349 SetCRT2ToHiVisionTV |
3350 SwitchToCRT2 |
3351 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303352 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303354 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
3355 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode)))
3356 tempbx = DisableCRT2Display;
3357 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003358
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303359 if (!(tempbx & DisableCRT2Display)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003360 if ((!(tempbx & DriverMode)) ||
3361 (!(modeflag & CRT2Mode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303362 if (pVBInfo->IF_DEF_LCDA == 1) {
3363 if (!(tempbx & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003364 tempbx |= (SetInSlaveMode |
3365 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303366 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303367 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003368
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003369 /* LCD+TV can't support in slave mode
3370 * (Force LCDA+TV->LCDB) */
3371 if ((tempbx & SetInSlaveMode) &&
3372 (tempbx & SetCRT2ToLCDA)) {
3373 tempbx ^= (SetCRT2ToLCD |
3374 SetCRT2ToLCDA |
3375 SetCRT2ToDualEdge);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303376 pVBInfo->SetFlag |= ReserveTVOption;
3377 }
3378 }
3379 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003380
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303381 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003382}
3383
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303384void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3385 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003386{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303387 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003388
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303389 tempbx = 0;
3390 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003391
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303392 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3393 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003394 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].
3395 St_ModeFlag; /* si+St_ModeFlag */
3396 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].
3397 St_ResInfo; /* si+St_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303398 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003399 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].
3400 Ext_ModeFlag;
3401 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].
3402 Ext_RESINFO; /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303403 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003404
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303405 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003406 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303407 tempbx = temp;
3408 if (tempbx & SetPALTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003409 tempbx &= (SetCHTVOverScan |
3410 SetPALMTV |
3411 SetPALNTV |
3412 SetPALTV);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303413 if (tempbx & SetPALMTV)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003414 /* set to NTSC if PAL-M */
3415 tempbx &= ~SetPALTV;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303416 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003417 tempbx &= (SetCHTVOverScan |
3418 SetNTSCJ |
3419 SetPALTV);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303420 /*
3421 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003422 //PAL-M/PAL-N Info
3423 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3424 //00:PAL, 01:PAL-M, 10:PAL-N
3425 temp2 = (index1 & 0xC0) >> 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303426 tempbx |= temp2;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003427 if (temp2 & 0x02) //PAL-M
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303428 tempbx &= (~SetPALTV);
3429 }
3430 */
3431 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003432
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303433 if (pVBInfo->IF_DEF_LVDS == 0) {
3434 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3435 tempbx |= SetPALTV;
3436 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003437
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303438 if (pVBInfo->IF_DEF_YPbPr == 1) {
3439 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003440 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303441 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003442
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303443 if (index1 == YPbPrMode525i)
3444 tempbx |= SetYPbPrMode525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003445
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303446 if (index1 == YPbPrMode525p)
3447 tempbx = tempbx | SetYPbPrMode525p;
3448 if (index1 == YPbPrMode750p)
3449 tempbx = tempbx | SetYPbPrMode750p;
3450 }
3451 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003452
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303453 if (pVBInfo->IF_DEF_HiVision == 1) {
3454 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
3455 tempbx = tempbx | SetYPbPrMode1080i | SetPALTV;
3456 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003457
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303458 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003459 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3460 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303461 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003462
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003463 if (!(tempbx & SetPALTV) &&
3464 (modeflag > 13) &&
3465 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303466 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003467
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303468 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003469
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303470 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3471 if (pVBInfo->VBInfo & SetInSlaveMode)
3472 tempbx &= (~RPLLDIV2XO);
3473 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003474 if (tempbx &
3475 (SetYPbPrMode525p | SetYPbPrMode750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303476 tempbx &= (~RPLLDIV2XO);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003477 else if (!(pVBInfo->VBType &
3478 (VB_XGI301B |
3479 VB_XGI302B |
3480 VB_XGI301LV |
3481 VB_XGI302LV |
3482 VB_XGI301C))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303483 if (tempbx & TVSimuMode)
3484 tempbx &= (~RPLLDIV2XO);
3485 }
3486 }
3487 }
3488 }
3489 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003490}
3491
Bill Pemberton108afbf2010-06-17 13:10:47 -04003492unsigned char XGI_GetLCDInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303493 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003494{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003496
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303497 pVBInfo->LCDResInfo = 0;
3498 pVBInfo->LCDTypeInfo = 0;
3499 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003500
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303501 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003502 /* si+St_ModeFlag // */
3503 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303504 } else {
3505 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003506 /* si+Ext_ResInfo // */
3507 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303508 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003509
Aaro Koskinen58839b02011-03-13 12:26:23 +02003510 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303511 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003512
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303513 if (tempbx == 0)
3514 tempbx = Panel1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003515
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303516 /* LCD75 [2003/8/22] Vicent */
3517 if ((tempbx == Panel1024x768) || (tempbx == Panel1280x1024)) {
3518 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003519 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303520 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
3521 tempax &= 0x0F;
3522 else
3523 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003524
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303525 if ((resinfo == 6) || (resinfo == 9)) {
3526 if (tempax >= 3)
3527 tempbx |= PanelRef75Hz;
3528 } else if ((resinfo == 7) || (resinfo == 8)) {
3529 if (tempax >= 4)
3530 tempbx |= PanelRef75Hz;
3531 }
3532 }
3533 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003534
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303535 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003536
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303537 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003538
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303539 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
3540 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003541
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303542 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003543
Aaro Koskinen58839b02011-03-13 12:26:23 +02003544 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003545
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303546 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003547
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303548 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003549
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303550 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003551
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303552 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003553
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303554 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3555 if (((pVBInfo->VBType & VB_XGI302LV) || (pVBInfo->VBType
3556 & VB_XGI301C)) && (tempax & LCDDualLink)) {
3557 tempbx |= SetLCDDualLink;
3558 }
3559 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003560
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303561 if (pVBInfo->IF_DEF_LVDS == 0) {
3562 if ((pVBInfo->LCDResInfo == Panel1400x1050) && (pVBInfo->VBInfo
3563 & SetCRT2ToLCD) && (ModeNo > 0x13) && (resinfo
3564 == 9) && (!(tempbx & EnableScalingLCD)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003565 /* set to center in 1280x1024 LCDB for Panel1400x1050 */
3566 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303567 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003568
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303569 /*
3570 if (tempax & LCDBToA) {
3571 tempbx |= SetLCDBToA;
3572 }
3573 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003574
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303575 if (pVBInfo->IF_DEF_ExpLink == 1) {
3576 if (modeflag & HalfDCLK) {
3577 /* if (!(pVBInfo->LCDInfo&LCDNonExpanding)) */
3578 if (!(tempbx & SetLCDtoNonExpanding)) {
3579 tempbx |= EnableLVDSDDA;
3580 } else {
3581 if (ModeNo > 0x13) {
3582 if (pVBInfo->LCDResInfo
3583 == Panel1024x768) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003584 if (resinfo == 4) {/* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303585 tempbx |= EnableLVDSDDA;
3586 }
3587 }
3588 }
3589 }
3590 }
3591 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003592
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303593 if (pVBInfo->VBInfo & SetInSlaveMode) {
3594 if (pVBInfo->VBInfo & SetNotSimuMode)
3595 tempbx |= LCDVESATiming;
3596 } else {
3597 tempbx |= LCDVESATiming;
3598 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003599
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303600 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003601
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303602 if (pVBInfo->IF_DEF_LVDS == 0) {
3603 if (tempax & (LockLCDBToA | StLCDBToA)) {
3604 if (pVBInfo->VBInfo & SetInSlaveMode) {
3605 if (!(tempax & LockLCDBToA)) {
3606 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003607 pVBInfo->VBInfo &=
3608 ~(SetSimuScanMode |
3609 SetInSlaveMode |
3610 SetCRT2ToLCD);
3611 pVBInfo->VBInfo |=
3612 SetCRT2ToLCDA |
3613 SetCRT2ToDualEdge;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303614 }
3615 }
3616 }
3617 }
3618 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003619
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303620 /*
3621 if (pVBInfo->IF_DEF_LVDS == 0) {
3622 if (tempax & (LockLCDBToA | StLCDBToA)) {
3623 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003624 if (!((!(tempax & LockLCDBToA)) &&
3625 (ModeNo > 0x13))) {
3626 pVBInfo->VBInfo &=
3627 ~(SetSimuScanMode |
3628 SetInSlaveMode |
3629 SetCRT2ToLCD);
3630 pVBInfo->VBInfo |=
3631 SetCRT2ToLCDA |
3632 SetCRT2ToDualEdge;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303633 }
3634 }
3635 }
3636 }
3637 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003638
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303639 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003640}
3641
Bill Pemberton108afbf2010-06-17 13:10:47 -04003642unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303643 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003644{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303645 if (ModeNo <= 5)
3646 ModeNo |= 1;
3647 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003648 /* for (*ModeIdIndex=0;
3649 *ModeIdIndex < sizeof(pVBInfo->SModeIDTable)
3650 / sizeof(struct XGI_StStruct);
3651 (*ModeIdIndex)++) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303652 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003653 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3654 ModeNo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303655 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003656 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3657 0xFF)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303658 return 0;
3659 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003660
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303661 if (ModeNo == 0x07)
3662 (*ModeIdIndex)++; /* 400 lines */
3663 if (ModeNo <= 3)
3664 (*ModeIdIndex) += 2; /* 400 lines */
3665 /* else 350 lines */
3666 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003667 /* for (*ModeIdIndex=0;
3668 *ModeIdIndex < sizeof(pVBInfo->EModeIDTable)
3669 / sizeof(struct XGI_ExtStruct);
3670 (*ModeIdIndex)++) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303671 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003672 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3673 ModeNo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303674 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003675 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3676 0xFF)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303677 return 0;
3678 }
3679 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003680
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303681 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003682}
3683
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003684static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3685{
3686 unsigned char ujRet = 0;
3687 unsigned char i = 0;
3688
3689 for (i = 0; i < 8; i++) {
3690 ujRet = ujRet << 1;
3691 /* ujRet |= GETBITS(ujDate >> i, 0:0); */
3692 ujRet |= (ujDate >> i) & 1;
3693 }
3694
3695 return ujRet;
3696}
3697
3698/*----------------------------------------------------------------------------*/
3699/* output */
3700/* bl[5] : LVDS signal */
3701/* bl[1] : LVDS backlight */
3702/* bl[0] : LVDS VDD */
3703/*----------------------------------------------------------------------------*/
3704static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3705{
3706 unsigned char CR4A, temp;
3707
Aaro Koskinen58839b02011-03-13 12:26:23 +02003708 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003709 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003710
Aaro Koskinen58839b02011-03-13 12:26:23 +02003711 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003712
3713 temp = XG21GPIODataTransfer(temp);
3714 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003715 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003716 return temp;
3717}
3718
3719/*----------------------------------------------------------------------------*/
3720/* output */
3721/* bl[5] : LVDS signal */
3722/* bl[1] : LVDS backlight */
3723/* bl[0] : LVDS VDD */
3724/*----------------------------------------------------------------------------*/
3725static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3726{
3727 unsigned char CR4A, CRB4, temp;
3728
Aaro Koskinen58839b02011-03-13 12:26:23 +02003729 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003730 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003731
Aaro Koskinen58839b02011-03-13 12:26:23 +02003732 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003733
3734 temp &= 0x0C;
3735 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003736 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003737 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003738 temp |= ((CRB4 & 0x04) << 3);
3739 return temp;
3740}
3741
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303742void XGI_DisplayOn(struct xgi_hw_device_info *pXGIHWDE,
3743 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003744{
3745
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003746 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303747 if (pXGIHWDE->jChipType == XG21) {
3748 if (pVBInfo->IF_DEF_LVDS == 1) {
3749 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003750 /* LVDS VDD on */
3751 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303752 XGI_XG21SetPanelDelay(2, pVBInfo);
3753 }
3754 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003755 /* LVDS signal on */
3756 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303757 XGI_XG21SetPanelDelay(3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003758 /* LVDS backlight on */
3759 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303760 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003761 /* DVO/DVI signal on */
3762 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303763 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003764
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303765 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003766
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303767 if (pXGIHWDE->jChipType == XG27) {
3768 if (pVBInfo->IF_DEF_LVDS == 1) {
3769 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003770 /* LVDS VDD on */
3771 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303772 XGI_XG21SetPanelDelay(2, pVBInfo);
3773 }
3774 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003775 /* LVDS signal on */
3776 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303777 XGI_XG21SetPanelDelay(3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003778 /* LVDS backlight on */
3779 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303780 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003781 /* DVO/DVI signal on */
3782 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303783 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003784
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303785 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003786}
3787
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303788void XGI_DisplayOff(struct xgi_hw_device_info *pXGIHWDE,
3789 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003790{
3791
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303792 if (pXGIHWDE->jChipType == XG21) {
3793 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003794 /* LVDS backlight off */
3795 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303796 XGI_XG21SetPanelDelay(3, pVBInfo);
3797 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003798 /* DVO/DVI signal off */
3799 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303800 }
3801 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003802
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303803 if (pXGIHWDE->jChipType == XG27) {
3804 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003805 /* LVDS backlight off */
3806 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303807 XGI_XG21SetPanelDelay(3, pVBInfo);
3808 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003809
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303810 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003811 /* DVO/DVI signal off */
3812 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303813 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003814
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003815 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003816}
3817
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003818static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003819{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003820 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303821 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003822
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003823 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303824 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003825}
3826
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003827static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003828{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03003829 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003830}
3831
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003832static void XGI_SaveCRT2Info(unsigned short ModeNo,
3833 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003834{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303835 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003836
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003837 /* reserve CR34 for CRT1 Mode No */
3838 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303839 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3840 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003841 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003842}
3843
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003844static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3845 unsigned short ModeIdIndex,
3846 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003847{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303848 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003849
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303850 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
3851 if (ModeNo <= 0x13) {
3852 xres = pVBInfo->StResInfo[resindex].HTotal;
3853 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003854 /* si+St_ResInfo */
3855 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;*/
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303856 } else {
3857 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3858 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003859 /* si+St_ModeFlag */
3860 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003861
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303862 /*
3863 if (pVBInfo->IF_DEF_FSTN) {
3864 xres *= 2;
3865 yres *= 2;
3866 } else {
3867 */
3868 if (modeflag & HalfDCLK)
3869 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003870
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303871 if (modeflag & DoubleScanMode)
3872 yres *= 2;
3873 /* } */
3874 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003875
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303876 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3877 if (pVBInfo->IF_DEF_LVDS == 0) {
3878 if (pVBInfo->LCDResInfo == Panel1600x1200) {
3879 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3880 if (yres == 1024)
3881 yres = 1056;
3882 }
3883 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303885 if (pVBInfo->LCDResInfo == Panel1280x1024) {
3886 if (yres == 400)
3887 yres = 405;
3888 else if (yres == 350)
3889 yres = 360;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003890
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303891 if (pVBInfo->LCDInfo & LCDVESATiming) {
3892 if (yres == 360)
3893 yres = 375;
3894 }
3895 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003896
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303897 if (pVBInfo->LCDResInfo == Panel1024x768) {
3898 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3899 if (!(pVBInfo->LCDInfo
3900 & LCDNonExpanding)) {
3901 if (yres == 350)
3902 yres = 357;
3903 else if (yres == 400)
3904 yres = 420;
3905 else if (yres == 480)
3906 yres = 525;
3907 }
3908 }
3909 }
3910 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003911
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303912 if (xres == 720)
3913 xres = 640;
3914 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303916 pVBInfo->VGAHDE = xres;
3917 pVBInfo->HDE = xres;
3918 pVBInfo->VGAVDE = yres;
3919 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003920}
3921
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003922static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003923{
3924
Dan Carpentera65fd092011-01-04 09:02:27 +03003925 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
3926 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303927 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303929 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003930}
3931
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003932static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3933 unsigned short ModeIdIndex,
3934 unsigned short RefreshRateTableIndex,
3935 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003936{
3937 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
3938 StandTableIndex, CRT1Index;
3939
3940 pVBInfo->RVBHCMAX = 1;
3941 pVBInfo->RVBHCFACT = 1;
3942
3943 if (ModeNo <= 0x13) {
3944 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3945 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
3946 tempax = pVBInfo->StandTable[StandTableIndex].CRTC[0];
3947 tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[6];
3948 temp1 = pVBInfo->StandTable[StandTableIndex].CRTC[7];
3949 } else {
3950 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003951 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
3952 Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003953 CRT1Index &= IndexMask;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003954 temp1 = (unsigned short) pVBInfo->
3955 XGINEWUB_CRT1Table[CRT1Index].CR[0];
3956 temp2 = (unsigned short) pVBInfo->
3957 XGINEWUB_CRT1Table[CRT1Index].CR[5];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003958 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003959 tempbx = (unsigned short) pVBInfo->
3960 XGINEWUB_CRT1Table[CRT1Index].CR[8];
3961 tempcx = (unsigned short) pVBInfo->
3962 XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003963 tempcx &= 0x0100;
3964 tempcx = tempcx << 2;
3965 tempbx |= tempcx;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003966 temp1 = (unsigned short) pVBInfo->
3967 XGINEWUB_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003968 }
3969
3970 if (temp1 & 0x01)
3971 tempbx |= 0x0100;
3972
3973 if (temp1 & 0x20)
3974 tempbx |= 0x0200;
3975 tempax += 5;
3976
3977 if (modeflag & Charx8Dot)
3978 tempax *= 8;
3979 else
3980 tempax *= 9;
3981
3982 pVBInfo->VGAHT = tempax;
3983 pVBInfo->HT = tempax;
3984 tempbx++;
3985 pVBInfo->VGAVT = tempbx;
3986 pVBInfo->VT = tempbx;
3987}
3988
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003989static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303990 unsigned short RefreshRateTableIndex,
3991 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003992{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303993 unsigned short tempax = 0, tempbx, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303995 struct XGI_LCDDataStruct *LCDPtr = NULL;
3996 struct XGI_TVDataStruct *TVPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003997
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303998 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003999 /* si+St_ResInfo */
4000 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304001 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4002 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004003 /* si+Ext_ResInfo */
4004 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304005 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4006 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004007
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304008 pVBInfo->NewFlickerMode = 0;
4009 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004010
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304011 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4012 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4013 pVBInfo);
4014 return;
4015 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304017 tempbx = 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004018
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304019 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
4020 LCDPtr = (struct XGI_LCDDataStruct *) XGI_GetLcdPtr(tempbx,
4021 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4022 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304024 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
4025 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
4026 pVBInfo->VGAHT = LCDPtr->VGAHT;
4027 pVBInfo->VGAVT = LCDPtr->VGAVT;
4028 pVBInfo->HT = LCDPtr->LCDHT;
4029 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004030
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304031 if (pVBInfo->LCDResInfo == Panel1024x768) {
4032 tempax = 1024;
4033 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304035 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4036 if (pVBInfo->VGAVDE == 357)
4037 tempbx = 527;
4038 else if (pVBInfo->VGAVDE == 420)
4039 tempbx = 620;
4040 else if (pVBInfo->VGAVDE == 525)
4041 tempbx = 775;
4042 else if (pVBInfo->VGAVDE == 600)
4043 tempbx = 775;
4044 /* else if (pVBInfo->VGAVDE==350) tempbx=560; */
4045 /* else if (pVBInfo->VGAVDE==400) tempbx=640; */
4046 else
4047 tempbx = 768;
4048 } else
4049 tempbx = 768;
4050 } else if (pVBInfo->LCDResInfo == Panel1024x768x75) {
4051 tempax = 1024;
4052 tempbx = 768;
4053 } else if (pVBInfo->LCDResInfo == Panel1280x1024) {
4054 tempax = 1280;
4055 if (pVBInfo->VGAVDE == 360)
4056 tempbx = 768;
4057 else if (pVBInfo->VGAVDE == 375)
4058 tempbx = 800;
4059 else if (pVBInfo->VGAVDE == 405)
4060 tempbx = 864;
4061 else
4062 tempbx = 1024;
4063 } else if (pVBInfo->LCDResInfo == Panel1280x1024x75) {
4064 tempax = 1280;
4065 tempbx = 1024;
4066 } else if (pVBInfo->LCDResInfo == Panel1280x960) {
4067 tempax = 1280;
4068 if (pVBInfo->VGAVDE == 350)
4069 tempbx = 700;
4070 else if (pVBInfo->VGAVDE == 400)
4071 tempbx = 800;
4072 else if (pVBInfo->VGAVDE == 1024)
4073 tempbx = 960;
4074 else
4075 tempbx = 960;
4076 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
4077 tempax = 1400;
4078 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304080 if (pVBInfo->VGAVDE == 1024) {
4081 tempax = 1280;
4082 tempbx = 1024;
4083 }
4084 } else if (pVBInfo->LCDResInfo == Panel1600x1200) {
4085 tempax = 1600;
4086 tempbx = 1200; /* alan 10/14/2003 */
4087 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4088 if (pVBInfo->VGAVDE == 350)
4089 tempbx = 875;
4090 else if (pVBInfo->VGAVDE == 400)
4091 tempbx = 1000;
4092 }
4093 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004094
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304095 if (pVBInfo->LCDInfo & LCDNonExpanding) {
4096 tempax = pVBInfo->VGAHDE;
4097 tempbx = pVBInfo->VGAVDE;
4098 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304100 pVBInfo->HDE = tempax;
4101 pVBInfo->VDE = tempbx;
4102 return;
4103 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304105 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
4106 tempbx = 4;
4107 TVPtr = (struct XGI_TVDataStruct *) XGI_GetTVPtr(tempbx,
4108 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4109 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304111 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
4112 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
4113 pVBInfo->VGAHT = TVPtr->VGAHT;
4114 pVBInfo->VGAVT = TVPtr->VGAVT;
4115 pVBInfo->HDE = TVPtr->TVHDE;
4116 pVBInfo->VDE = TVPtr->TVVDE;
4117 pVBInfo->RVBHRS = TVPtr->RVBHRS;
4118 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304120 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4121 if (resinfo == 0x08)
4122 pVBInfo->NewFlickerMode = 0x40;
4123 else if (resinfo == 0x09)
4124 pVBInfo->NewFlickerMode = 0x40;
4125 else if (resinfo == 0x12)
4126 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304128 if (pVBInfo->VGAVDE == 350)
4129 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004130
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304131 tempax = ExtHiTVHT;
4132 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004133
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304134 if (pVBInfo->VBInfo & SetInSlaveMode) {
4135 if (pVBInfo->TVInfo & TVSimuMode) {
4136 tempax = StHiTVHT;
4137 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004138
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304139 if (!(modeflag & Charx8Dot)) {
4140 tempax = StHiTextTVHT;
4141 tempbx = StHiTextTVVT;
4142 }
4143 }
4144 }
4145 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4146 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
4147 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
4148 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
4149 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304151 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
4152 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
4153 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
4154 } else if (pVBInfo->TVInfo & SetYPbPrMode525i) {
4155 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
4156 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
4157 if (pVBInfo->TVInfo & NTSC1024x768)
4158 tempax = NTSC1024x768HT;
4159 }
4160 } else {
4161 tempax = PALHT;
4162 tempbx = PALVT;
4163 if (!(pVBInfo->TVInfo & SetPALTV)) {
4164 tempax = NTSCHT;
4165 tempbx = NTSCVT;
4166 if (pVBInfo->TVInfo & NTSC1024x768)
4167 tempax = NTSC1024x768HT;
4168 }
4169 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004170
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304171 pVBInfo->HT = tempax;
4172 pVBInfo->VT = tempbx;
4173 return;
4174 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004175}
4176
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004177static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304178 unsigned short RefreshRateTableIndex,
4179 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004180{
Bill Pemberton108afbf2010-06-17 13:10:47 -04004181 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004182
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304183 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
4184 pVBInfo);
4185 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
4186 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304188 if (pVBInfo->VBType & VB_XGI301) { /* shampoo 0129 */
4189 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004190 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
4191 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4192 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304193 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004194 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4195 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304196 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004197
Aaro Koskinen8104e322011-03-13 12:26:22 +02004198 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004199
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304200 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004201 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304202 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004203 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004204}
4205
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004206static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
4207 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004208{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004209 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
4210 short index;
4211 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304212
4213 if (ModeNo <= 0x13)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004214 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304215 else
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004216 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304217
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004218 index = (modeflag & ModeInfoFlag) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304219
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004220 if (index < 0)
4221 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304222
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004223 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304224}
4225
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004226static unsigned short XGI_GetOffset(unsigned short ModeNo,
4227 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304228 unsigned short RefreshRateTableIndex,
4229 struct xgi_hw_device_info *HwDeviceExtension,
4230 struct vb_device_info *pVBInfo)
4231{
4232 unsigned short temp, colordepth, modeinfo, index, infoflag,
4233 ColorDepth[] = { 0x01, 0x02, 0x04 };
4234
4235 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
4236 if (ModeNo <= 0x14)
4237 infoflag = 0;
4238 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004239 infoflag = pVBInfo->
4240 RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304241
4242 index = (modeinfo >> 8) & 0xFF;
4243
4244 temp = pVBInfo->ScreenOffset[index];
4245
4246 if (infoflag & InterlaceMode)
4247 temp = temp << 1;
4248
4249 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4250
4251 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
4252 temp = ModeNo - 0x7C;
4253 colordepth = ColorDepth[temp];
4254 temp = 0x6B;
4255 if (infoflag & InterlaceMode)
4256 temp = temp << 1;
4257 return temp * colordepth;
4258 } else {
4259 return temp * colordepth;
4260 }
4261}
4262
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004263static void XGI_SetCRT2Offset(unsigned short ModeNo,
4264 unsigned short ModeIdIndex,
4265 unsigned short RefreshRateTableIndex,
4266 struct xgi_hw_device_info *HwDeviceExtension,
4267 struct vb_device_info *pVBInfo)
4268{
4269 unsigned short offset;
4270 unsigned char temp;
4271
4272 if (pVBInfo->VBInfo & SetInSlaveMode)
4273 return;
4274
4275 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4276 HwDeviceExtension, pVBInfo);
4277 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004278 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004279 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004280 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004281 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004282 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004283}
4284
Randy Dunlap89229672010-08-10 08:46:44 -07004285static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004286{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004287 /* threshold high ,disable auto threshold */
4288 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
4289 /* threshold low default 04h */
4290 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004291}
4292
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004293static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304294 struct xgi_hw_device_info *HwDeviceExtension,
4295 unsigned short RefreshRateTableIndex,
4296 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004297{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304298 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004299
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304300 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004301 CRT1Index = pVBInfo->
4302 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304303 CRT1Index &= IndexMask;
4304 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4305 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004306
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304307 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4308 HwDeviceExtension, pVBInfo);
4309 XGI_SetCRT2FIFO(pVBInfo);
4310 /* XGI_SetCRT2Sync(ModeNo,RefreshRateTableIndex); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004311
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304312 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004313 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004314
Aaro Koskinen8104e322011-03-13 12:26:22 +02004315 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
4316 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004317}
4318
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004319static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304320 struct xgi_hw_device_info *HwDeviceExtension,
4321 unsigned short RefreshRateTableIndex,
4322 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004323{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304324 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
4325 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004326
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304327 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004328 CRT1Index = pVBInfo->
4329 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304330 CRT1Index &= IndexMask;
4331 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004332 }
4333
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304334 if (ModeNo <= 0x13)
4335 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4336 else
4337 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004338
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304339 /* bainy change table name */
4340 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004341 /* BTVGA2HT 0x08,0x09 */
4342 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004343 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304344 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004345 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004346 /* BTVGA2HDEE 0x0A,0x0C */
4347 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004348 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304349 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
4350 pushbx = pVBInfo->VGAHDE / 2 + 16;
4351 tempcx = tempcx >> 1;
4352 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4353 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004354
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304355 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4356 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004357 tempbx |= ((pVBInfo->
4358 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
4359 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304360 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4361 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
4362 tempcx &= 0x1F;
4363 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
4364 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4365 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4366 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304368 tempbx += 4;
4369 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004370
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304371 if (tempcx > (pVBInfo->VGAHT / 2))
4372 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004373
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304374 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004375
Aaro Koskinen8104e322011-03-13 12:26:22 +02004376 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304377 } else {
4378 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004379 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304380 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004381 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004382 /* BTVGA2HDEE 0x0A,0x0C */
4383 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004384 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304385 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
4386 pushbx = pVBInfo->VGAHDE + 16;
4387 tempcx = tempcx >> 1;
4388 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4389 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004390
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304391 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4392 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004393 tempbx |= ((pVBInfo->
4394 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
4395 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304396 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4397 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4398 tempcx &= 0x1F;
4399 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
4400 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4401 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4402 tempbx += 16;
4403 tempcx += 16;
4404 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004405
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304406 if (tempcx > pVBInfo->VGAHT)
4407 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004408
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304409 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004410 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304411 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004412
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304413 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
4414 tempbx = pushbx;
4415 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
4416 tempax |= (tempbx & 0xFF00);
4417 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004418 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304419 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004420 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304421 tempcx = (pVBInfo->VGAVT - 1);
4422 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004423
Aaro Koskinen8104e322011-03-13 12:26:22 +02004424 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304425 tempbx = pVBInfo->VGAVDE - 1;
4426 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004427 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304428 temp = ((tempbx & 0xFF00) << 3) >> 8;
4429 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004430 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004431
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304432 tempax = pVBInfo->VGAVDE;
4433 tempbx = pVBInfo->VGAVDE;
4434 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004435 /* BTVGA2VRS 0x10,0x11 */
4436 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
4437 /* BTVGA2VRE 0x11 */
4438 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004439
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304440 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4441 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
4442 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004443
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304444 if (temp & 0x04)
4445 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004446
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304447 if (temp & 0x080)
4448 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004449
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304450 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004451
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304452 if (temp & 0x08)
4453 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304455 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
4456 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
4457 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004458
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304459 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004460 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304461 temp = ((tempbx & 0xFF00) >> 8) << 4;
4462 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004463 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304464 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004465
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304466 if (modeflag & DoubleScanMode)
4467 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004468
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304469 if (modeflag & HalfDCLK)
4470 tempax |= 0x40;
4471
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004472 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004473}
4474
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004475static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4476{
4477 unsigned long tempax, tempbx;
4478
4479 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4480 & 0xFFFF;
4481 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4482 tempax = (tempax * pVBInfo->HT) / tempbx;
4483
4484 return (unsigned short) tempax;
4485}
4486
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004487static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304488 struct xgi_hw_device_info *HwDeviceExtension,
4489 unsigned short RefreshRateTableIndex,
4490 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004491{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304492 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4493 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304495 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004496 /* si+St_ResInfo */
4497 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304498 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4499 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004500 /* si+Ext_ResInfo */
4501 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304502 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004503 CRT1Index = pVBInfo->
4504 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304505 CRT1Index &= IndexMask;
4506 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004507
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304508 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4509 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004510
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304511 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004512 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304513 /* if (modeflag & Charx8Dot) */
4514 /* tempcx = 0x08; */
4515 /* else */
4516 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004517
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304518 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4519 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004520
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304521 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004522
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304523 if (modeflag & HalfDCLK)
4524 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004525
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304526 tempax = (tempax / tempcx) - 1;
4527 tempbx |= ((tempax & 0x00FF) << 8);
4528 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004529 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004530
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304531 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004532
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304533 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4534 if (!(pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4535 | VB_XGI302LV | VB_XGI301C)))
4536 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004537
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304538 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4539 if (pVBInfo->VBType & VB_XGI301LV) {
4540 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4541 if (resinfo == 7)
4542 temp -= 2;
4543 }
4544 } else if (resinfo == 7) {
4545 temp -= 2;
4546 }
4547 }
4548 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004549
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004550 /* 0x05 Horizontal Display Start */
4551 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4552 /* 0x06 Horizontal Blank end */
4553 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004554
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304555 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4556 if (pVBInfo->VBInfo & SetCRT2ToTV)
4557 tempax = pVBInfo->VGAHT;
4558 else
4559 tempax = XGI_GetVGAHT2(pVBInfo);
4560 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004561
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304562 if (tempax >= pVBInfo->VGAHT)
4563 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004564
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304565 if (modeflag & HalfDCLK)
4566 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004567
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304568 tempax = (tempax / tempcx) - 5;
4569 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
4570 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4571 temp = (tempbx & 0x00FF) - 1;
4572 if (!(modeflag & HalfDCLK)) {
4573 temp -= 6;
4574 if (pVBInfo->TVInfo & TVSimuMode) {
4575 temp -= 4;
4576 if (ModeNo > 0x13)
4577 temp -= 10;
4578 }
4579 }
4580 } else {
4581 /* tempcx = tempbx & 0x00FF ; */
4582 tempbx = (tempbx & 0xFF00) >> 8;
4583 tempcx = (tempcx + tempbx) >> 1;
4584 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004585
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304586 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4587 temp -= 1;
4588 if (!(modeflag & HalfDCLK)) {
4589 if ((modeflag & Charx8Dot)) {
4590 temp += 4;
4591 if (pVBInfo->VGAHDE >= 800)
4592 temp -= 6;
4593 }
4594 }
4595 } else {
4596 if (!(modeflag & HalfDCLK)) {
4597 temp -= 4;
4598 if (pVBInfo->LCDResInfo != Panel1280x960) {
4599 if (pVBInfo->VGAHDE >= 800) {
4600 temp -= 7;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004601 if (pVBInfo->ModeType ==
4602 ModeEGA) {
4603 if (pVBInfo->VGAVDE ==
4604 1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304605 temp += 15;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004606 if (pVBInfo->LCDResInfo != Panel1280x1024) {
4607 temp +=
4608 7;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304609 }
4610 }
4611 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004612
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304613 if (pVBInfo->VGAHDE >= 1280) {
4614 if (pVBInfo->LCDResInfo
4615 != Panel1280x960) {
4616 if (pVBInfo->LCDInfo
4617 & LCDNonExpanding) {
4618 temp
4619 += 28;
4620 }
4621 }
4622 }
4623 }
4624 }
4625 }
4626 }
4627 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004628
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004629 /* 0x07 Horizontal Retrace Start */
4630 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4631 /* 0x08 Horizontal Retrace End */
4632 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004633
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304634 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4635 if (pVBInfo->TVInfo & TVSimuMode) {
4636 if ((ModeNo == 0x06) || (ModeNo == 0x10) || (ModeNo
4637 == 0x11) || (ModeNo == 0x13) || (ModeNo
4638 == 0x0F)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004639 xgifb_reg_set(pVBInfo->Part1Port, 0x07, 0x5b);
4640 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0x03);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304641 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004642
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304643 if ((ModeNo == 0x00) || (ModeNo == 0x01)) {
4644 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004645 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304646 0x07, 0x2A);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004647 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304648 0x08, 0x61);
4649 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004650 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304651 0x07, 0x2A);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004652 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304653 0x08, 0x41);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004654 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304655 0x0C, 0xF0);
4656 }
4657 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004658
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304659 if ((ModeNo == 0x02) || (ModeNo == 0x03) || (ModeNo
4660 == 0x07)) {
4661 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004662 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304663 0x07, 0x54);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004664 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304665 0x08, 0x00);
4666 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004667 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304668 0x07, 0x55);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004669 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304670 0x08, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004671 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304672 0x0C, 0xF0);
4673 }
4674 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004675
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304676 if ((ModeNo == 0x04) || (ModeNo == 0x05) || (ModeNo
4677 == 0x0D) || (ModeNo == 0x50)) {
4678 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004679 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304680 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004681 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304682 0x08, 0x03);
4683 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004684 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304685 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004686 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304687 0x08, 0x02);
4688 }
4689 }
4690 }
4691 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004692
Aaro Koskinen8104e322011-03-13 12:26:22 +02004693 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004694 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004695 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004696
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304697 tempbx = pVBInfo->VGAVT;
4698 push1 = tempbx;
4699 tempcx = 0x121;
4700 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004701
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304702 if (tempbx == 357)
4703 tempbx = 350;
4704 if (tempbx == 360)
4705 tempbx = 350;
4706 if (tempbx == 375)
4707 tempbx = 350;
4708 if (tempbx == 405)
4709 tempbx = 400;
4710 if (tempbx == 525)
4711 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004712
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304713 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004714
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304715 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4716 if (pVBInfo->LCDResInfo == Panel1024x768) {
4717 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4718 if (tempbx == 350)
4719 tempbx += 5;
4720 if (tempbx == 480)
4721 tempbx += 5;
4722 }
4723 }
4724 }
4725 tempbx--;
4726 temp = tempbx & 0x00FF;
4727 tempbx--;
4728 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004729 /* 0x10 vertical Blank Start */
4730 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304731 tempbx = push2;
4732 tempbx--;
4733 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004734 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004735
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304736 if (tempbx & 0x0100)
4737 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004738
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304739 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004740
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304741 if (modeflag & DoubleScanMode)
4742 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004743
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304744 if (tempbx & 0x0200)
4745 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004746
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304747 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004748 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004749
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304750 if (tempbx & 0x0400)
4751 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004752
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004753 /* 0x11 Vertival Blank End */
4754 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304755
4756 tempax = push1;
4757 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4758 tempax = tempax >> 2;
4759 push1 = tempax; /* push ax */
4760
4761 if (resinfo != 0x09) {
4762 tempax = tempax << 1;
4763 tempbx += tempax;
4764 }
4765
4766 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4767 if (pVBInfo->VBType & VB_XGI301LV) {
4768 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
4769 tempbx -= 10;
4770 } else {
4771 if (pVBInfo->TVInfo & TVSimuMode) {
4772 if (pVBInfo->TVInfo & SetPALTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004773 if (pVBInfo->VBType &
4774 VB_XGI301LV) {
4775 if (!(pVBInfo->TVInfo &
4776 (SetYPbPrMode525p |
4777 SetYPbPrMode750p |
4778 SetYPbPrMode1080i)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304779 tempbx += 40;
4780 } else {
4781 tempbx += 40;
4782 }
4783 }
4784 }
4785 }
4786 } else {
4787 tempbx -= 10;
4788 }
4789 } else {
4790 if (pVBInfo->TVInfo & TVSimuMode) {
4791 if (pVBInfo->TVInfo & SetPALTV) {
4792 if (pVBInfo->VBType & VB_XGI301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004793 if (!(pVBInfo->TVInfo &
4794 (SetYPbPrMode525p |
4795 SetYPbPrMode750p |
4796 SetYPbPrMode1080i)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304797 tempbx += 40;
4798 } else {
4799 tempbx += 40;
4800 }
4801 }
4802 }
4803 }
4804 tempax = push1;
4805 tempax = tempax >> 2;
4806 tempax++;
4807 tempax += tempbx;
4808 push1 = tempax; /* push ax */
4809
4810 if ((pVBInfo->TVInfo & SetPALTV)) {
4811 if (tempbx <= 513) {
4812 if (tempax >= 513)
4813 tempbx = 513;
4814 }
4815 }
4816
4817 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004818 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304819 tempbx--;
4820 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004821 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304822
4823 if (tempbx & 0x0100)
4824 tempcx |= 0x0008;
4825
4826 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004827 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304828
4829 tempbx++;
4830
4831 if (tempbx & 0x0100)
4832 tempcx |= 0x0004;
4833
4834 if (tempbx & 0x0200)
4835 tempcx |= 0x0080;
4836
4837 if (tempbx & 0x0400)
4838 tempcx |= 0x0C00;
4839
4840 tempbx = push1; /* pop ax */
4841 temp = tempbx & 0x00FF;
4842 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004843 /* 0x0D vertical Retrace End */
4844 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304845
4846 if (tempbx & 0x0010)
4847 tempcx |= 0x2000;
4848
4849 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004850 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304851 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004852 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304853 tempax = modeflag;
4854 temp = (tempax & 0xFF00) >> 8;
4855
4856 temp = (temp >> 1) & 0x09;
4857
4858 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4859 temp |= 0x01;
4860
Aaro Koskinen8104e322011-03-13 12:26:22 +02004861 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4862 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4863 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304864
4865 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4866 temp = 0x80;
4867 else
4868 temp = 0x00;
4869
Aaro Koskinen8104e322011-03-13 12:26:22 +02004870 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304871
4872 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004873}
4874
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004875static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304876 unsigned short RefreshRateTableIndex,
4877 struct xgi_hw_device_info *HwDeviceExtension,
4878 struct vb_device_info *pVBInfo)
4879{
4880 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4881 modeflag, resinfo, crt2crtc;
4882 unsigned char *TimingPoint;
4883
4884 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4885
4886 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004887 /* si+St_ResInfo */
4888 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304889 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4890 crt2crtc = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
4891 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004892 /* si+Ext_ResInfo */
4893 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304894 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004895 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].
4896 Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304897 }
4898
4899 tempax = 0;
4900
4901 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4902 tempax |= 0x0800;
4903
4904 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4905 tempax |= 0x0400;
4906
4907 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4908 tempax |= 0x0200;
4909
4910 if (!(pVBInfo->TVInfo & SetPALTV))
4911 tempax |= 0x1000;
4912
4913 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4914 tempax |= 0x0100;
4915
4916 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
4917 tempax &= 0xfe00;
4918
4919 tempax = (tempax & 0xff00) >> 8;
4920
Aaro Koskinen8104e322011-03-13 12:26:22 +02004921 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304922 TimingPoint = pVBInfo->NTSCTiming;
4923
4924 if (pVBInfo->TVInfo & SetPALTV)
4925 TimingPoint = pVBInfo->PALTiming;
4926
4927 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4928 TimingPoint = pVBInfo->HiTVExtTiming;
4929
4930 if (pVBInfo->VBInfo & SetInSlaveMode)
4931 TimingPoint = pVBInfo->HiTVSt2Timing;
4932
4933 if (pVBInfo->SetFlag & TVSimuMode)
4934 TimingPoint = pVBInfo->HiTVSt1Timing;
4935
4936 if (!(modeflag & Charx8Dot))
4937 TimingPoint = pVBInfo->HiTVTextTiming;
4938 }
4939
4940 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4941 if (pVBInfo->TVInfo & SetYPbPrMode525i)
4942 TimingPoint = pVBInfo->YPbPr525iTiming;
4943
4944 if (pVBInfo->TVInfo & SetYPbPrMode525p)
4945 TimingPoint = pVBInfo->YPbPr525pTiming;
4946
4947 if (pVBInfo->TVInfo & SetYPbPrMode750p)
4948 TimingPoint = pVBInfo->YPbPr750pTiming;
4949 }
4950
4951 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004952 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304953
4954 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004955 /* di->temp2[j] */
4956 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304957
4958 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004959 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304960
4961 temp = pVBInfo->NewFlickerMode;
4962 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004963 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304964
4965 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4966 tempax = 950;
4967
4968 if (pVBInfo->TVInfo & SetPALTV)
4969 tempax = 520;
4970 else
4971 tempax = 440;
4972
4973 if (pVBInfo->VDE <= tempax) {
4974 tempax -= pVBInfo->VDE;
4975 tempax = tempax >> 2;
4976 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
4977 push1 = tempax;
4978 temp = (tempax & 0xFF00) >> 8;
4979 temp += (unsigned short) TimingPoint[0];
4980
4981 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4982 | VB_XGI302LV | VB_XGI301C)) {
4983 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4984 | SetCRT2ToSVIDEO | SetCRT2ToSCART
4985 | SetCRT2ToYPbPr)) {
4986 tempcx = pVBInfo->VGAHDE;
4987 if (tempcx >= 1024) {
4988 temp = 0x17; /* NTSC */
4989 if (pVBInfo->TVInfo & SetPALTV)
4990 temp = 0x19; /* PAL */
4991 }
4992 }
4993 }
4994
Aaro Koskinen8104e322011-03-13 12:26:22 +02004995 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304996 tempax = push1;
4997 temp = (tempax & 0xFF00) >> 8;
4998 temp += TimingPoint[1];
4999
5000 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5001 | VB_XGI302LV | VB_XGI301C)) {
5002 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
5003 | SetCRT2ToSVIDEO | SetCRT2ToSCART
5004 | SetCRT2ToYPbPr))) {
5005 tempcx = pVBInfo->VGAHDE;
5006 if (tempcx >= 1024) {
5007 temp = 0x1D; /* NTSC */
5008 if (pVBInfo->TVInfo & SetPALTV)
5009 temp = 0x52; /* PAL */
5010 }
5011 }
5012 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005013 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305014 }
5015
5016 /* 301b */
5017 tempcx = pVBInfo->HT;
5018
5019 if (XGI_IsLCDDualLink(pVBInfo))
5020 tempcx = tempcx >> 1;
5021
5022 tempcx -= 2;
5023 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005024 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305025
5026 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005027 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305028
5029 tempcx = pVBInfo->HT >> 1;
5030 push1 = tempcx; /* push cx */
5031 tempcx += 7;
5032
5033 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5034 tempcx -= 4;
5035
5036 temp = tempcx & 0x00FF;
5037 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005038 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305039
5040 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5041 tempbx += tempcx;
5042 push2 = tempbx;
5043 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005044 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305045 temp = (tempbx & 0xFF00) >> 8;
5046 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005047 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305048
5049 tempbx = push2;
5050 tempbx = tempbx + 8;
5051 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5052 tempbx = tempbx - 4;
5053 tempcx = tempbx;
5054 }
5055
5056 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005057 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305058
5059 j += 2;
5060 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
5061 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005062 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305063 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005064 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305065
5066 tempcx += 8;
5067 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5068 tempcx -= 4;
5069
5070 temp = tempcx & 0xFF;
5071 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005072 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305073
5074 tempcx = push1; /* pop cx */
5075 j += 2;
5076 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5077 tempcx -= temp;
5078 temp = tempcx & 0x00FF;
5079 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005080 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305081
5082 tempcx -= 11;
5083
5084 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
5085 tempax = XGI_GetVGAHT2(pVBInfo);
5086 tempcx = tempax - 1;
5087 }
5088 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005089 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305090
5091 tempbx = pVBInfo->VDE;
5092
5093 if (pVBInfo->VGAVDE == 360)
5094 tempbx = 746;
5095 if (pVBInfo->VGAVDE == 375)
5096 tempbx = 746;
5097 if (pVBInfo->VGAVDE == 405)
5098 tempbx = 853;
5099
5100 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005101 if (pVBInfo->VBType &
5102 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
5103 if (!(pVBInfo->TVInfo &
5104 (SetYPbPrMode525p | SetYPbPrMode750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305105 tempbx = tempbx >> 1;
5106 } else
5107 tempbx = tempbx >> 1;
5108 }
5109
5110 tempbx -= 2;
5111 temp = tempbx & 0x00FF;
5112
5113 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5114 if (pVBInfo->VBType & VB_XGI301LV) {
5115 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5116 if (pVBInfo->VBInfo & SetInSlaveMode) {
5117 if (ModeNo == 0x2f)
5118 temp += 1;
5119 }
5120 }
5121 } else {
5122 if (pVBInfo->VBInfo & SetInSlaveMode) {
5123 if (ModeNo == 0x2f)
5124 temp += 1;
5125 }
5126 }
5127 }
5128
Aaro Koskinen8104e322011-03-13 12:26:22 +02005129 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305130
5131 temp = (tempcx & 0xFF00) >> 8;
5132 temp |= ((tempbx & 0xFF00) >> 8) << 6;
5133
5134 if (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) {
5135 if (pVBInfo->VBType & VB_XGI301LV) {
5136 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5137 temp |= 0x10;
5138
5139 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5140 temp |= 0x20;
5141 }
5142 } else {
5143 temp |= 0x10;
5144 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5145 temp |= 0x20;
5146 }
5147 }
5148
Aaro Koskinen8104e322011-03-13 12:26:22 +02005149 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305150
5151 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5152 | VB_XGI302LV | VB_XGI301C)) { /* TV gatingno */
5153 tempbx = pVBInfo->VDE;
5154 tempcx = tempbx - 2;
5155
5156 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5157 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p
5158 | SetYPbPrMode750p)))
5159 tempbx = tempbx >> 1;
5160 }
5161
5162 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
5163 temp = 0;
5164 if (tempcx & 0x0400)
5165 temp |= 0x20;
5166
5167 if (tempbx & 0x0400)
5168 temp |= 0x40;
5169
Aaro Koskinen8104e322011-03-13 12:26:22 +02005170 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305171 }
5172
5173 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005174 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305175 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005176 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305177 }
5178
5179 tempbx = tempbx & 0x00FF;
5180
5181 if (!(modeflag & HalfDCLK)) {
5182 tempcx = pVBInfo->VGAHDE;
5183 if (tempcx >= pVBInfo->HDE) {
5184 tempbx |= 0x2000;
5185 tempax &= 0x00FF;
5186 }
5187 }
5188
5189 tempcx = 0x0101;
5190
5191 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
5192 if (pVBInfo->VGAHDE >= 1024) {
5193 tempcx = 0x1920;
5194 if (pVBInfo->VGAHDE >= 1280) {
5195 tempcx = 0x1420;
5196 tempbx = tempbx & 0xDFFF;
5197 }
5198 }
5199 }
5200
5201 if (!(tempbx & 0x2000)) {
5202 if (modeflag & HalfDCLK)
5203 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
5204
5205 push1 = tempbx;
5206 tempeax = pVBInfo->VGAHDE;
5207 tempebx = (tempcx & 0xFF00) >> 8;
5208 longtemp = tempeax * tempebx;
5209 tempecx = tempcx & 0x00FF;
5210 longtemp = longtemp / tempecx;
5211
5212 /* 301b */
5213 tempecx = 8 * 1024;
5214
5215 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5216 | VB_XGI302LV | VB_XGI301C)) {
5217 tempecx = tempecx * 8;
5218 }
5219
5220 longtemp = longtemp * tempecx;
5221 tempecx = pVBInfo->HDE;
5222 temp2 = longtemp % tempecx;
5223 tempeax = longtemp / tempecx;
5224 if (temp2 != 0)
5225 tempeax += 1;
5226
5227 tempax = (unsigned short) tempeax;
5228
5229 /* 301b */
5230 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5231 | VB_XGI302LV | VB_XGI301C)) {
5232 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
5233 }
5234 /* end 301b */
5235
5236 tempbx = push1;
5237 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
5238 | (tempbx & 0x00FF));
5239 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
5240 | (tempax & 0x00FF));
5241 temp = (tempax & 0xFF00) >> 8;
5242 } else {
5243 temp = (tempax & 0x00FF) >> 8;
5244 }
5245
Aaro Koskinen8104e322011-03-13 12:26:22 +02005246 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305247 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005248 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305249 temp = tempcx & 0x00FF;
5250
5251 if (tempbx & 0x2000)
5252 temp = 0;
5253
5254 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5255 temp |= 0x18;
5256
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005257 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305258 if (pVBInfo->TVInfo & SetPALTV) {
5259 tempbx = 0x0382;
5260 tempcx = 0x007e;
5261 } else {
5262 tempbx = 0x0369;
5263 tempcx = 0x0061;
5264 }
5265
5266 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005267 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305268 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005269 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305270
5271 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
5272 temp = temp << 2;
5273 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
5274
5275 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5276 temp |= 0x10;
5277
5278 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5279 temp |= 0x20;
5280
5281 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5282 temp |= 0x60;
5283 }
5284
Aaro Koskinen8104e322011-03-13 12:26:22 +02005285 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005286 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005287 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305288
5289 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))) {
5290 if (pVBInfo->TVInfo & NTSC1024x768) {
5291 TimingPoint = XGI_NTSC1024AdjTime;
5292 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005293 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305294 TimingPoint[j]);
5295 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005296 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305297 }
5298 }
5299
5300 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
5301 if (pVBInfo->VBType & VB_XGI301C) {
5302 if (pVBInfo->TVInfo & SetPALMTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005303 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305304 0x08); /* PALM Mode */
5305 }
5306
5307 if (pVBInfo->TVInfo & SetPALMTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005308 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305309 0x01);
5310 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02005311 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305312
5313 /* if ( !( pVBInfo->VBType & VB_XGI301C ) ) */
Aaro Koskinendc505562011-03-13 12:26:26 +02005314 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305315 }
5316
5317 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5318 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02005319 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305320 }
5321
5322 if (pVBInfo->VBInfo & SetCRT2ToTV)
5323 return;
5324}
5325
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005326static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305327 struct xgi_hw_device_info *HwDeviceExtension,
5328 unsigned short RefreshRateTableIndex,
5329 struct vb_device_info *pVBInfo)
5330{
5331 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
5332 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
5333
5334 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
5335
5336 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005337 /* si+St_ResInfo */
5338 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305339 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
5340 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005341 /* si+Ext_ResInfo */
5342 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305343 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005344 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
5345 Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305346 CRT1Index &= IndexMask;
5347 }
5348
5349 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5350 return;
5351
5352 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
5353
5354 if (XGI_IsLCDDualLink(pVBInfo))
5355 tempbx = tempbx >> 1;
5356
5357 tempbx -= 1;
5358 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005359 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305360 temp = (tempbx & 0xFF00) >> 8;
5361 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005362 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305363 temp = 0x01;
5364
5365 if (pVBInfo->LCDResInfo == Panel1280x1024) {
5366 if (pVBInfo->ModeType == ModeEGA) {
5367 if (pVBInfo->VGAHDE >= 1024) {
5368 temp = 0x02;
5369 if (pVBInfo->LCDInfo & LCDVESATiming)
5370 temp = 0x01;
5371 }
5372 }
5373 }
5374
Aaro Koskinen8104e322011-03-13 12:26:22 +02005375 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305376 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
5377 push1 = tempbx;
5378 tempbx--;
5379 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005380 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305381 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005382 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305383
5384 tempcx = pVBInfo->VT - 1;
5385 push2 = tempcx + 1;
5386 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005387 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305388 temp = (tempcx & 0xFF00) >> 8;
5389 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005390 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005391 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
5392 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
5393 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
5394 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305395
5396 /* Customized LCDB Des no add */
5397 tempbx = 5;
5398 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
5399 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5400 tempah = pVBInfo->LCDResInfo;
5401 tempah &= PanelResInfo;
5402
5403 if ((tempah == Panel1024x768) || (tempah == Panel1024x768x75)) {
5404 tempbx = 1024;
5405 tempcx = 768;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005406 } else if ((tempah == Panel1280x1024) ||
5407 (tempah == Panel1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305408 tempbx = 1280;
5409 tempcx = 1024;
5410 } else if (tempah == Panel1400x1050) {
5411 tempbx = 1400;
5412 tempcx = 1050;
5413 } else {
5414 tempbx = 1600;
5415 tempcx = 1200;
5416 }
5417
5418 if (pVBInfo->LCDInfo & EnableScalingLCD) {
5419 tempbx = pVBInfo->HDE;
5420 tempcx = pVBInfo->VDE;
5421 }
5422
5423 pushbx = tempbx;
5424 tempax = pVBInfo->VT;
5425 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
5426 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
5427 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
5428 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
5429 tempbx = pVBInfo->LCDVDES;
5430 tempcx += tempbx;
5431
5432 if (tempcx >= tempax)
5433 tempcx -= tempax; /* lcdvdes */
5434
5435 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005436 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305437 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005438 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305439 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
5440 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
5441 tempah = tempch;
5442 tempah = tempah << 3;
5443 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005444 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305445
5446 /* getlcdsync() */
5447 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5448 tempcx = tempbx;
5449 tempax = pVBInfo->VT;
5450 tempbx = pVBInfo->LCDVRS;
5451
5452 /* if (SetLCD_Info & EnableScalingLCD) */
5453 tempcx += tempbx;
5454 if (tempcx >= tempax)
5455 tempcx -= tempax;
5456
5457 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005458 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305459 temp = (tempbx & 0xFF00) >> 8;
5460 temp = temp << 4;
5461 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005462 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305463 tempcx = pushbx;
5464 tempax = pVBInfo->HT;
5465 tempbx = pVBInfo->LCDHDES;
5466 tempbx &= 0x0FFF;
5467
5468 if (XGI_IsLCDDualLink(pVBInfo)) {
5469 tempax = tempax >> 1;
5470 tempbx = tempbx >> 1;
5471 tempcx = tempcx >> 1;
5472 }
5473
5474 if (pVBInfo->VBType & VB_XGI302LV)
5475 tempbx += 1;
5476
5477 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
5478 tempbx += 1;
5479
5480 tempcx += tempbx;
5481
5482 if (tempcx >= tempax)
5483 tempcx -= tempax;
5484
5485 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005486 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305487 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005488 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305489 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005490 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305491 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005492 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305493
5494 /* getlcdsync() */
5495 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5496 tempcx = tempax;
5497 tempax = pVBInfo->HT;
5498 tempbx = pVBInfo->LCDHRS;
5499 /* if ( SetLCD_Info & EnableScalingLCD) */
5500 if (XGI_IsLCDDualLink(pVBInfo)) {
5501 tempax = tempax >> 1;
5502 tempbx = tempbx >> 1;
5503 tempcx = tempcx >> 1;
5504 }
5505
5506 if (pVBInfo->VBType & VB_XGI302LV)
5507 tempbx += 1;
5508
5509 tempcx += tempbx;
5510
5511 if (tempcx >= tempax)
5512 tempcx -= tempax;
5513
5514 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005515 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305516
5517 temp = (tempbx & 0xFF00) >> 8;
5518 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005519 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305520 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005521 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305522
5523 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
5524 if (pVBInfo->VGAVDE == 525) {
5525 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5526 | VB_XGI301LV | VB_XGI302LV
5527 | VB_XGI301C)) {
5528 temp = 0xC6;
5529 } else
5530 temp = 0xC4;
5531
Aaro Koskinen8104e322011-03-13 12:26:22 +02005532 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5533 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305534 }
5535
5536 if (pVBInfo->VGAVDE == 420) {
5537 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5538 | VB_XGI301LV | VB_XGI302LV
5539 | VB_XGI301C)) {
5540 temp = 0x4F;
5541 } else
5542 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005543 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305544 }
5545 }
5546}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005547
5548/* --------------------------------------------------------------------- */
5549/* Function : XGI_GetTap4Ptr */
5550/* Input : */
5551/* Output : di -> Tap4 Reg. Setting Pointer */
5552/* Description : */
5553/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005554static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305555 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005556{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305557 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005558
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305559 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005560
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305561 if (tempcx == 0) {
5562 tempax = pVBInfo->VGAHDE;
5563 tempbx = pVBInfo->HDE;
5564 } else {
5565 tempax = pVBInfo->VGAVDE;
5566 tempbx = pVBInfo->VDE;
5567 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005568
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005569 if (tempax <= tempbx)
5570 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305571 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005572 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005573
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305574 if (pVBInfo->TVInfo & SetPALTV)
5575 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005576
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305577 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005578 if ((pVBInfo->TVInfo & SetYPbPrMode525i) ||
5579 (pVBInfo->TVInfo & SetYPbPrMode525p))
5580 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305581 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5582 Tap4TimingPtr = YPbPr750pTap4Timing;
5583 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005584
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305585 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005586 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005587
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305588 i = 0;
5589 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5590 if (Tap4TimingPtr[i].DE == tempax)
5591 break;
5592 i++;
5593 }
5594 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005595}
5596
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005597static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005598{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305599 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005600
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305601 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005602
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305603 if (!(pVBInfo->VBType & VB_XGI301C))
5604 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005605
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305606 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5607 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005608 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005609
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005610 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5611 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV))) {
5612 /* Set Vertical Scaling */
5613 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305614 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005615 xgifb_reg_set(pVBInfo->Part2Port,
5616 i,
5617 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305618 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005619
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005620 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5621 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)))
5622 /* Enable V.Scaling */
5623 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305624 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005625 /* Enable H.Scaling */
5626 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005627}
5628
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005629static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305630 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005631{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305632 unsigned short i;
5633 unsigned char *tempdi;
5634 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005635
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305636 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005637 /* si+St_ResInfo */
5638 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305639 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005640 /* si+Ext_ResInfo */
5641 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005642
Aaro Koskinen8104e322011-03-13 12:26:22 +02005643 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305644 if (pVBInfo->TVInfo & SetPALTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005645 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5646 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305647 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005648 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5649 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305650 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005651
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305652 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5653 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005654
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305655 if (pVBInfo->TVInfo & SetPALMTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005656 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5657 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5658 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305659 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005660
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305661 if ((pVBInfo->VBInfo & SetCRT2ToHiVisionTV) || (pVBInfo->VBInfo
5662 & SetCRT2ToYPbPr)) {
5663 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5664 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005665
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305666 tempdi = pVBInfo->HiTVGroup3Data;
5667 if (pVBInfo->SetFlag & TVSimuMode) {
5668 tempdi = pVBInfo->HiTVGroup3Simu;
5669 if (!(modeflag & Charx8Dot))
5670 tempdi = pVBInfo->HiTVGroup3Text;
5671 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005672
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305673 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5674 tempdi = pVBInfo->Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005675
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305676 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5677 tempdi = pVBInfo->Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005678
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305679 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005680 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005681
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305682 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
5683 if (pVBInfo->TVInfo & SetYPbPrMode525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005684 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305685 }
5686 }
5687 return;
5688} /* {end of XGI_SetGroup3} */
5689
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005690static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305691 unsigned short RefreshRateTableIndex,
5692 struct xgi_hw_device_info *HwDeviceExtension,
5693 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005694{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305695 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005696
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305697 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005698
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305699 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005700 /* si+St_ResInfo */
5701 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305702 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005703 /* si+Ext_ResInfo */
5704 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005705
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305706 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005707 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005708
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305709 tempbx = pVBInfo->RVBHCMAX;
5710 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005711 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305712 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5713 tempcx = pVBInfo->VGAHT - 1;
5714 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005715 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005716
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305717 temp = ((tempcx & 0xFF00) >> 8) << 3;
5718 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005719
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305720 tempcx = pVBInfo->VGAVT - 1;
5721 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5722 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005723
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305724 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005725 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305726 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005727 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005728 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305729 tempcx = pVBInfo->VBInfo;
5730 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005731
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305732 if (modeflag & HalfDCLK)
5733 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005734
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305735 if (XGI_IsLCDDualLink(pVBInfo))
5736 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005737
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305738 if (tempcx & SetCRT2ToHiVisionTV) {
5739 temp = 0;
5740 if (tempbx <= 1024)
5741 temp = 0xA0;
5742 if (tempbx == 1280)
5743 temp = 0xC0;
5744 } else if (tempcx & SetCRT2ToTV) {
5745 temp = 0xA0;
5746 if (tempbx <= 800)
5747 temp = 0x80;
5748 } else {
5749 temp = 0x80;
5750 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5751 temp = 0;
5752 if (tempbx > 800)
5753 temp = 0x60;
5754 }
5755 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005756
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305757 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p)) {
5758 temp = 0x00;
5759 if (pVBInfo->VGAHDE == 1280)
5760 temp = 0x40;
5761 if (pVBInfo->VGAHDE == 1024)
5762 temp = 0x20;
5763 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005764 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005765
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305766 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005767
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305768 if (tempcx & SetCRT2ToHiVisionTV) {
5769 if (!(temp & 0xE000))
5770 tempbx = tempbx >> 1;
5771 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005772
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305773 tempcx = pVBInfo->RVBHRS;
5774 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005775 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005776
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305777 tempeax = pVBInfo->VGAVDE;
5778 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005779
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305780 if (tempeax <= tempebx) {
5781 tempcx = (tempcx & (~0x4000));
5782 tempeax = pVBInfo->VGAVDE;
5783 } else {
5784 tempeax -= tempebx;
5785 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005786
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305787 templong = (tempeax * 256 * 1024) % tempebx;
5788 tempeax = (tempeax * 256 * 1024) / tempebx;
5789 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005790
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305791 if (templong != 0)
5792 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005793
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305794 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005795 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305797 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005798 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305799 tempbx = (unsigned short) (tempebx >> 16);
5800 temp = tempbx & 0x00FF;
5801 temp = temp << 4;
5802 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005803 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005804
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305805 /* 301b */
5806 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5807 | VB_XGI302LV | VB_XGI301C)) {
5808 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005809 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305810 tempax = pVBInfo->VGAHDE;
5811 if (modeflag & HalfDCLK)
5812 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305814 if (XGI_IsLCDDualLink(pVBInfo))
5815 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005816
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005817 /* if((pVBInfo->VBInfo&(SetCRT2ToLCD)) ||
5818 ((pVBInfo->TVInfo&SetYPbPrMode525p) ||
5819 (pVBInfo->TVInfo&SetYPbPrMode750p))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305820 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5821 if (tempax > 800)
5822 tempax -= 800;
5823 } else {
5824 if (pVBInfo->VGAHDE > 800) {
5825 if (pVBInfo->VGAHDE == 1024)
5826 tempax = (tempax * 25 / 32) - 1;
5827 else
5828 tempax = (tempax * 20 / 32) - 1;
5829 }
5830 }
5831 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305833 /*
5834 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5835 if (pVBInfo->VBType & VB_XGI301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005836 if (!(pVBInfo->TVInfo &
5837 (SetYPbPrMode525p |
5838 SetYPbPrMode750p |
5839 SetYPbPrMode1080i))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305840 if (pVBInfo->VGAHDE > 800) {
5841 if (pVBInfo->VGAHDE == 1024)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005842 tempax =(tempax * 25 /
5843 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305844 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005845 tempax = (tempax * 20 /
5846 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305847 }
5848 }
5849 } else {
5850 if (pVBInfo->VGAHDE > 800) {
5851 if (pVBInfo->VGAHDE == 1024)
5852 tempax = (tempax * 25 / 32) - 1;
5853 else
5854 tempax = (tempax * 20 / 32) - 1;
5855 }
5856 }
5857 }
5858 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005859
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305860 temp = (tempax & 0xFF00) >> 8;
5861 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005862 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305863 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005864 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005865
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305866 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5867 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005868 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005869
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305870 }
5871 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005872
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305873 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5874 if (!(pVBInfo->TVInfo & (NTSC1024x768
5875 | SetYPbPrMode525p | SetYPbPrMode750p
5876 | SetYPbPrMode1080i))) {
5877 temp |= 0x0001;
5878 if ((pVBInfo->VBInfo & SetInSlaveMode)
5879 && (!(pVBInfo->TVInfo
5880 & TVSimuMode)))
5881 temp &= (~0x0001);
5882 }
5883 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005884
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005885 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305886 tempbx = pVBInfo->HT;
5887 if (XGI_IsLCDDualLink(pVBInfo))
5888 tempbx = tempbx >> 1;
5889 tempbx = (tempbx >> 1) - 2;
5890 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005891 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305892 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005893 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305894 }
5895 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005896
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305897 if (pVBInfo->ISXPDOS == 0)
5898 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5899 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005900}
5901
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005902static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5903{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005904 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005905}
5906
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005907static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305908 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005909{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305910 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005911
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305912 Pindex = pVBInfo->Part5Port;
5913 Pdata = pVBInfo->Part5Port + 1;
5914 if (pVBInfo->ModeType == ModeVGA) {
5915 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
5916 | CRT2DisplayFlag))) {
5917 XGINew_EnableCRT2(pVBInfo);
5918 /* LoadDAC2(pVBInfo->Part5Port, ModeNo, ModeIdIndex); */
5919 }
5920 }
5921 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005922}
5923
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005924static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305925 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005926{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005927 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005928}
5929
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005930static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305931 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005932{
5933
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005934 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005935}
5936
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005937/*----------------------------------------------------------------------------*/
5938/* input */
5939/* bl[5] : 1;LVDS signal on */
5940/* bl[1] : 1;LVDS backlight on */
5941/* bl[0] : 1:LVDS VDD on */
5942/* bh: 100000b : clear bit 5, to set bit5 */
5943/* 000010b : clear bit 1, to set bit1 */
5944/* 000001b : clear bit 0, to set bit0 */
5945/*----------------------------------------------------------------------------*/
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305946void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
5947 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005948{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305949 unsigned char CR4A, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005950
Aaro Koskinen58839b02011-03-13 12:26:23 +02005951 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305952 tempbh &= 0x23;
5953 tempbl &= 0x23;
Aaro Koskinendc505562011-03-13 12:26:26 +02005954 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005955
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305956 if (tempbh & 0x20) {
5957 temp = (tempbl >> 4) & 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005958
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005959 /* CR B4[1] */
5960 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005961
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305962 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005963
Aaro Koskinen58839b02011-03-13 12:26:23 +02005964 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305966 temp = XG21GPIODataTransfer(temp);
5967 temp &= ~tempbh;
5968 temp |= tempbl;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005969 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005970}
5971
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305972void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
5973 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005974{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305975 unsigned char CR4A, temp;
5976 unsigned short tempbh0, tempbl0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005977
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305978 tempbh0 = tempbh;
5979 tempbl0 = tempbl;
5980 tempbh0 &= 0x20;
5981 tempbl0 &= 0x20;
5982 tempbh0 >>= 3;
5983 tempbl0 >>= 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005984
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305985 if (tempbh & 0x20) {
5986 temp = (tempbl >> 4) & 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005987
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005988 /* CR B4[1] */
5989 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005990
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305991 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005992 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005993
Aaro Koskinen58839b02011-03-13 12:26:23 +02005994 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305995 tempbh &= 0x03;
5996 tempbl &= 0x03;
5997 tempbh <<= 2;
5998 tempbl <<= 2; /* GPIOC,GPIOD */
Aaro Koskinendc505562011-03-13 12:26:26 +02005999 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006000 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006001}
6002
6003/* --------------------------------------------------------------------- */
Bill Pemberton80adad82010-06-17 13:10:51 -04006004unsigned short XGI_GetLVDSOEMTableIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006005{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306006 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006007
Aaro Koskinen58839b02011-03-13 12:26:23 +02006008 index = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306009 if (index < sizeof(XGI21_LCDCapList)
6010 / sizeof(struct XGI21_LVDSCapStruct))
6011 return index;
6012 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006013}
6014
6015/* --------------------------------------------------------------------- */
6016/* Function : XGI_XG21SetPanelDelay */
6017/* Input : */
6018/* Output : */
6019/* Description : */
6020/* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
6021/* : bl : 2 ; T2 : the duration signal on and Vdd on */
6022/* : bl : 3 ; T3 : the duration between CPL off and signal off */
6023/* : bl : 4 ; T4 : the duration signal off and Vdd off */
6024/* --------------------------------------------------------------------- */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306025void XGI_XG21SetPanelDelay(unsigned short tempbl,
6026 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006027{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306028 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306030 index = XGI_GetLVDSOEMTableIndex(pVBInfo);
6031 if (tempbl == 1)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006032 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306034 if (tempbl == 2)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006035 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006036
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306037 if (tempbl == 3)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006038 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S3);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306040 if (tempbl == 4)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006041 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S4);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006042}
6043
Bill Pemberton82d6eb52010-06-17 13:10:46 -04006044unsigned char XGI_XG21CheckLVDSMode(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306045 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006046{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306047 unsigned short xres, yres, colordepth, modeflag, resindex,
6048 lvdstableindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306050 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6051 if (ModeNo <= 0x13) {
6052 xres = pVBInfo->StResInfo[resindex].HTotal;
6053 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006054 /* si+St_ResInfo */
6055 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306056 } else {
6057 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6058 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006059 /* si+St_ModeFlag */
6060 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306061 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006062
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306063 if (!(modeflag & Charx8Dot)) {
6064 xres /= 9;
6065 xres *= 8;
6066 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006067
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306068 if (ModeNo > 0x13) {
6069 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
6070 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006071
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306072 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6073 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006074
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306075 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006076
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306077 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6078 if (xres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE))
6079 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04006080
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306081 if (yres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE))
6082 return 0;
6083
6084 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006085 if ((xres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6086 LVDSHDE)) ||
6087 (yres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6088 LVDSVDE))) {
6089 colordepth = XGI_GetColorDepth(ModeNo,
6090 ModeIdIndex,
6091 pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306092 if (colordepth > 2)
6093 return 0;
6094
6095 }
6096 }
6097 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006098}
6099
Bill Pemberton80adad82010-06-17 13:10:51 -04006100void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006101{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306102 unsigned char temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006103
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006104 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
6105 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306106 temp = (temp & 3) << 6;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006107 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
6108 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
6109 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
6110 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006111
6112}
6113
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006114static void xgifb_set_lvds(int chip_id,
6115 unsigned short ModeNo,
6116 unsigned short ModeIdIndex,
6117 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006118{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306119 unsigned char temp, Miscdata;
6120 unsigned short xres, yres, modeflag, resindex, lvdstableindex;
6121 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
6122 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
6123 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306125 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006126 temp = (unsigned char) ((pVBInfo->XG21_LVDSCapList[lvdstableindex].
6127 LVDS_Capability &
6128 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306129 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006130 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006131
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006132 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006133
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006134 temp = (unsigned char) (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6135 LVDS_Capability & LCDPolarity);
6136 /* SR35[7] FP VSync polarity */
6137 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
6138 /* SR30[5] FP HSync polarity */
6139 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006140
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006141 if (chip_id == XG27)
6142 XGI_SetXG27FPBits(pVBInfo);
6143 else
6144 XGI_SetXG21FPBits(pVBInfo);
6145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306146 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6147 if (ModeNo <= 0x13) {
6148 xres = pVBInfo->StResInfo[resindex].HTotal;
6149 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006150 /* si+St_ResInfo */
6151 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306152 } else {
6153 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6154 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006155 /* si+St_ModeFlag */
6156 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306157 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006158
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306159 if (!(modeflag & Charx8Dot))
6160 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306162 LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006163
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306164 LVDSHBS = xres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE
6165 - xres) / 2;
6166 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
6167 LVDSHBS -= xres / 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306169 if (LVDSHBS > LVDSHT)
6170 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006171
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306172 LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP;
6173 if (LVDSHRS > LVDSHT)
6174 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006175
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306176 LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC;
6177 if (LVDSHRE > LVDSHT)
6178 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306180 LVDSHBE = LVDSHBS + LVDSHT
6181 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006182
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306183 LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006184
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306185 LVDSVBS = yres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE
6186 - yres) / 2;
6187 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6188 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306190 if (LVDSVBS > LVDSVT)
6191 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306193 LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP;
6194 if (LVDSVRS > LVDSVT)
6195 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006196
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006197 LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].
6198 LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306199 if (LVDSVRE > LVDSVT)
6200 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306202 LVDSVBE = LVDSVBS + LVDSVT
6203 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006204
Aaro Koskinen58839b02011-03-13 12:26:23 +02006205 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006206 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006207
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306208 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006209 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306211 /* HT SR0B[1:0] CR00 */
6212 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006213 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006214 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006215
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306216 /* HBS SR0B[5:4] CR02 */
6217 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006218 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006219 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006220
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306221 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
6222 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006223 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
6224 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
6225 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306227 /* HRS SR0B[7:6] CR04 */
6228 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006229 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006230 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006231
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306232 /* Panel HRS SR2F[1:0] SR2E[7:0] */
6233 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006234 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006235 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306237 /* HRE SR0C[2] CR05[4:0] */
6238 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006239 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
6240 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006241
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306242 /* Panel HRE SR2F[7:2] */
6243 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006244 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306246 /* VT SR0A[0] CR07[5][0] CR06 */
6247 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006248 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
6249 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
6250 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006251 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006252
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306253 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
6254 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006255 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
6256 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
6257 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006258 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006259
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306260 /* VBE SR0A[4] CR16 */
6261 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006262 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006263 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006264
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306265 /* VRS SR0A[3] CR7[7][2] CR10 */
6266 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006267 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
6268 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
6269 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006270 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006271
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006272 if (chip_id == XG27) {
6273 /* Panel VRS SR35[2:0] SR34[7:0] */
6274 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
6275 (value & 0x700) >> 8);
6276 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
6277 } else {
6278 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
6279 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
6280 (value & 0x600) >> 9);
6281 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
6282 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
6283 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006284
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306285 /* VRE SR0A[5] CR11[3:0] */
6286 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006287 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
6288 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306290 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006291 if (chip_id == XG27)
6292 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6293 (value << 2) & 0xFC);
6294 else
6295 /* SR3F[7] has to be 0, h/w bug */
6296 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6297 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006298
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306299 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006300
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006301 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006302 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006303 0x2B,
6304 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6305 VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006306 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006307 0x2C,
6308 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6309 VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306310 value += 0x10;
6311 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006312
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306313 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006314 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006315 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006316 /* set data, panning = 0, shift left 1 dot*/
6317 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006318
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006319 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006320 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306321
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006322 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306323 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006324
6325}
6326
6327/* --------------------------------------------------------------------- */
6328/* Function : XGI_IsLCDON */
6329/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04006330/* Output : 0 : Skip PSC Control */
6331/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006332/* Description : */
6333/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006334static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006335{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306336 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006337
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306338 tempax = pVBInfo->VBInfo;
6339 if (tempax & SetCRT2ToDualEdge)
6340 return 0;
6341 else if (tempax & (DisableCRT2Display | SwitchToCRT2 | SetSimuScanMode))
6342 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306344 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006345}
6346
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006347/* --------------------------------------------------------------------- */
6348/* Function : XGI_DisableChISLCD */
6349/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04006350/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006351/* Description : */
6352/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006353static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006354{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306355 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006356
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306357 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006358 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006359
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306360 if (tempbx & (EnableChA | DisableChA)) {
6361 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6362 return 0;
6363 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006364
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306365 if (!(tempbx & (EnableChB | DisableChB)))
6366 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306368 if (tempah & 0x01) /* Chk LCDB Mode */
6369 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006370
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306371 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006372}
6373
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006374/* --------------------------------------------------------------------- */
6375/* Function : XGI_EnableChISLCD */
6376/* Input : */
6377/* Output : 0 -> Not LCD mode */
6378/* Description : */
6379/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006380static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006381{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306382 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006383
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306384 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006385 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006386
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306387 if (tempbx & (EnableChA | DisableChA)) {
6388 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6389 return 0;
6390 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006391
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306392 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04006393 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006394
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306395 if (tempah & 0x01) /* Chk LCDB Mode */
6396 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006397
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306398 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006399}
6400
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306401void XGI_DisableBridge(struct xgi_hw_device_info *HwDeviceExtension,
6402 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006403{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02006404 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006405
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306406 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6407 | VB_XGI302LV | VB_XGI301C)) {
6408 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006409 if (!(pVBInfo->VBInfo &
6410 (DisableCRT2Display | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306411 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6412 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6413 tempah = 0x7F; /* Disable Channel A */
6414 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006415 /* Disable Channel B */
6416 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006417
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306418 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006419 /* force to disable Cahnnel */
6420 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006421
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306422 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006423 /* Force to disable Channel B */
6424 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306425 }
6426 }
6427 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006428
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006429 /* disable part4_1f */
6430 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006431
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306432 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6433 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
6434 || (XGI_DisableChISLCD(pVBInfo))
6435 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006436 /* LVDS Driver power down */
6437 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006439
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306440 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6441 & (DisableCRT2Display | SetCRT2ToLCDA
6442 | SetSimuScanMode))) {
6443 if (pVBInfo->SetFlag & GatingCRT)
6444 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
6445 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6446 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006447
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306448 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6449 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6450 & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006451 /* Power down */
6452 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306453 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006454
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006455 /* disable TV as primary VGA swap */
6456 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006457
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306458 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02006459 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006460
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006461 if ((pVBInfo->SetFlag & DisableChB) ||
6462 (pVBInfo->VBInfo &
6463 (DisableCRT2Display | SetSimuScanMode)) ||
6464 ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) &&
6465 (pVBInfo->VBInfo &
6466 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
6467 /* BScreenOff=1 */
6468 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006469
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006470 if ((pVBInfo->SetFlag & DisableChB) ||
6471 (pVBInfo->VBInfo &
6472 (DisableCRT2Display | SetSimuScanMode)) ||
6473 (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) ||
6474 (pVBInfo->VBInfo &
6475 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
6476 /* save Part1 index 0 */
6477 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6478 /* BTDAC = 1, avoid VB reset */
6479 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
6480 /* disable CRT2 */
6481 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6482 /* restore Part1 index 0 */
6483 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306484 }
6485 } else { /* {301} */
6486 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006487 /* BScreenOff=1 */
6488 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6489 /* Disable CRT2 */
6490 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6491 /* Disable TV asPrimary VGA swap */
6492 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306493 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306495 if (pVBInfo->VBInfo & (DisableCRT2Display | SetCRT2ToLCDA
6496 | SetSimuScanMode))
6497 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6498 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006499}
6500
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006501/* --------------------------------------------------------------------- */
6502/* Function : XGI_GetTVPtrIndex */
6503/* Input : */
6504/* Output : */
6505/* Description : bx 0 : ExtNTSC */
6506/* 1 : StNTSC */
6507/* 2 : ExtPAL */
6508/* 3 : StPAL */
6509/* 4 : ExtHiTV */
6510/* 5 : StHiTV */
6511/* 6 : Ext525i */
6512/* 7 : St525i */
6513/* 8 : Ext525p */
6514/* 9 : St525p */
6515/* A : Ext750p */
6516/* B : St750p */
6517/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006518static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006519{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306520 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006521
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306522 if (pVBInfo->TVInfo & SetPALTV)
6523 tempbx = 2;
6524 if (pVBInfo->TVInfo & SetYPbPrMode1080i)
6525 tempbx = 4;
6526 if (pVBInfo->TVInfo & SetYPbPrMode525i)
6527 tempbx = 6;
6528 if (pVBInfo->TVInfo & SetYPbPrMode525p)
6529 tempbx = 8;
6530 if (pVBInfo->TVInfo & SetYPbPrMode750p)
6531 tempbx = 10;
6532 if (pVBInfo->TVInfo & TVSimuMode)
6533 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006534
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306535 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006536}
6537
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006538/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006539/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006540/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006541/* Output : bx 0 : NTSC */
6542/* 1 : PAL */
6543/* 2 : PALM */
6544/* 3 : PALN */
6545/* 4 : NTSC1024x768 */
6546/* 5 : PAL-M 1024x768 */
6547/* 6-7: reserved */
6548/* cl 0 : YFilter1 */
6549/* 1 : YFilter2 */
6550/* ch 0 : 301A */
6551/* 1 : 301B/302B/301LV/302LV */
6552/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006553/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006554static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
6555 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006556{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006557 *tempbx = 0;
6558 *tempcl = 0;
6559 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006560
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006561 if (pVBInfo->TVInfo & SetPALTV)
6562 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006563
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006564 if (pVBInfo->TVInfo & SetPALMTV)
6565 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006566
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006567 if (pVBInfo->TVInfo & SetPALNTV)
6568 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006569
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006570 if (pVBInfo->TVInfo & NTSC1024x768) {
6571 *tempbx = 4;
6572 if (pVBInfo->TVInfo & SetPALMTV)
6573 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306574 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006575
6576 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6577 | VB_XGI302LV | VB_XGI301C)) {
6578 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
6579 & TVSimuMode)) {
6580 *tempbx += 8;
6581 *tempcl += 1;
6582 }
6583 }
6584
6585 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6586 | VB_XGI302LV | VB_XGI301C))
6587 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006588}
6589
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006590static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006591{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306592 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006593
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306594 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006595
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306596 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6597 | VB_XGI302LV | VB_XGI301C)) {
6598 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA
6599 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
6600 tempbl = 0;
6601 tempbh = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006602
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306603 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
6604 tempbl = pVBInfo->XGI_TVDelayList[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006605
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306606 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
6607 | VB_XGI301LV | VB_XGI302LV
6608 | VB_XGI301C))
6609 tempbl = pVBInfo->XGI_TVDelayList2[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006610
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306611 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6612 tempbl = tempbl >> 4;
6613 /*
6614 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
6615 tempbl = CRT2Delay1; // Get CRT2 Delay
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006616 if (pVBInfo->VBType &
6617 (VB_XGI301B |
6618 VB_XGI302B |
6619 VB_XGI301LV |
6620 VB_XGI302LV |
6621 VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306622 tempbl = CRT2Delay2;
6623 */
6624 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006625 /* Get LCD Delay */
6626 index = XGI_GetLCDCapPtr(pVBInfo);
6627 tempbh = pVBInfo->LCDCapList[index].
6628 LCD_DelayCompensation;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006629
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306630 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6631 tempbl = tempbh;
6632 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006633
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306634 tempbl &= 0x0F;
6635 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02006636 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306638 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
6639 | SetCRT2ToTV)) { /* Channel B */
6640 tempah &= 0xF0;
6641 tempah |= tempbl;
6642 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006643
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306644 if (pVBInfo->VBInfo & SetCRT2ToLCDA) { /* Channel A */
6645 tempah &= 0x0F;
6646 tempah |= tempbh;
6647 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02006648 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306649 }
6650 } else if (pVBInfo->IF_DEF_LVDS == 1) {
6651 tempbl = 0;
6652 tempbh = 0;
6653 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006654 /* / Get LCD Delay */
6655 tempah = pVBInfo->LCDCapList[
6656 XGI_GetLCDCapPtr(pVBInfo)].
6657 LCD_DelayCompensation;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306658 tempah &= 0x0f;
6659 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006660 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306661 tempah);
6662 }
6663 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006664}
6665
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006666static void XGI_SetLCDCap_A(unsigned short tempcx,
6667 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006668{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306669 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006670
Aaro Koskinen58839b02011-03-13 12:26:23 +02006671 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006672
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306673 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006674 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006675 /* Enable Dither */
6676 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006677 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306678 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006679 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306680 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006681 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306682 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006683
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306684 /*
6685 if (tempcx & EnableLCD24bpp) { // 24bits
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006686 xgifb_reg_and_or(pVBInfo->Part1Port,
6687 0x19,
6688 0x0F,
6689 (unsigned short)(0x30 | (tempcx&0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006690 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306691 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006692 xgifb_reg_and_or(pVBInfo->Part1Port,
6693 0x19,
6694 0x0F,
6695 // Enable Dither
6696 (unsigned short)(0x20 | (tempcx&0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006697 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306698 }
6699 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006700}
6701
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006702/* --------------------------------------------------------------------- */
6703/* Function : XGI_SetLCDCap_B */
6704/* Input : cx -> LCD Capability */
6705/* Output : */
6706/* Description : */
6707/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006708static void XGI_SetLCDCap_B(unsigned short tempcx,
6709 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006710{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306711 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006712 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306713 (unsigned short) (((tempcx & 0x00ff) >> 6)
6714 | 0x0c));
6715 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006716 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306717 (unsigned short) (((tempcx & 0x00ff) >> 6)
6718 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006719}
6720
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02006721static void XGI_LongWait(struct vb_device_info *pVBInfo)
6722{
6723 unsigned short i;
6724
6725 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
6726
6727 if (!(i & 0xC0)) {
6728 for (i = 0; i < 0xFFFF; i++) {
6729 if (!(inb(pVBInfo->P3da) & 0x08))
6730 break;
6731 }
6732
6733 for (i = 0; i < 0xFFFF; i++) {
6734 if ((inb(pVBInfo->P3da) & 0x08))
6735 break;
6736 }
6737 }
6738}
6739
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006740static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006741{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306742 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006743
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306744 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006745
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006746 /* disable down spectrum D[4] */
6747 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306748 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006749 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306750 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006751
Aaro Koskinen8104e322011-03-13 12:26:22 +02006752 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306753 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006754 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306755 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006756 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306757 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006758 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306759 pVBInfo->LCDCapList[index].Spectrum_34);
6760 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006761 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006762}
6763
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006764static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
6765{
6766 unsigned short tempcx;
6767
6768 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
6769
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006770 if (pVBInfo->VBType &
6771 (VB_XGI301B |
6772 VB_XGI302B |
6773 VB_XGI301LV |
6774 VB_XGI302LV |
6775 VB_XGI301C)) { /* 301LV/302LV only */
6776 if (pVBInfo->VBType &
6777 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006778 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006779 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006780 (unsigned char) (tempcx & 0x1F));
6781 }
6782 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006783 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006784 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
6785 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
6786 | EnablePLLSPLOW)) >> 8));
6787 }
6788
6789 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6790 | VB_XGI302LV | VB_XGI301C)) {
6791 if (pVBInfo->VBInfo & SetCRT2ToLCD)
6792 XGI_SetLCDCap_B(tempcx, pVBInfo);
6793 else if (pVBInfo->VBInfo & SetCRT2ToLCDA)
6794 XGI_SetLCDCap_A(tempcx, pVBInfo);
6795
6796 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6797 if (tempcx & EnableSpectrum)
6798 SetSpectrum(pVBInfo);
6799 }
6800 } else {
6801 /* LVDS,CH7017 */
6802 XGI_SetLCDCap_A(tempcx, pVBInfo);
6803 }
6804}
6805
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006806/* --------------------------------------------------------------------- */
6807/* Function : XGI_SetAntiFlicker */
6808/* Input : */
6809/* Output : */
6810/* Description : Set TV Customized Param. */
6811/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006812static void XGI_SetAntiFlicker(unsigned short ModeNo,
6813 unsigned short ModeIdIndex,
6814 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006815{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306816 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306818 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306820 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
6821 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006822
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306823 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6824 tempbx &= 0xFE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306826 if (ModeNo <= 0x13)
6827 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
6828 else
6829 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006830
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306831 tempbx += index;
6832 tempah = TVAntiFlickList[tempbx];
6833 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006834
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006835 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006836}
6837
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006838static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6839 unsigned short ModeIdIndex,
6840 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006841{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306842 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006843
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306844 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306846 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6847 tempbx &= 0xFE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006848
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306849 if (ModeNo <= 0x13)
6850 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
6851 else
6852 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306854 tempbx += index;
6855 tempah = TVEdgeList[tempbx];
6856 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006857
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006858 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006859}
6860
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006861static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006862{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306863 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006864
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306865 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306867 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006868
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306869 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6870 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006871
Aaro Koskinen8104e322011-03-13 12:26:22 +02006872 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306873 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006874 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306875 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006876 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306877 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006878 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306879 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006880}
6881
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006882static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306883 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006884{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306885 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306887 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006888
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306889 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006890
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306891 switch (tempbx) {
6892 case 0x00:
6893 case 0x04:
6894 filterPtr = NTSCYFilter1;
6895 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006896
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306897 case 0x01:
6898 filterPtr = PALYFilter1;
6899 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006900
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306901 case 0x02:
6902 case 0x05:
6903 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306904 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03006905 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306906 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006907
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306908 case 0x08:
6909 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306910 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306911 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306912 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03006913 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306914 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306916 default:
6917 return;
6918 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006919
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306920 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006921 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
6922 VB_StTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306923 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006924 tempal = pVBInfo->EModeIDTable[ModeIdIndex].
6925 VB_ExtTVYFilterIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006926
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306927 if (tempcl == 0)
6928 index = tempal * 4;
6929 else
6930 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006931
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306932 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006933 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
6934 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
6935 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
6936 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306937 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006938 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
6939 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
6940 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
6941 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306942 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306944 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6945 | VB_XGI302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006946 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
6947 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
6948 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306949 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006950}
6951
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006952/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006953/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006954/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006955/* Output : */
6956/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006957/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006958static void XGI_OEM310Setting(unsigned short ModeNo,
6959 unsigned short ModeIdIndex,
6960 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006961{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006962 /* GetPart1IO(); */
6963 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006964
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006965 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
6966 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006967
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006968 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6969 /* GetPart2IO() */
6970 XGI_SetPhaseIncr(pVBInfo);
6971 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
6972 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006973
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006974 if (pVBInfo->VBType & VB_XGI301)
6975 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306976 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006977}
6978
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006979/* --------------------------------------------------------------------- */
6980/* Function : XGI_SetCRT2ModeRegs */
6981/* Input : */
6982/* Output : */
6983/* Description : Origin code for crt2group */
6984/* --------------------------------------------------------------------- */
Bill Pemberton82d6eb52010-06-17 13:10:46 -04006985void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306986 struct xgi_hw_device_info *HwDeviceExtension,
6987 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006988{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306989 unsigned short tempbl;
6990 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006991
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306992 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006993
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006994 /* // fix write part1 index 0 BTDRAM bit Bug
6995 * xgifb_reg_set(pVBInfo->Part1Port, 0x03, 0x00); */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306996 tempah = 0;
6997 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006998 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306999 tempah &= ~0x10; /* BTRAMDAC */
7000 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307002 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7003 | SetCRT2ToLCD)) {
7004 tempah = 0x40; /* BTDRAM */
7005 if (ModeNo > 0x13) {
7006 tempcl = pVBInfo->ModeType;
7007 tempcl -= ModeVGA;
7008 if (tempcl >= 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007009 /* BT Color */
7010 tempah = (0x008 >> tempcl);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307011 if (tempah == 0)
7012 tempah = 1;
7013 tempah |= 0x040;
7014 }
7015 }
7016 if (pVBInfo->VBInfo & SetInSlaveMode)
7017 tempah ^= 0x50; /* BTDAC */
7018 }
7019 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007020
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307021 /* 0210 shampoo
7022 if (pVBInfo->VBInfo & DisableCRT2Display) {
7023 tempah = 0;
7024 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007025
Aaro Koskinen8104e322011-03-13 12:26:22 +02007026 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307027 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)) {
7028 tempcl = pVBInfo->ModeType;
7029 if (ModeNo > 0x13) {
7030 tempcl -= ModeVGA;
7031 if ((tempcl > 0) || (tempcl == 0)) {
7032 tempah=(0x008>>tempcl) ;
7033 if (tempah == 0)
7034 tempah = 1;
7035 tempah |= 0x040;
7036 }
7037 } else {
7038 tempah = 0x040;
7039 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307041 if (pVBInfo->VBInfo & SetInSlaveMode) {
7042 tempah = (tempah ^ 0x050);
7043 }
7044 }
7045 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007046
Aaro Koskinen8104e322011-03-13 12:26:22 +02007047 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307048 tempah = 0x08;
7049 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007050
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307051 if (pVBInfo->VBInfo & DisableCRT2Display) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007052 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307053 } else {
7054 tempah = 0x00;
7055 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007056
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307057 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7058 | SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007059 if ((pVBInfo->VBInfo & SetCRT2ToLCDA) &&
7060 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307061 tempbl &= 0xf7;
7062 tempah |= 0x01;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007063 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307064 tempbl, tempah);
7065 } else {
7066 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7067 tempbl &= 0xf7;
7068 tempah |= 0x01;
7069 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007070
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007071 if (pVBInfo->VBInfo &
7072 (SetCRT2ToRAMDAC |
7073 SetCRT2ToTV |
7074 SetCRT2ToLCD)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307075 tempbl &= 0xf8;
7076 tempah = 0x01;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307078 if (!(pVBInfo->VBInfo & SetInSlaveMode))
7079 tempah |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007080
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007081 if (!(pVBInfo->VBInfo &
7082 SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307083 tempah = tempah ^ 0x05;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007084 if (!(pVBInfo->VBInfo &
7085 SetCRT2ToLCD))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307086 tempah = tempah ^ 0x01;
7087 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007088
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007089 if (!(pVBInfo->VBInfo &
7090 SetCRT2ToDualEdge))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307091 tempah |= 0x08;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007092 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307093 0x2e, tempbl, tempah);
7094 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007095 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307096 0x2e, tempbl, tempah);
7097 }
7098 }
7099 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007100 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307101 tempah);
7102 }
7103 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307105 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
7106 | SetCRT2ToLCDA)) {
7107 tempah &= (~0x08);
7108 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
7109 & SetInSlaveMode))) {
7110 tempah |= 0x010;
7111 }
7112 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307114 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007115 /* if (!(pVBInfo->TVInfo &
7116 (SetYPbPrMode525p | SetYPbPrMode750p))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307117 tempah |= 0x020;
7118 if (ModeNo > 0x13) {
7119 if (pVBInfo->VBInfo & DriverMode)
7120 tempah = tempah ^ 0x20;
7121 }
7122 /* } */
7123 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007124
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007125 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307126 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307128 if (pVBInfo->LCDInfo & SetLCDDualLink)
7129 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007130
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307131 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007132 /* if ((!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) &&
7133 (!(pVBInfo->TVInfo &
7134 (SetYPbPrMode525p | SetYPbPrMode750p)))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307135 if (pVBInfo->TVInfo & RPLLDIV2XO)
7136 tempah |= 0x40;
7137 /* } */
7138 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307140 if ((pVBInfo->LCDResInfo == Panel1280x1024)
7141 || (pVBInfo->LCDResInfo == Panel1280x1024x75))
7142 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307144 if (pVBInfo->LCDResInfo == Panel1280x960)
7145 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007146
Aaro Koskinen8104e322011-03-13 12:26:22 +02007147 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307148 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307150 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7151 | VB_XGI302LV | VB_XGI301C)) {
7152 tempah = 0;
7153 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007154
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307155 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7156 tempbl = 0xff;
7157 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7158 tempah |= 0x04; /* shampoo 0129 */
7159 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007160
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007161 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307162 tempah = 0x00;
7163 tempbl = 0xcf;
7164 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7165 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7166 tempah |= 0x30;
7167 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007168
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007169 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307170 tempah = 0;
7171 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307173 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7174 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7175 tempah |= 0xc0;
7176 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007177 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307178 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307180 tempah = 0;
7181 tempbl = 0x7f;
7182 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) {
7183 tempbl = 0xff;
7184 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
7185 tempah |= 0x80;
7186 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007187
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007188 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307190 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7191 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007192 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
7193 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307194 }
7195 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007196}
7197
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007198static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307199 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007200{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307201 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007202
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307203 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307205 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7206 tempbx = 0x08A0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007207
7208}
7209
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307210void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7211 struct vb_device_info *pVBInfo)
7212{
7213
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007214 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007215
7216}
7217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307218void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7219 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007220{
7221
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007222 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007223
7224}
7225
Bill Pemberton80adad82010-06-17 13:10:51 -04007226unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007227{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307228 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007229
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307230 if (pVBInfo->IF_DEF_LVDS == 1) {
7231 return 1;
7232 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007233 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307234 if ((flag == 1) || (flag == 2))
7235 return 1; /* 301b */
7236 else
7237 return 0;
7238 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007239}
7240
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007241static void XGI_VBLongWait(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007242{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307243 unsigned short tempal, temp, i, j;
7244 return;
7245 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
7246 temp = 0;
7247 for (i = 0; i < 3; i++) {
7248 for (j = 0; j < 100; j++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007249 tempal = inb(pVBInfo->P3da);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307250 if (temp & 0x01) { /* VBWaitMode2 */
7251 if ((tempal & 0x08))
7252 continue;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307254 if (!(tempal & 0x08))
7255 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307257 } else { /* VBWaitMode1 */
7258 if (!(tempal & 0x08))
7259 continue;
7260
7261 if ((tempal & 0x08))
7262 break;
7263 }
7264 }
7265 temp = temp ^ 0x01;
7266 }
7267 } else {
7268 XGI_LongWait(pVBInfo);
7269 }
7270 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007271}
7272
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007273unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
7274 unsigned short ModeNo, unsigned short ModeIdIndex,
7275 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007276{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007277 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
7278 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
7279 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007280
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007281 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007282
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007283 if (ModeNo <= 0x13)
7284 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7285 else
7286 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7287
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007288 if (ModeNo < 0x14)
7289 return 0xFFFF;
7290
Aaro Koskinen58839b02011-03-13 12:26:23 +02007291 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007292 index = index >> pVBInfo->SelectCRT2Rate;
7293 index &= 0x0F;
7294
7295 if (pVBInfo->LCDInfo & LCDNonExpanding)
7296 index = 0;
7297
7298 if (index > 0)
7299 index--;
7300
7301 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007302 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
7303 if (pVBInfo->IF_DEF_LVDS == 0) {
7304 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
7305 | VB_XGI301LV | VB_XGI302LV
7306 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007307 /* 301b */
7308 temp = LCDARefreshIndex[
7309 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007310 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007311 temp = LCDRefreshIndex[
7312 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007313
7314 if (index > temp)
7315 index = temp;
7316 } else {
7317 index = 0;
7318 }
7319 }
7320 }
7321
7322 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
7323 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
7324 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
7325 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007326 if (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag &
7327 XG2xNotSupport) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007328 index++;
7329 }
7330 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007331 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
7332 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007333 index++;
7334 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007335 /* Alan 10/19/2007;
7336 * do the similar adjustment like XGISearchCRT1Rate() */
7337 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
7338 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007339 index++;
7340 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007341 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
7342 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007343 index++;
7344 }
7345 }
7346
7347 i = 0;
7348 do {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007349 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
7350 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007351 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007352 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
7353 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007354 temp &= ModeInfoFlag;
7355 if (temp < pVBInfo->ModeType)
7356 break;
7357 i++;
7358 index--;
7359
7360 } while (index != 0xFFFF);
7361 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
7362 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007363 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
7364 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007365 if (temp & InterlaceMode)
7366 i++;
7367 }
7368 }
7369 i--;
7370 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
7371 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
7372 RefreshRateTableIndex, &i, pVBInfo);
7373 }
7374 return RefreshRateTableIndex + i; /* return (0x01 | (temp1<<1)); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007375}
7376
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007377static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307378 struct xgi_hw_device_info *HwDeviceExtension,
7379 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007380{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007381 unsigned short RefreshRateTableIndex;
7382 /* unsigned short temp ; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007383
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007384 /* pVBInfo->SelectCRT2Rate = 0; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007385
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007386 pVBInfo->SetFlag |= ProgrammingCRT2;
7387 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7388 ModeIdIndex, pVBInfo);
7389 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
7390 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7391 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7392 HwDeviceExtension, pVBInfo);
7393 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7394 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007395}
7396
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007397unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
7398 struct xgi_hw_device_info *HwDeviceExtension,
7399 struct vb_device_info *pVBInfo)
7400{
7401 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
7402
7403 tempbx = pVBInfo->VBInfo;
7404 pVBInfo->SetFlag |= ProgrammingCRT2;
7405 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7406 pVBInfo->SelectCRT2Rate = 4;
7407 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7408 ModeIdIndex, pVBInfo);
7409 XGI_SaveCRT2Info(ModeNo, pVBInfo);
7410 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
7411 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7412 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7413 RefreshRateTableIndex, pVBInfo);
7414 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7415 RefreshRateTableIndex, pVBInfo);
7416 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7417 RefreshRateTableIndex, pVBInfo);
7418 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7419 HwDeviceExtension, pVBInfo);
7420 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7421 RefreshRateTableIndex, pVBInfo);
7422 XGI_SetTap4Regs(pVBInfo);
7423 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
7424 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7425 HwDeviceExtension, pVBInfo);
7426 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7427 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
7428 XGI_AutoThreshold(pVBInfo);
7429 return 1;
7430}
7431
7432void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
7433{
7434 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
7435 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
7436 0x05, 0x00 };
7437
7438 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
7439
7440 unsigned char CR17, CR63, SR31;
7441 unsigned short temp;
7442 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
7443
7444 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02007445 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007446
7447 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007448 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02007449 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007450 pVBInfo->P3d4, 0x53) | 0x02));
7451
Aaro Koskinen58839b02011-03-13 12:26:23 +02007452 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
7453 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
7454 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007455
Aaro Koskinen8104e322011-03-13 12:26:22 +02007456 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
7457 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007458
Aaro Koskinen58839b02011-03-13 12:26:23 +02007459 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007460 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007461
Aaro Koskinen58839b02011-03-13 12:26:23 +02007462 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007463 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007464
Aaro Koskinen58839b02011-03-13 12:26:23 +02007465 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007466 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02007467 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007468 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007469
Aaro Koskinen8104e322011-03-13 12:26:22 +02007470 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007471
7472 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007473 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007474
7475 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007476 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007477 CRTCData[i]);
7478
7479 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007480 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007481 CRTCData[i]);
7482
7483 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007484 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007485 CRTCData[i]);
7486
Aaro Koskinen8104e322011-03-13 12:26:22 +02007487 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007488 & 0xE0));
7489
Aaro Koskinen8104e322011-03-13 12:26:22 +02007490 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
7491 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7492 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007493
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007494 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007495
7496 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007497 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
7498 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
7499 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007500 }
7501
7502 XGI_VBLongWait(pVBInfo);
7503 XGI_VBLongWait(pVBInfo);
7504 XGI_VBLongWait(pVBInfo);
7505
7506 mdelay(1);
7507
7508 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007509 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007510
7511 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007512 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007513 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007514 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007515
7516 /* alan, avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007517 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007518
7519 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007520 outb(0, (pVBInfo->P3c8 + 1));
7521 outb(0, (pVBInfo->P3c8 + 1));
7522 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007523 }
7524
Aaro Koskinen8104e322011-03-13 12:26:22 +02007525 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
7526 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
7527 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007528
7529 /* [2004/05/11] Vicent */
Aaro Koskinen58839b02011-03-13 12:26:23 +02007530 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007531 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02007532 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007533}
7534
7535void XGI_EnableBridge(struct xgi_hw_device_info *HwDeviceExtension,
7536 struct vb_device_info *pVBInfo)
7537{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02007538 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007539
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007540 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7541 | VB_XGI302LV | VB_XGI301C)) {
7542 if (!(pVBInfo->SetFlag & DisableChA)) {
7543 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007544 /* Power on */
7545 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007546 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007547 /* SetCRT2ToLCDA ) */
7548 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7549 /* Power on */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007550 xgifb_reg_set(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007551 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007552 }
7553 }
7554 }
7555
7556 if (!(pVBInfo->SetFlag & DisableChB)) {
7557 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
7558 & (SetCRT2ToLCD | SetCRT2ToTV
7559 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007560 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007561 pVBInfo->P3c4, 0x32);
7562 tempah &= 0xDF;
7563 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007564 if (!(pVBInfo->VBInfo &
7565 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007566 tempah |= 0x20;
7567 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02007568 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007569 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007570
Aaro Koskinen58839b02011-03-13 12:26:23 +02007571 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007572 pVBInfo->Part1Port, 0x2E);
7573
7574 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007575 /* BVBDOENABLE = 1 */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007576 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007577 0x2E, 0x80);
7578 /* BScreenOFF = 0 */
7579 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007580 }
7581 }
7582
7583 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
7584 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007585 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007586 0x20); /* shampoo 0129 */
7587 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7588 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007589 if (XGI_EnableChISLCD(pVBInfo) ||
7590 (pVBInfo->VBInfo &
7591 (SetCRT2ToLCD | SetCRT2ToLCDA)))
7592 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02007593 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007594 pVBInfo->Part4Port,
7595 0x2A,
7596 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007597 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007598 /* LVDS Driver power on */
7599 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007600 }
7601 }
7602
7603 tempah = 0x00;
7604
7605 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7606 tempah = 0xc0;
7607
7608 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
7609 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007610 if (pVBInfo->VBInfo &
7611 SetCRT2ToDualEdge) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007612 tempah = tempah & 0x40;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007613 if (pVBInfo->VBInfo &
7614 SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007615 tempah = tempah ^ 0xC0;
7616
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007617 if (pVBInfo->SetFlag &
7618 DisableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007619 tempah &= 0xBF;
7620
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007621 if (pVBInfo->SetFlag &
7622 DisableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007623 tempah &= 0x7F;
7624
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007625 if (pVBInfo->SetFlag &
7626 EnableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007627 tempah |= 0x40;
7628
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007629 if (pVBInfo->SetFlag &
7630 EnableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007631 tempah |= 0x80;
7632 }
7633 }
7634 }
7635 }
7636
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007637 /* EnablePart4_1F */
7638 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007639
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007640 if (!(pVBInfo->SetFlag & DisableChA)) {
7641 XGI_VBLongWait(pVBInfo);
7642 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007643 XGI_DisableGatingCRT(HwDeviceExtension,
7644 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007645 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7646 XGI_VBLongWait(pVBInfo);
7647 }
7648 }
7649 } /* 301 */
7650 else { /* LVDS */
7651 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
7652 | SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007653 /* enable CRT2 */
7654 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007655
Aaro Koskinen58839b02011-03-13 12:26:23 +02007656 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007657 0x2E);
7658 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007659 /* BVBDOENABLE = 1 */
7660 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007661
Aaro Koskinendc505562011-03-13 12:26:26 +02007662 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007663 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7664 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007665}
7666
7667static void XGI_SetCRT1Group(struct xgi_hw_device_info *HwDeviceExtension,
7668 unsigned short ModeNo, unsigned short ModeIdIndex,
7669 struct vb_device_info *pVBInfo)
7670{
7671 unsigned short StandTableIndex, RefreshRateTableIndex, b3CC, temp;
7672
7673 unsigned short XGINew_P3cc = pVBInfo->P3cc;
7674
7675 /* XGINew_CRT1Mode = ModeNo; // SaveModeID */
7676 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
7677 /* XGI_SetBIOSData(ModeNo, ModeIdIndex); */
7678 /* XGI_ClearBankRegs(ModeNo, ModeIdIndex); */
7679 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7680 XGI_SetMiscRegs(StandTableIndex, pVBInfo);
7681 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
7682 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7683 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
7684 XGI_ClearExt1Regs(pVBInfo);
7685
7686 /* if (pVBInfo->IF_DEF_ExpLink) */
7687 if (HwDeviceExtension->jChipType == XG27) {
7688 if (pVBInfo->IF_DEF_LVDS == 0)
7689 XGI_SetDefaultVCLK(pVBInfo);
7690 }
7691
7692 temp = ~ProgrammingCRT2;
7693 pVBInfo->SetFlag &= temp;
7694 pVBInfo->SelectCRT2Rate = 0;
7695
7696 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7697 | VB_XGI302LV | VB_XGI301C)) {
7698 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA
7699 | SetInSlaveMode)) {
7700 pVBInfo->SetFlag |= ProgrammingCRT2;
7701 }
7702 }
7703
7704 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7705 ModeIdIndex, pVBInfo);
7706 if (RefreshRateTableIndex != 0xFFFF) {
7707 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
7708 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7709 pVBInfo, HwDeviceExtension);
7710 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
7711 RefreshRateTableIndex, pVBInfo);
7712 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7713 HwDeviceExtension, pVBInfo);
7714 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
7715 RefreshRateTableIndex, pVBInfo);
7716 }
7717
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007718 if ((HwDeviceExtension->jChipType >= XG20) &&
7719 (HwDeviceExtension->jChipType < XG27)) { /* fix H/W DCLK/2 bug */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007720 if ((ModeNo == 0x00) | (ModeNo == 0x01)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007721 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x4E);
7722 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE9);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007723 b3CC = (unsigned char) inb(XGINew_P3cc);
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007724 outb((b3CC |= 0x0C), XGINew_P3cc);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007725 } else if ((ModeNo == 0x04) | (ModeNo == 0x05) | (ModeNo
7726 == 0x0D)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007727 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7728 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE3);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007729 b3CC = (unsigned char) inb(XGINew_P3cc);
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007730 outb((b3CC |= 0x0C), XGINew_P3cc);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007731 }
7732 }
7733
7734 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007735 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007736 if (temp & 0xA0) {
7737
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007738 /* Enable write GPIOF */
7739 /* xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x20); */
7740 /* P. DWN */
7741 /* xgifb_reg_and(pVBInfo->P3d4, 0x48, ~0x20); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007742 /* XG21 CRT1 Timing */
7743 if (HwDeviceExtension->jChipType == XG27)
7744 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
7745 RefreshRateTableIndex, pVBInfo);
7746 else
7747 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
7748 RefreshRateTableIndex, pVBInfo);
7749
7750 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
7751 RefreshRateTableIndex);
7752
Aaro Koskinen105d8d02011-08-31 21:46:00 +03007753 xgifb_set_lcd(HwDeviceExtension->jChipType,
7754 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007755
Aaro Koskinen64db29f2011-08-31 21:46:01 +03007756 if (pVBInfo->IF_DEF_LVDS == 1)
7757 xgifb_set_lvds(HwDeviceExtension->jChipType,
7758 ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007759 /* P. ON */
7760 /* xgifb_reg_or(pVBInfo->P3d4, 0x48, 0x20); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007761 }
7762 }
7763
7764 pVBInfo->SetFlag &= (~ProgrammingCRT2);
7765 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
7766 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
7767 RefreshRateTableIndex, pVBInfo);
7768
7769 /* XGI_LoadCharacter(); //dif ifdef TVFont */
7770
7771 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
7772 /* XGI_ClearBuffer(HwDeviceExtension, ModeNo, pVBInfo); */
7773}
7774
7775unsigned char XGISetModeNew(struct xgi_hw_device_info *HwDeviceExtension,
7776 unsigned short ModeNo)
7777{
7778 unsigned short ModeIdIndex;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007779 /* unsigned char *pVBInfo->FBAddr =
7780 HwDeviceExtension->pjVideoMemoryAddress; */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007781 struct vb_device_info VBINF;
7782 struct vb_device_info *pVBInfo = &VBINF;
7783 pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase;
7784 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;
7785 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007786 pVBInfo->IF_DEF_LCDA = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007787
7788 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
7789 pVBInfo->IF_DEF_YPbPr = 0;
7790 pVBInfo->IF_DEF_HiVision = 0;
7791 pVBInfo->IF_DEF_CRT2Monitor = 0;
7792 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007793 } else {
7794 pVBInfo->IF_DEF_YPbPr = 1;
7795 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02007796 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007797 }
7798
7799 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
7800 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
7801 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
7802 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
7803 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
7804 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
7805 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
7806 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
7807 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
7808 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
7809 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
7810 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
7811 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
7812 pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04;
7813 pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10;
7814 pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12;
7815 pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14;
7816 pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2;
7817
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007818 /* for x86 Linux, XG21 LVDS */
7819 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007820 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007821 pVBInfo->IF_DEF_LVDS = 1;
7822 }
7823 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007824 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
7825 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007826 pVBInfo->IF_DEF_LVDS = 1;
7827 }
7828 }
7829
7830 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
7831 XGI_GetVBType(pVBInfo);
7832
7833 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
7834 if (ModeNo & 0x80) {
7835 ModeNo = ModeNo & 0x7F;
7836 /* XGINew_flag_clearbuffer = 0; */
7837 }
7838 /* else {
7839 XGINew_flag_clearbuffer = 1;
7840 }
7841 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007842 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007843
7844 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
7845 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
7846
7847 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7848
7849 XGI_GetVGAType(HwDeviceExtension, pVBInfo);
7850
7851 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7852 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
7853 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
7854 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
7855 XGI_DisableBridge(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007856
7857 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) {
7858 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7859 ModeIdIndex, pVBInfo);
7860
7861 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7862 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7863 HwDeviceExtension, pVBInfo);
7864 }
7865 } else {
7866 if (!(pVBInfo->VBInfo & SwitchToCRT2)) {
7867 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7868 ModeIdIndex, pVBInfo);
7869 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7870 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7871 HwDeviceExtension,
7872 pVBInfo);
7873 }
7874 }
7875 }
7876
7877 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchToCRT2)) {
7878 switch (HwDeviceExtension->ujVBChipID) {
7879 case VB_CHIP_301:
7880 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7881 pVBInfo); /*add for CRT2 */
7882 break;
7883
7884 case VB_CHIP_302:
7885 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7886 pVBInfo); /*add for CRT2 */
7887 break;
7888
7889 default:
7890 break;
7891 }
7892 }
7893
7894 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
7895 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
7896 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
7897 XGI_EnableBridge(HwDeviceExtension, pVBInfo);
7898 } /* !XG20 */
7899 else {
7900 if (pVBInfo->IF_DEF_LVDS == 1)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007901 if (!XGI_XG21CheckLVDSMode(ModeNo,
7902 ModeIdIndex,
7903 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007904 return 0;
7905
7906 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007907 pVBInfo->ModeType = pVBInfo->SModeIDTable[ModeIdIndex].
7908 St_ModeFlag & ModeInfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007909 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007910 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
7911 Ext_ModeFlag & ModeInfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007912 }
7913
7914 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03007915 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007916
7917 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
7918
7919 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex,
7920 pVBInfo);
7921
7922 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7923 /*
7924 if (HwDeviceExtension->jChipType == XG21)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007925 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0x80, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007926 */
7927 }
7928
7929 /*
7930 if (ModeNo <= 0x13) {
7931 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7932 } else {
7933 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7934 }
7935 pVBInfo->ModeType = modeflag&ModeInfoFlag;
7936 pVBInfo->SetFlag = 0x00;
7937 pVBInfo->VBInfo = DisableCRT2Display;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007938 temp = XGINew_CheckMemorySize(HwDeviceExtension,
7939 ModeNo,
7940 ModeIdIndex,
7941 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007942
7943 if (temp == 0)
7944 return (0);
7945
7946 XGI_DisplayOff(HwDeviceExtension, pVBInfo) ;
7947 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex, pVBInfo);
7948 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7949 */
7950
7951 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
7952
7953 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7954 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
7955 }
7956
7957 return 1;
7958}