blob: 8f0be88441870de255a591d5644199b163702fc6 [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_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040020 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
21 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
22 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
23 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
24 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
25 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
26 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
27 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
28 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
29 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020030
Bill Pemberton80adad82010-06-17 13:10:51 -040031void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020032{
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +030033 pVBInfo->StandTable = (struct SiS_StandTable_S *) &XGI330_StandTable;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053034 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
35 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
36 pVBInfo->XGINEWUB_CRT1Table
37 = (struct XGI_CRT1TableStruct *) XGI_CRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020038
Peter Huewefc39dcb2012-01-15 19:22:12 +010039 pVBInfo->MCLKData = (struct SiS_MCLKData *) XGI340New_MCLKData;
Aaro Koskinen06587332011-03-13 12:26:10 +020040 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
Peter Huewefc39dcb2012-01-15 19:22:12 +010041 pVBInfo->VCLKData = (struct SiS_VCLKData *) XGI_VCLKData;
42 pVBInfo->VBVCLKData = (struct SiS_VBVCLKData *) XGI_VBVCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053043 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
Peter Huewefc39dcb2012-01-15 19:22:12 +010044 pVBInfo->StResInfo = (struct SiS_StResInfo_S *) XGI330_StResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053045 pVBInfo->ModeResInfo
Peter Huewefc39dcb2012-01-15 19:22:12 +010046 = (struct SiS_ModeResInfo_S *) XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020047
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053048 pVBInfo->pOutputSelect = &XGI330_OutputSelect;
49 pVBInfo->pSoftSetting = &XGI330_SoftSetting;
50 pVBInfo->pSR07 = &XGI330_SR07;
51 pVBInfo->LCDResInfo = 0;
52 pVBInfo->LCDTypeInfo = 0;
53 pVBInfo->LCDInfo = 0;
54 pVBInfo->VBInfo = 0;
55 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020056
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053057 pVBInfo->SR15 = XGI340_SR13;
58 pVBInfo->CR40 = XGI340_cr41;
59 pVBInfo->SR25 = XGI330_sr25;
60 pVBInfo->pSR31 = &XGI330_sr31;
61 pVBInfo->pSR32 = &XGI330_sr32;
62 pVBInfo->CR6B = XGI340_CR6B;
63 pVBInfo->CR6E = XGI340_CR6E;
64 pVBInfo->CR6F = XGI340_CR6F;
65 pVBInfo->CR89 = XGI340_CR89;
66 pVBInfo->AGPReg = XGI340_AGPReg;
67 pVBInfo->SR16 = XGI340_SR16;
68 pVBInfo->pCRCF = &XG40_CRCF;
69 pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053071 pVBInfo->CR49 = XGI330_CR49;
72 pVBInfo->pSR1F = &XGI330_SR1F;
73 pVBInfo->pSR21 = &XGI330_SR21;
74 pVBInfo->pSR22 = &XGI330_SR22;
75 pVBInfo->pSR23 = &XGI330_SR23;
76 pVBInfo->pSR24 = &XGI330_SR24;
77 pVBInfo->pSR33 = &XGI330_SR33;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020078
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053079 pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2;
80 pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D;
81 pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E;
82 pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10;
83 pVBInfo->pRGBSenseData = &XGI330_RGBSenseData;
84 pVBInfo->pVideoSenseData = &XGI330_VideoSenseData;
85 pVBInfo->pYCSenseData = &XGI330_YCSenseData;
86 pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2;
87 pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2;
88 pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053090 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
91 pVBInfo->PALTiming = XGI330_PALTiming;
92 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
93 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
94 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
95 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
96 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
97 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
98 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
99 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
100 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
101 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
102 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
103 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530105 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
106 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
107 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530109 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +0100110 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530111 pVBInfo->LCDCapList = XGI_LCDDLCapList;
112 else
113 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530115 pVBInfo->XGI_TVDelayList = XGI301TVDelayList;
116 pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530118 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530120 if (ChipType >= XG20)
121 pVBInfo->pXGINew_CR97 = &XG20_CR97;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530123 if (ChipType == XG27) {
124 pVBInfo->MCLKData
Peter Huewefc39dcb2012-01-15 19:22:12 +0100125 = (struct SiS_MCLKData *) XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530126 pVBInfo->CR40 = XGI27_cr41;
127 pVBInfo->pXGINew_CR97 = &XG27_CR97;
128 pVBInfo->pSR36 = &XG27_SR36;
129 pVBInfo->pCR8F = &XG27_CR8F;
130 pVBInfo->pCRD0 = XG27_CRD0;
131 pVBInfo->pCRDE = XG27_CRDE;
132 pVBInfo->pSR40 = &XG27_SR40;
133 pVBInfo->pSR41 = &XG27_SR41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530135 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530137 if (ChipType >= XG20) {
138 pVBInfo->pDVOSetting = &XG21_DVOSetting;
139 pVBInfo->pCR2E = &XG21_CR2E;
140 pVBInfo->pCR2F = &XG21_CR2F;
141 pVBInfo->pCR46 = &XG21_CR46;
142 pVBInfo->pCR47 = &XG21_CR47;
143 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200144
145}
146
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800147static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800148 unsigned short ModeIdIndex,
149 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200150{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530151 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530152 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200153
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300154 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200155
Aaro Koskinen8104e322011-03-13 12:26:22 +0200156 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +0300157 tempah = pVBInfo->StandTable->SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200158
Peter Huewea3d675c2012-02-09 21:11:47 +0100159 i = XGI_SetCRT2ToLCDA;
160 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530161 tempah |= 0x01;
162 } else {
163 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
164 if (pVBInfo->VBInfo & SetInSlaveMode)
165 tempah |= 0x01;
166 }
167 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530169 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200170 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200171
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530172 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800173 /* Get SR2,3,4 from file */
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +0300174 SRdata = pVBInfo->StandTable->SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200175 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530176 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200177}
178
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200179static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800180 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 CRTCdata;
183 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200184
Aaro Koskinen58839b02011-03-13 12:26:23 +0200185 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530186 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200187 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200188
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530189 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800190 /* Get CRTC from file */
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +0300191 CRTCdata = pVBInfo->StandTable->CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200192 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530193 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200194}
195
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800196static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800197 unsigned short ModeIdIndex,
198 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200199{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530200 unsigned char ARdata;
201 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200202
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300203 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530205 for (i = 0; i <= 0x13; i++) {
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +0300206 ARdata = pVBInfo->StandTable->ATTR[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530207 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
208 if (i == 0x13) {
Peter Huewea3d675c2012-02-09 21:11:47 +0100209 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530210 ARdata = 0;
211 } else {
212 if (pVBInfo->VBInfo & (SetCRT2ToTV
213 | SetCRT2ToLCD)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800214 if (pVBInfo->VBInfo &
215 SetInSlaveMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530216 ARdata = 0;
217 }
218 }
219 }
220 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200221
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200222 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200223 outb(i, pVBInfo->P3c0); /* set index */
224 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530225 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200226
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200227 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200228 outb(0x14, pVBInfo->P3c0); /* set index */
229 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200230 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200231 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200232}
233
Aaro Koskinena1579612012-04-07 01:14:05 +0300234static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200235{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530236 unsigned char GRdata;
237 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530239 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800240 /* Get GR from file */
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +0300241 GRdata = pVBInfo->StandTable->GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200242 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530243 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200244
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530245 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200246 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530247 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200248 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530249 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200250}
251
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200252static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200253{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530254 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530256 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200257 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200258}
259
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200260static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200261{
262
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200263 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200264 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
265 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200266
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200267 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200268 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
269 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200270
Aaro Koskinendc505562011-03-13 12:26:26 +0200271 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530272 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200273}
274
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200275static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530276 unsigned short ModeIdIndex,
277 unsigned short RefreshRateTableIndex, unsigned short *i,
278 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200279{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530280 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200281
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300282 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530283 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
284 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
285 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200286
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530287 if (pVBInfo->IF_DEF_LVDS == 0) {
288 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
289 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200290
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530291 if (pVBInfo->VBType & VB_XGI301C)
292 tempax |= SupportCRT2in301C;
293 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200294
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800295 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100296 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530297 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200298
Peter Huewe255aabd2012-02-09 21:11:44 +0100299 if (pVBInfo->LCDResInfo != Panel_1280x1024) {
300 if (pVBInfo->LCDResInfo != Panel_1280x960) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800301 if (pVBInfo->LCDInfo &
302 LCDNonExpanding) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530303 if (resinfo >= 9) {
304 tempax = 0;
305 return 0;
306 }
307 }
308 }
309 }
310 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200311
Peter Huewe599801f2012-02-09 21:11:45 +0100312 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Peter Huewe6896b942012-02-09 21:11:46 +0100313 if ((pVBInfo->VBType & VB_SIS301LV) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800314 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Peter Huewe6896b942012-02-09 21:11:46 +0100315 tempax |= SupportYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530316 if (pVBInfo->VBInfo & SetInSlaveMode) {
317 if (resinfo == 4)
318 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200319
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530320 if (resinfo == 3)
321 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200322
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530323 if (resinfo > 7)
324 return 0;
325 }
326 } else {
Peter Huewe6896b942012-02-09 21:11:46 +0100327 tempax |= SupportHiVision;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530328 if (pVBInfo->VBInfo & SetInSlaveMode) {
329 if (resinfo == 4)
330 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530332 if (resinfo == 3) {
333 if (pVBInfo->SetFlag
334 & TVSimuMode)
335 return 0;
336 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200337
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530338 if (resinfo > 7)
339 return 0;
340 }
341 }
342 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800343 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
344 SetCRT2ToSVIDEO |
345 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100346 SetCRT2ToYPbPr525750 |
347 SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530348 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200349
Peter Huewe6896b942012-02-09 21:11:46 +0100350 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
351 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530352 | VB_XGI301C)) {
353 tempax |= SupportTV1024;
354 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200355
Peter Huewe599801f2012-02-09 21:11:45 +0100356 if (!(pVBInfo->VBInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530357 if (modeflag & NoSupportSimuTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800358 if (pVBInfo->VBInfo &
359 SetInSlaveMode) {
360 if (!(pVBInfo->VBInfo &
361 SetNotSimuMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530362 return 0;
363 }
364 }
365 }
366 }
367 }
368 }
369 } else { /* for LVDS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530370 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
371 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200372
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530373 if (resinfo > 0x08)
374 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200375
Peter Huewe255aabd2012-02-09 21:11:44 +0100376 if (pVBInfo->LCDResInfo < Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530377 if (resinfo > 0x07)
378 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530380 if (resinfo == 0x04)
381 return 0; /* 512x384 */
382 }
383 }
384 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200385
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800386 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
387 tempbx; (*i)--) {
388 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
389 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530390 if (infoflag & tempax)
391 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530393 if ((*i) == 0)
394 break;
395 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200396
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530397 for ((*i) = 0;; (*i)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800398 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
399 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530400 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
401 != tempbx) {
402 return 0;
403 }
404
405 if (infoflag & tempax)
406 return 1;
407 }
408 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200409}
410
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200411static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530412 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200413{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530414 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200415
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800416 /* di+0x00 */
417 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530418 sync &= 0xC0;
419 temp = 0x2F;
420 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200421 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200422}
423
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200424static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530425 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200426{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530427 unsigned char data, data1, pushax;
428 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200429
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800430 /* unlock cr0-7 */
431 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530432 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200433 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200434
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530435 data = pVBInfo->TimingH[0].data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200436 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200437
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530438 for (i = 0x01; i <= 0x04; i++) {
439 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200440 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530441 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200442
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530443 for (i = 0x05; i <= 0x06; i++) {
444 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200445 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530446 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200447
Aaro Koskinen58839b02011-03-13 12:26:23 +0200448 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530449 j &= 0x1F;
450 data = pVBInfo->TimingH[0].data[7];
451 data &= 0xE0;
452 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200453 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530455 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200456 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530457 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200458 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200459 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530460 data1 = data;
461 data1 &= 0xE0;
462 data &= 0x1F;
463 if (data == 0) {
464 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200465 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530466 0x0c);
467 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200468 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530469 data = pushax;
470 }
471 data = data - 1;
472 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200473 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200474 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530475 data = data >> 5;
476 data = data + 3;
477 if (data > 7)
478 data = data - 7;
479 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200480 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530481 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200482}
483
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800484static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
485 unsigned short ModeNo,
486 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200487{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530488 unsigned char data;
489 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200490
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530491 for (i = 0x00; i <= 0x01; i++) {
492 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200493 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530494 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200495
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530496 for (i = 0x02; i <= 0x03; i++) {
497 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200498 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530499 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200500
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530501 for (i = 0x04; i <= 0x05; i++) {
502 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200503 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530504 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200505
Aaro Koskinen58839b02011-03-13 12:26:23 +0200506 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530507 j &= 0xC0;
508 data = pVBInfo->TimingV[0].data[6];
509 data &= 0x3F;
510 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200511 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200512
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530513 data = pVBInfo->TimingV[0].data[6];
514 data &= 0x80;
515 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200516
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300517 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530518 i &= DoubleScanMode;
519 if (i)
520 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200521
Aaro Koskinen58839b02011-03-13 12:26:23 +0200522 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530523 j &= 0x5F;
524 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200525 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200526}
527
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200528static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
529 unsigned short RefreshRateTableIndex,
530 struct vb_device_info *pVBInfo,
531 struct xgi_hw_device_info *HwDeviceExtension)
532{
533 unsigned char index, data;
534 unsigned short i;
535
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800536 /* Get index */
537 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200538 index = index & IndexMask;
539
Aaro Koskinen58839b02011-03-13 12:26:23 +0200540 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200541 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200542 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200543
544 for (i = 0; i < 8; i++)
545 pVBInfo->TimingH[0].data[i]
546 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
547
548 for (i = 0; i < 7; i++)
549 pVBInfo->TimingV[0].data[i]
550 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
551
552 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
553
554 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
555
556 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200557 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200558}
559
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200560/* --------------------------------------------------------------------- */
561/* Function : XGI_SetXG21CRTC */
562/* Input : Stand or enhance CRTC table */
563/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
564/* Description : Set LCD timing */
565/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200566static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530567 unsigned short RefreshRateTableIndex,
568 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200569{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300570 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530571 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200572
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300573 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
574 /* Tempax: CR4 HRS */
575 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
576 Tempcx = Tempax; /* Tempcx: HRS */
577 /* SR2E[7:0]->HRS */
578 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200579
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300580 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
581 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
582 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
583 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
584 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800585
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300586 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
587 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200588
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300589 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
590 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
591 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
592 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200593
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300594 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
595 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200596
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300597 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
598 if (Tempax < Tempcx) /* HRE < HRS */
599 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200600
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300601 Temp2 &= 0xFF;
602 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
603 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
604 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
605 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
606 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
607 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
608 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200609
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300610 /* CR10 VRS */
611 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
612 Tempbx = Tempax; /* Tempbx: VRS */
613 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
614 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
615 /* CR7[2][7] VRE */
616 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
617 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
618 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
619 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
620 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
621 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200622
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300623 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
624 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
625 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
626 Tempax &= 0x80;
627 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
628 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
629 /* Tempax: SRA */
630 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
631 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
632 Temp2 = Tempax;
633 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
634 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200635
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300636 /* Tempax: CR11 VRE */
637 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
638 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
639 /* Tempbx: SRA */
640 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
641 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
642 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
643 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
644 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
645 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200646
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300647 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
648 if (Tempax < Temp3) /* VRE < VRS */
649 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200650
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300651 Temp2 &= 0xFF;
652 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
653 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
654 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
655 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
656 Tempbx = (unsigned char) Temp1;
657 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
658 Tempax &= 0x7F;
659 /* SR3F D[7:2]->VRE D[1:0]->VRS */
660 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200661}
662
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800663static void XGI_SetXG27CRTC(unsigned short ModeNo,
664 unsigned short ModeIdIndex,
665 unsigned short RefreshRateTableIndex,
666 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200667{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300668 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200669
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300670 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
671 /* Tempax: CR4 HRS */
672 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
673 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
674 /* SR2E[7:0]->HRS */
675 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200676
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300677 /* SR0B */
678 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
679 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
680 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200681
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300682 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
683 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
684 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200685
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300686 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
687 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
688 Tempax <<= 3; /* Tempax[5]: HRE[5] */
689 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200690
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300691 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
692 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200693
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300694 /* Tempax: CR4 HRS */
695 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
696 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
697 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
698 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200699
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300700 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
701 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
702 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
703 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
704 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
705 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
706 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200707
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300708 /* CR10 VRS */
709 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
710 /* SR34[7:0]->VRS[7:0] */
711 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200712
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300713 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
714 /* CR7[7][2] VRS[9][8] */
715 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
716 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
717 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
718 Tempax >>= 2; /* Tempax[0]: VRS[8] */
719 /* SR35[0]: VRS[8] */
720 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
721 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
722 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
723 /* Tempax: SR0A */
724 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
725 Tempax &= 0x08; /* SR0A[3] VRS[10] */
726 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200727
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300728 /* Tempax: CR11 VRE */
729 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
730 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
731 /* Tempbx: SR0A */
732 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
733 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
734 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
735 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
736 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
737 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
738 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200739
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300740 if (Tempbx <= Tempcx) /* VRE <= VRS */
741 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200742
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300743 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
744 Tempax = (Tempbx << 2) & 0xFF;
745 /* SR3F[7:2]:VRE[5:0] */
746 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
747 Tempax = Tempcx >> 8;
748 /* SR35[2:0]:VRS[10:8] */
749 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200750}
751
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200752static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
753{
754 unsigned char temp;
755
756 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
757 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
758 temp = (temp & 3) << 6;
759 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
760 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
761 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
762 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
763
764}
765
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300766static void xgifb_set_lcd(int chip_id,
767 struct vb_device_info *pVBInfo,
768 unsigned short RefreshRateTableIndex,
769 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200770{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300771 unsigned short Data, Temp;
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400772 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200773
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530774 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200775
Aaro Koskinen8104e322011-03-13 12:26:22 +0200776 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
777 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
778 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
779 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300780
781 if (chip_id == XG27) {
782 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
783 if ((Temp & 0x03) == 0) { /* dual 12 */
784 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
785 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
786 }
787 }
788
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530789 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200790 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
791 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
792 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
793 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530794 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200795
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300796 if (chip_id == XG27) {
797 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530798 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300799 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
800 if (Temp & 0x01) {
801 /* 18 bits FP */
802 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
803 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
804 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530805 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200806
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200807 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200808
Aaro Koskinendc505562011-03-13 12:26:26 +0200809 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
810 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200811
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300812 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
813 if (Data & 0x4000)
814 /* Hsync polarity */
815 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
816 if (Data & 0x8000)
817 /* Vsync polarity */
818 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200819}
820
821/* --------------------------------------------------------------------- */
822/* Function : XGI_UpdateXG21CRTC */
823/* Input : */
824/* Output : CRT1 CRTC */
825/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
826/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800827static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
828 struct vb_device_info *pVBInfo,
829 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200830{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300831 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200832
Aaro Koskinendc505562011-03-13 12:26:26 +0200833 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300834 if (ModeNo == 0x2E &&
835 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
836 RES640x480x60))
837 index = 12;
838 else if (ModeNo == 0x2E && (pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800839 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300840 index = 13;
841 else if (ModeNo == 0x2F)
842 index = 14;
843 else if (ModeNo == 0x50)
844 index = 15;
845 else if (ModeNo == 0x59)
846 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530848 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200849 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530850 pVBInfo->UpdateCRT1[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200851 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530852 pVBInfo->UpdateCRT1[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200853 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530854 pVBInfo->UpdateCRT1[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200855 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530856 pVBInfo->UpdateCRT1[index].CR16);
857 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200858}
859
Aaro Koskinen06465962011-11-27 23:03:06 +0200860static unsigned short XGI_GetResInfo(unsigned short ModeNo,
861 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
862{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300863 /* si+Ext_ResInfo */
864 return pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen06465962011-11-27 23:03:06 +0200865}
866
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200867static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530868 unsigned short ModeNo, unsigned short ModeIdIndex,
869 unsigned short RefreshRateTableIndex,
870 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200871{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400872 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200873
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530874 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200875
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530876 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200877
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300878 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
879 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
880 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530882 if (modeflag & HalfDCLK)
883 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200884
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300885 if (modeflag & HalfDCLK)
886 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200887
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300888 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200889
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300890 if (temp & InterlaceMode)
891 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200892
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300893 if (modeflag & DoubleScanMode)
894 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200895
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530896 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200897
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530898 tempax /= tempcx;
899 tempax -= 1;
900 tempbx -= 1;
901 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200902 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
903 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530904 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200905 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
906 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200907 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530908 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200909 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530910 tempax = 0;
911 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200912
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530913 if (tempbx & 0x01)
914 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530916 if (tempbx & 0x02)
917 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200918
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200919 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200920 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530921 data &= 0xFF;
922 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200923
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530924 if (tempbx & 0x04)
925 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200926
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200927 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200928 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200929}
930
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800931static void XGI_SetCRT1Offset(unsigned short ModeNo,
932 unsigned short ModeIdIndex,
933 unsigned short RefreshRateTableIndex,
934 struct xgi_hw_device_info *HwDeviceExtension,
935 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200936{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530937 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530939 /* GetOffset */
940 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
941 temp = temp >> 8;
942 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530944 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
945 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200946
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530947 if (temp2)
948 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200949
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530950 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200951
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530952 switch (temp2) {
953 case 0:
954 temp2 = 1;
955 break;
956 case 1:
957 temp2 = 2;
958 break;
959 case 2:
960 temp2 = 4;
961 break;
962 case 3:
963 temp2 = 4;
964 break;
965 case 4:
966 temp2 = 6;
967 break;
968 case 5:
969 temp2 = 8;
970 break;
971 default:
972 break;
973 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200974
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530975 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
976 temp = temp * temp2 + temp2 / 2;
977 else
978 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200979
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530980 /* SetOffset */
981 DisplayUnit = temp;
982 temp2 = temp;
983 temp = temp >> 8; /* ah */
984 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200985 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530986 i &= 0xF0;
987 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200988 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200989
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530990 temp = (unsigned char) temp2;
991 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200992 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200993
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530994 /* SetDisplayUnit */
995 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
996 temp2 &= InterlaceMode;
997 if (temp2)
998 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200999
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301000 DisplayUnit = DisplayUnit << 5;
1001 ah = (DisplayUnit & 0xff00) >> 8;
1002 al = DisplayUnit & 0x00ff;
1003 if (al == 0)
1004 ah += 1;
1005 else
1006 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001007
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301008 if (HwDeviceExtension->jChipType >= XG20)
1009 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1010 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001011
Aaro Koskinen8104e322011-03-13 12:26:22 +02001012 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001013}
1014
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001015static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1016 unsigned short ModeIdIndex,
1017 unsigned short RefreshRateTableIndex,
1018 struct xgi_hw_device_info *HwDeviceExtension,
1019 struct vb_device_info *pVBInfo)
1020{
Peter Huewe6896b942012-02-09 21:11:46 +01001021 unsigned short LCDXlat1VCLK[4] = { VCLK65_315 + 2,
1022 VCLK65_315 + 2,
1023 VCLK65_315 + 2,
1024 VCLK65_315 + 2 };
1025 unsigned short LCDXlat2VCLK[4] = { VCLK108_2_315 + 5,
1026 VCLK108_2_315 + 5,
1027 VCLK108_2_315 + 5,
1028 VCLK108_2_315 + 5 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001029 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
Peter Huewe6896b942012-02-09 21:11:46 +01001030 unsigned short LVDSXlat2VCLK[4] = { VCLK65_315 + 2,
1031 VCLK65_315 + 2,
1032 VCLK65_315 + 2,
1033 VCLK65_315 + 2 };
1034 unsigned short LVDSXlat3VCLK[4] = { VCLK65_315 + 2,
1035 VCLK65_315 + 2,
1036 VCLK65_315 + 2,
1037 VCLK65_315 + 2 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001038
1039 unsigned short CRT2Index, VCLKIndex;
1040 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001041
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001042 /* si+Ext_ResInfo */
1043 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1044 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1045 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001046
1047 if (pVBInfo->IF_DEF_LVDS == 0) {
1048 CRT2Index = CRT2Index >> 6; /* for LCD */
Peter Huewea3d675c2012-02-09 21:11:47 +01001049 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
Peter Huewe255aabd2012-02-09 21:11:44 +01001050 if (pVBInfo->LCDResInfo != Panel_1024x768)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001051 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1052 else
1053 VCLKIndex = LCDXlat1VCLK[CRT2Index];
Peter Huewe599801f2012-02-09 21:11:45 +01001054 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001055 if (pVBInfo->SetFlag & RPLLDIV2XO) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001056 VCLKIndex = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001057 VCLKIndex += 25;
1058 } else {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001059 VCLKIndex = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001060 VCLKIndex += 25;
1061 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001062
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001063 if (pVBInfo->SetFlag & TVSimuMode) {
1064 if (modeflag & Charx8Dot) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001065 VCLKIndex = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001066 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001067 } else {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001068 VCLKIndex = TVCLKBASE_315 + HiTVTextVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001069 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001070 }
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001071 }
1072
1073 /* 301lv */
Peter Huewe6896b942012-02-09 21:11:46 +01001074 if ((pVBInfo->VBType & VB_SIS301LV) &&
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001075 !(pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Peter Huewe6896b942012-02-09 21:11:46 +01001076 if (pVBInfo->VBExtInfo == YPbPr750p)
Peter Huewea3d675c2012-02-09 21:11:47 +01001077 VCLKIndex = XGI_YPbPr750pVCLK;
Peter Huewe6896b942012-02-09 21:11:46 +01001078 else if (pVBInfo->VBExtInfo == YPbPr525p)
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001079 VCLKIndex = YPbPr525pVCLK;
1080 else if (pVBInfo->SetFlag & RPLLDIV2XO)
1081 VCLKIndex = YPbPr525iVCLK_2;
1082 else
1083 VCLKIndex = YPbPr525iVCLK;
1084 }
1085 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
1086 if (pVBInfo->SetFlag & RPLLDIV2XO) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001087 VCLKIndex = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001088 VCLKIndex += 25;
1089 } else {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001090 VCLKIndex = TVCLKBASE_315 + TVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001091 VCLKIndex += 25;
1092 }
1093 } else { /* for CRT2 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001094 /* di+Ext_CRTVCLK */
1095 VCLKIndex = pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001096 Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001097 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001098 }
1099 } else { /* LVDS */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001100 VCLKIndex = CRT2Index;
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001101 VCLKIndex = VCLKIndex >> 6;
Peter Huewe255aabd2012-02-09 21:11:44 +01001102 if ((pVBInfo->LCDResInfo == Panel_800x600) ||
1103 (pVBInfo->LCDResInfo == Panel_320x480))
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001104 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
Peter Huewe255aabd2012-02-09 21:11:44 +01001105 else if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1106 (pVBInfo->LCDResInfo == Panel_1024x768x75))
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001107 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1108 else
1109 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001110 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001111
1112 return VCLKIndex;
1113}
1114
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001115static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1116 unsigned short ModeIdIndex,
1117 struct xgi_hw_device_info *HwDeviceExtension,
1118 unsigned short RefreshRateTableIndex,
1119 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001120{
Bill Pemberton108afbf2010-06-17 13:10:47 -04001121 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301122 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301124 if (pVBInfo->IF_DEF_LVDS == 1) {
1125 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001126 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001127 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1128 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301129 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001130 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301131 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001132 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +01001133 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1134 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01001135 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301136 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1137 RefreshRateTableIndex, HwDeviceExtension,
1138 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001139 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001140 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301141 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001142 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301143 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001144 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1145 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301146 } else {
1147 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001148 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001149 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1150 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301151 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001152 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301153 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001154 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301155 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001156
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301157 if (HwDeviceExtension->jChipType >= XG20) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001158 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1159 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001160 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001161 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001162 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301163 index = data;
1164 index &= 0xE0;
1165 data &= 0x1F;
1166 data = data << 1;
1167 data += 1;
1168 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001169 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301170 }
1171 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001172}
1173
Aaro Koskinene85f2032011-11-27 23:03:07 +02001174static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1175{
1176 unsigned char temp;
1177
1178 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1179 temp = (temp & 1) << 6;
1180 /* SR06[6] 18bit Dither */
1181 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1182 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1183 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1184
1185}
1186
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001187static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301188 struct xgi_hw_device_info *HwDeviceExtension,
1189 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001190{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301191 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001192
Aaro Koskinen58839b02011-03-13 12:26:23 +02001193 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301194 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001195 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001196
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001197 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1198 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1199 data &= 0xC0;
1200 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1201 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1202 data |= 0x01;
1203 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301205 if (HwDeviceExtension->jChipType == XG21)
1206 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001207}
1208
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001209static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1210 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1211 struct vb_device_info *pVBInfo)
1212{
1213 unsigned short data, data2 = 0;
1214 short VCLK;
1215
1216 unsigned char index;
1217
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001218 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1219 index &= IndexMask;
1220 VCLK = pVBInfo->VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001221
Aaro Koskinen58839b02011-03-13 12:26:23 +02001222 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001223 data &= 0xf3;
1224 if (VCLK >= 200)
1225 data |= 0x0c; /* VCLK > 200 */
1226
1227 if (HwDeviceExtension->jChipType >= XG20)
1228 data &= ~0x04; /* 2 pixel mode */
1229
Aaro Koskinen8104e322011-03-13 12:26:22 +02001230 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001231
1232 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001233 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001234 data &= 0xE7;
1235 if (VCLK < 200)
1236 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001237 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001238 }
1239
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001240 data2 = 0x00;
1241
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001242 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001243 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001244 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001245
1246}
1247
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001248static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301249 unsigned short ModeNo, unsigned short ModeIdIndex,
1250 unsigned short RefreshRateTableIndex,
1251 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001252{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301253 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1254 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001255
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001256 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1257 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001258
Aaro Koskinen58839b02011-03-13 12:26:23 +02001259 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001260 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001261
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001262 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301263 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001264 data2 |= 0x02;
1265 data3 = pVBInfo->ModeType - ModeVGA;
1266 data3 = data3 << 2;
1267 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301268 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001269
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301270 if (data)
1271 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001272
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001273 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301274 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001275 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001276
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301277 data = 0x0000;
1278 if (infoflag & InterlaceMode) {
1279 if (xres == 1024)
1280 data = 0x0035;
1281 else if (xres == 1280)
1282 data = 0x0048;
1283 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001284
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301285 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001286 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301287 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001288 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301290 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001291 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001292
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301293 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001294
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301295 if (modeflag & LineCompareOff)
1296 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001297
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001298 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301299 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001300 data = data ^ 0x60;
1301 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001302 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001303
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301304 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1305 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001306
Aaro Koskinen58839b02011-03-13 12:26:23 +02001307 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001308
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301309 if (HwDeviceExtension->jChipType == XG27) {
1310 if (data & 0x40)
1311 data = 0x2c;
1312 else
1313 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001314 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001315 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301316 } else if (HwDeviceExtension->jChipType >= XG20) {
1317 if (data & 0x40)
1318 data = 0x33;
1319 else
1320 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001321 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1322 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301323 } else {
1324 if (data & 0x40)
1325 data = 0x2c;
1326 else
1327 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001328 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301329 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001330
1331}
1332
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001333static void XGI_WriteDAC(unsigned short dl,
1334 unsigned short ah,
1335 unsigned short al,
1336 unsigned short dh,
1337 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001338{
1339 unsigned short temp, bh, bl;
1340
1341 bh = ah;
1342 bl = al;
1343
1344 if (dl != 0) {
1345 temp = bh;
1346 bh = dh;
1347 dh = temp;
1348 if (dl == 1) {
1349 temp = bl;
1350 bl = dh;
1351 dh = temp;
1352 } else {
1353 temp = bl;
1354 bl = bh;
1355 bh = temp;
1356 }
1357 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001358 outb((unsigned short) dh, pVBInfo->P3c9);
1359 outb((unsigned short) bh, pVBInfo->P3c9);
1360 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001361}
1362
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001363static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301364 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001365{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001366 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1367 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001368
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001369 outb(0xFF, pVBInfo->P3c6);
1370 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001371
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001372 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301373 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001374
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301375 for (k = 0; k < 3; k++) {
1376 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001377
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301378 if (data & 0x01)
1379 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001380
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301381 if (data & 0x02)
1382 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001383
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001384 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301385 data = data >> 2;
1386 }
1387 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001388
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001389 for (i = 16; i < 32; i++) {
1390 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001391
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001392 for (k = 0; k < 3; k++)
1393 outb(data, pVBInfo->P3c9);
1394 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001395
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001396 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001397
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001398 for (m = 0; m < 9; m++) {
1399 di = si;
1400 bx = si + 0x04;
1401 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001402
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001403 for (n = 0; n < 3; n++) {
1404 for (o = 0; o < 5; o++) {
1405 dh = table[si];
1406 ah = table[di];
1407 al = table[bx];
1408 si++;
1409 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301410 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001411
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001412 si -= 2;
1413
1414 for (o = 0; o < 3; o++) {
1415 dh = table[bx];
1416 ah = table[di];
1417 al = table[si];
1418 si--;
1419 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1420 }
1421
1422 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301423 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001424
1425 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301426 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001427}
1428
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001429static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1430 unsigned short ModeIdIndex,
1431 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001432{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301433 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001434
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001435 /* si+Ext_ResInfo */
1436 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001437
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001438 /* si+Ext_ResInfo */
1439 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001440
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001441 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1442 yres = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001443
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001444 if (modeflag & HalfDCLK)
1445 xres = xres << 1;
1446
1447 if (modeflag & DoubleScanMode)
1448 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001449
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301450 if (xres == 720)
1451 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001452
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301453 pVBInfo->VGAHDE = xres;
1454 pVBInfo->HDE = xres;
1455 pVBInfo->VGAVDE = yres;
1456 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001457}
1458
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001459static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1460 unsigned short ModeIdIndex,
1461 unsigned short RefreshRateTableIndex,
1462 struct vb_device_info *pVBInfo)
1463{
1464 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1465
1466 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1467
1468 tempbx = BX;
1469
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001470 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1471 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001472
1473 tempal = tempal & 0x0f;
1474
1475 if (tempbx <= 1) { /* ExpLink */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001476 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001477
Peter Huewea3d675c2012-02-09 21:11:47 +01001478 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001479 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001480 Ext_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001481 }
1482
1483 if (tempbx & 0x01)
1484 tempal = (tempal >> 4);
1485
1486 tempal = (tempal & 0x0f);
1487 }
1488
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001489 tempcx = LCDLenList[tempbx];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001490
1491 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1492 if ((tempbx == 5) || (tempbx) == 7)
1493 tempcx = LCDDesDataLen2;
1494 else if ((tempbx == 3) || (tempbx == 8))
1495 tempcx = LVDSDesDataLen2;
1496 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001497
1498 switch (tempbx) {
1499 case 0:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001500 case 1:
Aaro Koskinencc5c2ae2011-08-31 21:46:08 +03001501 tempdi = xgifb_epllcd_crt1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001502 break;
1503 case 2:
1504 tempdi = XGI_EPLLCDDataPtr;
1505 break;
1506 case 3:
1507 tempdi = XGI_EPLLCDDesDataPtr;
1508 break;
1509 case 4:
1510 tempdi = XGI_LCDDataTable;
1511 break;
1512 case 5:
1513 tempdi = XGI_LCDDesDataTable;
1514 break;
1515 case 6:
1516 tempdi = XGI_EPLCHLCDRegPtr;
1517 break;
1518 case 7:
1519 case 8:
1520 case 9:
1521 tempdi = NULL;
1522 break;
1523 default:
1524 break;
1525 }
1526
1527 if (tempdi == NULL) /* OEMUtil */
1528 return NULL;
1529
1530 table = tempbx;
1531 i = 0;
1532
1533 while (tempdi[i].PANELID != 0xff) {
1534 tempdx = pVBInfo->LCDResInfo;
1535 if (tempbx & 0x0080) { /* OEMUtil */
1536 tempbx &= (~0x0080);
1537 tempdx = pVBInfo->LCDTypeInfo;
1538 }
1539
1540 if (pVBInfo->LCDInfo & EnableScalingLCD)
1541 tempdx &= (~PanelResInfo);
1542
1543 if (tempdi[i].PANELID == tempdx) {
1544 tempbx = tempdi[i].MASK;
1545 tempdx = pVBInfo->LCDInfo;
1546
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001547 if (modeflag & HalfDCLK)
1548 tempdx |= SetLCDLowResolution;
1549
1550 tempbx &= tempdx;
1551 if (tempbx == tempdi[i].CAP)
1552 break;
1553 }
1554 i++;
1555 }
1556
1557 if (table == 0) {
1558 switch (tempdi[i].DATAPTR) {
1559 case 0:
1560 return &XGI_LVDSCRT11024x768_1_H[tempal];
1561 break;
1562 case 1:
1563 return &XGI_LVDSCRT11024x768_2_H[tempal];
1564 break;
1565 case 2:
1566 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1567 break;
1568 case 3:
1569 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1570 break;
1571 case 4:
1572 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1573 break;
1574 case 5:
1575 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1576 break;
1577 case 6:
1578 return &XGI_LVDSCRT11600x1200_1_H[tempal];
1579 break;
1580 case 7:
1581 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
1582 break;
1583 case 8:
1584 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
1585 break;
1586 case 9:
1587 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
1588 break;
1589 case 10:
1590 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
1591 break;
1592 default:
1593 break;
1594 }
1595 } else if (table == 1) {
1596 switch (tempdi[i].DATAPTR) {
1597 case 0:
1598 return &XGI_LVDSCRT11024x768_1_V[tempal];
1599 break;
1600 case 1:
1601 return &XGI_LVDSCRT11024x768_2_V[tempal];
1602 break;
1603 case 2:
1604 return &XGI_LVDSCRT11280x1024_1_V[tempal];
1605 break;
1606 case 3:
1607 return &XGI_LVDSCRT11280x1024_2_V[tempal];
1608 break;
1609 case 4:
1610 return &XGI_LVDSCRT11400x1050_1_V[tempal];
1611 break;
1612 case 5:
1613 return &XGI_LVDSCRT11400x1050_2_V[tempal];
1614 break;
1615 case 6:
1616 return &XGI_LVDSCRT11600x1200_1_V[tempal];
1617 break;
1618 case 7:
1619 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
1620 break;
1621 case 8:
1622 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
1623 break;
1624 case 9:
1625 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
1626 break;
1627 case 10:
1628 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
1629 break;
1630 default:
1631 break;
1632 }
1633 } else if (table == 2) {
1634 switch (tempdi[i].DATAPTR) {
1635 case 0:
1636 return &XGI_LVDS1024x768Data_1[tempal];
1637 break;
1638 case 1:
1639 return &XGI_LVDS1024x768Data_2[tempal];
1640 break;
1641 case 2:
1642 return &XGI_LVDS1280x1024Data_1[tempal];
1643 break;
1644 case 3:
1645 return &XGI_LVDS1280x1024Data_2[tempal];
1646 break;
1647 case 4:
1648 return &XGI_LVDS1400x1050Data_1[tempal];
1649 break;
1650 case 5:
1651 return &XGI_LVDS1400x1050Data_2[tempal];
1652 break;
1653 case 6:
1654 return &XGI_LVDS1600x1200Data_1[tempal];
1655 break;
1656 case 7:
1657 return &XGI_LVDSNoScalingData[tempal];
1658 break;
1659 case 8:
1660 return &XGI_LVDS1024x768Data_1x75[tempal];
1661 break;
1662 case 9:
1663 return &XGI_LVDS1024x768Data_2x75[tempal];
1664 break;
1665 case 10:
1666 return &XGI_LVDS1280x1024Data_1x75[tempal];
1667 break;
1668 case 11:
1669 return &XGI_LVDS1280x1024Data_2x75[tempal];
1670 break;
1671 case 12:
1672 return &XGI_LVDSNoScalingDatax75[tempal];
1673 break;
1674 default:
1675 break;
1676 }
1677 } else if (table == 3) {
1678 switch (tempdi[i].DATAPTR) {
1679 case 0:
1680 return &XGI_LVDS1024x768Des_1[tempal];
1681 break;
1682 case 1:
1683 return &XGI_LVDS1024x768Des_3[tempal];
1684 break;
1685 case 2:
1686 return &XGI_LVDS1024x768Des_2[tempal];
1687 break;
1688 case 3:
1689 return &XGI_LVDS1280x1024Des_1[tempal];
1690 break;
1691 case 4:
1692 return &XGI_LVDS1280x1024Des_2[tempal];
1693 break;
1694 case 5:
1695 return &XGI_LVDS1400x1050Des_1[tempal];
1696 break;
1697 case 6:
1698 return &XGI_LVDS1400x1050Des_2[tempal];
1699 break;
1700 case 7:
1701 return &XGI_LVDS1600x1200Des_1[tempal];
1702 break;
1703 case 8:
1704 return &XGI_LVDSNoScalingDesData[tempal];
1705 break;
1706 case 9:
1707 return &XGI_LVDS1024x768Des_1x75[tempal];
1708 break;
1709 case 10:
1710 return &XGI_LVDS1024x768Des_3x75[tempal];
1711 break;
1712 case 11:
1713 return &XGI_LVDS1024x768Des_2x75[tempal];
1714 break;
1715 case 12:
1716 return &XGI_LVDS1280x1024Des_1x75[tempal];
1717 break;
1718 case 13:
1719 return &XGI_LVDS1280x1024Des_2x75[tempal];
1720 break;
1721 case 14:
1722 return &XGI_LVDSNoScalingDesDatax75[tempal];
1723 break;
1724 default:
1725 break;
1726 }
1727 } else if (table == 4) {
1728 switch (tempdi[i].DATAPTR) {
1729 case 0:
1730 return &XGI_ExtLCD1024x768Data[tempal];
1731 break;
1732 case 1:
1733 return &XGI_StLCD1024x768Data[tempal];
1734 break;
1735 case 2:
1736 return &XGI_CetLCD1024x768Data[tempal];
1737 break;
1738 case 3:
1739 return &XGI_ExtLCD1280x1024Data[tempal];
1740 break;
1741 case 4:
1742 return &XGI_StLCD1280x1024Data[tempal];
1743 break;
1744 case 5:
1745 return &XGI_CetLCD1280x1024Data[tempal];
1746 break;
1747 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001748 case 7:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001749 return &xgifb_lcd_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001750 break;
1751 case 8:
1752 return &XGI_CetLCD1400x1050Data[tempal];
1753 break;
1754 case 9:
1755 return &XGI_ExtLCD1600x1200Data[tempal];
1756 break;
1757 case 10:
1758 return &XGI_StLCD1600x1200Data[tempal];
1759 break;
1760 case 11:
1761 return &XGI_NoScalingData[tempal];
1762 break;
1763 case 12:
1764 return &XGI_ExtLCD1024x768x75Data[tempal];
1765 break;
1766 case 13:
1767 return &XGI_ExtLCD1024x768x75Data[tempal];
1768 break;
1769 case 14:
1770 return &XGI_CetLCD1024x768x75Data[tempal];
1771 break;
1772 case 15:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001773 case 16:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001774 return &xgifb_lcd_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001775 break;
1776 case 17:
1777 return &XGI_CetLCD1280x1024x75Data[tempal];
1778 break;
1779 case 18:
1780 return &XGI_NoScalingDatax75[tempal];
1781 break;
1782 default:
1783 break;
1784 }
1785 } else if (table == 5) {
1786 switch (tempdi[i].DATAPTR) {
1787 case 0:
1788 return &XGI_ExtLCDDes1024x768Data[tempal];
1789 break;
1790 case 1:
1791 return &XGI_StLCDDes1024x768Data[tempal];
1792 break;
1793 case 2:
1794 return &XGI_CetLCDDes1024x768Data[tempal];
1795 break;
1796 case 3:
Peter Huewe6896b942012-02-09 21:11:46 +01001797 if ((pVBInfo->VBType & VB_SIS301LV) ||
1798 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001799 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
1800 else
1801 return &XGI_ExtLCDDes1280x1024Data[tempal];
1802 break;
1803 case 4:
Peter Huewe6896b942012-02-09 21:11:46 +01001804 if ((pVBInfo->VBType & VB_SIS301LV) ||
1805 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001806 return &XGI_StLCDDLDes1280x1024Data[tempal];
1807 else
1808 return &XGI_StLCDDes1280x1024Data[tempal];
1809 break;
1810 case 5:
Peter Huewe6896b942012-02-09 21:11:46 +01001811 if ((pVBInfo->VBType & VB_SIS301LV) ||
1812 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001813 return &XGI_CetLCDDLDes1280x1024Data[tempal];
1814 else
1815 return &XGI_CetLCDDes1280x1024Data[tempal];
1816 break;
1817 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001818 case 7:
Peter Huewe6896b942012-02-09 21:11:46 +01001819 if ((pVBInfo->VBType & VB_SIS301LV) ||
1820 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001821 return &xgifb_lcddldes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001822 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001823 return &xgifb_lcddes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001824 break;
1825 case 8:
1826 return &XGI_CetLCDDes1400x1050Data[tempal];
1827 break;
1828 case 9:
1829 return &XGI_CetLCDDes1400x1050Data2[tempal];
1830 break;
1831 case 10:
Peter Huewe6896b942012-02-09 21:11:46 +01001832 if ((pVBInfo->VBType & VB_SIS301LV) ||
1833 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001834 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
1835 else
1836 return &XGI_ExtLCDDes1600x1200Data[tempal];
1837 break;
1838 case 11:
Peter Huewe6896b942012-02-09 21:11:46 +01001839 if ((pVBInfo->VBType & VB_SIS301LV) ||
1840 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001841 return &XGI_StLCDDLDes1600x1200Data[tempal];
1842 else
1843 return &XGI_StLCDDes1600x1200Data[tempal];
1844 break;
1845 case 12:
1846 return &XGI_NoScalingDesData[tempal];
1847 break;
1848 case 13:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001849 case 14:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001850 return &xgifb_lcddes_1024x768x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001851 break;
1852 case 15:
1853 return &XGI_CetLCDDes1024x768x75Data[tempal];
1854 break;
1855 case 16:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001856 case 17:
Peter Huewe6896b942012-02-09 21:11:46 +01001857 if ((pVBInfo->VBType & VB_SIS301LV) ||
1858 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001859 return &xgifb_lcddldes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001860 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001861 return &xgifb_lcddes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001862 break;
1863 case 18:
Peter Huewe6896b942012-02-09 21:11:46 +01001864 if ((pVBInfo->VBType & VB_SIS301LV) ||
1865 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001866 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
1867 else
1868 return &XGI_CetLCDDes1280x1024x75Data[tempal];
1869 break;
1870 case 19:
1871 return &XGI_NoScalingDesDatax75[tempal];
1872 break;
1873 default:
1874 break;
1875 }
1876 } else if (table == 6) {
1877 switch (tempdi[i].DATAPTR) {
1878 case 0:
1879 return &XGI_CH7017LV1024x768[tempal];
1880 break;
1881 case 1:
1882 return &XGI_CH7017LV1400x1050[tempal];
1883 break;
1884 default:
1885 break;
1886 }
1887 }
1888 return NULL;
1889}
1890
1891static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
1892 unsigned short ModeIdIndex,
1893 unsigned short RefreshRateTableIndex,
1894 struct vb_device_info *pVBInfo)
1895{
1896 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
1897 struct XGI330_TVDataTablStruct *tempdi = NULL;
1898
1899 tempbx = BX;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001900 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1901 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001902 tempal = tempal & 0x3f;
1903 table = tempbx;
1904
1905 switch (tempbx) {
1906 case 0:
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001907 tempdi = NULL;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001908 break;
1909 case 1:
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001910 tempdi = NULL;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001911 break;
1912 case 2:
Aaro Koskinen0c23b6d2011-08-31 21:46:09 +03001913 case 6:
1914 tempdi = xgifb_chrontel_tv;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001915 break;
1916 case 3:
1917 tempdi = NULL;
1918 break;
1919 case 4:
1920 tempdi = XGI_TVDataTable;
1921 break;
1922 case 5:
1923 tempdi = NULL;
1924 break;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001925 default:
1926 break;
1927 }
1928
1929 if (tempdi == NULL) /* OEMUtil */
1930 return NULL;
1931
1932 tempdx = pVBInfo->TVInfo;
1933
1934 if (pVBInfo->VBInfo & SetInSlaveMode)
1935 tempdx = tempdx | SetTVLockMode;
1936
1937 if (modeflag & HalfDCLK)
1938 tempdx = tempdx | SetTVLowResolution;
1939
1940 i = 0;
1941
1942 while (tempdi[i].MASK != 0xffff) {
1943 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
1944 break;
1945 i++;
1946 }
1947
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001948 /* 07/05/22 */
Aaro Koskinenebe33022011-11-27 23:03:18 +02001949 if (table == 0x04) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001950 switch (tempdi[i].DATAPTR) {
1951 case 0:
1952 return &XGI_ExtPALData[tempal];
1953 break;
1954 case 1:
1955 return &XGI_ExtNTSCData[tempal];
1956 break;
1957 case 2:
1958 return &XGI_StPALData[tempal];
1959 break;
1960 case 3:
1961 return &XGI_StNTSCData[tempal];
1962 break;
1963 case 4:
1964 return &XGI_ExtHiTVData[tempal];
1965 break;
1966 case 5:
1967 return &XGI_St2HiTVData[tempal];
1968 break;
1969 case 6:
1970 return &XGI_ExtYPbPr525iData[tempal];
1971 break;
1972 case 7:
1973 return &XGI_ExtYPbPr525pData[tempal];
1974 break;
1975 case 8:
1976 return &XGI_ExtYPbPr750pData[tempal];
1977 break;
1978 case 9:
1979 return &XGI_StYPbPr525iData[tempal];
1980 break;
1981 case 10:
1982 return &XGI_StYPbPr525pData[tempal];
1983 break;
1984 case 11:
1985 return &XGI_StYPbPr750pData[tempal];
1986 break;
1987 case 12: /* avoid system hang */
1988 return &XGI_ExtNTSCData[tempal];
1989 break;
1990 case 13:
1991 return &XGI_St1HiTVData[tempal];
1992 break;
1993 default:
1994 break;
1995 }
1996 } else if (table == 0x02) {
1997 switch (tempdi[i].DATAPTR) {
1998 case 0:
1999 return &XGI_CHTVUNTSCData[tempal];
2000 break;
2001 case 1:
2002 return &XGI_CHTVONTSCData[tempal];
2003 break;
2004 case 2:
2005 return &XGI_CHTVUPALData[tempal];
2006 break;
2007 case 3:
2008 return &XGI_CHTVOPALData[tempal];
2009 break;
2010 default:
2011 break;
2012 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002013 }
2014 return NULL;
2015}
2016
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002017static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302018 unsigned short RefreshRateTableIndex,
2019 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002020{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302021 unsigned short tempbx;
2022 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302024 tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002025
Peter Huewea3d675c2012-02-09 21:11:47 +01002026 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302027 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2028 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2029 pVBInfo);
2030 pVBInfo->VGAHT = LCDPtr->VGAHT;
2031 pVBInfo->VGAVT = LCDPtr->VGAVT;
2032 pVBInfo->HT = LCDPtr->LCDHT;
2033 pVBInfo->VT = LCDPtr->LCDVT;
2034 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002035
Peter Huewea3d675c2012-02-09 21:11:47 +01002036 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302037 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2038 | EnableScalingLCD))) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002039 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
2040 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302041 pVBInfo->HDE = 1024;
2042 pVBInfo->VDE = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002043 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
2044 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302045 pVBInfo->HDE = 1280;
2046 pVBInfo->VDE = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002047 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302048 pVBInfo->HDE = 1400;
2049 pVBInfo->VDE = 1050;
2050 } else {
2051 pVBInfo->HDE = 1600;
2052 pVBInfo->VDE = 1200;
2053 }
2054 }
2055 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002056}
2057
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002058static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302059 unsigned short RefreshRateTableIndex,
2060 struct xgi_hw_device_info *HwDeviceExtension,
2061 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002062{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302063 unsigned char index;
2064 unsigned short tempbx, i;
2065 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2066 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002067
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002068 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302069 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002070
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002071 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002072
Peter Huewea3d675c2012-02-09 21:11:47 +01002073 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002074 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2075 XGI_GetLcdPtr(tempbx, ModeNo,
2076 ModeIdIndex,
2077 RefreshRateTableIndex,
2078 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002079
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002080 for (i = 0; i < 8; i++)
2081 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302082 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002083
2084 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
2085
2086 tempbx = 1;
2087
Peter Huewea3d675c2012-02-09 21:11:47 +01002088 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002089 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2090 XGI_GetLcdPtr(
2091 tempbx,
2092 ModeNo,
2093 ModeIdIndex,
2094 RefreshRateTableIndex,
2095 pVBInfo);
2096 for (i = 0; i < 7; i++)
2097 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2098 }
2099
2100 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002101}
2102
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002103static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2104{
2105 unsigned char tempal, tempah, tempbl, i;
2106
Aaro Koskinen58839b02011-03-13 12:26:23 +02002107 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002108 tempal = tempah & 0x0F;
2109 tempah = tempah & 0xF0;
2110 i = 0;
2111 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2112
2113 while (tempbl != 0xFF) {
2114 if (tempbl & 0x80) { /* OEMUtil */
2115 tempal = tempah;
2116 tempbl = tempbl & ~(0x80);
2117 }
2118
2119 if (tempal == tempbl)
2120 break;
2121
2122 i++;
2123
2124 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2125 }
2126
2127 return i;
2128}
2129
2130static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2131{
2132 unsigned short tempah, tempal, tempbl, i;
2133
2134 tempal = pVBInfo->LCDResInfo;
2135 tempah = pVBInfo->LCDTypeInfo;
2136
2137 i = 0;
2138 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2139
2140 while (tempbl != 0xFF) {
2141 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2142 tempal = tempah;
2143 tempbl &= ~0x80;
2144 }
2145
2146 if (tempal == tempbl)
2147 break;
2148
2149 i++;
2150 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2151 }
2152
2153 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002154 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002155 pVBInfo->LCDTypeInfo = 0;
2156 i = 0;
2157 }
2158
2159 return i;
2160}
2161
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002162static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2163 unsigned short *VSyncWidth,
2164 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002165{
2166 unsigned short Index;
2167
2168 Index = XGI_GetLCDCapPtr(pVBInfo);
2169 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2170 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2171
2172 return;
2173}
2174
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002175static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302176 unsigned short RefreshRateTableIndex,
2177 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002178{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302179 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2180 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinend00d12f2012-04-07 01:14:10 +03002181 struct XGI_LCDDesStruct *LCDPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302182 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002183
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002184 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen66cface2011-08-31 21:46:13 +03002185 tempbx = 3;
2186 if (pVBInfo->LCDInfo & EnableScalingLCD)
2187 LCDPtr1 =
2188 (struct XGI330_LCDDataDesStruct2 *)
2189 XGI_GetLcdPtr(
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002190 tempbx,
2191 ModeNo,
2192 ModeIdIndex,
2193 RefreshRateTableIndex,
2194 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03002195 else
2196 LCDPtr =
Aaro Koskinend00d12f2012-04-07 01:14:10 +03002197 (struct XGI_LCDDesStruct *)
Aaro Koskinen66cface2011-08-31 21:46:13 +03002198 XGI_GetLcdPtr(
2199 tempbx,
2200 ModeNo,
2201 ModeIdIndex,
2202 RefreshRateTableIndex,
2203 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002204
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002205 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2206 push1 = tempbx;
2207 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002208
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002209 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01002210 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
2211 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002212 tempax = 1024;
2213 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002214 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
2215 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002216 tempax = 1280;
2217 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002218 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002219 tempax = 1400;
2220 tempbx = 1050;
2221 } else {
2222 tempax = 1600;
2223 tempbx = 1200;
2224 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002225
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002226 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2227 pVBInfo->HDE = tempax;
2228 pVBInfo->VDE = tempbx;
2229 pVBInfo->VGAHDE = tempax;
2230 pVBInfo->VGAVDE = tempbx;
2231 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002232
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002233 tempax = pVBInfo->HT;
2234
2235 if (pVBInfo->LCDInfo & EnableScalingLCD)
2236 tempbx = LCDPtr1->LCDHDES;
2237 else
2238 tempbx = LCDPtr->LCDHDES;
2239
2240 tempcx = pVBInfo->HDE;
2241 tempbx = tempbx & 0x0fff;
2242 tempcx += tempbx;
2243
2244 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002245 tempcx -= tempax;
2246
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002247 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002248
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002249 tempcx = tempcx >> 3;
2250 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002251
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002252 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2253 (unsigned short) (tempbx & 0xff));
2254 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2255 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002256
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002257 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002258
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002259 if (pVBInfo->LCDInfo & EnableScalingLCD)
2260 tempbx = LCDPtr1->LCDHRS;
2261 else
2262 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002263
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002264 tempcx = push2;
2265
2266 if (pVBInfo->LCDInfo & EnableScalingLCD)
2267 tempcx = LCDPtr1->LCDHSync;
2268
2269 tempcx += tempbx;
2270
2271 if (tempcx >= tempax)
2272 tempcx -= tempax;
2273
2274 tempax = tempbx & 0x07;
2275 tempax = tempax >> 5;
2276 tempcx = tempcx >> 3;
2277 tempbx = tempbx >> 3;
2278
2279 tempcx &= 0x1f;
2280 tempax |= tempcx;
2281
2282 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2283 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2284 (unsigned short) (tempbx & 0xff));
2285
2286 tempax = pVBInfo->VT;
2287 if (pVBInfo->LCDInfo & EnableScalingLCD)
2288 tempbx = LCDPtr1->LCDVDES;
2289 else
2290 tempbx = LCDPtr->LCDVDES;
2291 tempcx = pVBInfo->VDE;
2292
2293 tempbx = tempbx & 0x0fff;
2294 tempcx += tempbx;
2295 if (tempcx >= tempax)
2296 tempcx -= tempax;
2297
2298 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2299 (unsigned short) (tempbx & 0xff));
2300 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2301 (unsigned short) (tempcx & 0xff));
2302
2303 tempbx = (tempbx >> 8) & 0x07;
2304 tempcx = (tempcx >> 8) & 0x07;
2305
2306 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2307 (unsigned short) ((tempcx << 3)
2308 | tempbx));
2309
2310 tempax = pVBInfo->VT;
2311 if (pVBInfo->LCDInfo & EnableScalingLCD)
2312 tempbx = LCDPtr1->LCDVRS;
2313 else
2314 tempbx = LCDPtr->LCDVRS;
2315
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002316 tempcx = push1;
2317
2318 if (pVBInfo->LCDInfo & EnableScalingLCD)
2319 tempcx = LCDPtr1->LCDVSync;
2320
2321 tempcx += tempbx;
2322 if (tempcx >= tempax)
2323 tempcx -= tempax;
2324
2325 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2326 (unsigned short) (tempbx & 0xff));
2327 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2328 (unsigned short) (tempcx & 0x0f));
2329
2330 tempax = ((tempbx >> 8) & 0x07) << 3;
2331
2332 tempbx = pVBInfo->VGAVDE;
2333 if (tempbx != pVBInfo->VDE)
2334 tempax |= 0x40;
2335
Peter Huewea3d675c2012-02-09 21:11:47 +01002336 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002337 tempax |= 0x40;
2338
2339 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2340 tempax);
2341
2342 tempcx = pVBInfo->VGAVT;
2343 tempbx = pVBInfo->VDE;
2344 tempax = pVBInfo->VGAVDE;
2345 tempcx -= tempax;
2346
2347 temp = tempax; /* 0430 ylshieh */
2348 temp1 = (temp << 18) / tempbx;
2349
2350 tempdx = (unsigned short) ((temp << 18) % tempbx);
2351
2352 if (tempdx != 0)
2353 temp1 += 1;
2354
2355 temp2 = temp1;
2356 push3 = temp2;
2357
2358 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2359 (unsigned short) (temp2 & 0xff));
2360 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2361 (unsigned short) ((temp2 >> 8) & 0xff));
2362
2363 tempbx = (unsigned short) (temp2 >> 16);
2364 tempax = tempbx & 0x03;
2365
2366 tempbx = pVBInfo->VGAVDE;
2367 if (tempbx == pVBInfo->VDE)
2368 tempax |= 0x04;
2369
2370 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2371
2372 if (pVBInfo->VBType & VB_XGI301C) {
2373 temp2 = push3;
2374 xgifb_reg_set(pVBInfo->Part4Port,
2375 0x3c,
2376 (unsigned short) (temp2 & 0xff));
2377 xgifb_reg_set(pVBInfo->Part4Port,
2378 0x3b,
2379 (unsigned short) ((temp2 >> 8) &
2380 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002381 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002382 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2383 ~0xc0,
2384 (unsigned short) ((tempbx &
2385 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002386
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002387 tempcx = pVBInfo->VGAVDE;
2388 if (tempcx == pVBInfo->VDE)
2389 xgifb_reg_and_or(pVBInfo->Part4Port,
2390 0x30, ~0x0c, 0x00);
2391 else
2392 xgifb_reg_and_or(pVBInfo->Part4Port,
2393 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302394 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002395
2396 tempcx = pVBInfo->VGAHDE;
2397 tempbx = pVBInfo->HDE;
2398
2399 temp1 = tempcx << 16;
2400
2401 tempax = (unsigned short) (temp1 / tempbx);
2402
2403 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2404 tempax = 65535;
2405
2406 temp3 = tempax;
2407 temp1 = pVBInfo->VGAHDE << 16;
2408
2409 temp1 /= temp3;
2410 temp3 = temp3 << 16;
2411 temp1 -= 1;
2412
2413 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2414
2415 tempax = (unsigned short) (temp3 & 0xff);
2416 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2417
2418 temp1 = pVBInfo->VGAVDE << 18;
2419 temp1 = temp1 / push3;
2420 tempbx = (unsigned short) (temp1 & 0xffff);
2421
Peter Huewe255aabd2012-02-09 21:11:44 +01002422 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002423 tempbx -= 1;
2424
2425 tempax = ((tempbx >> 8) & 0xff) << 3;
2426 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2427 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2428 (unsigned short) (tempax & 0xff));
2429 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2430 (unsigned short) (tempbx & 0xff));
2431
2432 temp3 = temp3 >> 16;
2433
2434 if (modeflag & HalfDCLK)
2435 temp3 = temp3 >> 1;
2436
2437 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2438 (unsigned short) ((temp3 >> 8) & 0xff));
2439 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2440 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002441}
2442
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002443/* --------------------------------------------------------------------- */
2444/* Function : XGI_GETLCDVCLKPtr */
2445/* Input : */
2446/* Output : al -> VCLK Index */
2447/* Description : */
2448/* --------------------------------------------------------------------- */
2449static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2450 struct vb_device_info *pVBInfo)
2451{
2452 unsigned short index;
2453
Peter Huewea3d675c2012-02-09 21:11:47 +01002454 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002455 index = XGI_GetLCDCapPtr1(pVBInfo);
2456
2457 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2458 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2459 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2460 } else { /* LCDA */
2461 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2462 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2463 }
2464 }
2465 return;
2466}
2467
2468static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2469 unsigned short ModeNo, unsigned short ModeIdIndex,
2470 struct vb_device_info *pVBInfo)
2471{
2472
2473 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002474 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002475
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002476 /* si+Ext_ResInfo */
2477 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002478
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002479 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2480 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002481 index = XGI_GetLCDCapPtr(pVBInfo);
2482 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2483
Peter Huewea3d675c2012-02-09 21:11:47 +01002484 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002485 return tempal;
2486
2487 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002488 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002489 (VB_SIS301B |
2490 VB_SIS302B |
2491 VB_SIS301LV |
2492 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002493 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01002494 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002495 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002496 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002497 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002498 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002499 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002500 if (!(modeflag & Charx8Dot))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002501 tempal = TVCLKBASE_315 + HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002502
2503 }
2504 return tempal;
2505 }
2506
Peter Huewe599801f2012-02-09 21:11:45 +01002507 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002508 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002509 return tempal;
2510 }
2511
Peter Huewe599801f2012-02-09 21:11:45 +01002512 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002513 tempal = YPbPr525pVCLK;
2514 return tempal;
2515 }
2516
2517 tempal = NTSC1024VCLK;
2518
2519 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002520 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002521 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002522 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002523 }
2524
2525 if (pVBInfo->VBInfo & SetCRT2ToTV)
2526 return tempal;
2527 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002528 } /* {End of VB} */
2529
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002530 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002531 tempal = tempal >> 2;
2532 tempal &= 0x03;
2533
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002534 /* for Dot8 Scaling LCD */
2535 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002536 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2537
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002538 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2539 return tempal;
2540}
2541
2542static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
2543 unsigned char *di_1, struct vb_device_info *pVBInfo)
2544{
Peter Huewe6896b942012-02-09 21:11:46 +01002545 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
2546 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002547 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) && (pVBInfo->SetFlag
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002548 & ProgrammingCRT2)) {
2549 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
2550 *di_1 = XGI_VBVCLKData[tempal].SR2C;
2551 }
2552 } else {
2553 *di_0 = XGI_VCLKData[tempal].SR2B;
2554 *di_1 = XGI_VCLKData[tempal].SR2C;
2555 }
2556}
2557
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002558static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302559 unsigned short RefreshRateTableIndex,
2560 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002561{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302562 unsigned char di_0, di_1, tempal;
2563 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002564
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302565 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2566 pVBInfo);
2567 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2568 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002569
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302570 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002571 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302572 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01002573 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302574 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02002575 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
2576 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302577 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02002578 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
2579 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302580 }
2581 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002582}
2583
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002584static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302585 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002586{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302587 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002588
Peter Huewe6896b942012-02-09 21:11:46 +01002589 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
2590 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302591 tempcl = 0;
2592 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002593 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002594
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302595 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002596 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302597 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002598 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302599 if (!(temp & 0x40))
2600 tempcl |= ActiveCRT1;
2601 }
2602 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002603
Aaro Koskinen58839b02011-03-13 12:26:23 +02002604 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302605 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002606
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302607 if (!(temp == 0x08)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002608 /* Check ChannelA by Part1_13 [2003/10/03] */
2609 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302610 if (tempax & 0x04)
2611 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002612
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302613 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002614
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302615 if (!(tempcl & ActiveLCD))
2616 if (temp == 0x01)
2617 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302619 if (temp == 0x04)
2620 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002621
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302622 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002623 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302625 if (!(temp & 0x08))
2626 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002627
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302628 if (!(temp & 0x04))
2629 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002630
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302631 if (temp & 0x02)
2632 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002633
Peter Huewe599801f2012-02-09 21:11:45 +01002634 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302635 if (temp & 0x01)
2636 tempch |= ActiveHiTV;
2637 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002638
Peter Huewe599801f2012-02-09 21:11:45 +01002639 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002640 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302641 pVBInfo->Part2Port,
2642 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002643
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302644 if (temp & 0x10)
2645 tempch |= ActiveYPbPr;
2646 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302648 if (tempch != 0)
2649 tempcl |= ActiveTV;
2650 }
2651 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002652
Aaro Koskinen58839b02011-03-13 12:26:23 +02002653 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302654 if (tempcl & ActiveLCD) {
2655 if ((pVBInfo->SetFlag & ReserveTVOption)) {
2656 if (temp & ActiveTV)
2657 tempcl |= ActiveTV;
2658 }
2659 }
2660 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01002661 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002662 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002663
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302664 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02002665 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302666 } else {
2667 return;
2668 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002669}
2670
Bill Pemberton80adad82010-06-17 13:10:51 -04002671void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002672{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302673 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002674
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302675 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002676 tempbx = VB_SIS302B;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002677 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302678 if (flag != 0x02) {
Peter Huewe6896b942012-02-09 21:11:46 +01002679 tempbx = VB_SIS301;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002680 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302681 if (flag >= 0xB0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002682 tempbx = VB_SIS301B;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302683 if (flag >= 0xC0) {
2684 tempbx = VB_XGI301C;
2685 if (flag >= 0xD0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002686 tempbx = VB_SIS301LV;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302687 if (flag >= 0xE0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002688 tempbx = VB_SIS302LV;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002689 tempah = xgifb_reg_get(
2690 pVBInfo->Part4Port,
2691 0x39);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302692 if (tempah != 0xFF)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002693 tempbx =
2694 VB_XGI301C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302695 }
2696 }
2697 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002698
Peter Huewe6896b942012-02-09 21:11:46 +01002699 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002700 flag = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302701 pVBInfo->Part4Port,
2702 0x23);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002703
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302704 if (!(flag & 0x02))
2705 tempbx = tempbx | VB_NoLCD;
2706 }
2707 }
2708 }
2709 pVBInfo->VBType = tempbx;
2710 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002711}
2712
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002713static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302714 struct xgi_hw_device_info *HwDeviceExtension,
2715 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002716{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302717 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002718
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002719 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302720 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01002721 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302722 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002723
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302724 if (pVBInfo->VBType & 0xFFFF) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002725 /* Check Display Device */
2726 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302727 tempbx = tempbx | temp;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002728 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302729 push = temp;
2730 push = push << 8;
2731 tempax = temp << 8;
2732 tempbx = tempbx | tempax;
Peter Huewea3d675c2012-02-09 21:11:47 +01002733 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302734 | SetInSlaveMode | DisableCRT2Display);
2735 temp = 0xFFFF ^ temp;
2736 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002737
Aaro Koskinen58839b02011-03-13 12:26:23 +02002738 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002739
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302740 if (pVBInfo->IF_DEF_LCDA == 1) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002741
Aaro Koskinen9ffc7e92011-11-27 23:03:14 +02002742 if ((HwDeviceExtension->jChipType >= XG20) ||
2743 (HwDeviceExtension->jChipType >= XG40)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302744 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002745 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002746 (VB_SIS302B |
2747 VB_SIS301LV |
2748 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002749 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302750 if (temp & EnableDualEdge) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002751 tempbx |=
2752 SetCRT2ToDualEdge;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002753
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302754 if (temp & SetToLCDA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002755 tempbx |=
Peter Huewea3d675c2012-02-09 21:11:47 +01002756 XGI_SetCRT2ToLCDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302757 }
2758 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302759 }
2760 }
2761 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002762
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302763 if (pVBInfo->IF_DEF_YPbPr == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002764 /* [Billy] 07/05/04 */
2765 if (((pVBInfo->IF_DEF_LVDS == 0) &&
Peter Huewe6896b942012-02-09 21:11:46 +01002766 ((pVBInfo->VBType & VB_SIS301LV) ||
2767 (pVBInfo->VBType & VB_SIS302LV) ||
Aaro Koskinen83f76a92011-08-31 21:45:58 +03002768 (pVBInfo->VBType & VB_XGI301C)))) {
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02002769 if (temp & SetYPbPr) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302770 if (pVBInfo->IF_DEF_HiVision == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002771 /* shampoo add for new
2772 * scratch */
Aaro Koskinen58839b02011-03-13 12:26:23 +02002773 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302774 pVBInfo->P3d4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002775 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302776 temp &= YPbPrMode;
Peter Huewe599801f2012-02-09 21:11:45 +01002777 tempbx |= SetCRT2ToHiVision;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002778
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302779 if (temp != YPbPrMode1080i) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002780 tempbx &=
Peter Huewe599801f2012-02-09 21:11:45 +01002781 (~SetCRT2ToHiVision);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002782 tempbx |=
Peter Huewe599801f2012-02-09 21:11:45 +01002783 SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302784 }
2785 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302786 }
2787 }
2788 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002789
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302790 tempax = push; /* restore CR31 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002791
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302792 if (pVBInfo->IF_DEF_LVDS == 0) {
2793 if (pVBInfo->IF_DEF_YPbPr == 1) {
2794 if (pVBInfo->IF_DEF_HiVision == 1)
2795 temp = 0x09FC;
2796 else
2797 temp = 0x097C;
2798 } else {
2799 if (pVBInfo->IF_DEF_HiVision == 1)
2800 temp = 0x01FC;
2801 else
2802 temp = 0x017C;
2803 }
2804 } else { /* 3nd party chip */
Aaro Koskinen83f76a92011-08-31 21:45:58 +03002805 temp = SetCRT2ToLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302806 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002807
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302808 if (!(tempbx & temp)) {
2809 tempax |= DisableCRT2Display;
2810 tempbx = 0;
2811 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002812
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302813 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
2814 if (!(pVBInfo->VBType & VB_NoLCD)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002815 if (tempbx & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302816 if (tempbx & SetSimuScanMode)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002817 tempbx &= (~(SetCRT2ToLCD |
2818 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002819 SwitchCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302820 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002821 tempbx &= (~(SetCRT2ToLCD |
2822 SetCRT2ToRAMDAC |
2823 SetCRT2ToTV |
Peter Huewe6896b942012-02-09 21:11:46 +01002824 SwitchCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302825 }
2826 }
2827 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002828
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302829 /* shampoo add */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002830 /* for driver abnormal */
Peter Huewe6896b942012-02-09 21:11:46 +01002831 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302832 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2833 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002834 tempbx &= (0xFF00 |
2835 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002836 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002837 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002838 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302839 }
2840 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002841 tempbx &= (~(SetCRT2ToRAMDAC |
2842 SetCRT2ToLCD |
2843 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302844 }
2845 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302847 if (!(pVBInfo->VBType & VB_NoLCD)) {
2848 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002849 tempbx &= (0xFF00 |
2850 SetCRT2ToLCD |
Peter Huewe6896b942012-02-09 21:11:46 +01002851 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002852 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002853 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302854 }
2855 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002856
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302857 if (tempbx & SetCRT2ToSCART) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002858 tempbx &= (0xFF00 |
2859 SetCRT2ToSCART |
Peter Huewe6896b942012-02-09 21:11:46 +01002860 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002861 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002862 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302863 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002864
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302865 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002866 if (tempbx & SetCRT2ToYPbPr525750)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002867 tempbx &= (0xFF00 |
Peter Huewe6896b942012-02-09 21:11:46 +01002868 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002869 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302870 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302872 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002873 if (tempbx & SetCRT2ToHiVision)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002874 tempbx &= (0xFF00 |
Peter Huewe599801f2012-02-09 21:11:45 +01002875 SetCRT2ToHiVision |
Peter Huewe6896b942012-02-09 21:11:46 +01002876 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002877 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302878 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002879
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302880 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
Peter Huewe6896b942012-02-09 21:11:46 +01002881 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302882 tempbx = DisableCRT2Display;
2883 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302885 if (!(tempbx & DisableCRT2Display)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002886 if ((!(tempbx & DriverMode)) ||
2887 (!(modeflag & CRT2Mode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302888 if (pVBInfo->IF_DEF_LCDA == 1) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002889 if (!(tempbx & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002890 tempbx |= (SetInSlaveMode |
2891 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302892 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302893 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002894
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002895 /* LCD+TV can't support in slave mode
2896 * (Force LCDA+TV->LCDB) */
2897 if ((tempbx & SetInSlaveMode) &&
Peter Huewea3d675c2012-02-09 21:11:47 +01002898 (tempbx & XGI_SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002899 tempbx ^= (SetCRT2ToLCD |
Peter Huewea3d675c2012-02-09 21:11:47 +01002900 XGI_SetCRT2ToLCDA |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002901 SetCRT2ToDualEdge);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302902 pVBInfo->SetFlag |= ReserveTVOption;
2903 }
2904 }
2905 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002906
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302907 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002908}
2909
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002910static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302911 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002912{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302913 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002914
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302915 tempbx = 0;
2916 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002917
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302918 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002919 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2920 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002921
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302922 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002923 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302924 tempbx = temp;
Peter Huewe599801f2012-02-09 21:11:45 +01002925 if (tempbx & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002926 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002927 TVSetPALM |
2928 TVSetPALN |
2929 TVSetPAL);
2930 if (tempbx & TVSetPALM)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002931 /* set to NTSC if PAL-M */
Peter Huewe599801f2012-02-09 21:11:45 +01002932 tempbx &= ~TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302933 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002934 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002935 TVSetNTSCJ |
2936 TVSetPAL);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302937 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302939 if (pVBInfo->IF_DEF_LVDS == 0) {
2940 if (pVBInfo->VBInfo & SetCRT2ToSCART)
Peter Huewe599801f2012-02-09 21:11:45 +01002941 tempbx |= TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302942 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302944 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002945 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002946 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302947 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302949 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002950 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002951
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302952 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002953 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302954 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002955 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302956 }
2957 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002958
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302959 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002960 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2961 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302962 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002963
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302964 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002965 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2966 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302967 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002968
Peter Huewe599801f2012-02-09 21:11:45 +01002969 if (!(tempbx & TVSetPAL) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002970 (modeflag > 13) &&
2971 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302972 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002973
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302974 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002975
Peter Huewe599801f2012-02-09 21:11:45 +01002976 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302977 if (pVBInfo->VBInfo & SetInSlaveMode)
2978 tempbx &= (~RPLLDIV2XO);
2979 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002980 if (tempbx &
Peter Huewe599801f2012-02-09 21:11:45 +01002981 (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302982 tempbx &= (~RPLLDIV2XO);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002983 else if (!(pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002984 (VB_SIS301B |
2985 VB_SIS302B |
2986 VB_SIS301LV |
2987 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002988 VB_XGI301C))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302989 if (tempbx & TVSimuMode)
2990 tempbx &= (~RPLLDIV2XO);
2991 }
2992 }
2993 }
2994 }
2995 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002996}
2997
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002998static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2999 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003000{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303001 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003002
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303003 pVBInfo->LCDResInfo = 0;
3004 pVBInfo->LCDTypeInfo = 0;
3005 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003006
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003007 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3008 /* si+Ext_ResInfo // */
3009 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003010 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303011 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003012
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303013 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01003014 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303016 /* LCD75 [2003/8/22] Vicent */
Peter Huewe255aabd2012-02-09 21:11:44 +01003017 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303018 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003019 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01003020 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303021 tempax &= 0x0F;
3022 else
3023 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303025 if ((resinfo == 6) || (resinfo == 9)) {
3026 if (tempax >= 3)
3027 tempbx |= PanelRef75Hz;
3028 } else if ((resinfo == 7) || (resinfo == 8)) {
3029 if (tempax >= 4)
3030 tempbx |= PanelRef75Hz;
3031 }
3032 }
3033 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303035 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003036
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303037 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003038
Peter Huewea3d675c2012-02-09 21:11:47 +01003039 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303040 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003041
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303042 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003043
Aaro Koskinen58839b02011-03-13 12:26:23 +02003044 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003045
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303046 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003047
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303048 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303050 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303052 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303054 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Peter Huewe6896b942012-02-09 21:11:46 +01003055 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType
Peter Huewea3d675c2012-02-09 21:11:47 +01003056 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303057 tempbx |= SetLCDDualLink;
3058 }
3059 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003060
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303061 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003062 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003063 & SetCRT2ToLCD) && (resinfo == 9) &&
3064 (!(tempbx & EnableScalingLCD)))
Peter Huewe255aabd2012-02-09 21:11:44 +01003065 /* set to center in 1280x1024 LCDB for Panel_1400x1050 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003066 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303067 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003068
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303069 if (pVBInfo->IF_DEF_ExpLink == 1) {
3070 if (modeflag & HalfDCLK) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303071 if (!(tempbx & SetLCDtoNonExpanding)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003072 tempbx |= XGI_EnableLVDSDDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303073 } else {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003074 if (pVBInfo->LCDResInfo == Panel_1024x768) {
3075 if (resinfo == 4) {/* 512x384 */
3076 tempbx |= XGI_EnableLVDSDDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303077 }
3078 }
3079 }
3080 }
3081 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003082
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303083 if (pVBInfo->VBInfo & SetInSlaveMode) {
3084 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01003085 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303086 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01003087 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303088 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303090 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303092 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003093}
3094
Bill Pemberton108afbf2010-06-17 13:10:47 -04003095unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303096 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003097{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003098 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3099 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
3100 break;
3101 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
3102 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303103 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303105 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003106}
3107
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003108static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3109{
3110 unsigned char ujRet = 0;
3111 unsigned char i = 0;
3112
3113 for (i = 0; i < 8; i++) {
3114 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003115 ujRet |= (ujDate >> i) & 1;
3116 }
3117
3118 return ujRet;
3119}
3120
3121/*----------------------------------------------------------------------------*/
3122/* output */
3123/* bl[5] : LVDS signal */
3124/* bl[1] : LVDS backlight */
3125/* bl[0] : LVDS VDD */
3126/*----------------------------------------------------------------------------*/
3127static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3128{
3129 unsigned char CR4A, temp;
3130
Aaro Koskinen58839b02011-03-13 12:26:23 +02003131 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003132 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003133
Aaro Koskinen58839b02011-03-13 12:26:23 +02003134 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003135
3136 temp = XG21GPIODataTransfer(temp);
3137 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003138 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003139 return temp;
3140}
3141
3142/*----------------------------------------------------------------------------*/
3143/* output */
3144/* bl[5] : LVDS signal */
3145/* bl[1] : LVDS backlight */
3146/* bl[0] : LVDS VDD */
3147/*----------------------------------------------------------------------------*/
3148static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3149{
3150 unsigned char CR4A, CRB4, temp;
3151
Aaro Koskinen58839b02011-03-13 12:26:23 +02003152 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003153 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003154
Aaro Koskinen58839b02011-03-13 12:26:23 +02003155 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003156
3157 temp &= 0x0C;
3158 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003159 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003160 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003161 temp |= ((CRB4 & 0x04) << 3);
3162 return temp;
3163}
3164
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02003165/*----------------------------------------------------------------------------*/
3166/* input */
3167/* bl[5] : 1;LVDS signal on */
3168/* bl[1] : 1;LVDS backlight on */
3169/* bl[0] : 1:LVDS VDD on */
3170/* bh: 100000b : clear bit 5, to set bit5 */
3171/* 000010b : clear bit 1, to set bit1 */
3172/* 000001b : clear bit 0, to set bit0 */
3173/*----------------------------------------------------------------------------*/
3174static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3175 struct vb_device_info *pVBInfo)
3176{
3177 unsigned char CR4A, temp;
3178
3179 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3180 tempbh &= 0x23;
3181 tempbl &= 0x23;
3182 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3183
3184 if (tempbh & 0x20) {
3185 temp = (tempbl >> 4) & 0x02;
3186
3187 /* CR B4[1] */
3188 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3189
3190 }
3191
3192 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3193
3194 temp = XG21GPIODataTransfer(temp);
3195 temp &= ~tempbh;
3196 temp |= tempbl;
3197 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
3198}
3199
Aaro Koskinen776115a2011-11-27 23:03:10 +02003200static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3201 struct vb_device_info *pVBInfo)
3202{
3203 unsigned char CR4A, temp;
3204 unsigned short tempbh0, tempbl0;
3205
3206 tempbh0 = tempbh;
3207 tempbl0 = tempbl;
3208 tempbh0 &= 0x20;
3209 tempbl0 &= 0x20;
3210 tempbh0 >>= 3;
3211 tempbl0 >>= 3;
3212
3213 if (tempbh & 0x20) {
3214 temp = (tempbl >> 4) & 0x02;
3215
3216 /* CR B4[1] */
3217 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3218
3219 }
3220 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
3221
3222 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3223 tempbh &= 0x03;
3224 tempbl &= 0x03;
3225 tempbh <<= 2;
3226 tempbl <<= 2; /* GPIOC,GPIOD */
3227 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3228 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
3229}
3230
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003231/* --------------------------------------------------------------------- */
3232/* Function : XGI_XG21SetPanelDelay */
3233/* Input : */
3234/* Output : */
3235/* Description : */
3236/* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
3237/* : bl : 2 ; T2 : the duration signal on and Vdd on */
3238/* : bl : 3 ; T3 : the duration between CPL off and signal off */
3239/* : bl : 4 ; T4 : the duration signal off and Vdd off */
3240/* --------------------------------------------------------------------- */
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003241static void XGI_XG21SetPanelDelay(struct xgifb_video_info *xgifb_info,
3242 unsigned short tempbl,
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003243 struct vb_device_info *pVBInfo)
3244{
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003245 if (tempbl == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003246 mdelay(xgifb_info->lvds_data.PSC_S1);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003247
3248 if (tempbl == 2)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003249 mdelay(xgifb_info->lvds_data.PSC_S2);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003250
3251 if (tempbl == 3)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003252 mdelay(xgifb_info->lvds_data.PSC_S3);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003253
3254 if (tempbl == 4)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003255 mdelay(xgifb_info->lvds_data.PSC_S4);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003256}
3257
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003258static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
3259 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303260 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003261{
3262
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003263 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303264 if (pXGIHWDE->jChipType == XG21) {
3265 if (pVBInfo->IF_DEF_LVDS == 1) {
3266 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003267 /* LVDS VDD on */
3268 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003269 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303270 }
3271 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003272 /* LVDS signal on */
3273 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003274 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003275 /* LVDS backlight on */
3276 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303277 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003278 /* DVO/DVI signal on */
3279 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303280 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003281
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303282 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003283
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303284 if (pXGIHWDE->jChipType == XG27) {
3285 if (pVBInfo->IF_DEF_LVDS == 1) {
3286 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003287 /* LVDS VDD on */
3288 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003289 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303290 }
3291 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003292 /* LVDS signal on */
3293 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003294 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003295 /* LVDS backlight on */
3296 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303297 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003298 /* DVO/DVI signal on */
3299 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303300 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003301
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303302 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003303}
3304
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003305void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
3306 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303307 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003308{
3309
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303310 if (pXGIHWDE->jChipType == XG21) {
3311 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003312 /* LVDS backlight off */
3313 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003314 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303315 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003316 /* DVO/DVI signal off */
3317 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303318 }
3319 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003320
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303321 if (pXGIHWDE->jChipType == XG27) {
3322 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003323 /* LVDS backlight off */
3324 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003325 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303326 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003327
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303328 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003329 /* DVO/DVI signal off */
3330 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303331 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003332
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003333 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003334}
3335
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003336static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003337{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003338 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303339 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003340
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003341 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303342 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003343}
3344
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003345static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003346{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03003347 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003348}
3349
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003350static void XGI_SaveCRT2Info(unsigned short ModeNo,
3351 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003352{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303353 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003354
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003355 /* reserve CR34 for CRT1 Mode No */
3356 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303357 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3358 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003359 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003360}
3361
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003362static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3363 unsigned short ModeIdIndex,
3364 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003365{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303366 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303368 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003369 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3370 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
3371 /* si+St_ModeFlag */
3372 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003373
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003374 if (modeflag & HalfDCLK)
3375 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003376
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003377 if (modeflag & DoubleScanMode)
3378 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303380 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3381 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003382 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003383 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303384 if (yres == 1024)
3385 yres = 1056;
3386 }
3387 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003388
Peter Huewe255aabd2012-02-09 21:11:44 +01003389 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303390 if (yres == 400)
3391 yres = 405;
3392 else if (yres == 350)
3393 yres = 360;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003394
Peter Huewea3d675c2012-02-09 21:11:47 +01003395 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303396 if (yres == 360)
3397 yres = 375;
3398 }
3399 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003400
Peter Huewe255aabd2012-02-09 21:11:44 +01003401 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003402 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303403 if (!(pVBInfo->LCDInfo
3404 & LCDNonExpanding)) {
3405 if (yres == 350)
3406 yres = 357;
3407 else if (yres == 400)
3408 yres = 420;
3409 else if (yres == 480)
3410 yres = 525;
3411 }
3412 }
3413 }
3414 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003415
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303416 if (xres == 720)
3417 xres = 640;
3418 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003419
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303420 pVBInfo->VGAHDE = xres;
3421 pVBInfo->HDE = xres;
3422 pVBInfo->VGAVDE = yres;
3423 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003424}
3425
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003426static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003427{
3428
Peter Huewea3d675c2012-02-09 21:11:47 +01003429 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03003430 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303431 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003432
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303433 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003434}
3435
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003436static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3437 unsigned short ModeIdIndex,
3438 unsigned short RefreshRateTableIndex,
3439 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003440{
3441 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003442 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003443
3444 pVBInfo->RVBHCMAX = 1;
3445 pVBInfo->RVBHCFACT = 1;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003446 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3447 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3448 CRT1Index &= IndexMask;
3449 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[0];
3450 temp2 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
3451 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
3452 tempbx = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[8];
3453 tempcx = (unsigned short)
3454 pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
3455 tempcx &= 0x0100;
3456 tempcx = tempcx << 2;
3457 tempbx |= tempcx;
3458 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003459
3460 if (temp1 & 0x01)
3461 tempbx |= 0x0100;
3462
3463 if (temp1 & 0x20)
3464 tempbx |= 0x0200;
3465 tempax += 5;
3466
3467 if (modeflag & Charx8Dot)
3468 tempax *= 8;
3469 else
3470 tempax *= 9;
3471
3472 pVBInfo->VGAHT = tempax;
3473 pVBInfo->HT = tempax;
3474 tempbx++;
3475 pVBInfo->VGAVT = tempbx;
3476 pVBInfo->VT = tempbx;
3477}
3478
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003479static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303480 unsigned short RefreshRateTableIndex,
3481 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003482{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303483 unsigned short tempax = 0, tempbx, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003484
Peter Huewefc39dcb2012-01-15 19:22:12 +01003485 struct SiS_LCDData *LCDPtr = NULL;
3486 struct SiS_TVData *TVPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003487
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003488 /* si+Ext_ResInfo */
3489 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3490 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303491 pVBInfo->NewFlickerMode = 0;
3492 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003493
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303494 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3495 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3496 pVBInfo);
3497 return;
3498 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003499
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303500 tempbx = 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003501
Peter Huewea3d675c2012-02-09 21:11:47 +01003502 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewefc39dcb2012-01-15 19:22:12 +01003503 LCDPtr = (struct SiS_LCDData *) XGI_GetLcdPtr(tempbx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303504 ModeNo, ModeIdIndex, RefreshRateTableIndex,
3505 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003506
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303507 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
3508 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
3509 pVBInfo->VGAHT = LCDPtr->VGAHT;
3510 pVBInfo->VGAVT = LCDPtr->VGAVT;
3511 pVBInfo->HT = LCDPtr->LCDHT;
3512 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003513
Peter Huewe255aabd2012-02-09 21:11:44 +01003514 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303515 tempax = 1024;
3516 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003517
Peter Huewea3d675c2012-02-09 21:11:47 +01003518 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303519 if (pVBInfo->VGAVDE == 357)
3520 tempbx = 527;
3521 else if (pVBInfo->VGAVDE == 420)
3522 tempbx = 620;
3523 else if (pVBInfo->VGAVDE == 525)
3524 tempbx = 775;
3525 else if (pVBInfo->VGAVDE == 600)
3526 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303527 else
3528 tempbx = 768;
3529 } else
3530 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003531 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303532 tempax = 1024;
3533 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003534 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303535 tempax = 1280;
3536 if (pVBInfo->VGAVDE == 360)
3537 tempbx = 768;
3538 else if (pVBInfo->VGAVDE == 375)
3539 tempbx = 800;
3540 else if (pVBInfo->VGAVDE == 405)
3541 tempbx = 864;
3542 else
3543 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003544 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303545 tempax = 1280;
3546 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003547 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303548 tempax = 1280;
3549 if (pVBInfo->VGAVDE == 350)
3550 tempbx = 700;
3551 else if (pVBInfo->VGAVDE == 400)
3552 tempbx = 800;
3553 else if (pVBInfo->VGAVDE == 1024)
3554 tempbx = 960;
3555 else
3556 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01003557 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303558 tempax = 1400;
3559 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003560
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303561 if (pVBInfo->VGAVDE == 1024) {
3562 tempax = 1280;
3563 tempbx = 1024;
3564 }
Peter Huewe255aabd2012-02-09 21:11:44 +01003565 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303566 tempax = 1600;
3567 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01003568 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303569 if (pVBInfo->VGAVDE == 350)
3570 tempbx = 875;
3571 else if (pVBInfo->VGAVDE == 400)
3572 tempbx = 1000;
3573 }
3574 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003575
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303576 if (pVBInfo->LCDInfo & LCDNonExpanding) {
3577 tempax = pVBInfo->VGAHDE;
3578 tempbx = pVBInfo->VGAVDE;
3579 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003580
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303581 pVBInfo->HDE = tempax;
3582 pVBInfo->VDE = tempbx;
3583 return;
3584 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003585
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303586 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
3587 tempbx = 4;
Peter Huewefc39dcb2012-01-15 19:22:12 +01003588 TVPtr = (struct SiS_TVData *) XGI_GetTVPtr(tempbx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303589 ModeNo, ModeIdIndex, RefreshRateTableIndex,
3590 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003591
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303592 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
3593 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
3594 pVBInfo->VGAHT = TVPtr->VGAHT;
3595 pVBInfo->VGAVT = TVPtr->VGAVT;
3596 pVBInfo->HDE = TVPtr->TVHDE;
3597 pVBInfo->VDE = TVPtr->TVVDE;
3598 pVBInfo->RVBHRS = TVPtr->RVBHRS;
3599 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003600
Peter Huewe599801f2012-02-09 21:11:45 +01003601 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303602 if (resinfo == 0x08)
3603 pVBInfo->NewFlickerMode = 0x40;
3604 else if (resinfo == 0x09)
3605 pVBInfo->NewFlickerMode = 0x40;
3606 else if (resinfo == 0x12)
3607 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003608
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303609 if (pVBInfo->VGAVDE == 350)
3610 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003611
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303612 tempax = ExtHiTVHT;
3613 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003614
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303615 if (pVBInfo->VBInfo & SetInSlaveMode) {
3616 if (pVBInfo->TVInfo & TVSimuMode) {
3617 tempax = StHiTVHT;
3618 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003619
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303620 if (!(modeflag & Charx8Dot)) {
3621 tempax = StHiTextTVHT;
3622 tempbx = StHiTextTVVT;
3623 }
3624 }
3625 }
Peter Huewe599801f2012-02-09 21:11:45 +01003626 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3627 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303628 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
3629 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
3630 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003631
Peter Huewe599801f2012-02-09 21:11:45 +01003632 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303633 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
3634 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01003635 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303636 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
3637 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
3638 if (pVBInfo->TVInfo & NTSC1024x768)
3639 tempax = NTSC1024x768HT;
3640 }
3641 } else {
3642 tempax = PALHT;
3643 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01003644 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303645 tempax = NTSCHT;
3646 tempbx = NTSCVT;
3647 if (pVBInfo->TVInfo & NTSC1024x768)
3648 tempax = NTSC1024x768HT;
3649 }
3650 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003651
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303652 pVBInfo->HT = tempax;
3653 pVBInfo->VT = tempbx;
3654 return;
3655 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003656}
3657
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003658static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303659 unsigned short RefreshRateTableIndex,
3660 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003661{
Bill Pemberton108afbf2010-06-17 13:10:47 -04003662 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003663
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303664 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3665 pVBInfo);
3666 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3667 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003668
Peter Huewe6896b942012-02-09 21:11:46 +01003669 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303670 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003671 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
3672 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
3673 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303674 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003675 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
3676 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303677 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003678
Aaro Koskinen8104e322011-03-13 12:26:22 +02003679 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003680
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303681 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02003682 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303683 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02003684 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003685}
3686
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003687static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
3688 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003689{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003690 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
3691 short index;
3692 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303693
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003694 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01003695 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303696
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003697 if (index < 0)
3698 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303699
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003700 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303701}
3702
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003703static unsigned short XGI_GetOffset(unsigned short ModeNo,
3704 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303705 unsigned short RefreshRateTableIndex,
3706 struct xgi_hw_device_info *HwDeviceExtension,
3707 struct vb_device_info *pVBInfo)
3708{
3709 unsigned short temp, colordepth, modeinfo, index, infoflag,
3710 ColorDepth[] = { 0x01, 0x02, 0x04 };
3711
3712 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003713 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303714
3715 index = (modeinfo >> 8) & 0xFF;
3716
3717 temp = pVBInfo->ScreenOffset[index];
3718
3719 if (infoflag & InterlaceMode)
3720 temp = temp << 1;
3721
3722 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
3723
3724 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
3725 temp = ModeNo - 0x7C;
3726 colordepth = ColorDepth[temp];
3727 temp = 0x6B;
3728 if (infoflag & InterlaceMode)
3729 temp = temp << 1;
3730 return temp * colordepth;
3731 } else {
3732 return temp * colordepth;
3733 }
3734}
3735
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003736static void XGI_SetCRT2Offset(unsigned short ModeNo,
3737 unsigned short ModeIdIndex,
3738 unsigned short RefreshRateTableIndex,
3739 struct xgi_hw_device_info *HwDeviceExtension,
3740 struct vb_device_info *pVBInfo)
3741{
3742 unsigned short offset;
3743 unsigned char temp;
3744
3745 if (pVBInfo->VBInfo & SetInSlaveMode)
3746 return;
3747
3748 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3749 HwDeviceExtension, pVBInfo);
3750 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003751 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003752 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003753 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003754 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003755 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003756}
3757
Randy Dunlap89229672010-08-10 08:46:44 -07003758static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003759{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003760 /* threshold high ,disable auto threshold */
3761 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
3762 /* threshold low default 04h */
3763 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003764}
3765
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003766static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303767 struct xgi_hw_device_info *HwDeviceExtension,
3768 unsigned short RefreshRateTableIndex,
3769 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003770{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303771 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003772
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003773 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3774 CRT1Index &= IndexMask;
3775 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003776
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303777 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3778 HwDeviceExtension, pVBInfo);
3779 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003780
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303781 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003782 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003783
Aaro Koskinen8104e322011-03-13 12:26:22 +02003784 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
3785 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003786}
3787
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003788static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303789 struct xgi_hw_device_info *HwDeviceExtension,
3790 unsigned short RefreshRateTableIndex,
3791 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003792{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303793 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
3794 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003795
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003796 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3797 CRT1Index &= IndexMask;
3798 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3799 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303801 /* bainy change table name */
3802 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003803 /* BTVGA2HT 0x08,0x09 */
3804 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003805 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303806 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003807 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003808 /* BTVGA2HDEE 0x0A,0x0C */
3809 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003810 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303811 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
3812 pushbx = pVBInfo->VGAHDE / 2 + 16;
3813 tempcx = tempcx >> 1;
3814 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3815 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303817 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3818 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003819 tempbx |= ((pVBInfo->
3820 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
3821 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303822 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
3823 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
3824 tempcx &= 0x1F;
3825 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
3826 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3827 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3828 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303830 tempbx += 4;
3831 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303833 if (tempcx > (pVBInfo->VGAHT / 2))
3834 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303836 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003837
Aaro Koskinen8104e322011-03-13 12:26:22 +02003838 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303839 } else {
3840 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003841 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303842 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003843 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003844 /* BTVGA2HDEE 0x0A,0x0C */
3845 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003846 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303847 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
3848 pushbx = pVBInfo->VGAHDE + 16;
3849 tempcx = tempcx >> 1;
3850 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3851 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003852
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303853 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3854 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003855 tempbx |= ((pVBInfo->
3856 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
3857 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303858 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
3859 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
3860 tempcx &= 0x1F;
3861 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
3862 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3863 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3864 tempbx += 16;
3865 tempcx += 16;
3866 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003867
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303868 if (tempcx > pVBInfo->VGAHT)
3869 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003870
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303871 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003872 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303873 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303875 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3876 tempbx = pushbx;
3877 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3878 tempax |= (tempbx & 0xFF00);
3879 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003880 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303881 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003882 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303883 tempcx = (pVBInfo->VGAVT - 1);
3884 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003885
Aaro Koskinen8104e322011-03-13 12:26:22 +02003886 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303887 tempbx = pVBInfo->VGAVDE - 1;
3888 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003889 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303890 temp = ((tempbx & 0xFF00) << 3) >> 8;
3891 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003892 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003893
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303894 tempax = pVBInfo->VGAVDE;
3895 tempbx = pVBInfo->VGAVDE;
3896 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003897 /* BTVGA2VRS 0x10,0x11 */
3898 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3899 /* BTVGA2VRE 0x11 */
3900 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003901
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303902 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3903 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
3904 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003905
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303906 if (temp & 0x04)
3907 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003908
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303909 if (temp & 0x080)
3910 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003911
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303912 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003913
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303914 if (temp & 0x08)
3915 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003916
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303917 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
3918 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3919 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003920
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303921 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003922 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303923 temp = ((tempbx & 0xFF00) >> 8) << 4;
3924 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003925 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303926 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003927
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303928 if (modeflag & DoubleScanMode)
3929 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003930
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303931 if (modeflag & HalfDCLK)
3932 tempax |= 0x40;
3933
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003934 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003935}
3936
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003937static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3938{
3939 unsigned long tempax, tempbx;
3940
3941 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3942 & 0xFFFF;
3943 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3944 tempax = (tempax * pVBInfo->HT) / tempbx;
3945
3946 return (unsigned short) tempax;
3947}
3948
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003949static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303950 struct xgi_hw_device_info *HwDeviceExtension,
3951 unsigned short RefreshRateTableIndex,
3952 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003953{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303954 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
3955 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003956
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003957 /* si+Ext_ResInfo */
3958 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3959 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3960 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3961 CRT1Index &= IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003962
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303963 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3964 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303966 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003967 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303968 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003969
Peter Huewe6896b942012-02-09 21:11:46 +01003970 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303971 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303973 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003974
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303975 if (modeflag & HalfDCLK)
3976 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003977
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303978 tempax = (tempax / tempcx) - 1;
3979 tempbx |= ((tempax & 0x00FF) << 8);
3980 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003981 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003982
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303983 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003984
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303985 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003986 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3987 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303988 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003989
Peter Huewe599801f2012-02-09 21:11:45 +01003990 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003991 if (pVBInfo->VBType & VB_SIS301LV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303992 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
3993 if (resinfo == 7)
3994 temp -= 2;
3995 }
3996 } else if (resinfo == 7) {
3997 temp -= 2;
3998 }
3999 }
4000 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004001
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004002 /* 0x05 Horizontal Display Start */
4003 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4004 /* 0x06 Horizontal Blank end */
4005 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004006
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304007 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4008 if (pVBInfo->VBInfo & SetCRT2ToTV)
4009 tempax = pVBInfo->VGAHT;
4010 else
4011 tempax = XGI_GetVGAHT2(pVBInfo);
4012 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004013
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304014 if (tempax >= pVBInfo->VGAHT)
4015 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304017 if (modeflag & HalfDCLK)
4018 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004019
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304020 tempax = (tempax / tempcx) - 5;
4021 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01004022 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304023 temp = (tempbx & 0x00FF) - 1;
4024 if (!(modeflag & HalfDCLK)) {
4025 temp -= 6;
4026 if (pVBInfo->TVInfo & TVSimuMode) {
4027 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004028 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304029 }
4030 }
4031 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304032 tempbx = (tempbx & 0xFF00) >> 8;
4033 tempcx = (tempcx + tempbx) >> 1;
4034 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304036 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4037 temp -= 1;
4038 if (!(modeflag & HalfDCLK)) {
4039 if ((modeflag & Charx8Dot)) {
4040 temp += 4;
4041 if (pVBInfo->VGAHDE >= 800)
4042 temp -= 6;
4043 }
4044 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004045 } else if (!(modeflag & HalfDCLK)) {
4046 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01004047 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004048 pVBInfo->VGAHDE >= 800) {
4049 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004050 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01004051 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004052 (pVBInfo->LCDInfo & LCDNonExpanding))
4053 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304054 }
4055 }
4056 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004057
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004058 /* 0x07 Horizontal Retrace Start */
4059 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4060 /* 0x08 Horizontal Retrace End */
4061 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004062
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304063 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4064 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004065 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304066 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004067 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304068 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004069 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304070 0x08, 0x03);
4071 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004072 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304073 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004074 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304075 0x08, 0x02);
4076 }
4077 }
4078 }
4079 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004080
Aaro Koskinen8104e322011-03-13 12:26:22 +02004081 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004082 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004083 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004084
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304085 tempbx = pVBInfo->VGAVT;
4086 push1 = tempbx;
4087 tempcx = 0x121;
4088 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304090 if (tempbx == 357)
4091 tempbx = 350;
4092 if (tempbx == 360)
4093 tempbx = 350;
4094 if (tempbx == 375)
4095 tempbx = 350;
4096 if (tempbx == 405)
4097 tempbx = 400;
4098 if (tempbx == 525)
4099 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304101 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004102
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304103 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01004104 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004105 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304106 if (tempbx == 350)
4107 tempbx += 5;
4108 if (tempbx == 480)
4109 tempbx += 5;
4110 }
4111 }
4112 }
4113 tempbx--;
4114 temp = tempbx & 0x00FF;
4115 tempbx--;
4116 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004117 /* 0x10 vertical Blank Start */
4118 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304119 tempbx = push2;
4120 tempbx--;
4121 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004122 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304124 if (tempbx & 0x0100)
4125 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304127 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304129 if (modeflag & DoubleScanMode)
4130 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304132 if (tempbx & 0x0200)
4133 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304135 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004136 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304138 if (tempbx & 0x0400)
4139 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004140
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004141 /* 0x11 Vertival Blank End */
4142 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304143
4144 tempax = push1;
4145 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4146 tempax = tempax >> 2;
4147 push1 = tempax; /* push ax */
4148
4149 if (resinfo != 0x09) {
4150 tempax = tempax << 1;
4151 tempbx += tempax;
4152 }
4153
Peter Huewe599801f2012-02-09 21:11:45 +01004154 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01004155 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004156 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304157 tempbx -= 10;
4158 } else {
4159 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Huewe599801f2012-02-09 21:11:45 +01004160 if (pVBInfo->TVInfo & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004161 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004162 VB_SIS301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004163 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004164 (TVSetYPbPr525p |
4165 TVSetYPbPr750p |
4166 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304167 tempbx += 40;
4168 } else {
4169 tempbx += 40;
4170 }
4171 }
4172 }
4173 }
4174 } else {
4175 tempbx -= 10;
4176 }
4177 } else {
4178 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Huewe599801f2012-02-09 21:11:45 +01004179 if (pVBInfo->TVInfo & TVSetPAL) {
Peter Huewe6896b942012-02-09 21:11:46 +01004180 if (pVBInfo->VBType & VB_SIS301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004181 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004182 (TVSetYPbPr525p |
4183 TVSetYPbPr750p |
4184 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304185 tempbx += 40;
4186 } else {
4187 tempbx += 40;
4188 }
4189 }
4190 }
4191 }
4192 tempax = push1;
4193 tempax = tempax >> 2;
4194 tempax++;
4195 tempax += tempbx;
4196 push1 = tempax; /* push ax */
4197
Peter Huewe599801f2012-02-09 21:11:45 +01004198 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304199 if (tempbx <= 513) {
4200 if (tempax >= 513)
4201 tempbx = 513;
4202 }
4203 }
4204
4205 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004206 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304207 tempbx--;
4208 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004209 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304210
4211 if (tempbx & 0x0100)
4212 tempcx |= 0x0008;
4213
4214 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004215 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304216
4217 tempbx++;
4218
4219 if (tempbx & 0x0100)
4220 tempcx |= 0x0004;
4221
4222 if (tempbx & 0x0200)
4223 tempcx |= 0x0080;
4224
4225 if (tempbx & 0x0400)
4226 tempcx |= 0x0C00;
4227
4228 tempbx = push1; /* pop ax */
4229 temp = tempbx & 0x00FF;
4230 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004231 /* 0x0D vertical Retrace End */
4232 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304233
4234 if (tempbx & 0x0010)
4235 tempcx |= 0x2000;
4236
4237 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004238 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304239 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004240 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304241 tempax = modeflag;
4242 temp = (tempax & 0xFF00) >> 8;
4243
4244 temp = (temp >> 1) & 0x09;
4245
Peter Huewe6896b942012-02-09 21:11:46 +01004246 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304247 temp |= 0x01;
4248
Aaro Koskinen8104e322011-03-13 12:26:22 +02004249 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4250 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4251 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304252
4253 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4254 temp = 0x80;
4255 else
4256 temp = 0x00;
4257
Aaro Koskinen8104e322011-03-13 12:26:22 +02004258 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304259
4260 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004261}
4262
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004263static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304264 unsigned short RefreshRateTableIndex,
4265 struct xgi_hw_device_info *HwDeviceExtension,
4266 struct vb_device_info *pVBInfo)
4267{
4268 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4269 modeflag, resinfo, crt2crtc;
4270 unsigned char *TimingPoint;
4271
4272 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4273
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004274 /* si+Ext_ResInfo */
4275 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4276 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4277 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304278
4279 tempax = 0;
4280
4281 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4282 tempax |= 0x0800;
4283
4284 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4285 tempax |= 0x0400;
4286
4287 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4288 tempax |= 0x0200;
4289
Peter Huewe599801f2012-02-09 21:11:45 +01004290 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304291 tempax |= 0x1000;
4292
Peter Huewe599801f2012-02-09 21:11:45 +01004293 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304294 tempax |= 0x0100;
4295
Peter Huewe599801f2012-02-09 21:11:45 +01004296 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304297 tempax &= 0xfe00;
4298
4299 tempax = (tempax & 0xff00) >> 8;
4300
Aaro Koskinen8104e322011-03-13 12:26:22 +02004301 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304302 TimingPoint = pVBInfo->NTSCTiming;
4303
Peter Huewe599801f2012-02-09 21:11:45 +01004304 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304305 TimingPoint = pVBInfo->PALTiming;
4306
Peter Huewe599801f2012-02-09 21:11:45 +01004307 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304308 TimingPoint = pVBInfo->HiTVExtTiming;
4309
4310 if (pVBInfo->VBInfo & SetInSlaveMode)
4311 TimingPoint = pVBInfo->HiTVSt2Timing;
4312
4313 if (pVBInfo->SetFlag & TVSimuMode)
4314 TimingPoint = pVBInfo->HiTVSt1Timing;
4315
4316 if (!(modeflag & Charx8Dot))
4317 TimingPoint = pVBInfo->HiTVTextTiming;
4318 }
4319
Peter Huewe599801f2012-02-09 21:11:45 +01004320 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4321 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304322 TimingPoint = pVBInfo->YPbPr525iTiming;
4323
Peter Huewe599801f2012-02-09 21:11:45 +01004324 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304325 TimingPoint = pVBInfo->YPbPr525pTiming;
4326
Peter Huewe599801f2012-02-09 21:11:45 +01004327 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304328 TimingPoint = pVBInfo->YPbPr750pTiming;
4329 }
4330
4331 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004332 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304333
4334 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004335 /* di->temp2[j] */
4336 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304337
4338 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004339 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304340
4341 temp = pVBInfo->NewFlickerMode;
4342 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004343 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304344
Peter Huewe599801f2012-02-09 21:11:45 +01004345 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304346 tempax = 950;
4347
Peter Huewe599801f2012-02-09 21:11:45 +01004348 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304349 tempax = 520;
4350 else
4351 tempax = 440;
4352
4353 if (pVBInfo->VDE <= tempax) {
4354 tempax -= pVBInfo->VDE;
4355 tempax = tempax >> 2;
4356 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
4357 push1 = tempax;
4358 temp = (tempax & 0xFF00) >> 8;
4359 temp += (unsigned short) TimingPoint[0];
4360
Peter Huewe6896b942012-02-09 21:11:46 +01004361 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4362 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304363 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4364 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01004365 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304366 tempcx = pVBInfo->VGAHDE;
4367 if (tempcx >= 1024) {
4368 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01004369 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304370 temp = 0x19; /* PAL */
4371 }
4372 }
4373 }
4374
Aaro Koskinen8104e322011-03-13 12:26:22 +02004375 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304376 tempax = push1;
4377 temp = (tempax & 0xFF00) >> 8;
4378 temp += TimingPoint[1];
4379
Peter Huewe6896b942012-02-09 21:11:46 +01004380 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4381 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304382 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4383 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01004384 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304385 tempcx = pVBInfo->VGAHDE;
4386 if (tempcx >= 1024) {
4387 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01004388 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304389 temp = 0x52; /* PAL */
4390 }
4391 }
4392 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004393 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304394 }
4395
4396 /* 301b */
4397 tempcx = pVBInfo->HT;
4398
4399 if (XGI_IsLCDDualLink(pVBInfo))
4400 tempcx = tempcx >> 1;
4401
4402 tempcx -= 2;
4403 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004404 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304405
4406 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004407 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304408
4409 tempcx = pVBInfo->HT >> 1;
4410 push1 = tempcx; /* push cx */
4411 tempcx += 7;
4412
Peter Huewe599801f2012-02-09 21:11:45 +01004413 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304414 tempcx -= 4;
4415
4416 temp = tempcx & 0x00FF;
4417 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004418 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304419
4420 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4421 tempbx += tempcx;
4422 push2 = tempbx;
4423 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004424 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304425 temp = (tempbx & 0xFF00) >> 8;
4426 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004427 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304428
4429 tempbx = push2;
4430 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004431 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304432 tempbx = tempbx - 4;
4433 tempcx = tempbx;
4434 }
4435
4436 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004437 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304438
4439 j += 2;
4440 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
4441 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004442 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304443 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004444 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304445
4446 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004447 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304448 tempcx -= 4;
4449
4450 temp = tempcx & 0xFF;
4451 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004452 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304453
4454 tempcx = push1; /* pop cx */
4455 j += 2;
4456 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4457 tempcx -= temp;
4458 temp = tempcx & 0x00FF;
4459 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004460 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304461
4462 tempcx -= 11;
4463
4464 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
4465 tempax = XGI_GetVGAHT2(pVBInfo);
4466 tempcx = tempax - 1;
4467 }
4468 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004469 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304470
4471 tempbx = pVBInfo->VDE;
4472
4473 if (pVBInfo->VGAVDE == 360)
4474 tempbx = 746;
4475 if (pVBInfo->VGAVDE == 375)
4476 tempbx = 746;
4477 if (pVBInfo->VGAVDE == 405)
4478 tempbx = 853;
4479
4480 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004481 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004482 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004483 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004484 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304485 tempbx = tempbx >> 1;
4486 } else
4487 tempbx = tempbx >> 1;
4488 }
4489
4490 tempbx -= 2;
4491 temp = tempbx & 0x00FF;
4492
Peter Huewe599801f2012-02-09 21:11:45 +01004493 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01004494 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004495 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304496 if (pVBInfo->VBInfo & SetInSlaveMode) {
4497 if (ModeNo == 0x2f)
4498 temp += 1;
4499 }
4500 }
4501 } else {
4502 if (pVBInfo->VBInfo & SetInSlaveMode) {
4503 if (ModeNo == 0x2f)
4504 temp += 1;
4505 }
4506 }
4507 }
4508
Aaro Koskinen8104e322011-03-13 12:26:22 +02004509 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304510
4511 temp = (tempcx & 0xFF00) >> 8;
4512 temp |= ((tempbx & 0xFF00) >> 8) << 6;
4513
Peter Huewe599801f2012-02-09 21:11:45 +01004514 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01004515 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004516 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304517 temp |= 0x10;
4518
4519 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4520 temp |= 0x20;
4521 }
4522 } else {
4523 temp |= 0x10;
4524 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4525 temp |= 0x20;
4526 }
4527 }
4528
Aaro Koskinen8104e322011-03-13 12:26:22 +02004529 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304530
Peter Huewe6896b942012-02-09 21:11:46 +01004531 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4532 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304533 tempbx = pVBInfo->VDE;
4534 tempcx = tempbx - 2;
4535
4536 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004537 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
4538 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304539 tempbx = tempbx >> 1;
4540 }
4541
Peter Huewe6896b942012-02-09 21:11:46 +01004542 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304543 temp = 0;
4544 if (tempcx & 0x0400)
4545 temp |= 0x20;
4546
4547 if (tempbx & 0x0400)
4548 temp |= 0x40;
4549
Aaro Koskinen8104e322011-03-13 12:26:22 +02004550 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551 }
4552
4553 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004554 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304555 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004556 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304557 }
4558
4559 tempbx = tempbx & 0x00FF;
4560
4561 if (!(modeflag & HalfDCLK)) {
4562 tempcx = pVBInfo->VGAHDE;
4563 if (tempcx >= pVBInfo->HDE) {
4564 tempbx |= 0x2000;
4565 tempax &= 0x00FF;
4566 }
4567 }
4568
4569 tempcx = 0x0101;
4570
4571 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
4572 if (pVBInfo->VGAHDE >= 1024) {
4573 tempcx = 0x1920;
4574 if (pVBInfo->VGAHDE >= 1280) {
4575 tempcx = 0x1420;
4576 tempbx = tempbx & 0xDFFF;
4577 }
4578 }
4579 }
4580
4581 if (!(tempbx & 0x2000)) {
4582 if (modeflag & HalfDCLK)
4583 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
4584
4585 push1 = tempbx;
4586 tempeax = pVBInfo->VGAHDE;
4587 tempebx = (tempcx & 0xFF00) >> 8;
4588 longtemp = tempeax * tempebx;
4589 tempecx = tempcx & 0x00FF;
4590 longtemp = longtemp / tempecx;
4591
4592 /* 301b */
4593 tempecx = 8 * 1024;
4594
Peter Huewe6896b942012-02-09 21:11:46 +01004595 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4596 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304597 tempecx = tempecx * 8;
4598 }
4599
4600 longtemp = longtemp * tempecx;
4601 tempecx = pVBInfo->HDE;
4602 temp2 = longtemp % tempecx;
4603 tempeax = longtemp / tempecx;
4604 if (temp2 != 0)
4605 tempeax += 1;
4606
4607 tempax = (unsigned short) tempeax;
4608
4609 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004610 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4611 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304612 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
4613 }
4614 /* end 301b */
4615
4616 tempbx = push1;
4617 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
4618 | (tempbx & 0x00FF));
4619 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
4620 | (tempax & 0x00FF));
4621 temp = (tempax & 0xFF00) >> 8;
4622 } else {
4623 temp = (tempax & 0x00FF) >> 8;
4624 }
4625
Aaro Koskinen8104e322011-03-13 12:26:22 +02004626 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304627 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004628 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304629 temp = tempcx & 0x00FF;
4630
4631 if (tempbx & 0x2000)
4632 temp = 0;
4633
4634 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4635 temp |= 0x18;
4636
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004637 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01004638 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304639 tempbx = 0x0382;
4640 tempcx = 0x007e;
4641 } else {
4642 tempbx = 0x0369;
4643 tempcx = 0x0061;
4644 }
4645
4646 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004647 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304648 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004649 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304650
4651 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
4652 temp = temp << 2;
4653 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
4654
Peter Huewe599801f2012-02-09 21:11:45 +01004655 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304656 temp |= 0x10;
4657
Peter Huewe599801f2012-02-09 21:11:45 +01004658 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304659 temp |= 0x20;
4660
Peter Huewe599801f2012-02-09 21:11:45 +01004661 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304662 temp |= 0x60;
4663 }
4664
Aaro Koskinen8104e322011-03-13 12:26:22 +02004665 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004666 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004667 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304668
Peter Huewe599801f2012-02-09 21:11:45 +01004669 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304670 if (pVBInfo->TVInfo & NTSC1024x768) {
4671 TimingPoint = XGI_NTSC1024AdjTime;
4672 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004673 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304674 TimingPoint[j]);
4675 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004676 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304677 }
4678 }
4679
4680 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
4681 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01004682 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004683 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304684 0x08); /* PALM Mode */
4685 }
4686
Peter Huewe599801f2012-02-09 21:11:45 +01004687 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02004688 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304689 0x01);
4690 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02004691 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304692
Aaro Koskinendc505562011-03-13 12:26:26 +02004693 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304694 }
4695
Peter Huewe599801f2012-02-09 21:11:45 +01004696 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304697 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02004698 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304699 }
4700
4701 if (pVBInfo->VBInfo & SetCRT2ToTV)
4702 return;
4703}
4704
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004705static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304706 struct xgi_hw_device_info *HwDeviceExtension,
4707 unsigned short RefreshRateTableIndex,
4708 struct vb_device_info *pVBInfo)
4709{
4710 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
4711 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
4712
4713 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
4714
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004715 /* si+Ext_ResInfo */
4716 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4717 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4718 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4719 CRT1Index &= IndexMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304720
4721 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4722 return;
4723
4724 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
4725
4726 if (XGI_IsLCDDualLink(pVBInfo))
4727 tempbx = tempbx >> 1;
4728
4729 tempbx -= 1;
4730 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004731 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304732 temp = (tempbx & 0xFF00) >> 8;
4733 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004734 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304735 temp = 0x01;
4736
Aaro Koskinen8104e322011-03-13 12:26:22 +02004737 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304738 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
4739 push1 = tempbx;
4740 tempbx--;
4741 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004742 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304743 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004744 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304745
4746 tempcx = pVBInfo->VT - 1;
4747 push2 = tempcx + 1;
4748 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004749 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304750 temp = (tempcx & 0xFF00) >> 8;
4751 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004752 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004753 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
4754 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
4755 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
4756 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304757
4758 /* Customized LCDB Des no add */
4759 tempbx = 5;
4760 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
4761 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
4762 tempah = pVBInfo->LCDResInfo;
4763 tempah &= PanelResInfo;
4764
Peter Huewe255aabd2012-02-09 21:11:44 +01004765 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304766 tempbx = 1024;
4767 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01004768 } else if ((tempah == Panel_1280x1024) ||
4769 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304770 tempbx = 1280;
4771 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01004772 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304773 tempbx = 1400;
4774 tempcx = 1050;
4775 } else {
4776 tempbx = 1600;
4777 tempcx = 1200;
4778 }
4779
4780 if (pVBInfo->LCDInfo & EnableScalingLCD) {
4781 tempbx = pVBInfo->HDE;
4782 tempcx = pVBInfo->VDE;
4783 }
4784
4785 pushbx = tempbx;
4786 tempax = pVBInfo->VT;
4787 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
4788 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
4789 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
4790 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
4791 tempbx = pVBInfo->LCDVDES;
4792 tempcx += tempbx;
4793
4794 if (tempcx >= tempax)
4795 tempcx -= tempax; /* lcdvdes */
4796
4797 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004798 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304799 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004800 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304801 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
4802 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
4803 tempah = tempch;
4804 tempah = tempah << 3;
4805 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004806 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304807
4808 /* getlcdsync() */
4809 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4810 tempcx = tempbx;
4811 tempax = pVBInfo->VT;
4812 tempbx = pVBInfo->LCDVRS;
4813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304814 tempcx += tempbx;
4815 if (tempcx >= tempax)
4816 tempcx -= tempax;
4817
4818 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004819 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304820 temp = (tempbx & 0xFF00) >> 8;
4821 temp = temp << 4;
4822 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004823 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304824 tempcx = pushbx;
4825 tempax = pVBInfo->HT;
4826 tempbx = pVBInfo->LCDHDES;
4827 tempbx &= 0x0FFF;
4828
4829 if (XGI_IsLCDDualLink(pVBInfo)) {
4830 tempax = tempax >> 1;
4831 tempbx = tempbx >> 1;
4832 tempcx = tempcx >> 1;
4833 }
4834
Peter Huewe6896b942012-02-09 21:11:46 +01004835 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304836 tempbx += 1;
4837
4838 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
4839 tempbx += 1;
4840
4841 tempcx += tempbx;
4842
4843 if (tempcx >= tempax)
4844 tempcx -= tempax;
4845
4846 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004847 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304848 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004849 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304850 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004851 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304852 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004853 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304854
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304855 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4856 tempcx = tempax;
4857 tempax = pVBInfo->HT;
4858 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304859 if (XGI_IsLCDDualLink(pVBInfo)) {
4860 tempax = tempax >> 1;
4861 tempbx = tempbx >> 1;
4862 tempcx = tempcx >> 1;
4863 }
4864
Peter Huewe6896b942012-02-09 21:11:46 +01004865 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304866 tempbx += 1;
4867
4868 tempcx += tempbx;
4869
4870 if (tempcx >= tempax)
4871 tempcx -= tempax;
4872
4873 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004874 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304875
4876 temp = (tempbx & 0xFF00) >> 8;
4877 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004878 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304879 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004880 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304881
Peter Huewea3d675c2012-02-09 21:11:47 +01004882 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304883 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01004884 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4885 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304886 | VB_XGI301C)) {
4887 temp = 0xC6;
4888 } else
4889 temp = 0xC4;
4890
Aaro Koskinen8104e322011-03-13 12:26:22 +02004891 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4892 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304893 }
4894
4895 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004896 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4897 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304898 | VB_XGI301C)) {
4899 temp = 0x4F;
4900 } else
4901 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004902 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304903 }
4904 }
4905}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004906
4907/* --------------------------------------------------------------------- */
4908/* Function : XGI_GetTap4Ptr */
4909/* Input : */
4910/* Output : di -> Tap4 Reg. Setting Pointer */
4911/* Description : */
4912/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004913static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304914 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004915{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304916 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004917
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304918 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004919
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304920 if (tempcx == 0) {
4921 tempax = pVBInfo->VGAHDE;
4922 tempbx = pVBInfo->HDE;
4923 } else {
4924 tempax = pVBInfo->VGAVDE;
4925 tempbx = pVBInfo->VDE;
4926 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004927
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004928 if (tempax <= tempbx)
4929 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304930 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004931 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004932
Peter Huewe599801f2012-02-09 21:11:45 +01004933 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304934 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004935
Peter Huewe599801f2012-02-09 21:11:45 +01004936 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4937 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4938 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004939 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004940 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304941 Tap4TimingPtr = YPbPr750pTap4Timing;
4942 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004943
Peter Huewe599801f2012-02-09 21:11:45 +01004944 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004945 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004946
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304947 i = 0;
4948 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4949 if (Tap4TimingPtr[i].DE == tempax)
4950 break;
4951 i++;
4952 }
4953 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004954}
4955
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004956static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004957{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304958 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004959
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304960 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004961
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304962 if (!(pVBInfo->VBType & VB_XGI301C))
4963 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004964
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304965 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4966 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004967 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004968
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004969 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004970 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004971 /* Set Vertical Scaling */
4972 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304973 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004974 xgifb_reg_set(pVBInfo->Part2Port,
4975 i,
4976 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304977 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004978
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004979 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004980 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004981 /* Enable V.Scaling */
4982 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304983 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004984 /* Enable H.Scaling */
4985 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004986}
4987
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004988static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304989 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004990{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304991 unsigned short i;
4992 unsigned char *tempdi;
4993 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004994
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004995 /* si+Ext_ResInfo */
4996 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004997
Aaro Koskinen8104e322011-03-13 12:26:22 +02004998 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004999 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005000 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5001 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305002 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005003 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5004 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305005 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005006
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305007 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5008 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005009
Peter Huewe599801f2012-02-09 21:11:45 +01005010 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005011 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5012 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5013 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305014 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005015
Peter Huewe599801f2012-02-09 21:11:45 +01005016 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
5017 & SetCRT2ToYPbPr525750)) {
5018 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305019 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005020
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305021 tempdi = pVBInfo->HiTVGroup3Data;
5022 if (pVBInfo->SetFlag & TVSimuMode) {
5023 tempdi = pVBInfo->HiTVGroup3Simu;
5024 if (!(modeflag & Charx8Dot))
5025 tempdi = pVBInfo->HiTVGroup3Text;
5026 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005027
Peter Huewe599801f2012-02-09 21:11:45 +01005028 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305029 tempdi = pVBInfo->Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005030
Peter Huewe599801f2012-02-09 21:11:45 +01005031 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305032 tempdi = pVBInfo->Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305034 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005035 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005036
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305037 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01005038 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005039 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305040 }
5041 }
5042 return;
5043} /* {end of XGI_SetGroup3} */
5044
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005045static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305046 unsigned short RefreshRateTableIndex,
5047 struct xgi_hw_device_info *HwDeviceExtension,
5048 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005049{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305050 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305052 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005053
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005054 /* si+Ext_ResInfo */
5055 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305056 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005057 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305059 tempbx = pVBInfo->RVBHCMAX;
5060 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005061 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305062 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5063 tempcx = pVBInfo->VGAHT - 1;
5064 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005065 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005066
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305067 temp = ((tempcx & 0xFF00) >> 8) << 3;
5068 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005069
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305070 tempcx = pVBInfo->VGAVT - 1;
5071 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5072 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005073
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305074 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005075 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305076 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005077 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005078 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305079 tempcx = pVBInfo->VBInfo;
5080 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005081
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305082 if (modeflag & HalfDCLK)
5083 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005084
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305085 if (XGI_IsLCDDualLink(pVBInfo))
5086 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005087
Peter Huewe599801f2012-02-09 21:11:45 +01005088 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305089 temp = 0;
5090 if (tempbx <= 1024)
5091 temp = 0xA0;
5092 if (tempbx == 1280)
5093 temp = 0xC0;
5094 } else if (tempcx & SetCRT2ToTV) {
5095 temp = 0xA0;
5096 if (tempbx <= 800)
5097 temp = 0x80;
5098 } else {
5099 temp = 0x80;
5100 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5101 temp = 0;
5102 if (tempbx > 800)
5103 temp = 0x60;
5104 }
5105 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005106
Peter Huewe599801f2012-02-09 21:11:45 +01005107 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305108 temp = 0x00;
5109 if (pVBInfo->VGAHDE == 1280)
5110 temp = 0x40;
5111 if (pVBInfo->VGAHDE == 1024)
5112 temp = 0x20;
5113 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005114 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305116 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005117
Peter Huewe599801f2012-02-09 21:11:45 +01005118 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305119 if (!(temp & 0xE000))
5120 tempbx = tempbx >> 1;
5121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305123 tempcx = pVBInfo->RVBHRS;
5124 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005125 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305127 tempeax = pVBInfo->VGAVDE;
5128 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005129
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305130 if (tempeax <= tempebx) {
5131 tempcx = (tempcx & (~0x4000));
5132 tempeax = pVBInfo->VGAVDE;
5133 } else {
5134 tempeax -= tempebx;
5135 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305137 templong = (tempeax * 256 * 1024) % tempebx;
5138 tempeax = (tempeax * 256 * 1024) / tempebx;
5139 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305141 if (templong != 0)
5142 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305144 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005145 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305147 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005148 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305149 tempbx = (unsigned short) (tempebx >> 16);
5150 temp = tempbx & 0x00FF;
5151 temp = temp << 4;
5152 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005153 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005154
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305155 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01005156 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5157 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305158 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005159 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305160 tempax = pVBInfo->VGAHDE;
5161 if (modeflag & HalfDCLK)
5162 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005163
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305164 if (XGI_IsLCDDualLink(pVBInfo))
5165 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305167 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5168 if (tempax > 800)
5169 tempax -= 800;
5170 } else {
5171 if (pVBInfo->VGAHDE > 800) {
5172 if (pVBInfo->VGAHDE == 1024)
5173 tempax = (tempax * 25 / 32) - 1;
5174 else
5175 tempax = (tempax * 20 / 32) - 1;
5176 }
5177 }
5178 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305180 temp = (tempax & 0xFF00) >> 8;
5181 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005182 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305183 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005184 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005185
Peter Huewe599801f2012-02-09 21:11:45 +01005186 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305187 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005188 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305190 }
5191 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305193 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5194 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01005195 | TVSetYPbPr525p | TVSetYPbPr750p
5196 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305197 temp |= 0x0001;
5198 if ((pVBInfo->VBInfo & SetInSlaveMode)
5199 && (!(pVBInfo->TVInfo
5200 & TVSimuMode)))
5201 temp &= (~0x0001);
5202 }
5203 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005204
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005205 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305206 tempbx = pVBInfo->HT;
5207 if (XGI_IsLCDDualLink(pVBInfo))
5208 tempbx = tempbx >> 1;
5209 tempbx = (tempbx >> 1) - 2;
5210 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005211 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305212 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005213 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305214 }
5215 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005216
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305217 if (pVBInfo->ISXPDOS == 0)
5218 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5219 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005220}
5221
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005222static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5223{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005224 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005225}
5226
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005227static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305228 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005229{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305230 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005231
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305232 Pindex = pVBInfo->Part5Port;
5233 Pdata = pVBInfo->Part5Port + 1;
5234 if (pVBInfo->ModeType == ModeVGA) {
5235 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01005236 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305237 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305238 }
5239 }
5240 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005241}
5242
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005243static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305244 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005245{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005246 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005247}
5248
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005249static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305250 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005251{
5252
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005253 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005254}
5255
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005256static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
5257 unsigned short ModeNo, unsigned short ModeIdIndex,
5258 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005259{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005260 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005261
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305262 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005263 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5264 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5265 /* si+St_ModeFlag */
5266 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005267
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305268 if (!(modeflag & Charx8Dot)) {
5269 xres /= 9;
5270 xres *= 8;
5271 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005272
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005273 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
5274 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005275
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005276 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
5277 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005278
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005279 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305280 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04005281
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005282 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305283 return 0;
5284
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005285 if (xres != xgifb_info->lvds_data.LVDSHDE ||
5286 yres != xgifb_info->lvds_data.LVDSVDE) {
5287 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
5288 if (colordepth > 2)
5289 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305290 }
5291 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005292}
5293
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005294static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
5295 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005296 unsigned short ModeNo,
5297 unsigned short ModeIdIndex,
5298 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005299{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305300 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005301 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305302 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
5303 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
5304 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005305
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005306 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005307 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305308 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005309 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005310
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005311 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005312
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005313 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005314 /* SR35[7] FP VSync polarity */
5315 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
5316 /* SR30[5] FP HSync polarity */
5317 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005318
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005319 if (chip_id == XG27)
5320 XGI_SetXG27FPBits(pVBInfo);
5321 else
5322 XGI_SetXG21FPBits(pVBInfo);
5323
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305324 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005325 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5326 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5327 /* si+St_ModeFlag */
5328 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005329
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305330 if (!(modeflag & Charx8Dot))
5331 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005332
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005333 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005334
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005335 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005336
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305337 if (LVDSHBS > LVDSHT)
5338 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005339
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005340 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305341 if (LVDSHRS > LVDSHT)
5342 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005343
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005344 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305345 if (LVDSHRE > LVDSHT)
5346 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005347
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005348 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005349
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005350 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005351
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005352 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005353 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305354 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005355
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305356 if (LVDSVBS > LVDSVT)
5357 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005358
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005359 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305360 if (LVDSVRS > LVDSVT)
5361 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005362
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005363 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305364 if (LVDSVRE > LVDSVT)
5365 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005366
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005367 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005368
Aaro Koskinen58839b02011-03-13 12:26:23 +02005369 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005370 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005371
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305372 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005373 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005374
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305375 /* HT SR0B[1:0] CR00 */
5376 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005377 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005378 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305380 /* HBS SR0B[5:4] CR02 */
5381 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005382 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005383 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005384
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305385 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
5386 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005387 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
5388 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
5389 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005390
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305391 /* HRS SR0B[7:6] CR04 */
5392 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005393 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005394 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005395
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305396 /* Panel HRS SR2F[1:0] SR2E[7:0] */
5397 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005398 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005399 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005400
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305401 /* HRE SR0C[2] CR05[4:0] */
5402 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005403 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
5404 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005405
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305406 /* Panel HRE SR2F[7:2] */
5407 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005408 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005409
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305410 /* VT SR0A[0] CR07[5][0] CR06 */
5411 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005412 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
5413 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
5414 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005415 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005416
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305417 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
5418 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005419 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
5420 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
5421 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005422 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005423
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305424 /* VBE SR0A[4] CR16 */
5425 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005426 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005427 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005428
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305429 /* VRS SR0A[3] CR7[7][2] CR10 */
5430 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005431 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
5432 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
5433 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005434 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005435
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005436 if (chip_id == XG27) {
5437 /* Panel VRS SR35[2:0] SR34[7:0] */
5438 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
5439 (value & 0x700) >> 8);
5440 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
5441 } else {
5442 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
5443 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
5444 (value & 0x600) >> 9);
5445 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
5446 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
5447 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005448
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305449 /* VRE SR0A[5] CR11[3:0] */
5450 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005451 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
5452 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005453
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305454 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005455 if (chip_id == XG27)
5456 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
5457 (value << 2) & 0xFC);
5458 else
5459 /* SR3F[7] has to be 0, h/w bug */
5460 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
5461 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005462
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305463 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005464
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005465 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005466 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005467 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005468 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005469 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305470 value += 0x10;
5471 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005472
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305473 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005474 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005475 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005476 /* set data, panning = 0, shift left 1 dot*/
5477 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005478
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005479 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005480 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305481
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005482 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305483 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005484
5485}
5486
5487/* --------------------------------------------------------------------- */
5488/* Function : XGI_IsLCDON */
5489/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04005490/* Output : 0 : Skip PSC Control */
5491/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005492/* Description : */
5493/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005494static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005495{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305496 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005497
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305498 tempax = pVBInfo->VBInfo;
5499 if (tempax & SetCRT2ToDualEdge)
5500 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01005501 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305502 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005503
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305504 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005505}
5506
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005507/* --------------------------------------------------------------------- */
5508/* Function : XGI_DisableChISLCD */
5509/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04005510/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005511/* Description : */
5512/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005513static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005514{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305515 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005516
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305517 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005518 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005519
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305520 if (tempbx & (EnableChA | DisableChA)) {
5521 if (!(tempah & 0x08)) /* Chk LCDA Mode */
5522 return 0;
5523 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005524
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305525 if (!(tempbx & (EnableChB | DisableChB)))
5526 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005527
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305528 if (tempah & 0x01) /* Chk LCDB Mode */
5529 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005530
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305531 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005532}
5533
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005534/* --------------------------------------------------------------------- */
5535/* Function : XGI_EnableChISLCD */
5536/* Input : */
5537/* Output : 0 -> Not LCD mode */
5538/* Description : */
5539/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005540static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005541{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305542 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005543
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305544 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005545 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005546
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305547 if (tempbx & (EnableChA | DisableChA)) {
5548 if (!(tempah & 0x08)) /* Chk LCDA Mode */
5549 return 0;
5550 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005551
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305552 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04005553 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005554
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305555 if (tempah & 0x01) /* Chk LCDB Mode */
5556 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005557
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305558 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005559}
5560
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005561static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
5562 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305563 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005564{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005565 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005566
Peter Huewe6896b942012-02-09 21:11:46 +01005567 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5568 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305569 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005570 if (!(pVBInfo->VBInfo &
5571 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005572 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305573 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5574 tempah = 0x7F; /* Disable Channel A */
Peter Huewea3d675c2012-02-09 21:11:47 +01005575 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005576 /* Disable Channel B */
5577 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005578
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305579 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005580 /* force to disable Cahnnel */
5581 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005582
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305583 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005584 /* Force to disable Channel B */
5585 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305586 }
5587 }
5588 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005589
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005590 /* disable part4_1f */
5591 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005592
Peter Huewe6896b942012-02-09 21:11:46 +01005593 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005594 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305595 || (XGI_DisableChISLCD(pVBInfo))
5596 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005597 /* LVDS Driver power down */
5598 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305599 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005600
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305601 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01005602 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305603 | SetSimuScanMode))) {
5604 if (pVBInfo->SetFlag & GatingCRT)
5605 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005606 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305607 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005608
Peter Huewea3d675c2012-02-09 21:11:47 +01005609 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305610 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01005611 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005612 /* Power down */
5613 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305614 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005615
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005616 /* disable TV as primary VGA swap */
5617 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305619 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02005620 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005621
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005622 if ((pVBInfo->SetFlag & DisableChB) ||
5623 (pVBInfo->VBInfo &
5624 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01005625 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005626 (pVBInfo->VBInfo &
5627 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005628 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005629
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005630 if ((pVBInfo->SetFlag & DisableChB) ||
5631 (pVBInfo->VBInfo &
5632 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01005633 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005634 (pVBInfo->VBInfo &
5635 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
5636 /* save Part1 index 0 */
5637 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
5638 /* BTDAC = 1, avoid VB reset */
5639 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
5640 /* disable CRT2 */
5641 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
5642 /* restore Part1 index 0 */
5643 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305644 }
5645 } else { /* {301} */
5646 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005647 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
5648 /* Disable CRT2 */
5649 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
5650 /* Disable TV asPrimary VGA swap */
5651 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305652 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005653
Peter Huewea3d675c2012-02-09 21:11:47 +01005654 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305655 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005656 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305657 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005658}
5659
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005660/* --------------------------------------------------------------------- */
5661/* Function : XGI_GetTVPtrIndex */
5662/* Input : */
5663/* Output : */
5664/* Description : bx 0 : ExtNTSC */
5665/* 1 : StNTSC */
5666/* 2 : ExtPAL */
5667/* 3 : StPAL */
5668/* 4 : ExtHiTV */
5669/* 5 : StHiTV */
5670/* 6 : Ext525i */
5671/* 7 : St525i */
5672/* 8 : Ext525p */
5673/* 9 : St525p */
5674/* A : Ext750p */
5675/* B : St750p */
5676/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005677static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005678{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305679 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005680
Peter Huewe599801f2012-02-09 21:11:45 +01005681 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305682 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01005683 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305684 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01005685 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305686 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01005687 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305688 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01005689 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305690 tempbx = 10;
5691 if (pVBInfo->TVInfo & TVSimuMode)
5692 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005693
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305694 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005695}
5696
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005697/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005698/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005699/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005700/* Output : bx 0 : NTSC */
5701/* 1 : PAL */
5702/* 2 : PALM */
5703/* 3 : PALN */
5704/* 4 : NTSC1024x768 */
5705/* 5 : PAL-M 1024x768 */
5706/* 6-7: reserved */
5707/* cl 0 : YFilter1 */
5708/* 1 : YFilter2 */
5709/* ch 0 : 301A */
5710/* 1 : 301B/302B/301LV/302LV */
5711/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005712/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005713static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
5714 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005715{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005716 *tempbx = 0;
5717 *tempcl = 0;
5718 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005719
Peter Huewe599801f2012-02-09 21:11:45 +01005720 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005721 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005722
Peter Huewe599801f2012-02-09 21:11:45 +01005723 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005724 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005725
Peter Huewe599801f2012-02-09 21:11:45 +01005726 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005727 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005728
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005729 if (pVBInfo->TVInfo & NTSC1024x768) {
5730 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01005731 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005732 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305733 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005734
Peter Huewe6896b942012-02-09 21:11:46 +01005735 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5736 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005737 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
5738 & TVSimuMode)) {
5739 *tempbx += 8;
5740 *tempcl += 1;
5741 }
5742 }
5743
Peter Huewe6896b942012-02-09 21:11:46 +01005744 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5745 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005746 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005747}
5748
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005749static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005750{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305751 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005752
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305753 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005754
Peter Huewe6896b942012-02-09 21:11:46 +01005755 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5756 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005757 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305758 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
5759 tempbl = 0;
5760 tempbh = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005761
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305762 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
5763 tempbl = pVBInfo->XGI_TVDelayList[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005764
Peter Huewe6896b942012-02-09 21:11:46 +01005765 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
5766 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305767 | VB_XGI301C))
5768 tempbl = pVBInfo->XGI_TVDelayList2[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005769
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305770 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5771 tempbl = tempbl >> 4;
Peter Huewea3d675c2012-02-09 21:11:47 +01005772 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005773 /* Get LCD Delay */
5774 index = XGI_GetLCDCapPtr(pVBInfo);
5775 tempbh = pVBInfo->LCDCapList[index].
5776 LCD_DelayCompensation;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005777
Peter Huewea3d675c2012-02-09 21:11:47 +01005778 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305779 tempbl = tempbh;
5780 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005781
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305782 tempbl &= 0x0F;
5783 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02005784 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305786 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
5787 | SetCRT2ToTV)) { /* Channel B */
5788 tempah &= 0xF0;
5789 tempah |= tempbl;
5790 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005791
Peter Huewea3d675c2012-02-09 21:11:47 +01005792 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) { /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305793 tempah &= 0x0F;
5794 tempah |= tempbh;
5795 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005796 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305797 }
5798 } else if (pVBInfo->IF_DEF_LVDS == 1) {
5799 tempbl = 0;
5800 tempbh = 0;
5801 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005802 /* / Get LCD Delay */
5803 tempah = pVBInfo->LCDCapList[
5804 XGI_GetLCDCapPtr(pVBInfo)].
5805 LCD_DelayCompensation;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305806 tempah &= 0x0f;
5807 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005808 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305809 tempah);
5810 }
5811 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005812}
5813
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005814static void XGI_SetLCDCap_A(unsigned short tempcx,
5815 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005816{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305817 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005818
Aaro Koskinen58839b02011-03-13 12:26:23 +02005819 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305821 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005822 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005823 /* Enable Dither */
5824 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005825 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305826 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005827 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305828 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005829 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305830 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005831}
5832
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005833/* --------------------------------------------------------------------- */
5834/* Function : XGI_SetLCDCap_B */
5835/* Input : cx -> LCD Capability */
5836/* Output : */
5837/* Description : */
5838/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005839static void XGI_SetLCDCap_B(unsigned short tempcx,
5840 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005841{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305842 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005843 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305844 (unsigned short) (((tempcx & 0x00ff) >> 6)
5845 | 0x0c));
5846 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005847 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305848 (unsigned short) (((tempcx & 0x00ff) >> 6)
5849 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005850}
5851
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02005852static void XGI_LongWait(struct vb_device_info *pVBInfo)
5853{
5854 unsigned short i;
5855
5856 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5857
5858 if (!(i & 0xC0)) {
5859 for (i = 0; i < 0xFFFF; i++) {
5860 if (!(inb(pVBInfo->P3da) & 0x08))
5861 break;
5862 }
5863
5864 for (i = 0; i < 0xFFFF; i++) {
5865 if ((inb(pVBInfo->P3da) & 0x08))
5866 break;
5867 }
5868 }
5869}
5870
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005871static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005872{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305873 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305875 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005876
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005877 /* disable down spectrum D[4] */
5878 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305879 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005880 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305881 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005882
Aaro Koskinen8104e322011-03-13 12:26:22 +02005883 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305884 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005885 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305886 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005887 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305888 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005889 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305890 pVBInfo->LCDCapList[index].Spectrum_34);
5891 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005892 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005893}
5894
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005895static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5896{
5897 unsigned short tempcx;
5898
5899 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5900
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005901 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005902 (VB_SIS301B |
5903 VB_SIS302B |
5904 VB_SIS301LV |
5905 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005906 VB_XGI301C)) { /* 301LV/302LV only */
5907 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005908 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005909 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005910 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005911 (unsigned char) (tempcx & 0x1F));
5912 }
5913 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005914 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005915 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
5916 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
5917 | EnablePLLSPLOW)) >> 8));
5918 }
5919
Peter Huewe6896b942012-02-09 21:11:46 +01005920 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5921 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005922 if (pVBInfo->VBInfo & SetCRT2ToLCD)
5923 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01005924 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005925 XGI_SetLCDCap_A(tempcx, pVBInfo);
5926
Peter Huewe6896b942012-02-09 21:11:46 +01005927 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005928 if (tempcx & EnableSpectrum)
5929 SetSpectrum(pVBInfo);
5930 }
5931 } else {
5932 /* LVDS,CH7017 */
5933 XGI_SetLCDCap_A(tempcx, pVBInfo);
5934 }
5935}
5936
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005937/* --------------------------------------------------------------------- */
5938/* Function : XGI_SetAntiFlicker */
5939/* Input : */
5940/* Output : */
5941/* Description : Set TV Customized Param. */
5942/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005943static void XGI_SetAntiFlicker(unsigned short ModeNo,
5944 unsigned short ModeIdIndex,
5945 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005946{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03005947 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305949 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005950
Peter Huewe599801f2012-02-09 21:11:45 +01005951 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305952 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005953
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305954 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5955 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305956 tempah = TVAntiFlickList[tempbx];
5957 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005958
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005959 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005960}
5961
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005962static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5963 unsigned short ModeIdIndex,
5964 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005965{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03005966 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005967
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305968 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005969
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305970 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5971 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305972 tempah = TVEdgeList[tempbx];
5973 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005974
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005975 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005976}
5977
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005978static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005979{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305980 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005981
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305982 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005983
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305984 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005985
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305986 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5987 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005988
Aaro Koskinen8104e322011-03-13 12:26:22 +02005989 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305990 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005991 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305992 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005993 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305994 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005995 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305996 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005997}
5998
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005999static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306000 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006001{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306002 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306004 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006005
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306006 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006007
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306008 switch (tempbx) {
6009 case 0x00:
6010 case 0x04:
6011 filterPtr = NTSCYFilter1;
6012 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006013
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306014 case 0x01:
6015 filterPtr = PALYFilter1;
6016 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006017
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306018 case 0x02:
6019 case 0x05:
6020 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306021 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03006022 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306023 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306025 case 0x08:
6026 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306027 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306028 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306029 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03006030 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306031 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006032
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306033 default:
6034 return;
6035 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006036
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006037 tempal = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306038 if (tempcl == 0)
6039 index = tempal * 4;
6040 else
6041 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006042
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306043 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006044 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
6045 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
6046 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
6047 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306048 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006049 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
6050 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
6051 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
6052 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306053 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006054
Peter Huewe6896b942012-02-09 21:11:46 +01006055 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6056 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006057 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
6058 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
6059 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306060 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006061}
6062
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006063/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006064/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006065/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006066/* Output : */
6067/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006068/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006069static void XGI_OEM310Setting(unsigned short ModeNo,
6070 unsigned short ModeIdIndex,
6071 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006072{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006073 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006074
Peter Huewea3d675c2012-02-09 21:11:47 +01006075 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006076 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006077
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006078 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006079 XGI_SetPhaseIncr(pVBInfo);
6080 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
6081 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006082
Peter Huewe6896b942012-02-09 21:11:46 +01006083 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006084 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306085 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006086}
6087
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006088/* --------------------------------------------------------------------- */
6089/* Function : XGI_SetCRT2ModeRegs */
6090/* Input : */
6091/* Output : */
6092/* Description : Origin code for crt2group */
6093/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02006094static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306095 struct xgi_hw_device_info *HwDeviceExtension,
6096 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006097{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306098 unsigned short tempbl;
6099 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306101 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006102
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306103 tempah = 0;
6104 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006105 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306106 tempah &= ~0x10; /* BTRAMDAC */
6107 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306109 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6110 | SetCRT2ToLCD)) {
6111 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006112 tempcl = pVBInfo->ModeType;
6113 tempcl -= ModeVGA;
6114 if (tempcl >= 0) {
6115 /* BT Color */
6116 tempah = (0x008 >> tempcl);
6117 if (tempah == 0)
6118 tempah = 1;
6119 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306120 }
6121 if (pVBInfo->VBInfo & SetInSlaveMode)
6122 tempah ^= 0x50; /* BTDAC */
6123 }
6124 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006125
Aaro Koskinen8104e322011-03-13 12:26:22 +02006126 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306127 tempah = 0x08;
6128 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006129
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306130 if (pVBInfo->VBInfo & DisableCRT2Display) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006131 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306132 } else {
6133 tempah = 0x00;
6134 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306136 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
Peter Huewea3d675c2012-02-09 21:11:47 +01006137 | SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
6138 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006139 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306140 tempbl &= 0xf7;
6141 tempah |= 0x01;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006142 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306143 tempbl, tempah);
6144 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01006145 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306146 tempbl &= 0xf7;
6147 tempah |= 0x01;
6148 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006149
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006150 if (pVBInfo->VBInfo &
6151 (SetCRT2ToRAMDAC |
6152 SetCRT2ToTV |
6153 SetCRT2ToLCD)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306154 tempbl &= 0xf8;
6155 tempah = 0x01;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006156
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306157 if (!(pVBInfo->VBInfo & SetInSlaveMode))
6158 tempah |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006159
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006160 if (!(pVBInfo->VBInfo &
6161 SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306162 tempah = tempah ^ 0x05;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006163 if (!(pVBInfo->VBInfo &
6164 SetCRT2ToLCD))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306165 tempah = tempah ^ 0x01;
6166 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006167
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006168 if (!(pVBInfo->VBInfo &
6169 SetCRT2ToDualEdge))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306170 tempah |= 0x08;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006171 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306172 0x2e, tempbl, tempah);
6173 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006174 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306175 0x2e, tempbl, tempah);
6176 }
6177 }
6178 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006179 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306180 tempah);
6181 }
6182 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006183
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306184 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01006185 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306186 tempah &= (~0x08);
6187 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
6188 & SetInSlaveMode))) {
6189 tempah |= 0x010;
6190 }
6191 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306193 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306194 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006195 if (pVBInfo->VBInfo & DriverMode)
6196 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306197 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006198
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006199 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306200 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306202 if (pVBInfo->LCDInfo & SetLCDDualLink)
6203 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306205 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306206 if (pVBInfo->TVInfo & RPLLDIV2XO)
6207 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306208 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006209
Peter Huewe255aabd2012-02-09 21:11:44 +01006210 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
6211 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306212 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006213
Peter Huewe255aabd2012-02-09 21:11:44 +01006214 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306215 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006216
Aaro Koskinen8104e322011-03-13 12:26:22 +02006217 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306218 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006219
Peter Huewe6896b942012-02-09 21:11:46 +01006220 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6221 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306222 tempah = 0;
6223 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306225 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6226 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01006227 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306228 tempah |= 0x04; /* shampoo 0129 */
6229 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006230
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006231 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306232 tempah = 0x00;
6233 tempbl = 0xcf;
6234 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6235 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6236 tempah |= 0x30;
6237 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006238
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006239 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306240 tempah = 0;
6241 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006242
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306243 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6244 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6245 tempah |= 0xc0;
6246 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006247 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306248 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006249
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306250 tempah = 0;
6251 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01006252 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306253 tempbl = 0xff;
6254 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
6255 tempah |= 0x80;
6256 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006257
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006258 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006259
Peter Huewe6896b942012-02-09 21:11:46 +01006260 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306261 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006262 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
6263 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306264 }
6265 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006266}
6267
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006268static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306269 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006270{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306271 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006272
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306273 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006274
Peter Huewea3d675c2012-02-09 21:11:47 +01006275 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306276 tempbx = 0x08A0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006277
6278}
6279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306280void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6281 struct vb_device_info *pVBInfo)
6282{
6283
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006284 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006285
6286}
6287
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306288void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6289 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006290{
6291
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006292 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006293
6294}
6295
Bill Pemberton80adad82010-06-17 13:10:51 -04006296unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006297{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306298 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006299
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306300 if (pVBInfo->IF_DEF_LVDS == 1) {
6301 return 1;
6302 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006303 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306304 if ((flag == 1) || (flag == 2))
6305 return 1; /* 301b */
6306 else
6307 return 0;
6308 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006309}
6310
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006311unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
6312 unsigned short ModeNo, unsigned short ModeIdIndex,
6313 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006314{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006315 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
6316 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
6317 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006318
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006319 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006320
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006321 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006322
Aaro Koskinen58839b02011-03-13 12:26:23 +02006323 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006324 index = index >> pVBInfo->SelectCRT2Rate;
6325 index &= 0x0F;
6326
6327 if (pVBInfo->LCDInfo & LCDNonExpanding)
6328 index = 0;
6329
6330 if (index > 0)
6331 index--;
6332
6333 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006334 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006335 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01006336 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
6337 | VB_SIS301LV | VB_SIS302LV
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006338 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006339 /* 301b */
6340 temp = LCDARefreshIndex[
6341 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006342 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006343 temp = LCDRefreshIndex[
6344 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006345
6346 if (index > temp)
6347 index = temp;
6348 } else {
6349 index = 0;
6350 }
6351 }
6352 }
6353
6354 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
6355 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
6356 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006357 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
6358 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006359 index++;
6360 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006361 /* Alan 10/19/2007;
6362 * do the similar adjustment like XGISearchCRT1Rate() */
6363 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
6364 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006365 index++;
6366 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006367 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
6368 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006369 index++;
6370 }
6371 }
6372
6373 i = 0;
6374 do {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006375 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
6376 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006377 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006378 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
6379 Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01006380 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006381 if (temp < pVBInfo->ModeType)
6382 break;
6383 i++;
6384 index--;
6385
6386 } while (index != 0xFFFF);
6387 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
6388 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006389 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
6390 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006391 if (temp & InterlaceMode)
6392 i++;
6393 }
6394 }
6395 i--;
6396 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
6397 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
6398 RefreshRateTableIndex, &i, pVBInfo);
6399 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02006400 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006401}
6402
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006403static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306404 struct xgi_hw_device_info *HwDeviceExtension,
6405 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006406{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006407 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006408
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006409 pVBInfo->SetFlag |= ProgrammingCRT2;
6410 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6411 ModeIdIndex, pVBInfo);
6412 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
6413 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6414 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6415 HwDeviceExtension, pVBInfo);
6416 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6417 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006418}
6419
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02006420static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006421 struct xgi_hw_device_info *HwDeviceExtension,
6422 struct vb_device_info *pVBInfo)
6423{
6424 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
6425
6426 tempbx = pVBInfo->VBInfo;
6427 pVBInfo->SetFlag |= ProgrammingCRT2;
6428 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6429 pVBInfo->SelectCRT2Rate = 4;
6430 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6431 ModeIdIndex, pVBInfo);
6432 XGI_SaveCRT2Info(ModeNo, pVBInfo);
6433 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
6434 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6435 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
6436 RefreshRateTableIndex, pVBInfo);
6437 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
6438 RefreshRateTableIndex, pVBInfo);
6439 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
6440 RefreshRateTableIndex, pVBInfo);
6441 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6442 HwDeviceExtension, pVBInfo);
6443 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
6444 RefreshRateTableIndex, pVBInfo);
6445 XGI_SetTap4Regs(pVBInfo);
6446 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
6447 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6448 HwDeviceExtension, pVBInfo);
6449 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6450 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
6451 XGI_AutoThreshold(pVBInfo);
6452 return 1;
6453}
6454
6455void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
6456{
6457 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
6458 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
6459 0x05, 0x00 };
6460
6461 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
6462
6463 unsigned char CR17, CR63, SR31;
6464 unsigned short temp;
6465 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
6466
6467 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006468 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006469
6470 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006471 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006472 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006473 pVBInfo->P3d4, 0x53) | 0x02));
6474
Aaro Koskinen58839b02011-03-13 12:26:23 +02006475 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
6476 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
6477 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006478
Aaro Koskinen8104e322011-03-13 12:26:22 +02006479 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
6480 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006481
Aaro Koskinen58839b02011-03-13 12:26:23 +02006482 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006483 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006484
Aaro Koskinen58839b02011-03-13 12:26:23 +02006485 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006486 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006487
Aaro Koskinen58839b02011-03-13 12:26:23 +02006488 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006489 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02006490 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006491 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006492
Aaro Koskinen8104e322011-03-13 12:26:22 +02006493 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006494
6495 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006496 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006497
6498 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006499 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006500 CRTCData[i]);
6501
6502 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006503 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006504 CRTCData[i]);
6505
6506 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006507 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006508 CRTCData[i]);
6509
Aaro Koskinen8104e322011-03-13 12:26:22 +02006510 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006511 & 0xE0));
6512
Aaro Koskinen8104e322011-03-13 12:26:22 +02006513 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
6514 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
6515 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006516
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006517 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006518
6519 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006520 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
6521 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
6522 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006523 }
6524
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006525 mdelay(1);
6526
6527 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006528 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006529
6530 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006531 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006532 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006533 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006534
6535 /* alan, avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006536 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006537
6538 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006539 outb(0, (pVBInfo->P3c8 + 1));
6540 outb(0, (pVBInfo->P3c8 + 1));
6541 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006542 }
6543
Aaro Koskinen8104e322011-03-13 12:26:22 +02006544 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
6545 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
6546 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006547
6548 /* [2004/05/11] Vicent */
Aaro Koskinen58839b02011-03-13 12:26:23 +02006549 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006550 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006551 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006552}
6553
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006554static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
6555 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006556 struct vb_device_info *pVBInfo)
6557{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02006558 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006559
Peter Huewe6896b942012-02-09 21:11:46 +01006560 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6561 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006562 if (!(pVBInfo->SetFlag & DisableChA)) {
6563 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006564 /* Power on */
6565 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006566 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006567 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6568 /* Power on */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006569 xgifb_reg_set(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006570 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006571 }
6572 }
6573 }
6574
6575 if (!(pVBInfo->SetFlag & DisableChB)) {
6576 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
6577 & (SetCRT2ToLCD | SetCRT2ToTV
6578 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006579 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006580 pVBInfo->P3c4, 0x32);
6581 tempah &= 0xDF;
6582 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006583 if (!(pVBInfo->VBInfo &
6584 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006585 tempah |= 0x20;
6586 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02006587 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006588 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006589
Aaro Koskinen58839b02011-03-13 12:26:23 +02006590 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006591 pVBInfo->Part1Port, 0x2E);
6592
6593 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006594 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006595 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006596 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006597 }
6598 }
6599
6600 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
6601 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006602 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006603 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01006604 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006605 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006606 if (XGI_EnableChISLCD(pVBInfo) ||
6607 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01006608 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006609 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02006610 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006611 pVBInfo->Part4Port,
6612 0x2A,
6613 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006614 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006615 /* LVDS Driver power on */
6616 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006617 }
6618 }
6619
6620 tempah = 0x00;
6621
6622 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6623 tempah = 0xc0;
6624
6625 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006626 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006627 if (pVBInfo->VBInfo &
6628 SetCRT2ToDualEdge) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006629 tempah = tempah & 0x40;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006630 if (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01006631 XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006632 tempah = tempah ^ 0xC0;
6633
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006634 if (pVBInfo->SetFlag &
6635 DisableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006636 tempah &= 0xBF;
6637
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006638 if (pVBInfo->SetFlag &
6639 DisableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006640 tempah &= 0x7F;
6641
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006642 if (pVBInfo->SetFlag &
6643 EnableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006644 tempah |= 0x40;
6645
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006646 if (pVBInfo->SetFlag &
6647 EnableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006648 tempah |= 0x80;
6649 }
6650 }
6651 }
6652 }
6653
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006654 /* EnablePart4_1F */
6655 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006656
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006657 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006658 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006659 XGI_DisableGatingCRT(HwDeviceExtension,
6660 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006661 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
6662 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006663 }
6664 }
6665 } /* 301 */
6666 else { /* LVDS */
6667 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01006668 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006669 /* enable CRT2 */
6670 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006671
Aaro Koskinen58839b02011-03-13 12:26:23 +02006672 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006673 0x2E);
6674 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006675 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006676
Aaro Koskinendc505562011-03-13 12:26:26 +02006677 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006678 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006679 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006680}
6681
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006682static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
6683 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006684 unsigned short ModeNo, unsigned short ModeIdIndex,
6685 struct vb_device_info *pVBInfo)
6686{
Aaro Koskinena1579612012-04-07 01:14:05 +03006687 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006688
Aaro Koskinena1579612012-04-07 01:14:05 +03006689 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +03006690 outb(pVBInfo->StandTable->MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03006691 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
6692 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
6693 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006694 XGI_ClearExt1Regs(pVBInfo);
6695
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006696 if (HwDeviceExtension->jChipType == XG27) {
6697 if (pVBInfo->IF_DEF_LVDS == 0)
6698 XGI_SetDefaultVCLK(pVBInfo);
6699 }
6700
6701 temp = ~ProgrammingCRT2;
6702 pVBInfo->SetFlag &= temp;
6703 pVBInfo->SelectCRT2Rate = 0;
6704
Peter Huewe6896b942012-02-09 21:11:46 +01006705 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6706 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006707 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006708 | SetInSlaveMode)) {
6709 pVBInfo->SetFlag |= ProgrammingCRT2;
6710 }
6711 }
6712
6713 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6714 ModeIdIndex, pVBInfo);
6715 if (RefreshRateTableIndex != 0xFFFF) {
6716 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
6717 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6718 pVBInfo, HwDeviceExtension);
6719 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
6720 RefreshRateTableIndex, pVBInfo);
6721 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6722 HwDeviceExtension, pVBInfo);
6723 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
6724 RefreshRateTableIndex, pVBInfo);
6725 }
6726
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006727 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006728 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006729 if (temp & 0xA0) {
6730
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006731 if (HwDeviceExtension->jChipType == XG27)
6732 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
6733 RefreshRateTableIndex, pVBInfo);
6734 else
6735 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
6736 RefreshRateTableIndex, pVBInfo);
6737
6738 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
6739 RefreshRateTableIndex);
6740
Aaro Koskinen105d8d02011-08-31 21:46:00 +03006741 xgifb_set_lcd(HwDeviceExtension->jChipType,
6742 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006743
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006744 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006745 xgifb_set_lvds(xgifb_info,
6746 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006747 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006748 }
6749 }
6750
6751 pVBInfo->SetFlag &= (~ProgrammingCRT2);
6752 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
6753 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
6754 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006755 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006756}
6757
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006758unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
6759 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006760 unsigned short ModeNo)
6761{
6762 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006763 struct vb_device_info VBINF;
6764 struct vb_device_info *pVBInfo = &VBINF;
Dmitry Eremin-Solenikov9a801f22012-03-19 21:50:13 +04006765 pVBInfo->BaseAddr = xgifb_info->vga_base;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006766 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006767 pVBInfo->IF_DEF_LCDA = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006768
6769 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
6770 pVBInfo->IF_DEF_YPbPr = 0;
6771 pVBInfo->IF_DEF_HiVision = 0;
6772 pVBInfo->IF_DEF_CRT2Monitor = 0;
6773 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006774 } else {
6775 pVBInfo->IF_DEF_YPbPr = 1;
6776 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02006777 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006778 }
6779
6780 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
6781 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
6782 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
6783 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
6784 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
6785 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
6786 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
6787 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
6788 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
6789 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
6790 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
6791 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
6792 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
Peter Huewe6896b942012-02-09 21:11:46 +01006793 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
6794 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
6795 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
6796 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
6797 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006798
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006799 /* for x86 Linux, XG21 LVDS */
6800 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006801 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006802 pVBInfo->IF_DEF_LVDS = 1;
6803 }
6804 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006805 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
6806 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006807 pVBInfo->IF_DEF_LVDS = 1;
6808 }
6809 }
6810
6811 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
6812 XGI_GetVBType(pVBInfo);
6813
6814 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02006815 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006816 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006817 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006818
6819 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
6820 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
6821
6822 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6823
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006824 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
6825 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
6826 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
6827 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006828 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006829
Peter Huewea3d675c2012-02-09 21:11:47 +01006830 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006831 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006832 ModeIdIndex, pVBInfo);
6833
Peter Huewea3d675c2012-02-09 21:11:47 +01006834 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006835 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6836 HwDeviceExtension, pVBInfo);
6837 }
6838 } else {
Peter Huewe6896b942012-02-09 21:11:46 +01006839 if (!(pVBInfo->VBInfo & SwitchCRT2)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006840 XGI_SetCRT1Group(xgifb_info,
6841 HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006842 ModeIdIndex, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01006843 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006844 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6845 HwDeviceExtension,
6846 pVBInfo);
6847 }
6848 }
6849 }
6850
Peter Huewe6896b942012-02-09 21:11:46 +01006851 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006852 switch (HwDeviceExtension->ujVBChipID) {
6853 case VB_CHIP_301:
6854 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6855 pVBInfo); /*add for CRT2 */
6856 break;
6857
6858 case VB_CHIP_302:
6859 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6860 pVBInfo); /*add for CRT2 */
6861 break;
6862
6863 default:
6864 break;
6865 }
6866 }
6867
6868 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
6869 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
6870 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006871 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006872 } /* !XG20 */
6873 else {
6874 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006875 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006876 ModeIdIndex,
6877 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006878 return 0;
6879
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006880 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01006881 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006882
6883 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03006884 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006885
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006886 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006887
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006888 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6889 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006890
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006891 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006892 }
6893
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006894 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
6895
6896 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
6897 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
6898 }
6899
6900 return 1;
6901}