blob: a47395e92d20aecaa90eb4de981e4fba3a78ceaf [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);
Aya Mahfouz46283372015-02-26 11:27:44 +0200311 data >>= 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530312 data = data + 3;
313 if (data > 7)
314 data = data - 7;
Aya Mahfouz46283372015-02-26 11:27:44 +0200315 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;
Aya Mahfouz46283372015-02-26 11:27:44 +0200350 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)
Aya Mahfouz46283372015-02-26 11:27:44 +0200696 tempax >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200697
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300698 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +0200699 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)
Aya Mahfouz46283372015-02-26 11:27:44 +0200704 tempbx >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200705
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300706 if (modeflag & DoubleScanMode)
Aya Mahfouz46283372015-02-26 11:27:44 +0200707 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;
Aya Mahfouz46283372015-02-26 11:27:44 +0200724 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;
Aya Mahfouz46283372015-02-26 11:27:44 +0200753 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)
Aya Mahfouz46283372015-02-26 11:27:44 +0200760 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;
Aya Mahfouz46283372015-02-26 11:27:44 +0200795 temp >>= 8; /* ah */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530796 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
Aya Mahfouz46283372015-02-26 11:27:44 +0200812 DisplayUnit <<= 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530813 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;
Aya Mahfouz46283372015-02-26 11:27:44 +0200915 data <<= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530916 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02001014 data3 <<= 2;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001015 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);
Aya Mahfouz46283372015-02-26 11:27:44 +02001129 data >>= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301130 }
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)
Aya Mahfouz46283372015-02-26 11:27:44 +02001188 xres <<= 1;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001189
1190 if (modeflag & DoubleScanMode)
Aya Mahfouz46283372015-02-26 11:27:44 +02001191 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
Aya Mahfouz46283372015-02-26 11:27:44 +02001453 tempcx >>= 3;
1454 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02001476 tempax >>= 5;
1477 tempcx >>= 3;
1478 tempbx >>= 3;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001479
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;
Aya Mahfouz46283372015-02-26 11:27:44 +02001603 temp3 <<= 16;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001604 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
Aya Mahfouz46283372015-02-26 11:27:44 +02001625 temp3 >>= 16;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001626
1627 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +02001628 temp3 >>= 1;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001629
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;
Aya Mahfouz46283372015-02-26 11:27:44 +02001912 push <<= 8;
Miguel Gómezf9317352012-07-06 12:40:48 +02001913 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
Aya Mahfouz46283372015-02-26 11:27:44 +02002110 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++) {
Aya Mahfouz46283372015-02-26 11:27:44 +02002185 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02002497 tempcx <<= 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002498 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)
Aya Mahfouz46283372015-02-26 11:27:44 +02002748 temp <<= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302749
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)
Aya Mahfouz46283372015-02-26 11:27:44 +02002757 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02002829 tempcx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302830 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02002864 tempcx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302865 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)
Aya Mahfouz46283372015-02-26 11:27:44 +02002983 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)
Aya Mahfouz46283372015-02-26 11:27:44 +02003018 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 */
Aya Mahfouz46283372015-02-26 11:27:44 +02003145 tempax >>= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303146 push1 = tempax; /* push ax */
3147
3148 if (resinfo != 0x09) {
Aya Mahfouz46283372015-02-26 11:27:44 +02003149 tempax <<= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303150 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003182 tempax >>= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303183 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003335 tempax >>= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303336 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))
Aya Mahfouz46283372015-02-26 11:27:44 +02003380 tempcx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303381
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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003397 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003406 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003431 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003439 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)))
Aya Mahfouz46283372015-02-26 11:27:44 +02003465 tempbx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303466 } else
Aya Mahfouz46283372015-02-26 11:27:44 +02003467 tempbx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303468 }
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)))
Aya Mahfouz46283372015-02-26 11:27:44 +02003517 tempbx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303518 }
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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003630 temp <<= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303631 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))
Aya Mahfouz46283372015-02-26 11:27:44 +02003694 tempbx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303695
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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003700 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003716 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003773 tempah <<= 3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303774 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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003790 temp <<= 4;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303791 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)) {
Aya Mahfouz46283372015-02-26 11:27:44 +02003799 tempax >>= 1;
3800 tempbx >>= 1;
3801 tempcx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303802 }
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)) {
Aya Mahfouz46283372015-02-26 11:27:44 +02003829 tempax >>= 1;
3830 tempbx >>= 1;
3831 tempcx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303832 }
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;
Aya Mahfouz46283372015-02-26 11:27:44 +02003846 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];
Thomas Gummerer9c8c8312014-09-05 17:09:34 +02003898 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003899
Peter Huewe599801f2012-02-09 21:11:45 +01003900 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303901 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003902
Peter Huewe599801f2012-02-09 21:11:45 +01003903 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3904 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
3905 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003906 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01003907 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303908 Tap4TimingPtr = YPbPr750pTap4Timing;
3909 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003910
Peter Huewe599801f2012-02-09 21:11:45 +01003911 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003912 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003913
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303914 i = 0;
3915 while (Tap4TimingPtr[i].DE != 0xFFFF) {
3916 if (Tap4TimingPtr[i].DE == tempax)
3917 break;
3918 i++;
3919 }
3920 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003921}
3922
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003923static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003924{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303925 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003926 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003927
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303928 if (!(pVBInfo->VBType & VB_XGI301C))
3929 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003930
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303931 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
3932 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003933 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003934
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003935 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003936 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003937 /* Set Vertical Scaling */
3938 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303939 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003940 xgifb_reg_set(pVBInfo->Part2Port,
3941 i,
3942 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303943 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003944
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003945 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003946 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003947 /* Enable V.Scaling */
3948 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303949 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003950 /* Enable H.Scaling */
3951 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003952}
3953
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003954static void XGI_SetGroup3(unsigned short ModeIdIndex,
3955 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003956{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303957 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003958 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303959 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003960
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003961 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003962 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003963
Aaro Koskinen8104e322011-03-13 12:26:22 +02003964 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01003965 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003966 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3967 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303968 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003969 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
3970 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303971 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303973 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
3974 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003975
Peter Huewe599801f2012-02-09 21:11:45 +01003976 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003977 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3978 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
3979 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303980 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003981
Peter Huewe599801f2012-02-09 21:11:45 +01003982 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
3983 & SetCRT2ToYPbPr525750)) {
3984 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303985 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003986
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003987 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303988 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003989 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303990 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003991 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303992 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003993
Peter Huewe599801f2012-02-09 21:11:45 +01003994 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003995 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003996
Peter Huewe599801f2012-02-09 21:11:45 +01003997 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003998 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003999
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304000 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004001 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004002
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304003 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004004 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004005 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304006 }
4007 }
Aaro Koskinen2351d1f2013-05-29 23:59:13 +03004008}
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304009
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004010static void XGI_SetGroup4(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304011 unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304012 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004013{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304014 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304016 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004017
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004018 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004019 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304020 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004021 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004022
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304023 tempbx = pVBInfo->RVBHCMAX;
4024 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004025 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304026 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4027 tempcx = pVBInfo->VGAHT - 1;
4028 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004029 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004030
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304031 temp = ((tempcx & 0xFF00) >> 8) << 3;
4032 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304034 tempcx = pVBInfo->VGAVT - 1;
4035 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4036 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304038 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004039 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304040 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004041 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004042 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304043 tempcx = pVBInfo->VBInfo;
4044 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004045
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304046 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +02004047 tempbx >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004048
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304049 if (XGI_IsLCDDualLink(pVBInfo))
Aya Mahfouz46283372015-02-26 11:27:44 +02004050 tempbx >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004051
Peter Huewe599801f2012-02-09 21:11:45 +01004052 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304053 temp = 0;
4054 if (tempbx <= 1024)
4055 temp = 0xA0;
4056 if (tempbx == 1280)
4057 temp = 0xC0;
4058 } else if (tempcx & SetCRT2ToTV) {
4059 temp = 0xA0;
4060 if (tempbx <= 800)
4061 temp = 0x80;
4062 } else {
4063 temp = 0x80;
4064 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4065 temp = 0;
4066 if (tempbx > 800)
4067 temp = 0x60;
4068 }
4069 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004070
Peter Huewe599801f2012-02-09 21:11:45 +01004071 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304072 temp = 0x00;
4073 if (pVBInfo->VGAHDE == 1280)
4074 temp = 0x40;
4075 if (pVBInfo->VGAHDE == 1024)
4076 temp = 0x20;
4077 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004078 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304080 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004081
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304082 tempcx = pVBInfo->RVBHRS;
4083 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004084 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004085
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304086 tempeax = pVBInfo->VGAVDE;
4087 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304089 if (tempeax <= tempebx) {
4090 tempcx = (tempcx & (~0x4000));
4091 tempeax = pVBInfo->VGAVDE;
4092 } else {
4093 tempeax -= tempebx;
4094 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004095
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304096 templong = (tempeax * 256 * 1024) % tempebx;
4097 tempeax = (tempeax * 256 * 1024) / tempebx;
4098 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304100 if (templong != 0)
4101 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004102
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304103 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004104 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304106 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004107 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304108 tempbx = (unsigned short) (tempebx >> 16);
4109 temp = tempbx & 0x00FF;
Aya Mahfouz46283372015-02-26 11:27:44 +02004110 temp <<= 4;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304111 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004112 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304114 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004115 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4116 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304117 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004118 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304119 tempax = pVBInfo->VGAHDE;
4120 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +02004121 tempax >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304123 if (XGI_IsLCDDualLink(pVBInfo))
Aya Mahfouz46283372015-02-26 11:27:44 +02004124 tempax >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304126 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4127 if (tempax > 800)
4128 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004129 } else if (pVBInfo->VGAHDE > 800) {
4130 if (pVBInfo->VGAHDE == 1024)
4131 tempax = (tempax * 25 / 32) - 1;
4132 else
4133 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304134 }
4135 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304137 temp = (tempax & 0xFF00) >> 8;
Jiayi Ye1d06bb42014-10-25 10:58:28 +08004138 temp = (temp & 0x0003) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004139 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304140 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004141 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004142
Peter Huewe599801f2012-02-09 21:11:45 +01004143 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304144 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004145 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304147 }
4148 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304150 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4151 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004152 | TVSetYPbPr525p | TVSetYPbPr750p
4153 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304154 temp |= 0x0001;
4155 if ((pVBInfo->VBInfo & SetInSlaveMode)
4156 && (!(pVBInfo->TVInfo
4157 & TVSimuMode)))
4158 temp &= (~0x0001);
4159 }
4160 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004161
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004162 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304163 tempbx = pVBInfo->HT;
4164 if (XGI_IsLCDDualLink(pVBInfo))
Aya Mahfouz46283372015-02-26 11:27:44 +02004165 tempbx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304166 tempbx = (tempbx >> 1) - 2;
4167 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004168 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304169 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004170 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304171 }
4172 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004173
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004174 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004175}
4176
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004177static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4178{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004179 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004180}
4181
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004182static void XGI_SetGroup5(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004183{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304184 if (pVBInfo->ModeType == ModeVGA) {
4185 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004186 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304187 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304188 }
4189 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004190}
4191
Aaro Koskinenb053af12013-07-16 23:13:28 +03004192static void XGI_DisableGatingCRT(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004193{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004194 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004195}
4196
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004197static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
Aaro Koskinen334ab072013-07-16 23:13:30 +03004198 unsigned short ModeNo, unsigned short ModeIdIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004199{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004200 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004201
Aaro Koskinenb3979922012-11-04 21:14:52 +02004202 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004203 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4204 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004205 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004206 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004207
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304208 if (!(modeflag & Charx8Dot)) {
4209 xres /= 9;
4210 xres *= 8;
4211 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004212
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004213 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4214 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004215
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004216 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4217 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004218
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004219 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304220 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004221
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004222 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304223 return 0;
4224
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004225 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4226 yres != xgifb_info->lvds_data.LVDSVDE) {
Aaro Koskinen334ab072013-07-16 23:13:30 +03004227 colordepth = XGI_GetColorDepth(ModeIdIndex);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004228 if (colordepth > 2)
4229 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304230 }
4231 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004232}
4233
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004234static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4235 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004236 unsigned short ModeIdIndex,
4237 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004238{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304239 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004240 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304241 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4242 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4243 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004244
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004245 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004246 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304247 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004248 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004249
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004250 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004251
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004252 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004253 /* SR35[7] FP VSync polarity */
4254 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4255 /* SR30[5] FP HSync polarity */
4256 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004257
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004258 if (chip_id == XG27)
4259 XGI_SetXG27FPBits(pVBInfo);
4260 else
4261 XGI_SetXG21FPBits(pVBInfo);
4262
Aaro Koskinenb3979922012-11-04 21:14:52 +02004263 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004264 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4265 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004266 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004267 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004268
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304269 if (!(modeflag & Charx8Dot))
4270 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004271
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004272 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004273
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004274 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004275
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304276 if (LVDSHBS > LVDSHT)
4277 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004278
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004279 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304280 if (LVDSHRS > LVDSHT)
4281 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004282
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004283 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304284 if (LVDSHRE > LVDSHT)
4285 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004286
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004287 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004288
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004289 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004290
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004291 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004292 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304293 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004294
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304295 if (LVDSVBS > LVDSVT)
4296 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004297
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004298 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304299 if (LVDSVRS > LVDSVT)
4300 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004301
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004302 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304303 if (LVDSVRE > LVDSVT)
4304 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004305
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004306 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004307
Peter Huewe9388ad92013-02-15 20:37:10 +01004308 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004309 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004310
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304311 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004312 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004313
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304314 /* HT SR0B[1:0] CR00 */
4315 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004316 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004317 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004318
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304319 /* HBS SR0B[5:4] CR02 */
4320 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004321 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004322 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004323
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304324 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4325 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004326 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4327 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4328 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004329
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304330 /* HRS SR0B[7:6] CR04 */
4331 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004332 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004333 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004334
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304335 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4336 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004337 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004338 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004339
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304340 /* HRE SR0C[2] CR05[4:0] */
4341 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004342 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4343 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004344
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304345 /* Panel HRE SR2F[7:2] */
4346 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004347 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004348
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304349 /* VT SR0A[0] CR07[5][0] CR06 */
4350 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004351 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4352 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4353 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004354 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004355
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304356 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4357 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004358 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4359 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4360 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004361 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004362
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304363 /* VBE SR0A[4] CR16 */
4364 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004365 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004366 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304368 /* VRS SR0A[3] CR7[7][2] CR10 */
4369 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004370 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4371 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4372 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004373 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004374
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004375 if (chip_id == XG27) {
4376 /* Panel VRS SR35[2:0] SR34[7:0] */
4377 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4378 (value & 0x700) >> 8);
4379 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4380 } else {
4381 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4382 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4383 (value & 0x600) >> 9);
4384 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4385 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4386 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004387
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304388 /* VRE SR0A[5] CR11[3:0] */
4389 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004390 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4391 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304393 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004394 if (chip_id == XG27)
4395 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4396 (value << 2) & 0xFC);
4397 else
4398 /* SR3F[7] has to be 0, h/w bug */
4399 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4400 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004401
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304402 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004403
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004404 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004405 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004406 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004407 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004408 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304409 value += 0x10;
4410 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004411
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304412 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004413 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004414 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004415 /* set data, panning = 0, shift left 1 dot*/
4416 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004417
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004418 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004419 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304420
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004421 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304422 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004423
4424}
4425
4426/* --------------------------------------------------------------------- */
4427/* Function : XGI_IsLCDON */
4428/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004429/* Output : 0 : Skip PSC Control */
4430/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004431/* Description : */
4432/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004433static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004434{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304435 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004436
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304437 tempax = pVBInfo->VBInfo;
4438 if (tempax & SetCRT2ToDualEdge)
4439 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004440 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304441 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004442
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304443 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004444}
4445
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004446static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4447 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304448 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004449{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004450 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004451
Peter Huewe6896b942012-02-09 21:11:46 +01004452 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4453 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304454 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004455 if (!(pVBInfo->VBInfo &
4456 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004457 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004458 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304459 tempah = 0x7F; /* Disable Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304460 }
4461 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004462
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004463 /* disable part4_1f */
4464 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004465
Peter Huewe6896b942012-02-09 21:11:46 +01004466 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004467 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004468 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
Peter Huewe06cc47b2013-02-03 22:54:38 +01004469 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004470 /* LVDS Driver power down */
4471 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304472 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004473
Aaro Koskinend1724632013-05-29 23:59:09 +03004474 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA |
4475 SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004476 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004477
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004478 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4479 /* Power down */
4480 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004481
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004482 /* disable TV as primary VGA swap */
4483 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004484
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304485 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004486 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004487
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004488 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004489 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004490 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004491 (pVBInfo->VBInfo &
4492 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004493 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004494
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004495 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004496 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004497 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004498 (pVBInfo->VBInfo &
4499 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4500 /* save Part1 index 0 */
4501 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4502 /* BTDAC = 1, avoid VB reset */
4503 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4504 /* disable CRT2 */
4505 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4506 /* restore Part1 index 0 */
4507 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304508 }
4509 } else { /* {301} */
4510 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004511 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4512 /* Disable CRT2 */
4513 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4514 /* Disable TV asPrimary VGA swap */
4515 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304516 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004517
Peter Huewea3d675c2012-02-09 21:11:47 +01004518 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304519 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004520 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304521 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004522}
4523
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004524/* --------------------------------------------------------------------- */
4525/* Function : XGI_GetTVPtrIndex */
4526/* Input : */
4527/* Output : */
4528/* Description : bx 0 : ExtNTSC */
4529/* 1 : StNTSC */
4530/* 2 : ExtPAL */
4531/* 3 : StPAL */
4532/* 4 : ExtHiTV */
4533/* 5 : StHiTV */
4534/* 6 : Ext525i */
4535/* 7 : St525i */
4536/* 8 : Ext525p */
4537/* 9 : St525p */
4538/* A : Ext750p */
4539/* B : St750p */
4540/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004541static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004542{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304543 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004544
Peter Huewe599801f2012-02-09 21:11:45 +01004545 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304546 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004547 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304548 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004549 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304550 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004551 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304552 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004553 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304554 tempbx = 10;
4555 if (pVBInfo->TVInfo & TVSimuMode)
4556 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004557
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304558 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004559}
4560
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004561/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004562/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004563/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004564/* Output : bx 0 : NTSC */
4565/* 1 : PAL */
4566/* 2 : PALM */
4567/* 3 : PALN */
4568/* 4 : NTSC1024x768 */
4569/* 5 : PAL-M 1024x768 */
4570/* 6-7: reserved */
4571/* cl 0 : YFilter1 */
4572/* 1 : YFilter2 */
4573/* ch 0 : 301A */
4574/* 1 : 301B/302B/301LV/302LV */
4575/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004576/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004577static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4578 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004579{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004580 *tempbx = 0;
4581 *tempcl = 0;
4582 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004583
Peter Huewe599801f2012-02-09 21:11:45 +01004584 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004585 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004586
Peter Huewe599801f2012-02-09 21:11:45 +01004587 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004588 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004589
Peter Huewe599801f2012-02-09 21:11:45 +01004590 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004591 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004592
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004593 if (pVBInfo->TVInfo & NTSC1024x768) {
4594 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004595 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004596 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304597 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004598
Peter Huewe6896b942012-02-09 21:11:46 +01004599 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4600 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004601 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4602 & TVSimuMode)) {
4603 *tempbx += 8;
4604 *tempcl += 1;
4605 }
4606 }
4607
Peter Huewe6896b942012-02-09 21:11:46 +01004608 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4609 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004610 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004611}
4612
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004613static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004614{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304615 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004616
Peter Huewe6896b942012-02-09 21:11:46 +01004617 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4618 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004619 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304620 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304621 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004622 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004623
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304624 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Aya Mahfouz46283372015-02-26 11:27:44 +02004625 tempbl >>= 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004626 if (pVBInfo->VBInfo &
4627 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004628 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004629
Peter Huewea3d675c2012-02-09 21:11:47 +01004630 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304631 tempbl = tempbh;
4632 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004633
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304634 tempbl &= 0x0F;
4635 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004636 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304638 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4639 | SetCRT2ToTV)) { /* Channel B */
4640 tempah &= 0xF0;
4641 tempah |= tempbl;
4642 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004643
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004644 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4645 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304646 tempah &= 0x0F;
4647 tempah |= tempbh;
4648 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004649 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304650 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304651 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004652}
4653
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004654static void XGI_SetLCDCap_A(unsigned short tempcx,
4655 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004656{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304657 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004658
Aaro Koskinen58839b02011-03-13 12:26:23 +02004659 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004660
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304661 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004662 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004663 /* Enable Dither */
4664 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004665 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304666 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004667 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304668 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004669 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304670 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004671}
4672
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004673/* --------------------------------------------------------------------- */
4674/* Function : XGI_SetLCDCap_B */
4675/* Input : cx -> LCD Capability */
4676/* Output : */
4677/* Description : */
4678/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004679static void XGI_SetLCDCap_B(unsigned short tempcx,
4680 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004681{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304682 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004683 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304684 (unsigned short) (((tempcx & 0x00ff) >> 6)
4685 | 0x0c));
4686 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004687 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304688 (unsigned short) (((tempcx & 0x00ff) >> 6)
4689 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004690}
4691
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004692static void XGI_LongWait(struct vb_device_info *pVBInfo)
4693{
4694 unsigned short i;
4695
4696 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4697
4698 if (!(i & 0xC0)) {
4699 for (i = 0; i < 0xFFFF; i++) {
4700 if (!(inb(pVBInfo->P3da) & 0x08))
4701 break;
4702 }
4703
4704 for (i = 0; i < 0xFFFF; i++) {
4705 if ((inb(pVBInfo->P3da) & 0x08))
4706 break;
4707 }
4708 }
4709}
4710
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004711static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004712{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304713 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004714
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304715 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004716
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004717 /* disable down spectrum D[4] */
4718 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304719 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004720 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304721 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004722
Aaro Koskinen8104e322011-03-13 12:26:22 +02004723 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304724 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004725 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304726 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004727 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304728 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004729 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304730 pVBInfo->LCDCapList[index].Spectrum_34);
4731 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004732 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004733}
4734
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004735static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4736{
4737 unsigned short tempcx;
4738
4739 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4740
Peter Huewef951dd02013-02-05 00:29:47 +01004741 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4742 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004743 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004744 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004745 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004746 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004747 (unsigned char) (tempcx & 0x1F));
4748 }
4749 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004750 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004751 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4752 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4753 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004754
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004755 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4756 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004757 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004758 XGI_SetLCDCap_A(tempcx, pVBInfo);
4759
Peter Huewe6896b942012-02-09 21:11:46 +01004760 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004761 if (tempcx & EnableSpectrum)
4762 SetSpectrum(pVBInfo);
4763 }
4764 } else {
4765 /* LVDS,CH7017 */
4766 XGI_SetLCDCap_A(tempcx, pVBInfo);
4767 }
4768}
4769
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004770/* --------------------------------------------------------------------- */
4771/* Function : XGI_SetAntiFlicker */
4772/* Input : */
4773/* Output : */
4774/* Description : Set TV Customized Param. */
4775/* --------------------------------------------------------------------- */
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004776static void XGI_SetAntiFlicker(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004777{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004778 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004779
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304780 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004781
Peter Huewe599801f2012-02-09 21:11:45 +01004782 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304783 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004784
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304785 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4786 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304787 tempah = TVAntiFlickList[tempbx];
Aya Mahfouz46283372015-02-26 11:27:44 +02004788 tempah <<= 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004789
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004790 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004791}
4792
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004793static void XGI_SetEdgeEnhance(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004794{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03004795 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304797 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004798
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304799 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4800 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304801 tempah = TVEdgeList[tempbx];
Aya Mahfouz46283372015-02-26 11:27:44 +02004802 tempah <<= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004803
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004804 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004805}
4806
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004807static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004808{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304809 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004810
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304811 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004812
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304813 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004814
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304815 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4816 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004817
Aaro Koskinen8104e322011-03-13 12:26:22 +02004818 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304819 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004820 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304821 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004822 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304823 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004824 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304825 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004826}
4827
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004828static void XGI_SetYFilter(unsigned short ModeIdIndex,
4829 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004830{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304831 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02004832 unsigned char const *filterPtr;
4833 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004834
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304835 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004836
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304837 switch (tempbx) {
4838 case 0x00:
4839 case 0x04:
4840 filterPtr = NTSCYFilter1;
4841 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004842
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304843 case 0x01:
4844 filterPtr = PALYFilter1;
4845 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304847 case 0x02:
4848 case 0x05:
4849 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304850 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03004851 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304852 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304854 case 0x08:
4855 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304856 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304857 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304858 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03004859 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304860 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004861
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304862 default:
4863 return;
4864 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004865
Aaro Koskinenb3979922012-11-04 21:14:52 +02004866 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304867 if (tempcl == 0)
4868 index = tempal * 4;
4869 else
4870 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304872 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004873 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
4874 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
4875 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
4876 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304877 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004878 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
4879 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
4880 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
4881 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304882 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004883
Peter Huewe6896b942012-02-09 21:11:46 +01004884 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4885 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004886 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
4887 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
4888 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304889 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004890}
4891
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004892/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004893/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004894/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004895/* Output : */
4896/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004897/* --------------------------------------------------------------------- */
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004898static void XGI_OEM310Setting(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004899 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004900{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004901 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004902
Peter Huewea3d675c2012-02-09 21:11:47 +01004903 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004904 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004905
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004906 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004907 XGI_SetPhaseIncr(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004908 XGI_SetYFilter(ModeIdIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004909 XGI_SetAntiFlicker(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004910
Peter Huewe6896b942012-02-09 21:11:46 +01004911 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004912 XGI_SetEdgeEnhance(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304913 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004914}
4915
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004916/* --------------------------------------------------------------------- */
4917/* Function : XGI_SetCRT2ModeRegs */
4918/* Input : */
4919/* Output : */
4920/* Description : Origin code for crt2group */
4921/* --------------------------------------------------------------------- */
Aaro Koskinenb053af12013-07-16 23:13:28 +03004922static void XGI_SetCRT2ModeRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004923{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304924 unsigned short tempbl;
4925 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004926
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304927 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304929 tempah = 0;
4930 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02004931 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304932 tempah &= ~0x10; /* BTRAMDAC */
4933 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004934
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304935 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
4936 | SetCRT2ToLCD)) {
4937 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004938 tempcl = pVBInfo->ModeType;
4939 tempcl -= ModeVGA;
4940 if (tempcl >= 0) {
4941 /* BT Color */
4942 tempah = (0x008 >> tempcl);
4943 if (tempah == 0)
4944 tempah = 1;
4945 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304946 }
4947 if (pVBInfo->VBInfo & SetInSlaveMode)
4948 tempah ^= 0x50; /* BTDAC */
4949 }
4950 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004951
Aaro Koskinen8104e322011-03-13 12:26:22 +02004952 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304953 tempah = 0x08;
4954 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004955
Miguel Gómeze123e462012-07-06 12:40:52 +02004956 if (pVBInfo->VBInfo & DisableCRT2Display)
4957 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004958
Miguel Gómeze123e462012-07-06 12:40:52 +02004959 tempah = 0x00;
4960 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004961
Miguel Gómeze123e462012-07-06 12:40:52 +02004962 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
4963 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4964 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004965
Miguel Gómeze123e462012-07-06 12:40:52 +02004966 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
4967 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
4968 tempbl &= 0xf7;
4969 tempah |= 0x01;
4970 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304971 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004972
Miguel Gómeze123e462012-07-06 12:40:52 +02004973 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4974 tempbl &= 0xf7;
4975 tempah |= 0x01;
4976 }
4977
4978 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
4979 goto reg_and_or;
4980
4981 tempbl &= 0xf8;
4982 tempah = 0x01;
4983
4984 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4985 tempah |= 0x02;
4986
4987 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
4988 tempah = tempah ^ 0x05;
4989 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4990 tempah = tempah ^ 0x01;
4991 }
4992
4993 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
4994 tempah |= 0x08;
4995
4996reg_and_or:
4997 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
4998
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304999 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005000 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305001 tempah &= (~0x08);
5002 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5003 & SetInSlaveMode))) {
5004 tempah |= 0x010;
5005 }
5006 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005007
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305008 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305009 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005010 if (pVBInfo->VBInfo & DriverMode)
5011 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305012 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005013
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005014 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305015 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305017 if (pVBInfo->LCDInfo & SetLCDDualLink)
5018 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005019
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305020 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305021 if (pVBInfo->TVInfo & RPLLDIV2XO)
5022 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305023 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005024
Peter Huewe255aabd2012-02-09 21:11:44 +01005025 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5026 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305027 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005028
Peter Huewe255aabd2012-02-09 21:11:44 +01005029 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305030 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005031
Aaro Koskinen8104e322011-03-13 12:26:22 +02005032 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305033 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005034
Peter Huewe6896b942012-02-09 21:11:46 +01005035 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5036 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305037 tempah = 0;
5038 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305040 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5041 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005042 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305043 tempah |= 0x04; /* shampoo 0129 */
5044 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005045
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005046 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305047 tempah = 0x00;
5048 tempbl = 0xcf;
5049 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5050 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5051 tempah |= 0x30;
5052 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005053
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005054 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305055 tempah = 0;
5056 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005057
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305058 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5059 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5060 tempah |= 0xc0;
5061 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005062 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305063 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005064
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305065 tempah = 0;
5066 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005067 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305068 tempbl = 0xff;
5069 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5070 tempah |= 0x80;
5071 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005072
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005073 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005074
Peter Huewe6896b942012-02-09 21:11:46 +01005075 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305076 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005077 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5078 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305079 }
5080 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005081}
5082
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005083
Aaro Koskinenb053af12013-07-16 23:13:28 +03005084void XGI_UnLockCRT2(struct vb_device_info *pVBInfo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305085{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005086 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005087}
5088
Aaro Koskinenb053af12013-07-16 23:13:28 +03005089void XGI_LockCRT2(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005090{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005091 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005092}
5093
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005094unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5095 unsigned short ModeNo, unsigned short ModeIdIndex,
5096 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005097{
Peter Huewef2c22602013-02-03 22:54:30 +01005098 const u8 LCDARefreshIndex[] = {
5099 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005100
Peter Hueweef9a6b92013-02-03 04:08:43 +01005101 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005102
Aaro Koskinen58839b02011-03-13 12:26:23 +02005103 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aya Mahfouz46283372015-02-26 11:27:44 +02005104 index >>= pVBInfo->SelectCRT2Rate;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005105 index &= 0x0F;
5106
5107 if (pVBInfo->LCDInfo & LCDNonExpanding)
5108 index = 0;
5109
5110 if (index > 0)
5111 index--;
5112
5113 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005114 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005115 temp = LCDARefreshIndex[pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005116
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005117 if (index > temp)
5118 index = temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005119 }
5120 }
5121
Aaro Koskinenb3979922012-11-04 21:14:52 +02005122 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005123 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005124 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005125 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5126 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005127 index++;
5128 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005129 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005130 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5131 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005132 index++;
5133 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005134 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5135 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005136 index++;
5137 }
5138 }
5139
5140 i = 0;
5141 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005142 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005143 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005144 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005145 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005146 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005147 if (temp < pVBInfo->ModeType)
5148 break;
5149 i++;
5150 index--;
5151
5152 } while (index != 0xFFFF);
5153 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5154 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005155 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005156 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005157 if (temp & InterlaceMode)
5158 i++;
5159 }
5160 }
5161 i--;
5162 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005163 temp = XGI_AjustCRT2Rate(ModeIdIndex, RefreshRateTableIndex,
5164 &i, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005165 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005166 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005167}
5168
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005169static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305170 struct xgi_hw_device_info *HwDeviceExtension,
5171 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005172{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005173 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005174
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005175 pVBInfo->SetFlag |= ProgrammingCRT2;
5176 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5177 ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005178 XGI_GetLVDSResInfo(ModeIdIndex, pVBInfo);
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03005179 XGI_GetLVDSData(ModeIdIndex, pVBInfo);
5180 XGI_ModCRT1Regs(ModeIdIndex, HwDeviceExtension, pVBInfo);
5181 XGI_SetLVDSRegs(ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005182 XGI_SetCRT2ECLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005183}
5184
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005185static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005186 struct xgi_hw_device_info *HwDeviceExtension,
5187 struct vb_device_info *pVBInfo)
5188{
Peter Huewea9e29e62013-02-03 04:08:44 +01005189 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005190
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005191 pVBInfo->SetFlag |= ProgrammingCRT2;
Aaro Koskinen334ab072013-07-16 23:13:30 +03005192 XGI_SearchModeID(ModeNo, &ModeIdIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005193 pVBInfo->SelectCRT2Rate = 4;
5194 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5195 ModeIdIndex, pVBInfo);
5196 XGI_SaveCRT2Info(ModeNo, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005197 XGI_GetCRT2ResInfo(ModeIdIndex, pVBInfo);
5198 XGI_GetCRT2Data(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005199 XGI_PreSetGroup1(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5200 XGI_SetGroup1(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03005201 XGI_SetLockRegs(ModeNo, ModeIdIndex, pVBInfo);
5202 XGI_SetGroup2(ModeNo, ModeIdIndex, pVBInfo);
5203 XGI_SetLCDRegs(ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005204 XGI_SetTap4Regs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005205 XGI_SetGroup3(ModeIdIndex, pVBInfo);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005206 XGI_SetGroup4(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005207 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005208 XGI_SetGroup5(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005209 XGI_AutoThreshold(pVBInfo);
5210 return 1;
5211}
5212
5213void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5214{
5215 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5216 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5217 0x05, 0x00 };
5218
5219 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5220
5221 unsigned char CR17, CR63, SR31;
5222 unsigned short temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005223
5224 int i;
Vitor Braga694683f2014-03-30 00:44:59 -03005225
Aaro Koskinen8104e322011-03-13 12:26:22 +02005226 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005227
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005228 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005229 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005230 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005231 pVBInfo->P3d4, 0x53) | 0x02));
5232
Peter Huewe9388ad92013-02-15 20:37:10 +01005233 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5234 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5235 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005236
Aaro Koskinen8104e322011-03-13 12:26:22 +02005237 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5238 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005239
Peter Huewe9388ad92013-02-15 20:37:10 +01005240 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005241 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005242
Peter Huewe9388ad92013-02-15 20:37:10 +01005243 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005244 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005245
Peter Huewe9388ad92013-02-15 20:37:10 +01005246 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005247 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005248 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005249 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005250
Aaro Koskinen8104e322011-03-13 12:26:22 +02005251 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005252
5253 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005254 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005255
5256 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005257 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005258 CRTCData[i]);
5259
5260 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005261 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005262 CRTCData[i]);
5263
5264 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005265 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005266 CRTCData[i]);
5267
Aaro Koskinen8104e322011-03-13 12:26:22 +02005268 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005269 & 0xE0));
5270
Aaro Koskinen8104e322011-03-13 12:26:22 +02005271 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5272 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5273 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005274
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005275 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005276
Ebru Akagunduzf88d8182013-10-07 22:25:28 +03005277 for (i = 0; i < 256 * 3; i++)
Peter Huewe771f3ee2013-02-15 20:37:13 +01005278 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005279
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005280 mdelay(1);
5281
5282 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005283 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005284
5285 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005286 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005287 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005288 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005289
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005290 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005291 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005292
Ebru Akagunduzf88d8182013-10-07 22:25:28 +03005293 for (i = 0; i < 256 * 3; i++)
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005294 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005295
Aaro Koskinen8104e322011-03-13 12:26:22 +02005296 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5297 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5298 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005299
Peter Huewe9388ad92013-02-15 20:37:10 +01005300 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005301 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005302 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005303}
5304
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005305static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5306 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005307 struct vb_device_info *pVBInfo)
5308{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005309 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005310
Peter Huewe6896b942012-02-09 21:11:46 +01005311 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5312 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinena2526d12013-05-29 23:59:10 +03005313 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Aaro Koskinend1724632013-05-29 23:59:09 +03005314 /* Power on */
5315 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005316
Aaro Koskinenb8e34b32013-05-29 23:59:08 +03005317 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
5318 SetCRT2ToRAMDAC)) {
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005319 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5320 tempah &= 0xDF;
5321 if (pVBInfo->VBInfo & SetInSlaveMode) {
5322 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
5323 tempah |= 0x20;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005324 }
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005325 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5326 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5327
5328 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5329
5330 if (!(tempah & 0x80))
5331 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5332 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005333 }
5334
Aaro Koskinena2526d12013-05-29 23:59:10 +03005335 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005336 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005337 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005338 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen056b5402013-05-29 23:59:11 +03005339 if (pVBInfo->VBInfo &
5340 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
5341 /* LVDS PLL power on */
5342 xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
5343 0x7F);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005344 /* LVDS Driver power on */
5345 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005346 }
5347 }
5348
5349 tempah = 0x00;
5350
5351 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5352 tempah = 0xc0;
5353
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005354 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5355 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5356 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5357 tempah = tempah & 0x40;
5358 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5359 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005360 }
5361 }
5362
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005363 /* EnablePart4_1F */
5364 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005365
Aaro Koskinenb053af12013-07-16 23:13:28 +03005366 XGI_DisableGatingCRT(pVBInfo);
Aaro Koskinend1724632013-05-29 23:59:09 +03005367 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005368 } /* 301 */
5369 else { /* LVDS */
5370 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005371 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005372 /* enable CRT2 */
5373 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005374
Peter Huewe9388ad92013-02-15 20:37:10 +01005375 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005376 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005377 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005378
Aaro Koskinendc505562011-03-13 12:26:26 +02005379 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005380 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005381 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005382}
5383
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005384static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5385 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005386 unsigned short ModeNo, unsigned short ModeIdIndex,
5387 struct vb_device_info *pVBInfo)
5388{
Aaro Koskinena1579612012-04-07 01:14:05 +03005389 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005390
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005391 XGI_SetSeqRegs(pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005392 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005393 XGI_SetCRTCRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005394 XGI_SetATTRegs(ModeIdIndex, pVBInfo);
Aaro Koskinena1579612012-04-07 01:14:05 +03005395 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005396 XGI_ClearExt1Regs(pVBInfo);
5397
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005398 if (HwDeviceExtension->jChipType == XG27) {
5399 if (pVBInfo->IF_DEF_LVDS == 0)
5400 XGI_SetDefaultVCLK(pVBInfo);
5401 }
5402
5403 temp = ~ProgrammingCRT2;
5404 pVBInfo->SetFlag &= temp;
5405 pVBInfo->SelectCRT2Rate = 0;
5406
Peter Huewe6896b942012-02-09 21:11:46 +01005407 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5408 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005409 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005410 | SetInSlaveMode)) {
5411 pVBInfo->SetFlag |= ProgrammingCRT2;
5412 }
5413 }
5414
5415 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5416 ModeIdIndex, pVBInfo);
5417 if (RefreshRateTableIndex != 0xFFFF) {
5418 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005419 XGI_SetCRT1CRTC(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005420 pVBInfo, HwDeviceExtension);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005421 XGI_SetCRT1DE(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005422 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5423 HwDeviceExtension, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005424 XGI_SetCRT1VCLK(ModeIdIndex, HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005425 RefreshRateTableIndex, pVBInfo);
5426 }
5427
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005428 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005429 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005430 if (temp & 0xA0) {
5431
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005432 if (HwDeviceExtension->jChipType == XG27)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005433 XGI_SetXG27CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005434 else
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005435 XGI_SetXG21CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005436
5437 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5438 RefreshRateTableIndex);
5439
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005440 xgifb_set_lcd(HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005441 pVBInfo, RefreshRateTableIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005442
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005443 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005444 xgifb_set_lvds(xgifb_info,
5445 HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005446 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005447 }
5448 }
5449
5450 pVBInfo->SetFlag &= (~ProgrammingCRT2);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005451 XGI_SetCRT1FIFO(HwDeviceExtension, pVBInfo);
5452 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeIdIndex,
5453 RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005454 XGI_LoadDAC(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005455}
5456
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005457unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5458 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005459 unsigned short ModeNo)
5460{
5461 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005462 struct vb_device_info VBINF;
5463 struct vb_device_info *pVBInfo = &VBINF;
Chaitanya Hazarey0292bd42014-05-23 12:24:37 -07005464
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005465 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005466
Aaro Koskinenee768752013-05-29 23:59:16 +03005467 if (HwDeviceExtension->jChipType >= XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005468 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005469
Aaro Koskinen56810a92013-01-21 02:57:47 +02005470 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005471
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005472 /* for x86 Linux, XG21 LVDS */
5473 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005474 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005475 pVBInfo->IF_DEF_LVDS = 1;
5476 }
5477 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005478 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5479 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005480 pVBInfo->IF_DEF_LVDS = 1;
5481 }
5482 }
5483
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005484 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005485 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005486 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005487 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005488
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005489 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005490 XGI_UnLockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005491
Aaro Koskinen334ab072013-07-16 23:13:30 +03005492 XGI_SearchModeID(ModeNo, &ModeIdIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005493
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005494 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinenb053af12013-07-16 23:13:28 +03005495 XGI_GetVBInfo(ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005496 XGI_GetTVInfo(ModeIdIndex, pVBInfo);
5497 XGI_GetLCDInfo(ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005498 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005499
Peter Huewee44adfd2013-02-03 22:54:39 +01005500 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5501 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005502 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005503 ModeIdIndex, pVBInfo);
5504
Peter Huewea3d675c2012-02-09 21:11:47 +01005505 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005506 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5507 HwDeviceExtension, pVBInfo);
5508 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005509 }
5510
Peter Huewe6896b942012-02-09 21:11:46 +01005511 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005512 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005513 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005514 case VB_CHIP_302:
5515 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5516 pVBInfo); /*add for CRT2 */
5517 break;
5518
5519 default:
5520 break;
5521 }
5522 }
5523
Aaro Koskinenb053af12013-07-16 23:13:28 +03005524 XGI_SetCRT2ModeRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005525 XGI_OEM310Setting(ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005526 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005527 } /* !XG20 */
5528 else {
5529 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005530 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Aaro Koskinen334ab072013-07-16 23:13:30 +03005531 ModeIdIndex))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005532 return 0;
5533
Aaro Koskinenb3979922012-11-04 21:14:52 +02005534 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005535 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005536
5537 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005538 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005539
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005540 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005541
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005542 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5543 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005544
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005545 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005546 }
5547
Aaro Koskinenb053af12013-07-16 23:13:28 +03005548 XGI_UpdateModeInfo(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005549
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005550 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005551 XGI_LockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005552
5553 return 1;
5554}