blob: bf8bf63250fb3070b46508693539f9d0c3e77daa [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
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530898 if (pVBInfo->IF_DEF_LVDS == 1) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200899 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200900 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200901 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200902 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
903 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200904 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +0100905 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
906 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +0100907 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530908 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
909 RefreshRateTableIndex, HwDeviceExtension,
910 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200911 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200912 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200913 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200914 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200915 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200916 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
917 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530918 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200919 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200920 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200921 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200922 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
923 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200924 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530925 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200926
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530927 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200928 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800929 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200930 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200931 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200932 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530933 index = data;
934 index &= 0xE0;
935 data &= 0x1F;
936 data = data << 1;
937 data += 1;
938 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200939 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530940 }
941 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200942}
943
Aaro Koskinene85f2032011-11-27 23:03:07 +0200944static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
945{
946 unsigned char temp;
947
948 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
949 temp = (temp & 1) << 6;
950 /* SR06[6] 18bit Dither */
951 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
952 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
953 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
954
955}
956
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200957static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530958 struct xgi_hw_device_info *HwDeviceExtension,
959 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200960{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530961 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200962
Aaro Koskinen58839b02011-03-13 12:26:23 +0200963 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530964 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200965 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200966
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300967 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
968 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
969 data &= 0xC0;
970 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
971 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
972 data |= 0x01;
973 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200974
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530975 if (HwDeviceExtension->jChipType == XG21)
976 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200977}
978
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200979static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
980 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
981 struct vb_device_info *pVBInfo)
982{
983 unsigned short data, data2 = 0;
984 short VCLK;
985
986 unsigned char index;
987
Aaro Koskinena39325d2012-11-04 21:14:53 +0200988 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300989 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200990 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200991
Aaro Koskinen58839b02011-03-13 12:26:23 +0200992 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200993 data &= 0xf3;
994 if (VCLK >= 200)
995 data |= 0x0c; /* VCLK > 200 */
996
997 if (HwDeviceExtension->jChipType >= XG20)
998 data &= ~0x04; /* 2 pixel mode */
999
Aaro Koskinen8104e322011-03-13 12:26:22 +02001000 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001001
1002 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001003 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001004 data &= 0xE7;
1005 if (VCLK < 200)
1006 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001007 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001008 }
1009
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001010 data2 = 0x00;
1011
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001012 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001013 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001014 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001015
1016}
1017
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001018static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301019 unsigned short ModeNo, unsigned short ModeIdIndex,
1020 unsigned short RefreshRateTableIndex,
1021 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001022{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301023 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1024 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001025
Aaro Koskinenb3979922012-11-04 21:14:52 +02001026 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001027 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001028
Aaro Koskinen58839b02011-03-13 12:26:23 +02001029 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001030 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001031
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001032 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301033 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001034 data2 |= 0x02;
1035 data3 = pVBInfo->ModeType - ModeVGA;
1036 data3 = data3 << 2;
1037 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301038 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301040 if (data)
1041 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001042
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001043 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001044 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001045 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301047 data = 0x0000;
1048 if (infoflag & InterlaceMode) {
1049 if (xres == 1024)
1050 data = 0x0035;
1051 else if (xres == 1280)
1052 data = 0x0048;
1053 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001054
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001055 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1056 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001057
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301058 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001059 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001060
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301061 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001062
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301063 if (modeflag & LineCompareOff)
1064 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001065
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001066 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301067 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001068 data = data ^ 0x60;
1069 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001070 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001071
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301072 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1073 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001074
Aaro Koskinen58839b02011-03-13 12:26:23 +02001075 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001076
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301077 if (HwDeviceExtension->jChipType == XG27) {
1078 if (data & 0x40)
1079 data = 0x2c;
1080 else
1081 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001082 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001083 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301084 } else if (HwDeviceExtension->jChipType >= XG20) {
1085 if (data & 0x40)
1086 data = 0x33;
1087 else
1088 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001089 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1090 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301091 } else {
1092 if (data & 0x40)
1093 data = 0x2c;
1094 else
1095 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001096 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301097 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001098
1099}
1100
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001101static void XGI_WriteDAC(unsigned short dl,
1102 unsigned short ah,
1103 unsigned short al,
1104 unsigned short dh,
1105 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001106{
1107 unsigned short temp, bh, bl;
1108
1109 bh = ah;
1110 bl = al;
1111
1112 if (dl != 0) {
1113 temp = bh;
1114 bh = dh;
1115 dh = temp;
1116 if (dl == 1) {
1117 temp = bl;
1118 bl = dh;
1119 dh = temp;
1120 } else {
1121 temp = bl;
1122 bl = bh;
1123 bh = temp;
1124 }
1125 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001126 outb((unsigned short) dh, pVBInfo->P3c9);
1127 outb((unsigned short) bh, pVBInfo->P3c9);
1128 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001129}
1130
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001131static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301132 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001133{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001134 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1135 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001136
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001137 outb(0xFF, pVBInfo->P3c6);
1138 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001139
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001140 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301141 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001142
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301143 for (k = 0; k < 3; k++) {
1144 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301146 if (data & 0x01)
1147 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001148
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301149 if (data & 0x02)
1150 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001151
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001152 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301153 data = data >> 2;
1154 }
1155 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001156
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001157 for (i = 16; i < 32; i++) {
1158 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001159
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001160 for (k = 0; k < 3; k++)
1161 outb(data, pVBInfo->P3c9);
1162 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001163
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001164 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001165
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001166 for (m = 0; m < 9; m++) {
1167 di = si;
1168 bx = si + 0x04;
1169 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001170
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001171 for (n = 0; n < 3; n++) {
1172 for (o = 0; o < 5; o++) {
1173 dh = table[si];
1174 ah = table[di];
1175 al = table[bx];
1176 si++;
1177 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301178 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001179
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001180 si -= 2;
1181
1182 for (o = 0; o < 3; o++) {
1183 dh = table[bx];
1184 ah = table[di];
1185 al = table[si];
1186 si--;
1187 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1188 }
1189
1190 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301191 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001192
1193 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301194 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001195}
1196
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001197static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1198 unsigned short ModeIdIndex,
1199 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001200{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301201 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001202
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001203 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001204 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001205
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001206 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001207 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001208
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001209 xres = XGI330_ModeResInfo[resindex].HTotal;
1210 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001211
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001212 if (modeflag & HalfDCLK)
1213 xres = xres << 1;
1214
1215 if (modeflag & DoubleScanMode)
1216 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301218 if (xres == 720)
1219 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001220
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301221 pVBInfo->VGAHDE = xres;
1222 pVBInfo->HDE = xres;
1223 pVBInfo->VGAVDE = yres;
1224 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001225}
1226
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001227static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001228 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001229 unsigned short ModeIdIndex,
1230 unsigned short RefreshRateTableIndex,
1231 struct vb_device_info *pVBInfo)
1232{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001233 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001234
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001235 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001236
Aaro Koskinenb3979922012-11-04 21:14:52 +02001237 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001238
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001239 i = 0;
1240
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001241 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001242 tempdx = pVBInfo->LCDResInfo;
1243 if (tempbx & 0x0080) { /* OEMUtil */
1244 tempbx &= (~0x0080);
1245 tempdx = pVBInfo->LCDTypeInfo;
1246 }
1247
1248 if (pVBInfo->LCDInfo & EnableScalingLCD)
1249 tempdx &= (~PanelResInfo);
1250
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001251 if (table[i].PANELID == tempdx) {
1252 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001253 tempdx = pVBInfo->LCDInfo;
1254
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001255 if (modeflag & HalfDCLK)
1256 tempdx |= SetLCDLowResolution;
1257
1258 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001259 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001260 break;
1261 }
1262 i++;
1263 }
1264
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001265 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001266}
1267
Aaro Koskinen24572542012-09-11 00:15:21 +03001268static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001269 unsigned short ModeIdIndex,
1270 unsigned short RefreshRateTableIndex,
1271 struct vb_device_info *pVBInfo)
1272{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001273 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001274
Aaro Koskinenb3979922012-11-04 21:14:52 +02001275 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001276 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001277 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001278 tempdx = pVBInfo->TVInfo;
1279
1280 if (pVBInfo->VBInfo & SetInSlaveMode)
1281 tempdx = tempdx | SetTVLockMode;
1282
1283 if (modeflag & HalfDCLK)
1284 tempdx = tempdx | SetTVLowResolution;
1285
1286 i = 0;
1287
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001288 while (XGI_TVDataTable[i].MASK != 0xffff) {
1289 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1290 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001291 break;
1292 i++;
1293 }
1294
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001295 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001296}
1297
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001298static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301299 unsigned short RefreshRateTableIndex,
1300 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001301{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001302 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001303
Aaro Koskinen6008f872012-11-04 21:14:49 +02001304 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1305 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001306
Aaro Koskinen6008f872012-11-04 21:14:49 +02001307 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1308 RefreshRateTableIndex, pVBInfo);
1309 pVBInfo->VGAHT = LCDPtr->VGAHT;
1310 pVBInfo->VGAVT = LCDPtr->VGAVT;
1311 pVBInfo->HT = LCDPtr->LCDHT;
1312 pVBInfo->VT = LCDPtr->LCDVT;
1313
1314 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1315 return;
1316
1317 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1318 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1319 pVBInfo->HDE = 1024;
1320 pVBInfo->VDE = 768;
1321 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1322 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1323 pVBInfo->HDE = 1280;
1324 pVBInfo->VDE = 1024;
1325 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1326 pVBInfo->HDE = 1400;
1327 pVBInfo->VDE = 1050;
1328 } else {
1329 pVBInfo->HDE = 1600;
1330 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301331 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001332}
1333
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001334static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301335 unsigned short RefreshRateTableIndex,
1336 struct xgi_hw_device_info *HwDeviceExtension,
1337 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001338{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001339 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001340 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1341 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001342
Peter Huewea3d675c2012-02-09 21:11:47 +01001343 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001344 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001345 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001346
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001347 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001348 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301349 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001350
1351 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1352
Peter Huewea3d675c2012-02-09 21:11:47 +01001353 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001354 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1355 ModeIdIndex, RefreshRateTableIndex,
1356 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001357 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001358 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001359 }
1360
1361 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001362}
1363
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001364static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1365{
1366 unsigned char tempal, tempah, tempbl, i;
1367
Aaro Koskinen58839b02011-03-13 12:26:23 +02001368 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001369 tempal = tempah & 0x0F;
1370 tempah = tempah & 0xF0;
1371 i = 0;
1372 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1373
1374 while (tempbl != 0xFF) {
1375 if (tempbl & 0x80) { /* OEMUtil */
1376 tempal = tempah;
1377 tempbl = tempbl & ~(0x80);
1378 }
1379
1380 if (tempal == tempbl)
1381 break;
1382
1383 i++;
1384
1385 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1386 }
1387
1388 return i;
1389}
1390
1391static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1392{
1393 unsigned short tempah, tempal, tempbl, i;
1394
1395 tempal = pVBInfo->LCDResInfo;
1396 tempah = pVBInfo->LCDTypeInfo;
1397
1398 i = 0;
1399 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1400
1401 while (tempbl != 0xFF) {
1402 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1403 tempal = tempah;
1404 tempbl &= ~0x80;
1405 }
1406
1407 if (tempal == tempbl)
1408 break;
1409
1410 i++;
1411 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1412 }
1413
1414 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001415 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001416 pVBInfo->LCDTypeInfo = 0;
1417 i = 0;
1418 }
1419
1420 return i;
1421}
1422
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001423static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1424 unsigned short *VSyncWidth,
1425 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001426{
1427 unsigned short Index;
1428
1429 Index = XGI_GetLCDCapPtr(pVBInfo);
1430 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1431 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1432
1433 return;
1434}
1435
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001436static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301437 unsigned short RefreshRateTableIndex,
1438 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001439{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301440 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1441 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001442 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001443
Aaro Koskinenb3979922012-11-04 21:14:52 +02001444 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe826215d2013-02-05 00:29:46 +01001445 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo, ModeIdIndex,
1446 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001447
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001448 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1449 push1 = tempbx;
1450 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001451
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001452 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001453 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1454 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001455 tempax = 1024;
1456 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001457 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1458 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001459 tempax = 1280;
1460 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001461 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001462 tempax = 1400;
1463 tempbx = 1050;
1464 } else {
1465 tempax = 1600;
1466 tempbx = 1200;
1467 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001468
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001469 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1470 pVBInfo->HDE = tempax;
1471 pVBInfo->VDE = tempbx;
1472 pVBInfo->VGAHDE = tempax;
1473 pVBInfo->VGAVDE = tempbx;
1474 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001475
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001476 tempax = pVBInfo->HT;
1477
Peter Huewe826215d2013-02-05 00:29:46 +01001478 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001479
1480 tempcx = pVBInfo->HDE;
1481 tempbx = tempbx & 0x0fff;
1482 tempcx += tempbx;
1483
1484 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001485 tempcx -= tempax;
1486
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001487 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001488
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001489 tempcx = tempcx >> 3;
1490 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001491
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001492 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1493 (unsigned short) (tempbx & 0xff));
1494 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1495 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001496
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001497 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001498
Peter Huewe826215d2013-02-05 00:29:46 +01001499 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001500
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001501 tempcx = push2;
1502
1503 if (pVBInfo->LCDInfo & EnableScalingLCD)
1504 tempcx = LCDPtr1->LCDHSync;
1505
1506 tempcx += tempbx;
1507
1508 if (tempcx >= tempax)
1509 tempcx -= tempax;
1510
1511 tempax = tempbx & 0x07;
1512 tempax = tempax >> 5;
1513 tempcx = tempcx >> 3;
1514 tempbx = tempbx >> 3;
1515
1516 tempcx &= 0x1f;
1517 tempax |= tempcx;
1518
1519 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1520 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1521 (unsigned short) (tempbx & 0xff));
1522
1523 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001524 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001525 tempcx = pVBInfo->VDE;
1526
1527 tempbx = tempbx & 0x0fff;
1528 tempcx += tempbx;
1529 if (tempcx >= tempax)
1530 tempcx -= tempax;
1531
1532 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1533 (unsigned short) (tempbx & 0xff));
1534 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1535 (unsigned short) (tempcx & 0xff));
1536
1537 tempbx = (tempbx >> 8) & 0x07;
1538 tempcx = (tempcx >> 8) & 0x07;
1539
1540 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1541 (unsigned short) ((tempcx << 3)
1542 | tempbx));
1543
1544 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001545 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001546
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001547 tempcx = push1;
1548
1549 if (pVBInfo->LCDInfo & EnableScalingLCD)
1550 tempcx = LCDPtr1->LCDVSync;
1551
1552 tempcx += tempbx;
1553 if (tempcx >= tempax)
1554 tempcx -= tempax;
1555
1556 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1557 (unsigned short) (tempbx & 0xff));
1558 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1559 (unsigned short) (tempcx & 0x0f));
1560
1561 tempax = ((tempbx >> 8) & 0x07) << 3;
1562
1563 tempbx = pVBInfo->VGAVDE;
1564 if (tempbx != pVBInfo->VDE)
1565 tempax |= 0x40;
1566
Peter Huewea3d675c2012-02-09 21:11:47 +01001567 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001568 tempax |= 0x40;
1569
1570 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1571 tempax);
1572
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001573 tempbx = pVBInfo->VDE;
1574 tempax = pVBInfo->VGAVDE;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001575
1576 temp = tempax; /* 0430 ylshieh */
1577 temp1 = (temp << 18) / tempbx;
1578
1579 tempdx = (unsigned short) ((temp << 18) % tempbx);
1580
1581 if (tempdx != 0)
1582 temp1 += 1;
1583
1584 temp2 = temp1;
1585 push3 = temp2;
1586
1587 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1588 (unsigned short) (temp2 & 0xff));
1589 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1590 (unsigned short) ((temp2 >> 8) & 0xff));
1591
1592 tempbx = (unsigned short) (temp2 >> 16);
1593 tempax = tempbx & 0x03;
1594
1595 tempbx = pVBInfo->VGAVDE;
1596 if (tempbx == pVBInfo->VDE)
1597 tempax |= 0x04;
1598
1599 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1600
1601 if (pVBInfo->VBType & VB_XGI301C) {
1602 temp2 = push3;
1603 xgifb_reg_set(pVBInfo->Part4Port,
1604 0x3c,
1605 (unsigned short) (temp2 & 0xff));
1606 xgifb_reg_set(pVBInfo->Part4Port,
1607 0x3b,
1608 (unsigned short) ((temp2 >> 8) &
1609 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001610 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001611 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1612 ~0xc0,
1613 (unsigned short) ((tempbx &
1614 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001615
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001616 tempcx = pVBInfo->VGAVDE;
1617 if (tempcx == pVBInfo->VDE)
1618 xgifb_reg_and_or(pVBInfo->Part4Port,
1619 0x30, ~0x0c, 0x00);
1620 else
1621 xgifb_reg_and_or(pVBInfo->Part4Port,
1622 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301623 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001624
1625 tempcx = pVBInfo->VGAHDE;
1626 tempbx = pVBInfo->HDE;
1627
1628 temp1 = tempcx << 16;
1629
1630 tempax = (unsigned short) (temp1 / tempbx);
1631
1632 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1633 tempax = 65535;
1634
1635 temp3 = tempax;
1636 temp1 = pVBInfo->VGAHDE << 16;
1637
1638 temp1 /= temp3;
1639 temp3 = temp3 << 16;
1640 temp1 -= 1;
1641
1642 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1643
1644 tempax = (unsigned short) (temp3 & 0xff);
1645 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1646
1647 temp1 = pVBInfo->VGAVDE << 18;
1648 temp1 = temp1 / push3;
1649 tempbx = (unsigned short) (temp1 & 0xffff);
1650
Peter Huewe255aabd2012-02-09 21:11:44 +01001651 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001652 tempbx -= 1;
1653
1654 tempax = ((tempbx >> 8) & 0xff) << 3;
1655 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1656 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1657 (unsigned short) (tempax & 0xff));
1658 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1659 (unsigned short) (tempbx & 0xff));
1660
1661 temp3 = temp3 >> 16;
1662
1663 if (modeflag & HalfDCLK)
1664 temp3 = temp3 >> 1;
1665
1666 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1667 (unsigned short) ((temp3 >> 8) & 0xff));
1668 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1669 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001670}
1671
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001672/* --------------------------------------------------------------------- */
1673/* Function : XGI_GETLCDVCLKPtr */
1674/* Input : */
1675/* Output : al -> VCLK Index */
1676/* Description : */
1677/* --------------------------------------------------------------------- */
1678static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1679 struct vb_device_info *pVBInfo)
1680{
1681 unsigned short index;
1682
Peter Huewea3d675c2012-02-09 21:11:47 +01001683 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001684 index = XGI_GetLCDCapPtr1(pVBInfo);
1685
1686 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1687 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1688 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1689 } else { /* LCDA */
1690 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1691 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1692 }
1693 }
1694 return;
1695}
1696
1697static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1698 unsigned short ModeNo, unsigned short ModeIdIndex,
1699 struct vb_device_info *pVBInfo)
1700{
1701
1702 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001703 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001704
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001705 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001706 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001707
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001708 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1709 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001710 index = XGI_GetLCDCapPtr(pVBInfo);
1711 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1712
Peter Huewea3d675c2012-02-09 21:11:47 +01001713 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001714 return tempal;
1715
1716 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001717 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001718 (VB_SIS301B |
1719 VB_SIS302B |
1720 VB_SIS301LV |
1721 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001722 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001723 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001724 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001725 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001726 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001727 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001728 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001729 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001730 tempal = TVCLKBASE_315 +
1731 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001732
1733 }
1734 return tempal;
1735 }
1736
Peter Huewe599801f2012-02-09 21:11:45 +01001737 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001738 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001739 return tempal;
1740 }
1741
Peter Huewe599801f2012-02-09 21:11:45 +01001742 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001743 tempal = YPbPr525pVCLK;
1744 return tempal;
1745 }
1746
1747 tempal = NTSC1024VCLK;
1748
1749 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001750 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001751 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001752 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001753 }
1754
1755 if (pVBInfo->VBInfo & SetCRT2ToTV)
1756 return tempal;
1757 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001758 } /* {End of VB} */
1759
Peter Huewe516354e2013-02-15 20:37:11 +01001760 inb((pVBInfo->P3ca + 0x02));
Aaro Koskinena39325d2012-11-04 21:14:53 +02001761 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001762 return tempal;
1763}
1764
1765static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1766 unsigned char *di_1, struct vb_device_info *pVBInfo)
1767{
Peter Huewe6896b942012-02-09 21:11:46 +01001768 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1769 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001770 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1771 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001772 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001773 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001774 }
1775 } else {
1776 *di_0 = XGI_VCLKData[tempal].SR2B;
1777 *di_1 = XGI_VCLKData[tempal].SR2C;
1778 }
1779}
1780
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001781static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301782 unsigned short RefreshRateTableIndex,
1783 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001784{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301785 unsigned char di_0, di_1, tempal;
1786 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001787
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301788 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1789 pVBInfo);
1790 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1791 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001792
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301793 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001794 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301795 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001796 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301797 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001798 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1799 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301800 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001801 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1802 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301803 }
1804 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001805}
1806
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001807static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301808 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001809{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301810 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001811
Peter Huewe6896b942012-02-09 21:11:46 +01001812 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1813 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301814 tempcl = 0;
1815 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001816 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301818 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001819 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301820 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001821 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301822 if (!(temp & 0x40))
1823 tempcl |= ActiveCRT1;
1824 }
1825 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001826
Aaro Koskinen58839b02011-03-13 12:26:23 +02001827 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301828 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301830 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001831 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001832 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301833 if (tempax & 0x04)
1834 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301836 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001837
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301838 if (!(tempcl & ActiveLCD))
1839 if (temp == 0x01)
1840 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001841
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301842 if (temp == 0x04)
1843 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001844
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301845 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001846 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301848 if (!(temp & 0x08))
1849 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001850
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301851 if (!(temp & 0x04))
1852 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301854 if (temp & 0x02)
1855 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001856
Peter Huewe599801f2012-02-09 21:11:45 +01001857 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301858 if (temp & 0x01)
1859 tempch |= ActiveHiTV;
1860 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001861
Peter Huewe599801f2012-02-09 21:11:45 +01001862 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001863 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301864 pVBInfo->Part2Port,
1865 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301867 if (temp & 0x10)
1868 tempch |= ActiveYPbPr;
1869 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001870
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301871 if (tempch != 0)
1872 tempcl |= ActiveTV;
1873 }
1874 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001875
Aaro Koskinen58839b02011-03-13 12:26:23 +02001876 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301877 if (tempcl & ActiveLCD) {
1878 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1879 if (temp & ActiveTV)
1880 tempcl |= ActiveTV;
1881 }
1882 }
1883 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001884 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001885 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301887 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001888 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301889 } else {
1890 return;
1891 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001892}
1893
Bill Pemberton80adad82010-06-17 13:10:51 -04001894void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001895{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301896 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001897
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001898 tempbx = VB_SIS302B;
1899 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1900 if (flag == 0x02)
1901 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001902
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001903 tempbx = VB_SIS301;
1904 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1905 if (flag < 0xB0)
1906 goto finish;
1907
1908 tempbx = VB_SIS301B;
1909 if (flag < 0xC0)
1910 goto bigger_than_0xB0;
1911
1912 tempbx = VB_XGI301C;
1913 if (flag < 0xD0)
1914 goto bigger_than_0xB0;
1915
1916 tempbx = VB_SIS301LV;
1917 if (flag < 0xE0)
1918 goto bigger_than_0xB0;
1919
1920 tempbx = VB_SIS302LV;
1921 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1922 if (tempah != 0xFF)
1923 tempbx = VB_XGI301C;
1924
1925bigger_than_0xB0:
1926 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1927 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1928 if (!(flag & 0x02))
1929 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301930 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001931
1932finish:
1933 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001934}
1935
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02001936static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301937 struct xgi_hw_device_info *HwDeviceExtension,
1938 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001939{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301940 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001941
Aaro Koskinenb3979922012-11-04 21:14:52 +02001942 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301943 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001944 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301945 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001946
Miguel Gómezf9317352012-07-06 12:40:48 +02001947 if (!(pVBInfo->VBType & 0xFFFF))
1948 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001949
Miguel Gómezf9317352012-07-06 12:40:48 +02001950 /* Check Display Device */
1951 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1952 tempbx = tempbx | temp;
1953 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1954 push = temp;
1955 push = push << 8;
1956 tempax = temp << 8;
1957 tempbx = tempbx | tempax;
1958 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1959 | SetInSlaveMode | DisableCRT2Display);
1960 temp = 0xFFFF ^ temp;
1961 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001962
Miguel Gómezf9317352012-07-06 12:40:48 +02001963 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001964
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001965 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1966 VB_XGI301C)) {
1967 if (temp & EnableDualEdge) {
1968 tempbx |= SetCRT2ToDualEdge;
1969 if (temp & SetToLCDA)
1970 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02001971 }
1972 }
1973
1974 if (pVBInfo->IF_DEF_YPbPr == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001975 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
Miguel Gómezf9317352012-07-06 12:40:48 +02001976 if (temp & SetYPbPr) {
1977 if (pVBInfo->IF_DEF_HiVision == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001978 /* shampoo add for new scratch */
1979 temp = xgifb_reg_get(pVBInfo->P3d4,
1980 0x35);
Miguel Gómezf9317352012-07-06 12:40:48 +02001981 temp &= YPbPrMode;
1982 tempbx |= SetCRT2ToHiVision;
1983
1984 if (temp != YPbPrMode1080i) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001985 tempbx &= (~SetCRT2ToHiVision);
1986 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301987 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301988 }
1989 }
1990 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001991 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001992
Miguel Gómezf9317352012-07-06 12:40:48 +02001993 tempax = push; /* restore CR31 */
1994
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001995 if (pVBInfo->IF_DEF_YPbPr == 1) {
1996 if (pVBInfo->IF_DEF_HiVision == 1)
1997 temp = 0x09FC;
1998 else
1999 temp = 0x097C;
2000 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2001 temp = 0x01FC;
2002 } else {
2003 temp = 0x017C;
Miguel Gómezf9317352012-07-06 12:40:48 +02002004 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002005
Miguel Gómezf9317352012-07-06 12:40:48 +02002006 if (!(tempbx & temp)) {
2007 tempax |= DisableCRT2Display;
2008 tempbx = 0;
2009 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002010
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002011 if (!(pVBInfo->VBType & VB_NoLCD)) {
2012 if (tempbx & XGI_SetCRT2ToLCDA) {
2013 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002014 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002015 SwitchCRT2));
2016 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002017 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
2018 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002019 }
2020 }
2021
2022 /* shampoo add */
2023 /* for driver abnormal */
2024 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2025 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2026 if (tempbx & SetCRT2ToRAMDAC) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002027 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
2028 SwitchCRT2 | SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002029 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302030 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002031 } else {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002032 tempbx &= (~(SetCRT2ToRAMDAC | SetCRT2ToLCD |
Miguel Gómezf9317352012-07-06 12:40:48 +02002033 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302034 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002035 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002036
Miguel Gómezf9317352012-07-06 12:40:48 +02002037 if (!(pVBInfo->VBType & VB_NoLCD)) {
2038 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002039 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002040 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002041 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302042 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002043 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002044
Miguel Gómezf9317352012-07-06 12:40:48 +02002045 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002046 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002047 SetSimuScanMode);
2048 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2049 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002050
Miguel Gómezf9317352012-07-06 12:40:48 +02002051 if (pVBInfo->IF_DEF_YPbPr == 1) {
2052 if (tempbx & SetCRT2ToYPbPr525750)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002053 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002054 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002055
Miguel Gómezf9317352012-07-06 12:40:48 +02002056 if (pVBInfo->IF_DEF_HiVision == 1) {
2057 if (tempbx & SetCRT2ToHiVision)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002058 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002059 SetSimuScanMode);
2060 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002061
Miguel Gómezf9317352012-07-06 12:40:48 +02002062 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2063 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2064 tempbx = DisableCRT2Display;
2065 }
2066
2067 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002068 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002069 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002070 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002071 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002072
Miguel Gómezf9317352012-07-06 12:40:48 +02002073 /* LCD+TV can't support in slave mode
2074 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002075 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2076 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002077 SetCRT2ToDualEdge);
2078 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302079 }
2080 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002081
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302082 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002083}
2084
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002085static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302086 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002087{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002088 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302090 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002091 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2092 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002093
Peter Huewe5fc699f2013-02-03 04:08:45 +01002094 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2095 if (tempbx & TVSetPAL) {
2096 tempbx &= (SetCHTVOverScan |
2097 TVSetPALM |
2098 TVSetPALN |
2099 TVSetPAL);
2100 if (tempbx & TVSetPALM)
2101 /* set to NTSC if PAL-M */
2102 tempbx &= ~TVSetPAL;
2103 } else
2104 tempbx &= (SetCHTVOverScan |
2105 TVSetNTSCJ |
2106 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002107
Aaro Koskinena8b35292013-02-09 00:03:45 +02002108 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2109 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302111 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002112 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002113 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302114 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302116 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002117 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002118
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302119 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002120 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302121 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002122 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302123 }
2124 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302126 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002127 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2128 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302129 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002130
Aaro Koskinena8b35292013-02-09 00:03:45 +02002131 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2132 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2133 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002134
Aaro Koskinena8b35292013-02-09 00:03:45 +02002135 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2136 /* NTSC 1024x768, */
2137 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002138
Aaro Koskinena8b35292013-02-09 00:03:45 +02002139 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002140
Aaro Koskinena8b35292013-02-09 00:03:45 +02002141 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2142 if (pVBInfo->VBInfo & SetInSlaveMode)
2143 tempbx &= (~RPLLDIV2XO);
2144 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2145 tempbx &= (~RPLLDIV2XO);
2146 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2147 VB_SIS301LV | VB_SIS302LV |
2148 VB_XGI301C))) {
2149 if (tempbx & TVSimuMode)
2150 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302151 }
2152 }
2153 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002154}
2155
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002156static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2157 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002158{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002159 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302161 pVBInfo->LCDResInfo = 0;
2162 pVBInfo->LCDTypeInfo = 0;
2163 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002164
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002165 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002166 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002167 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302168 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302170 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002171 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002172
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002173 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002174 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302175 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002176 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002177 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302178 tempax &= 0x0F;
2179 else
2180 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002181
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302182 if ((resinfo == 6) || (resinfo == 9)) {
2183 if (tempax >= 3)
2184 tempbx |= PanelRef75Hz;
2185 } else if ((resinfo == 7) || (resinfo == 8)) {
2186 if (tempax >= 4)
2187 tempbx |= PanelRef75Hz;
2188 }
2189 }
2190 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302192 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002193
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302194 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002195
Peter Huewea3d675c2012-02-09 21:11:47 +01002196 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302197 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302199 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002200
Aaro Koskinen58839b02011-03-13 12:26:23 +02002201 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002202
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302203 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302205 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002206
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302207 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002208
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302209 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002210
Aaro Koskinen718e7152013-02-09 00:03:46 +02002211 if (((pVBInfo->VBType & VB_SIS302LV) ||
2212 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2213 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002214
Aaro Koskinen718e7152013-02-09 00:03:46 +02002215 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2216 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2217 (!(tempbx & EnableScalingLCD)))
2218 /*
2219 * set to center in 1280x1024 LCDB
2220 * for Panel_1400x1050
2221 */
2222 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302224 if (pVBInfo->VBInfo & SetInSlaveMode) {
2225 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002226 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302227 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002228 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302229 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002230
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302231 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302233 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002234}
2235
Bill Pemberton108afbf2010-06-17 13:10:47 -04002236unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302237 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002238{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002239 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002240 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002241 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002242 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002243 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302244 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302246 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002247}
2248
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002249static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2250{
2251 unsigned char ujRet = 0;
2252 unsigned char i = 0;
2253
2254 for (i = 0; i < 8; i++) {
2255 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002256 ujRet |= (ujDate >> i) & 1;
2257 }
2258
2259 return ujRet;
2260}
2261
2262/*----------------------------------------------------------------------------*/
2263/* output */
2264/* bl[5] : LVDS signal */
2265/* bl[1] : LVDS backlight */
2266/* bl[0] : LVDS VDD */
2267/*----------------------------------------------------------------------------*/
2268static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2269{
2270 unsigned char CR4A, temp;
2271
Aaro Koskinen58839b02011-03-13 12:26:23 +02002272 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002273 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002274
Aaro Koskinen58839b02011-03-13 12:26:23 +02002275 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002276
2277 temp = XG21GPIODataTransfer(temp);
2278 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002279 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002280 return temp;
2281}
2282
2283/*----------------------------------------------------------------------------*/
2284/* output */
2285/* bl[5] : LVDS signal */
2286/* bl[1] : LVDS backlight */
2287/* bl[0] : LVDS VDD */
2288/*----------------------------------------------------------------------------*/
2289static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2290{
2291 unsigned char CR4A, CRB4, temp;
2292
Aaro Koskinen58839b02011-03-13 12:26:23 +02002293 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002294 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002295
Aaro Koskinen58839b02011-03-13 12:26:23 +02002296 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002297
2298 temp &= 0x0C;
2299 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002300 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002301 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002302 temp |= ((CRB4 & 0x04) << 3);
2303 return temp;
2304}
2305
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002306/*----------------------------------------------------------------------------*/
2307/* input */
2308/* bl[5] : 1;LVDS signal on */
2309/* bl[1] : 1;LVDS backlight on */
2310/* bl[0] : 1:LVDS VDD on */
2311/* bh: 100000b : clear bit 5, to set bit5 */
2312/* 000010b : clear bit 1, to set bit1 */
2313/* 000001b : clear bit 0, to set bit0 */
2314/*----------------------------------------------------------------------------*/
2315static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2316 struct vb_device_info *pVBInfo)
2317{
2318 unsigned char CR4A, temp;
2319
2320 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2321 tempbh &= 0x23;
2322 tempbl &= 0x23;
2323 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2324
2325 if (tempbh & 0x20) {
2326 temp = (tempbl >> 4) & 0x02;
2327
2328 /* CR B4[1] */
2329 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2330
2331 }
2332
2333 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2334
2335 temp = XG21GPIODataTransfer(temp);
2336 temp &= ~tempbh;
2337 temp |= tempbl;
2338 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2339}
2340
Aaro Koskinen776115a2011-11-27 23:03:10 +02002341static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2342 struct vb_device_info *pVBInfo)
2343{
2344 unsigned char CR4A, temp;
2345 unsigned short tempbh0, tempbl0;
2346
2347 tempbh0 = tempbh;
2348 tempbl0 = tempbl;
2349 tempbh0 &= 0x20;
2350 tempbl0 &= 0x20;
2351 tempbh0 >>= 3;
2352 tempbl0 >>= 3;
2353
2354 if (tempbh & 0x20) {
2355 temp = (tempbl >> 4) & 0x02;
2356
2357 /* CR B4[1] */
2358 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2359
2360 }
2361 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2362
2363 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2364 tempbh &= 0x03;
2365 tempbl &= 0x03;
2366 tempbh <<= 2;
2367 tempbl <<= 2; /* GPIOC,GPIOD */
2368 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2369 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2370}
2371
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002372static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2373 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302374 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002375{
2376
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002377 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302378 if (pXGIHWDE->jChipType == XG21) {
2379 if (pVBInfo->IF_DEF_LVDS == 1) {
2380 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002381 /* LVDS VDD on */
2382 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002383 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302384 }
2385 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002386 /* LVDS signal on */
2387 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002388 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002389 /* LVDS backlight on */
2390 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302391 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002392 /* DVO/DVI signal on */
2393 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302394 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002395
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302396 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002397
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302398 if (pXGIHWDE->jChipType == XG27) {
2399 if (pVBInfo->IF_DEF_LVDS == 1) {
2400 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002401 /* LVDS VDD on */
2402 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002403 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302404 }
2405 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002406 /* LVDS signal on */
2407 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002408 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002409 /* LVDS backlight on */
2410 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302411 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002412 /* DVO/DVI signal on */
2413 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302414 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002415
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302416 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002417}
2418
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002419void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2420 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302421 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002422{
2423
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302424 if (pXGIHWDE->jChipType == XG21) {
2425 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002426 /* LVDS backlight off */
2427 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002428 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302429 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002430 /* DVO/DVI signal off */
2431 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302432 }
2433 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002434
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302435 if (pXGIHWDE->jChipType == XG27) {
2436 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002437 /* LVDS backlight off */
2438 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002439 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302440 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002441
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302442 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002443 /* DVO/DVI signal off */
2444 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302445 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002446
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002447 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002448}
2449
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002450static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002451{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002452 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302453 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002454
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002455 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302456 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002457}
2458
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002459static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002460{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002461 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002462}
2463
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002464static void XGI_SaveCRT2Info(unsigned short ModeNo,
2465 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002466{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302467 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002468
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002469 /* reserve CR34 for CRT1 Mode No */
2470 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302471 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2472 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002473 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002474}
2475
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002476static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2477 unsigned short ModeIdIndex,
2478 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002479{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302480 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002481
Aaro Koskinenb3979922012-11-04 21:14:52 +02002482 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002483 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2484 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002485 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002486 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002487
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002488 if (modeflag & HalfDCLK)
2489 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002490
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002491 if (modeflag & DoubleScanMode)
2492 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002493
Miguel Gómez3339db82012-07-06 12:40:49 +02002494 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2495 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002496
Aaro Koskinen22006832013-02-09 00:03:47 +02002497 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2498 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2499 if (yres == 1024)
2500 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302501 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002502 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002503
Aaro Koskinen22006832013-02-09 00:03:47 +02002504 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2505 if (yres == 400)
2506 yres = 405;
2507 else if (yres == 350)
2508 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002509
Aaro Koskinen22006832013-02-09 00:03:47 +02002510 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2511 if (yres == 360)
2512 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002513 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002514 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002515
Aaro Koskinen22006832013-02-09 00:03:47 +02002516 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2517 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2518 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2519 if (yres == 350)
2520 yres = 357;
2521 else if (yres == 400)
2522 yres = 420;
2523 else if (yres == 480)
2524 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002525 }
2526 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302527 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002528
Miguel Gómez3339db82012-07-06 12:40:49 +02002529 if (xres == 720)
2530 xres = 640;
2531
2532exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302533 pVBInfo->VGAHDE = xres;
2534 pVBInfo->HDE = xres;
2535 pVBInfo->VGAVDE = yres;
2536 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002537}
2538
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002539static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002540{
2541
Peter Huewea3d675c2012-02-09 21:11:47 +01002542 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002543 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302544 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002545
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302546 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002547}
2548
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002549static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2550 unsigned short ModeIdIndex,
2551 unsigned short RefreshRateTableIndex,
2552 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002553{
2554 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002555 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002556
2557 pVBInfo->RVBHCMAX = 1;
2558 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002559 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002560 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002561 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002562 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2563 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002564 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002565 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002566 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002567 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002568 tempcx &= 0x0100;
2569 tempcx = tempcx << 2;
2570 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002571 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002572
2573 if (temp1 & 0x01)
2574 tempbx |= 0x0100;
2575
2576 if (temp1 & 0x20)
2577 tempbx |= 0x0200;
2578 tempax += 5;
2579
2580 if (modeflag & Charx8Dot)
2581 tempax *= 8;
2582 else
2583 tempax *= 9;
2584
2585 pVBInfo->VGAHT = tempax;
2586 pVBInfo->HT = tempax;
2587 tempbx++;
2588 pVBInfo->VGAVT = tempbx;
2589 pVBInfo->VT = tempbx;
2590}
2591
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002592static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302593 unsigned short RefreshRateTableIndex,
2594 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002595{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002596 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002597
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002598 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002599
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002600 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002601 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2602 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302603 pVBInfo->NewFlickerMode = 0;
2604 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002605
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302606 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2607 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2608 pVBInfo);
2609 return;
2610 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002611
Peter Huewea3d675c2012-02-09 21:11:47 +01002612 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002613 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002614 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002615
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302616 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2617 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2618 pVBInfo->VGAHT = LCDPtr->VGAHT;
2619 pVBInfo->VGAVT = LCDPtr->VGAVT;
2620 pVBInfo->HT = LCDPtr->LCDHT;
2621 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002622
Peter Huewe255aabd2012-02-09 21:11:44 +01002623 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302624 tempax = 1024;
2625 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002626
Peter Huewea3d675c2012-02-09 21:11:47 +01002627 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302628 if (pVBInfo->VGAVDE == 357)
2629 tempbx = 527;
2630 else if (pVBInfo->VGAVDE == 420)
2631 tempbx = 620;
2632 else if (pVBInfo->VGAVDE == 525)
2633 tempbx = 775;
2634 else if (pVBInfo->VGAVDE == 600)
2635 tempbx = 775;
Peter Huewe7580d7f2013-05-18 00:19:54 +02002636 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002637 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302638 tempax = 1024;
2639 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002640 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302641 tempax = 1280;
2642 if (pVBInfo->VGAVDE == 360)
2643 tempbx = 768;
2644 else if (pVBInfo->VGAVDE == 375)
2645 tempbx = 800;
2646 else if (pVBInfo->VGAVDE == 405)
2647 tempbx = 864;
2648 else
2649 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002650 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302651 tempax = 1280;
2652 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002653 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302654 tempax = 1280;
2655 if (pVBInfo->VGAVDE == 350)
2656 tempbx = 700;
2657 else if (pVBInfo->VGAVDE == 400)
2658 tempbx = 800;
2659 else if (pVBInfo->VGAVDE == 1024)
2660 tempbx = 960;
2661 else
2662 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002663 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302664 tempax = 1400;
2665 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002666
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302667 if (pVBInfo->VGAVDE == 1024) {
2668 tempax = 1280;
2669 tempbx = 1024;
2670 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002671 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302672 tempax = 1600;
2673 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002674 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302675 if (pVBInfo->VGAVDE == 350)
2676 tempbx = 875;
2677 else if (pVBInfo->VGAVDE == 400)
2678 tempbx = 1000;
2679 }
2680 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002681
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302682 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2683 tempax = pVBInfo->VGAHDE;
2684 tempbx = pVBInfo->VGAVDE;
2685 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002686
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302687 pVBInfo->HDE = tempax;
2688 pVBInfo->VDE = tempbx;
2689 return;
2690 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002691
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302692 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002693 struct SiS_TVData const *TVPtr;
2694
2695 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2696 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002697
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302698 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2699 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2700 pVBInfo->VGAHT = TVPtr->VGAHT;
2701 pVBInfo->VGAVT = TVPtr->VGAVT;
2702 pVBInfo->HDE = TVPtr->TVHDE;
2703 pVBInfo->VDE = TVPtr->TVVDE;
2704 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2705 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002706
Peter Huewe599801f2012-02-09 21:11:45 +01002707 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302708 if (resinfo == 0x08)
2709 pVBInfo->NewFlickerMode = 0x40;
2710 else if (resinfo == 0x09)
2711 pVBInfo->NewFlickerMode = 0x40;
2712 else if (resinfo == 0x12)
2713 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002714
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302715 if (pVBInfo->VGAVDE == 350)
2716 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002717
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302718 tempax = ExtHiTVHT;
2719 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002720
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302721 if (pVBInfo->VBInfo & SetInSlaveMode) {
2722 if (pVBInfo->TVInfo & TVSimuMode) {
2723 tempax = StHiTVHT;
2724 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002725
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302726 if (!(modeflag & Charx8Dot)) {
2727 tempax = StHiTextTVHT;
2728 tempbx = StHiTextTVVT;
2729 }
2730 }
2731 }
Peter Huewe599801f2012-02-09 21:11:45 +01002732 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2733 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302734 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2735 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2736 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002737
Peter Huewe599801f2012-02-09 21:11:45 +01002738 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302739 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2740 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002741 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302742 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2743 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2744 if (pVBInfo->TVInfo & NTSC1024x768)
2745 tempax = NTSC1024x768HT;
2746 }
2747 } else {
2748 tempax = PALHT;
2749 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002750 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302751 tempax = NTSCHT;
2752 tempbx = NTSCVT;
2753 if (pVBInfo->TVInfo & NTSC1024x768)
2754 tempax = NTSC1024x768HT;
2755 }
2756 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002757
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302758 pVBInfo->HT = tempax;
2759 pVBInfo->VT = tempbx;
2760 return;
2761 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002762}
2763
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002764static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302765 unsigned short RefreshRateTableIndex,
2766 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002767{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002768 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002769
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302770 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2771 pVBInfo);
2772 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2773 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002774
Peter Huewe6896b942012-02-09 21:11:46 +01002775 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302776 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002777 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2778 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2779 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302780 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002781 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2782 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302783 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002784
Aaro Koskinen8104e322011-03-13 12:26:22 +02002785 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002786
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302787 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002788 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302789 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002790 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002791}
2792
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002793static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2794 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002795{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002796 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2797 short index;
2798 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302799
Aaro Koskinenb3979922012-11-04 21:14:52 +02002800 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002801 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302802
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002803 if (index < 0)
2804 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302805
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002806 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302807}
2808
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002809static unsigned short XGI_GetOffset(unsigned short ModeNo,
2810 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302811 unsigned short RefreshRateTableIndex,
2812 struct xgi_hw_device_info *HwDeviceExtension,
2813 struct vb_device_info *pVBInfo)
2814{
2815 unsigned short temp, colordepth, modeinfo, index, infoflag,
2816 ColorDepth[] = { 0x01, 0x02, 0x04 };
2817
Aaro Koskinenb3979922012-11-04 21:14:52 +02002818 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002819 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302820
2821 index = (modeinfo >> 8) & 0xFF;
2822
Aaro Koskinen224114c2012-11-04 21:14:59 +02002823 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302824
2825 if (infoflag & InterlaceMode)
2826 temp = temp << 1;
2827
2828 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2829
2830 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2831 temp = ModeNo - 0x7C;
2832 colordepth = ColorDepth[temp];
2833 temp = 0x6B;
2834 if (infoflag & InterlaceMode)
2835 temp = temp << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302836 }
Peter Huewe053004b2013-02-15 20:37:12 +01002837 return temp * colordepth;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302838}
2839
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002840static void XGI_SetCRT2Offset(unsigned short ModeNo,
2841 unsigned short ModeIdIndex,
2842 unsigned short RefreshRateTableIndex,
2843 struct xgi_hw_device_info *HwDeviceExtension,
2844 struct vb_device_info *pVBInfo)
2845{
2846 unsigned short offset;
2847 unsigned char temp;
2848
2849 if (pVBInfo->VBInfo & SetInSlaveMode)
2850 return;
2851
2852 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2853 HwDeviceExtension, pVBInfo);
2854 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002855 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002856 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002857 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002858 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002859 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002860}
2861
Randy Dunlap89229672010-08-10 08:46:44 -07002862static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002863{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002864 /* threshold high ,disable auto threshold */
2865 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2866 /* threshold low default 04h */
2867 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002868}
2869
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002870static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302871 struct xgi_hw_device_info *HwDeviceExtension,
2872 unsigned short RefreshRateTableIndex,
2873 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002874{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002875 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002876
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302877 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2878 HwDeviceExtension, pVBInfo);
2879 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002880
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302881 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002882 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002883
Aaro Koskinen8104e322011-03-13 12:26:22 +02002884 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2885 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002886}
2887
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002888static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302889 struct xgi_hw_device_info *HwDeviceExtension,
2890 unsigned short RefreshRateTableIndex,
2891 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002892{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302893 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002894 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002895
Aaro Koskinena39325d2012-11-04 21:14:53 +02002896 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002897 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002898 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002899
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302900 /* bainy change table name */
2901 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002902 /* BTVGA2HT 0x08,0x09 */
2903 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002904 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302905 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002906 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002907 /* BTVGA2HDEE 0x0A,0x0C */
2908 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002909 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302910 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2911 pushbx = pVBInfo->VGAHDE / 2 + 16;
2912 tempcx = tempcx >> 1;
2913 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2914 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302916 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002917 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2918 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002919 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302920 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002921 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302922 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002923 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302924 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2925 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2926 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002927
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302928 tempbx += 4;
2929 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002930
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302931 if (tempcx > (pVBInfo->VGAHT / 2))
2932 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002933
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302934 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002935
Aaro Koskinen8104e322011-03-13 12:26:22 +02002936 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302937 } else {
2938 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002939 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302940 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002941 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002942 /* BTVGA2HDEE 0x0A,0x0C */
2943 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002944 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302945 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2946 pushbx = pVBInfo->VGAHDE + 16;
2947 tempcx = tempcx >> 1;
2948 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2949 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002950
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302951 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002952 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2953 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002954 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302955 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002956 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302957 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002958 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302959 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2960 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2961 tempbx += 16;
2962 tempcx += 16;
2963 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002964
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302965 if (tempcx > pVBInfo->VGAHT)
2966 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002967
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302968 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002969 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302970 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002971
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302972 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2973 tempbx = pushbx;
2974 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2975 tempax |= (tempbx & 0xFF00);
2976 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002977 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302978 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002979 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302980 tempcx = (pVBInfo->VGAVT - 1);
2981 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002982
Aaro Koskinen8104e322011-03-13 12:26:22 +02002983 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302984 tempbx = pVBInfo->VGAVDE - 1;
2985 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002986 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302987 temp = ((tempbx & 0xFF00) << 3) >> 8;
2988 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002989 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002990
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002991 /* BTVGA2VRS 0x10,0x11 */
2992 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
2993 /* BTVGA2VRE 0x11 */
2994 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002995
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302996 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002997 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
2998 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002999
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303000 if (temp & 0x04)
3001 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003002
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303003 if (temp & 0x080)
3004 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003005
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003006 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003007
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303008 if (temp & 0x08)
3009 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003010
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003011 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303012 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3013 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003014
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303015 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003016 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303017 temp = ((tempbx & 0xFF00) >> 8) << 4;
3018 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003019 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303020 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003021
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303022 if (modeflag & DoubleScanMode)
3023 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303025 if (modeflag & HalfDCLK)
3026 tempax |= 0x40;
3027
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003028 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003029}
3030
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003031static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3032{
3033 unsigned long tempax, tempbx;
3034
3035 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3036 & 0xFFFF;
3037 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3038 tempax = (tempax * pVBInfo->HT) / tempbx;
3039
3040 return (unsigned short) tempax;
3041}
3042
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003043static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303044 struct xgi_hw_device_info *HwDeviceExtension,
3045 unsigned short RefreshRateTableIndex,
3046 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003047{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303048 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003049 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003050
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003051 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003052 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3053 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303055 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3056 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003057
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303058 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003059 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303060 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003061
Peter Huewe6896b942012-02-09 21:11:46 +01003062 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303063 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003064
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303065 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003066
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303067 if (modeflag & HalfDCLK)
3068 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003069
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303070 tempax = (tempax / tempcx) - 1;
3071 tempbx |= ((tempax & 0x00FF) << 8);
3072 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003073 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003074
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303075 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003076
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303077 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003078 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3079 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303080 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003081
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003082 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3083 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303084 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303085 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003086
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003087 /* 0x05 Horizontal Display Start */
3088 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3089 /* 0x06 Horizontal Blank end */
3090 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303092 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3093 if (pVBInfo->VBInfo & SetCRT2ToTV)
3094 tempax = pVBInfo->VGAHT;
3095 else
3096 tempax = XGI_GetVGAHT2(pVBInfo);
3097 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303099 if (tempax >= pVBInfo->VGAHT)
3100 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303102 if (modeflag & HalfDCLK)
3103 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303105 tempax = (tempax / tempcx) - 5;
3106 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003107 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303108 temp = (tempbx & 0x00FF) - 1;
3109 if (!(modeflag & HalfDCLK)) {
3110 temp -= 6;
3111 if (pVBInfo->TVInfo & TVSimuMode) {
3112 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003113 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303114 }
3115 }
3116 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303117 tempbx = (tempbx & 0xFF00) >> 8;
3118 tempcx = (tempcx + tempbx) >> 1;
3119 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303121 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3122 temp -= 1;
3123 if (!(modeflag & HalfDCLK)) {
3124 if ((modeflag & Charx8Dot)) {
3125 temp += 4;
3126 if (pVBInfo->VGAHDE >= 800)
3127 temp -= 6;
3128 }
3129 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003130 } else if (!(modeflag & HalfDCLK)) {
3131 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003132 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003133 pVBInfo->VGAHDE >= 800) {
3134 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003135 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003136 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003137 (pVBInfo->LCDInfo & LCDNonExpanding))
3138 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303139 }
3140 }
3141 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003142
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003143 /* 0x07 Horizontal Retrace Start */
3144 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3145 /* 0x08 Horizontal Retrace End */
3146 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003147
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303148 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3149 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003150 if (ModeNo == 0x50) {
Peter Huewe85b38472013-05-13 23:41:49 +02003151 if (pVBInfo->TVInfo == SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003152 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303153 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003154 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303155 0x08, 0x03);
3156 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003157 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303158 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003159 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303160 0x08, 0x02);
3161 }
3162 }
3163 }
3164 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003165
Aaro Koskinen8104e322011-03-13 12:26:22 +02003166 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003167 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003168 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303170 tempbx = pVBInfo->VGAVT;
3171 push1 = tempbx;
3172 tempcx = 0x121;
3173 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303175 if (tempbx == 357)
3176 tempbx = 350;
3177 if (tempbx == 360)
3178 tempbx = 350;
3179 if (tempbx == 375)
3180 tempbx = 350;
3181 if (tempbx == 405)
3182 tempbx = 400;
3183 if (tempbx == 525)
3184 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003185
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303186 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303188 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003189 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003190 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303191 if (tempbx == 350)
3192 tempbx += 5;
3193 if (tempbx == 480)
3194 tempbx += 5;
3195 }
3196 }
3197 }
3198 tempbx--;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303199 tempbx--;
3200 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003201 /* 0x10 vertical Blank Start */
3202 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303203 tempbx = push2;
3204 tempbx--;
3205 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003206 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003207
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303208 if (tempbx & 0x0100)
3209 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303211 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303213 if (modeflag & DoubleScanMode)
3214 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003215
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303216 if (tempbx & 0x0200)
3217 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303219 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003220 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003221
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303222 if (tempbx & 0x0400)
3223 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003224
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003225 /* 0x11 Vertival Blank End */
3226 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303227
3228 tempax = push1;
3229 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3230 tempax = tempax >> 2;
3231 push1 = tempax; /* push ax */
3232
3233 if (resinfo != 0x09) {
3234 tempax = tempax << 1;
3235 tempbx += tempax;
3236 }
3237
Peter Huewe599801f2012-02-09 21:11:45 +01003238 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003239 if ((pVBInfo->VBType & VB_SIS301LV) &&
3240 !(pVBInfo->TVInfo & TVSetHiVision)) {
3241 if ((pVBInfo->TVInfo & TVSimuMode) &&
3242 (pVBInfo->TVInfo & TVSetPAL)) {
3243 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3244 !(pVBInfo->TVInfo &
3245 (TVSetYPbPr525p |
3246 TVSetYPbPr750p |
3247 TVSetHiVision)))
3248 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303249 }
3250 } else {
3251 tempbx -= 10;
3252 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003253 } else if (pVBInfo->TVInfo & TVSimuMode) {
3254 if (pVBInfo->TVInfo & TVSetPAL) {
3255 if (pVBInfo->VBType & VB_SIS301LV) {
3256 if (!(pVBInfo->TVInfo &
3257 (TVSetYPbPr525p |
3258 TVSetYPbPr750p |
3259 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303260 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003261 } else {
3262 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303263 }
3264 }
3265 }
3266 tempax = push1;
3267 tempax = tempax >> 2;
3268 tempax++;
3269 tempax += tempbx;
3270 push1 = tempax; /* push ax */
3271
Peter Huewe599801f2012-02-09 21:11:45 +01003272 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303273 if (tempbx <= 513) {
3274 if (tempax >= 513)
3275 tempbx = 513;
3276 }
3277 }
3278
3279 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003280 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303281 tempbx--;
3282 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003283 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303284
3285 if (tempbx & 0x0100)
3286 tempcx |= 0x0008;
3287
3288 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003289 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303290
3291 tempbx++;
3292
3293 if (tempbx & 0x0100)
3294 tempcx |= 0x0004;
3295
3296 if (tempbx & 0x0200)
3297 tempcx |= 0x0080;
3298
3299 if (tempbx & 0x0400)
3300 tempcx |= 0x0C00;
3301
3302 tempbx = push1; /* pop ax */
3303 temp = tempbx & 0x00FF;
3304 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003305 /* 0x0D vertical Retrace End */
3306 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303307
3308 if (tempbx & 0x0010)
3309 tempcx |= 0x2000;
3310
3311 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003312 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303313 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003314 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303315 tempax = modeflag;
3316 temp = (tempax & 0xFF00) >> 8;
3317
3318 temp = (temp >> 1) & 0x09;
3319
Peter Huewe6896b942012-02-09 21:11:46 +01003320 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303321 temp |= 0x01;
3322
Aaro Koskinen8104e322011-03-13 12:26:22 +02003323 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3324 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3325 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303326
3327 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3328 temp = 0x80;
3329 else
3330 temp = 0x00;
3331
Aaro Koskinen8104e322011-03-13 12:26:22 +02003332 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303333
3334 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003335}
3336
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003337static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303338 unsigned short RefreshRateTableIndex,
3339 struct xgi_hw_device_info *HwDeviceExtension,
3340 struct vb_device_info *pVBInfo)
3341{
3342 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003343 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003344 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303345
3346 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3347
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003348 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003349 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303350
3351 tempax = 0;
3352
3353 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3354 tempax |= 0x0800;
3355
3356 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3357 tempax |= 0x0400;
3358
3359 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3360 tempax |= 0x0200;
3361
Peter Huewe599801f2012-02-09 21:11:45 +01003362 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303363 tempax |= 0x1000;
3364
Peter Huewe599801f2012-02-09 21:11:45 +01003365 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303366 tempax |= 0x0100;
3367
Peter Huewe599801f2012-02-09 21:11:45 +01003368 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303369 tempax &= 0xfe00;
3370
3371 tempax = (tempax & 0xff00) >> 8;
3372
Aaro Koskinen8104e322011-03-13 12:26:22 +02003373 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003374 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303375
Peter Huewe599801f2012-02-09 21:11:45 +01003376 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003377 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303378
Peter Huewe599801f2012-02-09 21:11:45 +01003379 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003380 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303381
3382 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003383 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303384
3385 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003386 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303387
3388 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003389 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303390 }
3391
Peter Huewe599801f2012-02-09 21:11:45 +01003392 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3393 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003394 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303395
Peter Huewe599801f2012-02-09 21:11:45 +01003396 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003397 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303398
Peter Huewe599801f2012-02-09 21:11:45 +01003399 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003400 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303401 }
3402
3403 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003404 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303405
3406 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003407 /* di->temp2[j] */
3408 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303409
3410 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003411 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303412
3413 temp = pVBInfo->NewFlickerMode;
3414 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003415 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303416
Peter Huewe599801f2012-02-09 21:11:45 +01003417 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303418 tempax = 520;
3419 else
3420 tempax = 440;
3421
3422 if (pVBInfo->VDE <= tempax) {
3423 tempax -= pVBInfo->VDE;
3424 tempax = tempax >> 2;
3425 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3426 push1 = tempax;
3427 temp = (tempax & 0xFF00) >> 8;
3428 temp += (unsigned short) TimingPoint[0];
3429
Peter Huewe6896b942012-02-09 21:11:46 +01003430 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3431 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303432 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3433 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003434 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303435 tempcx = pVBInfo->VGAHDE;
3436 if (tempcx >= 1024) {
3437 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003438 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303439 temp = 0x19; /* PAL */
3440 }
3441 }
3442 }
3443
Aaro Koskinen8104e322011-03-13 12:26:22 +02003444 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303445 tempax = push1;
3446 temp = (tempax & 0xFF00) >> 8;
3447 temp += TimingPoint[1];
3448
Peter Huewe6896b942012-02-09 21:11:46 +01003449 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3450 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303451 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3452 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003453 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303454 tempcx = pVBInfo->VGAHDE;
3455 if (tempcx >= 1024) {
3456 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003457 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303458 temp = 0x52; /* PAL */
3459 }
3460 }
3461 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003462 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303463 }
3464
3465 /* 301b */
3466 tempcx = pVBInfo->HT;
3467
3468 if (XGI_IsLCDDualLink(pVBInfo))
3469 tempcx = tempcx >> 1;
3470
3471 tempcx -= 2;
3472 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003473 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303474
3475 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003476 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303477
3478 tempcx = pVBInfo->HT >> 1;
3479 push1 = tempcx; /* push cx */
3480 tempcx += 7;
3481
Peter Huewe599801f2012-02-09 21:11:45 +01003482 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303483 tempcx -= 4;
3484
3485 temp = tempcx & 0x00FF;
3486 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003487 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303488
3489 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3490 tempbx += tempcx;
3491 push2 = tempbx;
3492 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003493 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303494 temp = (tempbx & 0xFF00) >> 8;
3495 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003496 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303497
3498 tempbx = push2;
3499 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003500 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303501 tempbx = tempbx - 4;
3502 tempcx = tempbx;
3503 }
3504
3505 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003506 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303507
3508 j += 2;
3509 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3510 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003511 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303512 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003513 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303514
3515 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003516 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303517 tempcx -= 4;
3518
3519 temp = tempcx & 0xFF;
3520 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003521 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303522
3523 tempcx = push1; /* pop cx */
3524 j += 2;
3525 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3526 tempcx -= temp;
3527 temp = tempcx & 0x00FF;
3528 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003529 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303530
3531 tempcx -= 11;
3532
3533 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3534 tempax = XGI_GetVGAHT2(pVBInfo);
3535 tempcx = tempax - 1;
3536 }
3537 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003538 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303539
3540 tempbx = pVBInfo->VDE;
3541
3542 if (pVBInfo->VGAVDE == 360)
3543 tempbx = 746;
3544 if (pVBInfo->VGAVDE == 375)
3545 tempbx = 746;
3546 if (pVBInfo->VGAVDE == 405)
3547 tempbx = 853;
3548
3549 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003550 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003551 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003552 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003553 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303554 tempbx = tempbx >> 1;
3555 } else
3556 tempbx = tempbx >> 1;
3557 }
3558
3559 tempbx -= 2;
3560 temp = tempbx & 0x00FF;
3561
Peter Huewe599801f2012-02-09 21:11:45 +01003562 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003563 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003564 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303565 if (pVBInfo->VBInfo & SetInSlaveMode) {
3566 if (ModeNo == 0x2f)
3567 temp += 1;
3568 }
3569 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003570 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3571 if (ModeNo == 0x2f)
3572 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303573 }
3574 }
3575
Aaro Koskinen8104e322011-03-13 12:26:22 +02003576 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303577
3578 temp = (tempcx & 0xFF00) >> 8;
3579 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3580
Peter Huewe599801f2012-02-09 21:11:45 +01003581 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003582 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003583 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303584 temp |= 0x10;
3585
3586 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3587 temp |= 0x20;
3588 }
3589 } else {
3590 temp |= 0x10;
3591 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3592 temp |= 0x20;
3593 }
3594 }
3595
Aaro Koskinen8104e322011-03-13 12:26:22 +02003596 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303597
Peter Huewe6896b942012-02-09 21:11:46 +01003598 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3599 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303600 tempbx = pVBInfo->VDE;
3601 tempcx = tempbx - 2;
3602
3603 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003604 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3605 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303606 tempbx = tempbx >> 1;
3607 }
3608
Peter Huewe6896b942012-02-09 21:11:46 +01003609 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303610 temp = 0;
3611 if (tempcx & 0x0400)
3612 temp |= 0x20;
3613
3614 if (tempbx & 0x0400)
3615 temp |= 0x40;
3616
Aaro Koskinen8104e322011-03-13 12:26:22 +02003617 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303618 }
3619
3620 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003621 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303622 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003623 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303624 }
3625
3626 tempbx = tempbx & 0x00FF;
3627
3628 if (!(modeflag & HalfDCLK)) {
3629 tempcx = pVBInfo->VGAHDE;
3630 if (tempcx >= pVBInfo->HDE) {
3631 tempbx |= 0x2000;
3632 tempax &= 0x00FF;
3633 }
3634 }
3635
3636 tempcx = 0x0101;
3637
3638 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3639 if (pVBInfo->VGAHDE >= 1024) {
3640 tempcx = 0x1920;
3641 if (pVBInfo->VGAHDE >= 1280) {
3642 tempcx = 0x1420;
3643 tempbx = tempbx & 0xDFFF;
3644 }
3645 }
3646 }
3647
3648 if (!(tempbx & 0x2000)) {
3649 if (modeflag & HalfDCLK)
3650 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3651
3652 push1 = tempbx;
3653 tempeax = pVBInfo->VGAHDE;
3654 tempebx = (tempcx & 0xFF00) >> 8;
3655 longtemp = tempeax * tempebx;
3656 tempecx = tempcx & 0x00FF;
3657 longtemp = longtemp / tempecx;
3658
3659 /* 301b */
3660 tempecx = 8 * 1024;
3661
Peter Huewe6896b942012-02-09 21:11:46 +01003662 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3663 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303664 tempecx = tempecx * 8;
3665 }
3666
3667 longtemp = longtemp * tempecx;
3668 tempecx = pVBInfo->HDE;
3669 temp2 = longtemp % tempecx;
3670 tempeax = longtemp / tempecx;
3671 if (temp2 != 0)
3672 tempeax += 1;
3673
3674 tempax = (unsigned short) tempeax;
3675
3676 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003677 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3678 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303679 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3680 }
3681 /* end 301b */
3682
3683 tempbx = push1;
3684 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3685 | (tempbx & 0x00FF));
3686 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3687 | (tempax & 0x00FF));
3688 temp = (tempax & 0xFF00) >> 8;
3689 } else {
3690 temp = (tempax & 0x00FF) >> 8;
3691 }
3692
Aaro Koskinen8104e322011-03-13 12:26:22 +02003693 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303694 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003695 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303696 temp = tempcx & 0x00FF;
3697
3698 if (tempbx & 0x2000)
3699 temp = 0;
3700
3701 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3702 temp |= 0x18;
3703
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003704 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003705 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303706 tempbx = 0x0382;
3707 tempcx = 0x007e;
3708 } else {
3709 tempbx = 0x0369;
3710 tempcx = 0x0061;
3711 }
3712
3713 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003714 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303715 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003716 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303717
3718 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3719 temp = temp << 2;
3720 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3721
Peter Huewe599801f2012-02-09 21:11:45 +01003722 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303723 temp |= 0x10;
3724
Peter Huewe599801f2012-02-09 21:11:45 +01003725 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303726 temp |= 0x20;
3727
Peter Huewe599801f2012-02-09 21:11:45 +01003728 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303729 temp |= 0x60;
3730 }
3731
Aaro Koskinen8104e322011-03-13 12:26:22 +02003732 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003733 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003734 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303735
Peter Huewe599801f2012-02-09 21:11:45 +01003736 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303737 if (pVBInfo->TVInfo & NTSC1024x768) {
3738 TimingPoint = XGI_NTSC1024AdjTime;
3739 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003740 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303741 TimingPoint[j]);
3742 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003743 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303744 }
3745 }
3746
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003747 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303748 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003749 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003750 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303751 0x08); /* PALM Mode */
3752 }
3753
Peter Huewe599801f2012-02-09 21:11:45 +01003754 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003755 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303756 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003757 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303758
Aaro Koskinendc505562011-03-13 12:26:26 +02003759 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303760 }
3761
Peter Huewe599801f2012-02-09 21:11:45 +01003762 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303763 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003764 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303765 }
3766
3767 if (pVBInfo->VBInfo & SetCRT2ToTV)
3768 return;
3769}
3770
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003771static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303772 struct xgi_hw_device_info *HwDeviceExtension,
3773 unsigned short RefreshRateTableIndex,
3774 struct vb_device_info *pVBInfo)
3775{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003776 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3777 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303778
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003779 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303780
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003781 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303782 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3783 return;
3784
3785 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3786
3787 if (XGI_IsLCDDualLink(pVBInfo))
3788 tempbx = tempbx >> 1;
3789
3790 tempbx -= 1;
3791 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003792 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303793 temp = (tempbx & 0xFF00) >> 8;
3794 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003795 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303796 temp = 0x01;
3797
Aaro Koskinen8104e322011-03-13 12:26:22 +02003798 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303799 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303800 tempbx--;
3801 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003802 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303803 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003804 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303805
3806 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303807 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003808 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303809 temp = (tempcx & 0xFF00) >> 8;
3810 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003811 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003812 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3813 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3814 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3815 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303816
Justin P. Mattock558f7582012-10-02 21:17:11 -07003817 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003818 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
3819 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
3820 RefreshRateTableIndex, pVBInfo);
3821 else
3822 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
3823 ModeIdIndex, RefreshRateTableIndex,
3824 pVBInfo);
3825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303826 tempah = pVBInfo->LCDResInfo;
3827 tempah &= PanelResInfo;
3828
Peter Huewe255aabd2012-02-09 21:11:44 +01003829 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303830 tempbx = 1024;
3831 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003832 } else if ((tempah == Panel_1280x1024) ||
3833 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303834 tempbx = 1280;
3835 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003836 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303837 tempbx = 1400;
3838 tempcx = 1050;
3839 } else {
3840 tempbx = 1600;
3841 tempcx = 1200;
3842 }
3843
3844 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3845 tempbx = pVBInfo->HDE;
3846 tempcx = pVBInfo->VDE;
3847 }
3848
3849 pushbx = tempbx;
3850 tempax = pVBInfo->VT;
3851 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3852 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3853 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3854 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3855 tempbx = pVBInfo->LCDVDES;
3856 tempcx += tempbx;
3857
3858 if (tempcx >= tempax)
3859 tempcx -= tempax; /* lcdvdes */
3860
3861 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003862 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303863 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003864 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303865 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3866 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3867 tempah = tempch;
3868 tempah = tempah << 3;
3869 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003870 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303871
3872 /* getlcdsync() */
3873 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3874 tempcx = tempbx;
3875 tempax = pVBInfo->VT;
3876 tempbx = pVBInfo->LCDVRS;
3877
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303878 tempcx += tempbx;
3879 if (tempcx >= tempax)
3880 tempcx -= tempax;
3881
3882 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003883 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303884 temp = (tempbx & 0xFF00) >> 8;
3885 temp = temp << 4;
3886 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003887 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303888 tempcx = pushbx;
3889 tempax = pVBInfo->HT;
3890 tempbx = pVBInfo->LCDHDES;
3891 tempbx &= 0x0FFF;
3892
3893 if (XGI_IsLCDDualLink(pVBInfo)) {
3894 tempax = tempax >> 1;
3895 tempbx = tempbx >> 1;
3896 tempcx = tempcx >> 1;
3897 }
3898
Peter Huewe6896b942012-02-09 21:11:46 +01003899 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303900 tempbx += 1;
3901
3902 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3903 tempbx += 1;
3904
3905 tempcx += tempbx;
3906
3907 if (tempcx >= tempax)
3908 tempcx -= tempax;
3909
3910 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003911 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303912 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003913 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303914 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003915 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303916 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003917 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303918
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303919 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3920 tempcx = tempax;
3921 tempax = pVBInfo->HT;
3922 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303923 if (XGI_IsLCDDualLink(pVBInfo)) {
3924 tempax = tempax >> 1;
3925 tempbx = tempbx >> 1;
3926 tempcx = tempcx >> 1;
3927 }
3928
Peter Huewe6896b942012-02-09 21:11:46 +01003929 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303930 tempbx += 1;
3931
3932 tempcx += tempbx;
3933
3934 if (tempcx >= tempax)
3935 tempcx -= tempax;
3936
3937 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003938 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303939
3940 temp = (tempbx & 0xFF00) >> 8;
3941 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003942 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303943 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003944 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303945
Peter Huewea3d675c2012-02-09 21:11:47 +01003946 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303947 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003948 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3949 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303950 | VB_XGI301C)) {
3951 temp = 0xC6;
3952 } else
3953 temp = 0xC4;
3954
Aaro Koskinen8104e322011-03-13 12:26:22 +02003955 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3956 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303957 }
3958
3959 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01003960 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3961 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303962 | VB_XGI301C)) {
3963 temp = 0x4F;
3964 } else
3965 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003966 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303967 }
3968 }
3969}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003970
3971/* --------------------------------------------------------------------- */
3972/* Function : XGI_GetTap4Ptr */
3973/* Input : */
3974/* Output : di -> Tap4 Reg. Setting Pointer */
3975/* Description : */
3976/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003977static struct XGI301C_Tap4TimingStruct const
3978*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003979{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303980 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003981 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003982
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303983 if (tempcx == 0) {
3984 tempax = pVBInfo->VGAHDE;
3985 tempbx = pVBInfo->HDE;
3986 } else {
3987 tempax = pVBInfo->VGAVDE;
3988 tempbx = pVBInfo->VDE;
3989 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003990
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003991 if (tempax <= tempbx)
3992 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303993 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003994 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003995
Peter Huewe599801f2012-02-09 21:11:45 +01003996 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303997 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003998
Peter Huewe599801f2012-02-09 21:11:45 +01003999 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4000 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4001 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004002 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004003 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304004 Tap4TimingPtr = YPbPr750pTap4Timing;
4005 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004006
Peter Huewe599801f2012-02-09 21:11:45 +01004007 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004008 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004009
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304010 i = 0;
4011 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4012 if (Tap4TimingPtr[i].DE == tempax)
4013 break;
4014 i++;
4015 }
4016 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004017}
4018
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004019static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004020{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304021 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004022 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304024 if (!(pVBInfo->VBType & VB_XGI301C))
4025 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004026
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304027 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4028 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004029 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004030
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004031 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004032 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004033 /* Set Vertical Scaling */
4034 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304035 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004036 xgifb_reg_set(pVBInfo->Part2Port,
4037 i,
4038 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304039 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004040
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004041 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004042 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004043 /* Enable V.Scaling */
4044 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304045 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004046 /* Enable H.Scaling */
4047 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004048}
4049
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004050static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304051 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004052{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304053 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004054 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304055 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004056
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004057 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004058 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004059
Aaro Koskinen8104e322011-03-13 12:26:22 +02004060 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004061 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004062 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4063 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304064 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004065 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4066 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304067 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004068
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304069 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4070 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004071
Peter Huewe599801f2012-02-09 21:11:45 +01004072 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004073 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4074 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4075 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304076 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004077
Peter Huewe599801f2012-02-09 21:11:45 +01004078 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4079 & SetCRT2ToYPbPr525750)) {
4080 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304081 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004082
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004083 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304084 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004085 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304086 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004087 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304088 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004089
Peter Huewe599801f2012-02-09 21:11:45 +01004090 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004091 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004092
Peter Huewe599801f2012-02-09 21:11:45 +01004093 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004094 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004095
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304096 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004097 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304099 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004100 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004101 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304102 }
4103 }
4104 return;
4105} /* {end of XGI_SetGroup3} */
4106
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004107static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304108 unsigned short RefreshRateTableIndex,
4109 struct xgi_hw_device_info *HwDeviceExtension,
4110 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004111{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304112 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304114 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004115
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004116 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004117 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304118 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004119 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304121 tempbx = pVBInfo->RVBHCMAX;
4122 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004123 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304124 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4125 tempcx = pVBInfo->VGAHT - 1;
4126 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004127 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304129 temp = ((tempcx & 0xFF00) >> 8) << 3;
4130 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304132 tempcx = pVBInfo->VGAVT - 1;
4133 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4134 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304136 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004137 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304138 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004139 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004140 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304141 tempcx = pVBInfo->VBInfo;
4142 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304144 if (modeflag & HalfDCLK)
4145 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304147 if (XGI_IsLCDDualLink(pVBInfo))
4148 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004149
Peter Huewe599801f2012-02-09 21:11:45 +01004150 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304151 temp = 0;
4152 if (tempbx <= 1024)
4153 temp = 0xA0;
4154 if (tempbx == 1280)
4155 temp = 0xC0;
4156 } else if (tempcx & SetCRT2ToTV) {
4157 temp = 0xA0;
4158 if (tempbx <= 800)
4159 temp = 0x80;
4160 } else {
4161 temp = 0x80;
4162 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4163 temp = 0;
4164 if (tempbx > 800)
4165 temp = 0x60;
4166 }
4167 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004168
Peter Huewe599801f2012-02-09 21:11:45 +01004169 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304170 temp = 0x00;
4171 if (pVBInfo->VGAHDE == 1280)
4172 temp = 0x40;
4173 if (pVBInfo->VGAHDE == 1024)
4174 temp = 0x20;
4175 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004176 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004177
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304178 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304180 tempcx = pVBInfo->RVBHRS;
4181 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004182 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004183
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304184 tempeax = pVBInfo->VGAVDE;
4185 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304187 if (tempeax <= tempebx) {
4188 tempcx = (tempcx & (~0x4000));
4189 tempeax = pVBInfo->VGAVDE;
4190 } else {
4191 tempeax -= tempebx;
4192 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004193
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304194 templong = (tempeax * 256 * 1024) % tempebx;
4195 tempeax = (tempeax * 256 * 1024) / tempebx;
4196 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004197
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304198 if (templong != 0)
4199 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004200
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304201 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004202 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304204 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004205 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304206 tempbx = (unsigned short) (tempebx >> 16);
4207 temp = tempbx & 0x00FF;
4208 temp = temp << 4;
4209 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004210 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004211
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304212 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004213 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4214 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304215 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004216 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304217 tempax = pVBInfo->VGAHDE;
4218 if (modeflag & HalfDCLK)
4219 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004220
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304221 if (XGI_IsLCDDualLink(pVBInfo))
4222 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304224 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4225 if (tempax > 800)
4226 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004227 } else if (pVBInfo->VGAHDE > 800) {
4228 if (pVBInfo->VGAHDE == 1024)
4229 tempax = (tempax * 25 / 32) - 1;
4230 else
4231 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304232 }
4233 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004234
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304235 temp = (tempax & 0xFF00) >> 8;
4236 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004237 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304238 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004239 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004240
Peter Huewe599801f2012-02-09 21:11:45 +01004241 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304242 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004243 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004244
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304245 }
4246 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004247
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304248 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4249 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004250 | TVSetYPbPr525p | TVSetYPbPr750p
4251 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304252 temp |= 0x0001;
4253 if ((pVBInfo->VBInfo & SetInSlaveMode)
4254 && (!(pVBInfo->TVInfo
4255 & TVSimuMode)))
4256 temp &= (~0x0001);
4257 }
4258 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004259
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004260 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304261 tempbx = pVBInfo->HT;
4262 if (XGI_IsLCDDualLink(pVBInfo))
4263 tempbx = tempbx >> 1;
4264 tempbx = (tempbx >> 1) - 2;
4265 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004266 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304267 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004268 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304269 }
4270 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004271
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004272 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004273}
4274
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004275static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4276{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004277 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004278}
4279
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004280static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304281 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004282{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304283 if (pVBInfo->ModeType == ModeVGA) {
4284 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004285 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304286 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304287 }
4288 }
4289 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004290}
4291
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004292static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304293 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004294{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004295 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004296}
4297
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004298static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304299 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004300{
4301
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004302 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004303}
4304
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004305static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4306 unsigned short ModeNo, unsigned short ModeIdIndex,
4307 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004308{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004309 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004310
Aaro Koskinenb3979922012-11-04 21:14:52 +02004311 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004312 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4313 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004314 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004315 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004316
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304317 if (!(modeflag & Charx8Dot)) {
4318 xres /= 9;
4319 xres *= 8;
4320 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004321
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004322 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4323 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004324
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004325 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4326 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004327
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004328 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304329 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004330
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004331 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304332 return 0;
4333
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004334 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4335 yres != xgifb_info->lvds_data.LVDSVDE) {
4336 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4337 if (colordepth > 2)
4338 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304339 }
4340 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004341}
4342
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004343static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4344 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004345 unsigned short ModeNo,
4346 unsigned short ModeIdIndex,
4347 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004348{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304349 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004350 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304351 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4352 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4353 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004354
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004355 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004356 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304357 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004358 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004359
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004360 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004361
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004362 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004363 /* SR35[7] FP VSync polarity */
4364 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4365 /* SR30[5] FP HSync polarity */
4366 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004367
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004368 if (chip_id == XG27)
4369 XGI_SetXG27FPBits(pVBInfo);
4370 else
4371 XGI_SetXG21FPBits(pVBInfo);
4372
Aaro Koskinenb3979922012-11-04 21:14:52 +02004373 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004374 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4375 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004376 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004377 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004378
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304379 if (!(modeflag & Charx8Dot))
4380 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004381
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004382 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004383
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004384 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004385
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304386 if (LVDSHBS > LVDSHT)
4387 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004388
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004389 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304390 if (LVDSHRS > LVDSHT)
4391 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004392
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004393 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304394 if (LVDSHRE > LVDSHT)
4395 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004396
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004397 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004398
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004399 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004400
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004401 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004402 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304403 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004404
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304405 if (LVDSVBS > LVDSVT)
4406 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004407
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004408 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304409 if (LVDSVRS > LVDSVT)
4410 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004411
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004412 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304413 if (LVDSVRE > LVDSVT)
4414 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004415
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004416 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004417
Peter Huewe9388ad92013-02-15 20:37:10 +01004418 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004419 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004420
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304421 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004422 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004423
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304424 /* HT SR0B[1:0] CR00 */
4425 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004426 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004427 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004428
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304429 /* HBS SR0B[5:4] CR02 */
4430 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004431 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004432 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004433
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304434 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4435 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004436 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4437 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4438 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004439
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304440 /* HRS SR0B[7:6] CR04 */
4441 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004442 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004443 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004444
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304445 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4446 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004447 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004448 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004449
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304450 /* HRE SR0C[2] CR05[4:0] */
4451 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004452 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4453 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304455 /* Panel HRE SR2F[7:2] */
4456 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004457 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004458
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304459 /* VT SR0A[0] CR07[5][0] CR06 */
4460 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004461 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4462 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4463 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004464 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004465
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304466 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4467 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004468 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4469 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4470 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004471 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004472
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304473 /* VBE SR0A[4] CR16 */
4474 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004475 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004476 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004477
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304478 /* VRS SR0A[3] CR7[7][2] CR10 */
4479 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004480 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4481 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4482 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004483 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004484
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004485 if (chip_id == XG27) {
4486 /* Panel VRS SR35[2:0] SR34[7:0] */
4487 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4488 (value & 0x700) >> 8);
4489 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4490 } else {
4491 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4492 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4493 (value & 0x600) >> 9);
4494 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4495 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4496 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004497
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304498 /* VRE SR0A[5] CR11[3:0] */
4499 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004500 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4501 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004502
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304503 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004504 if (chip_id == XG27)
4505 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4506 (value << 2) & 0xFC);
4507 else
4508 /* SR3F[7] has to be 0, h/w bug */
4509 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4510 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004511
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304512 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004513
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004514 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004515 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004516 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004517 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004518 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304519 value += 0x10;
4520 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004521
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304522 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004523 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004524 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004525 /* set data, panning = 0, shift left 1 dot*/
4526 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004527
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004528 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004529 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304530
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004531 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304532 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004533
4534}
4535
4536/* --------------------------------------------------------------------- */
4537/* Function : XGI_IsLCDON */
4538/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004539/* Output : 0 : Skip PSC Control */
4540/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004541/* Description : */
4542/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004543static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004544{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304545 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004546
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304547 tempax = pVBInfo->VBInfo;
4548 if (tempax & SetCRT2ToDualEdge)
4549 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004550 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004552
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304553 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004554}
4555
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004556/* --------------------------------------------------------------------- */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004557/* Function : XGI_EnableChISLCD */
4558/* Input : */
4559/* Output : 0 -> Not LCD mode */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004560/* Description : if bool enable = true -> enable, else disable */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004561/* --------------------------------------------------------------------- */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004562static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo,
4563 bool enable)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004564{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304565 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004566
Peter Huewe06cc47b2013-02-03 22:54:38 +01004567 if (enable)
4568 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
4569 else
4570 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
4571
Aaro Koskinen58839b02011-03-13 12:26:23 +02004572 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004573
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304574 if (tempbx & (EnableChA | DisableChA)) {
4575 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4576 return 0;
4577 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004578
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304579 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04004580 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004581
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304582 if (tempah & 0x01) /* Chk LCDB Mode */
4583 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004584
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304585 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004586}
4587
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004588static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4589 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304590 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004591{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004592 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004593
Peter Huewe6896b942012-02-09 21:11:46 +01004594 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4595 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304596 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004597 if (!(pVBInfo->VBInfo &
4598 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004599 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304600 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
4601 tempah = 0x7F; /* Disable Channel A */
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004602 if (!(pVBInfo->VBInfo &
4603 XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004604 /* Disable Channel B */
4605 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004606
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304607 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004608 /* force to disable Cahnnel */
4609 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004610
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304611 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004612 /* Force to disable Channel B */
4613 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304614 }
4615 }
4616 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004617
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004618 /* disable part4_1f */
4619 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004620
Peter Huewe6896b942012-02-09 21:11:46 +01004621 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004622 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004623 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
4624 (XGI_EnableChISLCD(pVBInfo, false)) ||
4625 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004626 /* LVDS Driver power down */
4627 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304628 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004629
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304630 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004631 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304632 | SetSimuScanMode))) {
4633 if (pVBInfo->SetFlag & GatingCRT)
4634 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004635 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304636 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004637
Peter Huewea3d675c2012-02-09 21:11:47 +01004638 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304639 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004640 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004641 /* Power down */
4642 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304643 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004644
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004645 /* disable TV as primary VGA swap */
4646 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304648 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004649 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004650
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004651 if ((pVBInfo->SetFlag & DisableChB) ||
4652 (pVBInfo->VBInfo &
4653 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004654 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004655 (pVBInfo->VBInfo &
4656 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004657 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004658
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004659 if ((pVBInfo->SetFlag & DisableChB) ||
4660 (pVBInfo->VBInfo &
4661 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004662 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004663 (pVBInfo->VBInfo &
4664 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4665 /* save Part1 index 0 */
4666 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4667 /* BTDAC = 1, avoid VB reset */
4668 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4669 /* disable CRT2 */
4670 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4671 /* restore Part1 index 0 */
4672 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304673 }
4674 } else { /* {301} */
4675 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004676 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4677 /* Disable CRT2 */
4678 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4679 /* Disable TV asPrimary VGA swap */
4680 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304681 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004682
Peter Huewea3d675c2012-02-09 21:11:47 +01004683 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304684 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004685 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304686 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004687}
4688
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004689/* --------------------------------------------------------------------- */
4690/* Function : XGI_GetTVPtrIndex */
4691/* Input : */
4692/* Output : */
4693/* Description : bx 0 : ExtNTSC */
4694/* 1 : StNTSC */
4695/* 2 : ExtPAL */
4696/* 3 : StPAL */
4697/* 4 : ExtHiTV */
4698/* 5 : StHiTV */
4699/* 6 : Ext525i */
4700/* 7 : St525i */
4701/* 8 : Ext525p */
4702/* 9 : St525p */
4703/* A : Ext750p */
4704/* B : St750p */
4705/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004706static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004707{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304708 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004709
Peter Huewe599801f2012-02-09 21:11:45 +01004710 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304711 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004712 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304713 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004714 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304715 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004716 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304717 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004718 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304719 tempbx = 10;
4720 if (pVBInfo->TVInfo & TVSimuMode)
4721 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004722
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304723 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004724}
4725
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004726/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004727/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004728/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004729/* Output : bx 0 : NTSC */
4730/* 1 : PAL */
4731/* 2 : PALM */
4732/* 3 : PALN */
4733/* 4 : NTSC1024x768 */
4734/* 5 : PAL-M 1024x768 */
4735/* 6-7: reserved */
4736/* cl 0 : YFilter1 */
4737/* 1 : YFilter2 */
4738/* ch 0 : 301A */
4739/* 1 : 301B/302B/301LV/302LV */
4740/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004741/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004742static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4743 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004744{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004745 *tempbx = 0;
4746 *tempcl = 0;
4747 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004748
Peter Huewe599801f2012-02-09 21:11:45 +01004749 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004750 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004751
Peter Huewe599801f2012-02-09 21:11:45 +01004752 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004753 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004754
Peter Huewe599801f2012-02-09 21:11:45 +01004755 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004756 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004757
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004758 if (pVBInfo->TVInfo & NTSC1024x768) {
4759 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004760 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004761 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304762 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004763
Peter Huewe6896b942012-02-09 21:11:46 +01004764 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4765 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004766 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4767 & TVSimuMode)) {
4768 *tempbx += 8;
4769 *tempcl += 1;
4770 }
4771 }
4772
Peter Huewe6896b942012-02-09 21:11:46 +01004773 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4774 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004775 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004776}
4777
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004778static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004779{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304780 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004781
Peter Huewe6896b942012-02-09 21:11:46 +01004782 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4783 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004784 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304785 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304786 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004787 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004788
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304789 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4790 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004791 if (pVBInfo->VBInfo &
4792 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004793 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004794
Peter Huewea3d675c2012-02-09 21:11:47 +01004795 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304796 tempbl = tempbh;
4797 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004798
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304799 tempbl &= 0x0F;
4800 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004801 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004802
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304803 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4804 | SetCRT2ToTV)) { /* Channel B */
4805 tempah &= 0xF0;
4806 tempah |= tempbl;
4807 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004808
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004809 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4810 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304811 tempah &= 0x0F;
4812 tempah |= tempbh;
4813 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004814 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304815 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304816 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004817}
4818
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004819static void XGI_SetLCDCap_A(unsigned short tempcx,
4820 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004821{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304822 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004823
Aaro Koskinen58839b02011-03-13 12:26:23 +02004824 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304826 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004827 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004828 /* Enable Dither */
4829 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004830 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304831 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004832 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304833 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004834 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304835 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004836}
4837
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004838/* --------------------------------------------------------------------- */
4839/* Function : XGI_SetLCDCap_B */
4840/* Input : cx -> LCD Capability */
4841/* Output : */
4842/* Description : */
4843/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004844static void XGI_SetLCDCap_B(unsigned short tempcx,
4845 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004846{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304847 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004848 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304849 (unsigned short) (((tempcx & 0x00ff) >> 6)
4850 | 0x0c));
4851 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004852 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304853 (unsigned short) (((tempcx & 0x00ff) >> 6)
4854 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004855}
4856
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004857static void XGI_LongWait(struct vb_device_info *pVBInfo)
4858{
4859 unsigned short i;
4860
4861 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4862
4863 if (!(i & 0xC0)) {
4864 for (i = 0; i < 0xFFFF; i++) {
4865 if (!(inb(pVBInfo->P3da) & 0x08))
4866 break;
4867 }
4868
4869 for (i = 0; i < 0xFFFF; i++) {
4870 if ((inb(pVBInfo->P3da) & 0x08))
4871 break;
4872 }
4873 }
4874}
4875
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004876static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004877{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304878 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004879
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304880 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004881
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004882 /* disable down spectrum D[4] */
4883 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304884 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004885 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304886 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004887
Aaro Koskinen8104e322011-03-13 12:26:22 +02004888 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304889 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004890 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304891 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004892 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304893 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004894 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304895 pVBInfo->LCDCapList[index].Spectrum_34);
4896 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004897 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004898}
4899
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004900static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4901{
4902 unsigned short tempcx;
4903
4904 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4905
Peter Huewef951dd02013-02-05 00:29:47 +01004906 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4907 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004908 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004909 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004910 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004911 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004912 (unsigned char) (tempcx & 0x1F));
4913 }
4914 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004915 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004916 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4917 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4918 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004919
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004920 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4921 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004922 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004923 XGI_SetLCDCap_A(tempcx, pVBInfo);
4924
Peter Huewe6896b942012-02-09 21:11:46 +01004925 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004926 if (tempcx & EnableSpectrum)
4927 SetSpectrum(pVBInfo);
4928 }
4929 } else {
4930 /* LVDS,CH7017 */
4931 XGI_SetLCDCap_A(tempcx, pVBInfo);
4932 }
4933}
4934
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004935/* --------------------------------------------------------------------- */
4936/* Function : XGI_SetAntiFlicker */
4937/* Input : */
4938/* Output : */
4939/* Description : Set TV Customized Param. */
4940/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004941static void XGI_SetAntiFlicker(unsigned short ModeNo,
4942 unsigned short ModeIdIndex,
4943 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004944{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004945 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004946
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304947 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004948
Peter Huewe599801f2012-02-09 21:11:45 +01004949 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304950 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004951
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304952 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4953 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304954 tempah = TVAntiFlickList[tempbx];
4955 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004956
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004957 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004958}
4959
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004960static void XGI_SetEdgeEnhance(unsigned short ModeNo,
4961 unsigned short ModeIdIndex,
4962 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004963{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03004964 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304966 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004967
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304968 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4969 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304970 tempah = TVEdgeList[tempbx];
4971 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004972
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004973 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004974}
4975
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004976static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004977{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304978 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004979
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304980 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004981
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304982 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004983
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304984 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4985 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004986
Aaro Koskinen8104e322011-03-13 12:26:22 +02004987 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304988 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004989 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304990 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004991 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304992 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004993 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304994 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004995}
4996
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004997static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304998 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004999{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305000 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02005001 unsigned char const *filterPtr;
5002 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305004 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005005
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305006 switch (tempbx) {
5007 case 0x00:
5008 case 0x04:
5009 filterPtr = NTSCYFilter1;
5010 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005011
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305012 case 0x01:
5013 filterPtr = PALYFilter1;
5014 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305016 case 0x02:
5017 case 0x05:
5018 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305019 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005020 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305021 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005022
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305023 case 0x08:
5024 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305025 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305026 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305027 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005028 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305029 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005030
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305031 default:
5032 return;
5033 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005034
Aaro Koskinenb3979922012-11-04 21:14:52 +02005035 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305036 if (tempcl == 0)
5037 index = tempal * 4;
5038 else
5039 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305041 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005042 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5043 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5044 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5045 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305046 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005047 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5048 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5049 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5050 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305051 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005052
Peter Huewe6896b942012-02-09 21:11:46 +01005053 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5054 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005055 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5056 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5057 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305058 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005059}
5060
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005061/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005062/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005063/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005064/* Output : */
5065/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005066/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005067static void XGI_OEM310Setting(unsigned short ModeNo,
5068 unsigned short ModeIdIndex,
5069 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005070{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005071 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005072
Peter Huewea3d675c2012-02-09 21:11:47 +01005073 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005074 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005075
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005076 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005077 XGI_SetPhaseIncr(pVBInfo);
5078 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5079 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005080
Peter Huewe6896b942012-02-09 21:11:46 +01005081 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005082 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305083 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005084}
5085
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005086/* --------------------------------------------------------------------- */
5087/* Function : XGI_SetCRT2ModeRegs */
5088/* Input : */
5089/* Output : */
5090/* Description : Origin code for crt2group */
5091/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005092static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305093 struct xgi_hw_device_info *HwDeviceExtension,
5094 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005095{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305096 unsigned short tempbl;
5097 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305099 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305101 tempah = 0;
5102 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005103 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305104 tempah &= ~0x10; /* BTRAMDAC */
5105 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305107 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5108 | SetCRT2ToLCD)) {
5109 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005110 tempcl = pVBInfo->ModeType;
5111 tempcl -= ModeVGA;
5112 if (tempcl >= 0) {
5113 /* BT Color */
5114 tempah = (0x008 >> tempcl);
5115 if (tempah == 0)
5116 tempah = 1;
5117 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305118 }
5119 if (pVBInfo->VBInfo & SetInSlaveMode)
5120 tempah ^= 0x50; /* BTDAC */
5121 }
5122 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005123
Aaro Koskinen8104e322011-03-13 12:26:22 +02005124 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305125 tempah = 0x08;
5126 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005127
Miguel Gómeze123e462012-07-06 12:40:52 +02005128 if (pVBInfo->VBInfo & DisableCRT2Display)
5129 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005130
Miguel Gómeze123e462012-07-06 12:40:52 +02005131 tempah = 0x00;
5132 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005133
Miguel Gómeze123e462012-07-06 12:40:52 +02005134 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5135 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5136 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005137
Miguel Gómeze123e462012-07-06 12:40:52 +02005138 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5139 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5140 tempbl &= 0xf7;
5141 tempah |= 0x01;
5142 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305143 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005144
Miguel Gómeze123e462012-07-06 12:40:52 +02005145 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5146 tempbl &= 0xf7;
5147 tempah |= 0x01;
5148 }
5149
5150 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5151 goto reg_and_or;
5152
5153 tempbl &= 0xf8;
5154 tempah = 0x01;
5155
5156 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5157 tempah |= 0x02;
5158
5159 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5160 tempah = tempah ^ 0x05;
5161 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5162 tempah = tempah ^ 0x01;
5163 }
5164
5165 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5166 tempah |= 0x08;
5167
5168reg_and_or:
5169 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5170
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305171 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005172 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305173 tempah &= (~0x08);
5174 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5175 & SetInSlaveMode))) {
5176 tempah |= 0x010;
5177 }
5178 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305180 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305181 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005182 if (pVBInfo->VBInfo & DriverMode)
5183 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305184 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005185
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005186 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305187 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005188
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305189 if (pVBInfo->LCDInfo & SetLCDDualLink)
5190 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305192 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305193 if (pVBInfo->TVInfo & RPLLDIV2XO)
5194 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305195 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005196
Peter Huewe255aabd2012-02-09 21:11:44 +01005197 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5198 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305199 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005200
Peter Huewe255aabd2012-02-09 21:11:44 +01005201 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305202 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005203
Aaro Koskinen8104e322011-03-13 12:26:22 +02005204 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305205 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005206
Peter Huewe6896b942012-02-09 21:11:46 +01005207 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5208 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305209 tempah = 0;
5210 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005211
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305212 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5213 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005214 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305215 tempah |= 0x04; /* shampoo 0129 */
5216 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005217
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005218 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305219 tempah = 0x00;
5220 tempbl = 0xcf;
5221 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5222 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5223 tempah |= 0x30;
5224 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005225
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005226 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305227 tempah = 0;
5228 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005229
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305230 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5231 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5232 tempah |= 0xc0;
5233 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005234 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305235 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305237 tempah = 0;
5238 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005239 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305240 tempbl = 0xff;
5241 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5242 tempah |= 0x80;
5243 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005244
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005245 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005246
Peter Huewe6896b942012-02-09 21:11:46 +01005247 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305248 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005249 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5250 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305251 }
5252 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005253}
5254
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305256void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5257 struct vb_device_info *pVBInfo)
5258{
5259
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005260 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005261
5262}
5263
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305264void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5265 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005266{
5267
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005268 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005269
5270}
5271
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005272unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5273 unsigned short ModeNo, unsigned short ModeIdIndex,
5274 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005275{
Peter Huewef2c22602013-02-03 22:54:30 +01005276 const u8 LCDARefreshIndex[] = {
5277 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005278
Peter Hueweef9a6b92013-02-03 04:08:43 +01005279 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005280
Aaro Koskinen58839b02011-03-13 12:26:23 +02005281 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005282 index = index >> pVBInfo->SelectCRT2Rate;
5283 index &= 0x0F;
5284
5285 if (pVBInfo->LCDInfo & LCDNonExpanding)
5286 index = 0;
5287
5288 if (index > 0)
5289 index--;
5290
5291 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005292 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005293 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewef2c22602013-02-03 22:54:30 +01005294 temp = LCDARefreshIndex[
5295 pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005296
5297 if (index > temp)
5298 index = temp;
5299 } else {
5300 index = 0;
5301 }
5302 }
5303 }
5304
Aaro Koskinenb3979922012-11-04 21:14:52 +02005305 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005306 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005307 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005308 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5309 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005310 index++;
5311 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005312 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005313 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5314 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005315 index++;
5316 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005317 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5318 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005319 index++;
5320 }
5321 }
5322
5323 i = 0;
5324 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005325 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005326 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005327 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005328 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005329 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005330 if (temp < pVBInfo->ModeType)
5331 break;
5332 i++;
5333 index--;
5334
5335 } while (index != 0xFFFF);
5336 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5337 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005338 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005339 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005340 if (temp & InterlaceMode)
5341 i++;
5342 }
5343 }
5344 i--;
5345 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5346 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5347 RefreshRateTableIndex, &i, pVBInfo);
5348 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005349 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005350}
5351
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005352static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305353 struct xgi_hw_device_info *HwDeviceExtension,
5354 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005355{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005356 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005357
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005358 pVBInfo->SetFlag |= ProgrammingCRT2;
5359 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5360 ModeIdIndex, pVBInfo);
5361 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5362 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5363 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5364 HwDeviceExtension, pVBInfo);
5365 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5366 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005367}
5368
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005369static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005370 struct xgi_hw_device_info *HwDeviceExtension,
5371 struct vb_device_info *pVBInfo)
5372{
Peter Huewea9e29e62013-02-03 04:08:44 +01005373 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005374
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005375 pVBInfo->SetFlag |= ProgrammingCRT2;
5376 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5377 pVBInfo->SelectCRT2Rate = 4;
5378 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5379 ModeIdIndex, pVBInfo);
5380 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5381 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5382 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5383 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5384 RefreshRateTableIndex, pVBInfo);
5385 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5386 RefreshRateTableIndex, pVBInfo);
5387 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5388 RefreshRateTableIndex, pVBInfo);
5389 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5390 HwDeviceExtension, pVBInfo);
5391 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5392 RefreshRateTableIndex, pVBInfo);
5393 XGI_SetTap4Regs(pVBInfo);
5394 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5395 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5396 HwDeviceExtension, pVBInfo);
5397 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5398 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5399 XGI_AutoThreshold(pVBInfo);
5400 return 1;
5401}
5402
5403void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5404{
5405 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5406 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5407 0x05, 0x00 };
5408
5409 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5410
5411 unsigned char CR17, CR63, SR31;
5412 unsigned short temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005413
5414 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005415 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005416
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005417 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005418 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
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) | 0x02));
5421
Peter Huewe9388ad92013-02-15 20:37:10 +01005422 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5423 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5424 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005425
Aaro Koskinen8104e322011-03-13 12:26:22 +02005426 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5427 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005428
Peter Huewe9388ad92013-02-15 20:37:10 +01005429 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005430 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005431
Peter Huewe9388ad92013-02-15 20:37:10 +01005432 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005433 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005434
Peter Huewe9388ad92013-02-15 20:37:10 +01005435 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005436 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005437 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005438 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005439
Aaro Koskinen8104e322011-03-13 12:26:22 +02005440 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005441
5442 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005443 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005444
5445 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005446 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005447 CRTCData[i]);
5448
5449 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005450 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005451 CRTCData[i]);
5452
5453 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005454 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005455 CRTCData[i]);
5456
Aaro Koskinen8104e322011-03-13 12:26:22 +02005457 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005458 & 0xE0));
5459
Aaro Koskinen8104e322011-03-13 12:26:22 +02005460 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5461 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5462 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005463
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005464 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005465
Peter Huewe771f3ee2013-02-15 20:37:13 +01005466 for (i = 0; i < 256 * 3; i++) {
5467 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005468 }
5469
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005470 mdelay(1);
5471
5472 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005473 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005474
5475 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005476 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005477 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005478 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005479
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005480 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005481 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005482
Peter Huewe771f3ee2013-02-15 20:37:13 +01005483 for (i = 0; i < 256 * 3; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005484 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005485 }
5486
Aaro Koskinen8104e322011-03-13 12:26:22 +02005487 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5488 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5489 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005490
Peter Huewe9388ad92013-02-15 20:37:10 +01005491 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005492 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005493 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005494}
5495
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005496static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5497 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005498 struct vb_device_info *pVBInfo)
5499{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005500 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005501
Peter Huewe6896b942012-02-09 21:11:46 +01005502 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5503 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005504 if (!(pVBInfo->SetFlag & DisableChA)) {
Peter Huewe66b43eb2013-02-15 20:37:09 +01005505 if ((pVBInfo->SetFlag & EnableChA) ||
5506 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005507 /* Power on */
5508 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005509 }
5510 }
5511
5512 if (!(pVBInfo->SetFlag & DisableChB)) {
5513 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5514 & (SetCRT2ToLCD | SetCRT2ToTV
5515 | SetCRT2ToRAMDAC))) {
Peter Huewe9388ad92013-02-15 20:37:10 +01005516 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005517 tempah &= 0xDF;
5518 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005519 if (!(pVBInfo->VBInfo &
5520 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005521 tempah |= 0x20;
5522 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005523 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005524 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005525
Peter Huewe9388ad92013-02-15 20:37:10 +01005526 tempah = xgifb_reg_get(pVBInfo->Part1Port,
5527 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005528
5529 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005530 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005531 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005532 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005533 }
5534 }
5535
5536 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
5537 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005538 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005539 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005540 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Peter Huewe06cc47b2013-02-03 22:54:38 +01005541 if (!XGI_EnableChISLCD(pVBInfo, false)) {
5542 if (XGI_EnableChISLCD(pVBInfo, true) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005543 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01005544 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005545 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02005546 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005547 pVBInfo->Part4Port,
5548 0x2A,
5549 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005550 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005551 /* LVDS Driver power on */
5552 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005553 }
5554 }
5555
5556 tempah = 0x00;
5557
5558 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5559 tempah = 0xc0;
5560
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005561 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5562 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5563 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5564 tempah = tempah & 0x40;
5565 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5566 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005567
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005568 if (pVBInfo->SetFlag & DisableChB)
5569 tempah &= 0xBF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005570
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005571 if (pVBInfo->SetFlag & DisableChA)
5572 tempah &= 0x7F;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005573
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005574 if (pVBInfo->SetFlag & EnableChB)
5575 tempah |= 0x40;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005576
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005577 if (pVBInfo->SetFlag & EnableChA)
5578 tempah |= 0x80;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005579 }
5580 }
5581
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005582 /* EnablePart4_1F */
5583 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005584
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005585 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005586 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005587 XGI_DisableGatingCRT(HwDeviceExtension,
5588 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005589 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
5590 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005591 }
5592 }
5593 } /* 301 */
5594 else { /* LVDS */
5595 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005596 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005597 /* enable CRT2 */
5598 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005599
Peter Huewe9388ad92013-02-15 20:37:10 +01005600 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005601 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005602 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005603
Aaro Koskinendc505562011-03-13 12:26:26 +02005604 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005605 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005606 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005607}
5608
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005609static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5610 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005611 unsigned short ModeNo, unsigned short ModeIdIndex,
5612 struct vb_device_info *pVBInfo)
5613{
Aaro Koskinena1579612012-04-07 01:14:05 +03005614 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005615
Aaro Koskinena1579612012-04-07 01:14:05 +03005616 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005617 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005618 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5619 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5620 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005621 XGI_ClearExt1Regs(pVBInfo);
5622
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005623 if (HwDeviceExtension->jChipType == XG27) {
5624 if (pVBInfo->IF_DEF_LVDS == 0)
5625 XGI_SetDefaultVCLK(pVBInfo);
5626 }
5627
5628 temp = ~ProgrammingCRT2;
5629 pVBInfo->SetFlag &= temp;
5630 pVBInfo->SelectCRT2Rate = 0;
5631
Peter Huewe6896b942012-02-09 21:11:46 +01005632 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5633 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005634 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005635 | SetInSlaveMode)) {
5636 pVBInfo->SetFlag |= ProgrammingCRT2;
5637 }
5638 }
5639
5640 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5641 ModeIdIndex, pVBInfo);
5642 if (RefreshRateTableIndex != 0xFFFF) {
5643 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5644 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5645 pVBInfo, HwDeviceExtension);
5646 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5647 RefreshRateTableIndex, pVBInfo);
5648 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5649 HwDeviceExtension, pVBInfo);
5650 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5651 RefreshRateTableIndex, pVBInfo);
5652 }
5653
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005654 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005655 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005656 if (temp & 0xA0) {
5657
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005658 if (HwDeviceExtension->jChipType == XG27)
5659 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5660 RefreshRateTableIndex, pVBInfo);
5661 else
5662 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5663 RefreshRateTableIndex, pVBInfo);
5664
5665 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5666 RefreshRateTableIndex);
5667
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005668 xgifb_set_lcd(HwDeviceExtension->jChipType,
5669 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005670
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005671 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005672 xgifb_set_lvds(xgifb_info,
5673 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005674 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005675 }
5676 }
5677
5678 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5679 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5680 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5681 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005682 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005683}
5684
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005685unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5686 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005687 unsigned short ModeNo)
5688{
5689 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005690 struct vb_device_info VBINF;
5691 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005692 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005693
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005694 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005695 pVBInfo->IF_DEF_YPbPr = 0;
5696 pVBInfo->IF_DEF_HiVision = 0;
5697 pVBInfo->IF_DEF_CRT2Monitor = 0;
5698 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005699 } else {
5700 pVBInfo->IF_DEF_YPbPr = 1;
5701 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005702 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005703 }
5704
Aaro Koskinen56810a92013-01-21 02:57:47 +02005705 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005706
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005707 /* for x86 Linux, XG21 LVDS */
5708 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005709 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005710 pVBInfo->IF_DEF_LVDS = 1;
5711 }
5712 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005713 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5714 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005715 pVBInfo->IF_DEF_LVDS = 1;
5716 }
5717 }
5718
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005719 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005720 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005721 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005722 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005723
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005724 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005725 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
5726
5727 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5728
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005729 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005730 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
5731 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
5732 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005733 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005734
Peter Huewee44adfd2013-02-03 22:54:39 +01005735 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5736 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005737 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005738 ModeIdIndex, pVBInfo);
5739
Peter Huewea3d675c2012-02-09 21:11:47 +01005740 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005741 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5742 HwDeviceExtension, pVBInfo);
5743 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005744 }
5745
Peter Huewe6896b942012-02-09 21:11:46 +01005746 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005747 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005748 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005749 case VB_CHIP_302:
5750 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5751 pVBInfo); /*add for CRT2 */
5752 break;
5753
5754 default:
5755 break;
5756 }
5757 }
5758
5759 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
5760 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005761 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005762 } /* !XG20 */
5763 else {
5764 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005765 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005766 ModeIdIndex,
5767 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005768 return 0;
5769
Aaro Koskinenb3979922012-11-04 21:14:52 +02005770 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005771 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005772
5773 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005774 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005775
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005776 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005777
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005778 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5779 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005780
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005781 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005782 }
5783
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005784 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
5785
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005786 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005787 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005788
5789 return 1;
5790}