blob: 2561e5a2c4754655cdb46e21a4516739091ab604 [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;
Peter Huewefc39dcb2012-01-15 19:22:12 +010064 pVBInfo->StandTable = (struct SiS_StandTable_S *) XGI330_StandTable;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053065 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
Peter Huewefc39dcb2012-01-15 19:22:12 +010070 pVBInfo->MCLKData = (struct SiS_MCLKData *) XGI340New_MCLKData;
Aaro Koskinen06587332011-03-13 12:26:10 +020071 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
Peter Huewefc39dcb2012-01-15 19:22:12 +010072 pVBInfo->VCLKData = (struct SiS_VCLKData *) XGI_VCLKData;
73 pVBInfo->VBVCLKData = (struct SiS_VBVCLKData *) XGI_VBVCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053074 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
Peter Huewefc39dcb2012-01-15 19:22:12 +010075 pVBInfo->StResInfo = (struct SiS_StResInfo_S *) XGI330_StResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053076 pVBInfo->ModeResInfo
Peter Huewefc39dcb2012-01-15 19:22:12 +010077 = (struct SiS_ModeResInfo_S *) XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020078
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053079 pVBInfo->pOutputSelect = &XGI330_OutputSelect;
80 pVBInfo->pSoftSetting = &XGI330_SoftSetting;
81 pVBInfo->pSR07 = &XGI330_SR07;
82 pVBInfo->LCDResInfo = 0;
83 pVBInfo->LCDTypeInfo = 0;
84 pVBInfo->LCDInfo = 0;
85 pVBInfo->VBInfo = 0;
86 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020087
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053088 pVBInfo->SR15 = XGI340_SR13;
89 pVBInfo->CR40 = XGI340_cr41;
90 pVBInfo->SR25 = XGI330_sr25;
91 pVBInfo->pSR31 = &XGI330_sr31;
92 pVBInfo->pSR32 = &XGI330_sr32;
93 pVBInfo->CR6B = XGI340_CR6B;
94 pVBInfo->CR6E = XGI340_CR6E;
95 pVBInfo->CR6F = XGI340_CR6F;
96 pVBInfo->CR89 = XGI340_CR89;
97 pVBInfo->AGPReg = XGI340_AGPReg;
98 pVBInfo->SR16 = XGI340_SR16;
99 pVBInfo->pCRCF = &XG40_CRCF;
100 pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530102 pVBInfo->CR49 = XGI330_CR49;
103 pVBInfo->pSR1F = &XGI330_SR1F;
104 pVBInfo->pSR21 = &XGI330_SR21;
105 pVBInfo->pSR22 = &XGI330_SR22;
106 pVBInfo->pSR23 = &XGI330_SR23;
107 pVBInfo->pSR24 = &XGI330_SR24;
108 pVBInfo->pSR33 = &XGI330_SR33;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200109
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530110 pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2;
111 pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D;
112 pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E;
113 pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10;
114 pVBInfo->pRGBSenseData = &XGI330_RGBSenseData;
115 pVBInfo->pVideoSenseData = &XGI330_VideoSenseData;
116 pVBInfo->pYCSenseData = &XGI330_YCSenseData;
117 pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2;
118 pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2;
119 pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530121 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
122 pVBInfo->PALTiming = XGI330_PALTiming;
123 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
124 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
125 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
126 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
127 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
128 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
129 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
130 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
131 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
132 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
133 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
134 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530136 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
137 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
138 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530140 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +0100141 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530142 pVBInfo->LCDCapList = XGI_LCDDLCapList;
143 else
144 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530146 pVBInfo->XGI_TVDelayList = XGI301TVDelayList;
147 pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200148
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530149 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530151 if (ChipType >= XG20)
152 pVBInfo->pXGINew_CR97 = &XG20_CR97;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530154 if (ChipType == XG27) {
155 pVBInfo->MCLKData
Peter Huewefc39dcb2012-01-15 19:22:12 +0100156 = (struct SiS_MCLKData *) XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530157 pVBInfo->CR40 = XGI27_cr41;
158 pVBInfo->pXGINew_CR97 = &XG27_CR97;
159 pVBInfo->pSR36 = &XG27_SR36;
160 pVBInfo->pCR8F = &XG27_CR8F;
161 pVBInfo->pCRD0 = XG27_CRD0;
162 pVBInfo->pCRDE = XG27_CRDE;
163 pVBInfo->pSR40 = &XG27_SR40;
164 pVBInfo->pSR41 = &XG27_SR41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200165
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530166 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200167
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530168 if (ChipType >= XG20) {
169 pVBInfo->pDVOSetting = &XG21_DVOSetting;
170 pVBInfo->pCR2E = &XG21_CR2E;
171 pVBInfo->pCR2F = &XG21_CR2F;
172 pVBInfo->pCR46 = &XG21_CR46;
173 pVBInfo->pCR47 = &XG21_CR47;
174 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200175
176}
177
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800178static unsigned char XGI_GetModePtr(unsigned short ModeNo,
179 unsigned short ModeIdIndex,
180 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200181{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530182 unsigned char index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200183
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300184 if (pVBInfo->ModeType <= 0x02)
185 index = 0x1B; /* 02 -> ModeEGA */
186 else
187 index = 0x0F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530188 return index; /* Get pVBInfo->StandTable index */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200189}
190
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800191static void XGI_SetSeqRegs(unsigned short ModeNo,
192 unsigned short StandTableIndex,
193 unsigned short ModeIdIndex,
194 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200195{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530196 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530197 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200198
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300199 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200200
Aaro Koskinen8104e322011-03-13 12:26:22 +0200201 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530202 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200203
Peter Huewea3d675c2012-02-09 21:11:47 +0100204 i = XGI_SetCRT2ToLCDA;
205 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530206 tempah |= 0x01;
207 } else {
208 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
209 if (pVBInfo->VBInfo & SetInSlaveMode)
210 tempah |= 0x01;
211 }
212 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200213
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530214 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200215 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200216
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530217 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800218 /* Get SR2,3,4 from file */
219 SRdata = pVBInfo->StandTable[StandTableIndex].SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200220 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530221 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200222}
223
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200224static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800225 unsigned short StandTableIndex,
226 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200227{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530228 unsigned char CRTCdata;
229 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200230
Aaro Koskinen58839b02011-03-13 12:26:23 +0200231 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530232 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200233 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200234
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530235 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800236 /* Get CRTC from file */
237 CRTCdata = pVBInfo->StandTable[StandTableIndex].CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200238 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530239 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200240}
241
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800242static void XGI_SetATTRegs(unsigned short ModeNo,
243 unsigned short StandTableIndex,
244 unsigned short ModeIdIndex,
245 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200246{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530247 unsigned char ARdata;
248 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200249
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300250 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530252 for (i = 0; i <= 0x13; i++) {
253 ARdata = pVBInfo->StandTable[StandTableIndex].ATTR[i];
254 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
255 if (i == 0x13) {
Peter Huewea3d675c2012-02-09 21:11:47 +0100256 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530257 ARdata = 0;
258 } else {
259 if (pVBInfo->VBInfo & (SetCRT2ToTV
260 | SetCRT2ToLCD)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800261 if (pVBInfo->VBInfo &
262 SetInSlaveMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530263 ARdata = 0;
264 }
265 }
266 }
267 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200268
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200269 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200270 outb(i, pVBInfo->P3c0); /* set index */
271 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530272 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200273
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200274 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200275 outb(0x14, pVBInfo->P3c0); /* set index */
276 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200277 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200278 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200279}
280
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200281static void XGI_SetGRCRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800282 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200283{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530284 unsigned char GRdata;
285 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200286
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530287 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800288 /* Get GR from file */
289 GRdata = pVBInfo->StandTable[StandTableIndex].GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200290 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530291 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200292
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530293 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200294 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530295 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200296 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530297 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200298}
299
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200300static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200301{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530302 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200303
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530304 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200305 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200306}
307
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200308static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200309{
310
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200311 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200312 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
313 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200314
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200315 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200316 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
317 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200318
Aaro Koskinendc505562011-03-13 12:26:26 +0200319 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530320 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200321}
322
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200323static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530324 unsigned short ModeIdIndex,
325 unsigned short RefreshRateTableIndex, unsigned short *i,
326 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200327{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530328 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200329
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300330 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530331 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
332 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
333 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200334
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530335 if (pVBInfo->IF_DEF_LVDS == 0) {
336 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
337 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200338
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530339 if (pVBInfo->VBType & VB_XGI301C)
340 tempax |= SupportCRT2in301C;
341 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200342
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800343 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100344 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530345 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200346
Peter Huewe255aabd2012-02-09 21:11:44 +0100347 if (pVBInfo->LCDResInfo != Panel_1280x1024) {
348 if (pVBInfo->LCDResInfo != Panel_1280x960) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800349 if (pVBInfo->LCDInfo &
350 LCDNonExpanding) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530351 if (resinfo >= 9) {
352 tempax = 0;
353 return 0;
354 }
355 }
356 }
357 }
358 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200359
Peter Huewe599801f2012-02-09 21:11:45 +0100360 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Peter Huewe6896b942012-02-09 21:11:46 +0100361 if ((pVBInfo->VBType & VB_SIS301LV) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800362 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Peter Huewe6896b942012-02-09 21:11:46 +0100363 tempax |= SupportYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530364 if (pVBInfo->VBInfo & SetInSlaveMode) {
365 if (resinfo == 4)
366 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530368 if (resinfo == 3)
369 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200370
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530371 if (resinfo > 7)
372 return 0;
373 }
374 } else {
Peter Huewe6896b942012-02-09 21:11:46 +0100375 tempax |= SupportHiVision;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530376 if (pVBInfo->VBInfo & SetInSlaveMode) {
377 if (resinfo == 4)
378 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530380 if (resinfo == 3) {
381 if (pVBInfo->SetFlag
382 & TVSimuMode)
383 return 0;
384 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200385
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530386 if (resinfo > 7)
387 return 0;
388 }
389 }
390 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800391 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
392 SetCRT2ToSVIDEO |
393 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100394 SetCRT2ToYPbPr525750 |
395 SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530396 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200397
Peter Huewe6896b942012-02-09 21:11:46 +0100398 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
399 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530400 | VB_XGI301C)) {
401 tempax |= SupportTV1024;
402 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200403
Peter Huewe599801f2012-02-09 21:11:45 +0100404 if (!(pVBInfo->VBInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530405 if (modeflag & NoSupportSimuTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800406 if (pVBInfo->VBInfo &
407 SetInSlaveMode) {
408 if (!(pVBInfo->VBInfo &
409 SetNotSimuMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530410 return 0;
411 }
412 }
413 }
414 }
415 }
416 }
417 } else { /* for LVDS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530418 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
419 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200420
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530421 if (resinfo > 0x08)
422 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200423
Peter Huewe255aabd2012-02-09 21:11:44 +0100424 if (pVBInfo->LCDResInfo < Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530425 if (resinfo > 0x07)
426 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200427
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530428 if (resinfo == 0x04)
429 return 0; /* 512x384 */
430 }
431 }
432 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200433
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800434 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
435 tempbx; (*i)--) {
436 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
437 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530438 if (infoflag & tempax)
439 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200440
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530441 if ((*i) == 0)
442 break;
443 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200444
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530445 for ((*i) = 0;; (*i)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800446 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
447 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530448 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
449 != tempbx) {
450 return 0;
451 }
452
453 if (infoflag & tempax)
454 return 1;
455 }
456 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200457}
458
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200459static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530460 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200461{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530462 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200463
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800464 /* di+0x00 */
465 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530466 sync &= 0xC0;
467 temp = 0x2F;
468 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200469 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200470}
471
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200472static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530473 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200474{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530475 unsigned char data, data1, pushax;
476 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200477
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800478 /* unlock cr0-7 */
479 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530480 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200481 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200482
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530483 data = pVBInfo->TimingH[0].data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200484 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200485
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530486 for (i = 0x01; i <= 0x04; i++) {
487 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200488 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530489 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200490
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530491 for (i = 0x05; i <= 0x06; i++) {
492 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200493 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530494 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200495
Aaro Koskinen58839b02011-03-13 12:26:23 +0200496 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530497 j &= 0x1F;
498 data = pVBInfo->TimingH[0].data[7];
499 data &= 0xE0;
500 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200501 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200502
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530503 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200504 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530505 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200506 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200507 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530508 data1 = data;
509 data1 &= 0xE0;
510 data &= 0x1F;
511 if (data == 0) {
512 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200513 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530514 0x0c);
515 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200516 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530517 data = pushax;
518 }
519 data = data - 1;
520 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200521 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200522 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530523 data = data >> 5;
524 data = data + 3;
525 if (data > 7)
526 data = data - 7;
527 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200528 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530529 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200530}
531
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800532static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
533 unsigned short ModeNo,
534 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200535{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530536 unsigned char data;
537 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200538
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530539 for (i = 0x00; i <= 0x01; i++) {
540 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200541 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530542 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200543
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530544 for (i = 0x02; i <= 0x03; i++) {
545 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200546 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530547 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200548
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530549 for (i = 0x04; i <= 0x05; i++) {
550 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200551 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530552 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200553
Aaro Koskinen58839b02011-03-13 12:26:23 +0200554 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530555 j &= 0xC0;
556 data = pVBInfo->TimingV[0].data[6];
557 data &= 0x3F;
558 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200559 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200560
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530561 data = pVBInfo->TimingV[0].data[6];
562 data &= 0x80;
563 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200564
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300565 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530566 i &= DoubleScanMode;
567 if (i)
568 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200569
Aaro Koskinen58839b02011-03-13 12:26:23 +0200570 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530571 j &= 0x5F;
572 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200573 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200574}
575
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200576static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
577 unsigned short RefreshRateTableIndex,
578 struct vb_device_info *pVBInfo,
579 struct xgi_hw_device_info *HwDeviceExtension)
580{
581 unsigned char index, data;
582 unsigned short i;
583
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800584 /* Get index */
585 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200586 index = index & IndexMask;
587
Aaro Koskinen58839b02011-03-13 12:26:23 +0200588 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200589 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200590 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200591
592 for (i = 0; i < 8; i++)
593 pVBInfo->TimingH[0].data[i]
594 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
595
596 for (i = 0; i < 7; i++)
597 pVBInfo->TimingV[0].data[i]
598 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
599
600 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
601
602 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
603
604 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200605 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200606}
607
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200608/* --------------------------------------------------------------------- */
609/* Function : XGI_SetXG21CRTC */
610/* Input : Stand or enhance CRTC table */
611/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
612/* Description : Set LCD timing */
613/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200614static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530615 unsigned short RefreshRateTableIndex,
616 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200617{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300618 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530619 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200620
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300621 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
622 /* Tempax: CR4 HRS */
623 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
624 Tempcx = Tempax; /* Tempcx: HRS */
625 /* SR2E[7:0]->HRS */
626 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200627
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300628 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
629 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
630 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
631 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
632 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800633
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300634 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
635 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200636
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300637 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
638 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
639 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
640 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200641
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300642 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
643 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200644
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300645 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
646 if (Tempax < Tempcx) /* HRE < HRS */
647 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200648
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300649 Temp2 &= 0xFF;
650 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
651 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
652 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
653 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
654 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
655 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
656 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200657
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300658 /* CR10 VRS */
659 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
660 Tempbx = Tempax; /* Tempbx: VRS */
661 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
662 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
663 /* CR7[2][7] VRE */
664 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
665 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
666 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
667 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
668 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
669 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200670
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300671 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
672 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
673 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
674 Tempax &= 0x80;
675 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
676 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
677 /* Tempax: SRA */
678 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
679 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
680 Temp2 = Tempax;
681 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
682 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200683
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300684 /* Tempax: CR11 VRE */
685 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
686 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
687 /* Tempbx: SRA */
688 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
689 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
690 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
691 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
692 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
693 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200694
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300695 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
696 if (Tempax < Temp3) /* VRE < VRS */
697 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200698
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300699 Temp2 &= 0xFF;
700 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
701 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
702 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
703 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
704 Tempbx = (unsigned char) Temp1;
705 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
706 Tempax &= 0x7F;
707 /* SR3F D[7:2]->VRE D[1:0]->VRS */
708 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200709}
710
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800711static void XGI_SetXG27CRTC(unsigned short ModeNo,
712 unsigned short ModeIdIndex,
713 unsigned short RefreshRateTableIndex,
714 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200715{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300716 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200717
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300718 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
719 /* Tempax: CR4 HRS */
720 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
721 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
722 /* SR2E[7:0]->HRS */
723 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200724
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300725 /* SR0B */
726 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
727 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
728 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200729
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300730 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
731 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
732 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200733
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300734 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
735 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
736 Tempax <<= 3; /* Tempax[5]: HRE[5] */
737 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200738
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300739 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
740 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200741
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300742 /* Tempax: CR4 HRS */
743 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
744 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
745 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
746 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200747
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300748 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
749 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
750 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
751 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
752 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
753 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
754 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200755
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300756 /* CR10 VRS */
757 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
758 /* SR34[7:0]->VRS[7:0] */
759 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200760
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300761 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
762 /* CR7[7][2] VRS[9][8] */
763 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
764 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
765 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
766 Tempax >>= 2; /* Tempax[0]: VRS[8] */
767 /* SR35[0]: VRS[8] */
768 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
769 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
770 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
771 /* Tempax: SR0A */
772 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
773 Tempax &= 0x08; /* SR0A[3] VRS[10] */
774 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200775
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300776 /* Tempax: CR11 VRE */
777 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
778 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
779 /* Tempbx: SR0A */
780 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
781 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
782 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
783 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
784 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
785 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
786 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200787
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300788 if (Tempbx <= Tempcx) /* VRE <= VRS */
789 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200790
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300791 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
792 Tempax = (Tempbx << 2) & 0xFF;
793 /* SR3F[7:2]:VRE[5:0] */
794 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
795 Tempax = Tempcx >> 8;
796 /* SR35[2:0]:VRS[10:8] */
797 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200798}
799
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200800static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
801{
802 unsigned char temp;
803
804 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
805 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
806 temp = (temp & 3) << 6;
807 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
808 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
809 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
810 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
811
812}
813
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300814static void xgifb_set_lcd(int chip_id,
815 struct vb_device_info *pVBInfo,
816 unsigned short RefreshRateTableIndex,
817 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200818{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300819 unsigned short Data, Temp;
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400820 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530822 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200823
Aaro Koskinen8104e322011-03-13 12:26:22 +0200824 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
825 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
826 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
827 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300828
829 if (chip_id == XG27) {
830 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
831 if ((Temp & 0x03) == 0) { /* dual 12 */
832 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
833 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
834 }
835 }
836
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530837 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200838 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
839 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
840 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
841 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530842 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200843
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300844 if (chip_id == XG27) {
845 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530846 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300847 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
848 if (Temp & 0x01) {
849 /* 18 bits FP */
850 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
851 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
852 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530853 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200854
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200855 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200856
Aaro Koskinendc505562011-03-13 12:26:26 +0200857 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
858 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200859
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300860 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
861 if (Data & 0x4000)
862 /* Hsync polarity */
863 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
864 if (Data & 0x8000)
865 /* Vsync polarity */
866 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200867}
868
869/* --------------------------------------------------------------------- */
870/* Function : XGI_UpdateXG21CRTC */
871/* Input : */
872/* Output : CRT1 CRTC */
873/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
874/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800875static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
876 struct vb_device_info *pVBInfo,
877 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200878{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300879 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200880
Aaro Koskinendc505562011-03-13 12:26:26 +0200881 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300882 if (ModeNo == 0x2E &&
883 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
884 RES640x480x60))
885 index = 12;
886 else if (ModeNo == 0x2E && (pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800887 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300888 index = 13;
889 else if (ModeNo == 0x2F)
890 index = 14;
891 else if (ModeNo == 0x50)
892 index = 15;
893 else if (ModeNo == 0x59)
894 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200895
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530896 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200897 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530898 pVBInfo->UpdateCRT1[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200899 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530900 pVBInfo->UpdateCRT1[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200901 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530902 pVBInfo->UpdateCRT1[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200903 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530904 pVBInfo->UpdateCRT1[index].CR16);
905 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200906}
907
Aaro Koskinen06465962011-11-27 23:03:06 +0200908static unsigned short XGI_GetResInfo(unsigned short ModeNo,
909 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
910{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300911 /* si+Ext_ResInfo */
912 return pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen06465962011-11-27 23:03:06 +0200913}
914
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200915static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530916 unsigned short ModeNo, unsigned short ModeIdIndex,
917 unsigned short RefreshRateTableIndex,
918 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200919{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400920 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200921
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530922 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200923
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530924 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200925
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300926 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
927 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
928 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200929
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530930 if (modeflag & HalfDCLK)
931 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200932
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300933 if (modeflag & HalfDCLK)
934 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200935
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300936 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200937
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300938 if (temp & InterlaceMode)
939 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200940
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300941 if (modeflag & DoubleScanMode)
942 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530944 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200945
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530946 tempax /= tempcx;
947 tempax -= 1;
948 tempbx -= 1;
949 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200950 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
951 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530952 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200953 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
954 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200955 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530956 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200957 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530958 tempax = 0;
959 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200960
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530961 if (tempbx & 0x01)
962 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200963
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530964 if (tempbx & 0x02)
965 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200966
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200967 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200968 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530969 data &= 0xFF;
970 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200971
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530972 if (tempbx & 0x04)
973 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200974
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200975 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200976 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200977}
978
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800979static void XGI_SetCRT1Offset(unsigned short ModeNo,
980 unsigned short ModeIdIndex,
981 unsigned short RefreshRateTableIndex,
982 struct xgi_hw_device_info *HwDeviceExtension,
983 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200984{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530985 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200986
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530987 /* GetOffset */
988 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
989 temp = temp >> 8;
990 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200991
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530992 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
993 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530995 if (temp2)
996 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200997
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530998 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200999
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301000 switch (temp2) {
1001 case 0:
1002 temp2 = 1;
1003 break;
1004 case 1:
1005 temp2 = 2;
1006 break;
1007 case 2:
1008 temp2 = 4;
1009 break;
1010 case 3:
1011 temp2 = 4;
1012 break;
1013 case 4:
1014 temp2 = 6;
1015 break;
1016 case 5:
1017 temp2 = 8;
1018 break;
1019 default:
1020 break;
1021 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001022
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301023 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1024 temp = temp * temp2 + temp2 / 2;
1025 else
1026 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001027
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301028 /* SetOffset */
1029 DisplayUnit = temp;
1030 temp2 = temp;
1031 temp = temp >> 8; /* ah */
1032 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001033 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301034 i &= 0xF0;
1035 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001036 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301038 temp = (unsigned char) temp2;
1039 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +02001040 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001041
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301042 /* SetDisplayUnit */
1043 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1044 temp2 &= InterlaceMode;
1045 if (temp2)
1046 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001047
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301048 DisplayUnit = DisplayUnit << 5;
1049 ah = (DisplayUnit & 0xff00) >> 8;
1050 al = DisplayUnit & 0x00ff;
1051 if (al == 0)
1052 ah += 1;
1053 else
1054 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001055
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301056 if (HwDeviceExtension->jChipType >= XG20)
1057 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1058 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001059
Aaro Koskinen8104e322011-03-13 12:26:22 +02001060 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001061}
1062
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001063static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1064 unsigned short ModeIdIndex,
1065 unsigned short RefreshRateTableIndex,
1066 struct xgi_hw_device_info *HwDeviceExtension,
1067 struct vb_device_info *pVBInfo)
1068{
Peter Huewe6896b942012-02-09 21:11:46 +01001069 unsigned short LCDXlat1VCLK[4] = { VCLK65_315 + 2,
1070 VCLK65_315 + 2,
1071 VCLK65_315 + 2,
1072 VCLK65_315 + 2 };
1073 unsigned short LCDXlat2VCLK[4] = { VCLK108_2_315 + 5,
1074 VCLK108_2_315 + 5,
1075 VCLK108_2_315 + 5,
1076 VCLK108_2_315 + 5 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001077 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
Peter Huewe6896b942012-02-09 21:11:46 +01001078 unsigned short LVDSXlat2VCLK[4] = { VCLK65_315 + 2,
1079 VCLK65_315 + 2,
1080 VCLK65_315 + 2,
1081 VCLK65_315 + 2 };
1082 unsigned short LVDSXlat3VCLK[4] = { VCLK65_315 + 2,
1083 VCLK65_315 + 2,
1084 VCLK65_315 + 2,
1085 VCLK65_315 + 2 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001086
1087 unsigned short CRT2Index, VCLKIndex;
1088 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001089
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001090 /* si+Ext_ResInfo */
1091 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1092 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1093 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001094
1095 if (pVBInfo->IF_DEF_LVDS == 0) {
1096 CRT2Index = CRT2Index >> 6; /* for LCD */
Peter Huewea3d675c2012-02-09 21:11:47 +01001097 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
Peter Huewe255aabd2012-02-09 21:11:44 +01001098 if (pVBInfo->LCDResInfo != Panel_1024x768)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001099 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1100 else
1101 VCLKIndex = LCDXlat1VCLK[CRT2Index];
Peter Huewe599801f2012-02-09 21:11:45 +01001102 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001103 if (pVBInfo->SetFlag & RPLLDIV2XO) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001104 VCLKIndex = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001105 VCLKIndex += 25;
1106 } else {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001107 VCLKIndex = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001108 VCLKIndex += 25;
1109 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001110
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001111 if (pVBInfo->SetFlag & TVSimuMode) {
1112 if (modeflag & Charx8Dot) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001113 VCLKIndex = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001114 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001115 } else {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001116 VCLKIndex = TVCLKBASE_315 + HiTVTextVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001117 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001118 }
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001119 }
1120
1121 /* 301lv */
Peter Huewe6896b942012-02-09 21:11:46 +01001122 if ((pVBInfo->VBType & VB_SIS301LV) &&
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001123 !(pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Peter Huewe6896b942012-02-09 21:11:46 +01001124 if (pVBInfo->VBExtInfo == YPbPr750p)
Peter Huewea3d675c2012-02-09 21:11:47 +01001125 VCLKIndex = XGI_YPbPr750pVCLK;
Peter Huewe6896b942012-02-09 21:11:46 +01001126 else if (pVBInfo->VBExtInfo == YPbPr525p)
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001127 VCLKIndex = YPbPr525pVCLK;
1128 else if (pVBInfo->SetFlag & RPLLDIV2XO)
1129 VCLKIndex = YPbPr525iVCLK_2;
1130 else
1131 VCLKIndex = YPbPr525iVCLK;
1132 }
1133 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
1134 if (pVBInfo->SetFlag & RPLLDIV2XO) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001135 VCLKIndex = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001136 VCLKIndex += 25;
1137 } else {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001138 VCLKIndex = TVCLKBASE_315 + TVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001139 VCLKIndex += 25;
1140 }
1141 } else { /* for CRT2 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001142 /* di+Ext_CRTVCLK */
1143 VCLKIndex = pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001144 Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001145 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001146 }
1147 } else { /* LVDS */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001148 VCLKIndex = CRT2Index;
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001149 VCLKIndex = VCLKIndex >> 6;
Peter Huewe255aabd2012-02-09 21:11:44 +01001150 if ((pVBInfo->LCDResInfo == Panel_800x600) ||
1151 (pVBInfo->LCDResInfo == Panel_320x480))
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001152 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
Peter Huewe255aabd2012-02-09 21:11:44 +01001153 else if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1154 (pVBInfo->LCDResInfo == Panel_1024x768x75))
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001155 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1156 else
1157 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001158 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001159
1160 return VCLKIndex;
1161}
1162
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001163static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1164 unsigned short ModeIdIndex,
1165 struct xgi_hw_device_info *HwDeviceExtension,
1166 unsigned short RefreshRateTableIndex,
1167 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001168{
Bill Pemberton108afbf2010-06-17 13:10:47 -04001169 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301170 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001171
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301172 if (pVBInfo->IF_DEF_LVDS == 1) {
1173 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001174 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001175 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1176 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301177 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001178 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301179 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001180 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +01001181 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1182 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01001183 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301184 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1185 RefreshRateTableIndex, HwDeviceExtension,
1186 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001187 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001188 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301189 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001190 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301191 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001192 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1193 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301194 } else {
1195 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001196 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001197 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1198 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301199 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001200 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301201 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001202 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301203 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301205 if (HwDeviceExtension->jChipType >= XG20) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001206 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1207 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001208 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001209 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001210 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301211 index = data;
1212 index &= 0xE0;
1213 data &= 0x1F;
1214 data = data << 1;
1215 data += 1;
1216 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001217 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301218 }
1219 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001220}
1221
Aaro Koskinene85f2032011-11-27 23:03:07 +02001222static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1223{
1224 unsigned char temp;
1225
1226 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1227 temp = (temp & 1) << 6;
1228 /* SR06[6] 18bit Dither */
1229 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1230 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1231 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1232
1233}
1234
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001235static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301236 struct xgi_hw_device_info *HwDeviceExtension,
1237 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001238{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301239 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001240
Aaro Koskinen58839b02011-03-13 12:26:23 +02001241 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301242 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001243 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001244
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001245 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1246 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1247 data &= 0xC0;
1248 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1249 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1250 data |= 0x01;
1251 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001252
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301253 if (HwDeviceExtension->jChipType == XG21)
1254 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001255}
1256
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001257static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1258 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1259 struct vb_device_info *pVBInfo)
1260{
1261 unsigned short data, data2 = 0;
1262 short VCLK;
1263
1264 unsigned char index;
1265
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001266 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1267 index &= IndexMask;
1268 VCLK = pVBInfo->VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001269
Aaro Koskinen58839b02011-03-13 12:26:23 +02001270 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001271 data &= 0xf3;
1272 if (VCLK >= 200)
1273 data |= 0x0c; /* VCLK > 200 */
1274
1275 if (HwDeviceExtension->jChipType >= XG20)
1276 data &= ~0x04; /* 2 pixel mode */
1277
Aaro Koskinen8104e322011-03-13 12:26:22 +02001278 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001279
1280 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001281 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001282 data &= 0xE7;
1283 if (VCLK < 200)
1284 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001285 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001286 }
1287
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001288 data2 = 0x00;
1289
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001290 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001291 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001292 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001293
1294}
1295
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001296static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301297 unsigned short ModeNo, unsigned short ModeIdIndex,
1298 unsigned short RefreshRateTableIndex,
1299 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001300{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301301 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1302 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001303
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001304 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1305 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001306
Aaro Koskinen58839b02011-03-13 12:26:23 +02001307 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001308 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001309
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001310 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301311 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001312
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001313 if (pVBInfo->ModeType > 0x02) {
1314 data2 |= 0x02;
1315 data3 = pVBInfo->ModeType - ModeVGA;
1316 data3 = data3 << 2;
1317 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301318 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001319
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301320 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001321
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301322 if (data)
1323 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001324
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001325 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301326 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001327 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001328
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301329 data = 0x0000;
1330 if (infoflag & InterlaceMode) {
1331 if (xres == 1024)
1332 data = 0x0035;
1333 else if (xres == 1280)
1334 data = 0x0048;
1335 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001336
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301337 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001338 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301339 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001340 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001341
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301342 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001343 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001344
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301345 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001346
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301347 if (modeflag & LineCompareOff)
1348 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001349
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001350 if (pVBInfo->ModeType == ModeEGA)
1351 data2 |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001352
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001353 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301354 data = 0x60;
1355 if (pVBInfo->ModeType != ModeText) {
1356 data = data ^ 0x60;
1357 if (pVBInfo->ModeType != ModeEGA)
1358 data = data ^ 0xA0;
1359 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001360 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001361
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301362 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1363 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001364
Aaro Koskinen58839b02011-03-13 12:26:23 +02001365 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001366
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301367 if (HwDeviceExtension->jChipType == XG27) {
1368 if (data & 0x40)
1369 data = 0x2c;
1370 else
1371 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001372 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001373 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301374 } else if (HwDeviceExtension->jChipType >= XG20) {
1375 if (data & 0x40)
1376 data = 0x33;
1377 else
1378 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001379 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1380 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301381 } else {
1382 if (data & 0x40)
1383 data = 0x2c;
1384 else
1385 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001386 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301387 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001388
1389}
1390
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001391static void XGI_WriteDAC(unsigned short dl,
1392 unsigned short ah,
1393 unsigned short al,
1394 unsigned short dh,
1395 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001396{
1397 unsigned short temp, bh, bl;
1398
1399 bh = ah;
1400 bl = al;
1401
1402 if (dl != 0) {
1403 temp = bh;
1404 bh = dh;
1405 dh = temp;
1406 if (dl == 1) {
1407 temp = bl;
1408 bl = dh;
1409 dh = temp;
1410 } else {
1411 temp = bl;
1412 bl = bh;
1413 bh = temp;
1414 }
1415 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001416 outb((unsigned short) dh, pVBInfo->P3c9);
1417 outb((unsigned short) bh, pVBInfo->P3c9);
1418 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001419}
1420
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001421static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301422 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001423{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301424 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al,
Aaro Koskinen624554d2011-10-11 21:47:35 +03001425 ah, dh;
1426 const unsigned short *table = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001427
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001428 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301429 data &= DACInfoFlag;
1430 time = 64;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001431
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301432 if (data == 0x00)
1433 table = XGINew_MDA_DAC;
1434 else if (data == 0x08)
1435 table = XGINew_CGA_DAC;
1436 else if (data == 0x10)
1437 table = XGINew_EGA_DAC;
1438 else if (data == 0x18) {
1439 time = 256;
1440 table = XGINew_VGA_DAC;
1441 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001442
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301443 if (time == 256)
1444 j = 16;
1445 else
1446 j = time;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001447
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001448 outb(0xFF, pVBInfo->P3c6);
1449 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001450
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301451 for (i = 0; i < j; i++) {
1452 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001453
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301454 for (k = 0; k < 3; k++) {
1455 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001456
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301457 if (data & 0x01)
1458 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001459
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301460 if (data & 0x02)
1461 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001462
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001463 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301464 data = data >> 2;
1465 }
1466 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001467
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301468 if (time == 256) {
1469 for (i = 16; i < 32; i++) {
1470 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001471
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301472 for (k = 0; k < 3; k++)
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001473 outb(data, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301474 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001475
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301476 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001477
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301478 for (m = 0; m < 9; m++) {
1479 di = si;
1480 bx = si + 0x04;
1481 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001482
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301483 for (n = 0; n < 3; n++) {
1484 for (o = 0; o < 5; o++) {
1485 dh = table[si];
1486 ah = table[di];
1487 al = table[bx];
1488 si++;
1489 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1490 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001491
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301492 si -= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001493
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301494 for (o = 0; o < 3; o++) {
1495 dh = table[bx];
1496 ah = table[di];
1497 al = table[si];
1498 si--;
1499 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1500 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001501
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301502 dl++;
1503 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001504
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301505 si += 5;
1506 }
1507 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001508}
1509
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001510static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1511 unsigned short ModeIdIndex,
1512 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001513{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301514 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001515
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001516 /* si+Ext_ResInfo */
1517 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001518
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001519 /* si+Ext_ResInfo */
1520 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001521
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001522 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1523 yres = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001524
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001525 if (modeflag & HalfDCLK)
1526 xres = xres << 1;
1527
1528 if (modeflag & DoubleScanMode)
1529 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001530
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301531 if (xres == 720)
1532 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001533
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301534 pVBInfo->VGAHDE = xres;
1535 pVBInfo->HDE = xres;
1536 pVBInfo->VGAVDE = yres;
1537 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001538}
1539
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001540static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1541 unsigned short ModeIdIndex,
1542 unsigned short RefreshRateTableIndex,
1543 struct vb_device_info *pVBInfo)
1544{
1545 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1546
1547 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1548
1549 tempbx = BX;
1550
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001551 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1552 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001553
1554 tempal = tempal & 0x0f;
1555
1556 if (tempbx <= 1) { /* ExpLink */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001557 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001558
Peter Huewea3d675c2012-02-09 21:11:47 +01001559 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001560 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001561 Ext_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001562 }
1563
1564 if (tempbx & 0x01)
1565 tempal = (tempal >> 4);
1566
1567 tempal = (tempal & 0x0f);
1568 }
1569
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001570 tempcx = LCDLenList[tempbx];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001571
1572 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1573 if ((tempbx == 5) || (tempbx) == 7)
1574 tempcx = LCDDesDataLen2;
1575 else if ((tempbx == 3) || (tempbx == 8))
1576 tempcx = LVDSDesDataLen2;
1577 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001578
1579 switch (tempbx) {
1580 case 0:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001581 case 1:
Aaro Koskinencc5c2ae2011-08-31 21:46:08 +03001582 tempdi = xgifb_epllcd_crt1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001583 break;
1584 case 2:
1585 tempdi = XGI_EPLLCDDataPtr;
1586 break;
1587 case 3:
1588 tempdi = XGI_EPLLCDDesDataPtr;
1589 break;
1590 case 4:
1591 tempdi = XGI_LCDDataTable;
1592 break;
1593 case 5:
1594 tempdi = XGI_LCDDesDataTable;
1595 break;
1596 case 6:
1597 tempdi = XGI_EPLCHLCDRegPtr;
1598 break;
1599 case 7:
1600 case 8:
1601 case 9:
1602 tempdi = NULL;
1603 break;
1604 default:
1605 break;
1606 }
1607
1608 if (tempdi == NULL) /* OEMUtil */
1609 return NULL;
1610
1611 table = tempbx;
1612 i = 0;
1613
1614 while (tempdi[i].PANELID != 0xff) {
1615 tempdx = pVBInfo->LCDResInfo;
1616 if (tempbx & 0x0080) { /* OEMUtil */
1617 tempbx &= (~0x0080);
1618 tempdx = pVBInfo->LCDTypeInfo;
1619 }
1620
1621 if (pVBInfo->LCDInfo & EnableScalingLCD)
1622 tempdx &= (~PanelResInfo);
1623
1624 if (tempdi[i].PANELID == tempdx) {
1625 tempbx = tempdi[i].MASK;
1626 tempdx = pVBInfo->LCDInfo;
1627
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001628 if (modeflag & HalfDCLK)
1629 tempdx |= SetLCDLowResolution;
1630
1631 tempbx &= tempdx;
1632 if (tempbx == tempdi[i].CAP)
1633 break;
1634 }
1635 i++;
1636 }
1637
1638 if (table == 0) {
1639 switch (tempdi[i].DATAPTR) {
1640 case 0:
1641 return &XGI_LVDSCRT11024x768_1_H[tempal];
1642 break;
1643 case 1:
1644 return &XGI_LVDSCRT11024x768_2_H[tempal];
1645 break;
1646 case 2:
1647 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1648 break;
1649 case 3:
1650 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1651 break;
1652 case 4:
1653 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1654 break;
1655 case 5:
1656 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1657 break;
1658 case 6:
1659 return &XGI_LVDSCRT11600x1200_1_H[tempal];
1660 break;
1661 case 7:
1662 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
1663 break;
1664 case 8:
1665 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
1666 break;
1667 case 9:
1668 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
1669 break;
1670 case 10:
1671 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
1672 break;
1673 default:
1674 break;
1675 }
1676 } else if (table == 1) {
1677 switch (tempdi[i].DATAPTR) {
1678 case 0:
1679 return &XGI_LVDSCRT11024x768_1_V[tempal];
1680 break;
1681 case 1:
1682 return &XGI_LVDSCRT11024x768_2_V[tempal];
1683 break;
1684 case 2:
1685 return &XGI_LVDSCRT11280x1024_1_V[tempal];
1686 break;
1687 case 3:
1688 return &XGI_LVDSCRT11280x1024_2_V[tempal];
1689 break;
1690 case 4:
1691 return &XGI_LVDSCRT11400x1050_1_V[tempal];
1692 break;
1693 case 5:
1694 return &XGI_LVDSCRT11400x1050_2_V[tempal];
1695 break;
1696 case 6:
1697 return &XGI_LVDSCRT11600x1200_1_V[tempal];
1698 break;
1699 case 7:
1700 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
1701 break;
1702 case 8:
1703 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
1704 break;
1705 case 9:
1706 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
1707 break;
1708 case 10:
1709 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
1710 break;
1711 default:
1712 break;
1713 }
1714 } else if (table == 2) {
1715 switch (tempdi[i].DATAPTR) {
1716 case 0:
1717 return &XGI_LVDS1024x768Data_1[tempal];
1718 break;
1719 case 1:
1720 return &XGI_LVDS1024x768Data_2[tempal];
1721 break;
1722 case 2:
1723 return &XGI_LVDS1280x1024Data_1[tempal];
1724 break;
1725 case 3:
1726 return &XGI_LVDS1280x1024Data_2[tempal];
1727 break;
1728 case 4:
1729 return &XGI_LVDS1400x1050Data_1[tempal];
1730 break;
1731 case 5:
1732 return &XGI_LVDS1400x1050Data_2[tempal];
1733 break;
1734 case 6:
1735 return &XGI_LVDS1600x1200Data_1[tempal];
1736 break;
1737 case 7:
1738 return &XGI_LVDSNoScalingData[tempal];
1739 break;
1740 case 8:
1741 return &XGI_LVDS1024x768Data_1x75[tempal];
1742 break;
1743 case 9:
1744 return &XGI_LVDS1024x768Data_2x75[tempal];
1745 break;
1746 case 10:
1747 return &XGI_LVDS1280x1024Data_1x75[tempal];
1748 break;
1749 case 11:
1750 return &XGI_LVDS1280x1024Data_2x75[tempal];
1751 break;
1752 case 12:
1753 return &XGI_LVDSNoScalingDatax75[tempal];
1754 break;
1755 default:
1756 break;
1757 }
1758 } else if (table == 3) {
1759 switch (tempdi[i].DATAPTR) {
1760 case 0:
1761 return &XGI_LVDS1024x768Des_1[tempal];
1762 break;
1763 case 1:
1764 return &XGI_LVDS1024x768Des_3[tempal];
1765 break;
1766 case 2:
1767 return &XGI_LVDS1024x768Des_2[tempal];
1768 break;
1769 case 3:
1770 return &XGI_LVDS1280x1024Des_1[tempal];
1771 break;
1772 case 4:
1773 return &XGI_LVDS1280x1024Des_2[tempal];
1774 break;
1775 case 5:
1776 return &XGI_LVDS1400x1050Des_1[tempal];
1777 break;
1778 case 6:
1779 return &XGI_LVDS1400x1050Des_2[tempal];
1780 break;
1781 case 7:
1782 return &XGI_LVDS1600x1200Des_1[tempal];
1783 break;
1784 case 8:
1785 return &XGI_LVDSNoScalingDesData[tempal];
1786 break;
1787 case 9:
1788 return &XGI_LVDS1024x768Des_1x75[tempal];
1789 break;
1790 case 10:
1791 return &XGI_LVDS1024x768Des_3x75[tempal];
1792 break;
1793 case 11:
1794 return &XGI_LVDS1024x768Des_2x75[tempal];
1795 break;
1796 case 12:
1797 return &XGI_LVDS1280x1024Des_1x75[tempal];
1798 break;
1799 case 13:
1800 return &XGI_LVDS1280x1024Des_2x75[tempal];
1801 break;
1802 case 14:
1803 return &XGI_LVDSNoScalingDesDatax75[tempal];
1804 break;
1805 default:
1806 break;
1807 }
1808 } else if (table == 4) {
1809 switch (tempdi[i].DATAPTR) {
1810 case 0:
1811 return &XGI_ExtLCD1024x768Data[tempal];
1812 break;
1813 case 1:
1814 return &XGI_StLCD1024x768Data[tempal];
1815 break;
1816 case 2:
1817 return &XGI_CetLCD1024x768Data[tempal];
1818 break;
1819 case 3:
1820 return &XGI_ExtLCD1280x1024Data[tempal];
1821 break;
1822 case 4:
1823 return &XGI_StLCD1280x1024Data[tempal];
1824 break;
1825 case 5:
1826 return &XGI_CetLCD1280x1024Data[tempal];
1827 break;
1828 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001829 case 7:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001830 return &xgifb_lcd_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001831 break;
1832 case 8:
1833 return &XGI_CetLCD1400x1050Data[tempal];
1834 break;
1835 case 9:
1836 return &XGI_ExtLCD1600x1200Data[tempal];
1837 break;
1838 case 10:
1839 return &XGI_StLCD1600x1200Data[tempal];
1840 break;
1841 case 11:
1842 return &XGI_NoScalingData[tempal];
1843 break;
1844 case 12:
1845 return &XGI_ExtLCD1024x768x75Data[tempal];
1846 break;
1847 case 13:
1848 return &XGI_ExtLCD1024x768x75Data[tempal];
1849 break;
1850 case 14:
1851 return &XGI_CetLCD1024x768x75Data[tempal];
1852 break;
1853 case 15:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001854 case 16:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001855 return &xgifb_lcd_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001856 break;
1857 case 17:
1858 return &XGI_CetLCD1280x1024x75Data[tempal];
1859 break;
1860 case 18:
1861 return &XGI_NoScalingDatax75[tempal];
1862 break;
1863 default:
1864 break;
1865 }
1866 } else if (table == 5) {
1867 switch (tempdi[i].DATAPTR) {
1868 case 0:
1869 return &XGI_ExtLCDDes1024x768Data[tempal];
1870 break;
1871 case 1:
1872 return &XGI_StLCDDes1024x768Data[tempal];
1873 break;
1874 case 2:
1875 return &XGI_CetLCDDes1024x768Data[tempal];
1876 break;
1877 case 3:
Peter Huewe6896b942012-02-09 21:11:46 +01001878 if ((pVBInfo->VBType & VB_SIS301LV) ||
1879 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001880 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
1881 else
1882 return &XGI_ExtLCDDes1280x1024Data[tempal];
1883 break;
1884 case 4:
Peter Huewe6896b942012-02-09 21:11:46 +01001885 if ((pVBInfo->VBType & VB_SIS301LV) ||
1886 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001887 return &XGI_StLCDDLDes1280x1024Data[tempal];
1888 else
1889 return &XGI_StLCDDes1280x1024Data[tempal];
1890 break;
1891 case 5:
Peter Huewe6896b942012-02-09 21:11:46 +01001892 if ((pVBInfo->VBType & VB_SIS301LV) ||
1893 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001894 return &XGI_CetLCDDLDes1280x1024Data[tempal];
1895 else
1896 return &XGI_CetLCDDes1280x1024Data[tempal];
1897 break;
1898 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001899 case 7:
Peter Huewe6896b942012-02-09 21:11:46 +01001900 if ((pVBInfo->VBType & VB_SIS301LV) ||
1901 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001902 return &xgifb_lcddldes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001903 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001904 return &xgifb_lcddes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001905 break;
1906 case 8:
1907 return &XGI_CetLCDDes1400x1050Data[tempal];
1908 break;
1909 case 9:
1910 return &XGI_CetLCDDes1400x1050Data2[tempal];
1911 break;
1912 case 10:
Peter Huewe6896b942012-02-09 21:11:46 +01001913 if ((pVBInfo->VBType & VB_SIS301LV) ||
1914 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001915 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
1916 else
1917 return &XGI_ExtLCDDes1600x1200Data[tempal];
1918 break;
1919 case 11:
Peter Huewe6896b942012-02-09 21:11:46 +01001920 if ((pVBInfo->VBType & VB_SIS301LV) ||
1921 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001922 return &XGI_StLCDDLDes1600x1200Data[tempal];
1923 else
1924 return &XGI_StLCDDes1600x1200Data[tempal];
1925 break;
1926 case 12:
1927 return &XGI_NoScalingDesData[tempal];
1928 break;
1929 case 13:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001930 case 14:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001931 return &xgifb_lcddes_1024x768x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001932 break;
1933 case 15:
1934 return &XGI_CetLCDDes1024x768x75Data[tempal];
1935 break;
1936 case 16:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001937 case 17:
Peter Huewe6896b942012-02-09 21:11:46 +01001938 if ((pVBInfo->VBType & VB_SIS301LV) ||
1939 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001940 return &xgifb_lcddldes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001941 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001942 return &xgifb_lcddes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001943 break;
1944 case 18:
Peter Huewe6896b942012-02-09 21:11:46 +01001945 if ((pVBInfo->VBType & VB_SIS301LV) ||
1946 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001947 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
1948 else
1949 return &XGI_CetLCDDes1280x1024x75Data[tempal];
1950 break;
1951 case 19:
1952 return &XGI_NoScalingDesDatax75[tempal];
1953 break;
1954 default:
1955 break;
1956 }
1957 } else if (table == 6) {
1958 switch (tempdi[i].DATAPTR) {
1959 case 0:
1960 return &XGI_CH7017LV1024x768[tempal];
1961 break;
1962 case 1:
1963 return &XGI_CH7017LV1400x1050[tempal];
1964 break;
1965 default:
1966 break;
1967 }
1968 }
1969 return NULL;
1970}
1971
1972static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
1973 unsigned short ModeIdIndex,
1974 unsigned short RefreshRateTableIndex,
1975 struct vb_device_info *pVBInfo)
1976{
1977 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
1978 struct XGI330_TVDataTablStruct *tempdi = NULL;
1979
1980 tempbx = BX;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001981 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1982 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001983 tempal = tempal & 0x3f;
1984 table = tempbx;
1985
1986 switch (tempbx) {
1987 case 0:
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001988 tempdi = NULL;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001989 break;
1990 case 1:
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001991 tempdi = NULL;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001992 break;
1993 case 2:
Aaro Koskinen0c23b6d2011-08-31 21:46:09 +03001994 case 6:
1995 tempdi = xgifb_chrontel_tv;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001996 break;
1997 case 3:
1998 tempdi = NULL;
1999 break;
2000 case 4:
2001 tempdi = XGI_TVDataTable;
2002 break;
2003 case 5:
2004 tempdi = NULL;
2005 break;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002006 default:
2007 break;
2008 }
2009
2010 if (tempdi == NULL) /* OEMUtil */
2011 return NULL;
2012
2013 tempdx = pVBInfo->TVInfo;
2014
2015 if (pVBInfo->VBInfo & SetInSlaveMode)
2016 tempdx = tempdx | SetTVLockMode;
2017
2018 if (modeflag & HalfDCLK)
2019 tempdx = tempdx | SetTVLowResolution;
2020
2021 i = 0;
2022
2023 while (tempdi[i].MASK != 0xffff) {
2024 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2025 break;
2026 i++;
2027 }
2028
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002029 /* 07/05/22 */
Aaro Koskinenebe33022011-11-27 23:03:18 +02002030 if (table == 0x04) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002031 switch (tempdi[i].DATAPTR) {
2032 case 0:
2033 return &XGI_ExtPALData[tempal];
2034 break;
2035 case 1:
2036 return &XGI_ExtNTSCData[tempal];
2037 break;
2038 case 2:
2039 return &XGI_StPALData[tempal];
2040 break;
2041 case 3:
2042 return &XGI_StNTSCData[tempal];
2043 break;
2044 case 4:
2045 return &XGI_ExtHiTVData[tempal];
2046 break;
2047 case 5:
2048 return &XGI_St2HiTVData[tempal];
2049 break;
2050 case 6:
2051 return &XGI_ExtYPbPr525iData[tempal];
2052 break;
2053 case 7:
2054 return &XGI_ExtYPbPr525pData[tempal];
2055 break;
2056 case 8:
2057 return &XGI_ExtYPbPr750pData[tempal];
2058 break;
2059 case 9:
2060 return &XGI_StYPbPr525iData[tempal];
2061 break;
2062 case 10:
2063 return &XGI_StYPbPr525pData[tempal];
2064 break;
2065 case 11:
2066 return &XGI_StYPbPr750pData[tempal];
2067 break;
2068 case 12: /* avoid system hang */
2069 return &XGI_ExtNTSCData[tempal];
2070 break;
2071 case 13:
2072 return &XGI_St1HiTVData[tempal];
2073 break;
2074 default:
2075 break;
2076 }
2077 } else if (table == 0x02) {
2078 switch (tempdi[i].DATAPTR) {
2079 case 0:
2080 return &XGI_CHTVUNTSCData[tempal];
2081 break;
2082 case 1:
2083 return &XGI_CHTVONTSCData[tempal];
2084 break;
2085 case 2:
2086 return &XGI_CHTVUPALData[tempal];
2087 break;
2088 case 3:
2089 return &XGI_CHTVOPALData[tempal];
2090 break;
2091 default:
2092 break;
2093 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002094 }
2095 return NULL;
2096}
2097
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002098static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302099 unsigned short RefreshRateTableIndex,
2100 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002101{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302102 unsigned short tempbx;
2103 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302105 tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002106
Peter Huewea3d675c2012-02-09 21:11:47 +01002107 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302108 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2109 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2110 pVBInfo);
2111 pVBInfo->VGAHT = LCDPtr->VGAHT;
2112 pVBInfo->VGAVT = LCDPtr->VGAVT;
2113 pVBInfo->HT = LCDPtr->LCDHT;
2114 pVBInfo->VT = LCDPtr->LCDVT;
2115 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002116
Peter Huewea3d675c2012-02-09 21:11:47 +01002117 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302118 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2119 | EnableScalingLCD))) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002120 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
2121 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302122 pVBInfo->HDE = 1024;
2123 pVBInfo->VDE = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002124 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
2125 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302126 pVBInfo->HDE = 1280;
2127 pVBInfo->VDE = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002128 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302129 pVBInfo->HDE = 1400;
2130 pVBInfo->VDE = 1050;
2131 } else {
2132 pVBInfo->HDE = 1600;
2133 pVBInfo->VDE = 1200;
2134 }
2135 }
2136 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002137}
2138
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002139static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302140 unsigned short RefreshRateTableIndex,
2141 struct xgi_hw_device_info *HwDeviceExtension,
2142 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002143{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302144 unsigned char index;
2145 unsigned short tempbx, i;
2146 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2147 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002148
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002149 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302150 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002151
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002152 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002153
Peter Huewea3d675c2012-02-09 21:11:47 +01002154 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002155 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2156 XGI_GetLcdPtr(tempbx, ModeNo,
2157 ModeIdIndex,
2158 RefreshRateTableIndex,
2159 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002160
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002161 for (i = 0; i < 8; i++)
2162 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302163 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002164
2165 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
2166
2167 tempbx = 1;
2168
Peter Huewea3d675c2012-02-09 21:11:47 +01002169 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002170 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2171 XGI_GetLcdPtr(
2172 tempbx,
2173 ModeNo,
2174 ModeIdIndex,
2175 RefreshRateTableIndex,
2176 pVBInfo);
2177 for (i = 0; i < 7; i++)
2178 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2179 }
2180
2181 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002182}
2183
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002184static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2185{
2186 unsigned char tempal, tempah, tempbl, i;
2187
Aaro Koskinen58839b02011-03-13 12:26:23 +02002188 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002189 tempal = tempah & 0x0F;
2190 tempah = tempah & 0xF0;
2191 i = 0;
2192 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2193
2194 while (tempbl != 0xFF) {
2195 if (tempbl & 0x80) { /* OEMUtil */
2196 tempal = tempah;
2197 tempbl = tempbl & ~(0x80);
2198 }
2199
2200 if (tempal == tempbl)
2201 break;
2202
2203 i++;
2204
2205 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2206 }
2207
2208 return i;
2209}
2210
2211static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2212{
2213 unsigned short tempah, tempal, tempbl, i;
2214
2215 tempal = pVBInfo->LCDResInfo;
2216 tempah = pVBInfo->LCDTypeInfo;
2217
2218 i = 0;
2219 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2220
2221 while (tempbl != 0xFF) {
2222 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2223 tempal = tempah;
2224 tempbl &= ~0x80;
2225 }
2226
2227 if (tempal == tempbl)
2228 break;
2229
2230 i++;
2231 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2232 }
2233
2234 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002235 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002236 pVBInfo->LCDTypeInfo = 0;
2237 i = 0;
2238 }
2239
2240 return i;
2241}
2242
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002243static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2244 unsigned short *VSyncWidth,
2245 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002246{
2247 unsigned short Index;
2248
2249 Index = XGI_GetLCDCapPtr(pVBInfo);
2250 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2251 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2252
2253 return;
2254}
2255
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002256static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302257 unsigned short RefreshRateTableIndex,
2258 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002259{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302260 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2261 unsigned long temp, temp1, temp2, temp3, push3;
2262 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2263 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002264
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002265 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen66cface2011-08-31 21:46:13 +03002266 tempbx = 3;
2267 if (pVBInfo->LCDInfo & EnableScalingLCD)
2268 LCDPtr1 =
2269 (struct XGI330_LCDDataDesStruct2 *)
2270 XGI_GetLcdPtr(
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002271 tempbx,
2272 ModeNo,
2273 ModeIdIndex,
2274 RefreshRateTableIndex,
2275 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03002276 else
2277 LCDPtr =
2278 (struct XGI330_LCDDataDesStruct *)
2279 XGI_GetLcdPtr(
2280 tempbx,
2281 ModeNo,
2282 ModeIdIndex,
2283 RefreshRateTableIndex,
2284 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002285
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002286 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2287 push1 = tempbx;
2288 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002289
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002290 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01002291 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
2292 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002293 tempax = 1024;
2294 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002295 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
2296 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002297 tempax = 1280;
2298 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002299 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002300 tempax = 1400;
2301 tempbx = 1050;
2302 } else {
2303 tempax = 1600;
2304 tempbx = 1200;
2305 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002306
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002307 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2308 pVBInfo->HDE = tempax;
2309 pVBInfo->VDE = tempbx;
2310 pVBInfo->VGAHDE = tempax;
2311 pVBInfo->VGAVDE = tempbx;
2312 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002313
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002314 tempax = pVBInfo->HT;
2315
2316 if (pVBInfo->LCDInfo & EnableScalingLCD)
2317 tempbx = LCDPtr1->LCDHDES;
2318 else
2319 tempbx = LCDPtr->LCDHDES;
2320
2321 tempcx = pVBInfo->HDE;
2322 tempbx = tempbx & 0x0fff;
2323 tempcx += tempbx;
2324
2325 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002326 tempcx -= tempax;
2327
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002328 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002329
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002330 tempcx = tempcx >> 3;
2331 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002332
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002333 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2334 (unsigned short) (tempbx & 0xff));
2335 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2336 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002337
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002338 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002339
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002340 if (pVBInfo->LCDInfo & EnableScalingLCD)
2341 tempbx = LCDPtr1->LCDHRS;
2342 else
2343 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002344
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002345 tempcx = push2;
2346
2347 if (pVBInfo->LCDInfo & EnableScalingLCD)
2348 tempcx = LCDPtr1->LCDHSync;
2349
2350 tempcx += tempbx;
2351
2352 if (tempcx >= tempax)
2353 tempcx -= tempax;
2354
2355 tempax = tempbx & 0x07;
2356 tempax = tempax >> 5;
2357 tempcx = tempcx >> 3;
2358 tempbx = tempbx >> 3;
2359
2360 tempcx &= 0x1f;
2361 tempax |= tempcx;
2362
2363 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2364 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2365 (unsigned short) (tempbx & 0xff));
2366
2367 tempax = pVBInfo->VT;
2368 if (pVBInfo->LCDInfo & EnableScalingLCD)
2369 tempbx = LCDPtr1->LCDVDES;
2370 else
2371 tempbx = LCDPtr->LCDVDES;
2372 tempcx = pVBInfo->VDE;
2373
2374 tempbx = tempbx & 0x0fff;
2375 tempcx += tempbx;
2376 if (tempcx >= tempax)
2377 tempcx -= tempax;
2378
2379 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2380 (unsigned short) (tempbx & 0xff));
2381 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2382 (unsigned short) (tempcx & 0xff));
2383
2384 tempbx = (tempbx >> 8) & 0x07;
2385 tempcx = (tempcx >> 8) & 0x07;
2386
2387 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2388 (unsigned short) ((tempcx << 3)
2389 | tempbx));
2390
2391 tempax = pVBInfo->VT;
2392 if (pVBInfo->LCDInfo & EnableScalingLCD)
2393 tempbx = LCDPtr1->LCDVRS;
2394 else
2395 tempbx = LCDPtr->LCDVRS;
2396
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002397 tempcx = push1;
2398
2399 if (pVBInfo->LCDInfo & EnableScalingLCD)
2400 tempcx = LCDPtr1->LCDVSync;
2401
2402 tempcx += tempbx;
2403 if (tempcx >= tempax)
2404 tempcx -= tempax;
2405
2406 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2407 (unsigned short) (tempbx & 0xff));
2408 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2409 (unsigned short) (tempcx & 0x0f));
2410
2411 tempax = ((tempbx >> 8) & 0x07) << 3;
2412
2413 tempbx = pVBInfo->VGAVDE;
2414 if (tempbx != pVBInfo->VDE)
2415 tempax |= 0x40;
2416
Peter Huewea3d675c2012-02-09 21:11:47 +01002417 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002418 tempax |= 0x40;
2419
2420 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2421 tempax);
2422
2423 tempcx = pVBInfo->VGAVT;
2424 tempbx = pVBInfo->VDE;
2425 tempax = pVBInfo->VGAVDE;
2426 tempcx -= tempax;
2427
2428 temp = tempax; /* 0430 ylshieh */
2429 temp1 = (temp << 18) / tempbx;
2430
2431 tempdx = (unsigned short) ((temp << 18) % tempbx);
2432
2433 if (tempdx != 0)
2434 temp1 += 1;
2435
2436 temp2 = temp1;
2437 push3 = temp2;
2438
2439 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2440 (unsigned short) (temp2 & 0xff));
2441 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2442 (unsigned short) ((temp2 >> 8) & 0xff));
2443
2444 tempbx = (unsigned short) (temp2 >> 16);
2445 tempax = tempbx & 0x03;
2446
2447 tempbx = pVBInfo->VGAVDE;
2448 if (tempbx == pVBInfo->VDE)
2449 tempax |= 0x04;
2450
2451 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2452
2453 if (pVBInfo->VBType & VB_XGI301C) {
2454 temp2 = push3;
2455 xgifb_reg_set(pVBInfo->Part4Port,
2456 0x3c,
2457 (unsigned short) (temp2 & 0xff));
2458 xgifb_reg_set(pVBInfo->Part4Port,
2459 0x3b,
2460 (unsigned short) ((temp2 >> 8) &
2461 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002462 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002463 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2464 ~0xc0,
2465 (unsigned short) ((tempbx &
2466 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002467
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002468 tempcx = pVBInfo->VGAVDE;
2469 if (tempcx == pVBInfo->VDE)
2470 xgifb_reg_and_or(pVBInfo->Part4Port,
2471 0x30, ~0x0c, 0x00);
2472 else
2473 xgifb_reg_and_or(pVBInfo->Part4Port,
2474 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302475 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002476
2477 tempcx = pVBInfo->VGAHDE;
2478 tempbx = pVBInfo->HDE;
2479
2480 temp1 = tempcx << 16;
2481
2482 tempax = (unsigned short) (temp1 / tempbx);
2483
2484 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2485 tempax = 65535;
2486
2487 temp3 = tempax;
2488 temp1 = pVBInfo->VGAHDE << 16;
2489
2490 temp1 /= temp3;
2491 temp3 = temp3 << 16;
2492 temp1 -= 1;
2493
2494 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2495
2496 tempax = (unsigned short) (temp3 & 0xff);
2497 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2498
2499 temp1 = pVBInfo->VGAVDE << 18;
2500 temp1 = temp1 / push3;
2501 tempbx = (unsigned short) (temp1 & 0xffff);
2502
Peter Huewe255aabd2012-02-09 21:11:44 +01002503 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002504 tempbx -= 1;
2505
2506 tempax = ((tempbx >> 8) & 0xff) << 3;
2507 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2508 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2509 (unsigned short) (tempax & 0xff));
2510 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2511 (unsigned short) (tempbx & 0xff));
2512
2513 temp3 = temp3 >> 16;
2514
2515 if (modeflag & HalfDCLK)
2516 temp3 = temp3 >> 1;
2517
2518 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2519 (unsigned short) ((temp3 >> 8) & 0xff));
2520 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2521 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002522}
2523
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002524/* --------------------------------------------------------------------- */
2525/* Function : XGI_GETLCDVCLKPtr */
2526/* Input : */
2527/* Output : al -> VCLK Index */
2528/* Description : */
2529/* --------------------------------------------------------------------- */
2530static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2531 struct vb_device_info *pVBInfo)
2532{
2533 unsigned short index;
2534
Peter Huewea3d675c2012-02-09 21:11:47 +01002535 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002536 index = XGI_GetLCDCapPtr1(pVBInfo);
2537
2538 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2539 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2540 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2541 } else { /* LCDA */
2542 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2543 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2544 }
2545 }
2546 return;
2547}
2548
2549static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2550 unsigned short ModeNo, unsigned short ModeIdIndex,
2551 struct vb_device_info *pVBInfo)
2552{
2553
2554 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002555 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002556
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002557 /* si+Ext_ResInfo */
2558 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002559
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002560 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2561 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002562 index = XGI_GetLCDCapPtr(pVBInfo);
2563 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2564
Peter Huewea3d675c2012-02-09 21:11:47 +01002565 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002566 return tempal;
2567
2568 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002569 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002570 (VB_SIS301B |
2571 VB_SIS302B |
2572 VB_SIS301LV |
2573 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002574 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01002575 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002576 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002577 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002578 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002579 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002580 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002581 if (!(modeflag & Charx8Dot))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002582 tempal = TVCLKBASE_315 + HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002583
2584 }
2585 return tempal;
2586 }
2587
Peter Huewe599801f2012-02-09 21:11:45 +01002588 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002589 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002590 return tempal;
2591 }
2592
Peter Huewe599801f2012-02-09 21:11:45 +01002593 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002594 tempal = YPbPr525pVCLK;
2595 return tempal;
2596 }
2597
2598 tempal = NTSC1024VCLK;
2599
2600 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002601 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002602 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002603 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002604 }
2605
2606 if (pVBInfo->VBInfo & SetCRT2ToTV)
2607 return tempal;
2608 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002609 } /* {End of VB} */
2610
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002611 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002612 tempal = tempal >> 2;
2613 tempal &= 0x03;
2614
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002615 /* for Dot8 Scaling LCD */
2616 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002617 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2618
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002619 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2620 return tempal;
2621}
2622
2623static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
2624 unsigned char *di_1, struct vb_device_info *pVBInfo)
2625{
Peter Huewe6896b942012-02-09 21:11:46 +01002626 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
2627 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002628 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) && (pVBInfo->SetFlag
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002629 & ProgrammingCRT2)) {
2630 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
2631 *di_1 = XGI_VBVCLKData[tempal].SR2C;
2632 }
2633 } else {
2634 *di_0 = XGI_VCLKData[tempal].SR2B;
2635 *di_1 = XGI_VCLKData[tempal].SR2C;
2636 }
2637}
2638
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002639static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302640 unsigned short RefreshRateTableIndex,
2641 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002642{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302643 unsigned char di_0, di_1, tempal;
2644 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302646 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2647 pVBInfo);
2648 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2649 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002650
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302651 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002652 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302653 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01002654 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302655 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02002656 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
2657 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302658 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02002659 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
2660 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302661 }
2662 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002663}
2664
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002665static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302666 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002667{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302668 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002669
Peter Huewe6896b942012-02-09 21:11:46 +01002670 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
2671 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302672 tempcl = 0;
2673 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002674 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002675
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302676 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002677 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302678 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002679 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302680 if (!(temp & 0x40))
2681 tempcl |= ActiveCRT1;
2682 }
2683 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002684
Aaro Koskinen58839b02011-03-13 12:26:23 +02002685 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302686 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002687
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302688 if (!(temp == 0x08)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002689 /* Check ChannelA by Part1_13 [2003/10/03] */
2690 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302691 if (tempax & 0x04)
2692 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002693
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302694 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002695
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302696 if (!(tempcl & ActiveLCD))
2697 if (temp == 0x01)
2698 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002699
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302700 if (temp == 0x04)
2701 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002702
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302703 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002704 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002705
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302706 if (!(temp & 0x08))
2707 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002708
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302709 if (!(temp & 0x04))
2710 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302712 if (temp & 0x02)
2713 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002714
Peter Huewe599801f2012-02-09 21:11:45 +01002715 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302716 if (temp & 0x01)
2717 tempch |= ActiveHiTV;
2718 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002719
Peter Huewe599801f2012-02-09 21:11:45 +01002720 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002721 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302722 pVBInfo->Part2Port,
2723 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002724
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302725 if (temp & 0x10)
2726 tempch |= ActiveYPbPr;
2727 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002728
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302729 if (tempch != 0)
2730 tempcl |= ActiveTV;
2731 }
2732 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002733
Aaro Koskinen58839b02011-03-13 12:26:23 +02002734 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302735 if (tempcl & ActiveLCD) {
2736 if ((pVBInfo->SetFlag & ReserveTVOption)) {
2737 if (temp & ActiveTV)
2738 tempcl |= ActiveTV;
2739 }
2740 }
2741 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01002742 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002743 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002744
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302745 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02002746 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302747 } else {
2748 return;
2749 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002750}
2751
Bill Pemberton80adad82010-06-17 13:10:51 -04002752void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002753{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302754 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002755
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302756 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002757 tempbx = VB_SIS302B;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002758 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302759 if (flag != 0x02) {
Peter Huewe6896b942012-02-09 21:11:46 +01002760 tempbx = VB_SIS301;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002761 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302762 if (flag >= 0xB0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002763 tempbx = VB_SIS301B;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302764 if (flag >= 0xC0) {
2765 tempbx = VB_XGI301C;
2766 if (flag >= 0xD0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002767 tempbx = VB_SIS301LV;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302768 if (flag >= 0xE0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002769 tempbx = VB_SIS302LV;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002770 tempah = xgifb_reg_get(
2771 pVBInfo->Part4Port,
2772 0x39);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302773 if (tempah != 0xFF)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002774 tempbx =
2775 VB_XGI301C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302776 }
2777 }
2778 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002779
Peter Huewe6896b942012-02-09 21:11:46 +01002780 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002781 flag = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302782 pVBInfo->Part4Port,
2783 0x23);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002784
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302785 if (!(flag & 0x02))
2786 tempbx = tempbx | VB_NoLCD;
2787 }
2788 }
2789 }
2790 pVBInfo->VBType = tempbx;
2791 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002792}
2793
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002794static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302795 struct xgi_hw_device_info *HwDeviceExtension,
2796 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002797{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302798 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002799
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002800 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302801 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01002802 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302803 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002804
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302805 if (pVBInfo->VBType & 0xFFFF) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002806 /* Check Display Device */
2807 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302808 tempbx = tempbx | temp;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002809 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302810 push = temp;
2811 push = push << 8;
2812 tempax = temp << 8;
2813 tempbx = tempbx | tempax;
Peter Huewea3d675c2012-02-09 21:11:47 +01002814 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302815 | SetInSlaveMode | DisableCRT2Display);
2816 temp = 0xFFFF ^ temp;
2817 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002818
Aaro Koskinen58839b02011-03-13 12:26:23 +02002819 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302821 if (pVBInfo->IF_DEF_LCDA == 1) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002822
Aaro Koskinen9ffc7e92011-11-27 23:03:14 +02002823 if ((HwDeviceExtension->jChipType >= XG20) ||
2824 (HwDeviceExtension->jChipType >= XG40)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302825 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002826 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002827 (VB_SIS302B |
2828 VB_SIS301LV |
2829 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002830 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302831 if (temp & EnableDualEdge) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002832 tempbx |=
2833 SetCRT2ToDualEdge;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002834
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302835 if (temp & SetToLCDA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002836 tempbx |=
Peter Huewea3d675c2012-02-09 21:11:47 +01002837 XGI_SetCRT2ToLCDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302838 }
2839 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302840 }
2841 }
2842 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002843
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302844 if (pVBInfo->IF_DEF_YPbPr == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002845 /* [Billy] 07/05/04 */
2846 if (((pVBInfo->IF_DEF_LVDS == 0) &&
Peter Huewe6896b942012-02-09 21:11:46 +01002847 ((pVBInfo->VBType & VB_SIS301LV) ||
2848 (pVBInfo->VBType & VB_SIS302LV) ||
Aaro Koskinen83f76a92011-08-31 21:45:58 +03002849 (pVBInfo->VBType & VB_XGI301C)))) {
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02002850 if (temp & SetYPbPr) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302851 if (pVBInfo->IF_DEF_HiVision == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002852 /* shampoo add for new
2853 * scratch */
Aaro Koskinen58839b02011-03-13 12:26:23 +02002854 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302855 pVBInfo->P3d4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002856 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302857 temp &= YPbPrMode;
Peter Huewe599801f2012-02-09 21:11:45 +01002858 tempbx |= SetCRT2ToHiVision;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002859
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302860 if (temp != YPbPrMode1080i) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002861 tempbx &=
Peter Huewe599801f2012-02-09 21:11:45 +01002862 (~SetCRT2ToHiVision);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002863 tempbx |=
Peter Huewe599801f2012-02-09 21:11:45 +01002864 SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302865 }
2866 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302867 }
2868 }
2869 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002870
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302871 tempax = push; /* restore CR31 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002872
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302873 if (pVBInfo->IF_DEF_LVDS == 0) {
2874 if (pVBInfo->IF_DEF_YPbPr == 1) {
2875 if (pVBInfo->IF_DEF_HiVision == 1)
2876 temp = 0x09FC;
2877 else
2878 temp = 0x097C;
2879 } else {
2880 if (pVBInfo->IF_DEF_HiVision == 1)
2881 temp = 0x01FC;
2882 else
2883 temp = 0x017C;
2884 }
2885 } else { /* 3nd party chip */
Aaro Koskinen83f76a92011-08-31 21:45:58 +03002886 temp = SetCRT2ToLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302887 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002888
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302889 if (!(tempbx & temp)) {
2890 tempax |= DisableCRT2Display;
2891 tempbx = 0;
2892 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002893
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302894 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
2895 if (!(pVBInfo->VBType & VB_NoLCD)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002896 if (tempbx & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302897 if (tempbx & SetSimuScanMode)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002898 tempbx &= (~(SetCRT2ToLCD |
2899 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002900 SwitchCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302901 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002902 tempbx &= (~(SetCRT2ToLCD |
2903 SetCRT2ToRAMDAC |
2904 SetCRT2ToTV |
Peter Huewe6896b942012-02-09 21:11:46 +01002905 SwitchCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302906 }
2907 }
2908 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002909
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302910 /* shampoo add */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002911 /* for driver abnormal */
Peter Huewe6896b942012-02-09 21:11:46 +01002912 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302913 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2914 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002915 tempbx &= (0xFF00 |
2916 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002917 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002918 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002919 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302920 }
2921 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002922 tempbx &= (~(SetCRT2ToRAMDAC |
2923 SetCRT2ToLCD |
2924 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302925 }
2926 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002927
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302928 if (!(pVBInfo->VBType & VB_NoLCD)) {
2929 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002930 tempbx &= (0xFF00 |
2931 SetCRT2ToLCD |
Peter Huewe6896b942012-02-09 21:11:46 +01002932 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002933 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002934 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302935 }
2936 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002937
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302938 if (tempbx & SetCRT2ToSCART) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002939 tempbx &= (0xFF00 |
2940 SetCRT2ToSCART |
Peter Huewe6896b942012-02-09 21:11:46 +01002941 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002942 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002943 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302944 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002945
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302946 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002947 if (tempbx & SetCRT2ToYPbPr525750)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002948 tempbx &= (0xFF00 |
Peter Huewe6896b942012-02-09 21:11:46 +01002949 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002950 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302951 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002952
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302953 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002954 if (tempbx & SetCRT2ToHiVision)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002955 tempbx &= (0xFF00 |
Peter Huewe599801f2012-02-09 21:11:45 +01002956 SetCRT2ToHiVision |
Peter Huewe6896b942012-02-09 21:11:46 +01002957 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002958 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302959 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002960
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302961 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
Peter Huewe6896b942012-02-09 21:11:46 +01002962 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302963 tempbx = DisableCRT2Display;
2964 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302966 if (!(tempbx & DisableCRT2Display)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002967 if ((!(tempbx & DriverMode)) ||
2968 (!(modeflag & CRT2Mode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302969 if (pVBInfo->IF_DEF_LCDA == 1) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002970 if (!(tempbx & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002971 tempbx |= (SetInSlaveMode |
2972 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302973 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302974 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002975
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002976 /* LCD+TV can't support in slave mode
2977 * (Force LCDA+TV->LCDB) */
2978 if ((tempbx & SetInSlaveMode) &&
Peter Huewea3d675c2012-02-09 21:11:47 +01002979 (tempbx & XGI_SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002980 tempbx ^= (SetCRT2ToLCD |
Peter Huewea3d675c2012-02-09 21:11:47 +01002981 XGI_SetCRT2ToLCDA |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002982 SetCRT2ToDualEdge);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302983 pVBInfo->SetFlag |= ReserveTVOption;
2984 }
2985 }
2986 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002987
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302988 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002989}
2990
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002991static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302992 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002993{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302994 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002995
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302996 tempbx = 0;
2997 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002998
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302999 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003000 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3001 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003002
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303003 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003004 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303005 tempbx = temp;
Peter Huewe599801f2012-02-09 21:11:45 +01003006 if (tempbx & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003007 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01003008 TVSetPALM |
3009 TVSetPALN |
3010 TVSetPAL);
3011 if (tempbx & TVSetPALM)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003012 /* set to NTSC if PAL-M */
Peter Huewe599801f2012-02-09 21:11:45 +01003013 tempbx &= ~TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303014 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003015 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01003016 TVSetNTSCJ |
3017 TVSetPAL);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303018 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003019
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303020 if (pVBInfo->IF_DEF_LVDS == 0) {
3021 if (pVBInfo->VBInfo & SetCRT2ToSCART)
Peter Huewe599801f2012-02-09 21:11:45 +01003022 tempbx |= TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303023 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303025 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01003026 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003027 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303028 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303030 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01003031 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003032
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303033 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01003034 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303035 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01003036 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303037 }
3038 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303040 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01003041 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
3042 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303043 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303045 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003046 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3047 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303048 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003049
Peter Huewe599801f2012-02-09 21:11:45 +01003050 if (!(tempbx & TVSetPAL) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003051 (modeflag > 13) &&
3052 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303053 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303055 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003056
Peter Huewe599801f2012-02-09 21:11:45 +01003057 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303058 if (pVBInfo->VBInfo & SetInSlaveMode)
3059 tempbx &= (~RPLLDIV2XO);
3060 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003061 if (tempbx &
Peter Huewe599801f2012-02-09 21:11:45 +01003062 (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303063 tempbx &= (~RPLLDIV2XO);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003064 else if (!(pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003065 (VB_SIS301B |
3066 VB_SIS302B |
3067 VB_SIS301LV |
3068 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003069 VB_XGI301C))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303070 if (tempbx & TVSimuMode)
3071 tempbx &= (~RPLLDIV2XO);
3072 }
3073 }
3074 }
3075 }
3076 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003077}
3078
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02003079static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
3080 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003081{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303082 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303084 pVBInfo->LCDResInfo = 0;
3085 pVBInfo->LCDTypeInfo = 0;
3086 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003087
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003088 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3089 /* si+Ext_ResInfo // */
3090 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003091 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303092 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003093
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303094 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01003095 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003096
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303097 /* LCD75 [2003/8/22] Vicent */
Peter Huewe255aabd2012-02-09 21:11:44 +01003098 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303099 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003100 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01003101 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303102 tempax &= 0x0F;
3103 else
3104 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303106 if ((resinfo == 6) || (resinfo == 9)) {
3107 if (tempax >= 3)
3108 tempbx |= PanelRef75Hz;
3109 } else if ((resinfo == 7) || (resinfo == 8)) {
3110 if (tempax >= 4)
3111 tempbx |= PanelRef75Hz;
3112 }
3113 }
3114 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303116 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303118 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003119
Peter Huewea3d675c2012-02-09 21:11:47 +01003120 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303121 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303123 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003124
Aaro Koskinen58839b02011-03-13 12:26:23 +02003125 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303127 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303129 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003130
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303131 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303133 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303135 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Peter Huewe6896b942012-02-09 21:11:46 +01003136 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType
Peter Huewea3d675c2012-02-09 21:11:47 +01003137 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303138 tempbx |= SetLCDDualLink;
3139 }
3140 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303142 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003143 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003144 & SetCRT2ToLCD) && (resinfo == 9) &&
3145 (!(tempbx & EnableScalingLCD)))
Peter Huewe255aabd2012-02-09 21:11:44 +01003146 /* set to center in 1280x1024 LCDB for Panel_1400x1050 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003147 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303148 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303150 if (pVBInfo->IF_DEF_ExpLink == 1) {
3151 if (modeflag & HalfDCLK) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303152 if (!(tempbx & SetLCDtoNonExpanding)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003153 tempbx |= XGI_EnableLVDSDDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303154 } else {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003155 if (pVBInfo->LCDResInfo == Panel_1024x768) {
3156 if (resinfo == 4) {/* 512x384 */
3157 tempbx |= XGI_EnableLVDSDDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303158 }
3159 }
3160 }
3161 }
3162 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003163
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303164 if (pVBInfo->VBInfo & SetInSlaveMode) {
3165 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01003166 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303167 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01003168 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303169 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003170
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303171 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303173 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003174}
3175
Bill Pemberton108afbf2010-06-17 13:10:47 -04003176unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303177 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003178{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003179 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3180 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
3181 break;
3182 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
3183 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303184 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003185
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303186 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003187}
3188
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003189static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3190{
3191 unsigned char ujRet = 0;
3192 unsigned char i = 0;
3193
3194 for (i = 0; i < 8; i++) {
3195 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003196 ujRet |= (ujDate >> i) & 1;
3197 }
3198
3199 return ujRet;
3200}
3201
3202/*----------------------------------------------------------------------------*/
3203/* output */
3204/* bl[5] : LVDS signal */
3205/* bl[1] : LVDS backlight */
3206/* bl[0] : LVDS VDD */
3207/*----------------------------------------------------------------------------*/
3208static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3209{
3210 unsigned char CR4A, temp;
3211
Aaro Koskinen58839b02011-03-13 12:26:23 +02003212 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003213 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003214
Aaro Koskinen58839b02011-03-13 12:26:23 +02003215 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003216
3217 temp = XG21GPIODataTransfer(temp);
3218 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003219 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003220 return temp;
3221}
3222
3223/*----------------------------------------------------------------------------*/
3224/* output */
3225/* bl[5] : LVDS signal */
3226/* bl[1] : LVDS backlight */
3227/* bl[0] : LVDS VDD */
3228/*----------------------------------------------------------------------------*/
3229static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3230{
3231 unsigned char CR4A, CRB4, temp;
3232
Aaro Koskinen58839b02011-03-13 12:26:23 +02003233 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003234 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003235
Aaro Koskinen58839b02011-03-13 12:26:23 +02003236 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003237
3238 temp &= 0x0C;
3239 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003240 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003241 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003242 temp |= ((CRB4 & 0x04) << 3);
3243 return temp;
3244}
3245
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02003246/*----------------------------------------------------------------------------*/
3247/* input */
3248/* bl[5] : 1;LVDS signal on */
3249/* bl[1] : 1;LVDS backlight on */
3250/* bl[0] : 1:LVDS VDD on */
3251/* bh: 100000b : clear bit 5, to set bit5 */
3252/* 000010b : clear bit 1, to set bit1 */
3253/* 000001b : clear bit 0, to set bit0 */
3254/*----------------------------------------------------------------------------*/
3255static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3256 struct vb_device_info *pVBInfo)
3257{
3258 unsigned char CR4A, temp;
3259
3260 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3261 tempbh &= 0x23;
3262 tempbl &= 0x23;
3263 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3264
3265 if (tempbh & 0x20) {
3266 temp = (tempbl >> 4) & 0x02;
3267
3268 /* CR B4[1] */
3269 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3270
3271 }
3272
3273 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3274
3275 temp = XG21GPIODataTransfer(temp);
3276 temp &= ~tempbh;
3277 temp |= tempbl;
3278 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
3279}
3280
Aaro Koskinen776115a2011-11-27 23:03:10 +02003281static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3282 struct vb_device_info *pVBInfo)
3283{
3284 unsigned char CR4A, temp;
3285 unsigned short tempbh0, tempbl0;
3286
3287 tempbh0 = tempbh;
3288 tempbl0 = tempbl;
3289 tempbh0 &= 0x20;
3290 tempbl0 &= 0x20;
3291 tempbh0 >>= 3;
3292 tempbl0 >>= 3;
3293
3294 if (tempbh & 0x20) {
3295 temp = (tempbl >> 4) & 0x02;
3296
3297 /* CR B4[1] */
3298 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3299
3300 }
3301 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
3302
3303 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3304 tempbh &= 0x03;
3305 tempbl &= 0x03;
3306 tempbh <<= 2;
3307 tempbl <<= 2; /* GPIOC,GPIOD */
3308 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3309 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
3310}
3311
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003312/* --------------------------------------------------------------------- */
3313/* Function : XGI_XG21SetPanelDelay */
3314/* Input : */
3315/* Output : */
3316/* Description : */
3317/* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
3318/* : bl : 2 ; T2 : the duration signal on and Vdd on */
3319/* : bl : 3 ; T3 : the duration between CPL off and signal off */
3320/* : bl : 4 ; T4 : the duration signal off and Vdd off */
3321/* --------------------------------------------------------------------- */
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003322static void XGI_XG21SetPanelDelay(struct xgifb_video_info *xgifb_info,
3323 unsigned short tempbl,
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003324 struct vb_device_info *pVBInfo)
3325{
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003326 if (tempbl == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003327 mdelay(xgifb_info->lvds_data.PSC_S1);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003328
3329 if (tempbl == 2)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003330 mdelay(xgifb_info->lvds_data.PSC_S2);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003331
3332 if (tempbl == 3)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003333 mdelay(xgifb_info->lvds_data.PSC_S3);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003334
3335 if (tempbl == 4)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003336 mdelay(xgifb_info->lvds_data.PSC_S4);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003337}
3338
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003339static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
3340 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303341 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003342{
3343
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003344 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303345 if (pXGIHWDE->jChipType == XG21) {
3346 if (pVBInfo->IF_DEF_LVDS == 1) {
3347 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003348 /* LVDS VDD on */
3349 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003350 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303351 }
3352 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003353 /* LVDS signal on */
3354 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003355 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003356 /* LVDS backlight on */
3357 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303358 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003359 /* DVO/DVI signal on */
3360 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303361 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003362
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303363 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003364
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303365 if (pXGIHWDE->jChipType == XG27) {
3366 if (pVBInfo->IF_DEF_LVDS == 1) {
3367 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003368 /* LVDS VDD on */
3369 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003370 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303371 }
3372 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003373 /* LVDS signal on */
3374 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003375 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003376 /* LVDS backlight on */
3377 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303378 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003379 /* DVO/DVI signal on */
3380 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303381 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303383 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003384}
3385
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003386void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
3387 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303388 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003389{
3390
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303391 if (pXGIHWDE->jChipType == XG21) {
3392 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003393 /* LVDS backlight off */
3394 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003395 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303396 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003397 /* DVO/DVI signal off */
3398 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303399 }
3400 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003401
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303402 if (pXGIHWDE->jChipType == XG27) {
3403 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003404 /* LVDS backlight off */
3405 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003406 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303407 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003408
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303409 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003410 /* DVO/DVI signal off */
3411 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303412 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003413
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003414 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003415}
3416
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003417static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003418{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003419 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303420 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003421
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003422 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303423 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003424}
3425
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003426static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003427{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03003428 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003429}
3430
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003431static void XGI_SaveCRT2Info(unsigned short ModeNo,
3432 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003433{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303434 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003435
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003436 /* reserve CR34 for CRT1 Mode No */
3437 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303438 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3439 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003440 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003441}
3442
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003443static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3444 unsigned short ModeIdIndex,
3445 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003446{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303447 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003448
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303449 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003450 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3451 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
3452 /* si+St_ModeFlag */
3453 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003454
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003455 if (modeflag & HalfDCLK)
3456 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003457
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003458 if (modeflag & DoubleScanMode)
3459 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003460
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303461 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3462 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003463 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003464 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303465 if (yres == 1024)
3466 yres = 1056;
3467 }
3468 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003469
Peter Huewe255aabd2012-02-09 21:11:44 +01003470 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303471 if (yres == 400)
3472 yres = 405;
3473 else if (yres == 350)
3474 yres = 360;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003475
Peter Huewea3d675c2012-02-09 21:11:47 +01003476 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303477 if (yres == 360)
3478 yres = 375;
3479 }
3480 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003481
Peter Huewe255aabd2012-02-09 21:11:44 +01003482 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003483 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303484 if (!(pVBInfo->LCDInfo
3485 & LCDNonExpanding)) {
3486 if (yres == 350)
3487 yres = 357;
3488 else if (yres == 400)
3489 yres = 420;
3490 else if (yres == 480)
3491 yres = 525;
3492 }
3493 }
3494 }
3495 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003496
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303497 if (xres == 720)
3498 xres = 640;
3499 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003500
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303501 pVBInfo->VGAHDE = xres;
3502 pVBInfo->HDE = xres;
3503 pVBInfo->VGAVDE = yres;
3504 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003505}
3506
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003507static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003508{
3509
Peter Huewea3d675c2012-02-09 21:11:47 +01003510 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03003511 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303512 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003513
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303514 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003515}
3516
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003517static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3518 unsigned short ModeIdIndex,
3519 unsigned short RefreshRateTableIndex,
3520 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003521{
3522 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003523 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003524
3525 pVBInfo->RVBHCMAX = 1;
3526 pVBInfo->RVBHCFACT = 1;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003527 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3528 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3529 CRT1Index &= IndexMask;
3530 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[0];
3531 temp2 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
3532 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
3533 tempbx = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[8];
3534 tempcx = (unsigned short)
3535 pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
3536 tempcx &= 0x0100;
3537 tempcx = tempcx << 2;
3538 tempbx |= tempcx;
3539 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003540
3541 if (temp1 & 0x01)
3542 tempbx |= 0x0100;
3543
3544 if (temp1 & 0x20)
3545 tempbx |= 0x0200;
3546 tempax += 5;
3547
3548 if (modeflag & Charx8Dot)
3549 tempax *= 8;
3550 else
3551 tempax *= 9;
3552
3553 pVBInfo->VGAHT = tempax;
3554 pVBInfo->HT = tempax;
3555 tempbx++;
3556 pVBInfo->VGAVT = tempbx;
3557 pVBInfo->VT = tempbx;
3558}
3559
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003560static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303561 unsigned short RefreshRateTableIndex,
3562 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003563{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303564 unsigned short tempax = 0, tempbx, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003565
Peter Huewefc39dcb2012-01-15 19:22:12 +01003566 struct SiS_LCDData *LCDPtr = NULL;
3567 struct SiS_TVData *TVPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003568
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003569 /* si+Ext_ResInfo */
3570 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3571 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303572 pVBInfo->NewFlickerMode = 0;
3573 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003574
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303575 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3576 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3577 pVBInfo);
3578 return;
3579 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003580
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303581 tempbx = 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003582
Peter Huewea3d675c2012-02-09 21:11:47 +01003583 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewefc39dcb2012-01-15 19:22:12 +01003584 LCDPtr = (struct SiS_LCDData *) XGI_GetLcdPtr(tempbx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303585 ModeNo, ModeIdIndex, RefreshRateTableIndex,
3586 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003587
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303588 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
3589 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
3590 pVBInfo->VGAHT = LCDPtr->VGAHT;
3591 pVBInfo->VGAVT = LCDPtr->VGAVT;
3592 pVBInfo->HT = LCDPtr->LCDHT;
3593 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003594
Peter Huewe255aabd2012-02-09 21:11:44 +01003595 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303596 tempax = 1024;
3597 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003598
Peter Huewea3d675c2012-02-09 21:11:47 +01003599 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303600 if (pVBInfo->VGAVDE == 357)
3601 tempbx = 527;
3602 else if (pVBInfo->VGAVDE == 420)
3603 tempbx = 620;
3604 else if (pVBInfo->VGAVDE == 525)
3605 tempbx = 775;
3606 else if (pVBInfo->VGAVDE == 600)
3607 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303608 else
3609 tempbx = 768;
3610 } else
3611 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003612 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303613 tempax = 1024;
3614 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003615 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303616 tempax = 1280;
3617 if (pVBInfo->VGAVDE == 360)
3618 tempbx = 768;
3619 else if (pVBInfo->VGAVDE == 375)
3620 tempbx = 800;
3621 else if (pVBInfo->VGAVDE == 405)
3622 tempbx = 864;
3623 else
3624 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003625 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303626 tempax = 1280;
3627 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003628 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303629 tempax = 1280;
3630 if (pVBInfo->VGAVDE == 350)
3631 tempbx = 700;
3632 else if (pVBInfo->VGAVDE == 400)
3633 tempbx = 800;
3634 else if (pVBInfo->VGAVDE == 1024)
3635 tempbx = 960;
3636 else
3637 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01003638 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303639 tempax = 1400;
3640 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003641
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303642 if (pVBInfo->VGAVDE == 1024) {
3643 tempax = 1280;
3644 tempbx = 1024;
3645 }
Peter Huewe255aabd2012-02-09 21:11:44 +01003646 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303647 tempax = 1600;
3648 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01003649 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303650 if (pVBInfo->VGAVDE == 350)
3651 tempbx = 875;
3652 else if (pVBInfo->VGAVDE == 400)
3653 tempbx = 1000;
3654 }
3655 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003656
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303657 if (pVBInfo->LCDInfo & LCDNonExpanding) {
3658 tempax = pVBInfo->VGAHDE;
3659 tempbx = pVBInfo->VGAVDE;
3660 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003661
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303662 pVBInfo->HDE = tempax;
3663 pVBInfo->VDE = tempbx;
3664 return;
3665 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003666
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303667 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
3668 tempbx = 4;
Peter Huewefc39dcb2012-01-15 19:22:12 +01003669 TVPtr = (struct SiS_TVData *) XGI_GetTVPtr(tempbx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303670 ModeNo, ModeIdIndex, RefreshRateTableIndex,
3671 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003672
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303673 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
3674 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
3675 pVBInfo->VGAHT = TVPtr->VGAHT;
3676 pVBInfo->VGAVT = TVPtr->VGAVT;
3677 pVBInfo->HDE = TVPtr->TVHDE;
3678 pVBInfo->VDE = TVPtr->TVVDE;
3679 pVBInfo->RVBHRS = TVPtr->RVBHRS;
3680 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003681
Peter Huewe599801f2012-02-09 21:11:45 +01003682 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303683 if (resinfo == 0x08)
3684 pVBInfo->NewFlickerMode = 0x40;
3685 else if (resinfo == 0x09)
3686 pVBInfo->NewFlickerMode = 0x40;
3687 else if (resinfo == 0x12)
3688 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003689
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303690 if (pVBInfo->VGAVDE == 350)
3691 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003692
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303693 tempax = ExtHiTVHT;
3694 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003695
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303696 if (pVBInfo->VBInfo & SetInSlaveMode) {
3697 if (pVBInfo->TVInfo & TVSimuMode) {
3698 tempax = StHiTVHT;
3699 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003700
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303701 if (!(modeflag & Charx8Dot)) {
3702 tempax = StHiTextTVHT;
3703 tempbx = StHiTextTVVT;
3704 }
3705 }
3706 }
Peter Huewe599801f2012-02-09 21:11:45 +01003707 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3708 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303709 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
3710 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
3711 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003712
Peter Huewe599801f2012-02-09 21:11:45 +01003713 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303714 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
3715 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01003716 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303717 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
3718 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
3719 if (pVBInfo->TVInfo & NTSC1024x768)
3720 tempax = NTSC1024x768HT;
3721 }
3722 } else {
3723 tempax = PALHT;
3724 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01003725 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303726 tempax = NTSCHT;
3727 tempbx = NTSCVT;
3728 if (pVBInfo->TVInfo & NTSC1024x768)
3729 tempax = NTSC1024x768HT;
3730 }
3731 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003732
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303733 pVBInfo->HT = tempax;
3734 pVBInfo->VT = tempbx;
3735 return;
3736 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003737}
3738
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003739static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303740 unsigned short RefreshRateTableIndex,
3741 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003742{
Bill Pemberton108afbf2010-06-17 13:10:47 -04003743 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003744
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303745 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3746 pVBInfo);
3747 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3748 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003749
Peter Huewe6896b942012-02-09 21:11:46 +01003750 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303751 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003752 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
3753 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
3754 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303755 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003756 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
3757 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303758 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003759
Aaro Koskinen8104e322011-03-13 12:26:22 +02003760 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003761
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303762 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02003763 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303764 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02003765 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003766}
3767
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003768static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
3769 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003770{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003771 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
3772 short index;
3773 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303774
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003775 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01003776 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303777
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003778 if (index < 0)
3779 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303780
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003781 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303782}
3783
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003784static unsigned short XGI_GetOffset(unsigned short ModeNo,
3785 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303786 unsigned short RefreshRateTableIndex,
3787 struct xgi_hw_device_info *HwDeviceExtension,
3788 struct vb_device_info *pVBInfo)
3789{
3790 unsigned short temp, colordepth, modeinfo, index, infoflag,
3791 ColorDepth[] = { 0x01, 0x02, 0x04 };
3792
3793 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003794 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303795
3796 index = (modeinfo >> 8) & 0xFF;
3797
3798 temp = pVBInfo->ScreenOffset[index];
3799
3800 if (infoflag & InterlaceMode)
3801 temp = temp << 1;
3802
3803 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
3804
3805 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
3806 temp = ModeNo - 0x7C;
3807 colordepth = ColorDepth[temp];
3808 temp = 0x6B;
3809 if (infoflag & InterlaceMode)
3810 temp = temp << 1;
3811 return temp * colordepth;
3812 } else {
3813 return temp * colordepth;
3814 }
3815}
3816
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003817static void XGI_SetCRT2Offset(unsigned short ModeNo,
3818 unsigned short ModeIdIndex,
3819 unsigned short RefreshRateTableIndex,
3820 struct xgi_hw_device_info *HwDeviceExtension,
3821 struct vb_device_info *pVBInfo)
3822{
3823 unsigned short offset;
3824 unsigned char temp;
3825
3826 if (pVBInfo->VBInfo & SetInSlaveMode)
3827 return;
3828
3829 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3830 HwDeviceExtension, pVBInfo);
3831 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003832 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003833 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003834 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003835 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003836 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003837}
3838
Randy Dunlap89229672010-08-10 08:46:44 -07003839static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003840{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003841 /* threshold high ,disable auto threshold */
3842 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
3843 /* threshold low default 04h */
3844 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003845}
3846
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003847static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303848 struct xgi_hw_device_info *HwDeviceExtension,
3849 unsigned short RefreshRateTableIndex,
3850 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003851{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303852 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003853
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003854 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3855 CRT1Index &= IndexMask;
3856 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003857
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303858 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3859 HwDeviceExtension, pVBInfo);
3860 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003861
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303862 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003863 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003864
Aaro Koskinen8104e322011-03-13 12:26:22 +02003865 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
3866 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003867}
3868
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003869static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303870 struct xgi_hw_device_info *HwDeviceExtension,
3871 unsigned short RefreshRateTableIndex,
3872 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003873{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303874 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
3875 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003876
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003877 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3878 CRT1Index &= IndexMask;
3879 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3880 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303882 /* bainy change table name */
3883 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003884 /* BTVGA2HT 0x08,0x09 */
3885 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003886 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303887 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003888 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003889 /* BTVGA2HDEE 0x0A,0x0C */
3890 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003891 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303892 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
3893 pushbx = pVBInfo->VGAHDE / 2 + 16;
3894 tempcx = tempcx >> 1;
3895 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3896 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003897
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303898 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3899 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003900 tempbx |= ((pVBInfo->
3901 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
3902 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303903 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
3904 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
3905 tempcx &= 0x1F;
3906 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
3907 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3908 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3909 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003910
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303911 tempbx += 4;
3912 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003913
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303914 if (tempcx > (pVBInfo->VGAHT / 2))
3915 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003916
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303917 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003918
Aaro Koskinen8104e322011-03-13 12:26:22 +02003919 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303920 } else {
3921 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003922 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303923 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003924 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003925 /* BTVGA2HDEE 0x0A,0x0C */
3926 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003927 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303928 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
3929 pushbx = pVBInfo->VGAHDE + 16;
3930 tempcx = tempcx >> 1;
3931 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3932 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003933
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303934 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3935 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003936 tempbx |= ((pVBInfo->
3937 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
3938 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303939 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
3940 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
3941 tempcx &= 0x1F;
3942 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
3943 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3944 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3945 tempbx += 16;
3946 tempcx += 16;
3947 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303949 if (tempcx > pVBInfo->VGAHT)
3950 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003951
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303952 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003953 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303954 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003955
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303956 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3957 tempbx = pushbx;
3958 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3959 tempax |= (tempbx & 0xFF00);
3960 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003961 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303962 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003963 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303964 tempcx = (pVBInfo->VGAVT - 1);
3965 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003966
Aaro Koskinen8104e322011-03-13 12:26:22 +02003967 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303968 tempbx = pVBInfo->VGAVDE - 1;
3969 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003970 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303971 temp = ((tempbx & 0xFF00) << 3) >> 8;
3972 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003973 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003974
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303975 tempax = pVBInfo->VGAVDE;
3976 tempbx = pVBInfo->VGAVDE;
3977 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003978 /* BTVGA2VRS 0x10,0x11 */
3979 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3980 /* BTVGA2VRE 0x11 */
3981 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003982
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303983 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3984 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
3985 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003986
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303987 if (temp & 0x04)
3988 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003989
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303990 if (temp & 0x080)
3991 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003992
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303993 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303995 if (temp & 0x08)
3996 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003997
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303998 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
3999 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
4000 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304002 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004003 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304004 temp = ((tempbx & 0xFF00) >> 8) << 4;
4005 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004006 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304007 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004008
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304009 if (modeflag & DoubleScanMode)
4010 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004011
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304012 if (modeflag & HalfDCLK)
4013 tempax |= 0x40;
4014
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004015 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004016}
4017
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004018static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4019{
4020 unsigned long tempax, tempbx;
4021
4022 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4023 & 0xFFFF;
4024 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4025 tempax = (tempax * pVBInfo->HT) / tempbx;
4026
4027 return (unsigned short) tempax;
4028}
4029
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004030static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304031 struct xgi_hw_device_info *HwDeviceExtension,
4032 unsigned short RefreshRateTableIndex,
4033 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004034{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304035 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4036 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004037
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004038 /* si+Ext_ResInfo */
4039 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4040 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4041 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4042 CRT1Index &= IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304044 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4045 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304047 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004048 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304049 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004050
Peter Huewe6896b942012-02-09 21:11:46 +01004051 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304052 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304054 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004055
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304056 if (modeflag & HalfDCLK)
4057 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304059 tempax = (tempax / tempcx) - 1;
4060 tempbx |= ((tempax & 0x00FF) << 8);
4061 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004062 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004063
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304064 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004065
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304066 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01004067 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4068 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304069 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004070
Peter Huewe599801f2012-02-09 21:11:45 +01004071 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01004072 if (pVBInfo->VBType & VB_SIS301LV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304073 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4074 if (resinfo == 7)
4075 temp -= 2;
4076 }
4077 } else if (resinfo == 7) {
4078 temp -= 2;
4079 }
4080 }
4081 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004082
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004083 /* 0x05 Horizontal Display Start */
4084 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4085 /* 0x06 Horizontal Blank end */
4086 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004087
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304088 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4089 if (pVBInfo->VBInfo & SetCRT2ToTV)
4090 tempax = pVBInfo->VGAHT;
4091 else
4092 tempax = XGI_GetVGAHT2(pVBInfo);
4093 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004094
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304095 if (tempax >= pVBInfo->VGAHT)
4096 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304098 if (modeflag & HalfDCLK)
4099 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304101 tempax = (tempax / tempcx) - 5;
4102 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01004103 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304104 temp = (tempbx & 0x00FF) - 1;
4105 if (!(modeflag & HalfDCLK)) {
4106 temp -= 6;
4107 if (pVBInfo->TVInfo & TVSimuMode) {
4108 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004109 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304110 }
4111 }
4112 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304113 tempbx = (tempbx & 0xFF00) >> 8;
4114 tempcx = (tempcx + tempbx) >> 1;
4115 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004116
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304117 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4118 temp -= 1;
4119 if (!(modeflag & HalfDCLK)) {
4120 if ((modeflag & Charx8Dot)) {
4121 temp += 4;
4122 if (pVBInfo->VGAHDE >= 800)
4123 temp -= 6;
4124 }
4125 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004126 } else if (!(modeflag & HalfDCLK)) {
4127 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01004128 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004129 pVBInfo->VGAHDE >= 800) {
4130 temp -= 7;
4131 if (pVBInfo->ModeType == ModeEGA &&
4132 pVBInfo->VGAVDE == 1024) {
4133 temp += 15;
4134 if (pVBInfo->LCDResInfo !=
Peter Huewe255aabd2012-02-09 21:11:44 +01004135 Panel_1280x1024)
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004136 temp += 7;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304137 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004138
4139 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01004140 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004141 (pVBInfo->LCDInfo & LCDNonExpanding))
4142 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304143 }
4144 }
4145 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004146
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004147 /* 0x07 Horizontal Retrace Start */
4148 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4149 /* 0x08 Horizontal Retrace End */
4150 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004151
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304152 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4153 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004154 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304155 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004156 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304157 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004158 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304159 0x08, 0x03);
4160 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004161 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304162 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004163 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304164 0x08, 0x02);
4165 }
4166 }
4167 }
4168 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004169
Aaro Koskinen8104e322011-03-13 12:26:22 +02004170 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004171 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004172 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304174 tempbx = pVBInfo->VGAVT;
4175 push1 = tempbx;
4176 tempcx = 0x121;
4177 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004178
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304179 if (tempbx == 357)
4180 tempbx = 350;
4181 if (tempbx == 360)
4182 tempbx = 350;
4183 if (tempbx == 375)
4184 tempbx = 350;
4185 if (tempbx == 405)
4186 tempbx = 400;
4187 if (tempbx == 525)
4188 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304190 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304192 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01004193 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004194 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304195 if (tempbx == 350)
4196 tempbx += 5;
4197 if (tempbx == 480)
4198 tempbx += 5;
4199 }
4200 }
4201 }
4202 tempbx--;
4203 temp = tempbx & 0x00FF;
4204 tempbx--;
4205 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004206 /* 0x10 vertical Blank Start */
4207 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304208 tempbx = push2;
4209 tempbx--;
4210 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004211 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304213 if (tempbx & 0x0100)
4214 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004215
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304216 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304218 if (modeflag & DoubleScanMode)
4219 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004220
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304221 if (tempbx & 0x0200)
4222 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304224 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004225 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304227 if (tempbx & 0x0400)
4228 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004229
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004230 /* 0x11 Vertival Blank End */
4231 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304232
4233 tempax = push1;
4234 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4235 tempax = tempax >> 2;
4236 push1 = tempax; /* push ax */
4237
4238 if (resinfo != 0x09) {
4239 tempax = tempax << 1;
4240 tempbx += tempax;
4241 }
4242
Peter Huewe599801f2012-02-09 21:11:45 +01004243 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01004244 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004245 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304246 tempbx -= 10;
4247 } else {
4248 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Huewe599801f2012-02-09 21:11:45 +01004249 if (pVBInfo->TVInfo & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004250 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004251 VB_SIS301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004252 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004253 (TVSetYPbPr525p |
4254 TVSetYPbPr750p |
4255 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304256 tempbx += 40;
4257 } else {
4258 tempbx += 40;
4259 }
4260 }
4261 }
4262 }
4263 } else {
4264 tempbx -= 10;
4265 }
4266 } else {
4267 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Huewe599801f2012-02-09 21:11:45 +01004268 if (pVBInfo->TVInfo & TVSetPAL) {
Peter Huewe6896b942012-02-09 21:11:46 +01004269 if (pVBInfo->VBType & VB_SIS301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004270 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004271 (TVSetYPbPr525p |
4272 TVSetYPbPr750p |
4273 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304274 tempbx += 40;
4275 } else {
4276 tempbx += 40;
4277 }
4278 }
4279 }
4280 }
4281 tempax = push1;
4282 tempax = tempax >> 2;
4283 tempax++;
4284 tempax += tempbx;
4285 push1 = tempax; /* push ax */
4286
Peter Huewe599801f2012-02-09 21:11:45 +01004287 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304288 if (tempbx <= 513) {
4289 if (tempax >= 513)
4290 tempbx = 513;
4291 }
4292 }
4293
4294 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004295 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304296 tempbx--;
4297 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004298 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304299
4300 if (tempbx & 0x0100)
4301 tempcx |= 0x0008;
4302
4303 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004304 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304305
4306 tempbx++;
4307
4308 if (tempbx & 0x0100)
4309 tempcx |= 0x0004;
4310
4311 if (tempbx & 0x0200)
4312 tempcx |= 0x0080;
4313
4314 if (tempbx & 0x0400)
4315 tempcx |= 0x0C00;
4316
4317 tempbx = push1; /* pop ax */
4318 temp = tempbx & 0x00FF;
4319 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004320 /* 0x0D vertical Retrace End */
4321 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304322
4323 if (tempbx & 0x0010)
4324 tempcx |= 0x2000;
4325
4326 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004327 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304328 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004329 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304330 tempax = modeflag;
4331 temp = (tempax & 0xFF00) >> 8;
4332
4333 temp = (temp >> 1) & 0x09;
4334
Peter Huewe6896b942012-02-09 21:11:46 +01004335 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304336 temp |= 0x01;
4337
Aaro Koskinen8104e322011-03-13 12:26:22 +02004338 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4339 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4340 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304341
4342 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4343 temp = 0x80;
4344 else
4345 temp = 0x00;
4346
Aaro Koskinen8104e322011-03-13 12:26:22 +02004347 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304348
4349 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004350}
4351
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004352static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304353 unsigned short RefreshRateTableIndex,
4354 struct xgi_hw_device_info *HwDeviceExtension,
4355 struct vb_device_info *pVBInfo)
4356{
4357 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4358 modeflag, resinfo, crt2crtc;
4359 unsigned char *TimingPoint;
4360
4361 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4362
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004363 /* si+Ext_ResInfo */
4364 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4365 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4366 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304367
4368 tempax = 0;
4369
4370 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4371 tempax |= 0x0800;
4372
4373 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4374 tempax |= 0x0400;
4375
4376 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4377 tempax |= 0x0200;
4378
Peter Huewe599801f2012-02-09 21:11:45 +01004379 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304380 tempax |= 0x1000;
4381
Peter Huewe599801f2012-02-09 21:11:45 +01004382 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304383 tempax |= 0x0100;
4384
Peter Huewe599801f2012-02-09 21:11:45 +01004385 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304386 tempax &= 0xfe00;
4387
4388 tempax = (tempax & 0xff00) >> 8;
4389
Aaro Koskinen8104e322011-03-13 12:26:22 +02004390 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304391 TimingPoint = pVBInfo->NTSCTiming;
4392
Peter Huewe599801f2012-02-09 21:11:45 +01004393 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304394 TimingPoint = pVBInfo->PALTiming;
4395
Peter Huewe599801f2012-02-09 21:11:45 +01004396 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304397 TimingPoint = pVBInfo->HiTVExtTiming;
4398
4399 if (pVBInfo->VBInfo & SetInSlaveMode)
4400 TimingPoint = pVBInfo->HiTVSt2Timing;
4401
4402 if (pVBInfo->SetFlag & TVSimuMode)
4403 TimingPoint = pVBInfo->HiTVSt1Timing;
4404
4405 if (!(modeflag & Charx8Dot))
4406 TimingPoint = pVBInfo->HiTVTextTiming;
4407 }
4408
Peter Huewe599801f2012-02-09 21:11:45 +01004409 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4410 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304411 TimingPoint = pVBInfo->YPbPr525iTiming;
4412
Peter Huewe599801f2012-02-09 21:11:45 +01004413 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304414 TimingPoint = pVBInfo->YPbPr525pTiming;
4415
Peter Huewe599801f2012-02-09 21:11:45 +01004416 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304417 TimingPoint = pVBInfo->YPbPr750pTiming;
4418 }
4419
4420 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004421 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304422
4423 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004424 /* di->temp2[j] */
4425 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304426
4427 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004428 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304429
4430 temp = pVBInfo->NewFlickerMode;
4431 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004432 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304433
Peter Huewe599801f2012-02-09 21:11:45 +01004434 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304435 tempax = 950;
4436
Peter Huewe599801f2012-02-09 21:11:45 +01004437 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304438 tempax = 520;
4439 else
4440 tempax = 440;
4441
4442 if (pVBInfo->VDE <= tempax) {
4443 tempax -= pVBInfo->VDE;
4444 tempax = tempax >> 2;
4445 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
4446 push1 = tempax;
4447 temp = (tempax & 0xFF00) >> 8;
4448 temp += (unsigned short) TimingPoint[0];
4449
Peter Huewe6896b942012-02-09 21:11:46 +01004450 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4451 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304452 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4453 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01004454 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304455 tempcx = pVBInfo->VGAHDE;
4456 if (tempcx >= 1024) {
4457 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01004458 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304459 temp = 0x19; /* PAL */
4460 }
4461 }
4462 }
4463
Aaro Koskinen8104e322011-03-13 12:26:22 +02004464 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304465 tempax = push1;
4466 temp = (tempax & 0xFF00) >> 8;
4467 temp += TimingPoint[1];
4468
Peter Huewe6896b942012-02-09 21:11:46 +01004469 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4470 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304471 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4472 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01004473 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304474 tempcx = pVBInfo->VGAHDE;
4475 if (tempcx >= 1024) {
4476 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01004477 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304478 temp = 0x52; /* PAL */
4479 }
4480 }
4481 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004482 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304483 }
4484
4485 /* 301b */
4486 tempcx = pVBInfo->HT;
4487
4488 if (XGI_IsLCDDualLink(pVBInfo))
4489 tempcx = tempcx >> 1;
4490
4491 tempcx -= 2;
4492 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004493 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304494
4495 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004496 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304497
4498 tempcx = pVBInfo->HT >> 1;
4499 push1 = tempcx; /* push cx */
4500 tempcx += 7;
4501
Peter Huewe599801f2012-02-09 21:11:45 +01004502 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304503 tempcx -= 4;
4504
4505 temp = tempcx & 0x00FF;
4506 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004507 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304508
4509 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4510 tempbx += tempcx;
4511 push2 = tempbx;
4512 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004513 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304514 temp = (tempbx & 0xFF00) >> 8;
4515 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004516 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304517
4518 tempbx = push2;
4519 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004520 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304521 tempbx = tempbx - 4;
4522 tempcx = tempbx;
4523 }
4524
4525 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004526 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304527
4528 j += 2;
4529 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
4530 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004531 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304532 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004533 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304534
4535 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004536 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304537 tempcx -= 4;
4538
4539 temp = tempcx & 0xFF;
4540 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004541 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304542
4543 tempcx = push1; /* pop cx */
4544 j += 2;
4545 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4546 tempcx -= temp;
4547 temp = tempcx & 0x00FF;
4548 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004549 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304550
4551 tempcx -= 11;
4552
4553 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
4554 tempax = XGI_GetVGAHT2(pVBInfo);
4555 tempcx = tempax - 1;
4556 }
4557 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004558 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304559
4560 tempbx = pVBInfo->VDE;
4561
4562 if (pVBInfo->VGAVDE == 360)
4563 tempbx = 746;
4564 if (pVBInfo->VGAVDE == 375)
4565 tempbx = 746;
4566 if (pVBInfo->VGAVDE == 405)
4567 tempbx = 853;
4568
4569 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004570 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004571 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004572 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004573 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304574 tempbx = tempbx >> 1;
4575 } else
4576 tempbx = tempbx >> 1;
4577 }
4578
4579 tempbx -= 2;
4580 temp = tempbx & 0x00FF;
4581
Peter Huewe599801f2012-02-09 21:11:45 +01004582 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01004583 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004584 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304585 if (pVBInfo->VBInfo & SetInSlaveMode) {
4586 if (ModeNo == 0x2f)
4587 temp += 1;
4588 }
4589 }
4590 } else {
4591 if (pVBInfo->VBInfo & SetInSlaveMode) {
4592 if (ModeNo == 0x2f)
4593 temp += 1;
4594 }
4595 }
4596 }
4597
Aaro Koskinen8104e322011-03-13 12:26:22 +02004598 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304599
4600 temp = (tempcx & 0xFF00) >> 8;
4601 temp |= ((tempbx & 0xFF00) >> 8) << 6;
4602
Peter Huewe599801f2012-02-09 21:11:45 +01004603 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01004604 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004605 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304606 temp |= 0x10;
4607
4608 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4609 temp |= 0x20;
4610 }
4611 } else {
4612 temp |= 0x10;
4613 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4614 temp |= 0x20;
4615 }
4616 }
4617
Aaro Koskinen8104e322011-03-13 12:26:22 +02004618 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304619
Peter Huewe6896b942012-02-09 21:11:46 +01004620 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4621 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304622 tempbx = pVBInfo->VDE;
4623 tempcx = tempbx - 2;
4624
4625 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004626 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
4627 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304628 tempbx = tempbx >> 1;
4629 }
4630
Peter Huewe6896b942012-02-09 21:11:46 +01004631 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304632 temp = 0;
4633 if (tempcx & 0x0400)
4634 temp |= 0x20;
4635
4636 if (tempbx & 0x0400)
4637 temp |= 0x40;
4638
Aaro Koskinen8104e322011-03-13 12:26:22 +02004639 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304640 }
4641
4642 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004643 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304644 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004645 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304646 }
4647
4648 tempbx = tempbx & 0x00FF;
4649
4650 if (!(modeflag & HalfDCLK)) {
4651 tempcx = pVBInfo->VGAHDE;
4652 if (tempcx >= pVBInfo->HDE) {
4653 tempbx |= 0x2000;
4654 tempax &= 0x00FF;
4655 }
4656 }
4657
4658 tempcx = 0x0101;
4659
4660 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
4661 if (pVBInfo->VGAHDE >= 1024) {
4662 tempcx = 0x1920;
4663 if (pVBInfo->VGAHDE >= 1280) {
4664 tempcx = 0x1420;
4665 tempbx = tempbx & 0xDFFF;
4666 }
4667 }
4668 }
4669
4670 if (!(tempbx & 0x2000)) {
4671 if (modeflag & HalfDCLK)
4672 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
4673
4674 push1 = tempbx;
4675 tempeax = pVBInfo->VGAHDE;
4676 tempebx = (tempcx & 0xFF00) >> 8;
4677 longtemp = tempeax * tempebx;
4678 tempecx = tempcx & 0x00FF;
4679 longtemp = longtemp / tempecx;
4680
4681 /* 301b */
4682 tempecx = 8 * 1024;
4683
Peter Huewe6896b942012-02-09 21:11:46 +01004684 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4685 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304686 tempecx = tempecx * 8;
4687 }
4688
4689 longtemp = longtemp * tempecx;
4690 tempecx = pVBInfo->HDE;
4691 temp2 = longtemp % tempecx;
4692 tempeax = longtemp / tempecx;
4693 if (temp2 != 0)
4694 tempeax += 1;
4695
4696 tempax = (unsigned short) tempeax;
4697
4698 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004699 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4700 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304701 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
4702 }
4703 /* end 301b */
4704
4705 tempbx = push1;
4706 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
4707 | (tempbx & 0x00FF));
4708 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
4709 | (tempax & 0x00FF));
4710 temp = (tempax & 0xFF00) >> 8;
4711 } else {
4712 temp = (tempax & 0x00FF) >> 8;
4713 }
4714
Aaro Koskinen8104e322011-03-13 12:26:22 +02004715 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304716 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004717 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304718 temp = tempcx & 0x00FF;
4719
4720 if (tempbx & 0x2000)
4721 temp = 0;
4722
4723 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4724 temp |= 0x18;
4725
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004726 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01004727 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304728 tempbx = 0x0382;
4729 tempcx = 0x007e;
4730 } else {
4731 tempbx = 0x0369;
4732 tempcx = 0x0061;
4733 }
4734
4735 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004736 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304737 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004738 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304739
4740 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
4741 temp = temp << 2;
4742 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
4743
Peter Huewe599801f2012-02-09 21:11:45 +01004744 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304745 temp |= 0x10;
4746
Peter Huewe599801f2012-02-09 21:11:45 +01004747 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304748 temp |= 0x20;
4749
Peter Huewe599801f2012-02-09 21:11:45 +01004750 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304751 temp |= 0x60;
4752 }
4753
Aaro Koskinen8104e322011-03-13 12:26:22 +02004754 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004755 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004756 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304757
Peter Huewe599801f2012-02-09 21:11:45 +01004758 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304759 if (pVBInfo->TVInfo & NTSC1024x768) {
4760 TimingPoint = XGI_NTSC1024AdjTime;
4761 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004762 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304763 TimingPoint[j]);
4764 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004765 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304766 }
4767 }
4768
4769 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
4770 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01004771 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004772 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304773 0x08); /* PALM Mode */
4774 }
4775
Peter Huewe599801f2012-02-09 21:11:45 +01004776 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02004777 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304778 0x01);
4779 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02004780 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304781
Aaro Koskinendc505562011-03-13 12:26:26 +02004782 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304783 }
4784
Peter Huewe599801f2012-02-09 21:11:45 +01004785 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304786 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02004787 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304788 }
4789
4790 if (pVBInfo->VBInfo & SetCRT2ToTV)
4791 return;
4792}
4793
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004794static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304795 struct xgi_hw_device_info *HwDeviceExtension,
4796 unsigned short RefreshRateTableIndex,
4797 struct vb_device_info *pVBInfo)
4798{
4799 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
4800 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
4801
4802 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
4803
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004804 /* si+Ext_ResInfo */
4805 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4806 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4807 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4808 CRT1Index &= IndexMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304809
4810 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4811 return;
4812
4813 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
4814
4815 if (XGI_IsLCDDualLink(pVBInfo))
4816 tempbx = tempbx >> 1;
4817
4818 tempbx -= 1;
4819 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004820 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304821 temp = (tempbx & 0xFF00) >> 8;
4822 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004823 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304824 temp = 0x01;
4825
Peter Huewe255aabd2012-02-09 21:11:44 +01004826 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304827 if (pVBInfo->ModeType == ModeEGA) {
4828 if (pVBInfo->VGAHDE >= 1024) {
4829 temp = 0x02;
Peter Huewea3d675c2012-02-09 21:11:47 +01004830 if (pVBInfo->LCDInfo & XGI_LCDVESATiming)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304831 temp = 0x01;
4832 }
4833 }
4834 }
4835
Aaro Koskinen8104e322011-03-13 12:26:22 +02004836 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304837 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
4838 push1 = tempbx;
4839 tempbx--;
4840 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004841 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304842 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004843 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304844
4845 tempcx = pVBInfo->VT - 1;
4846 push2 = tempcx + 1;
4847 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004848 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304849 temp = (tempcx & 0xFF00) >> 8;
4850 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004851 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004852 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
4853 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
4854 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
4855 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304856
4857 /* Customized LCDB Des no add */
4858 tempbx = 5;
4859 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
4860 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
4861 tempah = pVBInfo->LCDResInfo;
4862 tempah &= PanelResInfo;
4863
Peter Huewe255aabd2012-02-09 21:11:44 +01004864 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304865 tempbx = 1024;
4866 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01004867 } else if ((tempah == Panel_1280x1024) ||
4868 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304869 tempbx = 1280;
4870 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01004871 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304872 tempbx = 1400;
4873 tempcx = 1050;
4874 } else {
4875 tempbx = 1600;
4876 tempcx = 1200;
4877 }
4878
4879 if (pVBInfo->LCDInfo & EnableScalingLCD) {
4880 tempbx = pVBInfo->HDE;
4881 tempcx = pVBInfo->VDE;
4882 }
4883
4884 pushbx = tempbx;
4885 tempax = pVBInfo->VT;
4886 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
4887 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
4888 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
4889 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
4890 tempbx = pVBInfo->LCDVDES;
4891 tempcx += tempbx;
4892
4893 if (tempcx >= tempax)
4894 tempcx -= tempax; /* lcdvdes */
4895
4896 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004897 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304898 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004899 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304900 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
4901 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
4902 tempah = tempch;
4903 tempah = tempah << 3;
4904 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004905 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304906
4907 /* getlcdsync() */
4908 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4909 tempcx = tempbx;
4910 tempax = pVBInfo->VT;
4911 tempbx = pVBInfo->LCDVRS;
4912
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304913 tempcx += tempbx;
4914 if (tempcx >= tempax)
4915 tempcx -= tempax;
4916
4917 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004918 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304919 temp = (tempbx & 0xFF00) >> 8;
4920 temp = temp << 4;
4921 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004922 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304923 tempcx = pushbx;
4924 tempax = pVBInfo->HT;
4925 tempbx = pVBInfo->LCDHDES;
4926 tempbx &= 0x0FFF;
4927
4928 if (XGI_IsLCDDualLink(pVBInfo)) {
4929 tempax = tempax >> 1;
4930 tempbx = tempbx >> 1;
4931 tempcx = tempcx >> 1;
4932 }
4933
Peter Huewe6896b942012-02-09 21:11:46 +01004934 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304935 tempbx += 1;
4936
4937 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
4938 tempbx += 1;
4939
4940 tempcx += tempbx;
4941
4942 if (tempcx >= tempax)
4943 tempcx -= tempax;
4944
4945 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004946 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304947 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004948 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304949 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004950 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304951 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004952 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304953
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304954 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4955 tempcx = tempax;
4956 tempax = pVBInfo->HT;
4957 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304958 if (XGI_IsLCDDualLink(pVBInfo)) {
4959 tempax = tempax >> 1;
4960 tempbx = tempbx >> 1;
4961 tempcx = tempcx >> 1;
4962 }
4963
Peter Huewe6896b942012-02-09 21:11:46 +01004964 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304965 tempbx += 1;
4966
4967 tempcx += tempbx;
4968
4969 if (tempcx >= tempax)
4970 tempcx -= tempax;
4971
4972 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004973 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304974
4975 temp = (tempbx & 0xFF00) >> 8;
4976 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004977 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304978 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004979 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304980
Peter Huewea3d675c2012-02-09 21:11:47 +01004981 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304982 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01004983 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4984 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304985 | VB_XGI301C)) {
4986 temp = 0xC6;
4987 } else
4988 temp = 0xC4;
4989
Aaro Koskinen8104e322011-03-13 12:26:22 +02004990 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4991 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304992 }
4993
4994 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004995 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4996 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304997 | VB_XGI301C)) {
4998 temp = 0x4F;
4999 } else
5000 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005001 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305002 }
5003 }
5004}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005005
5006/* --------------------------------------------------------------------- */
5007/* Function : XGI_GetTap4Ptr */
5008/* Input : */
5009/* Output : di -> Tap4 Reg. Setting Pointer */
5010/* Description : */
5011/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005012static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305013 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005014{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305015 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305017 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005018
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305019 if (tempcx == 0) {
5020 tempax = pVBInfo->VGAHDE;
5021 tempbx = pVBInfo->HDE;
5022 } else {
5023 tempax = pVBInfo->VGAVDE;
5024 tempbx = pVBInfo->VDE;
5025 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005026
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005027 if (tempax <= tempbx)
5028 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305029 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005030 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005031
Peter Huewe599801f2012-02-09 21:11:45 +01005032 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305033 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005034
Peter Huewe599801f2012-02-09 21:11:45 +01005035 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
5036 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
5037 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005038 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01005039 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305040 Tap4TimingPtr = YPbPr750pTap4Timing;
5041 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005042
Peter Huewe599801f2012-02-09 21:11:45 +01005043 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005044 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005045
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305046 i = 0;
5047 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5048 if (Tap4TimingPtr[i].DE == tempax)
5049 break;
5050 i++;
5051 }
5052 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005053}
5054
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005055static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005056{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305057 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305059 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005060
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305061 if (!(pVBInfo->VBType & VB_XGI301C))
5062 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005063
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305064 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5065 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005066 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005067
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005068 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01005069 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005070 /* Set Vertical Scaling */
5071 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305072 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005073 xgifb_reg_set(pVBInfo->Part2Port,
5074 i,
5075 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305076 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005077
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005078 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01005079 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005080 /* Enable V.Scaling */
5081 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305082 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005083 /* Enable H.Scaling */
5084 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005085}
5086
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005087static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305088 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005089{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305090 unsigned short i;
5091 unsigned char *tempdi;
5092 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005093
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005094 /* si+Ext_ResInfo */
5095 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005096
Aaro Koskinen8104e322011-03-13 12:26:22 +02005097 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01005098 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005099 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5100 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305101 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005102 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5103 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305104 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305106 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5107 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005108
Peter Huewe599801f2012-02-09 21:11:45 +01005109 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005110 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5111 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5112 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305113 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005114
Peter Huewe599801f2012-02-09 21:11:45 +01005115 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
5116 & SetCRT2ToYPbPr525750)) {
5117 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305118 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305120 tempdi = pVBInfo->HiTVGroup3Data;
5121 if (pVBInfo->SetFlag & TVSimuMode) {
5122 tempdi = pVBInfo->HiTVGroup3Simu;
5123 if (!(modeflag & Charx8Dot))
5124 tempdi = pVBInfo->HiTVGroup3Text;
5125 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005126
Peter Huewe599801f2012-02-09 21:11:45 +01005127 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305128 tempdi = pVBInfo->Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005129
Peter Huewe599801f2012-02-09 21:11:45 +01005130 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305131 tempdi = pVBInfo->Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305133 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005134 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305136 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01005137 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005138 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305139 }
5140 }
5141 return;
5142} /* {end of XGI_SetGroup3} */
5143
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005144static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305145 unsigned short RefreshRateTableIndex,
5146 struct xgi_hw_device_info *HwDeviceExtension,
5147 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005148{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305149 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305151 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005152
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005153 /* si+Ext_ResInfo */
5154 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305155 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005156 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305158 tempbx = pVBInfo->RVBHCMAX;
5159 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005160 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305161 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5162 tempcx = pVBInfo->VGAHT - 1;
5163 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005164 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005165
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305166 temp = ((tempcx & 0xFF00) >> 8) << 3;
5167 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305169 tempcx = pVBInfo->VGAVT - 1;
5170 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5171 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305173 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005174 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305175 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005176 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005177 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305178 tempcx = pVBInfo->VBInfo;
5179 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005180
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305181 if (modeflag & HalfDCLK)
5182 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005183
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305184 if (XGI_IsLCDDualLink(pVBInfo))
5185 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005186
Peter Huewe599801f2012-02-09 21:11:45 +01005187 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305188 temp = 0;
5189 if (tempbx <= 1024)
5190 temp = 0xA0;
5191 if (tempbx == 1280)
5192 temp = 0xC0;
5193 } else if (tempcx & SetCRT2ToTV) {
5194 temp = 0xA0;
5195 if (tempbx <= 800)
5196 temp = 0x80;
5197 } else {
5198 temp = 0x80;
5199 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5200 temp = 0;
5201 if (tempbx > 800)
5202 temp = 0x60;
5203 }
5204 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005205
Peter Huewe599801f2012-02-09 21:11:45 +01005206 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305207 temp = 0x00;
5208 if (pVBInfo->VGAHDE == 1280)
5209 temp = 0x40;
5210 if (pVBInfo->VGAHDE == 1024)
5211 temp = 0x20;
5212 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005213 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305215 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005216
Peter Huewe599801f2012-02-09 21:11:45 +01005217 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305218 if (!(temp & 0xE000))
5219 tempbx = tempbx >> 1;
5220 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005221
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305222 tempcx = pVBInfo->RVBHRS;
5223 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005224 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005225
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305226 tempeax = pVBInfo->VGAVDE;
5227 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305229 if (tempeax <= tempebx) {
5230 tempcx = (tempcx & (~0x4000));
5231 tempeax = pVBInfo->VGAVDE;
5232 } else {
5233 tempeax -= tempebx;
5234 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005235
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305236 templong = (tempeax * 256 * 1024) % tempebx;
5237 tempeax = (tempeax * 256 * 1024) / tempebx;
5238 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305240 if (templong != 0)
5241 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005242
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305243 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005244 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305246 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005247 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305248 tempbx = (unsigned short) (tempebx >> 16);
5249 temp = tempbx & 0x00FF;
5250 temp = temp << 4;
5251 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005252 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305254 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01005255 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5256 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305257 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005258 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305259 tempax = pVBInfo->VGAHDE;
5260 if (modeflag & HalfDCLK)
5261 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005262
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305263 if (XGI_IsLCDDualLink(pVBInfo))
5264 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005265
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305266 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5267 if (tempax > 800)
5268 tempax -= 800;
5269 } else {
5270 if (pVBInfo->VGAHDE > 800) {
5271 if (pVBInfo->VGAHDE == 1024)
5272 tempax = (tempax * 25 / 32) - 1;
5273 else
5274 tempax = (tempax * 20 / 32) - 1;
5275 }
5276 }
5277 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005278
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305279 temp = (tempax & 0xFF00) >> 8;
5280 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005281 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305282 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005283 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005284
Peter Huewe599801f2012-02-09 21:11:45 +01005285 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305286 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005287 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005288
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305289 }
5290 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005291
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305292 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5293 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01005294 | TVSetYPbPr525p | TVSetYPbPr750p
5295 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305296 temp |= 0x0001;
5297 if ((pVBInfo->VBInfo & SetInSlaveMode)
5298 && (!(pVBInfo->TVInfo
5299 & TVSimuMode)))
5300 temp &= (~0x0001);
5301 }
5302 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005303
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005304 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305305 tempbx = pVBInfo->HT;
5306 if (XGI_IsLCDDualLink(pVBInfo))
5307 tempbx = tempbx >> 1;
5308 tempbx = (tempbx >> 1) - 2;
5309 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005310 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305311 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005312 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305313 }
5314 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005315
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305316 if (pVBInfo->ISXPDOS == 0)
5317 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5318 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005319}
5320
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005321static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5322{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005323 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005324}
5325
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005326static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305327 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005328{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305329 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305331 Pindex = pVBInfo->Part5Port;
5332 Pdata = pVBInfo->Part5Port + 1;
5333 if (pVBInfo->ModeType == ModeVGA) {
5334 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01005335 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305336 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305337 }
5338 }
5339 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005340}
5341
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005342static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305343 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005344{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005345 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005346}
5347
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005348static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305349 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005350{
5351
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005352 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005353}
5354
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005355static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
5356 unsigned short ModeNo, unsigned short ModeIdIndex,
5357 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005358{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005359 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005360
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305361 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005362 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5363 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5364 /* si+St_ModeFlag */
5365 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005366
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305367 if (!(modeflag & Charx8Dot)) {
5368 xres /= 9;
5369 xres *= 8;
5370 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005371
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005372 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
5373 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005374
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005375 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
5376 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005377
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005378 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305379 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04005380
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005381 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305382 return 0;
5383
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005384 if (xres != xgifb_info->lvds_data.LVDSHDE ||
5385 yres != xgifb_info->lvds_data.LVDSVDE) {
5386 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
5387 if (colordepth > 2)
5388 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305389 }
5390 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005391}
5392
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005393static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
5394 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005395 unsigned short ModeNo,
5396 unsigned short ModeIdIndex,
5397 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005398{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305399 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005400 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305401 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
5402 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
5403 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005404
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005405 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005406 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305407 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005408 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005409
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005410 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005411
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005412 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005413 /* SR35[7] FP VSync polarity */
5414 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
5415 /* SR30[5] FP HSync polarity */
5416 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005417
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005418 if (chip_id == XG27)
5419 XGI_SetXG27FPBits(pVBInfo);
5420 else
5421 XGI_SetXG21FPBits(pVBInfo);
5422
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305423 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005424 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5425 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5426 /* si+St_ModeFlag */
5427 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005428
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305429 if (!(modeflag & Charx8Dot))
5430 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005431
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005432 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005433
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005434 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005435
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305436 if (LVDSHBS > LVDSHT)
5437 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005438
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005439 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305440 if (LVDSHRS > LVDSHT)
5441 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005442
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005443 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305444 if (LVDSHRE > LVDSHT)
5445 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005446
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005447 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005448
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005449 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005450
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005451 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005452 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305453 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305455 if (LVDSVBS > LVDSVT)
5456 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005457
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005458 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305459 if (LVDSVRS > LVDSVT)
5460 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005461
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005462 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305463 if (LVDSVRE > LVDSVT)
5464 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005465
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005466 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005467
Aaro Koskinen58839b02011-03-13 12:26:23 +02005468 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005469 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005470
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305471 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005472 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005473
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305474 /* HT SR0B[1:0] CR00 */
5475 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005476 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005477 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005478
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305479 /* HBS SR0B[5:4] CR02 */
5480 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005481 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005482 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005483
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305484 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
5485 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005486 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
5487 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
5488 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005489
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305490 /* HRS SR0B[7:6] CR04 */
5491 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005492 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005493 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305495 /* Panel HRS SR2F[1:0] SR2E[7:0] */
5496 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005497 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005498 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005499
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305500 /* HRE SR0C[2] CR05[4:0] */
5501 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005502 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
5503 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005504
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305505 /* Panel HRE SR2F[7:2] */
5506 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005507 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005508
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305509 /* VT SR0A[0] CR07[5][0] CR06 */
5510 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005511 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
5512 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
5513 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005514 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005515
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305516 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
5517 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005518 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
5519 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
5520 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005521 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005522
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305523 /* VBE SR0A[4] CR16 */
5524 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005525 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005526 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005527
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305528 /* VRS SR0A[3] CR7[7][2] CR10 */
5529 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005530 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
5531 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
5532 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005533 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005534
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005535 if (chip_id == XG27) {
5536 /* Panel VRS SR35[2:0] SR34[7:0] */
5537 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
5538 (value & 0x700) >> 8);
5539 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
5540 } else {
5541 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
5542 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
5543 (value & 0x600) >> 9);
5544 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
5545 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
5546 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005547
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305548 /* VRE SR0A[5] CR11[3:0] */
5549 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005550 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
5551 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005552
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305553 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005554 if (chip_id == XG27)
5555 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
5556 (value << 2) & 0xFC);
5557 else
5558 /* SR3F[7] has to be 0, h/w bug */
5559 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
5560 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005561
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305562 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005563
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005564 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005565 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005566 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005567 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005568 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305569 value += 0x10;
5570 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005571
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305572 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005573 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005574 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005575 /* set data, panning = 0, shift left 1 dot*/
5576 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005577
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005578 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005579 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305580
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005581 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305582 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005583
5584}
5585
5586/* --------------------------------------------------------------------- */
5587/* Function : XGI_IsLCDON */
5588/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04005589/* Output : 0 : Skip PSC Control */
5590/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005591/* Description : */
5592/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005593static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005594{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305595 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005596
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305597 tempax = pVBInfo->VBInfo;
5598 if (tempax & SetCRT2ToDualEdge)
5599 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01005600 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305601 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005602
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305603 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005604}
5605
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005606/* --------------------------------------------------------------------- */
5607/* Function : XGI_DisableChISLCD */
5608/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04005609/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005610/* Description : */
5611/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005612static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005613{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305614 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005615
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305616 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005617 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305619 if (tempbx & (EnableChA | DisableChA)) {
5620 if (!(tempah & 0x08)) /* Chk LCDA Mode */
5621 return 0;
5622 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005623
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305624 if (!(tempbx & (EnableChB | DisableChB)))
5625 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005626
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305627 if (tempah & 0x01) /* Chk LCDB Mode */
5628 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005629
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305630 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005631}
5632
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005633/* --------------------------------------------------------------------- */
5634/* Function : XGI_EnableChISLCD */
5635/* Input : */
5636/* Output : 0 -> Not LCD mode */
5637/* Description : */
5638/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005639static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005640{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305641 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005642
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305643 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005644 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305646 if (tempbx & (EnableChA | DisableChA)) {
5647 if (!(tempah & 0x08)) /* Chk LCDA Mode */
5648 return 0;
5649 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005650
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305651 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04005652 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005653
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305654 if (tempah & 0x01) /* Chk LCDB Mode */
5655 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005656
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305657 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005658}
5659
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005660static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
5661 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305662 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005663{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005664 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005665
Peter Huewe6896b942012-02-09 21:11:46 +01005666 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5667 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305668 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005669 if (!(pVBInfo->VBInfo &
5670 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005671 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305672 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5673 tempah = 0x7F; /* Disable Channel A */
Peter Huewea3d675c2012-02-09 21:11:47 +01005674 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005675 /* Disable Channel B */
5676 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005677
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305678 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005679 /* force to disable Cahnnel */
5680 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005681
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305682 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005683 /* Force to disable Channel B */
5684 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305685 }
5686 }
5687 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005688
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005689 /* disable part4_1f */
5690 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005691
Peter Huewe6896b942012-02-09 21:11:46 +01005692 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005693 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305694 || (XGI_DisableChISLCD(pVBInfo))
5695 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005696 /* LVDS Driver power down */
5697 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305698 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005699
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305700 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01005701 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305702 | SetSimuScanMode))) {
5703 if (pVBInfo->SetFlag & GatingCRT)
5704 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005705 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305706 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005707
Peter Huewea3d675c2012-02-09 21:11:47 +01005708 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305709 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01005710 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005711 /* Power down */
5712 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305713 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005714
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005715 /* disable TV as primary VGA swap */
5716 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005717
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305718 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02005719 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005720
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005721 if ((pVBInfo->SetFlag & DisableChB) ||
5722 (pVBInfo->VBInfo &
5723 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01005724 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005725 (pVBInfo->VBInfo &
5726 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005727 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005728
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005729 if ((pVBInfo->SetFlag & DisableChB) ||
5730 (pVBInfo->VBInfo &
5731 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01005732 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005733 (pVBInfo->VBInfo &
5734 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
5735 /* save Part1 index 0 */
5736 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
5737 /* BTDAC = 1, avoid VB reset */
5738 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
5739 /* disable CRT2 */
5740 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
5741 /* restore Part1 index 0 */
5742 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305743 }
5744 } else { /* {301} */
5745 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005746 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
5747 /* Disable CRT2 */
5748 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
5749 /* Disable TV asPrimary VGA swap */
5750 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305751 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005752
Peter Huewea3d675c2012-02-09 21:11:47 +01005753 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305754 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005755 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305756 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005757}
5758
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005759/* --------------------------------------------------------------------- */
5760/* Function : XGI_GetTVPtrIndex */
5761/* Input : */
5762/* Output : */
5763/* Description : bx 0 : ExtNTSC */
5764/* 1 : StNTSC */
5765/* 2 : ExtPAL */
5766/* 3 : StPAL */
5767/* 4 : ExtHiTV */
5768/* 5 : StHiTV */
5769/* 6 : Ext525i */
5770/* 7 : St525i */
5771/* 8 : Ext525p */
5772/* 9 : St525p */
5773/* A : Ext750p */
5774/* B : St750p */
5775/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005776static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005777{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305778 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005779
Peter Huewe599801f2012-02-09 21:11:45 +01005780 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305781 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01005782 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305783 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01005784 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305785 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01005786 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305787 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01005788 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305789 tempbx = 10;
5790 if (pVBInfo->TVInfo & TVSimuMode)
5791 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005792
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305793 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005794}
5795
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005796/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005797/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005798/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005799/* Output : bx 0 : NTSC */
5800/* 1 : PAL */
5801/* 2 : PALM */
5802/* 3 : PALN */
5803/* 4 : NTSC1024x768 */
5804/* 5 : PAL-M 1024x768 */
5805/* 6-7: reserved */
5806/* cl 0 : YFilter1 */
5807/* 1 : YFilter2 */
5808/* ch 0 : 301A */
5809/* 1 : 301B/302B/301LV/302LV */
5810/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005811/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005812static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
5813 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005814{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005815 *tempbx = 0;
5816 *tempcl = 0;
5817 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005818
Peter Huewe599801f2012-02-09 21:11:45 +01005819 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005820 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005821
Peter Huewe599801f2012-02-09 21:11:45 +01005822 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005823 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005824
Peter Huewe599801f2012-02-09 21:11:45 +01005825 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005826 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005827
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005828 if (pVBInfo->TVInfo & NTSC1024x768) {
5829 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01005830 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005831 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305832 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005833
Peter Huewe6896b942012-02-09 21:11:46 +01005834 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5835 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005836 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
5837 & TVSimuMode)) {
5838 *tempbx += 8;
5839 *tempcl += 1;
5840 }
5841 }
5842
Peter Huewe6896b942012-02-09 21:11:46 +01005843 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5844 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005845 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005846}
5847
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005848static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005849{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305850 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005851
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305852 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005853
Peter Huewe6896b942012-02-09 21:11:46 +01005854 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5855 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005856 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305857 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
5858 tempbl = 0;
5859 tempbh = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005860
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305861 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
5862 tempbl = pVBInfo->XGI_TVDelayList[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005863
Peter Huewe6896b942012-02-09 21:11:46 +01005864 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
5865 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305866 | VB_XGI301C))
5867 tempbl = pVBInfo->XGI_TVDelayList2[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005868
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305869 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5870 tempbl = tempbl >> 4;
Peter Huewea3d675c2012-02-09 21:11:47 +01005871 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005872 /* Get LCD Delay */
5873 index = XGI_GetLCDCapPtr(pVBInfo);
5874 tempbh = pVBInfo->LCDCapList[index].
5875 LCD_DelayCompensation;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005876
Peter Huewea3d675c2012-02-09 21:11:47 +01005877 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305878 tempbl = tempbh;
5879 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005880
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305881 tempbl &= 0x0F;
5882 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02005883 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305885 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
5886 | SetCRT2ToTV)) { /* Channel B */
5887 tempah &= 0xF0;
5888 tempah |= tempbl;
5889 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005890
Peter Huewea3d675c2012-02-09 21:11:47 +01005891 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) { /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305892 tempah &= 0x0F;
5893 tempah |= tempbh;
5894 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005895 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305896 }
5897 } else if (pVBInfo->IF_DEF_LVDS == 1) {
5898 tempbl = 0;
5899 tempbh = 0;
5900 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005901 /* / Get LCD Delay */
5902 tempah = pVBInfo->LCDCapList[
5903 XGI_GetLCDCapPtr(pVBInfo)].
5904 LCD_DelayCompensation;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305905 tempah &= 0x0f;
5906 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005907 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305908 tempah);
5909 }
5910 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005911}
5912
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005913static void XGI_SetLCDCap_A(unsigned short tempcx,
5914 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005915{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305916 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005917
Aaro Koskinen58839b02011-03-13 12:26:23 +02005918 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005919
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305920 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005921 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005922 /* Enable Dither */
5923 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005924 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305925 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005926 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305927 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005928 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305929 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005930}
5931
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005932/* --------------------------------------------------------------------- */
5933/* Function : XGI_SetLCDCap_B */
5934/* Input : cx -> LCD Capability */
5935/* Output : */
5936/* Description : */
5937/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005938static void XGI_SetLCDCap_B(unsigned short tempcx,
5939 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005940{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305941 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005942 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305943 (unsigned short) (((tempcx & 0x00ff) >> 6)
5944 | 0x0c));
5945 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005946 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305947 (unsigned short) (((tempcx & 0x00ff) >> 6)
5948 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005949}
5950
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02005951static void XGI_LongWait(struct vb_device_info *pVBInfo)
5952{
5953 unsigned short i;
5954
5955 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5956
5957 if (!(i & 0xC0)) {
5958 for (i = 0; i < 0xFFFF; i++) {
5959 if (!(inb(pVBInfo->P3da) & 0x08))
5960 break;
5961 }
5962
5963 for (i = 0; i < 0xFFFF; i++) {
5964 if ((inb(pVBInfo->P3da) & 0x08))
5965 break;
5966 }
5967 }
5968}
5969
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005970static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005971{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305972 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005973
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305974 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005975
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005976 /* disable down spectrum D[4] */
5977 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305978 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005979 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305980 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005981
Aaro Koskinen8104e322011-03-13 12:26:22 +02005982 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305983 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005984 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305985 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005986 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305987 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005988 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305989 pVBInfo->LCDCapList[index].Spectrum_34);
5990 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005991 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005992}
5993
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005994static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5995{
5996 unsigned short tempcx;
5997
5998 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5999
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006000 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01006001 (VB_SIS301B |
6002 VB_SIS302B |
6003 VB_SIS301LV |
6004 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006005 VB_XGI301C)) { /* 301LV/302LV only */
6006 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01006007 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006008 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006009 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006010 (unsigned char) (tempcx & 0x1F));
6011 }
6012 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006013 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006014 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
6015 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
6016 | EnablePLLSPLOW)) >> 8));
6017 }
6018
Peter Huewe6896b942012-02-09 21:11:46 +01006019 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6020 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006021 if (pVBInfo->VBInfo & SetCRT2ToLCD)
6022 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01006023 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006024 XGI_SetLCDCap_A(tempcx, pVBInfo);
6025
Peter Huewe6896b942012-02-09 21:11:46 +01006026 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006027 if (tempcx & EnableSpectrum)
6028 SetSpectrum(pVBInfo);
6029 }
6030 } else {
6031 /* LVDS,CH7017 */
6032 XGI_SetLCDCap_A(tempcx, pVBInfo);
6033 }
6034}
6035
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006036/* --------------------------------------------------------------------- */
6037/* Function : XGI_SetAntiFlicker */
6038/* Input : */
6039/* Output : */
6040/* Description : Set TV Customized Param. */
6041/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006042static void XGI_SetAntiFlicker(unsigned short ModeNo,
6043 unsigned short ModeIdIndex,
6044 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006045{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306046 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006047
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306048 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006049
Peter Huewe599801f2012-02-09 21:11:45 +01006050 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306051 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006052
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306053 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6054 tempbx &= 0xFE;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006055 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306056 tempbx += index;
6057 tempah = TVAntiFlickList[tempbx];
6058 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006059
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006060 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006061}
6062
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006063static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6064 unsigned short ModeIdIndex,
6065 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006066{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306067 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006068
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306069 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306071 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6072 tempbx &= 0xFE;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006073 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306074 tempbx += index;
6075 tempah = TVEdgeList[tempbx];
6076 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006077
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006078 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006079}
6080
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006081static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006082{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306083 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006084
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306085 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006086
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306087 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306089 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6090 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006091
Aaro Koskinen8104e322011-03-13 12:26:22 +02006092 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306093 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006094 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306095 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006096 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306097 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006098 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306099 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006100}
6101
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006102static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306103 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006104{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306105 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306107 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306109 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306111 switch (tempbx) {
6112 case 0x00:
6113 case 0x04:
6114 filterPtr = NTSCYFilter1;
6115 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006116
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306117 case 0x01:
6118 filterPtr = PALYFilter1;
6119 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306121 case 0x02:
6122 case 0x05:
6123 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306124 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03006125 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306126 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306128 case 0x08:
6129 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306130 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306131 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306132 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03006133 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306134 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306136 default:
6137 return;
6138 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006139
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006140 tempal = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306141 if (tempcl == 0)
6142 index = tempal * 4;
6143 else
6144 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306146 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006147 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
6148 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
6149 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
6150 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306151 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006152 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
6153 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
6154 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
6155 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306156 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006157
Peter Huewe6896b942012-02-09 21:11:46 +01006158 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6159 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006160 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
6161 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
6162 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306163 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006164}
6165
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006166/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006167/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006168/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006169/* Output : */
6170/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006171/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006172static void XGI_OEM310Setting(unsigned short ModeNo,
6173 unsigned short ModeIdIndex,
6174 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006175{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006176 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006177
Peter Huewea3d675c2012-02-09 21:11:47 +01006178 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006179 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006180
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006181 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006182 XGI_SetPhaseIncr(pVBInfo);
6183 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
6184 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006185
Peter Huewe6896b942012-02-09 21:11:46 +01006186 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006187 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306188 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006189}
6190
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006191/* --------------------------------------------------------------------- */
6192/* Function : XGI_SetCRT2ModeRegs */
6193/* Input : */
6194/* Output : */
6195/* Description : Origin code for crt2group */
6196/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02006197static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306198 struct xgi_hw_device_info *HwDeviceExtension,
6199 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006200{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306201 unsigned short tempbl;
6202 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306204 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006205
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306206 tempah = 0;
6207 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006208 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306209 tempah &= ~0x10; /* BTRAMDAC */
6210 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006211
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306212 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6213 | SetCRT2ToLCD)) {
6214 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006215 tempcl = pVBInfo->ModeType;
6216 tempcl -= ModeVGA;
6217 if (tempcl >= 0) {
6218 /* BT Color */
6219 tempah = (0x008 >> tempcl);
6220 if (tempah == 0)
6221 tempah = 1;
6222 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306223 }
6224 if (pVBInfo->VBInfo & SetInSlaveMode)
6225 tempah ^= 0x50; /* BTDAC */
6226 }
6227 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006228
Aaro Koskinen8104e322011-03-13 12:26:22 +02006229 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306230 tempah = 0x08;
6231 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306233 if (pVBInfo->VBInfo & DisableCRT2Display) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006234 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306235 } else {
6236 tempah = 0x00;
6237 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306239 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
Peter Huewea3d675c2012-02-09 21:11:47 +01006240 | SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
6241 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006242 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306243 tempbl &= 0xf7;
6244 tempah |= 0x01;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006245 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306246 tempbl, tempah);
6247 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01006248 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306249 tempbl &= 0xf7;
6250 tempah |= 0x01;
6251 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006252
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006253 if (pVBInfo->VBInfo &
6254 (SetCRT2ToRAMDAC |
6255 SetCRT2ToTV |
6256 SetCRT2ToLCD)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306257 tempbl &= 0xf8;
6258 tempah = 0x01;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006259
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306260 if (!(pVBInfo->VBInfo & SetInSlaveMode))
6261 tempah |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006262
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006263 if (!(pVBInfo->VBInfo &
6264 SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306265 tempah = tempah ^ 0x05;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006266 if (!(pVBInfo->VBInfo &
6267 SetCRT2ToLCD))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306268 tempah = tempah ^ 0x01;
6269 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006270
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006271 if (!(pVBInfo->VBInfo &
6272 SetCRT2ToDualEdge))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306273 tempah |= 0x08;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006274 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306275 0x2e, tempbl, tempah);
6276 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006277 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306278 0x2e, tempbl, tempah);
6279 }
6280 }
6281 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006282 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306283 tempah);
6284 }
6285 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006286
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306287 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01006288 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306289 tempah &= (~0x08);
6290 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
6291 & SetInSlaveMode))) {
6292 tempah |= 0x010;
6293 }
6294 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006295
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306296 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306297 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006298 if (pVBInfo->VBInfo & DriverMode)
6299 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306300 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006301
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006302 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306303 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006304
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306305 if (pVBInfo->LCDInfo & SetLCDDualLink)
6306 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006307
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306308 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306309 if (pVBInfo->TVInfo & RPLLDIV2XO)
6310 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306311 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006312
Peter Huewe255aabd2012-02-09 21:11:44 +01006313 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
6314 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306315 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006316
Peter Huewe255aabd2012-02-09 21:11:44 +01006317 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306318 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006319
Aaro Koskinen8104e322011-03-13 12:26:22 +02006320 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306321 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006322
Peter Huewe6896b942012-02-09 21:11:46 +01006323 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6324 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306325 tempah = 0;
6326 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006327
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306328 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6329 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01006330 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306331 tempah |= 0x04; /* shampoo 0129 */
6332 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006333
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006334 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306335 tempah = 0x00;
6336 tempbl = 0xcf;
6337 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6338 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6339 tempah |= 0x30;
6340 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006341
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006342 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306343 tempah = 0;
6344 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306346 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6347 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6348 tempah |= 0xc0;
6349 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006350 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306351 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006352
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306353 tempah = 0;
6354 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01006355 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306356 tempbl = 0xff;
6357 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
6358 tempah |= 0x80;
6359 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006360
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006361 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006362
Peter Huewe6896b942012-02-09 21:11:46 +01006363 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306364 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006365 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
6366 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306367 }
6368 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006369}
6370
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006371static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306372 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006373{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306374 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006375
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306376 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006377
Peter Huewea3d675c2012-02-09 21:11:47 +01006378 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306379 tempbx = 0x08A0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006380
6381}
6382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306383void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6384 struct vb_device_info *pVBInfo)
6385{
6386
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006387 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006388
6389}
6390
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306391void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6392 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006393{
6394
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006395 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006396
6397}
6398
Bill Pemberton80adad82010-06-17 13:10:51 -04006399unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006400{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306401 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006402
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306403 if (pVBInfo->IF_DEF_LVDS == 1) {
6404 return 1;
6405 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006406 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306407 if ((flag == 1) || (flag == 2))
6408 return 1; /* 301b */
6409 else
6410 return 0;
6411 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006412}
6413
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006414unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
6415 unsigned short ModeNo, unsigned short ModeIdIndex,
6416 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006417{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006418 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
6419 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
6420 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006421
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006422 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006423
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006424 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006425
Aaro Koskinen58839b02011-03-13 12:26:23 +02006426 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006427 index = index >> pVBInfo->SelectCRT2Rate;
6428 index &= 0x0F;
6429
6430 if (pVBInfo->LCDInfo & LCDNonExpanding)
6431 index = 0;
6432
6433 if (index > 0)
6434 index--;
6435
6436 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006437 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006438 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01006439 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
6440 | VB_SIS301LV | VB_SIS302LV
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006441 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006442 /* 301b */
6443 temp = LCDARefreshIndex[
6444 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006445 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006446 temp = LCDRefreshIndex[
6447 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006448
6449 if (index > temp)
6450 index = temp;
6451 } else {
6452 index = 0;
6453 }
6454 }
6455 }
6456
6457 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
6458 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
6459 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006460 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
6461 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006462 index++;
6463 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006464 /* Alan 10/19/2007;
6465 * do the similar adjustment like XGISearchCRT1Rate() */
6466 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
6467 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006468 index++;
6469 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006470 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
6471 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006472 index++;
6473 }
6474 }
6475
6476 i = 0;
6477 do {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006478 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
6479 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006480 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006481 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
6482 Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01006483 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006484 if (temp < pVBInfo->ModeType)
6485 break;
6486 i++;
6487 index--;
6488
6489 } while (index != 0xFFFF);
6490 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
6491 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006492 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
6493 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006494 if (temp & InterlaceMode)
6495 i++;
6496 }
6497 }
6498 i--;
6499 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
6500 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
6501 RefreshRateTableIndex, &i, pVBInfo);
6502 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02006503 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006504}
6505
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006506static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306507 struct xgi_hw_device_info *HwDeviceExtension,
6508 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006509{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006510 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006511
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006512 pVBInfo->SetFlag |= ProgrammingCRT2;
6513 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6514 ModeIdIndex, pVBInfo);
6515 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
6516 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6517 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6518 HwDeviceExtension, pVBInfo);
6519 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6520 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006521}
6522
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02006523static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006524 struct xgi_hw_device_info *HwDeviceExtension,
6525 struct vb_device_info *pVBInfo)
6526{
6527 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
6528
6529 tempbx = pVBInfo->VBInfo;
6530 pVBInfo->SetFlag |= ProgrammingCRT2;
6531 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6532 pVBInfo->SelectCRT2Rate = 4;
6533 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6534 ModeIdIndex, pVBInfo);
6535 XGI_SaveCRT2Info(ModeNo, pVBInfo);
6536 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
6537 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6538 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
6539 RefreshRateTableIndex, pVBInfo);
6540 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
6541 RefreshRateTableIndex, pVBInfo);
6542 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
6543 RefreshRateTableIndex, pVBInfo);
6544 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6545 HwDeviceExtension, pVBInfo);
6546 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
6547 RefreshRateTableIndex, pVBInfo);
6548 XGI_SetTap4Regs(pVBInfo);
6549 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
6550 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6551 HwDeviceExtension, pVBInfo);
6552 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6553 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
6554 XGI_AutoThreshold(pVBInfo);
6555 return 1;
6556}
6557
6558void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
6559{
6560 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
6561 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
6562 0x05, 0x00 };
6563
6564 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
6565
6566 unsigned char CR17, CR63, SR31;
6567 unsigned short temp;
6568 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
6569
6570 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006571 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006572
6573 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006574 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006575 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006576 pVBInfo->P3d4, 0x53) | 0x02));
6577
Aaro Koskinen58839b02011-03-13 12:26:23 +02006578 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
6579 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
6580 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006581
Aaro Koskinen8104e322011-03-13 12:26:22 +02006582 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
6583 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006584
Aaro Koskinen58839b02011-03-13 12:26:23 +02006585 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006586 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006587
Aaro Koskinen58839b02011-03-13 12:26:23 +02006588 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006589 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006590
Aaro Koskinen58839b02011-03-13 12:26:23 +02006591 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006592 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02006593 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006594 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006595
Aaro Koskinen8104e322011-03-13 12:26:22 +02006596 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006597
6598 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006599 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006600
6601 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006602 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006603 CRTCData[i]);
6604
6605 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006606 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006607 CRTCData[i]);
6608
6609 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006610 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006611 CRTCData[i]);
6612
Aaro Koskinen8104e322011-03-13 12:26:22 +02006613 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006614 & 0xE0));
6615
Aaro Koskinen8104e322011-03-13 12:26:22 +02006616 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
6617 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
6618 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006619
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006620 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006621
6622 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006623 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
6624 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
6625 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006626 }
6627
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006628 mdelay(1);
6629
6630 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006631 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006632
6633 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006634 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006635 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006636 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006637
6638 /* alan, avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006639 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006640
6641 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006642 outb(0, (pVBInfo->P3c8 + 1));
6643 outb(0, (pVBInfo->P3c8 + 1));
6644 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006645 }
6646
Aaro Koskinen8104e322011-03-13 12:26:22 +02006647 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
6648 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
6649 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006650
6651 /* [2004/05/11] Vicent */
Aaro Koskinen58839b02011-03-13 12:26:23 +02006652 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006653 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006654 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006655}
6656
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006657static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
6658 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006659 struct vb_device_info *pVBInfo)
6660{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02006661 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006662
Peter Huewe6896b942012-02-09 21:11:46 +01006663 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6664 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006665 if (!(pVBInfo->SetFlag & DisableChA)) {
6666 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006667 /* Power on */
6668 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006669 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006670 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6671 /* Power on */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006672 xgifb_reg_set(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006673 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006674 }
6675 }
6676 }
6677
6678 if (!(pVBInfo->SetFlag & DisableChB)) {
6679 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
6680 & (SetCRT2ToLCD | SetCRT2ToTV
6681 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006682 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006683 pVBInfo->P3c4, 0x32);
6684 tempah &= 0xDF;
6685 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006686 if (!(pVBInfo->VBInfo &
6687 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006688 tempah |= 0x20;
6689 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02006690 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006691 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006692
Aaro Koskinen58839b02011-03-13 12:26:23 +02006693 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006694 pVBInfo->Part1Port, 0x2E);
6695
6696 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006697 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006698 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006699 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006700 }
6701 }
6702
6703 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
6704 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006705 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006706 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01006707 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006708 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006709 if (XGI_EnableChISLCD(pVBInfo) ||
6710 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01006711 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006712 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02006713 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006714 pVBInfo->Part4Port,
6715 0x2A,
6716 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006717 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006718 /* LVDS Driver power on */
6719 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006720 }
6721 }
6722
6723 tempah = 0x00;
6724
6725 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6726 tempah = 0xc0;
6727
6728 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006729 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006730 if (pVBInfo->VBInfo &
6731 SetCRT2ToDualEdge) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006732 tempah = tempah & 0x40;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006733 if (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01006734 XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006735 tempah = tempah ^ 0xC0;
6736
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006737 if (pVBInfo->SetFlag &
6738 DisableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006739 tempah &= 0xBF;
6740
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006741 if (pVBInfo->SetFlag &
6742 DisableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006743 tempah &= 0x7F;
6744
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006745 if (pVBInfo->SetFlag &
6746 EnableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006747 tempah |= 0x40;
6748
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006749 if (pVBInfo->SetFlag &
6750 EnableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006751 tempah |= 0x80;
6752 }
6753 }
6754 }
6755 }
6756
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006757 /* EnablePart4_1F */
6758 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006759
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006760 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006761 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006762 XGI_DisableGatingCRT(HwDeviceExtension,
6763 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006764 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
6765 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006766 }
6767 }
6768 } /* 301 */
6769 else { /* LVDS */
6770 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01006771 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006772 /* enable CRT2 */
6773 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006774
Aaro Koskinen58839b02011-03-13 12:26:23 +02006775 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006776 0x2E);
6777 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006778 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006779
Aaro Koskinendc505562011-03-13 12:26:26 +02006780 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006781 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006782 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006783}
6784
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006785static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
6786 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006787 unsigned short ModeNo, unsigned short ModeIdIndex,
6788 struct vb_device_info *pVBInfo)
6789{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006790 unsigned short StandTableIndex, RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006791
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006792 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006793 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
Aaro Koskineneb9aef12011-11-27 23:03:15 +02006794 outb(pVBInfo->StandTable[StandTableIndex].MISC, pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006795 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
6796 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
6797 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
6798 XGI_ClearExt1Regs(pVBInfo);
6799
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006800 if (HwDeviceExtension->jChipType == XG27) {
6801 if (pVBInfo->IF_DEF_LVDS == 0)
6802 XGI_SetDefaultVCLK(pVBInfo);
6803 }
6804
6805 temp = ~ProgrammingCRT2;
6806 pVBInfo->SetFlag &= temp;
6807 pVBInfo->SelectCRT2Rate = 0;
6808
Peter Huewe6896b942012-02-09 21:11:46 +01006809 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6810 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006811 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006812 | SetInSlaveMode)) {
6813 pVBInfo->SetFlag |= ProgrammingCRT2;
6814 }
6815 }
6816
6817 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6818 ModeIdIndex, pVBInfo);
6819 if (RefreshRateTableIndex != 0xFFFF) {
6820 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
6821 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6822 pVBInfo, HwDeviceExtension);
6823 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
6824 RefreshRateTableIndex, pVBInfo);
6825 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6826 HwDeviceExtension, pVBInfo);
6827 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
6828 RefreshRateTableIndex, pVBInfo);
6829 }
6830
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006831 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006832 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006833 if (temp & 0xA0) {
6834
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006835 if (HwDeviceExtension->jChipType == XG27)
6836 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
6837 RefreshRateTableIndex, pVBInfo);
6838 else
6839 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
6840 RefreshRateTableIndex, pVBInfo);
6841
6842 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
6843 RefreshRateTableIndex);
6844
Aaro Koskinen105d8d02011-08-31 21:46:00 +03006845 xgifb_set_lcd(HwDeviceExtension->jChipType,
6846 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006847
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006848 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006849 xgifb_set_lvds(xgifb_info,
6850 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006851 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006852 }
6853 }
6854
6855 pVBInfo->SetFlag &= (~ProgrammingCRT2);
6856 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
6857 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
6858 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006859 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006860}
6861
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006862unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
6863 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006864 unsigned short ModeNo)
6865{
6866 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006867 struct vb_device_info VBINF;
6868 struct vb_device_info *pVBInfo = &VBINF;
Dmitry Eremin-Solenikov9a801f22012-03-19 21:50:13 +04006869 pVBInfo->BaseAddr = xgifb_info->vga_base;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006870 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006871 pVBInfo->IF_DEF_LCDA = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006872
6873 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
6874 pVBInfo->IF_DEF_YPbPr = 0;
6875 pVBInfo->IF_DEF_HiVision = 0;
6876 pVBInfo->IF_DEF_CRT2Monitor = 0;
6877 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006878 } else {
6879 pVBInfo->IF_DEF_YPbPr = 1;
6880 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02006881 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006882 }
6883
6884 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
6885 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
6886 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
6887 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
6888 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
6889 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
6890 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
6891 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
6892 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
6893 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
6894 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
6895 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
6896 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
Peter Huewe6896b942012-02-09 21:11:46 +01006897 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
6898 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
6899 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
6900 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
6901 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006902
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006903 /* for x86 Linux, XG21 LVDS */
6904 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006905 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006906 pVBInfo->IF_DEF_LVDS = 1;
6907 }
6908 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006909 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
6910 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006911 pVBInfo->IF_DEF_LVDS = 1;
6912 }
6913 }
6914
6915 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
6916 XGI_GetVBType(pVBInfo);
6917
6918 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02006919 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006920 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006921 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006922
6923 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
6924 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
6925
6926 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6927
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006928 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
6929 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
6930 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
6931 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006932 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006933
Peter Huewea3d675c2012-02-09 21:11:47 +01006934 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006935 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006936 ModeIdIndex, pVBInfo);
6937
Peter Huewea3d675c2012-02-09 21:11:47 +01006938 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006939 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6940 HwDeviceExtension, pVBInfo);
6941 }
6942 } else {
Peter Huewe6896b942012-02-09 21:11:46 +01006943 if (!(pVBInfo->VBInfo & SwitchCRT2)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006944 XGI_SetCRT1Group(xgifb_info,
6945 HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006946 ModeIdIndex, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01006947 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006948 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6949 HwDeviceExtension,
6950 pVBInfo);
6951 }
6952 }
6953 }
6954
Peter Huewe6896b942012-02-09 21:11:46 +01006955 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006956 switch (HwDeviceExtension->ujVBChipID) {
6957 case VB_CHIP_301:
6958 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6959 pVBInfo); /*add for CRT2 */
6960 break;
6961
6962 case VB_CHIP_302:
6963 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6964 pVBInfo); /*add for CRT2 */
6965 break;
6966
6967 default:
6968 break;
6969 }
6970 }
6971
6972 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
6973 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
6974 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006975 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006976 } /* !XG20 */
6977 else {
6978 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006979 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006980 ModeIdIndex,
6981 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006982 return 0;
6983
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006984 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01006985 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006986
6987 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03006988 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006989
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006990 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006991
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006992 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6993 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006994
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006995 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006996 }
6997
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006998 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
6999
7000 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7001 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
7002 }
7003
7004 return 1;
7005}