blob: 65eea6587cc70b64a3f6eee36e0a6f9724fef90a [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
Kenji Toyama1d7f6562011-04-23 19:36:49 +080066static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080067 unsigned short ModeIdIndex,
68 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020069{
Peter Huewe76a58992013-02-03 22:54:34 +010070 unsigned char SRdata, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020071
Aaro Koskinen8104e322011-03-13 12:26:22 +020072 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020073
Peter Huewe76a58992013-02-03 22:54:34 +010074 for (i = 0; i < 4; i++) {
75 /* Get SR1,2,3,4 from file */
76 /* SR1 is with screen off 0x20 */
77 SRdata = XGI330_StandTable.SR[i];
78 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053079 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020080}
81
Aaro Koskinen063b9c42011-03-08 22:16:13 +020082static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080083 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020084{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053085 unsigned char CRTCdata;
86 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020087
Peter Huewe9388ad92013-02-15 20:37:10 +010088 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053089 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +020090 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053092 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080093 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020094 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +020095 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053096 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020097}
98
Kenji Toyama1d7f6562011-04-23 19:36:49 +080099static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800100 unsigned short ModeIdIndex,
101 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200102{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530103 unsigned char ARdata;
104 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200105
Aaro Koskinenb3979922012-11-04 21:14:52 +0200106 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200107
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530108 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200109 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200110
111 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
112 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
113 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300114 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200115 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300116 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530117 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530118 }
119 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200120
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200121 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200122 outb(i, pVBInfo->P3c0); /* set index */
123 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530124 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200125
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200126 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200127 outb(0x14, pVBInfo->P3c0); /* set index */
128 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200129 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200130 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200131}
132
Aaro Koskinena1579612012-04-07 01:14:05 +0300133static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200134{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530135 unsigned char GRdata;
136 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530138 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800139 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200140 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200141 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530142 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530144 if (pVBInfo->ModeType > ModeVGA) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100145 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530146 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200147 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530148 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200149}
150
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200151static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200152{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530153 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200154
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530155 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200156 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200157}
158
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200159static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200160{
161
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200162 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200163 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
164 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200165
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200166 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200167 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
168 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200169
Aaro Koskinendc505562011-03-13 12:26:26 +0200170 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530171 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200172}
173
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200174static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530175 unsigned short ModeIdIndex,
176 unsigned short RefreshRateTableIndex, unsigned short *i,
177 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200178{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530179 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200180
Aaro Koskinenb3979922012-11-04 21:14:52 +0200181 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
182 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200183 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530184 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200185
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300186 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
187 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200188
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300189 if (pVBInfo->VBType & VB_XGI301C)
190 tempax |= SupportCRT2in301C;
191 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200192
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300193 /* 301b */
194 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300195 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200196
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300197 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
198 pVBInfo->LCDResInfo != Panel_1280x960 &&
199 (pVBInfo->LCDInfo & LCDNonExpanding) &&
200 resinfo >= 9)
201 return 0;
202 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200203
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300204 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
205 tempax |= SupportHiVision;
206 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
207 ((resinfo == 4) ||
208 (resinfo == 3 && (pVBInfo->SetFlag & TVSimuMode)) ||
209 (resinfo > 7)))
210 return 0;
211 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO | SetCRT2ToSVIDEO |
212 SetCRT2ToSCART | SetCRT2ToYPbPr525750 |
213 SetCRT2ToHiVision)) {
214 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200215
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300216 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
217 VB_SIS302LV | VB_XGI301C))
218 tempax |= SupportTV1024;
219
220 if (!(pVBInfo->VBInfo & TVSetPAL) &&
221 (modeflag & NoSupportSimuTV) &&
222 (pVBInfo->VBInfo & SetInSlaveMode) &&
223 (!(pVBInfo->VBInfo & SetNotSimuMode)))
224 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530225 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200226
Aaro Koskinena39325d2012-11-04 21:14:53 +0200227 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800228 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200229 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800230 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530231 if (infoflag & tempax)
232 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530234 if ((*i) == 0)
235 break;
236 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530238 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200239 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800240 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200241 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530242 != tempbx) {
243 return 0;
244 }
245
246 if (infoflag & tempax)
247 return 1;
248 }
249 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200250}
251
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200252static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530253 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200254{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530255 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200256
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800257 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200258 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530259 sync &= 0xC0;
260 temp = 0x2F;
261 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200262 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200263}
264
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200265static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530266 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200267{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530268 unsigned char data, data1, pushax;
269 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200270
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800271 /* unlock cr0-7 */
Peter Huewe9388ad92013-02-15 20:37:10 +0100272 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530273 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200274 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200275
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200276 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200277 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200278
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530279 for (i = 0x01; i <= 0x04; 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->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530282 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200283
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530284 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200285 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200286 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530287 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200288
Peter Huewe9388ad92013-02-15 20:37:10 +0100289 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530290 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200291 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530292 data &= 0xE0;
293 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200294 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200295
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530296 if (HwDeviceExtension->jChipType >= XG20) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100297 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530298 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200299 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100300 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530301 data1 = data;
302 data1 &= 0xE0;
303 data &= 0x1F;
304 if (data == 0) {
305 pushax = data;
Peter Huewe9388ad92013-02-15 20:37:10 +0100306 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530307 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200308 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530309 data = pushax;
310 }
311 data = data - 1;
312 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200313 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100314 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530315 data = data >> 5;
316 data = data + 3;
317 if (data > 7)
318 data = data - 7;
319 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200320 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530321 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200322}
323
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800324static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
325 unsigned short ModeNo,
326 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200327{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530328 unsigned char data;
329 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530331 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200332 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200333 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530334 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530336 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200337 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200338 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530339 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530341 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200342 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200343 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530344 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200345
Peter Huewe9388ad92013-02-15 20:37:10 +0100346 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530347 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200348 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530349 data &= 0x3F;
350 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200351 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200352
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200353 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530354 data &= 0x80;
355 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200356
Aaro Koskinenb3979922012-11-04 21:14:52 +0200357 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530358 i &= DoubleScanMode;
359 if (i)
360 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200361
Peter Huewe9388ad92013-02-15 20:37:10 +0100362 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530363 j &= 0x5F;
364 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200365 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200366}
367
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200368static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
369 unsigned short RefreshRateTableIndex,
370 struct vb_device_info *pVBInfo,
371 struct xgi_hw_device_info *HwDeviceExtension)
372{
373 unsigned char index, data;
374 unsigned short i;
375
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800376 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200377 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200378 index = index & IndexMask;
379
Peter Huewe9388ad92013-02-15 20:37:10 +0100380 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200381 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200382 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200383
384 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200385 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200386 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200387
388 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200389 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200390 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200391
392 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
393
394 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
395
396 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200397 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200398}
399
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200400/* --------------------------------------------------------------------- */
401/* Function : XGI_SetXG21CRTC */
402/* Input : Stand or enhance CRTC table */
403/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
404/* Description : Set LCD timing */
405/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200406static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530407 unsigned short RefreshRateTableIndex,
408 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200409{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300410 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530411 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200412
Aaro Koskinena39325d2012-11-04 21:14:53 +0200413 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300414 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200415 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300416 Tempcx = Tempax; /* Tempcx: HRS */
417 /* SR2E[7:0]->HRS */
418 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200419
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200420 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300421 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
422 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
423 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
424 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800425
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200426 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300427 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200428
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200429 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300430 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
431 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
432 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200433
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300434 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
435 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200436
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300437 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
438 if (Tempax < Tempcx) /* HRE < HRS */
439 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200440
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300441 Temp2 &= 0xFF;
442 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
443 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
444 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
445 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
446 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
447 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
448 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200449
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300450 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200451 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300452 Tempbx = Tempax; /* Tempbx: VRS */
453 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
454 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
455 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200456 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300457 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
458 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
459 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
460 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
461 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200462
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300463 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
464 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
465 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
466 Tempax &= 0x80;
467 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
468 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
469 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200470 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300471 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
472 Temp2 = Tempax;
473 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
474 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200475
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300476 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200477 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300478 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
479 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200480 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300481 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
482 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
483 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
484 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
485 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200486
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300487 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
488 if (Tempax < Temp3) /* VRE < VRS */
489 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200490
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300491 Temp2 &= 0xFF;
492 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
493 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
494 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
495 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
496 Tempbx = (unsigned char) Temp1;
497 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
498 Tempax &= 0x7F;
499 /* SR3F D[7:2]->VRE D[1:0]->VRS */
500 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200501}
502
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800503static void XGI_SetXG27CRTC(unsigned short ModeNo,
504 unsigned short ModeIdIndex,
505 unsigned short RefreshRateTableIndex,
506 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200507{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300508 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200509
Aaro Koskinena39325d2012-11-04 21:14:53 +0200510 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300511 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200512 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300513 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
514 /* SR2E[7:0]->HRS */
515 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200516
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300517 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200518 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300519 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
520 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200521
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200522 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300523 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
524 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200525
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200526 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300527 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
528 Tempax <<= 3; /* Tempax[5]: HRE[5] */
529 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200530
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300531 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
532 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200533
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300534 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200535 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300536 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
537 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
538 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200539
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200540 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300541 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
542 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
543 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
544 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
545 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
546 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200547
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300548 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200549 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300550 /* SR34[7:0]->VRS[7:0] */
551 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200552
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300553 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
554 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200555 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300556 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
557 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
558 Tempax >>= 2; /* Tempax[0]: VRS[8] */
559 /* SR35[0]: VRS[8] */
560 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
561 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
562 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
563 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200564 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300565 Tempax &= 0x08; /* SR0A[3] VRS[10] */
566 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200567
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300568 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200569 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300570 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
571 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200572 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300573 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
574 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
575 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
576 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
577 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
578 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200579
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300580 if (Tempbx <= Tempcx) /* VRE <= VRS */
581 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200582
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300583 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
584 Tempax = (Tempbx << 2) & 0xFF;
585 /* SR3F[7:2]:VRE[5:0] */
586 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
587 Tempax = Tempcx >> 8;
588 /* SR35[2:0]:VRS[10:8] */
589 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200590}
591
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200592static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
593{
594 unsigned char temp;
595
596 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
597 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
598 temp = (temp & 3) << 6;
599 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
600 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
601 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
602 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
603
604}
605
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300606static void xgifb_set_lcd(int chip_id,
607 struct vb_device_info *pVBInfo,
608 unsigned short RefreshRateTableIndex,
609 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200610{
Peter Huewee2e544c2013-02-03 04:08:46 +0100611 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200612
Aaro Koskinen8104e322011-03-13 12:26:22 +0200613 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
614 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
615 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
616 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300617
618 if (chip_id == XG27) {
Peter Huewee2e544c2013-02-03 04:08:46 +0100619 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
620 if ((temp & 0x03) == 0) { /* dual 12 */
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300621 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
622 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
623 }
624 }
625
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300626 if (chip_id == XG27) {
627 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530628 } else {
Peter Huewee2e544c2013-02-03 04:08:46 +0100629 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
630 if (temp & 0x01) {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300631 /* 18 bits FP */
632 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
633 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
634 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530635 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200636
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200637 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200638
Aaro Koskinendc505562011-03-13 12:26:26 +0200639 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
640 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200641
Peter Huewee2e544c2013-02-03 04:08:46 +0100642 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
643 if (temp & 0x4000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300644 /* Hsync polarity */
645 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Peter Huewee2e544c2013-02-03 04:08:46 +0100646 if (temp & 0x8000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300647 /* Vsync polarity */
648 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200649}
650
651/* --------------------------------------------------------------------- */
652/* Function : XGI_UpdateXG21CRTC */
653/* Input : */
654/* Output : CRT1 CRTC */
655/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
656/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800657static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
658 struct vb_device_info *pVBInfo,
659 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200660{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300661 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200662
Aaro Koskinendc505562011-03-13 12:26:26 +0200663 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300664 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200665 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300666 RES640x480x60))
667 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200668 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800669 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300670 index = 13;
671 else if (ModeNo == 0x2F)
672 index = 14;
673 else if (ModeNo == 0x50)
674 index = 15;
675 else if (ModeNo == 0x59)
676 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200677
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530678 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200679 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200680 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200681 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200682 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200683 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200684 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200685 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200686 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530687 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200688}
689
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200690static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530691 unsigned short ModeNo, unsigned short ModeIdIndex,
692 unsigned short RefreshRateTableIndex,
693 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200694{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400695 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200696
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530697 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200698
Aaro Koskinenb3979922012-11-04 21:14:52 +0200699 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200700
Aaro Koskinenb3979922012-11-04 21:14:52 +0200701 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinene8e6c752012-11-04 21:15:00 +0200702 tempax = XGI330_ModeResInfo[resindex].HTotal;
703 tempbx = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200704
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530705 if (modeflag & HalfDCLK)
706 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200707
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300708 if (modeflag & HalfDCLK)
709 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200710
Aaro Koskinena39325d2012-11-04 21:14:53 +0200711 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200712
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300713 if (temp & InterlaceMode)
714 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200715
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300716 if (modeflag & DoubleScanMode)
717 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200718
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530719 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200720
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530721 tempax /= tempcx;
722 tempax -= 1;
723 tempbx -= 1;
724 tempcx = tempax;
Peter Huewe9388ad92013-02-15 20:37:10 +0100725 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
726 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530727 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200728 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
729 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200730 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530731 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200732 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530733 tempax = 0;
734 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200735
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530736 if (tempbx & 0x01)
737 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200738
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530739 if (tempbx & 0x02)
740 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200741
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200742 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Peter Huewe9388ad92013-02-15 20:37:10 +0100743 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530744 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200745
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530746 if (tempbx & 0x04)
747 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200748
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200749 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200750 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200751}
752
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800753static void XGI_SetCRT1Offset(unsigned short ModeNo,
754 unsigned short ModeIdIndex,
755 unsigned short RefreshRateTableIndex,
756 struct xgi_hw_device_info *HwDeviceExtension,
757 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200758{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530759 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200760
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530761 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200762 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530763 temp = temp >> 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200764 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200765
Aaro Koskinena39325d2012-11-04 21:14:53 +0200766 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530767 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200768
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530769 if (temp2)
770 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200771
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530772 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200773
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530774 switch (temp2) {
775 case 0:
776 temp2 = 1;
777 break;
778 case 1:
779 temp2 = 2;
780 break;
781 case 2:
782 temp2 = 4;
783 break;
784 case 3:
785 temp2 = 4;
786 break;
787 case 4:
788 temp2 = 6;
789 break;
790 case 5:
791 temp2 = 8;
792 break;
793 default:
794 break;
795 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530797 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
798 temp = temp * temp2 + temp2 / 2;
799 else
800 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530802 /* SetOffset */
803 DisplayUnit = temp;
804 temp2 = temp;
805 temp = temp >> 8; /* ah */
806 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200807 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530808 i &= 0xF0;
809 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200810 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200811
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530812 temp = (unsigned char) temp2;
813 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200814 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530816 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200817 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530818 temp2 &= InterlaceMode;
819 if (temp2)
820 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530822 DisplayUnit = DisplayUnit << 5;
823 ah = (DisplayUnit & 0xff00) >> 8;
824 al = DisplayUnit & 0x00ff;
825 if (al == 0)
826 ah += 1;
827 else
828 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530830 if (HwDeviceExtension->jChipType >= XG20)
831 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
832 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200833
Aaro Koskinen8104e322011-03-13 12:26:22 +0200834 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200835}
836
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200837static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
838 unsigned short ModeIdIndex,
839 unsigned short RefreshRateTableIndex,
840 struct xgi_hw_device_info *HwDeviceExtension,
841 struct vb_device_info *pVBInfo)
842{
Peter Hueweef9a6b92013-02-03 04:08:43 +0100843 unsigned short VCLKIndex, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200844
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300845 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200846 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200847
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200848 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
849 if (pVBInfo->LCDResInfo != Panel_1024x768)
850 /* LCDXlat2VCLK */
851 VCLKIndex = VCLK108_2_315 + 5;
852 else
853 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
854 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
855 if (pVBInfo->SetFlag & RPLLDIV2XO)
856 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
857 else
858 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200859
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200860 if (pVBInfo->SetFlag & TVSimuMode) {
861 if (modeflag & Charx8Dot) {
862 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
863 } else {
864 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200865 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200866 }
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200867
868 /* 301lv */
869 if (pVBInfo->VBType & VB_SIS301LV) {
870 if (pVBInfo->SetFlag & RPLLDIV2XO)
871 VCLKIndex = YPbPr525iVCLK_2;
872 else
873 VCLKIndex = YPbPr525iVCLK;
874 }
875 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
876 if (pVBInfo->SetFlag & RPLLDIV2XO)
877 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
878 else
879 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
880 } else { /* for CRT2 */
881 /* di+Ext_CRTVCLK */
882 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
883 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200884 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200885
886 return VCLKIndex;
887}
888
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800889static void XGI_SetCRT1VCLK(unsigned short ModeNo,
890 unsigned short ModeIdIndex,
891 struct xgi_hw_device_info *HwDeviceExtension,
892 unsigned short RefreshRateTableIndex,
893 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200894{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400895 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530896 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200897
Aaro Koskinenb750f512013-05-29 23:59:05 +0300898 if ((pVBInfo->IF_DEF_LVDS == 0) &&
899 (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
900 VB_SIS302LV | VB_XGI301C)) &&
901 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530902 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
903 RefreshRateTableIndex, HwDeviceExtension,
904 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200905 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200906 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200907 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200908 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200909 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200910 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
911 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530912 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200913 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200914 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200915 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200916 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
917 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200918 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530919 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200920
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530921 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200922 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800923 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200924 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200925 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200926 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530927 index = data;
928 index &= 0xE0;
929 data &= 0x1F;
930 data = data << 1;
931 data += 1;
932 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200933 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530934 }
935 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200936}
937
Aaro Koskinene85f2032011-11-27 23:03:07 +0200938static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
939{
940 unsigned char temp;
941
942 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
943 temp = (temp & 1) << 6;
944 /* SR06[6] 18bit Dither */
945 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
946 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
947 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
948
949}
950
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200951static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530952 struct xgi_hw_device_info *HwDeviceExtension,
953 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200954{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530955 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200956
Aaro Koskinen58839b02011-03-13 12:26:23 +0200957 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530958 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200959 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200960
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300961 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
962 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
963 data &= 0xC0;
964 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
965 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
966 data |= 0x01;
967 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200968
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530969 if (HwDeviceExtension->jChipType == XG21)
970 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200971}
972
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200973static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
974 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
975 struct vb_device_info *pVBInfo)
976{
977 unsigned short data, data2 = 0;
978 short VCLK;
979
980 unsigned char index;
981
Aaro Koskinena39325d2012-11-04 21:14:53 +0200982 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300983 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200984 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200985
Aaro Koskinen58839b02011-03-13 12:26:23 +0200986 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200987 data &= 0xf3;
988 if (VCLK >= 200)
989 data |= 0x0c; /* VCLK > 200 */
990
991 if (HwDeviceExtension->jChipType >= XG20)
992 data &= ~0x04; /* 2 pixel mode */
993
Aaro Koskinen8104e322011-03-13 12:26:22 +0200994 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200995
996 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200997 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200998 data &= 0xE7;
999 if (VCLK < 200)
1000 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001001 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001002 }
1003
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001004 data2 = 0x00;
1005
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001006 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001007 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001008 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001009
1010}
1011
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001012static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301013 unsigned short ModeNo, unsigned short ModeIdIndex,
1014 unsigned short RefreshRateTableIndex,
1015 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001016{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301017 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1018 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001019
Aaro Koskinenb3979922012-11-04 21:14:52 +02001020 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001021 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001022
Aaro Koskinen58839b02011-03-13 12:26:23 +02001023 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001024 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001025
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001026 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301027 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001028 data2 |= 0x02;
1029 data3 = pVBInfo->ModeType - ModeVGA;
1030 data3 = data3 << 2;
1031 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301032 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301034 if (data)
1035 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001036
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001037 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001038 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001039 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301041 data = 0x0000;
1042 if (infoflag & InterlaceMode) {
1043 if (xres == 1024)
1044 data = 0x0035;
1045 else if (xres == 1280)
1046 data = 0x0048;
1047 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001048
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001049 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1050 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301052 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001053 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301055 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001056
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301057 if (modeflag & LineCompareOff)
1058 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001059
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001060 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301061 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001062 data = data ^ 0x60;
1063 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001064 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001065
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301066 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1067 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001068
Aaro Koskinen58839b02011-03-13 12:26:23 +02001069 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301071 if (HwDeviceExtension->jChipType == XG27) {
1072 if (data & 0x40)
1073 data = 0x2c;
1074 else
1075 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001076 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001077 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301078 } else if (HwDeviceExtension->jChipType >= XG20) {
1079 if (data & 0x40)
1080 data = 0x33;
1081 else
1082 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001083 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1084 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301085 } else {
1086 if (data & 0x40)
1087 data = 0x2c;
1088 else
1089 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001090 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301091 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001092
1093}
1094
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001095static void XGI_WriteDAC(unsigned short dl,
1096 unsigned short ah,
1097 unsigned short al,
1098 unsigned short dh,
1099 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001100{
1101 unsigned short temp, bh, bl;
1102
1103 bh = ah;
1104 bl = al;
1105
1106 if (dl != 0) {
1107 temp = bh;
1108 bh = dh;
1109 dh = temp;
1110 if (dl == 1) {
1111 temp = bl;
1112 bl = dh;
1113 dh = temp;
1114 } else {
1115 temp = bl;
1116 bl = bh;
1117 bh = temp;
1118 }
1119 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001120 outb((unsigned short) dh, pVBInfo->P3c9);
1121 outb((unsigned short) bh, pVBInfo->P3c9);
1122 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001123}
1124
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001125static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301126 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001127{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001128 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1129 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001130
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001131 outb(0xFF, pVBInfo->P3c6);
1132 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001133
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001134 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301135 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301137 for (k = 0; k < 3; k++) {
1138 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301140 if (data & 0x01)
1141 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001142
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301143 if (data & 0x02)
1144 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001145
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001146 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301147 data = data >> 2;
1148 }
1149 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001150
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001151 for (i = 16; i < 32; i++) {
1152 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001153
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001154 for (k = 0; k < 3; k++)
1155 outb(data, pVBInfo->P3c9);
1156 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001157
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001158 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001159
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001160 for (m = 0; m < 9; m++) {
1161 di = si;
1162 bx = si + 0x04;
1163 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001164
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001165 for (n = 0; n < 3; n++) {
1166 for (o = 0; o < 5; o++) {
1167 dh = table[si];
1168 ah = table[di];
1169 al = table[bx];
1170 si++;
1171 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301172 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001173
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001174 si -= 2;
1175
1176 for (o = 0; o < 3; o++) {
1177 dh = table[bx];
1178 ah = table[di];
1179 al = table[si];
1180 si--;
1181 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1182 }
1183
1184 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301185 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001186
1187 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301188 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001189}
1190
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001191static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1192 unsigned short ModeIdIndex,
1193 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001194{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301195 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001196
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001197 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001198 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001199
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001200 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001201 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001202
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001203 xres = XGI330_ModeResInfo[resindex].HTotal;
1204 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001205
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001206 if (modeflag & HalfDCLK)
1207 xres = xres << 1;
1208
1209 if (modeflag & DoubleScanMode)
1210 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001211
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301212 if (xres == 720)
1213 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301215 pVBInfo->VGAHDE = xres;
1216 pVBInfo->HDE = xres;
1217 pVBInfo->VGAVDE = yres;
1218 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001219}
1220
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001221static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001222 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001223 unsigned short ModeIdIndex,
1224 unsigned short RefreshRateTableIndex,
1225 struct vb_device_info *pVBInfo)
1226{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001227 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001228
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001229 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001230
Aaro Koskinenb3979922012-11-04 21:14:52 +02001231 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001232
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001233 i = 0;
1234
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001235 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001236 tempdx = pVBInfo->LCDResInfo;
1237 if (tempbx & 0x0080) { /* OEMUtil */
1238 tempbx &= (~0x0080);
1239 tempdx = pVBInfo->LCDTypeInfo;
1240 }
1241
1242 if (pVBInfo->LCDInfo & EnableScalingLCD)
1243 tempdx &= (~PanelResInfo);
1244
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001245 if (table[i].PANELID == tempdx) {
1246 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001247 tempdx = pVBInfo->LCDInfo;
1248
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001249 if (modeflag & HalfDCLK)
1250 tempdx |= SetLCDLowResolution;
1251
1252 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001253 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001254 break;
1255 }
1256 i++;
1257 }
1258
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001259 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001260}
1261
Aaro Koskinen24572542012-09-11 00:15:21 +03001262static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001263 unsigned short ModeIdIndex,
1264 unsigned short RefreshRateTableIndex,
1265 struct vb_device_info *pVBInfo)
1266{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001267 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001268
Aaro Koskinenb3979922012-11-04 21:14:52 +02001269 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001270 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001271 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001272 tempdx = pVBInfo->TVInfo;
1273
1274 if (pVBInfo->VBInfo & SetInSlaveMode)
1275 tempdx = tempdx | SetTVLockMode;
1276
1277 if (modeflag & HalfDCLK)
1278 tempdx = tempdx | SetTVLowResolution;
1279
1280 i = 0;
1281
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001282 while (XGI_TVDataTable[i].MASK != 0xffff) {
1283 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1284 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001285 break;
1286 i++;
1287 }
1288
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001289 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001290}
1291
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001292static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301293 unsigned short RefreshRateTableIndex,
1294 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001295{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001296 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001297
Aaro Koskinen6008f872012-11-04 21:14:49 +02001298 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1299 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001300
Aaro Koskinen6008f872012-11-04 21:14:49 +02001301 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1302 RefreshRateTableIndex, pVBInfo);
1303 pVBInfo->VGAHT = LCDPtr->VGAHT;
1304 pVBInfo->VGAVT = LCDPtr->VGAVT;
1305 pVBInfo->HT = LCDPtr->LCDHT;
1306 pVBInfo->VT = LCDPtr->LCDVT;
1307
1308 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1309 return;
1310
1311 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1312 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1313 pVBInfo->HDE = 1024;
1314 pVBInfo->VDE = 768;
1315 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1316 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1317 pVBInfo->HDE = 1280;
1318 pVBInfo->VDE = 1024;
1319 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1320 pVBInfo->HDE = 1400;
1321 pVBInfo->VDE = 1050;
1322 } else {
1323 pVBInfo->HDE = 1600;
1324 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301325 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001326}
1327
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001328static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301329 unsigned short RefreshRateTableIndex,
1330 struct xgi_hw_device_info *HwDeviceExtension,
1331 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001332{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001333 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001334 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1335 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001336
Peter Huewea3d675c2012-02-09 21:11:47 +01001337 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001338 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001339 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001340
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001341 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001342 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301343 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001344
1345 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1346
Peter Huewea3d675c2012-02-09 21:11:47 +01001347 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001348 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1349 ModeIdIndex, RefreshRateTableIndex,
1350 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001351 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001352 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001353 }
1354
1355 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001356}
1357
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001358static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1359{
1360 unsigned char tempal, tempah, tempbl, i;
1361
Aaro Koskinen58839b02011-03-13 12:26:23 +02001362 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001363 tempal = tempah & 0x0F;
1364 tempah = tempah & 0xF0;
1365 i = 0;
1366 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1367
1368 while (tempbl != 0xFF) {
1369 if (tempbl & 0x80) { /* OEMUtil */
1370 tempal = tempah;
1371 tempbl = tempbl & ~(0x80);
1372 }
1373
1374 if (tempal == tempbl)
1375 break;
1376
1377 i++;
1378
1379 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1380 }
1381
1382 return i;
1383}
1384
1385static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1386{
1387 unsigned short tempah, tempal, tempbl, i;
1388
1389 tempal = pVBInfo->LCDResInfo;
1390 tempah = pVBInfo->LCDTypeInfo;
1391
1392 i = 0;
1393 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1394
1395 while (tempbl != 0xFF) {
1396 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1397 tempal = tempah;
1398 tempbl &= ~0x80;
1399 }
1400
1401 if (tempal == tempbl)
1402 break;
1403
1404 i++;
1405 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1406 }
1407
1408 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001409 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001410 pVBInfo->LCDTypeInfo = 0;
1411 i = 0;
1412 }
1413
1414 return i;
1415}
1416
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001417static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1418 unsigned short *VSyncWidth,
1419 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001420{
1421 unsigned short Index;
1422
1423 Index = XGI_GetLCDCapPtr(pVBInfo);
1424 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1425 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1426
1427 return;
1428}
1429
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001430static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301431 unsigned short RefreshRateTableIndex,
1432 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001433{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301434 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1435 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001436 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001437
Aaro Koskinenb3979922012-11-04 21:14:52 +02001438 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe826215d2013-02-05 00:29:46 +01001439 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo, ModeIdIndex,
1440 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001441
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001442 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1443 push1 = tempbx;
1444 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001445
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001446 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001447 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1448 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001449 tempax = 1024;
1450 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001451 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1452 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001453 tempax = 1280;
1454 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001455 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001456 tempax = 1400;
1457 tempbx = 1050;
1458 } else {
1459 tempax = 1600;
1460 tempbx = 1200;
1461 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001462
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001463 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1464 pVBInfo->HDE = tempax;
1465 pVBInfo->VDE = tempbx;
1466 pVBInfo->VGAHDE = tempax;
1467 pVBInfo->VGAVDE = tempbx;
1468 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001469
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001470 tempax = pVBInfo->HT;
1471
Peter Huewe826215d2013-02-05 00:29:46 +01001472 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001473
1474 tempcx = pVBInfo->HDE;
1475 tempbx = tempbx & 0x0fff;
1476 tempcx += tempbx;
1477
1478 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001479 tempcx -= tempax;
1480
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001481 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001482
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001483 tempcx = tempcx >> 3;
1484 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001485
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001486 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1487 (unsigned short) (tempbx & 0xff));
1488 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1489 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001490
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001491 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001492
Peter Huewe826215d2013-02-05 00:29:46 +01001493 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001494
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001495 tempcx = push2;
1496
1497 if (pVBInfo->LCDInfo & EnableScalingLCD)
1498 tempcx = LCDPtr1->LCDHSync;
1499
1500 tempcx += tempbx;
1501
1502 if (tempcx >= tempax)
1503 tempcx -= tempax;
1504
1505 tempax = tempbx & 0x07;
1506 tempax = tempax >> 5;
1507 tempcx = tempcx >> 3;
1508 tempbx = tempbx >> 3;
1509
1510 tempcx &= 0x1f;
1511 tempax |= tempcx;
1512
1513 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1514 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1515 (unsigned short) (tempbx & 0xff));
1516
1517 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001518 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001519 tempcx = pVBInfo->VDE;
1520
1521 tempbx = tempbx & 0x0fff;
1522 tempcx += tempbx;
1523 if (tempcx >= tempax)
1524 tempcx -= tempax;
1525
1526 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1527 (unsigned short) (tempbx & 0xff));
1528 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1529 (unsigned short) (tempcx & 0xff));
1530
1531 tempbx = (tempbx >> 8) & 0x07;
1532 tempcx = (tempcx >> 8) & 0x07;
1533
1534 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1535 (unsigned short) ((tempcx << 3)
1536 | tempbx));
1537
1538 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001539 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001540
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001541 tempcx = push1;
1542
1543 if (pVBInfo->LCDInfo & EnableScalingLCD)
1544 tempcx = LCDPtr1->LCDVSync;
1545
1546 tempcx += tempbx;
1547 if (tempcx >= tempax)
1548 tempcx -= tempax;
1549
1550 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1551 (unsigned short) (tempbx & 0xff));
1552 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1553 (unsigned short) (tempcx & 0x0f));
1554
1555 tempax = ((tempbx >> 8) & 0x07) << 3;
1556
1557 tempbx = pVBInfo->VGAVDE;
1558 if (tempbx != pVBInfo->VDE)
1559 tempax |= 0x40;
1560
Peter Huewea3d675c2012-02-09 21:11:47 +01001561 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001562 tempax |= 0x40;
1563
1564 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1565 tempax);
1566
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001567 tempbx = pVBInfo->VDE;
1568 tempax = pVBInfo->VGAVDE;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001569
1570 temp = tempax; /* 0430 ylshieh */
1571 temp1 = (temp << 18) / tempbx;
1572
1573 tempdx = (unsigned short) ((temp << 18) % tempbx);
1574
1575 if (tempdx != 0)
1576 temp1 += 1;
1577
1578 temp2 = temp1;
1579 push3 = temp2;
1580
1581 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1582 (unsigned short) (temp2 & 0xff));
1583 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1584 (unsigned short) ((temp2 >> 8) & 0xff));
1585
1586 tempbx = (unsigned short) (temp2 >> 16);
1587 tempax = tempbx & 0x03;
1588
1589 tempbx = pVBInfo->VGAVDE;
1590 if (tempbx == pVBInfo->VDE)
1591 tempax |= 0x04;
1592
1593 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1594
1595 if (pVBInfo->VBType & VB_XGI301C) {
1596 temp2 = push3;
1597 xgifb_reg_set(pVBInfo->Part4Port,
1598 0x3c,
1599 (unsigned short) (temp2 & 0xff));
1600 xgifb_reg_set(pVBInfo->Part4Port,
1601 0x3b,
1602 (unsigned short) ((temp2 >> 8) &
1603 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001604 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001605 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1606 ~0xc0,
1607 (unsigned short) ((tempbx &
1608 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001609
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001610 tempcx = pVBInfo->VGAVDE;
1611 if (tempcx == pVBInfo->VDE)
1612 xgifb_reg_and_or(pVBInfo->Part4Port,
1613 0x30, ~0x0c, 0x00);
1614 else
1615 xgifb_reg_and_or(pVBInfo->Part4Port,
1616 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301617 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001618
1619 tempcx = pVBInfo->VGAHDE;
1620 tempbx = pVBInfo->HDE;
1621
1622 temp1 = tempcx << 16;
1623
1624 tempax = (unsigned short) (temp1 / tempbx);
1625
1626 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1627 tempax = 65535;
1628
1629 temp3 = tempax;
1630 temp1 = pVBInfo->VGAHDE << 16;
1631
1632 temp1 /= temp3;
1633 temp3 = temp3 << 16;
1634 temp1 -= 1;
1635
1636 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1637
1638 tempax = (unsigned short) (temp3 & 0xff);
1639 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1640
1641 temp1 = pVBInfo->VGAVDE << 18;
1642 temp1 = temp1 / push3;
1643 tempbx = (unsigned short) (temp1 & 0xffff);
1644
Peter Huewe255aabd2012-02-09 21:11:44 +01001645 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001646 tempbx -= 1;
1647
1648 tempax = ((tempbx >> 8) & 0xff) << 3;
1649 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1650 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1651 (unsigned short) (tempax & 0xff));
1652 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1653 (unsigned short) (tempbx & 0xff));
1654
1655 temp3 = temp3 >> 16;
1656
1657 if (modeflag & HalfDCLK)
1658 temp3 = temp3 >> 1;
1659
1660 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1661 (unsigned short) ((temp3 >> 8) & 0xff));
1662 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1663 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001664}
1665
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001666/* --------------------------------------------------------------------- */
1667/* Function : XGI_GETLCDVCLKPtr */
1668/* Input : */
1669/* Output : al -> VCLK Index */
1670/* Description : */
1671/* --------------------------------------------------------------------- */
1672static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1673 struct vb_device_info *pVBInfo)
1674{
1675 unsigned short index;
1676
Peter Huewea3d675c2012-02-09 21:11:47 +01001677 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001678 index = XGI_GetLCDCapPtr1(pVBInfo);
1679
1680 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1681 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1682 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1683 } else { /* LCDA */
1684 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1685 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1686 }
1687 }
1688 return;
1689}
1690
1691static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1692 unsigned short ModeNo, unsigned short ModeIdIndex,
1693 struct vb_device_info *pVBInfo)
1694{
1695
1696 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001697 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001698
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001699 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001700 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001701
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001702 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1703 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001704 index = XGI_GetLCDCapPtr(pVBInfo);
1705 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1706
Peter Huewea3d675c2012-02-09 21:11:47 +01001707 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001708 return tempal;
1709
1710 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001711 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001712 (VB_SIS301B |
1713 VB_SIS302B |
1714 VB_SIS301LV |
1715 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001716 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001717 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001718 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001719 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001720 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001721 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001722 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001723 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001724 tempal = TVCLKBASE_315 +
1725 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001726
1727 }
1728 return tempal;
1729 }
1730
Peter Huewe599801f2012-02-09 21:11:45 +01001731 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001732 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001733 return tempal;
1734 }
1735
Peter Huewe599801f2012-02-09 21:11:45 +01001736 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001737 tempal = YPbPr525pVCLK;
1738 return tempal;
1739 }
1740
1741 tempal = NTSC1024VCLK;
1742
1743 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001744 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001745 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001746 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001747 }
1748
1749 if (pVBInfo->VBInfo & SetCRT2ToTV)
1750 return tempal;
1751 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001752 } /* {End of VB} */
1753
Peter Huewe516354e2013-02-15 20:37:11 +01001754 inb((pVBInfo->P3ca + 0x02));
Aaro Koskinena39325d2012-11-04 21:14:53 +02001755 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001756 return tempal;
1757}
1758
1759static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1760 unsigned char *di_1, struct vb_device_info *pVBInfo)
1761{
Peter Huewe6896b942012-02-09 21:11:46 +01001762 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1763 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001764 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1765 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001766 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001767 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001768 }
1769 } else {
1770 *di_0 = XGI_VCLKData[tempal].SR2B;
1771 *di_1 = XGI_VCLKData[tempal].SR2C;
1772 }
1773}
1774
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001775static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301776 unsigned short RefreshRateTableIndex,
1777 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001778{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301779 unsigned char di_0, di_1, tempal;
1780 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001781
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301782 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1783 pVBInfo);
1784 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1785 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001786
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301787 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001788 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301789 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001790 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301791 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001792 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1793 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301794 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001795 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1796 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301797 }
1798 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001799}
1800
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001801static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301802 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001803{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301804 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001805
Peter Huewe6896b942012-02-09 21:11:46 +01001806 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1807 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301808 tempcl = 0;
1809 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001810 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001811
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301812 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001813 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301814 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001815 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301816 if (!(temp & 0x40))
1817 tempcl |= ActiveCRT1;
1818 }
1819 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001820
Aaro Koskinen58839b02011-03-13 12:26:23 +02001821 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301822 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001823
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301824 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001825 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001826 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301827 if (tempax & 0x04)
1828 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301830 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001831
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301832 if (!(tempcl & ActiveLCD))
1833 if (temp == 0x01)
1834 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301836 if (temp == 0x04)
1837 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001838
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301839 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001840 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001841
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301842 if (!(temp & 0x08))
1843 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001844
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301845 if (!(temp & 0x04))
1846 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301848 if (temp & 0x02)
1849 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001850
Peter Huewe599801f2012-02-09 21:11:45 +01001851 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301852 if (temp & 0x01)
1853 tempch |= ActiveHiTV;
1854 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001855
Peter Huewe599801f2012-02-09 21:11:45 +01001856 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001857 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301858 pVBInfo->Part2Port,
1859 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001860
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301861 if (temp & 0x10)
1862 tempch |= ActiveYPbPr;
1863 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001864
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301865 if (tempch != 0)
1866 tempcl |= ActiveTV;
1867 }
1868 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001869
Aaro Koskinen58839b02011-03-13 12:26:23 +02001870 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301871 if (tempcl & ActiveLCD) {
1872 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1873 if (temp & ActiveTV)
1874 tempcl |= ActiveTV;
1875 }
1876 }
1877 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001878 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001879 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001880
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301881 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001882 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301883 } else {
1884 return;
1885 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001886}
1887
Bill Pemberton80adad82010-06-17 13:10:51 -04001888void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001889{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301890 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001891
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001892 tempbx = VB_SIS302B;
1893 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1894 if (flag == 0x02)
1895 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001896
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001897 tempbx = VB_SIS301;
1898 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1899 if (flag < 0xB0)
1900 goto finish;
1901
1902 tempbx = VB_SIS301B;
1903 if (flag < 0xC0)
1904 goto bigger_than_0xB0;
1905
1906 tempbx = VB_XGI301C;
1907 if (flag < 0xD0)
1908 goto bigger_than_0xB0;
1909
1910 tempbx = VB_SIS301LV;
1911 if (flag < 0xE0)
1912 goto bigger_than_0xB0;
1913
1914 tempbx = VB_SIS302LV;
1915 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1916 if (tempah != 0xFF)
1917 tempbx = VB_XGI301C;
1918
1919bigger_than_0xB0:
1920 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1921 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1922 if (!(flag & 0x02))
1923 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301924 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001925
1926finish:
1927 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001928}
1929
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02001930static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301931 struct xgi_hw_device_info *HwDeviceExtension,
1932 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001933{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301934 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001935
Aaro Koskinenb3979922012-11-04 21:14:52 +02001936 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301937 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001938 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301939 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001940
Miguel Gómezf9317352012-07-06 12:40:48 +02001941 if (!(pVBInfo->VBType & 0xFFFF))
1942 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001943
Miguel Gómezf9317352012-07-06 12:40:48 +02001944 /* Check Display Device */
1945 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1946 tempbx = tempbx | temp;
1947 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1948 push = temp;
1949 push = push << 8;
1950 tempax = temp << 8;
1951 tempbx = tempbx | tempax;
1952 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1953 | SetInSlaveMode | DisableCRT2Display);
1954 temp = 0xFFFF ^ temp;
1955 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001956
Miguel Gómezf9317352012-07-06 12:40:48 +02001957 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001958
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001959 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1960 VB_XGI301C)) {
1961 if (temp & EnableDualEdge) {
1962 tempbx |= SetCRT2ToDualEdge;
1963 if (temp & SetToLCDA)
1964 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02001965 }
1966 }
1967
1968 if (pVBInfo->IF_DEF_YPbPr == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001969 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
Miguel Gómezf9317352012-07-06 12:40:48 +02001970 if (temp & SetYPbPr) {
1971 if (pVBInfo->IF_DEF_HiVision == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001972 /* shampoo add for new scratch */
1973 temp = xgifb_reg_get(pVBInfo->P3d4,
1974 0x35);
Miguel Gómezf9317352012-07-06 12:40:48 +02001975 temp &= YPbPrMode;
1976 tempbx |= SetCRT2ToHiVision;
1977
1978 if (temp != YPbPrMode1080i) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001979 tempbx &= (~SetCRT2ToHiVision);
1980 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301981 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301982 }
1983 }
1984 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001985 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001986
Miguel Gómezf9317352012-07-06 12:40:48 +02001987 tempax = push; /* restore CR31 */
1988
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001989 if (pVBInfo->IF_DEF_YPbPr == 1) {
1990 if (pVBInfo->IF_DEF_HiVision == 1)
1991 temp = 0x09FC;
1992 else
1993 temp = 0x097C;
1994 } else if (pVBInfo->IF_DEF_HiVision == 1) {
1995 temp = 0x01FC;
1996 } else {
1997 temp = 0x017C;
Miguel Gómezf9317352012-07-06 12:40:48 +02001998 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001999
Miguel Gómezf9317352012-07-06 12:40:48 +02002000 if (!(tempbx & temp)) {
2001 tempax |= DisableCRT2Display;
2002 tempbx = 0;
2003 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002004
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002005 if (!(pVBInfo->VBType & VB_NoLCD)) {
2006 if (tempbx & XGI_SetCRT2ToLCDA) {
2007 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002008 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002009 SwitchCRT2));
2010 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002011 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
2012 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002013 }
2014 }
2015
2016 /* shampoo add */
2017 /* for driver abnormal */
2018 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2019 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2020 if (tempbx & SetCRT2ToRAMDAC) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002021 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
2022 SwitchCRT2 | SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002023 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302024 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002025 } else {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002026 tempbx &= (~(SetCRT2ToRAMDAC | SetCRT2ToLCD |
Miguel Gómezf9317352012-07-06 12:40:48 +02002027 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302028 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002029 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002030
Miguel Gómezf9317352012-07-06 12:40:48 +02002031 if (!(pVBInfo->VBType & VB_NoLCD)) {
2032 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002033 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002034 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002035 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302036 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002037 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002038
Miguel Gómezf9317352012-07-06 12:40:48 +02002039 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002040 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002041 SetSimuScanMode);
2042 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2043 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002044
Miguel Gómezf9317352012-07-06 12:40:48 +02002045 if (pVBInfo->IF_DEF_YPbPr == 1) {
2046 if (tempbx & SetCRT2ToYPbPr525750)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002047 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002048 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002049
Miguel Gómezf9317352012-07-06 12:40:48 +02002050 if (pVBInfo->IF_DEF_HiVision == 1) {
2051 if (tempbx & SetCRT2ToHiVision)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002052 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002053 SetSimuScanMode);
2054 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002055
Miguel Gómezf9317352012-07-06 12:40:48 +02002056 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2057 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2058 tempbx = DisableCRT2Display;
2059 }
2060
2061 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002062 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002063 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002064 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002065 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002066
Miguel Gómezf9317352012-07-06 12:40:48 +02002067 /* LCD+TV can't support in slave mode
2068 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002069 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2070 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002071 SetCRT2ToDualEdge);
2072 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302073 }
2074 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302076 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002077}
2078
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002079static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302080 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002081{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002082 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302084 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002085 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2086 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002087
Peter Huewe5fc699f2013-02-03 04:08:45 +01002088 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2089 if (tempbx & TVSetPAL) {
2090 tempbx &= (SetCHTVOverScan |
2091 TVSetPALM |
2092 TVSetPALN |
2093 TVSetPAL);
2094 if (tempbx & TVSetPALM)
2095 /* set to NTSC if PAL-M */
2096 tempbx &= ~TVSetPAL;
2097 } else
2098 tempbx &= (SetCHTVOverScan |
2099 TVSetNTSCJ |
2100 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002101
Aaro Koskinena8b35292013-02-09 00:03:45 +02002102 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2103 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302105 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002106 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002107 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302108 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002109
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302110 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002111 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302113 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002114 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302115 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002116 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302117 }
2118 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302120 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002121 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2122 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302123 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002124
Aaro Koskinena8b35292013-02-09 00:03:45 +02002125 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2126 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2127 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002128
Aaro Koskinena8b35292013-02-09 00:03:45 +02002129 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2130 /* NTSC 1024x768, */
2131 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002132
Aaro Koskinena8b35292013-02-09 00:03:45 +02002133 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002134
Aaro Koskinena8b35292013-02-09 00:03:45 +02002135 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2136 if (pVBInfo->VBInfo & SetInSlaveMode)
2137 tempbx &= (~RPLLDIV2XO);
2138 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2139 tempbx &= (~RPLLDIV2XO);
2140 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2141 VB_SIS301LV | VB_SIS302LV |
2142 VB_XGI301C))) {
2143 if (tempbx & TVSimuMode)
2144 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302145 }
2146 }
2147 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002148}
2149
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002150static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2151 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002152{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002153 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002154
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302155 pVBInfo->LCDResInfo = 0;
2156 pVBInfo->LCDTypeInfo = 0;
2157 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002158
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002159 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002160 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002161 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302162 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002163
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302164 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002165 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002166
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002167 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002168 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302169 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002170 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002171 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302172 tempax &= 0x0F;
2173 else
2174 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002175
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302176 if ((resinfo == 6) || (resinfo == 9)) {
2177 if (tempax >= 3)
2178 tempbx |= PanelRef75Hz;
2179 } else if ((resinfo == 7) || (resinfo == 8)) {
2180 if (tempax >= 4)
2181 tempbx |= PanelRef75Hz;
2182 }
2183 }
2184 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002185
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302186 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302188 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002189
Peter Huewea3d675c2012-02-09 21:11:47 +01002190 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302191 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302193 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002194
Aaro Koskinen58839b02011-03-13 12:26:23 +02002195 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002196
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302197 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302199 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002200
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302201 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002202
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302203 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002204
Aaro Koskinen718e7152013-02-09 00:03:46 +02002205 if (((pVBInfo->VBType & VB_SIS302LV) ||
2206 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2207 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002208
Aaro Koskinen718e7152013-02-09 00:03:46 +02002209 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2210 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2211 (!(tempbx & EnableScalingLCD)))
2212 /*
2213 * set to center in 1280x1024 LCDB
2214 * for Panel_1400x1050
2215 */
2216 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302218 if (pVBInfo->VBInfo & SetInSlaveMode) {
2219 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002220 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302221 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002222 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302223 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302225 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302227 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002228}
2229
Bill Pemberton108afbf2010-06-17 13:10:47 -04002230unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302231 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002232{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002233 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002234 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002235 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002236 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002237 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302238 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302240 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002241}
2242
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002243static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2244{
2245 unsigned char ujRet = 0;
2246 unsigned char i = 0;
2247
2248 for (i = 0; i < 8; i++) {
2249 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002250 ujRet |= (ujDate >> i) & 1;
2251 }
2252
2253 return ujRet;
2254}
2255
2256/*----------------------------------------------------------------------------*/
2257/* output */
2258/* bl[5] : LVDS signal */
2259/* bl[1] : LVDS backlight */
2260/* bl[0] : LVDS VDD */
2261/*----------------------------------------------------------------------------*/
2262static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2263{
2264 unsigned char CR4A, temp;
2265
Aaro Koskinen58839b02011-03-13 12:26:23 +02002266 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002267 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002268
Aaro Koskinen58839b02011-03-13 12:26:23 +02002269 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002270
2271 temp = XG21GPIODataTransfer(temp);
2272 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002273 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002274 return temp;
2275}
2276
2277/*----------------------------------------------------------------------------*/
2278/* output */
2279/* bl[5] : LVDS signal */
2280/* bl[1] : LVDS backlight */
2281/* bl[0] : LVDS VDD */
2282/*----------------------------------------------------------------------------*/
2283static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2284{
2285 unsigned char CR4A, CRB4, temp;
2286
Aaro Koskinen58839b02011-03-13 12:26:23 +02002287 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002288 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002289
Aaro Koskinen58839b02011-03-13 12:26:23 +02002290 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002291
2292 temp &= 0x0C;
2293 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002294 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002295 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002296 temp |= ((CRB4 & 0x04) << 3);
2297 return temp;
2298}
2299
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002300/*----------------------------------------------------------------------------*/
2301/* input */
2302/* bl[5] : 1;LVDS signal on */
2303/* bl[1] : 1;LVDS backlight on */
2304/* bl[0] : 1:LVDS VDD on */
2305/* bh: 100000b : clear bit 5, to set bit5 */
2306/* 000010b : clear bit 1, to set bit1 */
2307/* 000001b : clear bit 0, to set bit0 */
2308/*----------------------------------------------------------------------------*/
2309static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2310 struct vb_device_info *pVBInfo)
2311{
2312 unsigned char CR4A, temp;
2313
2314 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2315 tempbh &= 0x23;
2316 tempbl &= 0x23;
2317 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2318
2319 if (tempbh & 0x20) {
2320 temp = (tempbl >> 4) & 0x02;
2321
2322 /* CR B4[1] */
2323 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2324
2325 }
2326
2327 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2328
2329 temp = XG21GPIODataTransfer(temp);
2330 temp &= ~tempbh;
2331 temp |= tempbl;
2332 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2333}
2334
Aaro Koskinen776115a2011-11-27 23:03:10 +02002335static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2336 struct vb_device_info *pVBInfo)
2337{
2338 unsigned char CR4A, temp;
2339 unsigned short tempbh0, tempbl0;
2340
2341 tempbh0 = tempbh;
2342 tempbl0 = tempbl;
2343 tempbh0 &= 0x20;
2344 tempbl0 &= 0x20;
2345 tempbh0 >>= 3;
2346 tempbl0 >>= 3;
2347
2348 if (tempbh & 0x20) {
2349 temp = (tempbl >> 4) & 0x02;
2350
2351 /* CR B4[1] */
2352 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2353
2354 }
2355 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2356
2357 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2358 tempbh &= 0x03;
2359 tempbl &= 0x03;
2360 tempbh <<= 2;
2361 tempbl <<= 2; /* GPIOC,GPIOD */
2362 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2363 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2364}
2365
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002366static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2367 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302368 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002369{
2370
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002371 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302372 if (pXGIHWDE->jChipType == XG21) {
2373 if (pVBInfo->IF_DEF_LVDS == 1) {
2374 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002375 /* LVDS VDD on */
2376 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002377 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302378 }
2379 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002380 /* LVDS signal on */
2381 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002382 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002383 /* LVDS backlight on */
2384 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302385 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002386 /* DVO/DVI signal on */
2387 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302388 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002389
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302390 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002391
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302392 if (pXGIHWDE->jChipType == XG27) {
2393 if (pVBInfo->IF_DEF_LVDS == 1) {
2394 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002395 /* LVDS VDD on */
2396 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002397 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302398 }
2399 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002400 /* LVDS signal on */
2401 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002402 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002403 /* LVDS backlight on */
2404 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302405 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002406 /* DVO/DVI signal on */
2407 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302408 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002409
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302410 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002411}
2412
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002413void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2414 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302415 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002416{
2417
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302418 if (pXGIHWDE->jChipType == XG21) {
2419 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002420 /* LVDS backlight off */
2421 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002422 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302423 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002424 /* DVO/DVI signal off */
2425 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302426 }
2427 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002428
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302429 if (pXGIHWDE->jChipType == XG27) {
2430 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002431 /* LVDS backlight off */
2432 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002433 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302434 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002435
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302436 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002437 /* DVO/DVI signal off */
2438 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302439 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002440
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002441 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002442}
2443
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002444static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002445{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002446 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302447 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002448
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002449 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302450 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002451}
2452
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002453static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002454{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002455 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002456}
2457
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002458static void XGI_SaveCRT2Info(unsigned short ModeNo,
2459 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002460{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302461 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002462
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002463 /* reserve CR34 for CRT1 Mode No */
2464 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302465 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2466 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002467 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002468}
2469
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002470static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2471 unsigned short ModeIdIndex,
2472 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002473{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302474 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002475
Aaro Koskinenb3979922012-11-04 21:14:52 +02002476 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002477 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2478 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002479 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002480 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002481
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002482 if (modeflag & HalfDCLK)
2483 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002484
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002485 if (modeflag & DoubleScanMode)
2486 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002487
Miguel Gómez3339db82012-07-06 12:40:49 +02002488 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2489 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002490
Aaro Koskinen22006832013-02-09 00:03:47 +02002491 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2492 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2493 if (yres == 1024)
2494 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302495 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002496 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002497
Aaro Koskinen22006832013-02-09 00:03:47 +02002498 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2499 if (yres == 400)
2500 yres = 405;
2501 else if (yres == 350)
2502 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002503
Aaro Koskinen22006832013-02-09 00:03:47 +02002504 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2505 if (yres == 360)
2506 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002507 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002508 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002509
Aaro Koskinen22006832013-02-09 00:03:47 +02002510 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2511 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2512 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2513 if (yres == 350)
2514 yres = 357;
2515 else if (yres == 400)
2516 yres = 420;
2517 else if (yres == 480)
2518 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002519 }
2520 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302521 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002522
Miguel Gómez3339db82012-07-06 12:40:49 +02002523 if (xres == 720)
2524 xres = 640;
2525
2526exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302527 pVBInfo->VGAHDE = xres;
2528 pVBInfo->HDE = xres;
2529 pVBInfo->VGAVDE = yres;
2530 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002531}
2532
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002533static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002534{
2535
Peter Huewea3d675c2012-02-09 21:11:47 +01002536 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002537 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302538 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002539
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302540 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002541}
2542
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002543static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2544 unsigned short ModeIdIndex,
2545 unsigned short RefreshRateTableIndex,
2546 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002547{
2548 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002549 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002550
2551 pVBInfo->RVBHCMAX = 1;
2552 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002553 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002554 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002555 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002556 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2557 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002558 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002559 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002560 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002561 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002562 tempcx &= 0x0100;
2563 tempcx = tempcx << 2;
2564 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002565 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002566
2567 if (temp1 & 0x01)
2568 tempbx |= 0x0100;
2569
2570 if (temp1 & 0x20)
2571 tempbx |= 0x0200;
2572 tempax += 5;
2573
2574 if (modeflag & Charx8Dot)
2575 tempax *= 8;
2576 else
2577 tempax *= 9;
2578
2579 pVBInfo->VGAHT = tempax;
2580 pVBInfo->HT = tempax;
2581 tempbx++;
2582 pVBInfo->VGAVT = tempbx;
2583 pVBInfo->VT = tempbx;
2584}
2585
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002586static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302587 unsigned short RefreshRateTableIndex,
2588 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002589{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002590 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002591
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002592 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002593
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002594 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002595 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2596 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302597 pVBInfo->NewFlickerMode = 0;
2598 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002599
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302600 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2601 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2602 pVBInfo);
2603 return;
2604 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002605
Peter Huewea3d675c2012-02-09 21:11:47 +01002606 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002607 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002608 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002609
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302610 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2611 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2612 pVBInfo->VGAHT = LCDPtr->VGAHT;
2613 pVBInfo->VGAVT = LCDPtr->VGAVT;
2614 pVBInfo->HT = LCDPtr->LCDHT;
2615 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002616
Peter Huewe255aabd2012-02-09 21:11:44 +01002617 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302618 tempax = 1024;
2619 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002620
Peter Huewea3d675c2012-02-09 21:11:47 +01002621 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302622 if (pVBInfo->VGAVDE == 357)
2623 tempbx = 527;
2624 else if (pVBInfo->VGAVDE == 420)
2625 tempbx = 620;
2626 else if (pVBInfo->VGAVDE == 525)
2627 tempbx = 775;
2628 else if (pVBInfo->VGAVDE == 600)
2629 tempbx = 775;
Peter Huewe7580d7f2013-05-18 00:19:54 +02002630 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002631 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302632 tempax = 1024;
2633 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002634 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302635 tempax = 1280;
2636 if (pVBInfo->VGAVDE == 360)
2637 tempbx = 768;
2638 else if (pVBInfo->VGAVDE == 375)
2639 tempbx = 800;
2640 else if (pVBInfo->VGAVDE == 405)
2641 tempbx = 864;
2642 else
2643 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002644 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302645 tempax = 1280;
2646 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002647 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302648 tempax = 1280;
2649 if (pVBInfo->VGAVDE == 350)
2650 tempbx = 700;
2651 else if (pVBInfo->VGAVDE == 400)
2652 tempbx = 800;
2653 else if (pVBInfo->VGAVDE == 1024)
2654 tempbx = 960;
2655 else
2656 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002657 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302658 tempax = 1400;
2659 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002660
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302661 if (pVBInfo->VGAVDE == 1024) {
2662 tempax = 1280;
2663 tempbx = 1024;
2664 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002665 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302666 tempax = 1600;
2667 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002668 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302669 if (pVBInfo->VGAVDE == 350)
2670 tempbx = 875;
2671 else if (pVBInfo->VGAVDE == 400)
2672 tempbx = 1000;
2673 }
2674 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002675
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302676 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2677 tempax = pVBInfo->VGAHDE;
2678 tempbx = pVBInfo->VGAVDE;
2679 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002680
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302681 pVBInfo->HDE = tempax;
2682 pVBInfo->VDE = tempbx;
2683 return;
2684 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002685
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302686 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002687 struct SiS_TVData const *TVPtr;
2688
2689 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2690 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002691
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302692 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2693 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2694 pVBInfo->VGAHT = TVPtr->VGAHT;
2695 pVBInfo->VGAVT = TVPtr->VGAVT;
2696 pVBInfo->HDE = TVPtr->TVHDE;
2697 pVBInfo->VDE = TVPtr->TVVDE;
2698 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2699 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002700
Peter Huewe599801f2012-02-09 21:11:45 +01002701 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302702 if (resinfo == 0x08)
2703 pVBInfo->NewFlickerMode = 0x40;
2704 else if (resinfo == 0x09)
2705 pVBInfo->NewFlickerMode = 0x40;
2706 else if (resinfo == 0x12)
2707 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002708
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302709 if (pVBInfo->VGAVDE == 350)
2710 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302712 tempax = ExtHiTVHT;
2713 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002714
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302715 if (pVBInfo->VBInfo & SetInSlaveMode) {
2716 if (pVBInfo->TVInfo & TVSimuMode) {
2717 tempax = StHiTVHT;
2718 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002719
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302720 if (!(modeflag & Charx8Dot)) {
2721 tempax = StHiTextTVHT;
2722 tempbx = StHiTextTVVT;
2723 }
2724 }
2725 }
Peter Huewe599801f2012-02-09 21:11:45 +01002726 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2727 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302728 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2729 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2730 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002731
Peter Huewe599801f2012-02-09 21:11:45 +01002732 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302733 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2734 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002735 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302736 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2737 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2738 if (pVBInfo->TVInfo & NTSC1024x768)
2739 tempax = NTSC1024x768HT;
2740 }
2741 } else {
2742 tempax = PALHT;
2743 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002744 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302745 tempax = NTSCHT;
2746 tempbx = NTSCVT;
2747 if (pVBInfo->TVInfo & NTSC1024x768)
2748 tempax = NTSC1024x768HT;
2749 }
2750 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002751
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302752 pVBInfo->HT = tempax;
2753 pVBInfo->VT = tempbx;
2754 return;
2755 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002756}
2757
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002758static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302759 unsigned short RefreshRateTableIndex,
2760 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002761{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002762 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002763
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302764 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2765 pVBInfo);
2766 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2767 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002768
Peter Huewe6896b942012-02-09 21:11:46 +01002769 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302770 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002771 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2772 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2773 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302774 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002775 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2776 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302777 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002778
Aaro Koskinen8104e322011-03-13 12:26:22 +02002779 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002780
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302781 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002782 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302783 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002784 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002785}
2786
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002787static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2788 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002789{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002790 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2791 short index;
2792 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302793
Aaro Koskinenb3979922012-11-04 21:14:52 +02002794 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002795 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302796
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002797 if (index < 0)
2798 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302799
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002800 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302801}
2802
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002803static unsigned short XGI_GetOffset(unsigned short ModeNo,
2804 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302805 unsigned short RefreshRateTableIndex,
2806 struct xgi_hw_device_info *HwDeviceExtension,
2807 struct vb_device_info *pVBInfo)
2808{
2809 unsigned short temp, colordepth, modeinfo, index, infoflag,
2810 ColorDepth[] = { 0x01, 0x02, 0x04 };
2811
Aaro Koskinenb3979922012-11-04 21:14:52 +02002812 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002813 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302814
2815 index = (modeinfo >> 8) & 0xFF;
2816
Aaro Koskinen224114c2012-11-04 21:14:59 +02002817 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302818
2819 if (infoflag & InterlaceMode)
2820 temp = temp << 1;
2821
2822 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2823
2824 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2825 temp = ModeNo - 0x7C;
2826 colordepth = ColorDepth[temp];
2827 temp = 0x6B;
2828 if (infoflag & InterlaceMode)
2829 temp = temp << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302830 }
Peter Huewe053004b2013-02-15 20:37:12 +01002831 return temp * colordepth;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302832}
2833
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002834static void XGI_SetCRT2Offset(unsigned short ModeNo,
2835 unsigned short ModeIdIndex,
2836 unsigned short RefreshRateTableIndex,
2837 struct xgi_hw_device_info *HwDeviceExtension,
2838 struct vb_device_info *pVBInfo)
2839{
2840 unsigned short offset;
2841 unsigned char temp;
2842
2843 if (pVBInfo->VBInfo & SetInSlaveMode)
2844 return;
2845
2846 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2847 HwDeviceExtension, pVBInfo);
2848 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002849 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002850 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002851 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002852 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002853 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002854}
2855
Randy Dunlap89229672010-08-10 08:46:44 -07002856static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002857{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002858 /* threshold high ,disable auto threshold */
2859 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2860 /* threshold low default 04h */
2861 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002862}
2863
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002864static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302865 struct xgi_hw_device_info *HwDeviceExtension,
2866 unsigned short RefreshRateTableIndex,
2867 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002868{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002869 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002870
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302871 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2872 HwDeviceExtension, pVBInfo);
2873 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302875 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002876 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002877
Aaro Koskinen8104e322011-03-13 12:26:22 +02002878 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2879 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002880}
2881
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002882static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302883 struct xgi_hw_device_info *HwDeviceExtension,
2884 unsigned short RefreshRateTableIndex,
2885 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002886{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302887 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002888 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002889
Aaro Koskinena39325d2012-11-04 21:14:53 +02002890 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002891 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002892 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002893
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302894 /* bainy change table name */
2895 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002896 /* BTVGA2HT 0x08,0x09 */
2897 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002898 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302899 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002900 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002901 /* BTVGA2HDEE 0x0A,0x0C */
2902 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002903 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302904 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2905 pushbx = pVBInfo->VGAHDE / 2 + 16;
2906 tempcx = tempcx >> 1;
2907 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2908 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002909
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302910 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002911 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2912 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002913 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302914 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002915 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302916 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002917 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302918 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2919 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2920 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002921
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302922 tempbx += 4;
2923 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002924
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302925 if (tempcx > (pVBInfo->VGAHT / 2))
2926 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002927
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302928 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002929
Aaro Koskinen8104e322011-03-13 12:26:22 +02002930 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302931 } else {
2932 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002933 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302934 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002935 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002936 /* BTVGA2HDEE 0x0A,0x0C */
2937 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002938 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302939 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2940 pushbx = pVBInfo->VGAHDE + 16;
2941 tempcx = tempcx >> 1;
2942 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2943 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002944
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302945 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002946 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2947 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002948 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302949 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002950 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302951 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002952 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302953 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2954 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2955 tempbx += 16;
2956 tempcx += 16;
2957 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002958
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302959 if (tempcx > pVBInfo->VGAHT)
2960 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002961
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302962 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002963 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302964 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302966 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2967 tempbx = pushbx;
2968 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2969 tempax |= (tempbx & 0xFF00);
2970 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002971 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302972 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002973 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302974 tempcx = (pVBInfo->VGAVT - 1);
2975 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002976
Aaro Koskinen8104e322011-03-13 12:26:22 +02002977 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302978 tempbx = pVBInfo->VGAVDE - 1;
2979 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002980 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302981 temp = ((tempbx & 0xFF00) << 3) >> 8;
2982 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002983 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002984
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002985 /* BTVGA2VRS 0x10,0x11 */
2986 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
2987 /* BTVGA2VRE 0x11 */
2988 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002989
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302990 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002991 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
2992 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002993
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302994 if (temp & 0x04)
2995 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002996
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302997 if (temp & 0x080)
2998 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002999
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003000 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303002 if (temp & 0x08)
3003 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003004
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003005 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303006 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3007 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003008
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303009 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003010 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303011 temp = ((tempbx & 0xFF00) >> 8) << 4;
3012 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003013 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303014 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303016 if (modeflag & DoubleScanMode)
3017 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003018
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303019 if (modeflag & HalfDCLK)
3020 tempax |= 0x40;
3021
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003022 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003023}
3024
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003025static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3026{
3027 unsigned long tempax, tempbx;
3028
3029 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3030 & 0xFFFF;
3031 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3032 tempax = (tempax * pVBInfo->HT) / tempbx;
3033
3034 return (unsigned short) tempax;
3035}
3036
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003037static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303038 struct xgi_hw_device_info *HwDeviceExtension,
3039 unsigned short RefreshRateTableIndex,
3040 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003041{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303042 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003043 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003044
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003045 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003046 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3047 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003048
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303049 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3050 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303052 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003053 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303054 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003055
Peter Huewe6896b942012-02-09 21:11:46 +01003056 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303057 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303059 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003060
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303061 if (modeflag & HalfDCLK)
3062 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003063
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303064 tempax = (tempax / tempcx) - 1;
3065 tempbx |= ((tempax & 0x00FF) << 8);
3066 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003067 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003068
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303069 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303071 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003072 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3073 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303074 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003075
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003076 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3077 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303078 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303079 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003080
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003081 /* 0x05 Horizontal Display Start */
3082 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3083 /* 0x06 Horizontal Blank end */
3084 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003085
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303086 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3087 if (pVBInfo->VBInfo & SetCRT2ToTV)
3088 tempax = pVBInfo->VGAHT;
3089 else
3090 tempax = XGI_GetVGAHT2(pVBInfo);
3091 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303093 if (tempax >= pVBInfo->VGAHT)
3094 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003095
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303096 if (modeflag & HalfDCLK)
3097 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303099 tempax = (tempax / tempcx) - 5;
3100 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003101 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303102 temp = (tempbx & 0x00FF) - 1;
3103 if (!(modeflag & HalfDCLK)) {
3104 temp -= 6;
3105 if (pVBInfo->TVInfo & TVSimuMode) {
3106 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003107 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303108 }
3109 }
3110 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303111 tempbx = (tempbx & 0xFF00) >> 8;
3112 tempcx = (tempcx + tempbx) >> 1;
3113 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303115 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3116 temp -= 1;
3117 if (!(modeflag & HalfDCLK)) {
3118 if ((modeflag & Charx8Dot)) {
3119 temp += 4;
3120 if (pVBInfo->VGAHDE >= 800)
3121 temp -= 6;
3122 }
3123 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003124 } else if (!(modeflag & HalfDCLK)) {
3125 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003126 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003127 pVBInfo->VGAHDE >= 800) {
3128 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003129 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003130 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003131 (pVBInfo->LCDInfo & LCDNonExpanding))
3132 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303133 }
3134 }
3135 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003136
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003137 /* 0x07 Horizontal Retrace Start */
3138 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3139 /* 0x08 Horizontal Retrace End */
3140 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303142 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3143 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003144 if (ModeNo == 0x50) {
Peter Huewe85b38472013-05-13 23:41:49 +02003145 if (pVBInfo->TVInfo == SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003146 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303147 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003148 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303149 0x08, 0x03);
3150 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003151 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303152 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003153 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303154 0x08, 0x02);
3155 }
3156 }
3157 }
3158 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003159
Aaro Koskinen8104e322011-03-13 12:26:22 +02003160 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003161 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003162 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003163
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303164 tempbx = pVBInfo->VGAVT;
3165 push1 = tempbx;
3166 tempcx = 0x121;
3167 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303169 if (tempbx == 357)
3170 tempbx = 350;
3171 if (tempbx == 360)
3172 tempbx = 350;
3173 if (tempbx == 375)
3174 tempbx = 350;
3175 if (tempbx == 405)
3176 tempbx = 400;
3177 if (tempbx == 525)
3178 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303180 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003181
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303182 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003183 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003184 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303185 if (tempbx == 350)
3186 tempbx += 5;
3187 if (tempbx == 480)
3188 tempbx += 5;
3189 }
3190 }
3191 }
3192 tempbx--;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303193 tempbx--;
3194 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003195 /* 0x10 vertical Blank Start */
3196 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303197 tempbx = push2;
3198 tempbx--;
3199 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003200 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303202 if (tempbx & 0x0100)
3203 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303205 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003206
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303207 if (modeflag & DoubleScanMode)
3208 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003209
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303210 if (tempbx & 0x0200)
3211 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303213 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003214 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003215
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303216 if (tempbx & 0x0400)
3217 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003218
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003219 /* 0x11 Vertival Blank End */
3220 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303221
3222 tempax = push1;
3223 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3224 tempax = tempax >> 2;
3225 push1 = tempax; /* push ax */
3226
3227 if (resinfo != 0x09) {
3228 tempax = tempax << 1;
3229 tempbx += tempax;
3230 }
3231
Peter Huewe599801f2012-02-09 21:11:45 +01003232 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003233 if ((pVBInfo->VBType & VB_SIS301LV) &&
3234 !(pVBInfo->TVInfo & TVSetHiVision)) {
3235 if ((pVBInfo->TVInfo & TVSimuMode) &&
3236 (pVBInfo->TVInfo & TVSetPAL)) {
3237 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3238 !(pVBInfo->TVInfo &
3239 (TVSetYPbPr525p |
3240 TVSetYPbPr750p |
3241 TVSetHiVision)))
3242 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303243 }
3244 } else {
3245 tempbx -= 10;
3246 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003247 } else if (pVBInfo->TVInfo & TVSimuMode) {
3248 if (pVBInfo->TVInfo & TVSetPAL) {
3249 if (pVBInfo->VBType & VB_SIS301LV) {
3250 if (!(pVBInfo->TVInfo &
3251 (TVSetYPbPr525p |
3252 TVSetYPbPr750p |
3253 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303254 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003255 } else {
3256 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303257 }
3258 }
3259 }
3260 tempax = push1;
3261 tempax = tempax >> 2;
3262 tempax++;
3263 tempax += tempbx;
3264 push1 = tempax; /* push ax */
3265
Peter Huewe599801f2012-02-09 21:11:45 +01003266 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303267 if (tempbx <= 513) {
3268 if (tempax >= 513)
3269 tempbx = 513;
3270 }
3271 }
3272
3273 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003274 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303275 tempbx--;
3276 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003277 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303278
3279 if (tempbx & 0x0100)
3280 tempcx |= 0x0008;
3281
3282 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003283 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303284
3285 tempbx++;
3286
3287 if (tempbx & 0x0100)
3288 tempcx |= 0x0004;
3289
3290 if (tempbx & 0x0200)
3291 tempcx |= 0x0080;
3292
3293 if (tempbx & 0x0400)
3294 tempcx |= 0x0C00;
3295
3296 tempbx = push1; /* pop ax */
3297 temp = tempbx & 0x00FF;
3298 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003299 /* 0x0D vertical Retrace End */
3300 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303301
3302 if (tempbx & 0x0010)
3303 tempcx |= 0x2000;
3304
3305 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003306 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303307 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003308 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303309 tempax = modeflag;
3310 temp = (tempax & 0xFF00) >> 8;
3311
3312 temp = (temp >> 1) & 0x09;
3313
Peter Huewe6896b942012-02-09 21:11:46 +01003314 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303315 temp |= 0x01;
3316
Aaro Koskinen8104e322011-03-13 12:26:22 +02003317 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3318 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3319 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303320
3321 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3322 temp = 0x80;
3323 else
3324 temp = 0x00;
3325
Aaro Koskinen8104e322011-03-13 12:26:22 +02003326 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303327
3328 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003329}
3330
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003331static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303332 unsigned short RefreshRateTableIndex,
3333 struct xgi_hw_device_info *HwDeviceExtension,
3334 struct vb_device_info *pVBInfo)
3335{
3336 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003337 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003338 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303339
3340 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3341
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003342 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003343 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303344
3345 tempax = 0;
3346
3347 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3348 tempax |= 0x0800;
3349
3350 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3351 tempax |= 0x0400;
3352
3353 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3354 tempax |= 0x0200;
3355
Peter Huewe599801f2012-02-09 21:11:45 +01003356 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303357 tempax |= 0x1000;
3358
Peter Huewe599801f2012-02-09 21:11:45 +01003359 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303360 tempax |= 0x0100;
3361
Peter Huewe599801f2012-02-09 21:11:45 +01003362 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303363 tempax &= 0xfe00;
3364
3365 tempax = (tempax & 0xff00) >> 8;
3366
Aaro Koskinen8104e322011-03-13 12:26:22 +02003367 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003368 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303369
Peter Huewe599801f2012-02-09 21:11:45 +01003370 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003371 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303372
Peter Huewe599801f2012-02-09 21:11:45 +01003373 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003374 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303375
3376 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003377 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303378
3379 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003380 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303381
3382 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003383 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303384 }
3385
Peter Huewe599801f2012-02-09 21:11:45 +01003386 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3387 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003388 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303389
Peter Huewe599801f2012-02-09 21:11:45 +01003390 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003391 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303392
Peter Huewe599801f2012-02-09 21:11:45 +01003393 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003394 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303395 }
3396
3397 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003398 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303399
3400 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003401 /* di->temp2[j] */
3402 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303403
3404 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003405 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303406
3407 temp = pVBInfo->NewFlickerMode;
3408 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003409 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303410
Peter Huewe599801f2012-02-09 21:11:45 +01003411 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303412 tempax = 520;
3413 else
3414 tempax = 440;
3415
3416 if (pVBInfo->VDE <= tempax) {
3417 tempax -= pVBInfo->VDE;
3418 tempax = tempax >> 2;
3419 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3420 push1 = tempax;
3421 temp = (tempax & 0xFF00) >> 8;
3422 temp += (unsigned short) TimingPoint[0];
3423
Peter Huewe6896b942012-02-09 21:11:46 +01003424 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3425 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303426 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3427 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003428 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303429 tempcx = pVBInfo->VGAHDE;
3430 if (tempcx >= 1024) {
3431 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003432 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303433 temp = 0x19; /* PAL */
3434 }
3435 }
3436 }
3437
Aaro Koskinen8104e322011-03-13 12:26:22 +02003438 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303439 tempax = push1;
3440 temp = (tempax & 0xFF00) >> 8;
3441 temp += TimingPoint[1];
3442
Peter Huewe6896b942012-02-09 21:11:46 +01003443 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3444 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303445 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3446 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003447 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303448 tempcx = pVBInfo->VGAHDE;
3449 if (tempcx >= 1024) {
3450 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003451 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303452 temp = 0x52; /* PAL */
3453 }
3454 }
3455 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003456 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303457 }
3458
3459 /* 301b */
3460 tempcx = pVBInfo->HT;
3461
3462 if (XGI_IsLCDDualLink(pVBInfo))
3463 tempcx = tempcx >> 1;
3464
3465 tempcx -= 2;
3466 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003467 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303468
3469 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003470 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303471
3472 tempcx = pVBInfo->HT >> 1;
3473 push1 = tempcx; /* push cx */
3474 tempcx += 7;
3475
Peter Huewe599801f2012-02-09 21:11:45 +01003476 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303477 tempcx -= 4;
3478
3479 temp = tempcx & 0x00FF;
3480 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003481 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303482
3483 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3484 tempbx += tempcx;
3485 push2 = tempbx;
3486 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003487 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303488 temp = (tempbx & 0xFF00) >> 8;
3489 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003490 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303491
3492 tempbx = push2;
3493 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003494 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495 tempbx = tempbx - 4;
3496 tempcx = tempbx;
3497 }
3498
3499 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003500 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303501
3502 j += 2;
3503 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3504 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003505 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303506 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003507 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303508
3509 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003510 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303511 tempcx -= 4;
3512
3513 temp = tempcx & 0xFF;
3514 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003515 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303516
3517 tempcx = push1; /* pop cx */
3518 j += 2;
3519 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3520 tempcx -= temp;
3521 temp = tempcx & 0x00FF;
3522 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003523 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303524
3525 tempcx -= 11;
3526
3527 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3528 tempax = XGI_GetVGAHT2(pVBInfo);
3529 tempcx = tempax - 1;
3530 }
3531 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003532 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303533
3534 tempbx = pVBInfo->VDE;
3535
3536 if (pVBInfo->VGAVDE == 360)
3537 tempbx = 746;
3538 if (pVBInfo->VGAVDE == 375)
3539 tempbx = 746;
3540 if (pVBInfo->VGAVDE == 405)
3541 tempbx = 853;
3542
3543 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003544 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003545 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003546 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003547 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303548 tempbx = tempbx >> 1;
3549 } else
3550 tempbx = tempbx >> 1;
3551 }
3552
3553 tempbx -= 2;
3554 temp = tempbx & 0x00FF;
3555
Peter Huewe599801f2012-02-09 21:11:45 +01003556 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003557 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003558 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303559 if (pVBInfo->VBInfo & SetInSlaveMode) {
3560 if (ModeNo == 0x2f)
3561 temp += 1;
3562 }
3563 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003564 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3565 if (ModeNo == 0x2f)
3566 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303567 }
3568 }
3569
Aaro Koskinen8104e322011-03-13 12:26:22 +02003570 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303571
3572 temp = (tempcx & 0xFF00) >> 8;
3573 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3574
Peter Huewe599801f2012-02-09 21:11:45 +01003575 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003576 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003577 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303578 temp |= 0x10;
3579
3580 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3581 temp |= 0x20;
3582 }
3583 } else {
3584 temp |= 0x10;
3585 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3586 temp |= 0x20;
3587 }
3588 }
3589
Aaro Koskinen8104e322011-03-13 12:26:22 +02003590 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303591
Peter Huewe6896b942012-02-09 21:11:46 +01003592 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3593 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303594 tempbx = pVBInfo->VDE;
3595 tempcx = tempbx - 2;
3596
3597 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003598 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3599 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303600 tempbx = tempbx >> 1;
3601 }
3602
Peter Huewe6896b942012-02-09 21:11:46 +01003603 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303604 temp = 0;
3605 if (tempcx & 0x0400)
3606 temp |= 0x20;
3607
3608 if (tempbx & 0x0400)
3609 temp |= 0x40;
3610
Aaro Koskinen8104e322011-03-13 12:26:22 +02003611 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303612 }
3613
3614 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003615 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303616 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003617 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303618 }
3619
3620 tempbx = tempbx & 0x00FF;
3621
3622 if (!(modeflag & HalfDCLK)) {
3623 tempcx = pVBInfo->VGAHDE;
3624 if (tempcx >= pVBInfo->HDE) {
3625 tempbx |= 0x2000;
3626 tempax &= 0x00FF;
3627 }
3628 }
3629
3630 tempcx = 0x0101;
3631
3632 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3633 if (pVBInfo->VGAHDE >= 1024) {
3634 tempcx = 0x1920;
3635 if (pVBInfo->VGAHDE >= 1280) {
3636 tempcx = 0x1420;
3637 tempbx = tempbx & 0xDFFF;
3638 }
3639 }
3640 }
3641
3642 if (!(tempbx & 0x2000)) {
3643 if (modeflag & HalfDCLK)
3644 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3645
3646 push1 = tempbx;
3647 tempeax = pVBInfo->VGAHDE;
3648 tempebx = (tempcx & 0xFF00) >> 8;
3649 longtemp = tempeax * tempebx;
3650 tempecx = tempcx & 0x00FF;
3651 longtemp = longtemp / tempecx;
3652
3653 /* 301b */
3654 tempecx = 8 * 1024;
3655
Peter Huewe6896b942012-02-09 21:11:46 +01003656 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3657 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303658 tempecx = tempecx * 8;
3659 }
3660
3661 longtemp = longtemp * tempecx;
3662 tempecx = pVBInfo->HDE;
3663 temp2 = longtemp % tempecx;
3664 tempeax = longtemp / tempecx;
3665 if (temp2 != 0)
3666 tempeax += 1;
3667
3668 tempax = (unsigned short) tempeax;
3669
3670 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003671 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3672 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303673 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3674 }
3675 /* end 301b */
3676
3677 tempbx = push1;
3678 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3679 | (tempbx & 0x00FF));
3680 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3681 | (tempax & 0x00FF));
3682 temp = (tempax & 0xFF00) >> 8;
3683 } else {
3684 temp = (tempax & 0x00FF) >> 8;
3685 }
3686
Aaro Koskinen8104e322011-03-13 12:26:22 +02003687 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303688 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003689 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303690 temp = tempcx & 0x00FF;
3691
3692 if (tempbx & 0x2000)
3693 temp = 0;
3694
3695 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3696 temp |= 0x18;
3697
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003698 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003699 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303700 tempbx = 0x0382;
3701 tempcx = 0x007e;
3702 } else {
3703 tempbx = 0x0369;
3704 tempcx = 0x0061;
3705 }
3706
3707 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003708 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303709 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003710 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303711
3712 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3713 temp = temp << 2;
3714 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3715
Peter Huewe599801f2012-02-09 21:11:45 +01003716 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303717 temp |= 0x10;
3718
Peter Huewe599801f2012-02-09 21:11:45 +01003719 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303720 temp |= 0x20;
3721
Peter Huewe599801f2012-02-09 21:11:45 +01003722 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303723 temp |= 0x60;
3724 }
3725
Aaro Koskinen8104e322011-03-13 12:26:22 +02003726 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003727 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003728 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303729
Peter Huewe599801f2012-02-09 21:11:45 +01003730 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303731 if (pVBInfo->TVInfo & NTSC1024x768) {
3732 TimingPoint = XGI_NTSC1024AdjTime;
3733 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003734 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303735 TimingPoint[j]);
3736 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003737 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303738 }
3739 }
3740
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003741 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303742 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003743 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003744 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303745 0x08); /* PALM Mode */
3746 }
3747
Peter Huewe599801f2012-02-09 21:11:45 +01003748 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003749 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303750 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003751 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303752
Aaro Koskinendc505562011-03-13 12:26:26 +02003753 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303754 }
3755
Peter Huewe599801f2012-02-09 21:11:45 +01003756 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303757 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003758 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303759 }
3760
3761 if (pVBInfo->VBInfo & SetCRT2ToTV)
3762 return;
3763}
3764
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003765static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303766 struct xgi_hw_device_info *HwDeviceExtension,
3767 unsigned short RefreshRateTableIndex,
3768 struct vb_device_info *pVBInfo)
3769{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003770 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3771 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303772
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003773 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303774
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003775 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303776 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3777 return;
3778
3779 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3780
3781 if (XGI_IsLCDDualLink(pVBInfo))
3782 tempbx = tempbx >> 1;
3783
3784 tempbx -= 1;
3785 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003786 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303787 temp = (tempbx & 0xFF00) >> 8;
3788 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003789 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303790 temp = 0x01;
3791
Aaro Koskinen8104e322011-03-13 12:26:22 +02003792 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303793 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303794 tempbx--;
3795 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003796 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303797 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003798 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303799
3800 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303801 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003802 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303803 temp = (tempcx & 0xFF00) >> 8;
3804 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003805 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003806 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3807 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3808 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3809 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303810
Justin P. Mattock558f7582012-10-02 21:17:11 -07003811 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003812 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
3813 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
3814 RefreshRateTableIndex, pVBInfo);
3815 else
3816 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
3817 ModeIdIndex, RefreshRateTableIndex,
3818 pVBInfo);
3819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303820 tempah = pVBInfo->LCDResInfo;
3821 tempah &= PanelResInfo;
3822
Peter Huewe255aabd2012-02-09 21:11:44 +01003823 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303824 tempbx = 1024;
3825 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003826 } else if ((tempah == Panel_1280x1024) ||
3827 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303828 tempbx = 1280;
3829 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003830 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303831 tempbx = 1400;
3832 tempcx = 1050;
3833 } else {
3834 tempbx = 1600;
3835 tempcx = 1200;
3836 }
3837
3838 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3839 tempbx = pVBInfo->HDE;
3840 tempcx = pVBInfo->VDE;
3841 }
3842
3843 pushbx = tempbx;
3844 tempax = pVBInfo->VT;
3845 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3846 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3847 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3848 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3849 tempbx = pVBInfo->LCDVDES;
3850 tempcx += tempbx;
3851
3852 if (tempcx >= tempax)
3853 tempcx -= tempax; /* lcdvdes */
3854
3855 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003856 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303857 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003858 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303859 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3860 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3861 tempah = tempch;
3862 tempah = tempah << 3;
3863 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003864 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303865
3866 /* getlcdsync() */
3867 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3868 tempcx = tempbx;
3869 tempax = pVBInfo->VT;
3870 tempbx = pVBInfo->LCDVRS;
3871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303872 tempcx += tempbx;
3873 if (tempcx >= tempax)
3874 tempcx -= tempax;
3875
3876 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003877 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303878 temp = (tempbx & 0xFF00) >> 8;
3879 temp = temp << 4;
3880 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003881 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303882 tempcx = pushbx;
3883 tempax = pVBInfo->HT;
3884 tempbx = pVBInfo->LCDHDES;
3885 tempbx &= 0x0FFF;
3886
3887 if (XGI_IsLCDDualLink(pVBInfo)) {
3888 tempax = tempax >> 1;
3889 tempbx = tempbx >> 1;
3890 tempcx = tempcx >> 1;
3891 }
3892
Peter Huewe6896b942012-02-09 21:11:46 +01003893 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303894 tempbx += 1;
3895
3896 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3897 tempbx += 1;
3898
3899 tempcx += tempbx;
3900
3901 if (tempcx >= tempax)
3902 tempcx -= tempax;
3903
3904 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003905 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303906 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003907 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303908 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003909 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303910 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003911 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303912
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303913 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3914 tempcx = tempax;
3915 tempax = pVBInfo->HT;
3916 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303917 if (XGI_IsLCDDualLink(pVBInfo)) {
3918 tempax = tempax >> 1;
3919 tempbx = tempbx >> 1;
3920 tempcx = tempcx >> 1;
3921 }
3922
Peter Huewe6896b942012-02-09 21:11:46 +01003923 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303924 tempbx += 1;
3925
3926 tempcx += tempbx;
3927
3928 if (tempcx >= tempax)
3929 tempcx -= tempax;
3930
3931 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003932 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303933
3934 temp = (tempbx & 0xFF00) >> 8;
3935 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003936 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303937 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003938 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303939
Peter Huewea3d675c2012-02-09 21:11:47 +01003940 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303941 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003942 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3943 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303944 | VB_XGI301C)) {
3945 temp = 0xC6;
3946 } else
3947 temp = 0xC4;
3948
Aaro Koskinen8104e322011-03-13 12:26:22 +02003949 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3950 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303951 }
3952
3953 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01003954 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3955 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303956 | VB_XGI301C)) {
3957 temp = 0x4F;
3958 } else
3959 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003960 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303961 }
3962 }
3963}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003964
3965/* --------------------------------------------------------------------- */
3966/* Function : XGI_GetTap4Ptr */
3967/* Input : */
3968/* Output : di -> Tap4 Reg. Setting Pointer */
3969/* Description : */
3970/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003971static struct XGI301C_Tap4TimingStruct const
3972*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003973{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303974 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003975 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003976
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303977 if (tempcx == 0) {
3978 tempax = pVBInfo->VGAHDE;
3979 tempbx = pVBInfo->HDE;
3980 } else {
3981 tempax = pVBInfo->VGAVDE;
3982 tempbx = pVBInfo->VDE;
3983 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003984
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003985 if (tempax <= tempbx)
3986 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303987 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003988 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003989
Peter Huewe599801f2012-02-09 21:11:45 +01003990 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303991 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003992
Peter Huewe599801f2012-02-09 21:11:45 +01003993 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3994 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
3995 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003996 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01003997 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303998 Tap4TimingPtr = YPbPr750pTap4Timing;
3999 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004000
Peter Huewe599801f2012-02-09 21:11:45 +01004001 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004002 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304004 i = 0;
4005 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4006 if (Tap4TimingPtr[i].DE == tempax)
4007 break;
4008 i++;
4009 }
4010 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004011}
4012
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004013static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004014{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304015 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004016 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004017
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304018 if (!(pVBInfo->VBType & VB_XGI301C))
4019 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004020
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304021 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4022 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004023 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004024
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004025 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004026 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004027 /* Set Vertical Scaling */
4028 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304029 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004030 xgifb_reg_set(pVBInfo->Part2Port,
4031 i,
4032 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304033 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004034
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004035 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004036 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004037 /* Enable V.Scaling */
4038 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304039 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004040 /* Enable H.Scaling */
4041 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004042}
4043
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004044static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304045 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004046{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304047 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004048 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304049 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004050
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004051 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004052 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004053
Aaro Koskinen8104e322011-03-13 12:26:22 +02004054 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004055 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004056 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4057 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304058 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004059 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4060 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304061 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004062
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304063 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4064 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004065
Peter Huewe599801f2012-02-09 21:11:45 +01004066 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004067 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4068 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4069 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304070 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004071
Peter Huewe599801f2012-02-09 21:11:45 +01004072 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4073 & SetCRT2ToYPbPr525750)) {
4074 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304075 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004076
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004077 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304078 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004079 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304080 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004081 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304082 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004083
Peter Huewe599801f2012-02-09 21:11:45 +01004084 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004085 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004086
Peter Huewe599801f2012-02-09 21:11:45 +01004087 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004088 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304090 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004091 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304093 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004094 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004095 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304096 }
4097 }
4098 return;
4099} /* {end of XGI_SetGroup3} */
4100
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004101static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304102 unsigned short RefreshRateTableIndex,
4103 struct xgi_hw_device_info *HwDeviceExtension,
4104 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004105{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304106 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004107
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304108 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004109
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004110 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004111 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304112 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004113 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304115 tempbx = pVBInfo->RVBHCMAX;
4116 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004117 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304118 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4119 tempcx = pVBInfo->VGAHT - 1;
4120 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004121 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304123 temp = ((tempcx & 0xFF00) >> 8) << 3;
4124 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304126 tempcx = pVBInfo->VGAVT - 1;
4127 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4128 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004129
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304130 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004131 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304132 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004133 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004134 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304135 tempcx = pVBInfo->VBInfo;
4136 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304138 if (modeflag & HalfDCLK)
4139 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304141 if (XGI_IsLCDDualLink(pVBInfo))
4142 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004143
Peter Huewe599801f2012-02-09 21:11:45 +01004144 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304145 temp = 0;
4146 if (tempbx <= 1024)
4147 temp = 0xA0;
4148 if (tempbx == 1280)
4149 temp = 0xC0;
4150 } else if (tempcx & SetCRT2ToTV) {
4151 temp = 0xA0;
4152 if (tempbx <= 800)
4153 temp = 0x80;
4154 } else {
4155 temp = 0x80;
4156 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4157 temp = 0;
4158 if (tempbx > 800)
4159 temp = 0x60;
4160 }
4161 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004162
Peter Huewe599801f2012-02-09 21:11:45 +01004163 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304164 temp = 0x00;
4165 if (pVBInfo->VGAHDE == 1280)
4166 temp = 0x40;
4167 if (pVBInfo->VGAHDE == 1024)
4168 temp = 0x20;
4169 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004170 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004171
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304172 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304174 tempcx = pVBInfo->RVBHRS;
4175 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004176 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004177
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304178 tempeax = pVBInfo->VGAVDE;
4179 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004180
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304181 if (tempeax <= tempebx) {
4182 tempcx = (tempcx & (~0x4000));
4183 tempeax = pVBInfo->VGAVDE;
4184 } else {
4185 tempeax -= tempebx;
4186 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304188 templong = (tempeax * 256 * 1024) % tempebx;
4189 tempeax = (tempeax * 256 * 1024) / tempebx;
4190 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304192 if (templong != 0)
4193 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004194
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304195 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004196 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004197
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304198 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004199 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304200 tempbx = (unsigned short) (tempebx >> 16);
4201 temp = tempbx & 0x00FF;
4202 temp = temp << 4;
4203 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004204 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004205
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304206 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004207 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4208 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304209 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004210 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304211 tempax = pVBInfo->VGAHDE;
4212 if (modeflag & HalfDCLK)
4213 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304215 if (XGI_IsLCDDualLink(pVBInfo))
4216 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304218 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4219 if (tempax > 800)
4220 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004221 } else if (pVBInfo->VGAHDE > 800) {
4222 if (pVBInfo->VGAHDE == 1024)
4223 tempax = (tempax * 25 / 32) - 1;
4224 else
4225 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304226 }
4227 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304229 temp = (tempax & 0xFF00) >> 8;
4230 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004231 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304232 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004233 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004234
Peter Huewe599801f2012-02-09 21:11:45 +01004235 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304236 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004237 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304239 }
4240 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004241
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304242 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4243 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004244 | TVSetYPbPr525p | TVSetYPbPr750p
4245 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304246 temp |= 0x0001;
4247 if ((pVBInfo->VBInfo & SetInSlaveMode)
4248 && (!(pVBInfo->TVInfo
4249 & TVSimuMode)))
4250 temp &= (~0x0001);
4251 }
4252 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004253
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004254 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304255 tempbx = pVBInfo->HT;
4256 if (XGI_IsLCDDualLink(pVBInfo))
4257 tempbx = tempbx >> 1;
4258 tempbx = (tempbx >> 1) - 2;
4259 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004260 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304261 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004262 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304263 }
4264 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004265
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004266 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004267}
4268
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004269static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4270{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004271 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004272}
4273
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004274static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304275 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004276{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304277 if (pVBInfo->ModeType == ModeVGA) {
4278 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004279 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304280 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304281 }
4282 }
4283 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004284}
4285
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004286static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304287 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004288{
4289
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004290 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004291}
4292
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004293static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4294 unsigned short ModeNo, unsigned short ModeIdIndex,
4295 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004296{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004297 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004298
Aaro Koskinenb3979922012-11-04 21:14:52 +02004299 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004300 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4301 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004302 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004303 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004304
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304305 if (!(modeflag & Charx8Dot)) {
4306 xres /= 9;
4307 xres *= 8;
4308 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004309
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004310 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4311 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004312
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004313 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4314 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004315
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004316 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304317 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004318
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004319 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304320 return 0;
4321
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004322 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4323 yres != xgifb_info->lvds_data.LVDSVDE) {
4324 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4325 if (colordepth > 2)
4326 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304327 }
4328 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004329}
4330
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004331static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4332 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004333 unsigned short ModeNo,
4334 unsigned short ModeIdIndex,
4335 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004336{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304337 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004338 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304339 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4340 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4341 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004342
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004343 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004344 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304345 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004346 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004347
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004348 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004349
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004350 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004351 /* SR35[7] FP VSync polarity */
4352 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4353 /* SR30[5] FP HSync polarity */
4354 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004355
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004356 if (chip_id == XG27)
4357 XGI_SetXG27FPBits(pVBInfo);
4358 else
4359 XGI_SetXG21FPBits(pVBInfo);
4360
Aaro Koskinenb3979922012-11-04 21:14:52 +02004361 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004362 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4363 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004364 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004365 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004366
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304367 if (!(modeflag & Charx8Dot))
4368 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004369
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004370 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004371
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004372 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004373
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304374 if (LVDSHBS > LVDSHT)
4375 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004376
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004377 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304378 if (LVDSHRS > LVDSHT)
4379 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004380
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004381 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304382 if (LVDSHRE > LVDSHT)
4383 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004384
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004385 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004386
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004387 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004388
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004389 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004390 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304391 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304393 if (LVDSVBS > LVDSVT)
4394 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004395
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004396 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304397 if (LVDSVRS > LVDSVT)
4398 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004399
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004400 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304401 if (LVDSVRE > LVDSVT)
4402 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004403
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004404 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004405
Peter Huewe9388ad92013-02-15 20:37:10 +01004406 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004407 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004408
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304409 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004410 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004411
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304412 /* HT SR0B[1:0] CR00 */
4413 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004414 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004415 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004416
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304417 /* HBS SR0B[5:4] CR02 */
4418 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004419 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004420 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004421
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304422 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4423 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004424 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4425 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4426 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004427
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304428 /* HRS SR0B[7:6] CR04 */
4429 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004430 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004431 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004432
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304433 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4434 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004435 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004436 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004437
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304438 /* HRE SR0C[2] CR05[4:0] */
4439 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004440 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4441 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004442
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304443 /* Panel HRE SR2F[7:2] */
4444 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004445 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004446
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304447 /* VT SR0A[0] CR07[5][0] CR06 */
4448 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004449 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4450 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4451 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004452 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004453
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304454 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4455 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004456 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4457 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4458 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004459 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004460
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304461 /* VBE SR0A[4] CR16 */
4462 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004463 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004464 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004465
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304466 /* VRS SR0A[3] CR7[7][2] CR10 */
4467 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004468 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4469 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4470 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004471 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004472
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004473 if (chip_id == XG27) {
4474 /* Panel VRS SR35[2:0] SR34[7:0] */
4475 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4476 (value & 0x700) >> 8);
4477 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4478 } else {
4479 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4480 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4481 (value & 0x600) >> 9);
4482 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4483 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4484 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004485
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304486 /* VRE SR0A[5] CR11[3:0] */
4487 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004488 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4489 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004490
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304491 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004492 if (chip_id == XG27)
4493 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4494 (value << 2) & 0xFC);
4495 else
4496 /* SR3F[7] has to be 0, h/w bug */
4497 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4498 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004499
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304500 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004501
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004502 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004503 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004504 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004505 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004506 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304507 value += 0x10;
4508 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004509
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304510 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004511 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004512 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004513 /* set data, panning = 0, shift left 1 dot*/
4514 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004515
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004516 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004517 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304518
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004519 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304520 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004521
4522}
4523
4524/* --------------------------------------------------------------------- */
4525/* Function : XGI_IsLCDON */
4526/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004527/* Output : 0 : Skip PSC Control */
4528/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004529/* Description : */
4530/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004531static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004532{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304533 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004534
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304535 tempax = pVBInfo->VBInfo;
4536 if (tempax & SetCRT2ToDualEdge)
4537 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004538 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304539 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004540
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304541 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004542}
4543
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004544static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4545 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304546 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004547{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004548 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004549
Peter Huewe6896b942012-02-09 21:11:46 +01004550 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4551 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304552 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004553 if (!(pVBInfo->VBInfo &
4554 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004555 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004556 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304557 tempah = 0x7F; /* Disable Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304558 }
4559 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004560
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004561 /* disable part4_1f */
4562 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004563
Peter Huewe6896b942012-02-09 21:11:46 +01004564 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004565 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004566 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
Peter Huewe06cc47b2013-02-03 22:54:38 +01004567 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004568 /* LVDS Driver power down */
4569 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304570 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004571
Aaro Koskinend1724632013-05-29 23:59:09 +03004572 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA |
4573 SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004574 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004575
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004576 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4577 /* Power down */
4578 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004579
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004580 /* disable TV as primary VGA swap */
4581 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004582
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304583 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004584 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004585
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004586 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004587 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004588 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004589 (pVBInfo->VBInfo &
4590 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004591 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004592
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004593 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004594 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004595 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004596 (pVBInfo->VBInfo &
4597 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4598 /* save Part1 index 0 */
4599 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4600 /* BTDAC = 1, avoid VB reset */
4601 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4602 /* disable CRT2 */
4603 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4604 /* restore Part1 index 0 */
4605 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304606 }
4607 } else { /* {301} */
4608 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004609 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4610 /* Disable CRT2 */
4611 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4612 /* Disable TV asPrimary VGA swap */
4613 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304614 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004615
Peter Huewea3d675c2012-02-09 21:11:47 +01004616 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304617 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004618 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304619 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004620}
4621
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004622/* --------------------------------------------------------------------- */
4623/* Function : XGI_GetTVPtrIndex */
4624/* Input : */
4625/* Output : */
4626/* Description : bx 0 : ExtNTSC */
4627/* 1 : StNTSC */
4628/* 2 : ExtPAL */
4629/* 3 : StPAL */
4630/* 4 : ExtHiTV */
4631/* 5 : StHiTV */
4632/* 6 : Ext525i */
4633/* 7 : St525i */
4634/* 8 : Ext525p */
4635/* 9 : St525p */
4636/* A : Ext750p */
4637/* B : St750p */
4638/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004639static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004640{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304641 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004642
Peter Huewe599801f2012-02-09 21:11:45 +01004643 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304644 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004645 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304646 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004647 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304648 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004649 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304650 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004651 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304652 tempbx = 10;
4653 if (pVBInfo->TVInfo & TVSimuMode)
4654 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004655
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304656 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004657}
4658
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004659/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004660/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004661/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004662/* Output : bx 0 : NTSC */
4663/* 1 : PAL */
4664/* 2 : PALM */
4665/* 3 : PALN */
4666/* 4 : NTSC1024x768 */
4667/* 5 : PAL-M 1024x768 */
4668/* 6-7: reserved */
4669/* cl 0 : YFilter1 */
4670/* 1 : YFilter2 */
4671/* ch 0 : 301A */
4672/* 1 : 301B/302B/301LV/302LV */
4673/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004674/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004675static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4676 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004677{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004678 *tempbx = 0;
4679 *tempcl = 0;
4680 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004681
Peter Huewe599801f2012-02-09 21:11:45 +01004682 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004683 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004684
Peter Huewe599801f2012-02-09 21:11:45 +01004685 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004686 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004687
Peter Huewe599801f2012-02-09 21:11:45 +01004688 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004689 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004690
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004691 if (pVBInfo->TVInfo & NTSC1024x768) {
4692 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004693 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004694 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304695 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004696
Peter Huewe6896b942012-02-09 21:11:46 +01004697 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4698 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004699 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4700 & TVSimuMode)) {
4701 *tempbx += 8;
4702 *tempcl += 1;
4703 }
4704 }
4705
Peter Huewe6896b942012-02-09 21:11:46 +01004706 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4707 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004708 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004709}
4710
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004711static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004712{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304713 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004714
Peter Huewe6896b942012-02-09 21:11:46 +01004715 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4716 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004717 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304718 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304719 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004720 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004721
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304722 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4723 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004724 if (pVBInfo->VBInfo &
4725 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004726 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004727
Peter Huewea3d675c2012-02-09 21:11:47 +01004728 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304729 tempbl = tempbh;
4730 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004731
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304732 tempbl &= 0x0F;
4733 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004734 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004735
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304736 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4737 | SetCRT2ToTV)) { /* Channel B */
4738 tempah &= 0xF0;
4739 tempah |= tempbl;
4740 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004741
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004742 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4743 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304744 tempah &= 0x0F;
4745 tempah |= tempbh;
4746 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004747 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304748 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304749 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004750}
4751
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004752static void XGI_SetLCDCap_A(unsigned short tempcx,
4753 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004754{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304755 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004756
Aaro Koskinen58839b02011-03-13 12:26:23 +02004757 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004758
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304759 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004760 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004761 /* Enable Dither */
4762 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004763 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304764 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004765 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304766 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004767 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304768 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004769}
4770
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004771/* --------------------------------------------------------------------- */
4772/* Function : XGI_SetLCDCap_B */
4773/* Input : cx -> LCD Capability */
4774/* Output : */
4775/* Description : */
4776/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004777static void XGI_SetLCDCap_B(unsigned short tempcx,
4778 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004779{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304780 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004781 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304782 (unsigned short) (((tempcx & 0x00ff) >> 6)
4783 | 0x0c));
4784 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004785 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304786 (unsigned short) (((tempcx & 0x00ff) >> 6)
4787 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004788}
4789
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004790static void XGI_LongWait(struct vb_device_info *pVBInfo)
4791{
4792 unsigned short i;
4793
4794 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4795
4796 if (!(i & 0xC0)) {
4797 for (i = 0; i < 0xFFFF; i++) {
4798 if (!(inb(pVBInfo->P3da) & 0x08))
4799 break;
4800 }
4801
4802 for (i = 0; i < 0xFFFF; i++) {
4803 if ((inb(pVBInfo->P3da) & 0x08))
4804 break;
4805 }
4806 }
4807}
4808
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004809static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004810{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304811 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004812
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304813 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004814
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004815 /* disable down spectrum D[4] */
4816 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304817 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004818 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304819 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004820
Aaro Koskinen8104e322011-03-13 12:26:22 +02004821 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304822 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004823 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304824 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004825 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304826 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004827 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304828 pVBInfo->LCDCapList[index].Spectrum_34);
4829 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004830 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004831}
4832
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004833static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4834{
4835 unsigned short tempcx;
4836
4837 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4838
Peter Huewef951dd02013-02-05 00:29:47 +01004839 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4840 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004841 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004842 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004843 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004844 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004845 (unsigned char) (tempcx & 0x1F));
4846 }
4847 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004848 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004849 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4850 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4851 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004852
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004853 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4854 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004855 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004856 XGI_SetLCDCap_A(tempcx, pVBInfo);
4857
Peter Huewe6896b942012-02-09 21:11:46 +01004858 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004859 if (tempcx & EnableSpectrum)
4860 SetSpectrum(pVBInfo);
4861 }
4862 } else {
4863 /* LVDS,CH7017 */
4864 XGI_SetLCDCap_A(tempcx, pVBInfo);
4865 }
4866}
4867
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004868/* --------------------------------------------------------------------- */
4869/* Function : XGI_SetAntiFlicker */
4870/* Input : */
4871/* Output : */
4872/* Description : Set TV Customized Param. */
4873/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004874static void XGI_SetAntiFlicker(unsigned short ModeNo,
4875 unsigned short ModeIdIndex,
4876 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004877{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004878 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004879
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304880 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004881
Peter Huewe599801f2012-02-09 21:11:45 +01004882 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304883 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304885 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4886 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304887 tempah = TVAntiFlickList[tempbx];
4888 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004889
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004890 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004891}
4892
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004893static void XGI_SetEdgeEnhance(unsigned short ModeNo,
4894 unsigned short ModeIdIndex,
4895 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004896{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03004897 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004898
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304899 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004900
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304901 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4902 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304903 tempah = TVEdgeList[tempbx];
4904 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004905
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004906 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004907}
4908
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004909static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004910{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304911 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004912
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304913 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004914
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304915 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004916
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304917 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4918 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004919
Aaro Koskinen8104e322011-03-13 12:26:22 +02004920 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304921 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004922 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304923 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004924 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304925 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004926 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304927 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004928}
4929
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004930static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304931 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004932{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304933 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02004934 unsigned char const *filterPtr;
4935 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004936
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304937 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304939 switch (tempbx) {
4940 case 0x00:
4941 case 0x04:
4942 filterPtr = NTSCYFilter1;
4943 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004944
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304945 case 0x01:
4946 filterPtr = PALYFilter1;
4947 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304949 case 0x02:
4950 case 0x05:
4951 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304952 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03004953 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304954 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004955
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304956 case 0x08:
4957 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304958 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304959 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304960 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03004961 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304962 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004963
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304964 default:
4965 return;
4966 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004967
Aaro Koskinenb3979922012-11-04 21:14:52 +02004968 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304969 if (tempcl == 0)
4970 index = tempal * 4;
4971 else
4972 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004973
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304974 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004975 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
4976 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
4977 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
4978 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304979 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004980 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
4981 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
4982 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
4983 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304984 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004985
Peter Huewe6896b942012-02-09 21:11:46 +01004986 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4987 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004988 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
4989 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
4990 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304991 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004992}
4993
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004994/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004995/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004996/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004997/* Output : */
4998/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004999/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005000static void XGI_OEM310Setting(unsigned short ModeNo,
5001 unsigned short ModeIdIndex,
5002 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005003{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005004 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005005
Peter Huewea3d675c2012-02-09 21:11:47 +01005006 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005007 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005008
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005009 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005010 XGI_SetPhaseIncr(pVBInfo);
5011 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5012 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005013
Peter Huewe6896b942012-02-09 21:11:46 +01005014 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005015 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305016 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005017}
5018
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005019/* --------------------------------------------------------------------- */
5020/* Function : XGI_SetCRT2ModeRegs */
5021/* Input : */
5022/* Output : */
5023/* Description : Origin code for crt2group */
5024/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005025static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305026 struct xgi_hw_device_info *HwDeviceExtension,
5027 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005028{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305029 unsigned short tempbl;
5030 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005031
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305032 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305034 tempah = 0;
5035 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005036 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305037 tempah &= ~0x10; /* BTRAMDAC */
5038 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305040 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5041 | SetCRT2ToLCD)) {
5042 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005043 tempcl = pVBInfo->ModeType;
5044 tempcl -= ModeVGA;
5045 if (tempcl >= 0) {
5046 /* BT Color */
5047 tempah = (0x008 >> tempcl);
5048 if (tempah == 0)
5049 tempah = 1;
5050 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305051 }
5052 if (pVBInfo->VBInfo & SetInSlaveMode)
5053 tempah ^= 0x50; /* BTDAC */
5054 }
5055 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005056
Aaro Koskinen8104e322011-03-13 12:26:22 +02005057 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305058 tempah = 0x08;
5059 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005060
Miguel Gómeze123e462012-07-06 12:40:52 +02005061 if (pVBInfo->VBInfo & DisableCRT2Display)
5062 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005063
Miguel Gómeze123e462012-07-06 12:40:52 +02005064 tempah = 0x00;
5065 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005066
Miguel Gómeze123e462012-07-06 12:40:52 +02005067 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5068 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5069 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005070
Miguel Gómeze123e462012-07-06 12:40:52 +02005071 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5072 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5073 tempbl &= 0xf7;
5074 tempah |= 0x01;
5075 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305076 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005077
Miguel Gómeze123e462012-07-06 12:40:52 +02005078 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5079 tempbl &= 0xf7;
5080 tempah |= 0x01;
5081 }
5082
5083 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5084 goto reg_and_or;
5085
5086 tempbl &= 0xf8;
5087 tempah = 0x01;
5088
5089 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5090 tempah |= 0x02;
5091
5092 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5093 tempah = tempah ^ 0x05;
5094 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5095 tempah = tempah ^ 0x01;
5096 }
5097
5098 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5099 tempah |= 0x08;
5100
5101reg_and_or:
5102 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305104 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005105 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305106 tempah &= (~0x08);
5107 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5108 & SetInSlaveMode))) {
5109 tempah |= 0x010;
5110 }
5111 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305113 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305114 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005115 if (pVBInfo->VBInfo & DriverMode)
5116 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305117 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005118
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005119 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305120 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305122 if (pVBInfo->LCDInfo & SetLCDDualLink)
5123 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305125 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305126 if (pVBInfo->TVInfo & RPLLDIV2XO)
5127 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305128 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005129
Peter Huewe255aabd2012-02-09 21:11:44 +01005130 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5131 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305132 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005133
Peter Huewe255aabd2012-02-09 21:11:44 +01005134 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305135 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005136
Aaro Koskinen8104e322011-03-13 12:26:22 +02005137 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305138 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005139
Peter Huewe6896b942012-02-09 21:11:46 +01005140 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5141 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305142 tempah = 0;
5143 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005144
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305145 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5146 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005147 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305148 tempah |= 0x04; /* shampoo 0129 */
5149 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005150
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005151 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305152 tempah = 0x00;
5153 tempbl = 0xcf;
5154 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5155 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5156 tempah |= 0x30;
5157 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005158
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005159 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305160 tempah = 0;
5161 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305163 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5164 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5165 tempah |= 0xc0;
5166 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005167 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305168 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305170 tempah = 0;
5171 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005172 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305173 tempbl = 0xff;
5174 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5175 tempah |= 0x80;
5176 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005177
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005178 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005179
Peter Huewe6896b942012-02-09 21:11:46 +01005180 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305181 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005182 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5183 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305184 }
5185 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005186}
5187
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005188
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305189void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5190 struct vb_device_info *pVBInfo)
5191{
5192
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005193 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005194
5195}
5196
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305197void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5198 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005199{
5200
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005201 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005202
5203}
5204
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005205unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5206 unsigned short ModeNo, unsigned short ModeIdIndex,
5207 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005208{
Peter Huewef2c22602013-02-03 22:54:30 +01005209 const u8 LCDARefreshIndex[] = {
5210 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005211
Peter Hueweef9a6b92013-02-03 04:08:43 +01005212 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005213
Aaro Koskinen58839b02011-03-13 12:26:23 +02005214 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005215 index = index >> pVBInfo->SelectCRT2Rate;
5216 index &= 0x0F;
5217
5218 if (pVBInfo->LCDInfo & LCDNonExpanding)
5219 index = 0;
5220
5221 if (index > 0)
5222 index--;
5223
5224 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005225 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005226 temp = LCDARefreshIndex[pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005227
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005228 if (index > temp)
5229 index = temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005230 }
5231 }
5232
Aaro Koskinenb3979922012-11-04 21:14:52 +02005233 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005234 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005235 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005236 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5237 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005238 index++;
5239 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005240 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005241 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5242 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005243 index++;
5244 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005245 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5246 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005247 index++;
5248 }
5249 }
5250
5251 i = 0;
5252 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005253 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005254 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005255 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005256 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005257 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005258 if (temp < pVBInfo->ModeType)
5259 break;
5260 i++;
5261 index--;
5262
5263 } while (index != 0xFFFF);
5264 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5265 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005266 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005267 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005268 if (temp & InterlaceMode)
5269 i++;
5270 }
5271 }
5272 i--;
5273 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5274 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5275 RefreshRateTableIndex, &i, pVBInfo);
5276 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005277 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005278}
5279
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005280static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305281 struct xgi_hw_device_info *HwDeviceExtension,
5282 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005283{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005284 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005285
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005286 pVBInfo->SetFlag |= ProgrammingCRT2;
5287 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5288 ModeIdIndex, pVBInfo);
5289 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5290 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5291 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5292 HwDeviceExtension, pVBInfo);
5293 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5294 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005295}
5296
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005297static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005298 struct xgi_hw_device_info *HwDeviceExtension,
5299 struct vb_device_info *pVBInfo)
5300{
Peter Huewea9e29e62013-02-03 04:08:44 +01005301 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005302
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005303 pVBInfo->SetFlag |= ProgrammingCRT2;
5304 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5305 pVBInfo->SelectCRT2Rate = 4;
5306 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5307 ModeIdIndex, pVBInfo);
5308 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5309 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5310 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5311 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5312 RefreshRateTableIndex, pVBInfo);
5313 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5314 RefreshRateTableIndex, pVBInfo);
5315 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5316 RefreshRateTableIndex, pVBInfo);
5317 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5318 HwDeviceExtension, pVBInfo);
5319 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5320 RefreshRateTableIndex, pVBInfo);
5321 XGI_SetTap4Regs(pVBInfo);
5322 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5323 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5324 HwDeviceExtension, pVBInfo);
5325 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5326 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5327 XGI_AutoThreshold(pVBInfo);
5328 return 1;
5329}
5330
5331void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5332{
5333 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5334 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5335 0x05, 0x00 };
5336
5337 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5338
5339 unsigned char CR17, CR63, SR31;
5340 unsigned short temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005341
5342 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005343 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005344
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005345 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005346 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005347 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005348 pVBInfo->P3d4, 0x53) | 0x02));
5349
Peter Huewe9388ad92013-02-15 20:37:10 +01005350 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5351 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5352 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005353
Aaro Koskinen8104e322011-03-13 12:26:22 +02005354 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5355 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005356
Peter Huewe9388ad92013-02-15 20:37:10 +01005357 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005358 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005359
Peter Huewe9388ad92013-02-15 20:37:10 +01005360 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005361 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005362
Peter Huewe9388ad92013-02-15 20:37:10 +01005363 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005364 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005365 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005366 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005367
Aaro Koskinen8104e322011-03-13 12:26:22 +02005368 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005369
5370 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005371 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005372
5373 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005374 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005375 CRTCData[i]);
5376
5377 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005378 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005379 CRTCData[i]);
5380
5381 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005382 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005383 CRTCData[i]);
5384
Aaro Koskinen8104e322011-03-13 12:26:22 +02005385 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005386 & 0xE0));
5387
Aaro Koskinen8104e322011-03-13 12:26:22 +02005388 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5389 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5390 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005391
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005392 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005393
Peter Huewe771f3ee2013-02-15 20:37:13 +01005394 for (i = 0; i < 256 * 3; i++) {
5395 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005396 }
5397
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005398 mdelay(1);
5399
5400 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005401 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005402
5403 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005404 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005405 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005406 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005407
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005408 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005409 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005410
Peter Huewe771f3ee2013-02-15 20:37:13 +01005411 for (i = 0; i < 256 * 3; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005412 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005413 }
5414
Aaro Koskinen8104e322011-03-13 12:26:22 +02005415 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5416 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5417 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005418
Peter Huewe9388ad92013-02-15 20:37:10 +01005419 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005420 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005421 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005422}
5423
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005424static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5425 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005426 struct vb_device_info *pVBInfo)
5427{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005428 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005429
Peter Huewe6896b942012-02-09 21:11:46 +01005430 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5431 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinena2526d12013-05-29 23:59:10 +03005432 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Aaro Koskinend1724632013-05-29 23:59:09 +03005433 /* Power on */
5434 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005435
Aaro Koskinenb8e34b32013-05-29 23:59:08 +03005436 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
5437 SetCRT2ToRAMDAC)) {
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005438 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5439 tempah &= 0xDF;
5440 if (pVBInfo->VBInfo & SetInSlaveMode) {
5441 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
5442 tempah |= 0x20;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005443 }
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005444 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5445 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5446
5447 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5448
5449 if (!(tempah & 0x80))
5450 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5451 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005452 }
5453
Aaro Koskinena2526d12013-05-29 23:59:10 +03005454 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005455 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005456 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005457 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen056b5402013-05-29 23:59:11 +03005458 if (pVBInfo->VBInfo &
5459 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
5460 /* LVDS PLL power on */
5461 xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
5462 0x7F);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005463 /* LVDS Driver power on */
5464 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005465 }
5466 }
5467
5468 tempah = 0x00;
5469
5470 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5471 tempah = 0xc0;
5472
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005473 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5474 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5475 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5476 tempah = tempah & 0x40;
5477 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5478 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005479 }
5480 }
5481
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005482 /* EnablePart4_1F */
5483 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005484
Aaro Koskinend1724632013-05-29 23:59:09 +03005485 XGI_DisableGatingCRT(HwDeviceExtension, pVBInfo);
5486 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005487 } /* 301 */
5488 else { /* LVDS */
5489 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005490 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005491 /* enable CRT2 */
5492 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005493
Peter Huewe9388ad92013-02-15 20:37:10 +01005494 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005495 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005496 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005497
Aaro Koskinendc505562011-03-13 12:26:26 +02005498 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005499 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005500 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005501}
5502
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005503static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5504 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005505 unsigned short ModeNo, unsigned short ModeIdIndex,
5506 struct vb_device_info *pVBInfo)
5507{
Aaro Koskinena1579612012-04-07 01:14:05 +03005508 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005509
Aaro Koskinena1579612012-04-07 01:14:05 +03005510 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005511 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005512 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5513 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5514 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005515 XGI_ClearExt1Regs(pVBInfo);
5516
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005517 if (HwDeviceExtension->jChipType == XG27) {
5518 if (pVBInfo->IF_DEF_LVDS == 0)
5519 XGI_SetDefaultVCLK(pVBInfo);
5520 }
5521
5522 temp = ~ProgrammingCRT2;
5523 pVBInfo->SetFlag &= temp;
5524 pVBInfo->SelectCRT2Rate = 0;
5525
Peter Huewe6896b942012-02-09 21:11:46 +01005526 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5527 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005528 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005529 | SetInSlaveMode)) {
5530 pVBInfo->SetFlag |= ProgrammingCRT2;
5531 }
5532 }
5533
5534 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5535 ModeIdIndex, pVBInfo);
5536 if (RefreshRateTableIndex != 0xFFFF) {
5537 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5538 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5539 pVBInfo, HwDeviceExtension);
5540 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5541 RefreshRateTableIndex, pVBInfo);
5542 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5543 HwDeviceExtension, pVBInfo);
5544 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5545 RefreshRateTableIndex, pVBInfo);
5546 }
5547
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005548 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005549 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005550 if (temp & 0xA0) {
5551
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005552 if (HwDeviceExtension->jChipType == XG27)
5553 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5554 RefreshRateTableIndex, pVBInfo);
5555 else
5556 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5557 RefreshRateTableIndex, pVBInfo);
5558
5559 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5560 RefreshRateTableIndex);
5561
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005562 xgifb_set_lcd(HwDeviceExtension->jChipType,
5563 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005564
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005565 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005566 xgifb_set_lvds(xgifb_info,
5567 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005568 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005569 }
5570 }
5571
5572 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5573 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5574 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5575 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005576 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005577}
5578
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005579unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5580 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005581 unsigned short ModeNo)
5582{
5583 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005584 struct vb_device_info VBINF;
5585 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005586 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005587
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005588 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005589 pVBInfo->IF_DEF_YPbPr = 0;
5590 pVBInfo->IF_DEF_HiVision = 0;
5591 pVBInfo->IF_DEF_CRT2Monitor = 0;
5592 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005593 } else {
5594 pVBInfo->IF_DEF_YPbPr = 1;
5595 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005596 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005597 }
5598
Aaro Koskinen56810a92013-01-21 02:57:47 +02005599 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005600
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005601 /* for x86 Linux, XG21 LVDS */
5602 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005603 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005604 pVBInfo->IF_DEF_LVDS = 1;
5605 }
5606 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005607 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5608 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005609 pVBInfo->IF_DEF_LVDS = 1;
5610 }
5611 }
5612
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005613 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005614 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005615 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005616 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005617
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005618 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005619 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
5620
5621 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5622
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005623 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005624 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
5625 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
5626 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005627 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005628
Peter Huewee44adfd2013-02-03 22:54:39 +01005629 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5630 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005631 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005632 ModeIdIndex, pVBInfo);
5633
Peter Huewea3d675c2012-02-09 21:11:47 +01005634 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005635 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5636 HwDeviceExtension, pVBInfo);
5637 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005638 }
5639
Peter Huewe6896b942012-02-09 21:11:46 +01005640 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005641 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005642 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005643 case VB_CHIP_302:
5644 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5645 pVBInfo); /*add for CRT2 */
5646 break;
5647
5648 default:
5649 break;
5650 }
5651 }
5652
5653 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
5654 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005655 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005656 } /* !XG20 */
5657 else {
5658 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005659 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005660 ModeIdIndex,
5661 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005662 return 0;
5663
Aaro Koskinenb3979922012-11-04 21:14:52 +02005664 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005665 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005666
5667 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005668 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005669
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005670 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005671
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005672 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5673 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005674
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005675 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005676 }
5677
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005678 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
5679
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005680 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005681 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005682
5683 return 1;
5684}