blob: 8795e173cb5aef1f6322a3279e370a745ee1ebc8 [file] [log] [blame]
Aaro Koskinend80aaa02011-02-17 23:29:14 +02001#include <linux/delay.h>
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002#include "XGIfb.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004#include "vb_def.h"
Aaro Koskinen56810a92013-01-21 02:57:47 +02005#include "vb_init.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006#include "vb_util.h"
7#include "vb_table.h"
Miguel Gómeze0541022012-06-18 13:12:05 +02008#include "vb_setmode.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02009
10#define IndexMask 0xff
Peter Huewe95072592012-06-14 00:21:48 +020011#define TVCLKBASE_315_25 (TVCLKBASE_315 + 25)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020012
Aaro Koskinen624554d2011-10-11 21:47:35 +030013static const unsigned short XGINew_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040014 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
15 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
16 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
17 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
18 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
19 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
20 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
21 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
22 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
23 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020024
Bill Pemberton80adad82010-06-17 13:10:51 -040025void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020026{
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030027 pVBInfo->MCLKData = XGI340New_MCLKData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020028
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053029 pVBInfo->LCDResInfo = 0;
30 pVBInfo->LCDTypeInfo = 0;
31 pVBInfo->LCDInfo = 0;
32 pVBInfo->VBInfo = 0;
33 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020034
Aaro Koskinen597d96b2013-03-27 23:53:15 +020035 pVBInfo->SR18 = XGI340_SR18;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053036 pVBInfo->CR40 = XGI340_cr41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020037
Aaro Koskinence76de52013-05-29 23:59:02 +030038 if (ChipType < XG20)
39 XGI_GetVBType(pVBInfo);
40
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053041 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010042 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053043 pVBInfo->LCDCapList = XGI_LCDDLCapList;
44 else
45 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053047 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020048 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053050 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040051 unsigned char temp;
Vitor Braga694683f2014-03-30 00:44:59 -030052
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030053 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053054 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020055 pVBInfo->XGINew_CR97 = 0xc1;
Aaro Koskinen597d96b2013-03-27 23:53:15 +020056 pVBInfo->SR18 = XG27_SR18;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020057
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040058 /*Z11m DDR*/
59 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
60 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
61 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020062 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053063 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020064
65}
66
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +030067static void XGI_SetSeqRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020068{
Peter Huewe76a58992013-02-03 22:54:34 +010069 unsigned char SRdata, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020070
Aaro Koskinen8104e322011-03-13 12:26:22 +020071 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020072
Peter Huewe76a58992013-02-03 22:54:34 +010073 for (i = 0; i < 4; i++) {
74 /* Get SR1,2,3,4 from file */
75 /* SR1 is with screen off 0x20 */
76 SRdata = XGI330_StandTable.SR[i];
77 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053078 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020079}
80
Aaro Koskinenb053af12013-07-16 23:13:28 +030081static void XGI_SetCRTCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020082{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053083 unsigned char CRTCdata;
84 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020085
Peter Huewe9388ad92013-02-15 20:37:10 +010086 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053087 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +020088 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053090 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080091 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020092 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +020093 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053094 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020095}
96
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +030097static void XGI_SetATTRegs(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080098 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020099{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530100 unsigned char ARdata;
101 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200102
Aaro Koskinenb3979922012-11-04 21:14:52 +0200103 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530105 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200106 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200107
108 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
109 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
110 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300111 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200112 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300113 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530115 }
116 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200117
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200118 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200119 outb(i, pVBInfo->P3c0); /* set index */
120 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200122
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200123 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200124 outb(0x14, pVBInfo->P3c0); /* set index */
125 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200126 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200127 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200128}
129
Aaro Koskinena1579612012-04-07 01:14:05 +0300130static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200131{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530132 unsigned char GRdata;
133 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530135 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800136 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200137 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200138 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530139 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530141 if (pVBInfo->ModeType > ModeVGA) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100142 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530143 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200144 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530145 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200146}
147
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200148static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200149{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530150 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200151
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530152 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200153 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200154}
155
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200156static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200157{
158
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200159 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200160 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
161 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200162
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200163 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200164 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
165 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200166
Aaro Koskinendc505562011-03-13 12:26:26 +0200167 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530168 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200169}
170
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300171static unsigned char XGI_AjustCRT2Rate(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530172 unsigned short RefreshRateTableIndex, unsigned short *i,
173 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200174{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530175 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200176
Aaro Koskinenb3979922012-11-04 21:14:52 +0200177 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
178 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200179 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530180 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200181
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300182 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
183 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200184
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300185 if (pVBInfo->VBType & VB_XGI301C)
186 tempax |= SupportCRT2in301C;
187 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200188
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300189 /* 301b */
190 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300191 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200192
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300193 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
194 pVBInfo->LCDResInfo != Panel_1280x960 &&
195 (pVBInfo->LCDInfo & LCDNonExpanding) &&
196 resinfo >= 9)
197 return 0;
198 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200199
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300200 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
201 tempax |= SupportHiVision;
202 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
203 ((resinfo == 4) ||
204 (resinfo == 3 && (pVBInfo->SetFlag & TVSimuMode)) ||
205 (resinfo > 7)))
206 return 0;
207 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO | SetCRT2ToSVIDEO |
208 SetCRT2ToSCART | SetCRT2ToYPbPr525750 |
209 SetCRT2ToHiVision)) {
210 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200211
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300212 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
213 VB_SIS302LV | VB_XGI301C))
214 tempax |= SupportTV1024;
215
216 if (!(pVBInfo->VBInfo & TVSetPAL) &&
217 (modeflag & NoSupportSimuTV) &&
218 (pVBInfo->VBInfo & SetInSlaveMode) &&
219 (!(pVBInfo->VBInfo & SetNotSimuMode)))
220 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530221 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200222
Aaro Koskinena39325d2012-11-04 21:14:53 +0200223 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800224 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200225 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800226 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530227 if (infoflag & tempax)
228 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200229
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530230 if ((*i) == 0)
231 break;
232 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530234 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200235 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800236 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200237 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530238 != tempbx) {
239 return 0;
240 }
241
242 if (infoflag & tempax)
243 return 1;
244 }
245 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200246}
247
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200248static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530249 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200250{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530251 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200252
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800253 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200254 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530255 sync &= 0xC0;
256 temp = 0x2F;
257 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200258 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200259}
260
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200261static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530262 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200263{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530264 unsigned char data, data1, pushax;
265 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200266
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800267 /* unlock cr0-7 */
Peter Huewe9388ad92013-02-15 20:37:10 +0100268 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530269 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200270 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200271
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200272 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200273 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200274
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530275 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200276 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200277 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530278 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530280 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200281 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200282 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530283 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200284
Peter Huewe9388ad92013-02-15 20:37:10 +0100285 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530286 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200287 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530288 data &= 0xE0;
289 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200290 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200291
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530292 if (HwDeviceExtension->jChipType >= XG20) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100293 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530294 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200295 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100296 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530297 data1 = data;
298 data1 &= 0xE0;
299 data &= 0x1F;
300 if (data == 0) {
301 pushax = data;
Peter Huewe9388ad92013-02-15 20:37:10 +0100302 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530303 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200304 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530305 data = pushax;
306 }
307 data = data - 1;
308 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200309 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100310 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530311 data = data >> 5;
312 data = data + 3;
313 if (data > 7)
314 data = data - 7;
315 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200316 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530317 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200318}
319
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800320static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800321 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200322{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530323 unsigned char data;
324 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200325
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530326 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200327 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200328 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530329 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530331 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200332 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200333 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530334 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530336 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200337 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200338 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530339 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200340
Peter Huewe9388ad92013-02-15 20:37:10 +0100341 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530342 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200343 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530344 data &= 0x3F;
345 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200346 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200347
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200348 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530349 data &= 0x80;
350 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200351
Aaro Koskinenb3979922012-11-04 21:14:52 +0200352 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530353 i &= DoubleScanMode;
354 if (i)
355 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200356
Peter Huewe9388ad92013-02-15 20:37:10 +0100357 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530358 j &= 0x5F;
359 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200360 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200361}
362
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300363static void XGI_SetCRT1CRTC(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200364 unsigned short RefreshRateTableIndex,
365 struct vb_device_info *pVBInfo,
366 struct xgi_hw_device_info *HwDeviceExtension)
367{
368 unsigned char index, data;
369 unsigned short i;
370
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800371 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200372 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200373 index = index & IndexMask;
374
Peter Huewe9388ad92013-02-15 20:37:10 +0100375 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200376 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200377 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200378
379 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200380 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200381 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200382
383 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200384 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200385 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200386
387 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
388
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300389 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200390
391 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200392 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200393}
394
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200395/* --------------------------------------------------------------------- */
396/* Function : XGI_SetXG21CRTC */
397/* Input : Stand or enhance CRTC table */
398/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
399/* Description : Set LCD timing */
400/* --------------------------------------------------------------------- */
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +0300401static void XGI_SetXG21CRTC(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530402 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200403{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300404 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530405 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200406
Aaro Koskinena39325d2012-11-04 21:14:53 +0200407 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300408 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200409 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300410 Tempcx = Tempax; /* Tempcx: HRS */
411 /* SR2E[7:0]->HRS */
412 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200413
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200414 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300415 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
416 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
417 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
418 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800419
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200420 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300421 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200422
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200423 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300424 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
425 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
426 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200427
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300428 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
429 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200430
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300431 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
432 if (Tempax < Tempcx) /* HRE < HRS */
433 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200434
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300435 Temp2 &= 0xFF;
436 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
437 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
438 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
439 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
440 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
441 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
442 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200443
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300444 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200445 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300446 Tempbx = Tempax; /* Tempbx: VRS */
447 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
448 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
449 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200450 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300451 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
452 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
453 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
454 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
455 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200456
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300457 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
458 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
459 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
460 Tempax &= 0x80;
461 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
462 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
463 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200464 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300465 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
466 Temp2 = Tempax;
467 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
468 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200469
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300470 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200471 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300472 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
473 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200474 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300475 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
476 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
477 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
478 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
479 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200480
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300481 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
482 if (Tempax < Temp3) /* VRE < VRS */
483 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200484
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300485 Temp2 &= 0xFF;
486 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
487 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
488 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
489 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
490 Tempbx = (unsigned char) Temp1;
491 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
492 Tempax &= 0x7F;
493 /* SR3F D[7:2]->VRE D[1:0]->VRS */
494 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200495}
496
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +0300497static void XGI_SetXG27CRTC(unsigned short RefreshRateTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800498 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200499{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300500 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200501
Aaro Koskinena39325d2012-11-04 21:14:53 +0200502 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300503 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200504 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300505 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
506 /* SR2E[7:0]->HRS */
507 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200508
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300509 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200510 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300511 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
512 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200513
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200514 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300515 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
516 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200517
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200518 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300519 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
520 Tempax <<= 3; /* Tempax[5]: HRE[5] */
521 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200522
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300523 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
524 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200525
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300526 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200527 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300528 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
529 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
530 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200531
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200532 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300533 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
534 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
535 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
536 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
537 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
538 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200539
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300540 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200541 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300542 /* SR34[7:0]->VRS[7:0] */
543 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200544
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300545 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
546 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200547 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300548 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
549 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
550 Tempax >>= 2; /* Tempax[0]: VRS[8] */
551 /* SR35[0]: VRS[8] */
552 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
553 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
554 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
555 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200556 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300557 Tempax &= 0x08; /* SR0A[3] VRS[10] */
558 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200559
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300560 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200561 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300562 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
563 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200564 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300565 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
566 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
567 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
568 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
569 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
570 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200571
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300572 if (Tempbx <= Tempcx) /* VRE <= VRS */
573 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200574
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300575 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
576 Tempax = (Tempbx << 2) & 0xFF;
577 /* SR3F[7:2]:VRE[5:0] */
578 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
579 Tempax = Tempcx >> 8;
580 /* SR35[2:0]:VRS[10:8] */
581 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200582}
583
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200584static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
585{
586 unsigned char temp;
587
588 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
589 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
590 temp = (temp & 3) << 6;
591 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
592 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
593 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
594 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
595
596}
597
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300598static void xgifb_set_lcd(int chip_id,
599 struct vb_device_info *pVBInfo,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300600 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200601{
Peter Huewee2e544c2013-02-03 04:08:46 +0100602 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200603
Aaro Koskinen8104e322011-03-13 12:26:22 +0200604 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
605 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
606 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
607 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300608
609 if (chip_id == XG27) {
Peter Huewee2e544c2013-02-03 04:08:46 +0100610 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
611 if ((temp & 0x03) == 0) { /* dual 12 */
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300612 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
613 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
614 }
615 }
616
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300617 if (chip_id == XG27) {
618 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530619 } else {
Peter Huewee2e544c2013-02-03 04:08:46 +0100620 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
621 if (temp & 0x01) {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300622 /* 18 bits FP */
623 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
624 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
625 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530626 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200627
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200628 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200629
Aaro Koskinendc505562011-03-13 12:26:26 +0200630 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
631 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200632
Peter Huewee2e544c2013-02-03 04:08:46 +0100633 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
634 if (temp & 0x4000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300635 /* Hsync polarity */
636 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Peter Huewee2e544c2013-02-03 04:08:46 +0100637 if (temp & 0x8000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300638 /* Vsync polarity */
639 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200640}
641
642/* --------------------------------------------------------------------- */
643/* Function : XGI_UpdateXG21CRTC */
644/* Input : */
645/* Output : CRT1 CRTC */
646/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
647/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800648static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
649 struct vb_device_info *pVBInfo,
650 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200651{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300652 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200653
Aaro Koskinendc505562011-03-13 12:26:26 +0200654 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300655 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200656 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300657 RES640x480x60))
658 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200659 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800660 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300661 index = 13;
662 else if (ModeNo == 0x2F)
663 index = 14;
664 else if (ModeNo == 0x50)
665 index = 15;
666 else if (ModeNo == 0x59)
667 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200668
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530669 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200670 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200671 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200672 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200673 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200674 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200675 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200676 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200677 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530678 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200679}
680
Aaro Koskinenb053af12013-07-16 23:13:28 +0300681static void XGI_SetCRT1DE(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530682 unsigned short RefreshRateTableIndex,
683 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200684{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400685 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200686
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530687 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200688
Aaro Koskinenb3979922012-11-04 21:14:52 +0200689 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200690
Aaro Koskinenb3979922012-11-04 21:14:52 +0200691 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinene8e6c752012-11-04 21:15:00 +0200692 tempax = XGI330_ModeResInfo[resindex].HTotal;
693 tempbx = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200694
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530695 if (modeflag & HalfDCLK)
696 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200697
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300698 if (modeflag & HalfDCLK)
699 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200700
Aaro Koskinena39325d2012-11-04 21:14:53 +0200701 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200702
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300703 if (temp & InterlaceMode)
704 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200705
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300706 if (modeflag & DoubleScanMode)
707 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200708
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530709 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200710
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530711 tempax /= tempcx;
712 tempax -= 1;
713 tempbx -= 1;
714 tempcx = tempax;
Peter Huewe9388ad92013-02-15 20:37:10 +0100715 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
716 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530717 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200718 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
719 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200720 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530721 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200722 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530723 tempax = 0;
724 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200725
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530726 if (tempbx & 0x01)
727 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200728
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530729 if (tempbx & 0x02)
730 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200731
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200732 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Peter Huewe9388ad92013-02-15 20:37:10 +0100733 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530734 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200735
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530736 if (tempbx & 0x04)
737 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200738
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200739 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200740 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200741}
742
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800743static void XGI_SetCRT1Offset(unsigned short ModeNo,
744 unsigned short ModeIdIndex,
745 unsigned short RefreshRateTableIndex,
746 struct xgi_hw_device_info *HwDeviceExtension,
747 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200748{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530749 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200750
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530751 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200752 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530753 temp = temp >> 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200754 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200755
Aaro Koskinena39325d2012-11-04 21:14:53 +0200756 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530757 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200758
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530759 if (temp2)
760 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200761
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530762 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200763
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530764 switch (temp2) {
765 case 0:
766 temp2 = 1;
767 break;
768 case 1:
769 temp2 = 2;
770 break;
771 case 2:
772 temp2 = 4;
773 break;
774 case 3:
775 temp2 = 4;
776 break;
777 case 4:
778 temp2 = 6;
779 break;
780 case 5:
781 temp2 = 8;
782 break;
783 default:
784 break;
785 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200786
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530787 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
788 temp = temp * temp2 + temp2 / 2;
789 else
790 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200791
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530792 /* SetOffset */
793 DisplayUnit = temp;
794 temp2 = temp;
795 temp = temp >> 8; /* ah */
796 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200797 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530798 i &= 0xF0;
799 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200800 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530802 temp = (unsigned char) temp2;
803 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200804 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200805
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530806 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200807 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530808 temp2 &= InterlaceMode;
809 if (temp2)
810 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200811
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530812 DisplayUnit = DisplayUnit << 5;
813 ah = (DisplayUnit & 0xff00) >> 8;
814 al = DisplayUnit & 0x00ff;
815 if (al == 0)
816 ah += 1;
817 else
818 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530820 if (HwDeviceExtension->jChipType >= XG20)
821 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
822 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200823
Aaro Koskinen8104e322011-03-13 12:26:22 +0200824 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200825}
826
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300827static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200828 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200829 struct vb_device_info *pVBInfo)
830{
Peter Hueweef9a6b92013-02-03 04:08:43 +0100831 unsigned short VCLKIndex, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200832
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300833 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200834 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200835
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200836 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
837 if (pVBInfo->LCDResInfo != Panel_1024x768)
838 /* LCDXlat2VCLK */
839 VCLKIndex = VCLK108_2_315 + 5;
840 else
841 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
842 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
843 if (pVBInfo->SetFlag & RPLLDIV2XO)
844 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
845 else
846 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200847
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200848 if (pVBInfo->SetFlag & TVSimuMode) {
Ebru Akagunduz4759e822013-10-29 22:50:54 +0200849 if (modeflag & Charx8Dot)
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200850 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
Ebru Akagunduz4759e822013-10-29 22:50:54 +0200851 else
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200852 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200853 }
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200854
855 /* 301lv */
856 if (pVBInfo->VBType & VB_SIS301LV) {
857 if (pVBInfo->SetFlag & RPLLDIV2XO)
858 VCLKIndex = YPbPr525iVCLK_2;
859 else
860 VCLKIndex = YPbPr525iVCLK;
861 }
862 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
863 if (pVBInfo->SetFlag & RPLLDIV2XO)
864 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
865 else
866 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
867 } else { /* for CRT2 */
868 /* di+Ext_CRTVCLK */
869 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
870 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200871 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200872
873 return VCLKIndex;
874}
875
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300876static void XGI_SetCRT1VCLK(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800877 struct xgi_hw_device_info *HwDeviceExtension,
878 unsigned short RefreshRateTableIndex,
879 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200880{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400881 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530882 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200883
Aaro Koskinenb750f512013-05-29 23:59:05 +0300884 if ((pVBInfo->IF_DEF_LVDS == 0) &&
885 (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
886 VB_SIS302LV | VB_XGI301C)) &&
887 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300888 vclkindex = XGI_GetVCLK2Ptr(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinenb053af12013-07-16 23:13:28 +0300889 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200890 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200891 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200892 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200893 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200894 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200895 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
896 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530897 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200898 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200899 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200900 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200901 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
902 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200903 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530904 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200905
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530906 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200907 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800908 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200909 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200910 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200911 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530912 index = data;
913 index &= 0xE0;
914 data &= 0x1F;
915 data = data << 1;
916 data += 1;
917 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200918 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530919 }
920 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200921}
922
Aaro Koskinene85f2032011-11-27 23:03:07 +0200923static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
924{
925 unsigned char temp;
926
927 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
928 temp = (temp & 1) << 6;
929 /* SR06[6] 18bit Dither */
930 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
931 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
932 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
933
934}
935
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300936static void XGI_SetCRT1FIFO(struct xgi_hw_device_info *HwDeviceExtension,
937 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200938{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530939 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200940
Aaro Koskinen58839b02011-03-13 12:26:23 +0200941 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530942 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200943 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200944
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300945 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
946 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
947 data &= 0xC0;
948 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
949 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
950 data |= 0x01;
951 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200952
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530953 if (HwDeviceExtension->jChipType == XG21)
954 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200955}
956
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200957static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300958 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200959 struct vb_device_info *pVBInfo)
960{
961 unsigned short data, data2 = 0;
962 short VCLK;
963
964 unsigned char index;
965
Aaro Koskinena39325d2012-11-04 21:14:53 +0200966 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300967 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200968 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200969
Aaro Koskinen58839b02011-03-13 12:26:23 +0200970 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200971 data &= 0xf3;
972 if (VCLK >= 200)
973 data |= 0x0c; /* VCLK > 200 */
974
975 if (HwDeviceExtension->jChipType >= XG20)
976 data &= ~0x04; /* 2 pixel mode */
977
Aaro Koskinen8104e322011-03-13 12:26:22 +0200978 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200979
980 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200981 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200982 data &= 0xE7;
983 if (VCLK < 200)
984 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200985 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200986 }
987
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200988 data2 = 0x00;
989
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200990 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200991 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200992 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200993
994}
995
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200996static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300997 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530998 unsigned short RefreshRateTableIndex,
999 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001000{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301001 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1002 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001003
Aaro Koskinenb3979922012-11-04 21:14:52 +02001004 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001005 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001006
Aaro Koskinen58839b02011-03-13 12:26:23 +02001007 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001008 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001009
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001010 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301011 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001012 data2 |= 0x02;
1013 data3 = pVBInfo->ModeType - ModeVGA;
1014 data3 = data3 << 2;
1015 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301016 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001017
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301018 if (data)
1019 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001020
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001021 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001022 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001023 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301025 data = 0x0000;
1026 if (infoflag & InterlaceMode) {
1027 if (xres == 1024)
1028 data = 0x0035;
1029 else if (xres == 1280)
1030 data = 0x0048;
1031 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001032
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001033 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1034 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301036 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001037 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301039 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301041 if (modeflag & LineCompareOff)
1042 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001043
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001044 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301045 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001046 data = data ^ 0x60;
1047 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001048 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001049
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001050 XGI_SetVCLKState(HwDeviceExtension, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001051
Aaro Koskinen58839b02011-03-13 12:26:23 +02001052 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301054 if (HwDeviceExtension->jChipType == XG27) {
1055 if (data & 0x40)
1056 data = 0x2c;
1057 else
1058 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001059 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001060 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301061 } else if (HwDeviceExtension->jChipType >= XG20) {
1062 if (data & 0x40)
1063 data = 0x33;
1064 else
1065 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001066 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1067 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301068 } else {
1069 if (data & 0x40)
1070 data = 0x2c;
1071 else
1072 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001073 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301074 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001075
1076}
1077
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001078static void XGI_WriteDAC(unsigned short dl,
1079 unsigned short ah,
1080 unsigned short al,
1081 unsigned short dh,
1082 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001083{
1084 unsigned short temp, bh, bl;
1085
1086 bh = ah;
1087 bl = al;
1088
1089 if (dl != 0) {
1090 temp = bh;
1091 bh = dh;
1092 dh = temp;
1093 if (dl == 1) {
1094 temp = bl;
1095 bl = dh;
1096 dh = temp;
1097 } else {
1098 temp = bl;
1099 bl = bh;
1100 bh = temp;
1101 }
1102 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001103 outb((unsigned short) dh, pVBInfo->P3c9);
1104 outb((unsigned short) bh, pVBInfo->P3c9);
1105 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001106}
1107
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03001108static void XGI_LoadDAC(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001109{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001110 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1111 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001112
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001113 outb(0xFF, pVBInfo->P3c6);
1114 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001115
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001116 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301117 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001118
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301119 for (k = 0; k < 3; k++) {
1120 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301122 if (data & 0x01)
1123 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301125 if (data & 0x02)
1126 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001127
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001128 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301129 data = data >> 2;
1130 }
1131 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001132
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001133 for (i = 16; i < 32; i++) {
1134 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001135
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001136 for (k = 0; k < 3; k++)
1137 outb(data, pVBInfo->P3c9);
1138 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001139
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001140 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001141
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001142 for (m = 0; m < 9; m++) {
1143 di = si;
1144 bx = si + 0x04;
1145 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001146
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001147 for (n = 0; n < 3; n++) {
1148 for (o = 0; o < 5; o++) {
1149 dh = table[si];
1150 ah = table[di];
1151 al = table[bx];
1152 si++;
1153 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301154 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001155
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001156 si -= 2;
1157
1158 for (o = 0; o < 3; o++) {
1159 dh = table[bx];
1160 ah = table[di];
1161 al = table[si];
1162 si--;
1163 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1164 }
1165
1166 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301167 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001168
1169 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301170 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001171}
1172
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001173static void XGI_GetLVDSResInfo(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001174 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001175{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301176 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001177
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001178 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001179 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001180
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001181 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001182 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001183
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001184 xres = XGI330_ModeResInfo[resindex].HTotal;
1185 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001186
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001187 if (modeflag & HalfDCLK)
1188 xres = xres << 1;
1189
1190 if (modeflag & DoubleScanMode)
1191 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301193 if (xres == 720)
1194 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301196 pVBInfo->VGAHDE = xres;
1197 pVBInfo->HDE = xres;
1198 pVBInfo->VGAVDE = yres;
1199 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001200}
1201
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001202static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001203 unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001204 struct vb_device_info *pVBInfo)
1205{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001206 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001207
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001208 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001209
Aaro Koskinenb3979922012-11-04 21:14:52 +02001210 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001211
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001212 i = 0;
1213
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001214 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001215 tempdx = pVBInfo->LCDResInfo;
1216 if (tempbx & 0x0080) { /* OEMUtil */
1217 tempbx &= (~0x0080);
1218 tempdx = pVBInfo->LCDTypeInfo;
1219 }
1220
1221 if (pVBInfo->LCDInfo & EnableScalingLCD)
1222 tempdx &= (~PanelResInfo);
1223
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001224 if (table[i].PANELID == tempdx) {
1225 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001226 tempdx = pVBInfo->LCDInfo;
1227
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001228 if (modeflag & HalfDCLK)
1229 tempdx |= SetLCDLowResolution;
1230
1231 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001232 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001233 break;
1234 }
1235 i++;
1236 }
1237
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001238 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001239}
1240
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001241static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001242 unsigned short RefreshRateTableIndex,
1243 struct vb_device_info *pVBInfo)
1244{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001245 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001246
Aaro Koskinenb3979922012-11-04 21:14:52 +02001247 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001248 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001249 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001250 tempdx = pVBInfo->TVInfo;
1251
1252 if (pVBInfo->VBInfo & SetInSlaveMode)
1253 tempdx = tempdx | SetTVLockMode;
1254
1255 if (modeflag & HalfDCLK)
1256 tempdx = tempdx | SetTVLowResolution;
1257
1258 i = 0;
1259
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001260 while (XGI_TVDataTable[i].MASK != 0xffff) {
1261 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1262 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001263 break;
1264 i++;
1265 }
1266
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001267 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001268}
1269
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001270static void XGI_GetLVDSData(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001271 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001272{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001273 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001274
Aaro Koskinen6008f872012-11-04 21:14:49 +02001275 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1276 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001277
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001278 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeIdIndex, pVBInfo);
Aaro Koskinen6008f872012-11-04 21:14:49 +02001279 pVBInfo->VGAHT = LCDPtr->VGAHT;
1280 pVBInfo->VGAVT = LCDPtr->VGAVT;
1281 pVBInfo->HT = LCDPtr->LCDHT;
1282 pVBInfo->VT = LCDPtr->LCDVT;
1283
1284 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1285 return;
1286
1287 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1288 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1289 pVBInfo->HDE = 1024;
1290 pVBInfo->VDE = 768;
1291 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1292 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1293 pVBInfo->HDE = 1280;
1294 pVBInfo->VDE = 1024;
1295 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1296 pVBInfo->HDE = 1400;
1297 pVBInfo->VDE = 1050;
1298 } else {
1299 pVBInfo->HDE = 1600;
1300 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301301 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001302}
1303
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001304static void XGI_ModCRT1Regs(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001305 struct xgi_hw_device_info *HwDeviceExtension,
1306 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001307{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001308 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001309 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1310 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001311
Peter Huewea3d675c2012-02-09 21:11:47 +01001312 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001313 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001314 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001315
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001316 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001317 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301318 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001319
1320 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1321
Peter Huewea3d675c2012-02-09 21:11:47 +01001322 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001323 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001324 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001325 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001326 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001327 }
1328
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001329 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001330}
1331
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001332static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1333{
1334 unsigned char tempal, tempah, tempbl, i;
1335
Aaro Koskinen58839b02011-03-13 12:26:23 +02001336 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001337 tempal = tempah & 0x0F;
1338 tempah = tempah & 0xF0;
1339 i = 0;
1340 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1341
1342 while (tempbl != 0xFF) {
1343 if (tempbl & 0x80) { /* OEMUtil */
1344 tempal = tempah;
1345 tempbl = tempbl & ~(0x80);
1346 }
1347
1348 if (tempal == tempbl)
1349 break;
1350
1351 i++;
1352
1353 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1354 }
1355
1356 return i;
1357}
1358
1359static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1360{
1361 unsigned short tempah, tempal, tempbl, i;
1362
1363 tempal = pVBInfo->LCDResInfo;
1364 tempah = pVBInfo->LCDTypeInfo;
1365
1366 i = 0;
1367 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1368
1369 while (tempbl != 0xFF) {
1370 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1371 tempal = tempah;
1372 tempbl &= ~0x80;
1373 }
1374
1375 if (tempal == tempbl)
1376 break;
1377
1378 i++;
1379 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1380 }
1381
1382 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001383 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001384 pVBInfo->LCDTypeInfo = 0;
1385 i = 0;
1386 }
1387
1388 return i;
1389}
1390
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001391static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1392 unsigned short *VSyncWidth,
1393 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001394{
1395 unsigned short Index;
1396
1397 Index = XGI_GetLCDCapPtr(pVBInfo);
1398 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1399 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001400}
1401
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001402static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001403 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001404{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301405 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1406 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001407 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001408
Aaro Koskinenb3979922012-11-04 21:14:52 +02001409 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001410 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001411
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001412 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1413 push1 = tempbx;
1414 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001415
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001416 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001417 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1418 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001419 tempax = 1024;
1420 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001421 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1422 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001423 tempax = 1280;
1424 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001425 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001426 tempax = 1400;
1427 tempbx = 1050;
1428 } else {
1429 tempax = 1600;
1430 tempbx = 1200;
1431 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001432
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001433 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1434 pVBInfo->HDE = tempax;
1435 pVBInfo->VDE = tempbx;
1436 pVBInfo->VGAHDE = tempax;
1437 pVBInfo->VGAVDE = tempbx;
1438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001439
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001440 tempax = pVBInfo->HT;
1441
Peter Huewe826215d2013-02-05 00:29:46 +01001442 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001443
1444 tempcx = pVBInfo->HDE;
1445 tempbx = tempbx & 0x0fff;
1446 tempcx += tempbx;
1447
1448 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001449 tempcx -= tempax;
1450
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001451 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001452
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001453 tempcx = tempcx >> 3;
1454 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001455
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001456 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1457 (unsigned short) (tempbx & 0xff));
1458 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1459 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001460
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001461 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001462
Peter Huewe826215d2013-02-05 00:29:46 +01001463 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001464
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001465 tempcx = push2;
1466
1467 if (pVBInfo->LCDInfo & EnableScalingLCD)
1468 tempcx = LCDPtr1->LCDHSync;
1469
1470 tempcx += tempbx;
1471
1472 if (tempcx >= tempax)
1473 tempcx -= tempax;
1474
1475 tempax = tempbx & 0x07;
1476 tempax = tempax >> 5;
1477 tempcx = tempcx >> 3;
1478 tempbx = tempbx >> 3;
1479
1480 tempcx &= 0x1f;
1481 tempax |= tempcx;
1482
1483 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1484 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1485 (unsigned short) (tempbx & 0xff));
1486
1487 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001488 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001489 tempcx = pVBInfo->VDE;
1490
1491 tempbx = tempbx & 0x0fff;
1492 tempcx += tempbx;
1493 if (tempcx >= tempax)
1494 tempcx -= tempax;
1495
1496 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1497 (unsigned short) (tempbx & 0xff));
1498 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1499 (unsigned short) (tempcx & 0xff));
1500
1501 tempbx = (tempbx >> 8) & 0x07;
1502 tempcx = (tempcx >> 8) & 0x07;
1503
1504 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1505 (unsigned short) ((tempcx << 3)
1506 | tempbx));
1507
1508 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001509 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001510
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001511 tempcx = push1;
1512
1513 if (pVBInfo->LCDInfo & EnableScalingLCD)
1514 tempcx = LCDPtr1->LCDVSync;
1515
1516 tempcx += tempbx;
1517 if (tempcx >= tempax)
1518 tempcx -= tempax;
1519
1520 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1521 (unsigned short) (tempbx & 0xff));
1522 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1523 (unsigned short) (tempcx & 0x0f));
1524
1525 tempax = ((tempbx >> 8) & 0x07) << 3;
1526
1527 tempbx = pVBInfo->VGAVDE;
1528 if (tempbx != pVBInfo->VDE)
1529 tempax |= 0x40;
1530
Peter Huewea3d675c2012-02-09 21:11:47 +01001531 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001532 tempax |= 0x40;
1533
1534 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1535 tempax);
1536
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001537 tempbx = pVBInfo->VDE;
1538 tempax = pVBInfo->VGAVDE;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001539
1540 temp = tempax; /* 0430 ylshieh */
1541 temp1 = (temp << 18) / tempbx;
1542
1543 tempdx = (unsigned short) ((temp << 18) % tempbx);
1544
1545 if (tempdx != 0)
1546 temp1 += 1;
1547
1548 temp2 = temp1;
1549 push3 = temp2;
1550
1551 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1552 (unsigned short) (temp2 & 0xff));
1553 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1554 (unsigned short) ((temp2 >> 8) & 0xff));
1555
1556 tempbx = (unsigned short) (temp2 >> 16);
1557 tempax = tempbx & 0x03;
1558
1559 tempbx = pVBInfo->VGAVDE;
1560 if (tempbx == pVBInfo->VDE)
1561 tempax |= 0x04;
1562
1563 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1564
1565 if (pVBInfo->VBType & VB_XGI301C) {
1566 temp2 = push3;
1567 xgifb_reg_set(pVBInfo->Part4Port,
1568 0x3c,
1569 (unsigned short) (temp2 & 0xff));
1570 xgifb_reg_set(pVBInfo->Part4Port,
1571 0x3b,
1572 (unsigned short) ((temp2 >> 8) &
1573 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001574 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001575 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1576 ~0xc0,
1577 (unsigned short) ((tempbx &
1578 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001579
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001580 tempcx = pVBInfo->VGAVDE;
1581 if (tempcx == pVBInfo->VDE)
1582 xgifb_reg_and_or(pVBInfo->Part4Port,
1583 0x30, ~0x0c, 0x00);
1584 else
1585 xgifb_reg_and_or(pVBInfo->Part4Port,
1586 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301587 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001588
1589 tempcx = pVBInfo->VGAHDE;
1590 tempbx = pVBInfo->HDE;
1591
1592 temp1 = tempcx << 16;
1593
1594 tempax = (unsigned short) (temp1 / tempbx);
1595
1596 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1597 tempax = 65535;
1598
1599 temp3 = tempax;
1600 temp1 = pVBInfo->VGAHDE << 16;
1601
1602 temp1 /= temp3;
1603 temp3 = temp3 << 16;
1604 temp1 -= 1;
1605
1606 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1607
1608 tempax = (unsigned short) (temp3 & 0xff);
1609 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1610
1611 temp1 = pVBInfo->VGAVDE << 18;
1612 temp1 = temp1 / push3;
1613 tempbx = (unsigned short) (temp1 & 0xffff);
1614
Peter Huewe255aabd2012-02-09 21:11:44 +01001615 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001616 tempbx -= 1;
1617
1618 tempax = ((tempbx >> 8) & 0xff) << 3;
1619 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1620 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1621 (unsigned short) (tempax & 0xff));
1622 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1623 (unsigned short) (tempbx & 0xff));
1624
1625 temp3 = temp3 >> 16;
1626
1627 if (modeflag & HalfDCLK)
1628 temp3 = temp3 >> 1;
1629
1630 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1631 (unsigned short) ((temp3 >> 8) & 0xff));
1632 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1633 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001634}
1635
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001636/* --------------------------------------------------------------------- */
1637/* Function : XGI_GETLCDVCLKPtr */
1638/* Input : */
1639/* Output : al -> VCLK Index */
1640/* Description : */
1641/* --------------------------------------------------------------------- */
1642static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1643 struct vb_device_info *pVBInfo)
1644{
1645 unsigned short index;
1646
Peter Huewea3d675c2012-02-09 21:11:47 +01001647 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001648 index = XGI_GetLCDCapPtr1(pVBInfo);
1649
1650 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1651 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1652 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1653 } else { /* LCDA */
1654 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1655 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1656 }
1657 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001658}
1659
1660static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001661 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001662{
1663
1664 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001665 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001666
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001667 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001668 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001669
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001670 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1671 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001672 index = XGI_GetLCDCapPtr(pVBInfo);
1673 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1674
Peter Huewea3d675c2012-02-09 21:11:47 +01001675 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001676 return tempal;
1677
1678 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001679 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001680 (VB_SIS301B |
1681 VB_SIS302B |
1682 VB_SIS301LV |
1683 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001684 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001685 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001686 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001687 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001688 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001689 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001690 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001691 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001692 tempal = TVCLKBASE_315 +
1693 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001694
1695 }
1696 return tempal;
1697 }
1698
Peter Huewe599801f2012-02-09 21:11:45 +01001699 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001700 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001701 return tempal;
1702 }
1703
Peter Huewe599801f2012-02-09 21:11:45 +01001704 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001705 tempal = YPbPr525pVCLK;
1706 return tempal;
1707 }
1708
1709 tempal = NTSC1024VCLK;
1710
1711 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001712 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001713 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001714 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001715 }
1716
1717 if (pVBInfo->VBInfo & SetCRT2ToTV)
1718 return tempal;
1719 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001720 } /* {End of VB} */
1721
Peter Huewe516354e2013-02-15 20:37:11 +01001722 inb((pVBInfo->P3ca + 0x02));
Aaro Koskinena39325d2012-11-04 21:14:53 +02001723 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001724 return tempal;
1725}
1726
1727static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1728 unsigned char *di_1, struct vb_device_info *pVBInfo)
1729{
Peter Huewe6896b942012-02-09 21:11:46 +01001730 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1731 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001732 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1733 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001734 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001735 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001736 }
1737 } else {
1738 *di_0 = XGI_VCLKData[tempal].SR2B;
1739 *di_1 = XGI_VCLKData[tempal].SR2C;
1740 }
1741}
1742
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001743static void XGI_SetCRT2ECLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301744 unsigned short RefreshRateTableIndex,
1745 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001746{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301747 unsigned char di_0, di_1, tempal;
1748 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001749
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001750 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301751 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1752 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001753
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301754 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001755 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301756 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001757 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301758 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001759 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1760 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301761 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001762 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1763 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301764 }
1765 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001766}
1767
Aaro Koskinenb053af12013-07-16 23:13:28 +03001768static void XGI_UpdateModeInfo(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001769{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301770 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001771
Peter Huewe6896b942012-02-09 21:11:46 +01001772 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1773 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301774 tempcl = 0;
1775 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001776 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001777
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301778 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001779 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301780 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001781 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301782 if (!(temp & 0x40))
1783 tempcl |= ActiveCRT1;
1784 }
1785 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001786
Aaro Koskinen58839b02011-03-13 12:26:23 +02001787 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301788 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001789
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301790 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001791 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001792 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301793 if (tempax & 0x04)
1794 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001795
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301796 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301798 if (!(tempcl & ActiveLCD))
1799 if (temp == 0x01)
1800 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301802 if (temp == 0x04)
1803 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001804
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301805 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001806 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001807
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301808 if (!(temp & 0x08))
1809 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001810
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301811 if (!(temp & 0x04))
1812 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301814 if (temp & 0x02)
1815 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001816
Peter Huewe599801f2012-02-09 21:11:45 +01001817 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301818 if (temp & 0x01)
1819 tempch |= ActiveHiTV;
1820 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001821
Peter Huewe599801f2012-02-09 21:11:45 +01001822 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001823 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301824 pVBInfo->Part2Port,
1825 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001826
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301827 if (temp & 0x10)
1828 tempch |= ActiveYPbPr;
1829 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001830
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301831 if (tempch != 0)
1832 tempcl |= ActiveTV;
1833 }
1834 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001835
Aaro Koskinen58839b02011-03-13 12:26:23 +02001836 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301837 if (tempcl & ActiveLCD) {
1838 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1839 if (temp & ActiveTV)
1840 tempcl |= ActiveTV;
1841 }
1842 }
1843 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001844 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001845 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301847 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001848 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301849 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001850}
1851
Bill Pemberton80adad82010-06-17 13:10:51 -04001852void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001853{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301854 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001855
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001856 tempbx = VB_SIS302B;
1857 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1858 if (flag == 0x02)
1859 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001860
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001861 tempbx = VB_SIS301;
1862 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1863 if (flag < 0xB0)
1864 goto finish;
1865
1866 tempbx = VB_SIS301B;
1867 if (flag < 0xC0)
1868 goto bigger_than_0xB0;
1869
1870 tempbx = VB_XGI301C;
1871 if (flag < 0xD0)
1872 goto bigger_than_0xB0;
1873
1874 tempbx = VB_SIS301LV;
1875 if (flag < 0xE0)
1876 goto bigger_than_0xB0;
1877
1878 tempbx = VB_SIS302LV;
1879 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1880 if (tempah != 0xFF)
1881 tempbx = VB_XGI301C;
1882
1883bigger_than_0xB0:
1884 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1885 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1886 if (!(flag & 0x02))
1887 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301888 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001889
1890finish:
1891 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001892}
1893
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001894static void XGI_GetVBInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301895 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001896{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301897 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001898
Aaro Koskinenb3979922012-11-04 21:14:52 +02001899 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301900 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001901 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301902 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001903
Miguel Gómezf9317352012-07-06 12:40:48 +02001904 if (!(pVBInfo->VBType & 0xFFFF))
1905 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001906
Miguel Gómezf9317352012-07-06 12:40:48 +02001907 /* Check Display Device */
1908 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1909 tempbx = tempbx | temp;
1910 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1911 push = temp;
1912 push = push << 8;
1913 tempax = temp << 8;
1914 tempbx = tempbx | tempax;
1915 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1916 | SetInSlaveMode | DisableCRT2Display);
1917 temp = 0xFFFF ^ temp;
1918 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001919
Miguel Gómezf9317352012-07-06 12:40:48 +02001920 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001921
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001922 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1923 VB_XGI301C)) {
1924 if (temp & EnableDualEdge) {
1925 tempbx |= SetCRT2ToDualEdge;
1926 if (temp & SetToLCDA)
1927 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02001928 }
1929 }
1930
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001931 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
1932 if (temp & SetYPbPr) {
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001933 /* shampoo add for new scratch */
1934 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
1935 temp &= YPbPrMode;
1936 tempbx |= SetCRT2ToHiVision;
Miguel Gómezf9317352012-07-06 12:40:48 +02001937
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001938 if (temp != YPbPrMode1080i) {
1939 tempbx &= (~SetCRT2ToHiVision);
1940 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301941 }
1942 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001943 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001944
Miguel Gómezf9317352012-07-06 12:40:48 +02001945 tempax = push; /* restore CR31 */
1946
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001947 temp = 0x09FC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001948
Miguel Gómezf9317352012-07-06 12:40:48 +02001949 if (!(tempbx & temp)) {
1950 tempax |= DisableCRT2Display;
1951 tempbx = 0;
1952 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001953
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001954 if (!(pVBInfo->VBType & VB_NoLCD)) {
1955 if (tempbx & XGI_SetCRT2ToLCDA) {
1956 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001957 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001958 SwitchCRT2));
1959 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001960 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
1961 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02001962 }
1963 }
1964
1965 /* shampoo add */
1966 /* for driver abnormal */
1967 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
Aaro Koskinenee768752013-05-29 23:59:16 +03001968 if (tempbx & SetCRT2ToRAMDAC) {
1969 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
1970 SwitchCRT2 | SetSimuScanMode);
1971 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301972 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001973 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001974
Miguel Gómezf9317352012-07-06 12:40:48 +02001975 if (!(pVBInfo->VBType & VB_NoLCD)) {
1976 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001977 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001978 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01001979 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301980 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001981 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001982
Miguel Gómezf9317352012-07-06 12:40:48 +02001983 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001984 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02001985 SetSimuScanMode);
1986 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
1987 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001988
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001989 if (tempbx & SetCRT2ToYPbPr525750)
1990 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001991
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001992 if (tempbx & SetCRT2ToHiVision)
1993 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
1994 SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001995
Miguel Gómezf9317352012-07-06 12:40:48 +02001996 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
1997 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
1998 tempbx = DisableCRT2Display;
1999 }
2000
2001 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002002 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002003 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002004 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002005 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002006
Miguel Gómezf9317352012-07-06 12:40:48 +02002007 /* LCD+TV can't support in slave mode
2008 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002009 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2010 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002011 SetCRT2ToDualEdge);
2012 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302013 }
2014 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302016 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002017}
2018
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002019static void XGI_GetTVInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302020 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002021{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002022 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302024 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002025 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2026 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002027
Peter Huewe5fc699f2013-02-03 04:08:45 +01002028 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2029 if (tempbx & TVSetPAL) {
2030 tempbx &= (SetCHTVOverScan |
2031 TVSetPALM |
2032 TVSetPALN |
2033 TVSetPAL);
2034 if (tempbx & TVSetPALM)
2035 /* set to NTSC if PAL-M */
2036 tempbx &= ~TVSetPAL;
2037 } else
2038 tempbx &= (SetCHTVOverScan |
2039 TVSetNTSCJ |
2040 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002041
Aaro Koskinena8b35292013-02-09 00:03:45 +02002042 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2043 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002044
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002045 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2046 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2047 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002048
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002049 if (index1 == YPbPrMode525i)
2050 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002051
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002052 if (index1 == YPbPrMode525p)
2053 tempbx = tempbx | TVSetYPbPr525p;
2054 if (index1 == YPbPrMode750p)
2055 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302056 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002057
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03002058 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2059 tempbx = tempbx | TVSetHiVision | TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002060
Aaro Koskinena8b35292013-02-09 00:03:45 +02002061 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2062 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2063 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002064
Aaro Koskinena8b35292013-02-09 00:03:45 +02002065 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2066 /* NTSC 1024x768, */
2067 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002068
Aaro Koskinena8b35292013-02-09 00:03:45 +02002069 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002070
Aaro Koskinena8b35292013-02-09 00:03:45 +02002071 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2072 if (pVBInfo->VBInfo & SetInSlaveMode)
2073 tempbx &= (~RPLLDIV2XO);
2074 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2075 tempbx &= (~RPLLDIV2XO);
2076 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2077 VB_SIS301LV | VB_SIS302LV |
2078 VB_XGI301C))) {
2079 if (tempbx & TVSimuMode)
2080 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302081 }
2082 }
2083 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002084}
2085
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002086static unsigned char XGI_GetLCDInfo(unsigned short ModeIdIndex,
2087 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002088{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002089 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002090
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302091 pVBInfo->LCDResInfo = 0;
2092 pVBInfo->LCDTypeInfo = 0;
2093 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002094
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002095 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002096 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002097 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302098 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302100 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002101 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002102
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002103 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002104 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302105 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002106 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002107 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302108 tempax &= 0x0F;
2109 else
2110 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302112 if ((resinfo == 6) || (resinfo == 9)) {
2113 if (tempax >= 3)
2114 tempbx |= PanelRef75Hz;
2115 } else if ((resinfo == 7) || (resinfo == 8)) {
2116 if (tempax >= 4)
2117 tempbx |= PanelRef75Hz;
2118 }
2119 }
2120 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302122 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302124 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002125
Peter Huewea3d675c2012-02-09 21:11:47 +01002126 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302127 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302129 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002130
Aaro Koskinen58839b02011-03-13 12:26:23 +02002131 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302133 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302135 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302137 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002138
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302139 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002140
Aaro Koskinen718e7152013-02-09 00:03:46 +02002141 if (((pVBInfo->VBType & VB_SIS302LV) ||
2142 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2143 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002144
Aaro Koskinen718e7152013-02-09 00:03:46 +02002145 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2146 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2147 (!(tempbx & EnableScalingLCD)))
2148 /*
2149 * set to center in 1280x1024 LCDB
2150 * for Panel_1400x1050
2151 */
2152 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302154 if (pVBInfo->VBInfo & SetInSlaveMode) {
2155 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002156 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302157 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002158 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302159 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302161 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302163 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002164}
2165
Bill Pemberton108afbf2010-06-17 13:10:47 -04002166unsigned char XGI_SearchModeID(unsigned short ModeNo,
Aaro Koskinen334ab072013-07-16 23:13:30 +03002167 unsigned short *ModeIdIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002168{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002169 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002170 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002171 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002172 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002173 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302174 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002175
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302176 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002177}
2178
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002179static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2180{
2181 unsigned char ujRet = 0;
2182 unsigned char i = 0;
2183
2184 for (i = 0; i < 8; i++) {
2185 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002186 ujRet |= (ujDate >> i) & 1;
2187 }
2188
2189 return ujRet;
2190}
2191
2192/*----------------------------------------------------------------------------*/
2193/* output */
2194/* bl[5] : LVDS signal */
2195/* bl[1] : LVDS backlight */
2196/* bl[0] : LVDS VDD */
2197/*----------------------------------------------------------------------------*/
2198static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2199{
2200 unsigned char CR4A, temp;
2201
Aaro Koskinen58839b02011-03-13 12:26:23 +02002202 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002203 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002204
Aaro Koskinen58839b02011-03-13 12:26:23 +02002205 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002206
2207 temp = XG21GPIODataTransfer(temp);
2208 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002209 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002210 return temp;
2211}
2212
2213/*----------------------------------------------------------------------------*/
2214/* output */
2215/* bl[5] : LVDS signal */
2216/* bl[1] : LVDS backlight */
2217/* bl[0] : LVDS VDD */
2218/*----------------------------------------------------------------------------*/
2219static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2220{
2221 unsigned char CR4A, CRB4, temp;
2222
Aaro Koskinen58839b02011-03-13 12:26:23 +02002223 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002224 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002225
Aaro Koskinen58839b02011-03-13 12:26:23 +02002226 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002227
2228 temp &= 0x0C;
2229 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002230 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002231 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002232 temp |= ((CRB4 & 0x04) << 3);
2233 return temp;
2234}
2235
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002236/*----------------------------------------------------------------------------*/
2237/* input */
2238/* bl[5] : 1;LVDS signal on */
2239/* bl[1] : 1;LVDS backlight on */
2240/* bl[0] : 1:LVDS VDD on */
2241/* bh: 100000b : clear bit 5, to set bit5 */
2242/* 000010b : clear bit 1, to set bit1 */
2243/* 000001b : clear bit 0, to set bit0 */
2244/*----------------------------------------------------------------------------*/
2245static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2246 struct vb_device_info *pVBInfo)
2247{
2248 unsigned char CR4A, temp;
2249
2250 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2251 tempbh &= 0x23;
2252 tempbl &= 0x23;
2253 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2254
2255 if (tempbh & 0x20) {
2256 temp = (tempbl >> 4) & 0x02;
2257
2258 /* CR B4[1] */
2259 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2260
2261 }
2262
2263 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2264
2265 temp = XG21GPIODataTransfer(temp);
2266 temp &= ~tempbh;
2267 temp |= tempbl;
2268 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2269}
2270
Aaro Koskinen776115a2011-11-27 23:03:10 +02002271static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2272 struct vb_device_info *pVBInfo)
2273{
2274 unsigned char CR4A, temp;
2275 unsigned short tempbh0, tempbl0;
2276
2277 tempbh0 = tempbh;
2278 tempbl0 = tempbl;
2279 tempbh0 &= 0x20;
2280 tempbl0 &= 0x20;
2281 tempbh0 >>= 3;
2282 tempbl0 >>= 3;
2283
2284 if (tempbh & 0x20) {
2285 temp = (tempbl >> 4) & 0x02;
2286
2287 /* CR B4[1] */
2288 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2289
2290 }
2291 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2292
2293 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2294 tempbh &= 0x03;
2295 tempbl &= 0x03;
2296 tempbh <<= 2;
2297 tempbl <<= 2; /* GPIOC,GPIOD */
2298 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2299 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2300}
2301
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002302static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2303 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302304 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002305{
2306
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002307 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302308 if (pXGIHWDE->jChipType == XG21) {
2309 if (pVBInfo->IF_DEF_LVDS == 1) {
2310 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002311 /* LVDS VDD on */
2312 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002313 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302314 }
2315 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002316 /* LVDS signal on */
2317 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002318 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002319 /* LVDS backlight on */
2320 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302321 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002322 /* DVO/DVI signal on */
2323 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302324 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002325
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302326 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002327
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302328 if (pXGIHWDE->jChipType == XG27) {
2329 if (pVBInfo->IF_DEF_LVDS == 1) {
2330 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002331 /* LVDS VDD on */
2332 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002333 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302334 }
2335 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002336 /* LVDS signal on */
2337 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002338 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002339 /* LVDS backlight on */
2340 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302341 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002342 /* DVO/DVI signal on */
2343 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302344 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302346 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002347}
2348
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002349void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2350 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302351 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002352{
2353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302354 if (pXGIHWDE->jChipType == XG21) {
2355 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002356 /* LVDS backlight off */
2357 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002358 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302359 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002360 /* DVO/DVI signal off */
2361 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302362 }
2363 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002364
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302365 if (pXGIHWDE->jChipType == XG27) {
2366 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002367 /* LVDS backlight off */
2368 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002369 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302370 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002371
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302372 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002373 /* DVO/DVI signal off */
2374 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302375 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002376
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002377 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002378}
2379
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002380static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002381{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002382 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302383 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002384
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002385 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302386 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002387}
2388
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002389static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002390{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002391 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002392}
2393
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002394static void XGI_SaveCRT2Info(unsigned short ModeNo,
2395 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002396{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302397 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002398
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002399 /* reserve CR34 for CRT1 Mode No */
2400 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302401 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2402 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002403 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002404}
2405
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002406static void XGI_GetCRT2ResInfo(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002407 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002408{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302409 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002410
Aaro Koskinenb3979922012-11-04 21:14:52 +02002411 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002412 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2413 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002414 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002415 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002416
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002417 if (modeflag & HalfDCLK)
2418 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002419
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002420 if (modeflag & DoubleScanMode)
2421 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002422
Miguel Gómez3339db82012-07-06 12:40:49 +02002423 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2424 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002425
Aaro Koskinen22006832013-02-09 00:03:47 +02002426 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2427 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2428 if (yres == 1024)
2429 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302430 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002431 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002432
Aaro Koskinen22006832013-02-09 00:03:47 +02002433 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2434 if (yres == 400)
2435 yres = 405;
2436 else if (yres == 350)
2437 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002438
Aaro Koskinen22006832013-02-09 00:03:47 +02002439 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2440 if (yres == 360)
2441 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002442 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002443 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002444
Aaro Koskinen22006832013-02-09 00:03:47 +02002445 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2446 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2447 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2448 if (yres == 350)
2449 yres = 357;
2450 else if (yres == 400)
2451 yres = 420;
2452 else if (yres == 480)
2453 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002454 }
2455 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302456 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002457
Miguel Gómez3339db82012-07-06 12:40:49 +02002458 if (xres == 720)
2459 xres = 640;
2460
2461exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302462 pVBInfo->VGAHDE = xres;
2463 pVBInfo->HDE = xres;
2464 pVBInfo->VGAVDE = yres;
2465 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002466}
2467
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002468static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002469{
2470
Peter Huewea3d675c2012-02-09 21:11:47 +01002471 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002472 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302473 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002474
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302475 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002476}
2477
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002478static void XGI_GetRAMDAC2DATA(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002479 unsigned short RefreshRateTableIndex,
2480 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002481{
2482 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002483 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002484
2485 pVBInfo->RVBHCMAX = 1;
2486 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002487 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002488 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002489 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002490 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2491 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002492 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002493 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002494 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002495 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002496 tempcx &= 0x0100;
2497 tempcx = tempcx << 2;
2498 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002499 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002500
2501 if (temp1 & 0x01)
2502 tempbx |= 0x0100;
2503
2504 if (temp1 & 0x20)
2505 tempbx |= 0x0200;
2506 tempax += 5;
2507
2508 if (modeflag & Charx8Dot)
2509 tempax *= 8;
2510 else
2511 tempax *= 9;
2512
2513 pVBInfo->VGAHT = tempax;
2514 pVBInfo->HT = tempax;
2515 tempbx++;
2516 pVBInfo->VGAVT = tempbx;
2517 pVBInfo->VT = tempbx;
2518}
2519
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002520static void XGI_GetCRT2Data(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302521 unsigned short RefreshRateTableIndex,
2522 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002523{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002524 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002525
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002526 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002527
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002528 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002529 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2530 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302531 pVBInfo->NewFlickerMode = 0;
2532 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002533
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302534 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002535 XGI_GetRAMDAC2DATA(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302536 return;
2537 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002538
Peter Huewea3d675c2012-02-09 21:11:47 +01002539 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002540 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03002541 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002542
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302543 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2544 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2545 pVBInfo->VGAHT = LCDPtr->VGAHT;
2546 pVBInfo->VGAVT = LCDPtr->VGAVT;
2547 pVBInfo->HT = LCDPtr->LCDHT;
2548 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002549
Peter Huewe255aabd2012-02-09 21:11:44 +01002550 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302551 tempax = 1024;
2552 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002553
Peter Huewea3d675c2012-02-09 21:11:47 +01002554 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302555 if (pVBInfo->VGAVDE == 357)
2556 tempbx = 527;
2557 else if (pVBInfo->VGAVDE == 420)
2558 tempbx = 620;
2559 else if (pVBInfo->VGAVDE == 525)
2560 tempbx = 775;
2561 else if (pVBInfo->VGAVDE == 600)
2562 tempbx = 775;
Peter Huewe7580d7f2013-05-18 00:19:54 +02002563 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002564 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302565 tempax = 1024;
2566 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002567 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302568 tempax = 1280;
2569 if (pVBInfo->VGAVDE == 360)
2570 tempbx = 768;
2571 else if (pVBInfo->VGAVDE == 375)
2572 tempbx = 800;
2573 else if (pVBInfo->VGAVDE == 405)
2574 tempbx = 864;
2575 else
2576 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002577 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302578 tempax = 1280;
2579 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002580 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302581 tempax = 1280;
2582 if (pVBInfo->VGAVDE == 350)
2583 tempbx = 700;
2584 else if (pVBInfo->VGAVDE == 400)
2585 tempbx = 800;
2586 else if (pVBInfo->VGAVDE == 1024)
2587 tempbx = 960;
2588 else
2589 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002590 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302591 tempax = 1400;
2592 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002593
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302594 if (pVBInfo->VGAVDE == 1024) {
2595 tempax = 1280;
2596 tempbx = 1024;
2597 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002598 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302599 tempax = 1600;
2600 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002601 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302602 if (pVBInfo->VGAVDE == 350)
2603 tempbx = 875;
2604 else if (pVBInfo->VGAVDE == 400)
2605 tempbx = 1000;
2606 }
2607 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002608
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302609 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2610 tempax = pVBInfo->VGAHDE;
2611 tempbx = pVBInfo->VGAVDE;
2612 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002613
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302614 pVBInfo->HDE = tempax;
2615 pVBInfo->VDE = tempbx;
2616 return;
2617 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302619 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002620 struct SiS_TVData const *TVPtr;
2621
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002622 TVPtr = XGI_GetTVPtr(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinen24572542012-09-11 00:15:21 +03002623 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302625 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2626 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2627 pVBInfo->VGAHT = TVPtr->VGAHT;
2628 pVBInfo->VGAVT = TVPtr->VGAVT;
2629 pVBInfo->HDE = TVPtr->TVHDE;
2630 pVBInfo->VDE = TVPtr->TVVDE;
2631 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2632 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
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 (resinfo == 0x08)
2636 pVBInfo->NewFlickerMode = 0x40;
2637 else if (resinfo == 0x09)
2638 pVBInfo->NewFlickerMode = 0x40;
2639 else if (resinfo == 0x12)
2640 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002641
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302642 if (pVBInfo->VGAVDE == 350)
2643 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002644
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302645 tempax = ExtHiTVHT;
2646 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302648 if (pVBInfo->VBInfo & SetInSlaveMode) {
2649 if (pVBInfo->TVInfo & TVSimuMode) {
2650 tempax = StHiTVHT;
2651 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002652
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302653 if (!(modeflag & Charx8Dot)) {
2654 tempax = StHiTextTVHT;
2655 tempbx = StHiTextTVVT;
2656 }
2657 }
2658 }
Peter Huewe599801f2012-02-09 21:11:45 +01002659 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2660 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302661 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2662 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2663 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002664
Peter Huewe599801f2012-02-09 21:11:45 +01002665 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302666 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2667 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002668 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302669 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2670 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2671 if (pVBInfo->TVInfo & NTSC1024x768)
2672 tempax = NTSC1024x768HT;
2673 }
2674 } else {
2675 tempax = PALHT;
2676 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002677 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302678 tempax = NTSCHT;
2679 tempbx = NTSCVT;
2680 if (pVBInfo->TVInfo & NTSC1024x768)
2681 tempax = NTSC1024x768HT;
2682 }
2683 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002684
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302685 pVBInfo->HT = tempax;
2686 pVBInfo->VT = tempbx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302687 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002688}
2689
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002690static void XGI_SetCRT2VCLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302691 unsigned short RefreshRateTableIndex,
2692 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002693{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002694 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002695
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002696 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302697 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2698 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002699
Peter Huewe6896b942012-02-09 21:11:46 +01002700 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302701 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002702 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2703 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2704 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302705 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002706 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2707 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302708 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002709
Aaro Koskinen8104e322011-03-13 12:26:22 +02002710 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302712 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002713 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302714 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002715 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002716}
2717
Aaro Koskinen334ab072013-07-16 23:13:30 +03002718static unsigned short XGI_GetColorDepth(unsigned short ModeIdIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002719{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002720 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2721 short index;
2722 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302723
Aaro Koskinenb3979922012-11-04 21:14:52 +02002724 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002725 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302726
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002727 if (index < 0)
2728 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302729
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002730 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302731}
2732
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002733static unsigned short XGI_GetOffset(unsigned short ModeNo,
2734 unsigned short ModeIdIndex,
Aaro Koskinen334ab072013-07-16 23:13:30 +03002735 unsigned short RefreshRateTableIndex)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302736{
2737 unsigned short temp, colordepth, modeinfo, index, infoflag,
2738 ColorDepth[] = { 0x01, 0x02, 0x04 };
2739
Aaro Koskinenb3979922012-11-04 21:14:52 +02002740 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002741 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302742
2743 index = (modeinfo >> 8) & 0xFF;
2744
Aaro Koskinen224114c2012-11-04 21:14:59 +02002745 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302746
2747 if (infoflag & InterlaceMode)
2748 temp = temp << 1;
2749
Aaro Koskinen334ab072013-07-16 23:13:30 +03002750 colordepth = XGI_GetColorDepth(ModeIdIndex);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302751
2752 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2753 temp = ModeNo - 0x7C;
2754 colordepth = ColorDepth[temp];
2755 temp = 0x6B;
2756 if (infoflag & InterlaceMode)
2757 temp = temp << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302758 }
Peter Huewe053004b2013-02-15 20:37:12 +01002759 return temp * colordepth;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302760}
2761
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002762static void XGI_SetCRT2Offset(unsigned short ModeNo,
2763 unsigned short ModeIdIndex,
2764 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002765 struct vb_device_info *pVBInfo)
2766{
2767 unsigned short offset;
2768 unsigned char temp;
2769
2770 if (pVBInfo->VBInfo & SetInSlaveMode)
2771 return;
2772
Aaro Koskinen334ab072013-07-16 23:13:30 +03002773 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002774 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002775 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002776 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002777 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002778 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002779 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002780}
2781
Randy Dunlap89229672010-08-10 08:46:44 -07002782static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002783{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002784 /* threshold high ,disable auto threshold */
2785 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2786 /* threshold low default 04h */
2787 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002788}
2789
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002790static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302791 unsigned short RefreshRateTableIndex,
2792 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002793{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002794 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002795
Aaro Koskinenb053af12013-07-16 23:13:28 +03002796 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302797 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002798
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302799 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002800 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002801
Aaro Koskinen8104e322011-03-13 12:26:22 +02002802 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2803 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002804}
2805
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002806static void XGI_SetGroup1(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302807 unsigned short RefreshRateTableIndex,
2808 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002809{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302810 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002811 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002812
Aaro Koskinena39325d2012-11-04 21:14:53 +02002813 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002814 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002815 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302817 /* bainy change table name */
2818 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002819 /* BTVGA2HT 0x08,0x09 */
2820 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002821 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302822 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002823 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002824 /* BTVGA2HDEE 0x0A,0x0C */
2825 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002826 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302827 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2828 pushbx = pVBInfo->VGAHDE / 2 + 16;
2829 tempcx = tempcx >> 1;
2830 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2831 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302833 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002834 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2835 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002836 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302837 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002838 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302839 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002840 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302841 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2842 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2843 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002844
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302845 tempbx += 4;
2846 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302848 if (tempcx > (pVBInfo->VGAHT / 2))
2849 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002850
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302851 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002852
Aaro Koskinen8104e322011-03-13 12:26:22 +02002853 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302854 } else {
2855 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002856 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302857 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002858 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002859 /* BTVGA2HDEE 0x0A,0x0C */
2860 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002861 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302862 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2863 pushbx = pVBInfo->VGAHDE + 16;
2864 tempcx = tempcx >> 1;
2865 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2866 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002867
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302868 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002869 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2870 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002871 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302872 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002873 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302874 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002875 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302876 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2877 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2878 tempbx += 16;
2879 tempcx += 16;
2880 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302882 if (tempcx > pVBInfo->VGAHT)
2883 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302885 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002886 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302887 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002888
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302889 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2890 tempbx = pushbx;
2891 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2892 tempax |= (tempbx & 0xFF00);
2893 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002894 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302895 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002896 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302897 tempcx = (pVBInfo->VGAVT - 1);
2898 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002899
Aaro Koskinen8104e322011-03-13 12:26:22 +02002900 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302901 tempbx = pVBInfo->VGAVDE - 1;
2902 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002903 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302904 temp = ((tempbx & 0xFF00) << 3) >> 8;
2905 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002906 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002907
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002908 /* BTVGA2VRS 0x10,0x11 */
2909 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
2910 /* BTVGA2VRE 0x11 */
2911 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002912
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302913 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002914 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
2915 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002916
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302917 if (temp & 0x04)
2918 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002919
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302920 if (temp & 0x080)
2921 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002922
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002923 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002924
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302925 if (temp & 0x08)
2926 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002927
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002928 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302929 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
2930 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002931
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302932 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002933 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302934 temp = ((tempbx & 0xFF00) >> 8) << 4;
2935 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02002936 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302937 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302939 if (modeflag & DoubleScanMode)
2940 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002941
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302942 if (modeflag & HalfDCLK)
2943 tempax |= 0x40;
2944
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002945 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002946}
2947
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002948static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
2949{
2950 unsigned long tempax, tempbx;
2951
2952 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
2953 & 0xFFFF;
2954 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
2955 tempax = (tempax * pVBInfo->HT) / tempbx;
2956
2957 return (unsigned short) tempax;
2958}
2959
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002960static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302961 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002962{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302963 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002964 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002965
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002966 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002967 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2968 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002969
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302970 if (!(pVBInfo->VBInfo & SetInSlaveMode))
2971 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302973 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002974 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302975 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002976
Peter Huewe6896b942012-02-09 21:11:46 +01002977 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302978 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002979
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302980 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002981
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302982 if (modeflag & HalfDCLK)
2983 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002984
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302985 tempax = (tempax / tempcx) - 1;
2986 tempbx |= ((tempax & 0x00FF) << 8);
2987 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002988 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002989
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302990 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002991
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302992 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01002993 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
2994 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302995 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002996
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002997 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
2998 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302999 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303000 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003001
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003002 /* 0x05 Horizontal Display Start */
3003 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3004 /* 0x06 Horizontal Blank end */
3005 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003006
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303007 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3008 if (pVBInfo->VBInfo & SetCRT2ToTV)
3009 tempax = pVBInfo->VGAHT;
3010 else
3011 tempax = XGI_GetVGAHT2(pVBInfo);
3012 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003013
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303014 if (tempax >= pVBInfo->VGAHT)
3015 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303017 if (modeflag & HalfDCLK)
3018 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003019
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303020 tempax = (tempax / tempcx) - 5;
3021 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003022 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303023 temp = (tempbx & 0x00FF) - 1;
3024 if (!(modeflag & HalfDCLK)) {
3025 temp -= 6;
3026 if (pVBInfo->TVInfo & TVSimuMode) {
3027 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003028 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303029 }
3030 }
3031 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303032 tempbx = (tempbx & 0xFF00) >> 8;
3033 tempcx = (tempcx + tempbx) >> 1;
3034 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303036 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3037 temp -= 1;
3038 if (!(modeflag & HalfDCLK)) {
3039 if ((modeflag & Charx8Dot)) {
3040 temp += 4;
3041 if (pVBInfo->VGAHDE >= 800)
3042 temp -= 6;
3043 }
3044 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003045 } else if (!(modeflag & HalfDCLK)) {
3046 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003047 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003048 pVBInfo->VGAHDE >= 800) {
3049 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003050 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003051 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003052 (pVBInfo->LCDInfo & LCDNonExpanding))
3053 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303054 }
3055 }
3056 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003057
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003058 /* 0x07 Horizontal Retrace Start */
3059 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3060 /* 0x08 Horizontal Retrace End */
3061 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003062
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303063 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3064 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003065 if (ModeNo == 0x50) {
Peter Huewe85b38472013-05-13 23:41:49 +02003066 if (pVBInfo->TVInfo == SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003067 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303068 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003069 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303070 0x08, 0x03);
3071 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003072 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303073 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003074 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303075 0x08, 0x02);
3076 }
3077 }
3078 }
3079 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003080
Aaro Koskinen8104e322011-03-13 12:26:22 +02003081 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003082 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003083 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003084
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303085 tempbx = pVBInfo->VGAVT;
3086 push1 = tempbx;
3087 tempcx = 0x121;
3088 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303090 if (tempbx == 357)
3091 tempbx = 350;
3092 if (tempbx == 360)
3093 tempbx = 350;
3094 if (tempbx == 375)
3095 tempbx = 350;
3096 if (tempbx == 405)
3097 tempbx = 400;
3098 if (tempbx == 525)
3099 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303101 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003102
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303103 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003104 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003105 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303106 if (tempbx == 350)
3107 tempbx += 5;
3108 if (tempbx == 480)
3109 tempbx += 5;
3110 }
3111 }
3112 }
3113 tempbx--;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303114 tempbx--;
3115 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003116 /* 0x10 vertical Blank Start */
3117 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303118 tempbx = push2;
3119 tempbx--;
3120 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003121 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303123 if (tempbx & 0x0100)
3124 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303126 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303128 if (modeflag & DoubleScanMode)
3129 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003130
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303131 if (tempbx & 0x0200)
3132 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003133
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303134 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003135 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303137 if (tempbx & 0x0400)
3138 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003139
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003140 /* 0x11 Vertival Blank End */
3141 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303142
3143 tempax = push1;
3144 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3145 tempax = tempax >> 2;
3146 push1 = tempax; /* push ax */
3147
3148 if (resinfo != 0x09) {
3149 tempax = tempax << 1;
3150 tempbx += tempax;
3151 }
3152
Peter Huewe599801f2012-02-09 21:11:45 +01003153 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003154 if ((pVBInfo->VBType & VB_SIS301LV) &&
3155 !(pVBInfo->TVInfo & TVSetHiVision)) {
3156 if ((pVBInfo->TVInfo & TVSimuMode) &&
3157 (pVBInfo->TVInfo & TVSetPAL)) {
3158 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3159 !(pVBInfo->TVInfo &
3160 (TVSetYPbPr525p |
3161 TVSetYPbPr750p |
3162 TVSetHiVision)))
3163 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303164 }
3165 } else {
3166 tempbx -= 10;
3167 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003168 } else if (pVBInfo->TVInfo & TVSimuMode) {
3169 if (pVBInfo->TVInfo & TVSetPAL) {
3170 if (pVBInfo->VBType & VB_SIS301LV) {
3171 if (!(pVBInfo->TVInfo &
3172 (TVSetYPbPr525p |
3173 TVSetYPbPr750p |
3174 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303175 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003176 } else {
3177 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303178 }
3179 }
3180 }
3181 tempax = push1;
3182 tempax = tempax >> 2;
3183 tempax++;
3184 tempax += tempbx;
3185 push1 = tempax; /* push ax */
3186
Peter Huewe599801f2012-02-09 21:11:45 +01003187 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303188 if (tempbx <= 513) {
3189 if (tempax >= 513)
3190 tempbx = 513;
3191 }
3192 }
3193
3194 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003195 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303196 tempbx--;
3197 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003198 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303199
3200 if (tempbx & 0x0100)
3201 tempcx |= 0x0008;
3202
3203 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003204 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303205
3206 tempbx++;
3207
3208 if (tempbx & 0x0100)
3209 tempcx |= 0x0004;
3210
3211 if (tempbx & 0x0200)
3212 tempcx |= 0x0080;
3213
3214 if (tempbx & 0x0400)
3215 tempcx |= 0x0C00;
3216
3217 tempbx = push1; /* pop ax */
3218 temp = tempbx & 0x00FF;
3219 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003220 /* 0x0D vertical Retrace End */
3221 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303222
3223 if (tempbx & 0x0010)
3224 tempcx |= 0x2000;
3225
3226 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003227 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303228 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003229 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303230 tempax = modeflag;
3231 temp = (tempax & 0xFF00) >> 8;
3232
3233 temp = (temp >> 1) & 0x09;
3234
Peter Huewe6896b942012-02-09 21:11:46 +01003235 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303236 temp |= 0x01;
3237
Aaro Koskinen8104e322011-03-13 12:26:22 +02003238 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3239 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3240 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303241
3242 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3243 temp = 0x80;
3244 else
3245 temp = 0x00;
3246
Aaro Koskinen8104e322011-03-13 12:26:22 +02003247 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003248}
3249
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003250static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303251 struct vb_device_info *pVBInfo)
3252{
3253 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003254 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003255 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303256
3257 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3258
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003259 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003260 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303261
3262 tempax = 0;
3263
3264 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3265 tempax |= 0x0800;
3266
3267 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3268 tempax |= 0x0400;
3269
3270 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3271 tempax |= 0x0200;
3272
Peter Huewe599801f2012-02-09 21:11:45 +01003273 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303274 tempax |= 0x1000;
3275
Peter Huewe599801f2012-02-09 21:11:45 +01003276 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303277 tempax |= 0x0100;
3278
Peter Huewe599801f2012-02-09 21:11:45 +01003279 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303280 tempax &= 0xfe00;
3281
3282 tempax = (tempax & 0xff00) >> 8;
3283
Aaro Koskinen8104e322011-03-13 12:26:22 +02003284 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003285 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303286
Peter Huewe599801f2012-02-09 21:11:45 +01003287 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003288 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303289
Peter Huewe599801f2012-02-09 21:11:45 +01003290 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003291 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303292
3293 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003294 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303295
3296 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003297 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303298
3299 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003300 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303301 }
3302
Peter Huewe599801f2012-02-09 21:11:45 +01003303 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3304 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003305 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303306
Peter Huewe599801f2012-02-09 21:11:45 +01003307 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003308 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303309
Peter Huewe599801f2012-02-09 21:11:45 +01003310 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003311 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303312 }
3313
3314 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003315 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303316
3317 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003318 /* di->temp2[j] */
3319 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303320
3321 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003322 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303323
3324 temp = pVBInfo->NewFlickerMode;
3325 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003326 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303327
Peter Huewe599801f2012-02-09 21:11:45 +01003328 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303329 tempax = 520;
3330 else
3331 tempax = 440;
3332
3333 if (pVBInfo->VDE <= tempax) {
3334 tempax -= pVBInfo->VDE;
3335 tempax = tempax >> 2;
3336 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3337 push1 = tempax;
3338 temp = (tempax & 0xFF00) >> 8;
3339 temp += (unsigned short) TimingPoint[0];
3340
Peter Huewe6896b942012-02-09 21:11:46 +01003341 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3342 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303343 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3344 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003345 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303346 tempcx = pVBInfo->VGAHDE;
3347 if (tempcx >= 1024) {
3348 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003349 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303350 temp = 0x19; /* PAL */
3351 }
3352 }
3353 }
3354
Aaro Koskinen8104e322011-03-13 12:26:22 +02003355 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303356 tempax = push1;
3357 temp = (tempax & 0xFF00) >> 8;
3358 temp += TimingPoint[1];
3359
Peter Huewe6896b942012-02-09 21:11:46 +01003360 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3361 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303362 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3363 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003364 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303365 tempcx = pVBInfo->VGAHDE;
3366 if (tempcx >= 1024) {
3367 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003368 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303369 temp = 0x52; /* PAL */
3370 }
3371 }
3372 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003373 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303374 }
3375
3376 /* 301b */
3377 tempcx = pVBInfo->HT;
3378
3379 if (XGI_IsLCDDualLink(pVBInfo))
3380 tempcx = tempcx >> 1;
3381
3382 tempcx -= 2;
3383 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003384 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303385
3386 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003387 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303388
3389 tempcx = pVBInfo->HT >> 1;
3390 push1 = tempcx; /* push cx */
3391 tempcx += 7;
3392
Peter Huewe599801f2012-02-09 21:11:45 +01003393 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303394 tempcx -= 4;
3395
3396 temp = tempcx & 0x00FF;
3397 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003398 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303399
3400 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3401 tempbx += tempcx;
3402 push2 = tempbx;
3403 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003404 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303405 temp = (tempbx & 0xFF00) >> 8;
3406 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003407 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303408
3409 tempbx = push2;
3410 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003411 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303412 tempbx = tempbx - 4;
3413 tempcx = tempbx;
3414 }
3415
3416 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003417 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303418
3419 j += 2;
3420 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3421 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003422 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303423 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003424 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303425
3426 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003427 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303428 tempcx -= 4;
3429
3430 temp = tempcx & 0xFF;
3431 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003432 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303433
3434 tempcx = push1; /* pop cx */
3435 j += 2;
3436 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3437 tempcx -= temp;
3438 temp = tempcx & 0x00FF;
3439 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003440 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303441
3442 tempcx -= 11;
3443
3444 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3445 tempax = XGI_GetVGAHT2(pVBInfo);
3446 tempcx = tempax - 1;
3447 }
3448 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003449 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303450
3451 tempbx = pVBInfo->VDE;
3452
3453 if (pVBInfo->VGAVDE == 360)
3454 tempbx = 746;
3455 if (pVBInfo->VGAVDE == 375)
3456 tempbx = 746;
3457 if (pVBInfo->VGAVDE == 405)
3458 tempbx = 853;
3459
3460 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003461 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003462 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003463 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003464 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303465 tempbx = tempbx >> 1;
3466 } else
3467 tempbx = tempbx >> 1;
3468 }
3469
3470 tempbx -= 2;
3471 temp = tempbx & 0x00FF;
3472
Peter Huewe599801f2012-02-09 21:11:45 +01003473 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003474 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003475 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303476 if (pVBInfo->VBInfo & SetInSlaveMode) {
3477 if (ModeNo == 0x2f)
3478 temp += 1;
3479 }
3480 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003481 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3482 if (ModeNo == 0x2f)
3483 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303484 }
3485 }
3486
Aaro Koskinen8104e322011-03-13 12:26:22 +02003487 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303488
3489 temp = (tempcx & 0xFF00) >> 8;
3490 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3491
Peter Huewe599801f2012-02-09 21:11:45 +01003492 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003493 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003494 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495 temp |= 0x10;
3496
3497 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3498 temp |= 0x20;
3499 }
3500 } else {
3501 temp |= 0x10;
3502 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3503 temp |= 0x20;
3504 }
3505 }
3506
Aaro Koskinen8104e322011-03-13 12:26:22 +02003507 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303508
Peter Huewe6896b942012-02-09 21:11:46 +01003509 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3510 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303511 tempbx = pVBInfo->VDE;
3512 tempcx = tempbx - 2;
3513
3514 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003515 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3516 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303517 tempbx = tempbx >> 1;
3518 }
3519
Peter Huewe6896b942012-02-09 21:11:46 +01003520 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303521 temp = 0;
3522 if (tempcx & 0x0400)
3523 temp |= 0x20;
3524
3525 if (tempbx & 0x0400)
3526 temp |= 0x40;
3527
Aaro Koskinen8104e322011-03-13 12:26:22 +02003528 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303529 }
3530
3531 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003532 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303533 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003534 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303535 }
3536
3537 tempbx = tempbx & 0x00FF;
3538
3539 if (!(modeflag & HalfDCLK)) {
3540 tempcx = pVBInfo->VGAHDE;
3541 if (tempcx >= pVBInfo->HDE) {
3542 tempbx |= 0x2000;
3543 tempax &= 0x00FF;
3544 }
3545 }
3546
3547 tempcx = 0x0101;
3548
3549 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3550 if (pVBInfo->VGAHDE >= 1024) {
3551 tempcx = 0x1920;
3552 if (pVBInfo->VGAHDE >= 1280) {
3553 tempcx = 0x1420;
3554 tempbx = tempbx & 0xDFFF;
3555 }
3556 }
3557 }
3558
3559 if (!(tempbx & 0x2000)) {
3560 if (modeflag & HalfDCLK)
3561 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3562
3563 push1 = tempbx;
3564 tempeax = pVBInfo->VGAHDE;
3565 tempebx = (tempcx & 0xFF00) >> 8;
3566 longtemp = tempeax * tempebx;
3567 tempecx = tempcx & 0x00FF;
3568 longtemp = longtemp / tempecx;
3569
3570 /* 301b */
3571 tempecx = 8 * 1024;
3572
Peter Huewe6896b942012-02-09 21:11:46 +01003573 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3574 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303575 tempecx = tempecx * 8;
3576 }
3577
3578 longtemp = longtemp * tempecx;
3579 tempecx = pVBInfo->HDE;
3580 temp2 = longtemp % tempecx;
3581 tempeax = longtemp / tempecx;
3582 if (temp2 != 0)
3583 tempeax += 1;
3584
3585 tempax = (unsigned short) tempeax;
3586
3587 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003588 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3589 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303590 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3591 }
3592 /* end 301b */
3593
3594 tempbx = push1;
3595 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3596 | (tempbx & 0x00FF));
3597 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3598 | (tempax & 0x00FF));
3599 temp = (tempax & 0xFF00) >> 8;
3600 } else {
3601 temp = (tempax & 0x00FF) >> 8;
3602 }
3603
Aaro Koskinen8104e322011-03-13 12:26:22 +02003604 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303605 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003606 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303607 temp = tempcx & 0x00FF;
3608
3609 if (tempbx & 0x2000)
3610 temp = 0;
3611
3612 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3613 temp |= 0x18;
3614
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003615 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003616 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303617 tempbx = 0x0382;
3618 tempcx = 0x007e;
3619 } else {
3620 tempbx = 0x0369;
3621 tempcx = 0x0061;
3622 }
3623
3624 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003625 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303626 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003627 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303628
3629 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3630 temp = temp << 2;
3631 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3632
Peter Huewe599801f2012-02-09 21:11:45 +01003633 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303634 temp |= 0x10;
3635
Peter Huewe599801f2012-02-09 21:11:45 +01003636 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303637 temp |= 0x20;
3638
Peter Huewe599801f2012-02-09 21:11:45 +01003639 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303640 temp |= 0x60;
3641 }
3642
Aaro Koskinen8104e322011-03-13 12:26:22 +02003643 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003644 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003645 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303646
Peter Huewe599801f2012-02-09 21:11:45 +01003647 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303648 if (pVBInfo->TVInfo & NTSC1024x768) {
3649 TimingPoint = XGI_NTSC1024AdjTime;
3650 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003651 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303652 TimingPoint[j]);
3653 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003654 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303655 }
3656 }
3657
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003658 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303659 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003660 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003661 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303662 0x08); /* PALM Mode */
3663 }
3664
Peter Huewe599801f2012-02-09 21:11:45 +01003665 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003666 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303667 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003668 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303669
Aaro Koskinendc505562011-03-13 12:26:26 +02003670 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303671 }
3672
Peter Huewe599801f2012-02-09 21:11:45 +01003673 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303674 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003675 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303676 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303677}
3678
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003679static void XGI_SetLCDRegs(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303680 struct vb_device_info *pVBInfo)
3681{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003682 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3683 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303684
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003685 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303686
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003687 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303688 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3689 return;
3690
3691 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3692
3693 if (XGI_IsLCDDualLink(pVBInfo))
3694 tempbx = tempbx >> 1;
3695
3696 tempbx -= 1;
3697 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003698 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303699 temp = (tempbx & 0xFF00) >> 8;
3700 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003701 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303702 temp = 0x01;
3703
Aaro Koskinen8104e322011-03-13 12:26:22 +02003704 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303705 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303706 tempbx--;
3707 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003708 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303709 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003710 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303711
3712 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303713 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003714 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303715 temp = (tempcx & 0xFF00) >> 8;
3716 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003717 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003718 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3719 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3720 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3721 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303722
Justin P. Mattock558f7582012-10-02 21:17:11 -07003723 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003724 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003725 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03003726 pVBInfo);
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003727 else
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003728 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03003729 pVBInfo);
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003730
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303731 tempah = pVBInfo->LCDResInfo;
3732 tempah &= PanelResInfo;
3733
Peter Huewe255aabd2012-02-09 21:11:44 +01003734 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303735 tempbx = 1024;
3736 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003737 } else if ((tempah == Panel_1280x1024) ||
3738 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303739 tempbx = 1280;
3740 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003741 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303742 tempbx = 1400;
3743 tempcx = 1050;
3744 } else {
3745 tempbx = 1600;
3746 tempcx = 1200;
3747 }
3748
3749 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3750 tempbx = pVBInfo->HDE;
3751 tempcx = pVBInfo->VDE;
3752 }
3753
3754 pushbx = tempbx;
3755 tempax = pVBInfo->VT;
3756 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3757 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3758 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3759 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3760 tempbx = pVBInfo->LCDVDES;
3761 tempcx += tempbx;
3762
3763 if (tempcx >= tempax)
3764 tempcx -= tempax; /* lcdvdes */
3765
3766 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003767 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303768 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003769 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303770 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3771 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3772 tempah = tempch;
3773 tempah = tempah << 3;
3774 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003775 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303776
3777 /* getlcdsync() */
3778 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3779 tempcx = tempbx;
3780 tempax = pVBInfo->VT;
3781 tempbx = pVBInfo->LCDVRS;
3782
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303783 tempcx += tempbx;
3784 if (tempcx >= tempax)
3785 tempcx -= tempax;
3786
3787 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003788 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303789 temp = (tempbx & 0xFF00) >> 8;
3790 temp = temp << 4;
3791 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003792 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303793 tempcx = pushbx;
3794 tempax = pVBInfo->HT;
3795 tempbx = pVBInfo->LCDHDES;
3796 tempbx &= 0x0FFF;
3797
3798 if (XGI_IsLCDDualLink(pVBInfo)) {
3799 tempax = tempax >> 1;
3800 tempbx = tempbx >> 1;
3801 tempcx = tempcx >> 1;
3802 }
3803
Peter Huewe6896b942012-02-09 21:11:46 +01003804 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303805 tempbx += 1;
3806
3807 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3808 tempbx += 1;
3809
3810 tempcx += tempbx;
3811
3812 if (tempcx >= tempax)
3813 tempcx -= tempax;
3814
3815 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003816 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303817 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003818 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303819 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003820 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303821 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003822 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303823
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303824 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3825 tempcx = tempax;
3826 tempax = pVBInfo->HT;
3827 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303828 if (XGI_IsLCDDualLink(pVBInfo)) {
3829 tempax = tempax >> 1;
3830 tempbx = tempbx >> 1;
3831 tempcx = tempcx >> 1;
3832 }
3833
Peter Huewe6896b942012-02-09 21:11:46 +01003834 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303835 tempbx += 1;
3836
3837 tempcx += tempbx;
3838
3839 if (tempcx >= tempax)
3840 tempcx -= tempax;
3841
3842 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003843 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303844
3845 temp = (tempbx & 0xFF00) >> 8;
3846 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003847 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303848 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003849 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303850
Peter Huewea3d675c2012-02-09 21:11:47 +01003851 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303852 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003853 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3854 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303855 | VB_XGI301C)) {
3856 temp = 0xC6;
3857 } else
3858 temp = 0xC4;
3859
Aaro Koskinen8104e322011-03-13 12:26:22 +02003860 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3861 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303862 }
3863
3864 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01003865 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3866 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303867 | VB_XGI301C)) {
3868 temp = 0x4F;
3869 } else
3870 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003871 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303872 }
3873 }
3874}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003875
3876/* --------------------------------------------------------------------- */
3877/* Function : XGI_GetTap4Ptr */
3878/* Input : */
3879/* Output : di -> Tap4 Reg. Setting Pointer */
3880/* Description : */
3881/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003882static struct XGI301C_Tap4TimingStruct const
3883*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003884{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303885 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003886 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003887
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303888 if (tempcx == 0) {
3889 tempax = pVBInfo->VGAHDE;
3890 tempbx = pVBInfo->HDE;
3891 } else {
3892 tempax = pVBInfo->VGAVDE;
3893 tempbx = pVBInfo->VDE;
3894 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003895
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003896 if (tempax <= tempbx)
3897 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303898 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003899 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003900
Peter Huewe599801f2012-02-09 21:11:45 +01003901 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303902 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003903
Peter Huewe599801f2012-02-09 21:11:45 +01003904 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3905 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
3906 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003907 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01003908 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303909 Tap4TimingPtr = YPbPr750pTap4Timing;
3910 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003911
Peter Huewe599801f2012-02-09 21:11:45 +01003912 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003913 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003914
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303915 i = 0;
3916 while (Tap4TimingPtr[i].DE != 0xFFFF) {
3917 if (Tap4TimingPtr[i].DE == tempax)
3918 break;
3919 i++;
3920 }
3921 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003922}
3923
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003924static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003925{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303926 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003927 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303929 if (!(pVBInfo->VBType & VB_XGI301C))
3930 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003931
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303932 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
3933 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003934 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003935
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003936 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003937 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003938 /* Set Vertical Scaling */
3939 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303940 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003941 xgifb_reg_set(pVBInfo->Part2Port,
3942 i,
3943 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303944 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003945
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003946 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003947 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003948 /* Enable V.Scaling */
3949 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303950 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003951 /* Enable H.Scaling */
3952 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003953}
3954
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003955static void XGI_SetGroup3(unsigned short ModeIdIndex,
3956 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003957{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303958 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003959 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303960 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003961
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003962 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003963 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003964
Aaro Koskinen8104e322011-03-13 12:26:22 +02003965 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01003966 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003967 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3968 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303969 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003970 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
3971 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303972 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003973
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303974 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
3975 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003976
Peter Huewe599801f2012-02-09 21:11:45 +01003977 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003978 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3979 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
3980 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303981 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003982
Peter Huewe599801f2012-02-09 21:11:45 +01003983 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
3984 & SetCRT2ToYPbPr525750)) {
3985 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303986 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003987
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003988 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303989 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003990 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303991 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003992 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303993 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003994
Peter Huewe599801f2012-02-09 21:11:45 +01003995 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003996 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003997
Peter Huewe599801f2012-02-09 21:11:45 +01003998 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003999 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004000
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304001 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004002 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304004 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004005 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004006 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304007 }
4008 }
Aaro Koskinen2351d1f2013-05-29 23:59:13 +03004009}
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304010
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004011static void XGI_SetGroup4(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304012 unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304013 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004014{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304015 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304017 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004018
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004019 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004020 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304021 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004022 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304024 tempbx = pVBInfo->RVBHCMAX;
4025 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004026 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304027 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4028 tempcx = pVBInfo->VGAHT - 1;
4029 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004030 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004031
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304032 temp = ((tempcx & 0xFF00) >> 8) << 3;
4033 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304035 tempcx = pVBInfo->VGAVT - 1;
4036 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4037 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304039 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004040 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304041 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004042 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004043 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304044 tempcx = pVBInfo->VBInfo;
4045 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304047 if (modeflag & HalfDCLK)
4048 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304050 if (XGI_IsLCDDualLink(pVBInfo))
4051 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004052
Peter Huewe599801f2012-02-09 21:11:45 +01004053 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304054 temp = 0;
4055 if (tempbx <= 1024)
4056 temp = 0xA0;
4057 if (tempbx == 1280)
4058 temp = 0xC0;
4059 } else if (tempcx & SetCRT2ToTV) {
4060 temp = 0xA0;
4061 if (tempbx <= 800)
4062 temp = 0x80;
4063 } else {
4064 temp = 0x80;
4065 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4066 temp = 0;
4067 if (tempbx > 800)
4068 temp = 0x60;
4069 }
4070 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004071
Peter Huewe599801f2012-02-09 21:11:45 +01004072 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304073 temp = 0x00;
4074 if (pVBInfo->VGAHDE == 1280)
4075 temp = 0x40;
4076 if (pVBInfo->VGAHDE == 1024)
4077 temp = 0x20;
4078 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004079 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004080
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304081 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004082
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304083 tempcx = pVBInfo->RVBHRS;
4084 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004085 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004086
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304087 tempeax = pVBInfo->VGAVDE;
4088 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304090 if (tempeax <= tempebx) {
4091 tempcx = (tempcx & (~0x4000));
4092 tempeax = pVBInfo->VGAVDE;
4093 } else {
4094 tempeax -= tempebx;
4095 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004096
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304097 templong = (tempeax * 256 * 1024) % tempebx;
4098 tempeax = (tempeax * 256 * 1024) / tempebx;
4099 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304101 if (templong != 0)
4102 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304104 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004105 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304107 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004108 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304109 tempbx = (unsigned short) (tempebx >> 16);
4110 temp = tempbx & 0x00FF;
4111 temp = temp << 4;
4112 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004113 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304115 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004116 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4117 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304118 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004119 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304120 tempax = pVBInfo->VGAHDE;
4121 if (modeflag & HalfDCLK)
4122 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304124 if (XGI_IsLCDDualLink(pVBInfo))
4125 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304127 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4128 if (tempax > 800)
4129 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004130 } else if (pVBInfo->VGAHDE > 800) {
4131 if (pVBInfo->VGAHDE == 1024)
4132 tempax = (tempax * 25 / 32) - 1;
4133 else
4134 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304135 }
4136 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304138 temp = (tempax & 0xFF00) >> 8;
4139 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004140 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304141 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004142 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004143
Peter Huewe599801f2012-02-09 21:11:45 +01004144 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304145 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004146 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004147
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304148 }
4149 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304151 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4152 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004153 | TVSetYPbPr525p | TVSetYPbPr750p
4154 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304155 temp |= 0x0001;
4156 if ((pVBInfo->VBInfo & SetInSlaveMode)
4157 && (!(pVBInfo->TVInfo
4158 & TVSimuMode)))
4159 temp &= (~0x0001);
4160 }
4161 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004162
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004163 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304164 tempbx = pVBInfo->HT;
4165 if (XGI_IsLCDDualLink(pVBInfo))
4166 tempbx = tempbx >> 1;
4167 tempbx = (tempbx >> 1) - 2;
4168 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004169 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304170 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004171 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304172 }
4173 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004174
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004175 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004176}
4177
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004178static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4179{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004180 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004181}
4182
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004183static void XGI_SetGroup5(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004184{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304185 if (pVBInfo->ModeType == ModeVGA) {
4186 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004187 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304188 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304189 }
4190 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004191}
4192
Aaro Koskinenb053af12013-07-16 23:13:28 +03004193static void XGI_DisableGatingCRT(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004194{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004195 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004196}
4197
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004198static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
Aaro Koskinen334ab072013-07-16 23:13:30 +03004199 unsigned short ModeNo, unsigned short ModeIdIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004200{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004201 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004202
Aaro Koskinenb3979922012-11-04 21:14:52 +02004203 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004204 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4205 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004206 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004207 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004208
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304209 if (!(modeflag & Charx8Dot)) {
4210 xres /= 9;
4211 xres *= 8;
4212 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004213
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004214 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4215 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004216
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004217 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4218 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004219
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004220 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304221 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004222
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004223 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304224 return 0;
4225
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004226 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4227 yres != xgifb_info->lvds_data.LVDSVDE) {
Aaro Koskinen334ab072013-07-16 23:13:30 +03004228 colordepth = XGI_GetColorDepth(ModeIdIndex);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004229 if (colordepth > 2)
4230 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304231 }
4232 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004233}
4234
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004235static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4236 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004237 unsigned short ModeIdIndex,
4238 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004239{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304240 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004241 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304242 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4243 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4244 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004245
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004246 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004247 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304248 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004249 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004250
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004251 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004252
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004253 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004254 /* SR35[7] FP VSync polarity */
4255 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4256 /* SR30[5] FP HSync polarity */
4257 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004258
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004259 if (chip_id == XG27)
4260 XGI_SetXG27FPBits(pVBInfo);
4261 else
4262 XGI_SetXG21FPBits(pVBInfo);
4263
Aaro Koskinenb3979922012-11-04 21:14:52 +02004264 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004265 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4266 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004267 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004268 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004269
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304270 if (!(modeflag & Charx8Dot))
4271 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004272
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004273 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004274
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004275 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004276
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304277 if (LVDSHBS > LVDSHT)
4278 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004279
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004280 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304281 if (LVDSHRS > LVDSHT)
4282 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004283
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004284 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304285 if (LVDSHRE > LVDSHT)
4286 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004287
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004288 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004289
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004290 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004291
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004292 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004293 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304294 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004295
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304296 if (LVDSVBS > LVDSVT)
4297 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004298
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004299 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304300 if (LVDSVRS > LVDSVT)
4301 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004302
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004303 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304304 if (LVDSVRE > LVDSVT)
4305 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004306
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004307 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004308
Peter Huewe9388ad92013-02-15 20:37:10 +01004309 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004310 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004311
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304312 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004313 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004314
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304315 /* HT SR0B[1:0] CR00 */
4316 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004317 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004318 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004319
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304320 /* HBS SR0B[5:4] CR02 */
4321 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004322 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004323 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004324
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304325 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4326 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004327 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4328 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4329 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304331 /* HRS SR0B[7:6] CR04 */
4332 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004333 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004334 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304336 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4337 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004338 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004339 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304341 /* HRE SR0C[2] CR05[4:0] */
4342 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004343 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4344 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304346 /* Panel HRE SR2F[7:2] */
4347 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004348 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004349
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304350 /* VT SR0A[0] CR07[5][0] CR06 */
4351 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004352 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4353 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4354 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004355 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004356
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304357 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4358 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004359 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4360 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4361 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004362 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004363
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304364 /* VBE SR0A[4] CR16 */
4365 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004366 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004367 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004368
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304369 /* VRS SR0A[3] CR7[7][2] CR10 */
4370 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004371 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4372 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4373 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004374 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004375
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004376 if (chip_id == XG27) {
4377 /* Panel VRS SR35[2:0] SR34[7:0] */
4378 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4379 (value & 0x700) >> 8);
4380 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4381 } else {
4382 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4383 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4384 (value & 0x600) >> 9);
4385 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4386 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4387 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004388
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304389 /* VRE SR0A[5] CR11[3:0] */
4390 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004391 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4392 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004393
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304394 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004395 if (chip_id == XG27)
4396 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4397 (value << 2) & 0xFC);
4398 else
4399 /* SR3F[7] has to be 0, h/w bug */
4400 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4401 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004402
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304403 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004404
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004405 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004406 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004407 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004408 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004409 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304410 value += 0x10;
4411 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004412
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304413 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004414 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004415 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004416 /* set data, panning = 0, shift left 1 dot*/
4417 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004418
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004419 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004420 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304421
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004422 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304423 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004424
4425}
4426
4427/* --------------------------------------------------------------------- */
4428/* Function : XGI_IsLCDON */
4429/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004430/* Output : 0 : Skip PSC Control */
4431/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004432/* Description : */
4433/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004434static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004435{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304436 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004437
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304438 tempax = pVBInfo->VBInfo;
4439 if (tempax & SetCRT2ToDualEdge)
4440 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004441 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304442 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004443
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304444 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004445}
4446
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004447static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4448 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304449 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004450{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004451 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004452
Peter Huewe6896b942012-02-09 21:11:46 +01004453 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4454 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304455 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004456 if (!(pVBInfo->VBInfo &
4457 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004458 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004459 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304460 tempah = 0x7F; /* Disable Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304461 }
4462 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004463
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004464 /* disable part4_1f */
4465 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004466
Peter Huewe6896b942012-02-09 21:11:46 +01004467 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004468 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004469 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
Peter Huewe06cc47b2013-02-03 22:54:38 +01004470 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004471 /* LVDS Driver power down */
4472 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304473 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004474
Aaro Koskinend1724632013-05-29 23:59:09 +03004475 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA |
4476 SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004477 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004478
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004479 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4480 /* Power down */
4481 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004482
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004483 /* disable TV as primary VGA swap */
4484 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004485
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304486 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004487 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004488
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004489 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004490 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004491 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004492 (pVBInfo->VBInfo &
4493 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004494 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004495
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004496 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004497 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004498 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004499 (pVBInfo->VBInfo &
4500 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4501 /* save Part1 index 0 */
4502 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4503 /* BTDAC = 1, avoid VB reset */
4504 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4505 /* disable CRT2 */
4506 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4507 /* restore Part1 index 0 */
4508 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304509 }
4510 } else { /* {301} */
4511 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004512 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4513 /* Disable CRT2 */
4514 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4515 /* Disable TV asPrimary VGA swap */
4516 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304517 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004518
Peter Huewea3d675c2012-02-09 21:11:47 +01004519 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304520 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004521 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304522 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004523}
4524
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004525/* --------------------------------------------------------------------- */
4526/* Function : XGI_GetTVPtrIndex */
4527/* Input : */
4528/* Output : */
4529/* Description : bx 0 : ExtNTSC */
4530/* 1 : StNTSC */
4531/* 2 : ExtPAL */
4532/* 3 : StPAL */
4533/* 4 : ExtHiTV */
4534/* 5 : StHiTV */
4535/* 6 : Ext525i */
4536/* 7 : St525i */
4537/* 8 : Ext525p */
4538/* 9 : St525p */
4539/* A : Ext750p */
4540/* B : St750p */
4541/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004542static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004543{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304544 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004545
Peter Huewe599801f2012-02-09 21:11:45 +01004546 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304547 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004548 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304549 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004550 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004552 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304553 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004554 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304555 tempbx = 10;
4556 if (pVBInfo->TVInfo & TVSimuMode)
4557 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004558
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304559 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004560}
4561
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004562/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004563/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004564/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004565/* Output : bx 0 : NTSC */
4566/* 1 : PAL */
4567/* 2 : PALM */
4568/* 3 : PALN */
4569/* 4 : NTSC1024x768 */
4570/* 5 : PAL-M 1024x768 */
4571/* 6-7: reserved */
4572/* cl 0 : YFilter1 */
4573/* 1 : YFilter2 */
4574/* ch 0 : 301A */
4575/* 1 : 301B/302B/301LV/302LV */
4576/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004577/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004578static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4579 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004580{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004581 *tempbx = 0;
4582 *tempcl = 0;
4583 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004584
Peter Huewe599801f2012-02-09 21:11:45 +01004585 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004586 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004587
Peter Huewe599801f2012-02-09 21:11:45 +01004588 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004589 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004590
Peter Huewe599801f2012-02-09 21:11:45 +01004591 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004592 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004593
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004594 if (pVBInfo->TVInfo & NTSC1024x768) {
4595 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004596 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004597 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304598 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004599
Peter Huewe6896b942012-02-09 21:11:46 +01004600 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4601 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004602 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4603 & TVSimuMode)) {
4604 *tempbx += 8;
4605 *tempcl += 1;
4606 }
4607 }
4608
Peter Huewe6896b942012-02-09 21:11:46 +01004609 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4610 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004611 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004612}
4613
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004614static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004615{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304616 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004617
Peter Huewe6896b942012-02-09 21:11:46 +01004618 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4619 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004620 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304621 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304622 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004623 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304625 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4626 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004627 if (pVBInfo->VBInfo &
4628 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004629 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004630
Peter Huewea3d675c2012-02-09 21:11:47 +01004631 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304632 tempbl = tempbh;
4633 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004634
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304635 tempbl &= 0x0F;
4636 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004637 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004638
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304639 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4640 | SetCRT2ToTV)) { /* Channel B */
4641 tempah &= 0xF0;
4642 tempah |= tempbl;
4643 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004644
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004645 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4646 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304647 tempah &= 0x0F;
4648 tempah |= tempbh;
4649 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004650 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304651 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304652 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004653}
4654
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004655static void XGI_SetLCDCap_A(unsigned short tempcx,
4656 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004657{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304658 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004659
Aaro Koskinen58839b02011-03-13 12:26:23 +02004660 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004661
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304662 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004663 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004664 /* Enable Dither */
4665 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004666 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304667 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004668 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304669 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004670 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304671 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004672}
4673
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004674/* --------------------------------------------------------------------- */
4675/* Function : XGI_SetLCDCap_B */
4676/* Input : cx -> LCD Capability */
4677/* Output : */
4678/* Description : */
4679/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004680static void XGI_SetLCDCap_B(unsigned short tempcx,
4681 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004682{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304683 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004684 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304685 (unsigned short) (((tempcx & 0x00ff) >> 6)
4686 | 0x0c));
4687 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004688 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304689 (unsigned short) (((tempcx & 0x00ff) >> 6)
4690 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004691}
4692
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004693static void XGI_LongWait(struct vb_device_info *pVBInfo)
4694{
4695 unsigned short i;
4696
4697 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4698
4699 if (!(i & 0xC0)) {
4700 for (i = 0; i < 0xFFFF; i++) {
4701 if (!(inb(pVBInfo->P3da) & 0x08))
4702 break;
4703 }
4704
4705 for (i = 0; i < 0xFFFF; i++) {
4706 if ((inb(pVBInfo->P3da) & 0x08))
4707 break;
4708 }
4709 }
4710}
4711
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004712static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004713{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304714 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004715
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304716 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004717
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004718 /* disable down spectrum D[4] */
4719 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304720 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004721 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304722 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004723
Aaro Koskinen8104e322011-03-13 12:26:22 +02004724 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304725 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004726 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304727 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004728 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304729 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004730 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304731 pVBInfo->LCDCapList[index].Spectrum_34);
4732 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004733 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004734}
4735
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004736static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4737{
4738 unsigned short tempcx;
4739
4740 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4741
Peter Huewef951dd02013-02-05 00:29:47 +01004742 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4743 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004744 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004745 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004746 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004747 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004748 (unsigned char) (tempcx & 0x1F));
4749 }
4750 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004751 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004752 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4753 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4754 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004755
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004756 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4757 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004758 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004759 XGI_SetLCDCap_A(tempcx, pVBInfo);
4760
Peter Huewe6896b942012-02-09 21:11:46 +01004761 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004762 if (tempcx & EnableSpectrum)
4763 SetSpectrum(pVBInfo);
4764 }
4765 } else {
4766 /* LVDS,CH7017 */
4767 XGI_SetLCDCap_A(tempcx, pVBInfo);
4768 }
4769}
4770
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004771/* --------------------------------------------------------------------- */
4772/* Function : XGI_SetAntiFlicker */
4773/* Input : */
4774/* Output : */
4775/* Description : Set TV Customized Param. */
4776/* --------------------------------------------------------------------- */
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004777static void XGI_SetAntiFlicker(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004778{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004779 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004780
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304781 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004782
Peter Huewe599801f2012-02-09 21:11:45 +01004783 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304784 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304786 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4787 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304788 tempah = TVAntiFlickList[tempbx];
4789 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004790
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004791 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004792}
4793
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004794static void XGI_SetEdgeEnhance(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004795{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03004796 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304798 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004799
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304800 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4801 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304802 tempah = TVEdgeList[tempbx];
4803 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004804
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004805 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004806}
4807
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004808static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004809{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304810 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004811
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304812 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304814 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304816 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4817 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004818
Aaro Koskinen8104e322011-03-13 12:26:22 +02004819 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304820 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004821 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304822 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004823 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304824 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004825 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304826 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004827}
4828
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004829static void XGI_SetYFilter(unsigned short ModeIdIndex,
4830 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004831{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304832 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02004833 unsigned char const *filterPtr;
4834 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304836 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004837
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304838 switch (tempbx) {
4839 case 0x00:
4840 case 0x04:
4841 filterPtr = NTSCYFilter1;
4842 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004843
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304844 case 0x01:
4845 filterPtr = PALYFilter1;
4846 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304848 case 0x02:
4849 case 0x05:
4850 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304851 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03004852 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304853 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004854
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304855 case 0x08:
4856 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304857 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304858 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304859 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03004860 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304861 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004862
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304863 default:
4864 return;
4865 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004866
Aaro Koskinenb3979922012-11-04 21:14:52 +02004867 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304868 if (tempcl == 0)
4869 index = tempal * 4;
4870 else
4871 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004872
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304873 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004874 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
4875 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
4876 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
4877 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304878 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004879 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
4880 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
4881 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
4882 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304883 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004884
Peter Huewe6896b942012-02-09 21:11:46 +01004885 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4886 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004887 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
4888 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
4889 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304890 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004891}
4892
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004893/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004894/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004895/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004896/* Output : */
4897/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004898/* --------------------------------------------------------------------- */
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004899static void XGI_OEM310Setting(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004900 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004901{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004902 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004903
Peter Huewea3d675c2012-02-09 21:11:47 +01004904 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004905 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004906
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004907 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004908 XGI_SetPhaseIncr(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004909 XGI_SetYFilter(ModeIdIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004910 XGI_SetAntiFlicker(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004911
Peter Huewe6896b942012-02-09 21:11:46 +01004912 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004913 XGI_SetEdgeEnhance(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304914 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004915}
4916
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004917/* --------------------------------------------------------------------- */
4918/* Function : XGI_SetCRT2ModeRegs */
4919/* Input : */
4920/* Output : */
4921/* Description : Origin code for crt2group */
4922/* --------------------------------------------------------------------- */
Aaro Koskinenb053af12013-07-16 23:13:28 +03004923static void XGI_SetCRT2ModeRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004924{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304925 unsigned short tempbl;
4926 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004927
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304928 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004929
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304930 tempah = 0;
4931 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02004932 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304933 tempah &= ~0x10; /* BTRAMDAC */
4934 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004935
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304936 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
4937 | SetCRT2ToLCD)) {
4938 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004939 tempcl = pVBInfo->ModeType;
4940 tempcl -= ModeVGA;
4941 if (tempcl >= 0) {
4942 /* BT Color */
4943 tempah = (0x008 >> tempcl);
4944 if (tempah == 0)
4945 tempah = 1;
4946 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304947 }
4948 if (pVBInfo->VBInfo & SetInSlaveMode)
4949 tempah ^= 0x50; /* BTDAC */
4950 }
4951 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004952
Aaro Koskinen8104e322011-03-13 12:26:22 +02004953 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304954 tempah = 0x08;
4955 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004956
Miguel Gómeze123e462012-07-06 12:40:52 +02004957 if (pVBInfo->VBInfo & DisableCRT2Display)
4958 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004959
Miguel Gómeze123e462012-07-06 12:40:52 +02004960 tempah = 0x00;
4961 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004962
Miguel Gómeze123e462012-07-06 12:40:52 +02004963 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
4964 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4965 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004966
Miguel Gómeze123e462012-07-06 12:40:52 +02004967 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
4968 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
4969 tempbl &= 0xf7;
4970 tempah |= 0x01;
4971 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304972 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004973
Miguel Gómeze123e462012-07-06 12:40:52 +02004974 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4975 tempbl &= 0xf7;
4976 tempah |= 0x01;
4977 }
4978
4979 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
4980 goto reg_and_or;
4981
4982 tempbl &= 0xf8;
4983 tempah = 0x01;
4984
4985 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4986 tempah |= 0x02;
4987
4988 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
4989 tempah = tempah ^ 0x05;
4990 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4991 tempah = tempah ^ 0x01;
4992 }
4993
4994 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
4995 tempah |= 0x08;
4996
4997reg_and_or:
4998 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
4999
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305000 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005001 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305002 tempah &= (~0x08);
5003 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5004 & SetInSlaveMode))) {
5005 tempah |= 0x010;
5006 }
5007 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005008
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305009 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305010 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005011 if (pVBInfo->VBInfo & DriverMode)
5012 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305013 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005014
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005015 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305016 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005017
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305018 if (pVBInfo->LCDInfo & SetLCDDualLink)
5019 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005020
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305021 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305022 if (pVBInfo->TVInfo & RPLLDIV2XO)
5023 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305024 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005025
Peter Huewe255aabd2012-02-09 21:11:44 +01005026 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5027 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305028 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005029
Peter Huewe255aabd2012-02-09 21:11:44 +01005030 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305031 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005032
Aaro Koskinen8104e322011-03-13 12:26:22 +02005033 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305034 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005035
Peter Huewe6896b942012-02-09 21:11:46 +01005036 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5037 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305038 tempah = 0;
5039 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305041 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5042 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005043 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305044 tempah |= 0x04; /* shampoo 0129 */
5045 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005046
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005047 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305048 tempah = 0x00;
5049 tempbl = 0xcf;
5050 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5051 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5052 tempah |= 0x30;
5053 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005054
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005055 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305056 tempah = 0;
5057 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305059 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5060 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5061 tempah |= 0xc0;
5062 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005063 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305064 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005065
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305066 tempah = 0;
5067 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005068 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305069 tempbl = 0xff;
5070 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5071 tempah |= 0x80;
5072 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005073
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005074 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005075
Peter Huewe6896b942012-02-09 21:11:46 +01005076 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305077 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005078 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5079 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305080 }
5081 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005082}
5083
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005084
Aaro Koskinenb053af12013-07-16 23:13:28 +03005085void XGI_UnLockCRT2(struct vb_device_info *pVBInfo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305086{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005087 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005088}
5089
Aaro Koskinenb053af12013-07-16 23:13:28 +03005090void XGI_LockCRT2(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005091{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005092 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005093}
5094
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005095unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5096 unsigned short ModeNo, unsigned short ModeIdIndex,
5097 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005098{
Peter Huewef2c22602013-02-03 22:54:30 +01005099 const u8 LCDARefreshIndex[] = {
5100 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005101
Peter Hueweef9a6b92013-02-03 04:08:43 +01005102 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005103
Aaro Koskinen58839b02011-03-13 12:26:23 +02005104 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005105 index = index >> pVBInfo->SelectCRT2Rate;
5106 index &= 0x0F;
5107
5108 if (pVBInfo->LCDInfo & LCDNonExpanding)
5109 index = 0;
5110
5111 if (index > 0)
5112 index--;
5113
5114 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005115 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005116 temp = LCDARefreshIndex[pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005117
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005118 if (index > temp)
5119 index = temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005120 }
5121 }
5122
Aaro Koskinenb3979922012-11-04 21:14:52 +02005123 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005124 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005125 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005126 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5127 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005128 index++;
5129 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005130 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005131 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5132 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005133 index++;
5134 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005135 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5136 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005137 index++;
5138 }
5139 }
5140
5141 i = 0;
5142 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005143 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005144 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005145 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005146 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005147 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005148 if (temp < pVBInfo->ModeType)
5149 break;
5150 i++;
5151 index--;
5152
5153 } while (index != 0xFFFF);
5154 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5155 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005156 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005157 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005158 if (temp & InterlaceMode)
5159 i++;
5160 }
5161 }
5162 i--;
5163 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005164 temp = XGI_AjustCRT2Rate(ModeIdIndex, RefreshRateTableIndex,
5165 &i, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005166 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005167 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005168}
5169
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005170static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305171 struct xgi_hw_device_info *HwDeviceExtension,
5172 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005173{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005174 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005175
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005176 pVBInfo->SetFlag |= ProgrammingCRT2;
5177 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5178 ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005179 XGI_GetLVDSResInfo(ModeIdIndex, pVBInfo);
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03005180 XGI_GetLVDSData(ModeIdIndex, pVBInfo);
5181 XGI_ModCRT1Regs(ModeIdIndex, HwDeviceExtension, pVBInfo);
5182 XGI_SetLVDSRegs(ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005183 XGI_SetCRT2ECLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005184}
5185
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005186static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005187 struct xgi_hw_device_info *HwDeviceExtension,
5188 struct vb_device_info *pVBInfo)
5189{
Peter Huewea9e29e62013-02-03 04:08:44 +01005190 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005191
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005192 pVBInfo->SetFlag |= ProgrammingCRT2;
Aaro Koskinen334ab072013-07-16 23:13:30 +03005193 XGI_SearchModeID(ModeNo, &ModeIdIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005194 pVBInfo->SelectCRT2Rate = 4;
5195 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5196 ModeIdIndex, pVBInfo);
5197 XGI_SaveCRT2Info(ModeNo, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005198 XGI_GetCRT2ResInfo(ModeIdIndex, pVBInfo);
5199 XGI_GetCRT2Data(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005200 XGI_PreSetGroup1(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5201 XGI_SetGroup1(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03005202 XGI_SetLockRegs(ModeNo, ModeIdIndex, pVBInfo);
5203 XGI_SetGroup2(ModeNo, ModeIdIndex, pVBInfo);
5204 XGI_SetLCDRegs(ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005205 XGI_SetTap4Regs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005206 XGI_SetGroup3(ModeIdIndex, pVBInfo);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005207 XGI_SetGroup4(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005208 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005209 XGI_SetGroup5(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005210 XGI_AutoThreshold(pVBInfo);
5211 return 1;
5212}
5213
5214void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5215{
5216 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5217 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5218 0x05, 0x00 };
5219
5220 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5221
5222 unsigned char CR17, CR63, SR31;
5223 unsigned short temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005224
5225 int i;
Vitor Braga694683f2014-03-30 00:44:59 -03005226
Aaro Koskinen8104e322011-03-13 12:26:22 +02005227 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005228
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005229 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005230 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005231 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005232 pVBInfo->P3d4, 0x53) | 0x02));
5233
Peter Huewe9388ad92013-02-15 20:37:10 +01005234 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5235 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5236 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005237
Aaro Koskinen8104e322011-03-13 12:26:22 +02005238 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5239 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005240
Peter Huewe9388ad92013-02-15 20:37:10 +01005241 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005242 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005243
Peter Huewe9388ad92013-02-15 20:37:10 +01005244 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005245 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005246
Peter Huewe9388ad92013-02-15 20:37:10 +01005247 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005248 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005249 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005250 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005251
Aaro Koskinen8104e322011-03-13 12:26:22 +02005252 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005253
5254 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005255 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005256
5257 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005258 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005259 CRTCData[i]);
5260
5261 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005262 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005263 CRTCData[i]);
5264
5265 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005266 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005267 CRTCData[i]);
5268
Aaro Koskinen8104e322011-03-13 12:26:22 +02005269 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005270 & 0xE0));
5271
Aaro Koskinen8104e322011-03-13 12:26:22 +02005272 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5273 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5274 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005275
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005276 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005277
Ebru Akagunduzf88d8182013-10-07 22:25:28 +03005278 for (i = 0; i < 256 * 3; i++)
Peter Huewe771f3ee2013-02-15 20:37:13 +01005279 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005280
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005281 mdelay(1);
5282
5283 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005284 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005285
5286 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005287 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005288 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005289 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005290
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005291 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005292 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005293
Ebru Akagunduzf88d8182013-10-07 22:25:28 +03005294 for (i = 0; i < 256 * 3; i++)
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005295 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005296
Aaro Koskinen8104e322011-03-13 12:26:22 +02005297 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5298 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5299 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005300
Peter Huewe9388ad92013-02-15 20:37:10 +01005301 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005302 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005303 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005304}
5305
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005306static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5307 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005308 struct vb_device_info *pVBInfo)
5309{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005310 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005311
Peter Huewe6896b942012-02-09 21:11:46 +01005312 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5313 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinena2526d12013-05-29 23:59:10 +03005314 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Aaro Koskinend1724632013-05-29 23:59:09 +03005315 /* Power on */
5316 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005317
Aaro Koskinenb8e34b32013-05-29 23:59:08 +03005318 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
5319 SetCRT2ToRAMDAC)) {
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005320 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5321 tempah &= 0xDF;
5322 if (pVBInfo->VBInfo & SetInSlaveMode) {
5323 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
5324 tempah |= 0x20;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005325 }
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005326 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5327 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5328
5329 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5330
5331 if (!(tempah & 0x80))
5332 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5333 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005334 }
5335
Aaro Koskinena2526d12013-05-29 23:59:10 +03005336 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005337 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005338 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005339 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen056b5402013-05-29 23:59:11 +03005340 if (pVBInfo->VBInfo &
5341 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
5342 /* LVDS PLL power on */
5343 xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
5344 0x7F);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005345 /* LVDS Driver power on */
5346 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005347 }
5348 }
5349
5350 tempah = 0x00;
5351
5352 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5353 tempah = 0xc0;
5354
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005355 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5356 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5357 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5358 tempah = tempah & 0x40;
5359 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5360 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005361 }
5362 }
5363
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005364 /* EnablePart4_1F */
5365 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005366
Aaro Koskinenb053af12013-07-16 23:13:28 +03005367 XGI_DisableGatingCRT(pVBInfo);
Aaro Koskinend1724632013-05-29 23:59:09 +03005368 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005369 } /* 301 */
5370 else { /* LVDS */
5371 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005372 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005373 /* enable CRT2 */
5374 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005375
Peter Huewe9388ad92013-02-15 20:37:10 +01005376 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005377 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005378 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005379
Aaro Koskinendc505562011-03-13 12:26:26 +02005380 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005381 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005382 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005383}
5384
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005385static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5386 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005387 unsigned short ModeNo, unsigned short ModeIdIndex,
5388 struct vb_device_info *pVBInfo)
5389{
Aaro Koskinena1579612012-04-07 01:14:05 +03005390 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005391
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005392 XGI_SetSeqRegs(pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005393 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005394 XGI_SetCRTCRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005395 XGI_SetATTRegs(ModeIdIndex, pVBInfo);
Aaro Koskinena1579612012-04-07 01:14:05 +03005396 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005397 XGI_ClearExt1Regs(pVBInfo);
5398
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005399 if (HwDeviceExtension->jChipType == XG27) {
5400 if (pVBInfo->IF_DEF_LVDS == 0)
5401 XGI_SetDefaultVCLK(pVBInfo);
5402 }
5403
5404 temp = ~ProgrammingCRT2;
5405 pVBInfo->SetFlag &= temp;
5406 pVBInfo->SelectCRT2Rate = 0;
5407
Peter Huewe6896b942012-02-09 21:11:46 +01005408 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5409 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005410 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005411 | SetInSlaveMode)) {
5412 pVBInfo->SetFlag |= ProgrammingCRT2;
5413 }
5414 }
5415
5416 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5417 ModeIdIndex, pVBInfo);
5418 if (RefreshRateTableIndex != 0xFFFF) {
5419 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005420 XGI_SetCRT1CRTC(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005421 pVBInfo, HwDeviceExtension);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005422 XGI_SetCRT1DE(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005423 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5424 HwDeviceExtension, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005425 XGI_SetCRT1VCLK(ModeIdIndex, HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005426 RefreshRateTableIndex, pVBInfo);
5427 }
5428
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005429 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005430 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005431 if (temp & 0xA0) {
5432
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005433 if (HwDeviceExtension->jChipType == XG27)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005434 XGI_SetXG27CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005435 else
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005436 XGI_SetXG21CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005437
5438 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5439 RefreshRateTableIndex);
5440
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005441 xgifb_set_lcd(HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005442 pVBInfo, RefreshRateTableIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005443
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005444 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005445 xgifb_set_lvds(xgifb_info,
5446 HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005447 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005448 }
5449 }
5450
5451 pVBInfo->SetFlag &= (~ProgrammingCRT2);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005452 XGI_SetCRT1FIFO(HwDeviceExtension, pVBInfo);
5453 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeIdIndex,
5454 RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005455 XGI_LoadDAC(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005456}
5457
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005458unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5459 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005460 unsigned short ModeNo)
5461{
5462 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005463 struct vb_device_info VBINF;
5464 struct vb_device_info *pVBInfo = &VBINF;
Chaitanya Hazarey0292bd42014-05-23 12:24:37 -07005465
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005466 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005467
Aaro Koskinenee768752013-05-29 23:59:16 +03005468 if (HwDeviceExtension->jChipType >= XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005469 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005470
Aaro Koskinen56810a92013-01-21 02:57:47 +02005471 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005472
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005473 /* for x86 Linux, XG21 LVDS */
5474 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005475 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005476 pVBInfo->IF_DEF_LVDS = 1;
5477 }
5478 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005479 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5480 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005481 pVBInfo->IF_DEF_LVDS = 1;
5482 }
5483 }
5484
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005485 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005486 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005487 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005488 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005489
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005490 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005491 XGI_UnLockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005492
Aaro Koskinen334ab072013-07-16 23:13:30 +03005493 XGI_SearchModeID(ModeNo, &ModeIdIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005494
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005495 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinenb053af12013-07-16 23:13:28 +03005496 XGI_GetVBInfo(ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005497 XGI_GetTVInfo(ModeIdIndex, pVBInfo);
5498 XGI_GetLCDInfo(ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005499 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005500
Peter Huewee44adfd2013-02-03 22:54:39 +01005501 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5502 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005503 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005504 ModeIdIndex, pVBInfo);
5505
Peter Huewea3d675c2012-02-09 21:11:47 +01005506 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005507 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5508 HwDeviceExtension, pVBInfo);
5509 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005510 }
5511
Peter Huewe6896b942012-02-09 21:11:46 +01005512 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005513 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005514 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005515 case VB_CHIP_302:
5516 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5517 pVBInfo); /*add for CRT2 */
5518 break;
5519
5520 default:
5521 break;
5522 }
5523 }
5524
Aaro Koskinenb053af12013-07-16 23:13:28 +03005525 XGI_SetCRT2ModeRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005526 XGI_OEM310Setting(ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005527 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005528 } /* !XG20 */
5529 else {
5530 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005531 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Aaro Koskinen334ab072013-07-16 23:13:30 +03005532 ModeIdIndex))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005533 return 0;
5534
Aaro Koskinenb3979922012-11-04 21:14:52 +02005535 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005536 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005537
5538 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005539 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005540
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005541 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005542
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005543 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5544 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005545
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005546 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005547 }
5548
Aaro Koskinenb053af12013-07-16 23:13:28 +03005549 XGI_UpdateModeInfo(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005550
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005551 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005552 XGI_LockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005553
5554 return 1;
5555}