blob: 400c726753fa48170e8a0187568d7025daed2092 [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;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030052 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053053 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020054 pVBInfo->XGINew_CR97 = 0xc1;
Aaro Koskinen597d96b2013-03-27 23:53:15 +020055 pVBInfo->SR18 = XG27_SR18;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020056
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040057 /*Z11m DDR*/
58 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
59 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
60 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020061 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053062 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020063
64}
65
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +030066static void XGI_SetSeqRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020067{
Peter Huewe76a58992013-02-03 22:54:34 +010068 unsigned char SRdata, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020069
Aaro Koskinen8104e322011-03-13 12:26:22 +020070 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020071
Peter Huewe76a58992013-02-03 22:54:34 +010072 for (i = 0; i < 4; i++) {
73 /* Get SR1,2,3,4 from file */
74 /* SR1 is with screen off 0x20 */
75 SRdata = XGI330_StandTable.SR[i];
76 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053077 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020078}
79
Aaro Koskinenb053af12013-07-16 23:13:28 +030080static void XGI_SetCRTCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020081{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053082 unsigned char CRTCdata;
83 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020084
Peter Huewe9388ad92013-02-15 20:37:10 +010085 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053086 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +020087 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053089 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080090 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020091 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +020092 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053093 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020094}
95
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +030096static void XGI_SetATTRegs(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080097 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020098{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053099 unsigned char ARdata;
100 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200101
Aaro Koskinenb3979922012-11-04 21:14:52 +0200102 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530104 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200105 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200106
107 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
108 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
109 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300110 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200111 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300112 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530113 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 }
115 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200116
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200117 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200118 outb(i, pVBInfo->P3c0); /* set index */
119 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530120 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200121
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200122 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200123 outb(0x14, pVBInfo->P3c0); /* set index */
124 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200125 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200126 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200127}
128
Aaro Koskinena1579612012-04-07 01:14:05 +0300129static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200130{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530131 unsigned char GRdata;
132 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200133
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530134 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800135 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200136 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200137 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530138 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530140 if (pVBInfo->ModeType > ModeVGA) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100141 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530142 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200143 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530144 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200145}
146
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200147static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200148{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530149 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530151 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200152 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200153}
154
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200155static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200156{
157
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200158 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200159 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
160 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200161
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200162 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200163 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
164 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200165
Aaro Koskinendc505562011-03-13 12:26:26 +0200166 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530167 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200168}
169
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300170static unsigned char XGI_AjustCRT2Rate(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530171 unsigned short RefreshRateTableIndex, unsigned short *i,
172 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200173{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530174 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200175
Aaro Koskinenb3979922012-11-04 21:14:52 +0200176 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
177 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200178 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530179 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200180
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300181 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
182 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200183
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300184 if (pVBInfo->VBType & VB_XGI301C)
185 tempax |= SupportCRT2in301C;
186 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200187
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300188 /* 301b */
189 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300190 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200191
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300192 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
193 pVBInfo->LCDResInfo != Panel_1280x960 &&
194 (pVBInfo->LCDInfo & LCDNonExpanding) &&
195 resinfo >= 9)
196 return 0;
197 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200198
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300199 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
200 tempax |= SupportHiVision;
201 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
202 ((resinfo == 4) ||
203 (resinfo == 3 && (pVBInfo->SetFlag & TVSimuMode)) ||
204 (resinfo > 7)))
205 return 0;
206 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO | SetCRT2ToSVIDEO |
207 SetCRT2ToSCART | SetCRT2ToYPbPr525750 |
208 SetCRT2ToHiVision)) {
209 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200210
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300211 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
212 VB_SIS302LV | VB_XGI301C))
213 tempax |= SupportTV1024;
214
215 if (!(pVBInfo->VBInfo & TVSetPAL) &&
216 (modeflag & NoSupportSimuTV) &&
217 (pVBInfo->VBInfo & SetInSlaveMode) &&
218 (!(pVBInfo->VBInfo & SetNotSimuMode)))
219 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530220 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200221
Aaro Koskinena39325d2012-11-04 21:14:53 +0200222 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800223 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200224 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800225 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530226 if (infoflag & tempax)
227 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530229 if ((*i) == 0)
230 break;
231 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530233 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200234 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800235 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200236 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530237 != tempbx) {
238 return 0;
239 }
240
241 if (infoflag & tempax)
242 return 1;
243 }
244 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200245}
246
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200247static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530248 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200249{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530250 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200251
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800252 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200253 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530254 sync &= 0xC0;
255 temp = 0x2F;
256 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200257 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200258}
259
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200260static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530261 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200262{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530263 unsigned char data, data1, pushax;
264 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200265
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800266 /* unlock cr0-7 */
Peter Huewe9388ad92013-02-15 20:37:10 +0100267 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530268 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200269 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200270
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200271 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200272 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530274 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200275 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200276 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530277 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200278
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530279 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200280 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200281 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530282 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200283
Peter Huewe9388ad92013-02-15 20:37:10 +0100284 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530285 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200286 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530287 data &= 0xE0;
288 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200289 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200290
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530291 if (HwDeviceExtension->jChipType >= XG20) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100292 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530293 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200294 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100295 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530296 data1 = data;
297 data1 &= 0xE0;
298 data &= 0x1F;
299 if (data == 0) {
300 pushax = data;
Peter Huewe9388ad92013-02-15 20:37:10 +0100301 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530302 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200303 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530304 data = pushax;
305 }
306 data = data - 1;
307 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200308 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100309 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530310 data = data >> 5;
311 data = data + 3;
312 if (data > 7)
313 data = data - 7;
314 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200315 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530316 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200317}
318
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800319static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800320 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200321{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530322 unsigned char data;
323 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200324
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530325 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200326 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200327 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530328 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200329
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530330 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200331 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200332 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530333 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200334
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530335 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200336 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200337 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530338 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200339
Peter Huewe9388ad92013-02-15 20:37:10 +0100340 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530341 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200342 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530343 data &= 0x3F;
344 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200345 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200346
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200347 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530348 data &= 0x80;
349 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200350
Aaro Koskinenb3979922012-11-04 21:14:52 +0200351 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530352 i &= DoubleScanMode;
353 if (i)
354 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200355
Peter Huewe9388ad92013-02-15 20:37:10 +0100356 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530357 j &= 0x5F;
358 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200359 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200360}
361
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300362static void XGI_SetCRT1CRTC(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200363 unsigned short RefreshRateTableIndex,
364 struct vb_device_info *pVBInfo,
365 struct xgi_hw_device_info *HwDeviceExtension)
366{
367 unsigned char index, data;
368 unsigned short i;
369
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800370 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200371 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200372 index = index & IndexMask;
373
Peter Huewe9388ad92013-02-15 20:37:10 +0100374 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200375 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200376 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200377
378 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200379 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200380 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200381
382 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200383 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200384 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200385
386 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
387
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300388 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200389
390 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200391 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200392}
393
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200394/* --------------------------------------------------------------------- */
395/* Function : XGI_SetXG21CRTC */
396/* Input : Stand or enhance CRTC table */
397/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
398/* Description : Set LCD timing */
399/* --------------------------------------------------------------------- */
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +0300400static void XGI_SetXG21CRTC(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530401 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200402{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300403 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530404 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200405
Aaro Koskinena39325d2012-11-04 21:14:53 +0200406 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300407 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200408 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300409 Tempcx = Tempax; /* Tempcx: HRS */
410 /* SR2E[7:0]->HRS */
411 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200412
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200413 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300414 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
415 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
416 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
417 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800418
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200419 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300420 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200421
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200422 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300423 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
424 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
425 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200426
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300427 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
428 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200429
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300430 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
431 if (Tempax < Tempcx) /* HRE < HRS */
432 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200433
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300434 Temp2 &= 0xFF;
435 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
436 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
437 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
438 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
439 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
440 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
441 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200442
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300443 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200444 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300445 Tempbx = Tempax; /* Tempbx: VRS */
446 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
447 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
448 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200449 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300450 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
451 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
452 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
453 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
454 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200455
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300456 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
457 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
458 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
459 Tempax &= 0x80;
460 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
461 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
462 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200463 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300464 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
465 Temp2 = Tempax;
466 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
467 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200468
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300469 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200470 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300471 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
472 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200473 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300474 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
475 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
476 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
477 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
478 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200479
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300480 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
481 if (Tempax < Temp3) /* VRE < VRS */
482 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200483
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300484 Temp2 &= 0xFF;
485 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
486 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
487 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
488 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
489 Tempbx = (unsigned char) Temp1;
490 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
491 Tempax &= 0x7F;
492 /* SR3F D[7:2]->VRE D[1:0]->VRS */
493 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200494}
495
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +0300496static void XGI_SetXG27CRTC(unsigned short RefreshRateTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800497 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200498{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300499 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200500
Aaro Koskinena39325d2012-11-04 21:14:53 +0200501 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300502 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200503 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300504 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
505 /* SR2E[7:0]->HRS */
506 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200507
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300508 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200509 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300510 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
511 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200512
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200513 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300514 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
515 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200516
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200517 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300518 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
519 Tempax <<= 3; /* Tempax[5]: HRE[5] */
520 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200521
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300522 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
523 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200524
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300525 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200526 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300527 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
528 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
529 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200530
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200531 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300532 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
533 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
534 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
535 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
536 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
537 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200538
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300539 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200540 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300541 /* SR34[7:0]->VRS[7:0] */
542 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200543
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300544 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
545 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200546 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300547 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
548 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
549 Tempax >>= 2; /* Tempax[0]: VRS[8] */
550 /* SR35[0]: VRS[8] */
551 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
552 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
553 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
554 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200555 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300556 Tempax &= 0x08; /* SR0A[3] VRS[10] */
557 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200558
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300559 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200560 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300561 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
562 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200563 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300564 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
565 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
566 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
567 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
568 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
569 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200570
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300571 if (Tempbx <= Tempcx) /* VRE <= VRS */
572 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200573
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300574 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
575 Tempax = (Tempbx << 2) & 0xFF;
576 /* SR3F[7:2]:VRE[5:0] */
577 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
578 Tempax = Tempcx >> 8;
579 /* SR35[2:0]:VRS[10:8] */
580 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200581}
582
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200583static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
584{
585 unsigned char temp;
586
587 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
588 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
589 temp = (temp & 3) << 6;
590 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
591 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
592 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
593 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
594
595}
596
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300597static void xgifb_set_lcd(int chip_id,
598 struct vb_device_info *pVBInfo,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300599 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200600{
Peter Huewee2e544c2013-02-03 04:08:46 +0100601 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200602
Aaro Koskinen8104e322011-03-13 12:26:22 +0200603 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
604 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
605 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
606 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300607
608 if (chip_id == XG27) {
Peter Huewee2e544c2013-02-03 04:08:46 +0100609 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
610 if ((temp & 0x03) == 0) { /* dual 12 */
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300611 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
612 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
613 }
614 }
615
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300616 if (chip_id == XG27) {
617 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530618 } else {
Peter Huewee2e544c2013-02-03 04:08:46 +0100619 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
620 if (temp & 0x01) {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300621 /* 18 bits FP */
622 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
623 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
624 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530625 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200626
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200627 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200628
Aaro Koskinendc505562011-03-13 12:26:26 +0200629 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
630 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200631
Peter Huewee2e544c2013-02-03 04:08:46 +0100632 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
633 if (temp & 0x4000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300634 /* Hsync polarity */
635 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Peter Huewee2e544c2013-02-03 04:08:46 +0100636 if (temp & 0x8000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300637 /* Vsync polarity */
638 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200639}
640
641/* --------------------------------------------------------------------- */
642/* Function : XGI_UpdateXG21CRTC */
643/* Input : */
644/* Output : CRT1 CRTC */
645/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
646/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800647static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
648 struct vb_device_info *pVBInfo,
649 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200650{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300651 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200652
Aaro Koskinendc505562011-03-13 12:26:26 +0200653 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300654 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200655 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300656 RES640x480x60))
657 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200658 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800659 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300660 index = 13;
661 else if (ModeNo == 0x2F)
662 index = 14;
663 else if (ModeNo == 0x50)
664 index = 15;
665 else if (ModeNo == 0x59)
666 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200667
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530668 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200669 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200670 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200671 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200672 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200673 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200674 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200675 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200676 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530677 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200678}
679
Aaro Koskinenb053af12013-07-16 23:13:28 +0300680static void XGI_SetCRT1DE(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530681 unsigned short RefreshRateTableIndex,
682 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200683{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400684 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200685
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530686 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200687
Aaro Koskinenb3979922012-11-04 21:14:52 +0200688 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200689
Aaro Koskinenb3979922012-11-04 21:14:52 +0200690 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinene8e6c752012-11-04 21:15:00 +0200691 tempax = XGI330_ModeResInfo[resindex].HTotal;
692 tempbx = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200693
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530694 if (modeflag & HalfDCLK)
695 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200696
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300697 if (modeflag & HalfDCLK)
698 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200699
Aaro Koskinena39325d2012-11-04 21:14:53 +0200700 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200701
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300702 if (temp & InterlaceMode)
703 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200704
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300705 if (modeflag & DoubleScanMode)
706 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200707
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530708 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200709
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530710 tempax /= tempcx;
711 tempax -= 1;
712 tempbx -= 1;
713 tempcx = tempax;
Peter Huewe9388ad92013-02-15 20:37:10 +0100714 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
715 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530716 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200717 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
718 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200719 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530720 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200721 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530722 tempax = 0;
723 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200724
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530725 if (tempbx & 0x01)
726 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200727
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530728 if (tempbx & 0x02)
729 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200730
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200731 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Peter Huewe9388ad92013-02-15 20:37:10 +0100732 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530733 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200734
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530735 if (tempbx & 0x04)
736 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200737
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200738 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200739 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200740}
741
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800742static void XGI_SetCRT1Offset(unsigned short ModeNo,
743 unsigned short ModeIdIndex,
744 unsigned short RefreshRateTableIndex,
745 struct xgi_hw_device_info *HwDeviceExtension,
746 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200747{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530748 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200749
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530750 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200751 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530752 temp = temp >> 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200753 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200754
Aaro Koskinena39325d2012-11-04 21:14:53 +0200755 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530756 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200757
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530758 if (temp2)
759 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200760
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530761 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200762
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530763 switch (temp2) {
764 case 0:
765 temp2 = 1;
766 break;
767 case 1:
768 temp2 = 2;
769 break;
770 case 2:
771 temp2 = 4;
772 break;
773 case 3:
774 temp2 = 4;
775 break;
776 case 4:
777 temp2 = 6;
778 break;
779 case 5:
780 temp2 = 8;
781 break;
782 default:
783 break;
784 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530786 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
787 temp = temp * temp2 + temp2 / 2;
788 else
789 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200790
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530791 /* SetOffset */
792 DisplayUnit = temp;
793 temp2 = temp;
794 temp = temp >> 8; /* ah */
795 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200796 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530797 i &= 0xF0;
798 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200799 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530801 temp = (unsigned char) temp2;
802 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200803 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200804
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530805 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200806 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530807 temp2 &= InterlaceMode;
808 if (temp2)
809 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200810
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530811 DisplayUnit = DisplayUnit << 5;
812 ah = (DisplayUnit & 0xff00) >> 8;
813 al = DisplayUnit & 0x00ff;
814 if (al == 0)
815 ah += 1;
816 else
817 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200818
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530819 if (HwDeviceExtension->jChipType >= XG20)
820 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
821 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200822
Aaro Koskinen8104e322011-03-13 12:26:22 +0200823 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200824}
825
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300826static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200827 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200828 struct vb_device_info *pVBInfo)
829{
Peter Hueweef9a6b92013-02-03 04:08:43 +0100830 unsigned short VCLKIndex, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200831
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300832 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200833 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200834
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200835 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
836 if (pVBInfo->LCDResInfo != Panel_1024x768)
837 /* LCDXlat2VCLK */
838 VCLKIndex = VCLK108_2_315 + 5;
839 else
840 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
841 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
842 if (pVBInfo->SetFlag & RPLLDIV2XO)
843 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
844 else
845 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200846
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200847 if (pVBInfo->SetFlag & TVSimuMode) {
Ebru Akagunduz4759e822013-10-29 22:50:54 +0200848 if (modeflag & Charx8Dot)
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200849 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
Ebru Akagunduz4759e822013-10-29 22:50:54 +0200850 else
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200851 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200852 }
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200853
854 /* 301lv */
855 if (pVBInfo->VBType & VB_SIS301LV) {
856 if (pVBInfo->SetFlag & RPLLDIV2XO)
857 VCLKIndex = YPbPr525iVCLK_2;
858 else
859 VCLKIndex = YPbPr525iVCLK;
860 }
861 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
862 if (pVBInfo->SetFlag & RPLLDIV2XO)
863 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
864 else
865 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
866 } else { /* for CRT2 */
867 /* di+Ext_CRTVCLK */
868 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
869 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200870 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200871
872 return VCLKIndex;
873}
874
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300875static void XGI_SetCRT1VCLK(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800876 struct xgi_hw_device_info *HwDeviceExtension,
877 unsigned short RefreshRateTableIndex,
878 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200879{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400880 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530881 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200882
Aaro Koskinenb750f512013-05-29 23:59:05 +0300883 if ((pVBInfo->IF_DEF_LVDS == 0) &&
884 (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
885 VB_SIS302LV | VB_XGI301C)) &&
886 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300887 vclkindex = XGI_GetVCLK2Ptr(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinenb053af12013-07-16 23:13:28 +0300888 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200889 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200890 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200891 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200892 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200893 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200894 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
895 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530896 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200897 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200898 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200899 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200900 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
901 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200902 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530903 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200904
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530905 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200906 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800907 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200908 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200909 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200910 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530911 index = data;
912 index &= 0xE0;
913 data &= 0x1F;
914 data = data << 1;
915 data += 1;
916 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200917 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530918 }
919 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200920}
921
Aaro Koskinene85f2032011-11-27 23:03:07 +0200922static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
923{
924 unsigned char temp;
925
926 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
927 temp = (temp & 1) << 6;
928 /* SR06[6] 18bit Dither */
929 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
930 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
931 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
932
933}
934
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300935static void XGI_SetCRT1FIFO(struct xgi_hw_device_info *HwDeviceExtension,
936 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200937{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530938 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200939
Aaro Koskinen58839b02011-03-13 12:26:23 +0200940 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530941 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200942 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200943
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300944 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
945 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
946 data &= 0xC0;
947 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
948 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
949 data |= 0x01;
950 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200951
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530952 if (HwDeviceExtension->jChipType == XG21)
953 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200954}
955
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200956static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300957 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200958 struct vb_device_info *pVBInfo)
959{
960 unsigned short data, data2 = 0;
961 short VCLK;
962
963 unsigned char index;
964
Aaro Koskinena39325d2012-11-04 21:14:53 +0200965 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300966 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200967 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200968
Aaro Koskinen58839b02011-03-13 12:26:23 +0200969 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200970 data &= 0xf3;
971 if (VCLK >= 200)
972 data |= 0x0c; /* VCLK > 200 */
973
974 if (HwDeviceExtension->jChipType >= XG20)
975 data &= ~0x04; /* 2 pixel mode */
976
Aaro Koskinen8104e322011-03-13 12:26:22 +0200977 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200978
979 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200980 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200981 data &= 0xE7;
982 if (VCLK < 200)
983 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200984 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200985 }
986
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200987 data2 = 0x00;
988
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200989 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200990 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200991 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200992
993}
994
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200995static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300996 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530997 unsigned short RefreshRateTableIndex,
998 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200999{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301000 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1001 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001002
Aaro Koskinenb3979922012-11-04 21:14:52 +02001003 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001004 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001005
Aaro Koskinen58839b02011-03-13 12:26:23 +02001006 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001007 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001008
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001009 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301010 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001011 data2 |= 0x02;
1012 data3 = pVBInfo->ModeType - ModeVGA;
1013 data3 = data3 << 2;
1014 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301015 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301017 if (data)
1018 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001019
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001020 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001021 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001022 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301024 data = 0x0000;
1025 if (infoflag & InterlaceMode) {
1026 if (xres == 1024)
1027 data = 0x0035;
1028 else if (xres == 1280)
1029 data = 0x0048;
1030 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001031
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001032 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1033 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301035 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001036 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301038 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301040 if (modeflag & LineCompareOff)
1041 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001042
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001043 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301044 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001045 data = data ^ 0x60;
1046 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001047 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001048
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001049 XGI_SetVCLKState(HwDeviceExtension, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001050
Aaro Koskinen58839b02011-03-13 12:26:23 +02001051 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001052
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301053 if (HwDeviceExtension->jChipType == XG27) {
1054 if (data & 0x40)
1055 data = 0x2c;
1056 else
1057 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001058 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001059 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301060 } else if (HwDeviceExtension->jChipType >= XG20) {
1061 if (data & 0x40)
1062 data = 0x33;
1063 else
1064 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001065 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1066 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301067 } else {
1068 if (data & 0x40)
1069 data = 0x2c;
1070 else
1071 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001072 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301073 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001074
1075}
1076
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001077static void XGI_WriteDAC(unsigned short dl,
1078 unsigned short ah,
1079 unsigned short al,
1080 unsigned short dh,
1081 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001082{
1083 unsigned short temp, bh, bl;
1084
1085 bh = ah;
1086 bl = al;
1087
1088 if (dl != 0) {
1089 temp = bh;
1090 bh = dh;
1091 dh = temp;
1092 if (dl == 1) {
1093 temp = bl;
1094 bl = dh;
1095 dh = temp;
1096 } else {
1097 temp = bl;
1098 bl = bh;
1099 bh = temp;
1100 }
1101 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001102 outb((unsigned short) dh, pVBInfo->P3c9);
1103 outb((unsigned short) bh, pVBInfo->P3c9);
1104 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001105}
1106
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03001107static void XGI_LoadDAC(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001108{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001109 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1110 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001111
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001112 outb(0xFF, pVBInfo->P3c6);
1113 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001114
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001115 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301116 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301118 for (k = 0; k < 3; k++) {
1119 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301121 if (data & 0x01)
1122 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301124 if (data & 0x02)
1125 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001126
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001127 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301128 data = data >> 2;
1129 }
1130 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001131
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001132 for (i = 16; i < 32; i++) {
1133 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001134
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001135 for (k = 0; k < 3; k++)
1136 outb(data, pVBInfo->P3c9);
1137 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001138
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001139 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001140
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001141 for (m = 0; m < 9; m++) {
1142 di = si;
1143 bx = si + 0x04;
1144 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001145
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001146 for (n = 0; n < 3; n++) {
1147 for (o = 0; o < 5; o++) {
1148 dh = table[si];
1149 ah = table[di];
1150 al = table[bx];
1151 si++;
1152 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301153 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001154
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001155 si -= 2;
1156
1157 for (o = 0; o < 3; o++) {
1158 dh = table[bx];
1159 ah = table[di];
1160 al = table[si];
1161 si--;
1162 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1163 }
1164
1165 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301166 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001167
1168 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301169 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001170}
1171
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001172static void XGI_GetLVDSResInfo(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001173 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001174{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301175 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001176
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001177 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001178 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001179
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001180 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001181 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001182
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001183 xres = XGI330_ModeResInfo[resindex].HTotal;
1184 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001185
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001186 if (modeflag & HalfDCLK)
1187 xres = xres << 1;
1188
1189 if (modeflag & DoubleScanMode)
1190 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301192 if (xres == 720)
1193 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001194
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301195 pVBInfo->VGAHDE = xres;
1196 pVBInfo->HDE = xres;
1197 pVBInfo->VGAVDE = yres;
1198 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001199}
1200
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001201static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001202 unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001203 struct vb_device_info *pVBInfo)
1204{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001205 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001206
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001207 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001208
Aaro Koskinenb3979922012-11-04 21:14:52 +02001209 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001210
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001211 i = 0;
1212
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001213 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001214 tempdx = pVBInfo->LCDResInfo;
1215 if (tempbx & 0x0080) { /* OEMUtil */
1216 tempbx &= (~0x0080);
1217 tempdx = pVBInfo->LCDTypeInfo;
1218 }
1219
1220 if (pVBInfo->LCDInfo & EnableScalingLCD)
1221 tempdx &= (~PanelResInfo);
1222
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001223 if (table[i].PANELID == tempdx) {
1224 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001225 tempdx = pVBInfo->LCDInfo;
1226
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001227 if (modeflag & HalfDCLK)
1228 tempdx |= SetLCDLowResolution;
1229
1230 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001231 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001232 break;
1233 }
1234 i++;
1235 }
1236
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001237 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001238}
1239
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001240static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001241 unsigned short RefreshRateTableIndex,
1242 struct vb_device_info *pVBInfo)
1243{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001244 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001245
Aaro Koskinenb3979922012-11-04 21:14:52 +02001246 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001247 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001248 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001249 tempdx = pVBInfo->TVInfo;
1250
1251 if (pVBInfo->VBInfo & SetInSlaveMode)
1252 tempdx = tempdx | SetTVLockMode;
1253
1254 if (modeflag & HalfDCLK)
1255 tempdx = tempdx | SetTVLowResolution;
1256
1257 i = 0;
1258
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001259 while (XGI_TVDataTable[i].MASK != 0xffff) {
1260 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1261 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001262 break;
1263 i++;
1264 }
1265
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001266 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001267}
1268
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001269static void XGI_GetLVDSData(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001270 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001271{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001272 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001273
Aaro Koskinen6008f872012-11-04 21:14:49 +02001274 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1275 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001276
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001277 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeIdIndex, pVBInfo);
Aaro Koskinen6008f872012-11-04 21:14:49 +02001278 pVBInfo->VGAHT = LCDPtr->VGAHT;
1279 pVBInfo->VGAVT = LCDPtr->VGAVT;
1280 pVBInfo->HT = LCDPtr->LCDHT;
1281 pVBInfo->VT = LCDPtr->LCDVT;
1282
1283 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1284 return;
1285
1286 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1287 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1288 pVBInfo->HDE = 1024;
1289 pVBInfo->VDE = 768;
1290 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1291 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1292 pVBInfo->HDE = 1280;
1293 pVBInfo->VDE = 1024;
1294 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1295 pVBInfo->HDE = 1400;
1296 pVBInfo->VDE = 1050;
1297 } else {
1298 pVBInfo->HDE = 1600;
1299 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301300 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001301}
1302
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001303static void XGI_ModCRT1Regs(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001304 struct xgi_hw_device_info *HwDeviceExtension,
1305 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001306{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001307 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001308 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1309 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001310
Peter Huewea3d675c2012-02-09 21:11:47 +01001311 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001312 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001313 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001314
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001315 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001316 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301317 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001318
1319 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1320
Peter Huewea3d675c2012-02-09 21:11:47 +01001321 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001322 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001323 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001324 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001325 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001326 }
1327
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001328 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001329}
1330
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001331static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1332{
1333 unsigned char tempal, tempah, tempbl, i;
1334
Aaro Koskinen58839b02011-03-13 12:26:23 +02001335 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001336 tempal = tempah & 0x0F;
1337 tempah = tempah & 0xF0;
1338 i = 0;
1339 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1340
1341 while (tempbl != 0xFF) {
1342 if (tempbl & 0x80) { /* OEMUtil */
1343 tempal = tempah;
1344 tempbl = tempbl & ~(0x80);
1345 }
1346
1347 if (tempal == tempbl)
1348 break;
1349
1350 i++;
1351
1352 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1353 }
1354
1355 return i;
1356}
1357
1358static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1359{
1360 unsigned short tempah, tempal, tempbl, i;
1361
1362 tempal = pVBInfo->LCDResInfo;
1363 tempah = pVBInfo->LCDTypeInfo;
1364
1365 i = 0;
1366 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1367
1368 while (tempbl != 0xFF) {
1369 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1370 tempal = tempah;
1371 tempbl &= ~0x80;
1372 }
1373
1374 if (tempal == tempbl)
1375 break;
1376
1377 i++;
1378 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1379 }
1380
1381 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001382 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001383 pVBInfo->LCDTypeInfo = 0;
1384 i = 0;
1385 }
1386
1387 return i;
1388}
1389
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001390static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1391 unsigned short *VSyncWidth,
1392 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001393{
1394 unsigned short Index;
1395
1396 Index = XGI_GetLCDCapPtr(pVBInfo);
1397 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1398 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001399}
1400
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001401static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001402 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001403{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301404 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1405 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001406 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001407
Aaro Koskinenb3979922012-11-04 21:14:52 +02001408 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001409 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001410
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001411 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1412 push1 = tempbx;
1413 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001414
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001415 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001416 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1417 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001418 tempax = 1024;
1419 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001420 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1421 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001422 tempax = 1280;
1423 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001424 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001425 tempax = 1400;
1426 tempbx = 1050;
1427 } else {
1428 tempax = 1600;
1429 tempbx = 1200;
1430 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001431
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001432 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1433 pVBInfo->HDE = tempax;
1434 pVBInfo->VDE = tempbx;
1435 pVBInfo->VGAHDE = tempax;
1436 pVBInfo->VGAVDE = tempbx;
1437 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001438
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001439 tempax = pVBInfo->HT;
1440
Peter Huewe826215d2013-02-05 00:29:46 +01001441 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001442
1443 tempcx = pVBInfo->HDE;
1444 tempbx = tempbx & 0x0fff;
1445 tempcx += tempbx;
1446
1447 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001448 tempcx -= tempax;
1449
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001450 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001451
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001452 tempcx = tempcx >> 3;
1453 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001454
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001455 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1456 (unsigned short) (tempbx & 0xff));
1457 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1458 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001459
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001460 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001461
Peter Huewe826215d2013-02-05 00:29:46 +01001462 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001463
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001464 tempcx = push2;
1465
1466 if (pVBInfo->LCDInfo & EnableScalingLCD)
1467 tempcx = LCDPtr1->LCDHSync;
1468
1469 tempcx += tempbx;
1470
1471 if (tempcx >= tempax)
1472 tempcx -= tempax;
1473
1474 tempax = tempbx & 0x07;
1475 tempax = tempax >> 5;
1476 tempcx = tempcx >> 3;
1477 tempbx = tempbx >> 3;
1478
1479 tempcx &= 0x1f;
1480 tempax |= tempcx;
1481
1482 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1483 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1484 (unsigned short) (tempbx & 0xff));
1485
1486 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001487 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001488 tempcx = pVBInfo->VDE;
1489
1490 tempbx = tempbx & 0x0fff;
1491 tempcx += tempbx;
1492 if (tempcx >= tempax)
1493 tempcx -= tempax;
1494
1495 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1496 (unsigned short) (tempbx & 0xff));
1497 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1498 (unsigned short) (tempcx & 0xff));
1499
1500 tempbx = (tempbx >> 8) & 0x07;
1501 tempcx = (tempcx >> 8) & 0x07;
1502
1503 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1504 (unsigned short) ((tempcx << 3)
1505 | tempbx));
1506
1507 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001508 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001509
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001510 tempcx = push1;
1511
1512 if (pVBInfo->LCDInfo & EnableScalingLCD)
1513 tempcx = LCDPtr1->LCDVSync;
1514
1515 tempcx += tempbx;
1516 if (tempcx >= tempax)
1517 tempcx -= tempax;
1518
1519 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1520 (unsigned short) (tempbx & 0xff));
1521 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1522 (unsigned short) (tempcx & 0x0f));
1523
1524 tempax = ((tempbx >> 8) & 0x07) << 3;
1525
1526 tempbx = pVBInfo->VGAVDE;
1527 if (tempbx != pVBInfo->VDE)
1528 tempax |= 0x40;
1529
Peter Huewea3d675c2012-02-09 21:11:47 +01001530 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001531 tempax |= 0x40;
1532
1533 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1534 tempax);
1535
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001536 tempbx = pVBInfo->VDE;
1537 tempax = pVBInfo->VGAVDE;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001538
1539 temp = tempax; /* 0430 ylshieh */
1540 temp1 = (temp << 18) / tempbx;
1541
1542 tempdx = (unsigned short) ((temp << 18) % tempbx);
1543
1544 if (tempdx != 0)
1545 temp1 += 1;
1546
1547 temp2 = temp1;
1548 push3 = temp2;
1549
1550 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1551 (unsigned short) (temp2 & 0xff));
1552 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1553 (unsigned short) ((temp2 >> 8) & 0xff));
1554
1555 tempbx = (unsigned short) (temp2 >> 16);
1556 tempax = tempbx & 0x03;
1557
1558 tempbx = pVBInfo->VGAVDE;
1559 if (tempbx == pVBInfo->VDE)
1560 tempax |= 0x04;
1561
1562 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1563
1564 if (pVBInfo->VBType & VB_XGI301C) {
1565 temp2 = push3;
1566 xgifb_reg_set(pVBInfo->Part4Port,
1567 0x3c,
1568 (unsigned short) (temp2 & 0xff));
1569 xgifb_reg_set(pVBInfo->Part4Port,
1570 0x3b,
1571 (unsigned short) ((temp2 >> 8) &
1572 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001573 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001574 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1575 ~0xc0,
1576 (unsigned short) ((tempbx &
1577 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001578
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001579 tempcx = pVBInfo->VGAVDE;
1580 if (tempcx == pVBInfo->VDE)
1581 xgifb_reg_and_or(pVBInfo->Part4Port,
1582 0x30, ~0x0c, 0x00);
1583 else
1584 xgifb_reg_and_or(pVBInfo->Part4Port,
1585 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301586 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001587
1588 tempcx = pVBInfo->VGAHDE;
1589 tempbx = pVBInfo->HDE;
1590
1591 temp1 = tempcx << 16;
1592
1593 tempax = (unsigned short) (temp1 / tempbx);
1594
1595 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1596 tempax = 65535;
1597
1598 temp3 = tempax;
1599 temp1 = pVBInfo->VGAHDE << 16;
1600
1601 temp1 /= temp3;
1602 temp3 = temp3 << 16;
1603 temp1 -= 1;
1604
1605 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1606
1607 tempax = (unsigned short) (temp3 & 0xff);
1608 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1609
1610 temp1 = pVBInfo->VGAVDE << 18;
1611 temp1 = temp1 / push3;
1612 tempbx = (unsigned short) (temp1 & 0xffff);
1613
Peter Huewe255aabd2012-02-09 21:11:44 +01001614 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001615 tempbx -= 1;
1616
1617 tempax = ((tempbx >> 8) & 0xff) << 3;
1618 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1619 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1620 (unsigned short) (tempax & 0xff));
1621 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1622 (unsigned short) (tempbx & 0xff));
1623
1624 temp3 = temp3 >> 16;
1625
1626 if (modeflag & HalfDCLK)
1627 temp3 = temp3 >> 1;
1628
1629 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1630 (unsigned short) ((temp3 >> 8) & 0xff));
1631 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1632 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001633}
1634
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001635/* --------------------------------------------------------------------- */
1636/* Function : XGI_GETLCDVCLKPtr */
1637/* Input : */
1638/* Output : al -> VCLK Index */
1639/* Description : */
1640/* --------------------------------------------------------------------- */
1641static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1642 struct vb_device_info *pVBInfo)
1643{
1644 unsigned short index;
1645
Peter Huewea3d675c2012-02-09 21:11:47 +01001646 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001647 index = XGI_GetLCDCapPtr1(pVBInfo);
1648
1649 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1650 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1651 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1652 } else { /* LCDA */
1653 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1654 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1655 }
1656 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001657}
1658
1659static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001660 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001661{
1662
1663 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001664 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001665
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001666 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001667 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001668
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001669 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1670 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001671 index = XGI_GetLCDCapPtr(pVBInfo);
1672 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1673
Peter Huewea3d675c2012-02-09 21:11:47 +01001674 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001675 return tempal;
1676
1677 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001678 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001679 (VB_SIS301B |
1680 VB_SIS302B |
1681 VB_SIS301LV |
1682 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001683 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001684 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001685 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001686 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001687 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001688 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001689 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001690 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001691 tempal = TVCLKBASE_315 +
1692 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001693
1694 }
1695 return tempal;
1696 }
1697
Peter Huewe599801f2012-02-09 21:11:45 +01001698 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001699 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001700 return tempal;
1701 }
1702
Peter Huewe599801f2012-02-09 21:11:45 +01001703 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001704 tempal = YPbPr525pVCLK;
1705 return tempal;
1706 }
1707
1708 tempal = NTSC1024VCLK;
1709
1710 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001711 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001712 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001713 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001714 }
1715
1716 if (pVBInfo->VBInfo & SetCRT2ToTV)
1717 return tempal;
1718 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001719 } /* {End of VB} */
1720
Peter Huewe516354e2013-02-15 20:37:11 +01001721 inb((pVBInfo->P3ca + 0x02));
Aaro Koskinena39325d2012-11-04 21:14:53 +02001722 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001723 return tempal;
1724}
1725
1726static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1727 unsigned char *di_1, struct vb_device_info *pVBInfo)
1728{
Peter Huewe6896b942012-02-09 21:11:46 +01001729 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1730 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001731 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1732 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001733 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001734 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001735 }
1736 } else {
1737 *di_0 = XGI_VCLKData[tempal].SR2B;
1738 *di_1 = XGI_VCLKData[tempal].SR2C;
1739 }
1740}
1741
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001742static void XGI_SetCRT2ECLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301743 unsigned short RefreshRateTableIndex,
1744 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001745{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301746 unsigned char di_0, di_1, tempal;
1747 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001748
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001749 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301750 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1751 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001752
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301753 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001754 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301755 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001756 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301757 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001758 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1759 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301760 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001761 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1762 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301763 }
1764 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001765}
1766
Aaro Koskinenb053af12013-07-16 23:13:28 +03001767static void XGI_UpdateModeInfo(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001768{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301769 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001770
Peter Huewe6896b942012-02-09 21:11:46 +01001771 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1772 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301773 tempcl = 0;
1774 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001775 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001776
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301777 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001778 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301779 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001780 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301781 if (!(temp & 0x40))
1782 tempcl |= ActiveCRT1;
1783 }
1784 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001785
Aaro Koskinen58839b02011-03-13 12:26:23 +02001786 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301787 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001788
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301789 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001790 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001791 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301792 if (tempax & 0x04)
1793 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001794
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301795 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301797 if (!(tempcl & ActiveLCD))
1798 if (temp == 0x01)
1799 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301801 if (temp == 0x04)
1802 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001803
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301804 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001805 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001806
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301807 if (!(temp & 0x08))
1808 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001809
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301810 if (!(temp & 0x04))
1811 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001812
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301813 if (temp & 0x02)
1814 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001815
Peter Huewe599801f2012-02-09 21:11:45 +01001816 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301817 if (temp & 0x01)
1818 tempch |= ActiveHiTV;
1819 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001820
Peter Huewe599801f2012-02-09 21:11:45 +01001821 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001822 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301823 pVBInfo->Part2Port,
1824 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301826 if (temp & 0x10)
1827 tempch |= ActiveYPbPr;
1828 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301830 if (tempch != 0)
1831 tempcl |= ActiveTV;
1832 }
1833 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001834
Aaro Koskinen58839b02011-03-13 12:26:23 +02001835 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301836 if (tempcl & ActiveLCD) {
1837 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1838 if (temp & ActiveTV)
1839 tempcl |= ActiveTV;
1840 }
1841 }
1842 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001843 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001844 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301846 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001847 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301848 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001849}
1850
Bill Pemberton80adad82010-06-17 13:10:51 -04001851void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001852{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301853 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001854
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001855 tempbx = VB_SIS302B;
1856 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1857 if (flag == 0x02)
1858 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001859
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001860 tempbx = VB_SIS301;
1861 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1862 if (flag < 0xB0)
1863 goto finish;
1864
1865 tempbx = VB_SIS301B;
1866 if (flag < 0xC0)
1867 goto bigger_than_0xB0;
1868
1869 tempbx = VB_XGI301C;
1870 if (flag < 0xD0)
1871 goto bigger_than_0xB0;
1872
1873 tempbx = VB_SIS301LV;
1874 if (flag < 0xE0)
1875 goto bigger_than_0xB0;
1876
1877 tempbx = VB_SIS302LV;
1878 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1879 if (tempah != 0xFF)
1880 tempbx = VB_XGI301C;
1881
1882bigger_than_0xB0:
1883 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1884 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1885 if (!(flag & 0x02))
1886 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301887 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001888
1889finish:
1890 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001891}
1892
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001893static void XGI_GetVBInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301894 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001895{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301896 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001897
Aaro Koskinenb3979922012-11-04 21:14:52 +02001898 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301899 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001900 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301901 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001902
Miguel Gómezf9317352012-07-06 12:40:48 +02001903 if (!(pVBInfo->VBType & 0xFFFF))
1904 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001905
Miguel Gómezf9317352012-07-06 12:40:48 +02001906 /* Check Display Device */
1907 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1908 tempbx = tempbx | temp;
1909 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1910 push = temp;
1911 push = push << 8;
1912 tempax = temp << 8;
1913 tempbx = tempbx | tempax;
1914 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1915 | SetInSlaveMode | DisableCRT2Display);
1916 temp = 0xFFFF ^ temp;
1917 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001918
Miguel Gómezf9317352012-07-06 12:40:48 +02001919 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001920
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001921 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1922 VB_XGI301C)) {
1923 if (temp & EnableDualEdge) {
1924 tempbx |= SetCRT2ToDualEdge;
1925 if (temp & SetToLCDA)
1926 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02001927 }
1928 }
1929
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001930 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
1931 if (temp & SetYPbPr) {
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001932 /* shampoo add for new scratch */
1933 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
1934 temp &= YPbPrMode;
1935 tempbx |= SetCRT2ToHiVision;
Miguel Gómezf9317352012-07-06 12:40:48 +02001936
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001937 if (temp != YPbPrMode1080i) {
1938 tempbx &= (~SetCRT2ToHiVision);
1939 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301940 }
1941 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001942 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001943
Miguel Gómezf9317352012-07-06 12:40:48 +02001944 tempax = push; /* restore CR31 */
1945
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001946 temp = 0x09FC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001947
Miguel Gómezf9317352012-07-06 12:40:48 +02001948 if (!(tempbx & temp)) {
1949 tempax |= DisableCRT2Display;
1950 tempbx = 0;
1951 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001952
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001953 if (!(pVBInfo->VBType & VB_NoLCD)) {
1954 if (tempbx & XGI_SetCRT2ToLCDA) {
1955 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001956 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001957 SwitchCRT2));
1958 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001959 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
1960 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02001961 }
1962 }
1963
1964 /* shampoo add */
1965 /* for driver abnormal */
1966 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
Aaro Koskinenee768752013-05-29 23:59:16 +03001967 if (tempbx & SetCRT2ToRAMDAC) {
1968 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
1969 SwitchCRT2 | SetSimuScanMode);
1970 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301971 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001972 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001973
Miguel Gómezf9317352012-07-06 12:40:48 +02001974 if (!(pVBInfo->VBType & VB_NoLCD)) {
1975 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001976 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001977 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01001978 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301979 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001980 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001981
Miguel Gómezf9317352012-07-06 12:40:48 +02001982 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001983 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02001984 SetSimuScanMode);
1985 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
1986 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001987
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001988 if (tempbx & SetCRT2ToYPbPr525750)
1989 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001990
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001991 if (tempbx & SetCRT2ToHiVision)
1992 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
1993 SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001994
Miguel Gómezf9317352012-07-06 12:40:48 +02001995 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
1996 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
1997 tempbx = DisableCRT2Display;
1998 }
1999
2000 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002001 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002002 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002003 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002004 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002005
Miguel Gómezf9317352012-07-06 12:40:48 +02002006 /* LCD+TV can't support in slave mode
2007 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002008 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2009 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002010 SetCRT2ToDualEdge);
2011 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302012 }
2013 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002014
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302015 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002016}
2017
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002018static void XGI_GetTVInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302019 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002020{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002021 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002022
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302023 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002024 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2025 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002026
Peter Huewe5fc699f2013-02-03 04:08:45 +01002027 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2028 if (tempbx & TVSetPAL) {
2029 tempbx &= (SetCHTVOverScan |
2030 TVSetPALM |
2031 TVSetPALN |
2032 TVSetPAL);
2033 if (tempbx & TVSetPALM)
2034 /* set to NTSC if PAL-M */
2035 tempbx &= ~TVSetPAL;
2036 } else
2037 tempbx &= (SetCHTVOverScan |
2038 TVSetNTSCJ |
2039 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002040
Aaro Koskinena8b35292013-02-09 00:03:45 +02002041 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2042 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002043
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002044 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2045 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2046 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002047
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002048 if (index1 == YPbPrMode525i)
2049 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002050
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002051 if (index1 == YPbPrMode525p)
2052 tempbx = tempbx | TVSetYPbPr525p;
2053 if (index1 == YPbPrMode750p)
2054 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302055 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002056
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03002057 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2058 tempbx = tempbx | TVSetHiVision | TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002059
Aaro Koskinena8b35292013-02-09 00:03:45 +02002060 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2061 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2062 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002063
Aaro Koskinena8b35292013-02-09 00:03:45 +02002064 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2065 /* NTSC 1024x768, */
2066 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002067
Aaro Koskinena8b35292013-02-09 00:03:45 +02002068 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002069
Aaro Koskinena8b35292013-02-09 00:03:45 +02002070 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2071 if (pVBInfo->VBInfo & SetInSlaveMode)
2072 tempbx &= (~RPLLDIV2XO);
2073 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2074 tempbx &= (~RPLLDIV2XO);
2075 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2076 VB_SIS301LV | VB_SIS302LV |
2077 VB_XGI301C))) {
2078 if (tempbx & TVSimuMode)
2079 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302080 }
2081 }
2082 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002083}
2084
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002085static unsigned char XGI_GetLCDInfo(unsigned short ModeIdIndex,
2086 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002087{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002088 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302090 pVBInfo->LCDResInfo = 0;
2091 pVBInfo->LCDTypeInfo = 0;
2092 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002093
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002094 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002095 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002096 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302097 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302099 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002100 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002101
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002102 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002103 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302104 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002105 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002106 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302107 tempax &= 0x0F;
2108 else
2109 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302111 if ((resinfo == 6) || (resinfo == 9)) {
2112 if (tempax >= 3)
2113 tempbx |= PanelRef75Hz;
2114 } else if ((resinfo == 7) || (resinfo == 8)) {
2115 if (tempax >= 4)
2116 tempbx |= PanelRef75Hz;
2117 }
2118 }
2119 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302121 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302123 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002124
Peter Huewea3d675c2012-02-09 21:11:47 +01002125 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302126 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302128 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002129
Aaro Koskinen58839b02011-03-13 12:26:23 +02002130 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302132 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002133
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302134 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302136 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302138 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002139
Aaro Koskinen718e7152013-02-09 00:03:46 +02002140 if (((pVBInfo->VBType & VB_SIS302LV) ||
2141 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2142 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002143
Aaro Koskinen718e7152013-02-09 00:03:46 +02002144 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2145 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2146 (!(tempbx & EnableScalingLCD)))
2147 /*
2148 * set to center in 1280x1024 LCDB
2149 * for Panel_1400x1050
2150 */
2151 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002152
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302153 if (pVBInfo->VBInfo & SetInSlaveMode) {
2154 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002155 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302156 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002157 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302158 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002159
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302160 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302162 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002163}
2164
Bill Pemberton108afbf2010-06-17 13:10:47 -04002165unsigned char XGI_SearchModeID(unsigned short ModeNo,
Aaro Koskinen334ab072013-07-16 23:13:30 +03002166 unsigned short *ModeIdIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002167{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002168 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002169 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002170 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002171 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002172 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302173 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302175 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002176}
2177
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002178static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2179{
2180 unsigned char ujRet = 0;
2181 unsigned char i = 0;
2182
2183 for (i = 0; i < 8; i++) {
2184 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002185 ujRet |= (ujDate >> i) & 1;
2186 }
2187
2188 return ujRet;
2189}
2190
2191/*----------------------------------------------------------------------------*/
2192/* output */
2193/* bl[5] : LVDS signal */
2194/* bl[1] : LVDS backlight */
2195/* bl[0] : LVDS VDD */
2196/*----------------------------------------------------------------------------*/
2197static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2198{
2199 unsigned char CR4A, temp;
2200
Aaro Koskinen58839b02011-03-13 12:26:23 +02002201 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002202 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002203
Aaro Koskinen58839b02011-03-13 12:26:23 +02002204 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002205
2206 temp = XG21GPIODataTransfer(temp);
2207 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002208 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002209 return temp;
2210}
2211
2212/*----------------------------------------------------------------------------*/
2213/* output */
2214/* bl[5] : LVDS signal */
2215/* bl[1] : LVDS backlight */
2216/* bl[0] : LVDS VDD */
2217/*----------------------------------------------------------------------------*/
2218static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2219{
2220 unsigned char CR4A, CRB4, temp;
2221
Aaro Koskinen58839b02011-03-13 12:26:23 +02002222 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002223 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002224
Aaro Koskinen58839b02011-03-13 12:26:23 +02002225 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002226
2227 temp &= 0x0C;
2228 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002229 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002230 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002231 temp |= ((CRB4 & 0x04) << 3);
2232 return temp;
2233}
2234
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002235/*----------------------------------------------------------------------------*/
2236/* input */
2237/* bl[5] : 1;LVDS signal on */
2238/* bl[1] : 1;LVDS backlight on */
2239/* bl[0] : 1:LVDS VDD on */
2240/* bh: 100000b : clear bit 5, to set bit5 */
2241/* 000010b : clear bit 1, to set bit1 */
2242/* 000001b : clear bit 0, to set bit0 */
2243/*----------------------------------------------------------------------------*/
2244static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2245 struct vb_device_info *pVBInfo)
2246{
2247 unsigned char CR4A, temp;
2248
2249 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2250 tempbh &= 0x23;
2251 tempbl &= 0x23;
2252 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2253
2254 if (tempbh & 0x20) {
2255 temp = (tempbl >> 4) & 0x02;
2256
2257 /* CR B4[1] */
2258 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2259
2260 }
2261
2262 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2263
2264 temp = XG21GPIODataTransfer(temp);
2265 temp &= ~tempbh;
2266 temp |= tempbl;
2267 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2268}
2269
Aaro Koskinen776115a2011-11-27 23:03:10 +02002270static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2271 struct vb_device_info *pVBInfo)
2272{
2273 unsigned char CR4A, temp;
2274 unsigned short tempbh0, tempbl0;
2275
2276 tempbh0 = tempbh;
2277 tempbl0 = tempbl;
2278 tempbh0 &= 0x20;
2279 tempbl0 &= 0x20;
2280 tempbh0 >>= 3;
2281 tempbl0 >>= 3;
2282
2283 if (tempbh & 0x20) {
2284 temp = (tempbl >> 4) & 0x02;
2285
2286 /* CR B4[1] */
2287 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2288
2289 }
2290 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2291
2292 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2293 tempbh &= 0x03;
2294 tempbl &= 0x03;
2295 tempbh <<= 2;
2296 tempbl <<= 2; /* GPIOC,GPIOD */
2297 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2298 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2299}
2300
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002301static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2302 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302303 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002304{
2305
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002306 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302307 if (pXGIHWDE->jChipType == XG21) {
2308 if (pVBInfo->IF_DEF_LVDS == 1) {
2309 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002310 /* LVDS VDD on */
2311 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002312 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302313 }
2314 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002315 /* LVDS signal on */
2316 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002317 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002318 /* LVDS backlight on */
2319 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302320 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002321 /* DVO/DVI signal on */
2322 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302323 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002324
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302325 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002326
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302327 if (pXGIHWDE->jChipType == XG27) {
2328 if (pVBInfo->IF_DEF_LVDS == 1) {
2329 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002330 /* LVDS VDD on */
2331 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002332 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302333 }
2334 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002335 /* LVDS signal on */
2336 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002337 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002338 /* LVDS backlight on */
2339 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302340 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002341 /* DVO/DVI signal on */
2342 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302343 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002344
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302345 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002346}
2347
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002348void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2349 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302350 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002351{
2352
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302353 if (pXGIHWDE->jChipType == XG21) {
2354 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002355 /* LVDS backlight off */
2356 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002357 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302358 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002359 /* DVO/DVI signal off */
2360 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302361 }
2362 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002363
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302364 if (pXGIHWDE->jChipType == XG27) {
2365 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002366 /* LVDS backlight off */
2367 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002368 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302369 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002370
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302371 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002372 /* DVO/DVI signal off */
2373 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302374 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002375
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002376 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002377}
2378
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002379static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002380{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002381 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302382 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002383
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002384 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302385 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002386}
2387
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002388static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002389{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002390 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002391}
2392
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002393static void XGI_SaveCRT2Info(unsigned short ModeNo,
2394 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002395{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302396 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002397
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002398 /* reserve CR34 for CRT1 Mode No */
2399 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302400 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2401 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002402 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002403}
2404
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002405static void XGI_GetCRT2ResInfo(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002406 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002407{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302408 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002409
Aaro Koskinenb3979922012-11-04 21:14:52 +02002410 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002411 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2412 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002413 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002414 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002415
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002416 if (modeflag & HalfDCLK)
2417 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002418
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002419 if (modeflag & DoubleScanMode)
2420 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002421
Miguel Gómez3339db82012-07-06 12:40:49 +02002422 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2423 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002424
Aaro Koskinen22006832013-02-09 00:03:47 +02002425 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2426 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2427 if (yres == 1024)
2428 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302429 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002430 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002431
Aaro Koskinen22006832013-02-09 00:03:47 +02002432 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2433 if (yres == 400)
2434 yres = 405;
2435 else if (yres == 350)
2436 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002437
Aaro Koskinen22006832013-02-09 00:03:47 +02002438 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2439 if (yres == 360)
2440 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002441 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002442 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002443
Aaro Koskinen22006832013-02-09 00:03:47 +02002444 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2445 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2446 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2447 if (yres == 350)
2448 yres = 357;
2449 else if (yres == 400)
2450 yres = 420;
2451 else if (yres == 480)
2452 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002453 }
2454 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302455 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002456
Miguel Gómez3339db82012-07-06 12:40:49 +02002457 if (xres == 720)
2458 xres = 640;
2459
2460exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302461 pVBInfo->VGAHDE = xres;
2462 pVBInfo->HDE = xres;
2463 pVBInfo->VGAVDE = yres;
2464 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002465}
2466
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002467static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002468{
2469
Peter Huewea3d675c2012-02-09 21:11:47 +01002470 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002471 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302472 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002473
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302474 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002475}
2476
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002477static void XGI_GetRAMDAC2DATA(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002478 unsigned short RefreshRateTableIndex,
2479 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002480{
2481 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002482 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002483
2484 pVBInfo->RVBHCMAX = 1;
2485 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002486 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002487 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002488 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002489 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2490 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002491 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002492 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002493 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002494 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002495 tempcx &= 0x0100;
2496 tempcx = tempcx << 2;
2497 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002498 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002499
2500 if (temp1 & 0x01)
2501 tempbx |= 0x0100;
2502
2503 if (temp1 & 0x20)
2504 tempbx |= 0x0200;
2505 tempax += 5;
2506
2507 if (modeflag & Charx8Dot)
2508 tempax *= 8;
2509 else
2510 tempax *= 9;
2511
2512 pVBInfo->VGAHT = tempax;
2513 pVBInfo->HT = tempax;
2514 tempbx++;
2515 pVBInfo->VGAVT = tempbx;
2516 pVBInfo->VT = tempbx;
2517}
2518
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002519static void XGI_GetCRT2Data(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302520 unsigned short RefreshRateTableIndex,
2521 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002522{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002523 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002524
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002525 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002526
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002527 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002528 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2529 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302530 pVBInfo->NewFlickerMode = 0;
2531 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002532
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302533 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002534 XGI_GetRAMDAC2DATA(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302535 return;
2536 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002537
Peter Huewea3d675c2012-02-09 21:11:47 +01002538 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002539 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03002540 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002541
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302542 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2543 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2544 pVBInfo->VGAHT = LCDPtr->VGAHT;
2545 pVBInfo->VGAVT = LCDPtr->VGAVT;
2546 pVBInfo->HT = LCDPtr->LCDHT;
2547 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002548
Peter Huewe255aabd2012-02-09 21:11:44 +01002549 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302550 tempax = 1024;
2551 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002552
Peter Huewea3d675c2012-02-09 21:11:47 +01002553 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302554 if (pVBInfo->VGAVDE == 357)
2555 tempbx = 527;
2556 else if (pVBInfo->VGAVDE == 420)
2557 tempbx = 620;
2558 else if (pVBInfo->VGAVDE == 525)
2559 tempbx = 775;
2560 else if (pVBInfo->VGAVDE == 600)
2561 tempbx = 775;
Peter Huewe7580d7f2013-05-18 00:19:54 +02002562 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002563 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302564 tempax = 1024;
2565 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002566 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302567 tempax = 1280;
2568 if (pVBInfo->VGAVDE == 360)
2569 tempbx = 768;
2570 else if (pVBInfo->VGAVDE == 375)
2571 tempbx = 800;
2572 else if (pVBInfo->VGAVDE == 405)
2573 tempbx = 864;
2574 else
2575 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002576 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302577 tempax = 1280;
2578 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002579 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302580 tempax = 1280;
2581 if (pVBInfo->VGAVDE == 350)
2582 tempbx = 700;
2583 else if (pVBInfo->VGAVDE == 400)
2584 tempbx = 800;
2585 else if (pVBInfo->VGAVDE == 1024)
2586 tempbx = 960;
2587 else
2588 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002589 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302590 tempax = 1400;
2591 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002592
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302593 if (pVBInfo->VGAVDE == 1024) {
2594 tempax = 1280;
2595 tempbx = 1024;
2596 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002597 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302598 tempax = 1600;
2599 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002600 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302601 if (pVBInfo->VGAVDE == 350)
2602 tempbx = 875;
2603 else if (pVBInfo->VGAVDE == 400)
2604 tempbx = 1000;
2605 }
2606 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002607
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302608 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2609 tempax = pVBInfo->VGAHDE;
2610 tempbx = pVBInfo->VGAVDE;
2611 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002612
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302613 pVBInfo->HDE = tempax;
2614 pVBInfo->VDE = tempbx;
2615 return;
2616 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002617
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302618 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002619 struct SiS_TVData const *TVPtr;
2620
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002621 TVPtr = XGI_GetTVPtr(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinen24572542012-09-11 00:15:21 +03002622 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002623
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302624 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2625 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2626 pVBInfo->VGAHT = TVPtr->VGAHT;
2627 pVBInfo->VGAVT = TVPtr->VGAVT;
2628 pVBInfo->HDE = TVPtr->TVHDE;
2629 pVBInfo->VDE = TVPtr->TVVDE;
2630 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2631 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002632
Peter Huewe599801f2012-02-09 21:11:45 +01002633 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302634 if (resinfo == 0x08)
2635 pVBInfo->NewFlickerMode = 0x40;
2636 else if (resinfo == 0x09)
2637 pVBInfo->NewFlickerMode = 0x40;
2638 else if (resinfo == 0x12)
2639 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002640
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302641 if (pVBInfo->VGAVDE == 350)
2642 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002643
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302644 tempax = ExtHiTVHT;
2645 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002646
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302647 if (pVBInfo->VBInfo & SetInSlaveMode) {
2648 if (pVBInfo->TVInfo & TVSimuMode) {
2649 tempax = StHiTVHT;
2650 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002651
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302652 if (!(modeflag & Charx8Dot)) {
2653 tempax = StHiTextTVHT;
2654 tempbx = StHiTextTVVT;
2655 }
2656 }
2657 }
Peter Huewe599801f2012-02-09 21:11:45 +01002658 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2659 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302660 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2661 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2662 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002663
Peter Huewe599801f2012-02-09 21:11:45 +01002664 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302665 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2666 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002667 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302668 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2669 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2670 if (pVBInfo->TVInfo & NTSC1024x768)
2671 tempax = NTSC1024x768HT;
2672 }
2673 } else {
2674 tempax = PALHT;
2675 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002676 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302677 tempax = NTSCHT;
2678 tempbx = NTSCVT;
2679 if (pVBInfo->TVInfo & NTSC1024x768)
2680 tempax = NTSC1024x768HT;
2681 }
2682 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002683
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302684 pVBInfo->HT = tempax;
2685 pVBInfo->VT = tempbx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302686 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002687}
2688
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002689static void XGI_SetCRT2VCLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302690 unsigned short RefreshRateTableIndex,
2691 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002692{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002693 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002694
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002695 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302696 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2697 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002698
Peter Huewe6896b942012-02-09 21:11:46 +01002699 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302700 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002701 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2702 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2703 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302704 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002705 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2706 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302707 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002708
Aaro Koskinen8104e322011-03-13 12:26:22 +02002709 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002710
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302711 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002712 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302713 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002714 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002715}
2716
Aaro Koskinen334ab072013-07-16 23:13:30 +03002717static unsigned short XGI_GetColorDepth(unsigned short ModeIdIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002718{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002719 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2720 short index;
2721 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302722
Aaro Koskinenb3979922012-11-04 21:14:52 +02002723 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002724 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302725
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002726 if (index < 0)
2727 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302728
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002729 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302730}
2731
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002732static unsigned short XGI_GetOffset(unsigned short ModeNo,
2733 unsigned short ModeIdIndex,
Aaro Koskinen334ab072013-07-16 23:13:30 +03002734 unsigned short RefreshRateTableIndex)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302735{
2736 unsigned short temp, colordepth, modeinfo, index, infoflag,
2737 ColorDepth[] = { 0x01, 0x02, 0x04 };
2738
Aaro Koskinenb3979922012-11-04 21:14:52 +02002739 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002740 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302741
2742 index = (modeinfo >> 8) & 0xFF;
2743
Aaro Koskinen224114c2012-11-04 21:14:59 +02002744 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302745
2746 if (infoflag & InterlaceMode)
2747 temp = temp << 1;
2748
Aaro Koskinen334ab072013-07-16 23:13:30 +03002749 colordepth = XGI_GetColorDepth(ModeIdIndex);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302750
2751 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2752 temp = ModeNo - 0x7C;
2753 colordepth = ColorDepth[temp];
2754 temp = 0x6B;
2755 if (infoflag & InterlaceMode)
2756 temp = temp << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302757 }
Peter Huewe053004b2013-02-15 20:37:12 +01002758 return temp * colordepth;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302759}
2760
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002761static void XGI_SetCRT2Offset(unsigned short ModeNo,
2762 unsigned short ModeIdIndex,
2763 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002764 struct vb_device_info *pVBInfo)
2765{
2766 unsigned short offset;
2767 unsigned char temp;
2768
2769 if (pVBInfo->VBInfo & SetInSlaveMode)
2770 return;
2771
Aaro Koskinen334ab072013-07-16 23:13:30 +03002772 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002773 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002774 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002775 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002776 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002777 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002778 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002779}
2780
Randy Dunlap89229672010-08-10 08:46:44 -07002781static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002782{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002783 /* threshold high ,disable auto threshold */
2784 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2785 /* threshold low default 04h */
2786 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002787}
2788
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002789static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302790 unsigned short RefreshRateTableIndex,
2791 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002792{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002793 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002794
Aaro Koskinenb053af12013-07-16 23:13:28 +03002795 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302796 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302798 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002799 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002800
Aaro Koskinen8104e322011-03-13 12:26:22 +02002801 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2802 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002803}
2804
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002805static void XGI_SetGroup1(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302806 unsigned short RefreshRateTableIndex,
2807 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002808{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302809 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002810 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002811
Aaro Koskinena39325d2012-11-04 21:14:53 +02002812 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002813 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002814 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302816 /* bainy change table name */
2817 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002818 /* BTVGA2HT 0x08,0x09 */
2819 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002820 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302821 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002822 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002823 /* BTVGA2HDEE 0x0A,0x0C */
2824 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002825 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302826 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2827 pushbx = pVBInfo->VGAHDE / 2 + 16;
2828 tempcx = tempcx >> 1;
2829 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2830 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002831
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302832 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002833 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2834 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002835 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302836 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002837 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302838 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002839 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302840 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2841 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2842 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002843
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302844 tempbx += 4;
2845 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302847 if (tempcx > (pVBInfo->VGAHT / 2))
2848 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002849
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302850 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002851
Aaro Koskinen8104e322011-03-13 12:26:22 +02002852 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302853 } else {
2854 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002855 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302856 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002857 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002858 /* BTVGA2HDEE 0x0A,0x0C */
2859 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002860 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302861 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2862 pushbx = pVBInfo->VGAHDE + 16;
2863 tempcx = tempcx >> 1;
2864 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2865 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302867 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002868 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2869 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002870 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302871 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002872 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302873 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002874 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302875 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2876 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2877 tempbx += 16;
2878 tempcx += 16;
2879 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002880
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302881 if (tempcx > pVBInfo->VGAHT)
2882 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002883
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302884 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002885 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302886 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002887
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302888 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2889 tempbx = pushbx;
2890 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2891 tempax |= (tempbx & 0xFF00);
2892 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002893 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302894 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002895 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302896 tempcx = (pVBInfo->VGAVT - 1);
2897 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002898
Aaro Koskinen8104e322011-03-13 12:26:22 +02002899 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302900 tempbx = pVBInfo->VGAVDE - 1;
2901 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002902 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302903 temp = ((tempbx & 0xFF00) << 3) >> 8;
2904 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002905 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002906
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002907 /* BTVGA2VRS 0x10,0x11 */
2908 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
2909 /* BTVGA2VRE 0x11 */
2910 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002911
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302912 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002913 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
2914 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302916 if (temp & 0x04)
2917 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002918
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302919 if (temp & 0x080)
2920 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002921
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002922 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002923
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302924 if (temp & 0x08)
2925 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002926
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002927 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302928 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
2929 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002930
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302931 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002932 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302933 temp = ((tempbx & 0xFF00) >> 8) << 4;
2934 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02002935 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302936 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002937
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302938 if (modeflag & DoubleScanMode)
2939 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002940
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302941 if (modeflag & HalfDCLK)
2942 tempax |= 0x40;
2943
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002944 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002945}
2946
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002947static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
2948{
2949 unsigned long tempax, tempbx;
2950
2951 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
2952 & 0xFFFF;
2953 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
2954 tempax = (tempax * pVBInfo->HT) / tempbx;
2955
2956 return (unsigned short) tempax;
2957}
2958
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002959static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302960 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002961{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302962 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002963 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002964
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002965 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002966 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2967 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002968
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302969 if (!(pVBInfo->VBInfo & SetInSlaveMode))
2970 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002971
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302972 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002973 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302974 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002975
Peter Huewe6896b942012-02-09 21:11:46 +01002976 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302977 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002978
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302979 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002980
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302981 if (modeflag & HalfDCLK)
2982 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002983
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302984 tempax = (tempax / tempcx) - 1;
2985 tempbx |= ((tempax & 0x00FF) << 8);
2986 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002987 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002988
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302989 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002990
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302991 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01002992 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
2993 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302994 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002995
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002996 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
2997 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302998 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302999 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003000
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003001 /* 0x05 Horizontal Display Start */
3002 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3003 /* 0x06 Horizontal Blank end */
3004 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003005
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303006 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3007 if (pVBInfo->VBInfo & SetCRT2ToTV)
3008 tempax = pVBInfo->VGAHT;
3009 else
3010 tempax = XGI_GetVGAHT2(pVBInfo);
3011 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003012
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303013 if (tempax >= pVBInfo->VGAHT)
3014 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303016 if (modeflag & HalfDCLK)
3017 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003018
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303019 tempax = (tempax / tempcx) - 5;
3020 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003021 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303022 temp = (tempbx & 0x00FF) - 1;
3023 if (!(modeflag & HalfDCLK)) {
3024 temp -= 6;
3025 if (pVBInfo->TVInfo & TVSimuMode) {
3026 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003027 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303028 }
3029 }
3030 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303031 tempbx = (tempbx & 0xFF00) >> 8;
3032 tempcx = (tempcx + tempbx) >> 1;
3033 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303035 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3036 temp -= 1;
3037 if (!(modeflag & HalfDCLK)) {
3038 if ((modeflag & Charx8Dot)) {
3039 temp += 4;
3040 if (pVBInfo->VGAHDE >= 800)
3041 temp -= 6;
3042 }
3043 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003044 } else if (!(modeflag & HalfDCLK)) {
3045 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003046 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003047 pVBInfo->VGAHDE >= 800) {
3048 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003049 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003050 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003051 (pVBInfo->LCDInfo & LCDNonExpanding))
3052 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303053 }
3054 }
3055 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003056
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003057 /* 0x07 Horizontal Retrace Start */
3058 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3059 /* 0x08 Horizontal Retrace End */
3060 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003061
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303062 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3063 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003064 if (ModeNo == 0x50) {
Peter Huewe85b38472013-05-13 23:41:49 +02003065 if (pVBInfo->TVInfo == SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003066 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303067 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003068 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303069 0x08, 0x03);
3070 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003071 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303072 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003073 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303074 0x08, 0x02);
3075 }
3076 }
3077 }
3078 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003079
Aaro Koskinen8104e322011-03-13 12:26:22 +02003080 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003081 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003082 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303084 tempbx = pVBInfo->VGAVT;
3085 push1 = tempbx;
3086 tempcx = 0x121;
3087 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303089 if (tempbx == 357)
3090 tempbx = 350;
3091 if (tempbx == 360)
3092 tempbx = 350;
3093 if (tempbx == 375)
3094 tempbx = 350;
3095 if (tempbx == 405)
3096 tempbx = 400;
3097 if (tempbx == 525)
3098 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303100 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303102 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003103 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003104 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303105 if (tempbx == 350)
3106 tempbx += 5;
3107 if (tempbx == 480)
3108 tempbx += 5;
3109 }
3110 }
3111 }
3112 tempbx--;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303113 tempbx--;
3114 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003115 /* 0x10 vertical Blank Start */
3116 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303117 tempbx = push2;
3118 tempbx--;
3119 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003120 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303122 if (tempbx & 0x0100)
3123 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303125 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303127 if (modeflag & DoubleScanMode)
3128 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003129
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303130 if (tempbx & 0x0200)
3131 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303133 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003134 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303136 if (tempbx & 0x0400)
3137 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003138
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003139 /* 0x11 Vertival Blank End */
3140 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303141
3142 tempax = push1;
3143 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3144 tempax = tempax >> 2;
3145 push1 = tempax; /* push ax */
3146
3147 if (resinfo != 0x09) {
3148 tempax = tempax << 1;
3149 tempbx += tempax;
3150 }
3151
Peter Huewe599801f2012-02-09 21:11:45 +01003152 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003153 if ((pVBInfo->VBType & VB_SIS301LV) &&
3154 !(pVBInfo->TVInfo & TVSetHiVision)) {
3155 if ((pVBInfo->TVInfo & TVSimuMode) &&
3156 (pVBInfo->TVInfo & TVSetPAL)) {
3157 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3158 !(pVBInfo->TVInfo &
3159 (TVSetYPbPr525p |
3160 TVSetYPbPr750p |
3161 TVSetHiVision)))
3162 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303163 }
3164 } else {
3165 tempbx -= 10;
3166 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003167 } else if (pVBInfo->TVInfo & TVSimuMode) {
3168 if (pVBInfo->TVInfo & TVSetPAL) {
3169 if (pVBInfo->VBType & VB_SIS301LV) {
3170 if (!(pVBInfo->TVInfo &
3171 (TVSetYPbPr525p |
3172 TVSetYPbPr750p |
3173 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303174 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003175 } else {
3176 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303177 }
3178 }
3179 }
3180 tempax = push1;
3181 tempax = tempax >> 2;
3182 tempax++;
3183 tempax += tempbx;
3184 push1 = tempax; /* push ax */
3185
Peter Huewe599801f2012-02-09 21:11:45 +01003186 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303187 if (tempbx <= 513) {
3188 if (tempax >= 513)
3189 tempbx = 513;
3190 }
3191 }
3192
3193 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003194 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303195 tempbx--;
3196 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003197 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303198
3199 if (tempbx & 0x0100)
3200 tempcx |= 0x0008;
3201
3202 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003203 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303204
3205 tempbx++;
3206
3207 if (tempbx & 0x0100)
3208 tempcx |= 0x0004;
3209
3210 if (tempbx & 0x0200)
3211 tempcx |= 0x0080;
3212
3213 if (tempbx & 0x0400)
3214 tempcx |= 0x0C00;
3215
3216 tempbx = push1; /* pop ax */
3217 temp = tempbx & 0x00FF;
3218 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003219 /* 0x0D vertical Retrace End */
3220 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303221
3222 if (tempbx & 0x0010)
3223 tempcx |= 0x2000;
3224
3225 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003226 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303227 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003228 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303229 tempax = modeflag;
3230 temp = (tempax & 0xFF00) >> 8;
3231
3232 temp = (temp >> 1) & 0x09;
3233
Peter Huewe6896b942012-02-09 21:11:46 +01003234 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303235 temp |= 0x01;
3236
Aaro Koskinen8104e322011-03-13 12:26:22 +02003237 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3238 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3239 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303240
3241 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3242 temp = 0x80;
3243 else
3244 temp = 0x00;
3245
Aaro Koskinen8104e322011-03-13 12:26:22 +02003246 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003247}
3248
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003249static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303250 struct vb_device_info *pVBInfo)
3251{
3252 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003253 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003254 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303255
3256 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3257
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003258 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003259 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303260
3261 tempax = 0;
3262
3263 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3264 tempax |= 0x0800;
3265
3266 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3267 tempax |= 0x0400;
3268
3269 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3270 tempax |= 0x0200;
3271
Peter Huewe599801f2012-02-09 21:11:45 +01003272 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303273 tempax |= 0x1000;
3274
Peter Huewe599801f2012-02-09 21:11:45 +01003275 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303276 tempax |= 0x0100;
3277
Peter Huewe599801f2012-02-09 21:11:45 +01003278 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303279 tempax &= 0xfe00;
3280
3281 tempax = (tempax & 0xff00) >> 8;
3282
Aaro Koskinen8104e322011-03-13 12:26:22 +02003283 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003284 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303285
Peter Huewe599801f2012-02-09 21:11:45 +01003286 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003287 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303288
Peter Huewe599801f2012-02-09 21:11:45 +01003289 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003290 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303291
3292 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003293 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303294
3295 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003296 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303297
3298 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003299 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303300 }
3301
Peter Huewe599801f2012-02-09 21:11:45 +01003302 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3303 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003304 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303305
Peter Huewe599801f2012-02-09 21:11:45 +01003306 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003307 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303308
Peter Huewe599801f2012-02-09 21:11:45 +01003309 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003310 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303311 }
3312
3313 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003314 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303315
3316 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003317 /* di->temp2[j] */
3318 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303319
3320 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003321 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303322
3323 temp = pVBInfo->NewFlickerMode;
3324 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003325 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303326
Peter Huewe599801f2012-02-09 21:11:45 +01003327 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303328 tempax = 520;
3329 else
3330 tempax = 440;
3331
3332 if (pVBInfo->VDE <= tempax) {
3333 tempax -= pVBInfo->VDE;
3334 tempax = tempax >> 2;
3335 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3336 push1 = tempax;
3337 temp = (tempax & 0xFF00) >> 8;
3338 temp += (unsigned short) TimingPoint[0];
3339
Peter Huewe6896b942012-02-09 21:11:46 +01003340 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3341 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303342 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3343 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003344 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303345 tempcx = pVBInfo->VGAHDE;
3346 if (tempcx >= 1024) {
3347 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003348 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303349 temp = 0x19; /* PAL */
3350 }
3351 }
3352 }
3353
Aaro Koskinen8104e322011-03-13 12:26:22 +02003354 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303355 tempax = push1;
3356 temp = (tempax & 0xFF00) >> 8;
3357 temp += TimingPoint[1];
3358
Peter Huewe6896b942012-02-09 21:11:46 +01003359 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3360 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303361 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3362 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003363 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303364 tempcx = pVBInfo->VGAHDE;
3365 if (tempcx >= 1024) {
3366 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003367 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303368 temp = 0x52; /* PAL */
3369 }
3370 }
3371 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003372 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303373 }
3374
3375 /* 301b */
3376 tempcx = pVBInfo->HT;
3377
3378 if (XGI_IsLCDDualLink(pVBInfo))
3379 tempcx = tempcx >> 1;
3380
3381 tempcx -= 2;
3382 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003383 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303384
3385 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003386 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303387
3388 tempcx = pVBInfo->HT >> 1;
3389 push1 = tempcx; /* push cx */
3390 tempcx += 7;
3391
Peter Huewe599801f2012-02-09 21:11:45 +01003392 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303393 tempcx -= 4;
3394
3395 temp = tempcx & 0x00FF;
3396 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003397 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303398
3399 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3400 tempbx += tempcx;
3401 push2 = tempbx;
3402 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003403 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303404 temp = (tempbx & 0xFF00) >> 8;
3405 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003406 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303407
3408 tempbx = push2;
3409 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003410 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303411 tempbx = tempbx - 4;
3412 tempcx = tempbx;
3413 }
3414
3415 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003416 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303417
3418 j += 2;
3419 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3420 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003421 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303422 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003423 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303424
3425 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003426 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303427 tempcx -= 4;
3428
3429 temp = tempcx & 0xFF;
3430 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003431 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303432
3433 tempcx = push1; /* pop cx */
3434 j += 2;
3435 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3436 tempcx -= temp;
3437 temp = tempcx & 0x00FF;
3438 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003439 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303440
3441 tempcx -= 11;
3442
3443 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3444 tempax = XGI_GetVGAHT2(pVBInfo);
3445 tempcx = tempax - 1;
3446 }
3447 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003448 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303449
3450 tempbx = pVBInfo->VDE;
3451
3452 if (pVBInfo->VGAVDE == 360)
3453 tempbx = 746;
3454 if (pVBInfo->VGAVDE == 375)
3455 tempbx = 746;
3456 if (pVBInfo->VGAVDE == 405)
3457 tempbx = 853;
3458
3459 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003460 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003461 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003462 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003463 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303464 tempbx = tempbx >> 1;
3465 } else
3466 tempbx = tempbx >> 1;
3467 }
3468
3469 tempbx -= 2;
3470 temp = tempbx & 0x00FF;
3471
Peter Huewe599801f2012-02-09 21:11:45 +01003472 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003473 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003474 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303475 if (pVBInfo->VBInfo & SetInSlaveMode) {
3476 if (ModeNo == 0x2f)
3477 temp += 1;
3478 }
3479 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003480 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3481 if (ModeNo == 0x2f)
3482 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303483 }
3484 }
3485
Aaro Koskinen8104e322011-03-13 12:26:22 +02003486 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303487
3488 temp = (tempcx & 0xFF00) >> 8;
3489 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3490
Peter Huewe599801f2012-02-09 21:11:45 +01003491 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003492 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003493 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303494 temp |= 0x10;
3495
3496 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3497 temp |= 0x20;
3498 }
3499 } else {
3500 temp |= 0x10;
3501 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3502 temp |= 0x20;
3503 }
3504 }
3505
Aaro Koskinen8104e322011-03-13 12:26:22 +02003506 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303507
Peter Huewe6896b942012-02-09 21:11:46 +01003508 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3509 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303510 tempbx = pVBInfo->VDE;
3511 tempcx = tempbx - 2;
3512
3513 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003514 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3515 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303516 tempbx = tempbx >> 1;
3517 }
3518
Peter Huewe6896b942012-02-09 21:11:46 +01003519 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303520 temp = 0;
3521 if (tempcx & 0x0400)
3522 temp |= 0x20;
3523
3524 if (tempbx & 0x0400)
3525 temp |= 0x40;
3526
Aaro Koskinen8104e322011-03-13 12:26:22 +02003527 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303528 }
3529
3530 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003531 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303532 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003533 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303534 }
3535
3536 tempbx = tempbx & 0x00FF;
3537
3538 if (!(modeflag & HalfDCLK)) {
3539 tempcx = pVBInfo->VGAHDE;
3540 if (tempcx >= pVBInfo->HDE) {
3541 tempbx |= 0x2000;
3542 tempax &= 0x00FF;
3543 }
3544 }
3545
3546 tempcx = 0x0101;
3547
3548 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3549 if (pVBInfo->VGAHDE >= 1024) {
3550 tempcx = 0x1920;
3551 if (pVBInfo->VGAHDE >= 1280) {
3552 tempcx = 0x1420;
3553 tempbx = tempbx & 0xDFFF;
3554 }
3555 }
3556 }
3557
3558 if (!(tempbx & 0x2000)) {
3559 if (modeflag & HalfDCLK)
3560 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3561
3562 push1 = tempbx;
3563 tempeax = pVBInfo->VGAHDE;
3564 tempebx = (tempcx & 0xFF00) >> 8;
3565 longtemp = tempeax * tempebx;
3566 tempecx = tempcx & 0x00FF;
3567 longtemp = longtemp / tempecx;
3568
3569 /* 301b */
3570 tempecx = 8 * 1024;
3571
Peter Huewe6896b942012-02-09 21:11:46 +01003572 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3573 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303574 tempecx = tempecx * 8;
3575 }
3576
3577 longtemp = longtemp * tempecx;
3578 tempecx = pVBInfo->HDE;
3579 temp2 = longtemp % tempecx;
3580 tempeax = longtemp / tempecx;
3581 if (temp2 != 0)
3582 tempeax += 1;
3583
3584 tempax = (unsigned short) tempeax;
3585
3586 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003587 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3588 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303589 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3590 }
3591 /* end 301b */
3592
3593 tempbx = push1;
3594 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3595 | (tempbx & 0x00FF));
3596 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3597 | (tempax & 0x00FF));
3598 temp = (tempax & 0xFF00) >> 8;
3599 } else {
3600 temp = (tempax & 0x00FF) >> 8;
3601 }
3602
Aaro Koskinen8104e322011-03-13 12:26:22 +02003603 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303604 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003605 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303606 temp = tempcx & 0x00FF;
3607
3608 if (tempbx & 0x2000)
3609 temp = 0;
3610
3611 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3612 temp |= 0x18;
3613
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003614 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003615 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303616 tempbx = 0x0382;
3617 tempcx = 0x007e;
3618 } else {
3619 tempbx = 0x0369;
3620 tempcx = 0x0061;
3621 }
3622
3623 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003624 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303625 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003626 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303627
3628 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3629 temp = temp << 2;
3630 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3631
Peter Huewe599801f2012-02-09 21:11:45 +01003632 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303633 temp |= 0x10;
3634
Peter Huewe599801f2012-02-09 21:11:45 +01003635 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303636 temp |= 0x20;
3637
Peter Huewe599801f2012-02-09 21:11:45 +01003638 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303639 temp |= 0x60;
3640 }
3641
Aaro Koskinen8104e322011-03-13 12:26:22 +02003642 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003643 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003644 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303645
Peter Huewe599801f2012-02-09 21:11:45 +01003646 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303647 if (pVBInfo->TVInfo & NTSC1024x768) {
3648 TimingPoint = XGI_NTSC1024AdjTime;
3649 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003650 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303651 TimingPoint[j]);
3652 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003653 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303654 }
3655 }
3656
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003657 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303658 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003659 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003660 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303661 0x08); /* PALM Mode */
3662 }
3663
Peter Huewe599801f2012-02-09 21:11:45 +01003664 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003665 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303666 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003667 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303668
Aaro Koskinendc505562011-03-13 12:26:26 +02003669 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303670 }
3671
Peter Huewe599801f2012-02-09 21:11:45 +01003672 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303673 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003674 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303675 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303676}
3677
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003678static void XGI_SetLCDRegs(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303679 struct vb_device_info *pVBInfo)
3680{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003681 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3682 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303683
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003684 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303685
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003686 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303687 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3688 return;
3689
3690 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3691
3692 if (XGI_IsLCDDualLink(pVBInfo))
3693 tempbx = tempbx >> 1;
3694
3695 tempbx -= 1;
3696 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003697 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303698 temp = (tempbx & 0xFF00) >> 8;
3699 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003700 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303701 temp = 0x01;
3702
Aaro Koskinen8104e322011-03-13 12:26:22 +02003703 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303704 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303705 tempbx--;
3706 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003707 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303708 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003709 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303710
3711 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303712 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003713 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303714 temp = (tempcx & 0xFF00) >> 8;
3715 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003716 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003717 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3718 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3719 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3720 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303721
Justin P. Mattock558f7582012-10-02 21:17:11 -07003722 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003723 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003724 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03003725 pVBInfo);
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003726 else
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003727 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03003728 pVBInfo);
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003729
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303730 tempah = pVBInfo->LCDResInfo;
3731 tempah &= PanelResInfo;
3732
Peter Huewe255aabd2012-02-09 21:11:44 +01003733 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303734 tempbx = 1024;
3735 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003736 } else if ((tempah == Panel_1280x1024) ||
3737 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303738 tempbx = 1280;
3739 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003740 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303741 tempbx = 1400;
3742 tempcx = 1050;
3743 } else {
3744 tempbx = 1600;
3745 tempcx = 1200;
3746 }
3747
3748 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3749 tempbx = pVBInfo->HDE;
3750 tempcx = pVBInfo->VDE;
3751 }
3752
3753 pushbx = tempbx;
3754 tempax = pVBInfo->VT;
3755 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3756 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3757 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3758 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3759 tempbx = pVBInfo->LCDVDES;
3760 tempcx += tempbx;
3761
3762 if (tempcx >= tempax)
3763 tempcx -= tempax; /* lcdvdes */
3764
3765 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003766 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303767 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003768 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303769 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3770 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3771 tempah = tempch;
3772 tempah = tempah << 3;
3773 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003774 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303775
3776 /* getlcdsync() */
3777 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3778 tempcx = tempbx;
3779 tempax = pVBInfo->VT;
3780 tempbx = pVBInfo->LCDVRS;
3781
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303782 tempcx += tempbx;
3783 if (tempcx >= tempax)
3784 tempcx -= tempax;
3785
3786 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003787 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303788 temp = (tempbx & 0xFF00) >> 8;
3789 temp = temp << 4;
3790 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003791 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303792 tempcx = pushbx;
3793 tempax = pVBInfo->HT;
3794 tempbx = pVBInfo->LCDHDES;
3795 tempbx &= 0x0FFF;
3796
3797 if (XGI_IsLCDDualLink(pVBInfo)) {
3798 tempax = tempax >> 1;
3799 tempbx = tempbx >> 1;
3800 tempcx = tempcx >> 1;
3801 }
3802
Peter Huewe6896b942012-02-09 21:11:46 +01003803 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303804 tempbx += 1;
3805
3806 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3807 tempbx += 1;
3808
3809 tempcx += tempbx;
3810
3811 if (tempcx >= tempax)
3812 tempcx -= tempax;
3813
3814 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003815 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303816 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003817 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303818 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003819 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303820 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003821 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303822
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303823 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3824 tempcx = tempax;
3825 tempax = pVBInfo->HT;
3826 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303827 if (XGI_IsLCDDualLink(pVBInfo)) {
3828 tempax = tempax >> 1;
3829 tempbx = tempbx >> 1;
3830 tempcx = tempcx >> 1;
3831 }
3832
Peter Huewe6896b942012-02-09 21:11:46 +01003833 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303834 tempbx += 1;
3835
3836 tempcx += tempbx;
3837
3838 if (tempcx >= tempax)
3839 tempcx -= tempax;
3840
3841 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003842 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303843
3844 temp = (tempbx & 0xFF00) >> 8;
3845 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003846 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303847 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003848 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303849
Peter Huewea3d675c2012-02-09 21:11:47 +01003850 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303851 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003852 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3853 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303854 | VB_XGI301C)) {
3855 temp = 0xC6;
3856 } else
3857 temp = 0xC4;
3858
Aaro Koskinen8104e322011-03-13 12:26:22 +02003859 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3860 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303861 }
3862
3863 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01003864 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3865 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303866 | VB_XGI301C)) {
3867 temp = 0x4F;
3868 } else
3869 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003870 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303871 }
3872 }
3873}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003874
3875/* --------------------------------------------------------------------- */
3876/* Function : XGI_GetTap4Ptr */
3877/* Input : */
3878/* Output : di -> Tap4 Reg. Setting Pointer */
3879/* Description : */
3880/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003881static struct XGI301C_Tap4TimingStruct const
3882*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003883{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303884 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003885 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303887 if (tempcx == 0) {
3888 tempax = pVBInfo->VGAHDE;
3889 tempbx = pVBInfo->HDE;
3890 } else {
3891 tempax = pVBInfo->VGAVDE;
3892 tempbx = pVBInfo->VDE;
3893 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003894
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003895 if (tempax <= tempbx)
3896 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303897 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003898 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)
4047 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004048
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304049 if (XGI_IsLCDDualLink(pVBInfo))
4050 tempbx = 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;
4110 temp = temp << 4;
4111 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)
4121 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304123 if (XGI_IsLCDDualLink(pVBInfo))
4124 tempax = 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;
4138 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))
4165 tempbx = tempbx >> 1;
4166 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)
4625 tempbl = 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];
4788 tempah = 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];
4802 tempah = 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);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005104 index = index >> pVBInfo->SelectCRT2Rate;
5105 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;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005225 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005226
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005227 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005228 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005229 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005230 pVBInfo->P3d4, 0x53) | 0x02));
5231
Peter Huewe9388ad92013-02-15 20:37:10 +01005232 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5233 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5234 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005235
Aaro Koskinen8104e322011-03-13 12:26:22 +02005236 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5237 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005238
Peter Huewe9388ad92013-02-15 20:37:10 +01005239 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005240 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005241
Peter Huewe9388ad92013-02-15 20:37:10 +01005242 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005243 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005244
Peter Huewe9388ad92013-02-15 20:37:10 +01005245 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005246 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005247 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005248 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005249
Aaro Koskinen8104e322011-03-13 12:26:22 +02005250 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005251
5252 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005253 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005254
5255 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005256 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005257 CRTCData[i]);
5258
5259 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005260 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005261 CRTCData[i]);
5262
5263 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005264 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005265 CRTCData[i]);
5266
Aaro Koskinen8104e322011-03-13 12:26:22 +02005267 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005268 & 0xE0));
5269
Aaro Koskinen8104e322011-03-13 12:26:22 +02005270 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5271 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5272 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005273
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005274 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005275
Ebru Akagunduzf88d8182013-10-07 22:25:28 +03005276 for (i = 0; i < 256 * 3; i++)
Peter Huewe771f3ee2013-02-15 20:37:13 +01005277 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005278
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005279 mdelay(1);
5280
5281 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005282 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005283
5284 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005285 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005286 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005287 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005288
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005289 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005290 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005291
Ebru Akagunduzf88d8182013-10-07 22:25:28 +03005292 for (i = 0; i < 256 * 3; i++)
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005293 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005294
Aaro Koskinen8104e322011-03-13 12:26:22 +02005295 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5296 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5297 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005298
Peter Huewe9388ad92013-02-15 20:37:10 +01005299 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005300 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005301 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005302}
5303
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005304static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5305 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005306 struct vb_device_info *pVBInfo)
5307{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005308 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005309
Peter Huewe6896b942012-02-09 21:11:46 +01005310 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5311 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinena2526d12013-05-29 23:59:10 +03005312 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Aaro Koskinend1724632013-05-29 23:59:09 +03005313 /* Power on */
5314 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005315
Aaro Koskinenb8e34b32013-05-29 23:59:08 +03005316 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
5317 SetCRT2ToRAMDAC)) {
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005318 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5319 tempah &= 0xDF;
5320 if (pVBInfo->VBInfo & SetInSlaveMode) {
5321 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
5322 tempah |= 0x20;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005323 }
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005324 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5325 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5326
5327 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5328
5329 if (!(tempah & 0x80))
5330 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5331 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005332 }
5333
Aaro Koskinena2526d12013-05-29 23:59:10 +03005334 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005335 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005336 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005337 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen056b5402013-05-29 23:59:11 +03005338 if (pVBInfo->VBInfo &
5339 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
5340 /* LVDS PLL power on */
5341 xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
5342 0x7F);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005343 /* LVDS Driver power on */
5344 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005345 }
5346 }
5347
5348 tempah = 0x00;
5349
5350 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5351 tempah = 0xc0;
5352
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005353 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5354 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5355 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5356 tempah = tempah & 0x40;
5357 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5358 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005359 }
5360 }
5361
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005362 /* EnablePart4_1F */
5363 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005364
Aaro Koskinenb053af12013-07-16 23:13:28 +03005365 XGI_DisableGatingCRT(pVBInfo);
Aaro Koskinend1724632013-05-29 23:59:09 +03005366 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005367 } /* 301 */
5368 else { /* LVDS */
5369 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005370 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005371 /* enable CRT2 */
5372 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005373
Peter Huewe9388ad92013-02-15 20:37:10 +01005374 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005375 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005376 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005377
Aaro Koskinendc505562011-03-13 12:26:26 +02005378 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005379 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005380 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005381}
5382
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005383static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5384 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005385 unsigned short ModeNo, unsigned short ModeIdIndex,
5386 struct vb_device_info *pVBInfo)
5387{
Aaro Koskinena1579612012-04-07 01:14:05 +03005388 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005389
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005390 XGI_SetSeqRegs(pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005391 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005392 XGI_SetCRTCRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005393 XGI_SetATTRegs(ModeIdIndex, pVBInfo);
Aaro Koskinena1579612012-04-07 01:14:05 +03005394 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005395 XGI_ClearExt1Regs(pVBInfo);
5396
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005397 if (HwDeviceExtension->jChipType == XG27) {
5398 if (pVBInfo->IF_DEF_LVDS == 0)
5399 XGI_SetDefaultVCLK(pVBInfo);
5400 }
5401
5402 temp = ~ProgrammingCRT2;
5403 pVBInfo->SetFlag &= temp;
5404 pVBInfo->SelectCRT2Rate = 0;
5405
Peter Huewe6896b942012-02-09 21:11:46 +01005406 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5407 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005408 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005409 | SetInSlaveMode)) {
5410 pVBInfo->SetFlag |= ProgrammingCRT2;
5411 }
5412 }
5413
5414 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5415 ModeIdIndex, pVBInfo);
5416 if (RefreshRateTableIndex != 0xFFFF) {
5417 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005418 XGI_SetCRT1CRTC(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005419 pVBInfo, HwDeviceExtension);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005420 XGI_SetCRT1DE(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005421 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5422 HwDeviceExtension, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005423 XGI_SetCRT1VCLK(ModeIdIndex, HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005424 RefreshRateTableIndex, pVBInfo);
5425 }
5426
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005427 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005428 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005429 if (temp & 0xA0) {
5430
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005431 if (HwDeviceExtension->jChipType == XG27)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005432 XGI_SetXG27CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005433 else
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005434 XGI_SetXG21CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005435
5436 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5437 RefreshRateTableIndex);
5438
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005439 xgifb_set_lcd(HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005440 pVBInfo, RefreshRateTableIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005441
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005442 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005443 xgifb_set_lvds(xgifb_info,
5444 HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005445 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005446 }
5447 }
5448
5449 pVBInfo->SetFlag &= (~ProgrammingCRT2);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005450 XGI_SetCRT1FIFO(HwDeviceExtension, pVBInfo);
5451 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeIdIndex,
5452 RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005453 XGI_LoadDAC(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005454}
5455
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005456unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5457 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005458 unsigned short ModeNo)
5459{
5460 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005461 struct vb_device_info VBINF;
5462 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005463 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005464
Aaro Koskinenee768752013-05-29 23:59:16 +03005465 if (HwDeviceExtension->jChipType >= XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005466 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005467
Aaro Koskinen56810a92013-01-21 02:57:47 +02005468 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005469
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005470 /* for x86 Linux, XG21 LVDS */
5471 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005472 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005473 pVBInfo->IF_DEF_LVDS = 1;
5474 }
5475 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005476 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5477 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005478 pVBInfo->IF_DEF_LVDS = 1;
5479 }
5480 }
5481
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005482 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005483 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005484 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005485 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005486
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005487 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005488 XGI_UnLockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005489
Aaro Koskinen334ab072013-07-16 23:13:30 +03005490 XGI_SearchModeID(ModeNo, &ModeIdIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005491
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005492 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinenb053af12013-07-16 23:13:28 +03005493 XGI_GetVBInfo(ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005494 XGI_GetTVInfo(ModeIdIndex, pVBInfo);
5495 XGI_GetLCDInfo(ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005496 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005497
Peter Huewee44adfd2013-02-03 22:54:39 +01005498 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5499 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005500 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005501 ModeIdIndex, pVBInfo);
5502
Peter Huewea3d675c2012-02-09 21:11:47 +01005503 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005504 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5505 HwDeviceExtension, pVBInfo);
5506 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005507 }
5508
Peter Huewe6896b942012-02-09 21:11:46 +01005509 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005510 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005511 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005512 case VB_CHIP_302:
5513 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5514 pVBInfo); /*add for CRT2 */
5515 break;
5516
5517 default:
5518 break;
5519 }
5520 }
5521
Aaro Koskinenb053af12013-07-16 23:13:28 +03005522 XGI_SetCRT2ModeRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005523 XGI_OEM310Setting(ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005524 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005525 } /* !XG20 */
5526 else {
5527 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005528 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Aaro Koskinen334ab072013-07-16 23:13:30 +03005529 ModeIdIndex))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005530 return 0;
5531
Aaro Koskinenb3979922012-11-04 21:14:52 +02005532 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005533 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005534
5535 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005536 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005537
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005538 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005539
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005540 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5541 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005542
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005543 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005544 }
5545
Aaro Koskinenb053af12013-07-16 23:13:28 +03005546 XGI_UpdateModeInfo(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005547
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005548 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005549 XGI_LockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005550
5551 return 1;
5552}