blob: 2078d57e97a41732aa941fb62b9ed6b98b24671f [file] [log] [blame]
Aaro Koskinend80aaa02011-02-17 23:29:14 +02001#include <linux/delay.h>
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002#include "XGIfb.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004#include "vb_def.h"
Aaro Koskinen56810a92013-01-21 02:57:47 +02005#include "vb_init.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006#include "vb_util.h"
7#include "vb_table.h"
Miguel Gómeze0541022012-06-18 13:12:05 +02008#include "vb_setmode.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02009
10#define IndexMask 0xff
Peter Huewe95072592012-06-14 00:21:48 +020011#define TVCLKBASE_315_25 (TVCLKBASE_315 + 25)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020012
Aaro Koskinen624554d2011-10-11 21:47:35 +030013static const unsigned short XGINew_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040014 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
15 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
16 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
17 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
18 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
19 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
20 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
21 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
22 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
23 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020024
Bill Pemberton80adad82010-06-17 13:10:51 -040025void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020026{
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030027 pVBInfo->MCLKData = XGI340New_MCLKData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020028
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053029 pVBInfo->LCDResInfo = 0;
30 pVBInfo->LCDTypeInfo = 0;
31 pVBInfo->LCDInfo = 0;
32 pVBInfo->VBInfo = 0;
33 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020034
Aaro Koskinen597d96b2013-03-27 23:53:15 +020035 pVBInfo->SR18 = XGI340_SR18;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053036 pVBInfo->CR40 = XGI340_cr41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020037
Aaro Koskinence76de52013-05-29 23:59:02 +030038 if (ChipType < XG20)
39 XGI_GetVBType(pVBInfo);
40
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053041 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010042 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053043 pVBInfo->LCDCapList = XGI_LCDDLCapList;
44 else
45 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053047 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020048 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053050 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040051 unsigned char temp;
Vitor Braga694683f2014-03-30 00:44:59 -030052
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030053 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053054 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020055 pVBInfo->XGINew_CR97 = 0xc1;
Aaro Koskinen597d96b2013-03-27 23:53:15 +020056 pVBInfo->SR18 = XG27_SR18;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020057
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040058 /*Z11m DDR*/
59 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
60 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
61 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020062 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053063 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020064}
65
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +030066static void XGI_SetSeqRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020067{
Peter Huewe76a58992013-02-03 22:54:34 +010068 unsigned char SRdata, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020069
Aaro Koskinen8104e322011-03-13 12:26:22 +020070 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020071
Peter Huewe76a58992013-02-03 22:54:34 +010072 for (i = 0; i < 4; i++) {
73 /* Get SR1,2,3,4 from file */
74 /* SR1 is with screen off 0x20 */
75 SRdata = XGI330_StandTable.SR[i];
76 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053077 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020078}
79
Aaro Koskinenb053af12013-07-16 23:13:28 +030080static void XGI_SetCRTCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020081{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053082 unsigned char CRTCdata;
83 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020084
Peter Huewe9388ad92013-02-15 20:37:10 +010085 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053086 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +020087 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053089 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080090 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020091 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +020092 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053093 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020094}
95
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +030096static void XGI_SetATTRegs(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080097 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020098{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053099 unsigned char ARdata;
100 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200101
Aaro Koskinenb3979922012-11-04 21:14:52 +0200102 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530104 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200105 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200106
107 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
108 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
109 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300110 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200111 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300112 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530113 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 }
115 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200116
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200117 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200118 outb(i, pVBInfo->P3c0); /* set index */
119 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530120 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200121
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200122 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200123 outb(0x14, pVBInfo->P3c0); /* set index */
124 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200125 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200126 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200127}
128
Aaro Koskinena1579612012-04-07 01:14:05 +0300129static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200130{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530131 unsigned char GRdata;
132 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200133
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530134 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800135 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200136 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200137 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530138 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530140 if (pVBInfo->ModeType > ModeVGA) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100141 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530142 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200143 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530144 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200145}
146
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200147static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200148{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530149 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530151 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200152 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200153}
154
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200155static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200156{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200157 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200158 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
159 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200160
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200161 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200162 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
163 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200164
Aaro Koskinendc505562011-03-13 12:26:26 +0200165 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530166 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200167}
168
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300169static unsigned char XGI_AjustCRT2Rate(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530170 unsigned short RefreshRateTableIndex, unsigned short *i,
171 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200172{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530173 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200174
Aaro Koskinenb3979922012-11-04 21:14:52 +0200175 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
176 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200177 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530178 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200179
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300180 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
181 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200182
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300183 if (pVBInfo->VBType & VB_XGI301C)
184 tempax |= SupportCRT2in301C;
185 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200186
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300187 /* 301b */
188 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300189 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200190
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300191 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
192 pVBInfo->LCDResInfo != Panel_1280x960 &&
193 (pVBInfo->LCDInfo & LCDNonExpanding) &&
194 resinfo >= 9)
195 return 0;
196 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200197
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300198 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
199 tempax |= SupportHiVision;
200 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
201 ((resinfo == 4) ||
202 (resinfo == 3 && (pVBInfo->SetFlag & TVSimuMode)) ||
203 (resinfo > 7)))
204 return 0;
205 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO | SetCRT2ToSVIDEO |
206 SetCRT2ToSCART | SetCRT2ToYPbPr525750 |
207 SetCRT2ToHiVision)) {
208 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200209
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300210 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
211 VB_SIS302LV | VB_XGI301C))
212 tempax |= SupportTV1024;
213
214 if (!(pVBInfo->VBInfo & TVSetPAL) &&
215 (modeflag & NoSupportSimuTV) &&
216 (pVBInfo->VBInfo & SetInSlaveMode) &&
217 (!(pVBInfo->VBInfo & SetNotSimuMode)))
218 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530219 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200220
Aaro Koskinena39325d2012-11-04 21:14:53 +0200221 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800222 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200223 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800224 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530225 if (infoflag & tempax)
226 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530228 if ((*i) == 0)
229 break;
230 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200231
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530232 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200233 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800234 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200235 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530236 != tempbx) {
237 return 0;
238 }
239
240 if (infoflag & tempax)
241 return 1;
242 }
243 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200244}
245
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200246static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530247 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200248{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530249 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200250
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800251 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200252 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530253 sync &= 0xC0;
254 temp = 0x2F;
255 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200256 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200257}
258
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200259static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530260 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200261{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530262 unsigned char data, data1, pushax;
263 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200264
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800265 /* unlock cr0-7 */
Peter Huewe9388ad92013-02-15 20:37:10 +0100266 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530267 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200268 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200269
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200270 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200271 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200272
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530273 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200274 data = pVBInfo->TimingH.data[i];
Bhumika Goyal89322a02016-02-09 19:57:40 +0530275 xgifb_reg_set(pVBInfo->P3d4, (unsigned short)(i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530276 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200277
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530278 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200279 data = pVBInfo->TimingH.data[i];
Bhumika Goyal89322a02016-02-09 19:57:40 +0530280 xgifb_reg_set(pVBInfo->P3c4, (unsigned short)(i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530281 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200282
Peter Huewe9388ad92013-02-15 20:37:10 +0100283 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530284 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200285 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530286 data &= 0xE0;
287 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200288 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530290 if (HwDeviceExtension->jChipType >= XG20) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100291 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530292 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200293 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100294 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530295 data1 = data;
296 data1 &= 0xE0;
297 data &= 0x1F;
298 if (data == 0) {
299 pushax = data;
Peter Huewe9388ad92013-02-15 20:37:10 +0100300 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530301 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200302 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530303 data = pushax;
304 }
305 data = data - 1;
306 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200307 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100308 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Aya Mahfouz46283372015-02-26 11:27:44 +0200309 data >>= 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530310 data = data + 3;
311 if (data > 7)
312 data = data - 7;
Aya Mahfouz46283372015-02-26 11:27:44 +0200313 data <<= 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200314 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530315 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200316}
317
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800318static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800319 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200320{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530321 unsigned char data;
322 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200323
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530324 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200325 data = pVBInfo->TimingV.data[i];
Bhumika Goyal89322a02016-02-09 19:57:40 +0530326 xgifb_reg_set(pVBInfo->P3d4, (unsigned short)(i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530327 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200328
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530329 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200330 data = pVBInfo->TimingV.data[i];
Bhumika Goyal89322a02016-02-09 19:57:40 +0530331 xgifb_reg_set(pVBInfo->P3d4, (unsigned short)(i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530332 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200333
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530334 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200335 data = pVBInfo->TimingV.data[i];
Bhumika Goyal89322a02016-02-09 19:57:40 +0530336 xgifb_reg_set(pVBInfo->P3d4, (unsigned short)(i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530337 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200338
Peter Huewe9388ad92013-02-15 20:37:10 +0100339 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530340 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200341 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530342 data &= 0x3F;
343 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200344 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200345
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200346 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530347 data &= 0x80;
Aya Mahfouz46283372015-02-26 11:27:44 +0200348 data >>= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200349
Aaro Koskinenb3979922012-11-04 21:14:52 +0200350 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530351 i &= DoubleScanMode;
352 if (i)
353 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200354
Peter Huewe9388ad92013-02-15 20:37:10 +0100355 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530356 j &= 0x5F;
357 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200358 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200359}
360
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300361static void XGI_SetCRT1CRTC(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200362 unsigned short RefreshRateTableIndex,
363 struct vb_device_info *pVBInfo,
364 struct xgi_hw_device_info *HwDeviceExtension)
365{
366 unsigned char index, data;
367 unsigned short i;
368
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800369 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200370 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200371 index = index & IndexMask;
372
Peter Huewe9388ad92013-02-15 20:37:10 +0100373 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200374 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200375 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200376
377 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200378 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200379 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200380
381 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200382 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200383 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200384
385 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
386
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300387 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200388
389 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200390 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200391}
392
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200393/* --------------------------------------------------------------------- */
394/* Function : XGI_SetXG21CRTC */
395/* Input : Stand or enhance CRTC table */
396/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
397/* Description : Set LCD timing */
398/* --------------------------------------------------------------------- */
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +0300399static void XGI_SetXG21CRTC(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530400 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200401{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300402 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530403 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200404
Aaro Koskinena39325d2012-11-04 21:14:53 +0200405 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300406 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200407 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300408 Tempcx = Tempax; /* Tempcx: HRS */
409 /* SR2E[7:0]->HRS */
410 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200411
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200412 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300413 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
414 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
415 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
416 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800417
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200418 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300419 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200420
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200421 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300422 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
423 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
424 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200425
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300426 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
427 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200428
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300429 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
430 if (Tempax < Tempcx) /* HRE < HRS */
431 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200432
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300433 Temp2 &= 0xFF;
Bhumika Goyal89322a02016-02-09 19:57:40 +0530434 Tempax = (unsigned char)Temp2; /* Tempax: HRE[7:0] */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300435 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
436 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
437 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
438 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
439 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
440 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200441
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300442 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200443 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300444 Tempbx = Tempax; /* Tempbx: VRS */
445 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
446 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
447 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200448 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300449 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
450 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
451 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
452 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
453 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200454
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300455 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
456 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
457 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
458 Tempax &= 0x80;
459 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
460 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
461 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200462 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300463 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
464 Temp2 = Tempax;
465 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
466 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200467
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300468 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200469 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300470 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
471 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200472 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300473 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
474 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
475 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
476 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
477 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200478
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300479 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
480 if (Tempax < Temp3) /* VRE < VRS */
481 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200482
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300483 Temp2 &= 0xFF;
Bhumika Goyal89322a02016-02-09 19:57:40 +0530484 Tempax = (unsigned char)Temp2; /* Tempax: VRE[7:0] */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300485 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
486 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
487 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
Bhumika Goyal89322a02016-02-09 19:57:40 +0530488 Tempbx = (unsigned char)Temp1;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300489 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
490 Tempax &= 0x7F;
491 /* SR3F D[7:2]->VRE D[1:0]->VRS */
492 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200493}
494
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +0300495static void XGI_SetXG27CRTC(unsigned short RefreshRateTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800496 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200497{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300498 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200499
Aaro Koskinena39325d2012-11-04 21:14:53 +0200500 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300501 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200502 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300503 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
504 /* SR2E[7:0]->HRS */
505 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200506
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300507 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200508 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300509 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
510 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200511
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200512 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300513 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
514 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200515
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200516 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300517 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
518 Tempax <<= 3; /* Tempax[5]: HRE[5] */
519 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200520
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300521 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
522 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200523
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300524 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200525 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300526 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
527 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
528 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200529
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200530 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300531 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
532 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
533 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
534 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
535 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
536 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200537
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300538 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200539 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300540 /* SR34[7:0]->VRS[7:0] */
541 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200542
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300543 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
544 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200545 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300546 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
547 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
548 Tempax >>= 2; /* Tempax[0]: VRS[8] */
549 /* SR35[0]: VRS[8] */
550 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
551 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
552 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
553 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200554 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300555 Tempax &= 0x08; /* SR0A[3] VRS[10] */
556 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200557
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300558 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200559 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300560 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
561 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200562 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300563 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
564 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
565 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
566 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
567 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
568 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200569
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300570 if (Tempbx <= Tempcx) /* VRE <= VRS */
571 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200572
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300573 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
574 Tempax = (Tempbx << 2) & 0xFF;
575 /* SR3F[7:2]:VRE[5:0] */
576 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
577 Tempax = Tempcx >> 8;
578 /* SR35[2:0]:VRS[10:8] */
579 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200580}
581
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200582static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
583{
584 unsigned char temp;
585
586 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
587 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
588 temp = (temp & 3) << 6;
589 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
590 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
591 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
592 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200593}
594
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300595static void xgifb_set_lcd(int chip_id,
596 struct vb_device_info *pVBInfo,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300597 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200598{
Peter Huewee2e544c2013-02-03 04:08:46 +0100599 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200600
Aaro Koskinen8104e322011-03-13 12:26:22 +0200601 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
602 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
603 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
604 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300605
606 if (chip_id == XG27) {
Peter Huewee2e544c2013-02-03 04:08:46 +0100607 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
608 if ((temp & 0x03) == 0) { /* dual 12 */
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300609 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
610 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
611 }
612 }
613
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300614 if (chip_id == XG27) {
615 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530616 } else {
Peter Huewee2e544c2013-02-03 04:08:46 +0100617 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
618 if (temp & 0x01) {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300619 /* 18 bits FP */
620 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
621 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
622 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530623 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200624
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200625 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200626
Aaro Koskinendc505562011-03-13 12:26:26 +0200627 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
628 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200629
Peter Huewee2e544c2013-02-03 04:08:46 +0100630 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
631 if (temp & 0x4000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300632 /* Hsync polarity */
633 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Peter Huewee2e544c2013-02-03 04:08:46 +0100634 if (temp & 0x8000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300635 /* Vsync polarity */
636 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200637}
638
639/* --------------------------------------------------------------------- */
640/* Function : XGI_UpdateXG21CRTC */
641/* Input : */
642/* Output : CRT1 CRTC */
643/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
644/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800645static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
646 struct vb_device_info *pVBInfo,
647 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200648{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300649 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200650
Aaro Koskinendc505562011-03-13 12:26:26 +0200651 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300652 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200653 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300654 RES640x480x60))
655 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200656 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800657 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300658 index = 13;
659 else if (ModeNo == 0x2F)
660 index = 14;
661 else if (ModeNo == 0x50)
662 index = 15;
663 else if (ModeNo == 0x59)
664 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200665
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530666 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200667 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200668 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200669 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200670 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200671 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200672 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200673 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200674 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530675 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200676}
677
Aaro Koskinenb053af12013-07-16 23:13:28 +0300678static void XGI_SetCRT1DE(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530679 unsigned short RefreshRateTableIndex,
680 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200681{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400682 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200683
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530684 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200685
Aaro Koskinenb3979922012-11-04 21:14:52 +0200686 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200687
Aaro Koskinenb3979922012-11-04 21:14:52 +0200688 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinene8e6c752012-11-04 21:15:00 +0200689 tempax = XGI330_ModeResInfo[resindex].HTotal;
690 tempbx = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200691
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530692 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +0200693 tempax >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200694
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300695 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +0200696 tempax <<= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200697
Aaro Koskinena39325d2012-11-04 21:14:53 +0200698 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200699
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300700 if (temp & InterlaceMode)
Aya Mahfouz46283372015-02-26 11:27:44 +0200701 tempbx >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200702
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300703 if (modeflag & DoubleScanMode)
Aya Mahfouz46283372015-02-26 11:27:44 +0200704 tempbx <<= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200705
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530706 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200707
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530708 tempax /= tempcx;
709 tempax -= 1;
710 tempbx -= 1;
711 tempcx = tempax;
Peter Huewe9388ad92013-02-15 20:37:10 +0100712 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
713 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530714 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200715 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Bhumika Goyal89322a02016-02-09 19:57:40 +0530716 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short)(tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200717 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Bhumika Goyal89322a02016-02-09 19:57:40 +0530718 (unsigned short)((tempcx & 0x0ff00) >> 10));
719 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short)(tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530720 tempax = 0;
Aya Mahfouz46283372015-02-26 11:27:44 +0200721 tempbx >>= 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200722
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530723 if (tempbx & 0x01)
724 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200725
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530726 if (tempbx & 0x02)
727 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200728
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200729 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Peter Huewe9388ad92013-02-15 20:37:10 +0100730 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530731 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200732
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530733 if (tempbx & 0x04)
734 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200735
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200736 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200737 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200738}
739
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800740static void XGI_SetCRT1Offset(unsigned short ModeNo,
741 unsigned short ModeIdIndex,
742 unsigned short RefreshRateTableIndex,
743 struct xgi_hw_device_info *HwDeviceExtension,
744 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200745{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530746 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200747
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530748 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200749 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aya Mahfouz46283372015-02-26 11:27:44 +0200750 temp >>= 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200751 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200752
Aaro Koskinena39325d2012-11-04 21:14:53 +0200753 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530754 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200755
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530756 if (temp2)
Aya Mahfouz46283372015-02-26 11:27:44 +0200757 temp <<= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200758
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530759 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200760
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530761 switch (temp2) {
762 case 0:
763 temp2 = 1;
764 break;
765 case 1:
766 temp2 = 2;
767 break;
768 case 2:
769 temp2 = 4;
770 break;
771 case 3:
772 temp2 = 4;
773 break;
774 case 4:
775 temp2 = 6;
776 break;
777 case 5:
778 temp2 = 8;
779 break;
780 default:
781 break;
782 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530784 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
785 temp = temp * temp2 + temp2 / 2;
786 else
787 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200788
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530789 /* SetOffset */
790 DisplayUnit = temp;
791 temp2 = temp;
Aya Mahfouz46283372015-02-26 11:27:44 +0200792 temp >>= 8; /* ah */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530793 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200794 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530795 i &= 0xF0;
796 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200797 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200798
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530799 temp = (unsigned char) temp2;
800 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200801 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200802
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530803 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200804 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530805 temp2 &= InterlaceMode;
806 if (temp2)
807 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200808
Aya Mahfouz46283372015-02-26 11:27:44 +0200809 DisplayUnit <<= 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530810 ah = (DisplayUnit & 0xff00) >> 8;
811 al = DisplayUnit & 0x00ff;
812 if (al == 0)
813 ah += 1;
814 else
815 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530817 if (HwDeviceExtension->jChipType >= XG20)
818 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
819 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200820
Aaro Koskinen8104e322011-03-13 12:26:22 +0200821 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200822}
823
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300824static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200825 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200826 struct vb_device_info *pVBInfo)
827{
Peter Hueweef9a6b92013-02-03 04:08:43 +0100828 unsigned short VCLKIndex, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200829
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300830 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200831 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200832
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200833 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
834 if (pVBInfo->LCDResInfo != Panel_1024x768)
835 /* LCDXlat2VCLK */
836 VCLKIndex = VCLK108_2_315 + 5;
837 else
838 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
839 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
840 if (pVBInfo->SetFlag & RPLLDIV2XO)
841 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
842 else
843 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200844
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200845 if (pVBInfo->SetFlag & TVSimuMode) {
Ebru Akagunduz4759e822013-10-29 22:50:54 +0200846 if (modeflag & Charx8Dot)
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200847 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
Ebru Akagunduz4759e822013-10-29 22:50:54 +0200848 else
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200849 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200850 }
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200851
852 /* 301lv */
853 if (pVBInfo->VBType & VB_SIS301LV) {
854 if (pVBInfo->SetFlag & RPLLDIV2XO)
855 VCLKIndex = YPbPr525iVCLK_2;
856 else
857 VCLKIndex = YPbPr525iVCLK;
858 }
859 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
860 if (pVBInfo->SetFlag & RPLLDIV2XO)
861 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
862 else
863 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
864 } else { /* for CRT2 */
865 /* di+Ext_CRTVCLK */
866 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
867 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200868 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200869
870 return VCLKIndex;
871}
872
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300873static void XGI_SetCRT1VCLK(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800874 struct xgi_hw_device_info *HwDeviceExtension,
875 unsigned short RefreshRateTableIndex,
876 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200877{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400878 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530879 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200880
Aaro Koskinenb750f512013-05-29 23:59:05 +0300881 if ((pVBInfo->IF_DEF_LVDS == 0) &&
882 (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
883 VB_SIS302LV | VB_XGI301C)) &&
884 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300885 vclkindex = XGI_GetVCLK2Ptr(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinenb053af12013-07-16 23:13:28 +0300886 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200887 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200888 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200889 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200890 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200891 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200892 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
893 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530894 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200895 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200896 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200897 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200898 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
899 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200900 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530901 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200902
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530903 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200904 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800905 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200906 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200907 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200908 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530909 index = data;
910 index &= 0xE0;
911 data &= 0x1F;
Aya Mahfouz46283372015-02-26 11:27:44 +0200912 data <<= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530913 data += 1;
914 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200915 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530916 }
917 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200918}
919
Aaro Koskinene85f2032011-11-27 23:03:07 +0200920static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
921{
922 unsigned char temp;
923
924 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
925 temp = (temp & 1) << 6;
926 /* SR06[6] 18bit Dither */
927 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
928 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
929 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
Aaro Koskinene85f2032011-11-27 23:03:07 +0200930}
931
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300932static void XGI_SetCRT1FIFO(struct xgi_hw_device_info *HwDeviceExtension,
933 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200934{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530935 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200936
Aaro Koskinen58839b02011-03-13 12:26:23 +0200937 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530938 data &= 0xfe;
Colin Cronin3786a0f2015-05-13 22:35:03 -0700939 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* disable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200940
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300941 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
942 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
943 data &= 0xC0;
944 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
945 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
946 data |= 0x01;
947 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530949 if (HwDeviceExtension->jChipType == XG21)
950 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200951}
952
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200953static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300954 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200955 struct vb_device_info *pVBInfo)
956{
957 unsigned short data, data2 = 0;
958 short VCLK;
959
960 unsigned char index;
961
Aaro Koskinena39325d2012-11-04 21:14:53 +0200962 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300963 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200964 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200965
Aaro Koskinen58839b02011-03-13 12:26:23 +0200966 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200967 data &= 0xf3;
968 if (VCLK >= 200)
969 data |= 0x0c; /* VCLK > 200 */
970
971 if (HwDeviceExtension->jChipType >= XG20)
972 data &= ~0x04; /* 2 pixel mode */
973
Aaro Koskinen8104e322011-03-13 12:26:22 +0200974 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200975
976 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200977 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200978 data &= 0xE7;
979 if (VCLK < 200)
980 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200981 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200982 }
983
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200984 data2 = 0x00;
985
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200986 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200987 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200988 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200989}
990
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200991static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300992 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530993 unsigned short RefreshRateTableIndex,
994 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200995{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530996 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
997 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200998
Aaro Koskinenb3979922012-11-04 21:14:52 +0200999 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001000 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001001
Aaro Koskinen58839b02011-03-13 12:26:23 +02001002 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001003 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001004
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001005 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301006 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001007 data2 |= 0x02;
1008 data3 = pVBInfo->ModeType - ModeVGA;
Aya Mahfouz46283372015-02-26 11:27:44 +02001009 data3 <<= 2;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001010 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301011 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001012
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301013 if (data)
1014 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001015
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001016 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001017 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001018 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001019
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301020 data = 0x0000;
1021 if (infoflag & InterlaceMode) {
1022 if (xres == 1024)
1023 data = 0x0035;
1024 else if (xres == 1280)
1025 data = 0x0048;
1026 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001027
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001028 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1029 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001030
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301031 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001032 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301034 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301036 if (modeflag & LineCompareOff)
1037 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001038
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001039 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301040 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001041 data = data ^ 0x60;
1042 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001043 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001044
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001045 XGI_SetVCLKState(HwDeviceExtension, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001046
Aaro Koskinen58839b02011-03-13 12:26:23 +02001047 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001048
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301049 if (HwDeviceExtension->jChipType == XG27) {
1050 if (data & 0x40)
1051 data = 0x2c;
1052 else
1053 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001054 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001055 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301056 } else if (HwDeviceExtension->jChipType >= XG20) {
1057 if (data & 0x40)
1058 data = 0x33;
1059 else
1060 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001061 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1062 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301063 } else {
1064 if (data & 0x40)
1065 data = 0x2c;
1066 else
1067 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001068 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301069 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001070}
1071
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001072static void XGI_WriteDAC(unsigned short dl,
1073 unsigned short ah,
1074 unsigned short al,
1075 unsigned short dh,
1076 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001077{
Fabian Frederick64746c02015-05-18 19:34:15 +02001078 unsigned short bh, bl;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001079
1080 bh = ah;
1081 bl = al;
1082
1083 if (dl != 0) {
Fabian Frederick64746c02015-05-18 19:34:15 +02001084 swap(bh, dh);
1085 if (dl == 1)
1086 swap(bl, dh);
1087 else
1088 swap(bl, bh);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001089 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001090 outb((unsigned short) dh, pVBInfo->P3c9);
1091 outb((unsigned short) bh, pVBInfo->P3c9);
1092 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001093}
1094
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03001095static void XGI_LoadDAC(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001096{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001097 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1098 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001099
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001100 outb(0xFF, pVBInfo->P3c6);
1101 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001102
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001103 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301104 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301106 for (k = 0; k < 3; k++) {
1107 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301109 if (data & 0x01)
1110 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301112 if (data & 0x02)
1113 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001114
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001115 outb(data2, pVBInfo->P3c9);
Aya Mahfouz46283372015-02-26 11:27:44 +02001116 data >>= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301117 }
1118 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001119
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001120 for (i = 16; i < 32; i++) {
1121 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001122
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001123 for (k = 0; k < 3; k++)
1124 outb(data, pVBInfo->P3c9);
1125 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001126
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001127 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001128
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001129 for (m = 0; m < 9; m++) {
1130 di = si;
1131 bx = si + 0x04;
1132 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001133
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001134 for (n = 0; n < 3; n++) {
1135 for (o = 0; o < 5; o++) {
1136 dh = table[si];
1137 ah = table[di];
1138 al = table[bx];
1139 si++;
1140 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301141 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001142
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001143 si -= 2;
1144
1145 for (o = 0; o < 3; o++) {
1146 dh = table[bx];
1147 ah = table[di];
1148 al = table[si];
1149 si--;
1150 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1151 }
1152
1153 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301154 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001155
1156 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301157 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001158}
1159
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001160static void XGI_GetLVDSResInfo(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001161 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001162{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301163 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001164
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001165 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001166 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001167
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001168 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001169 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001170
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001171 xres = XGI330_ModeResInfo[resindex].HTotal;
1172 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001173
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001174 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +02001175 xres <<= 1;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001176
1177 if (modeflag & DoubleScanMode)
Aya Mahfouz46283372015-02-26 11:27:44 +02001178 yres <<= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301180 if (xres == 720)
1181 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001182
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301183 pVBInfo->VGAHDE = xres;
1184 pVBInfo->HDE = xres;
1185 pVBInfo->VGAVDE = yres;
1186 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001187}
1188
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001189static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001190 unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001191 struct vb_device_info *pVBInfo)
1192{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001193 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001194
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001195 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001196
Aaro Koskinenb3979922012-11-04 21:14:52 +02001197 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001198
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001199 i = 0;
1200
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001201 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001202 tempdx = pVBInfo->LCDResInfo;
1203 if (tempbx & 0x0080) { /* OEMUtil */
1204 tempbx &= (~0x0080);
1205 tempdx = pVBInfo->LCDTypeInfo;
1206 }
1207
1208 if (pVBInfo->LCDInfo & EnableScalingLCD)
1209 tempdx &= (~PanelResInfo);
1210
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001211 if (table[i].PANELID == tempdx) {
1212 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001213 tempdx = pVBInfo->LCDInfo;
1214
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001215 if (modeflag & HalfDCLK)
1216 tempdx |= SetLCDLowResolution;
1217
1218 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001219 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001220 break;
1221 }
1222 i++;
1223 }
1224
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001225 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001226}
1227
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001228static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001229 unsigned short RefreshRateTableIndex,
1230 struct vb_device_info *pVBInfo)
1231{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001232 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001233
Aaro Koskinenb3979922012-11-04 21:14:52 +02001234 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001235 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001236 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001237 tempdx = pVBInfo->TVInfo;
1238
1239 if (pVBInfo->VBInfo & SetInSlaveMode)
1240 tempdx = tempdx | SetTVLockMode;
1241
1242 if (modeflag & HalfDCLK)
1243 tempdx = tempdx | SetTVLowResolution;
1244
1245 i = 0;
1246
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001247 while (XGI_TVDataTable[i].MASK != 0xffff) {
1248 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1249 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001250 break;
1251 i++;
1252 }
1253
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001254 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001255}
1256
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001257static void XGI_GetLVDSData(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001258 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001259{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001260 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001261
Aaro Koskinen6008f872012-11-04 21:14:49 +02001262 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1263 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001264
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001265 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeIdIndex, pVBInfo);
Aaro Koskinen6008f872012-11-04 21:14:49 +02001266 pVBInfo->VGAHT = LCDPtr->VGAHT;
1267 pVBInfo->VGAVT = LCDPtr->VGAVT;
1268 pVBInfo->HT = LCDPtr->LCDHT;
1269 pVBInfo->VT = LCDPtr->LCDVT;
1270
1271 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1272 return;
1273
1274 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1275 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1276 pVBInfo->HDE = 1024;
1277 pVBInfo->VDE = 768;
1278 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1279 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1280 pVBInfo->HDE = 1280;
1281 pVBInfo->VDE = 1024;
1282 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1283 pVBInfo->HDE = 1400;
1284 pVBInfo->VDE = 1050;
1285 } else {
1286 pVBInfo->HDE = 1600;
1287 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301288 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001289}
1290
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001291static void XGI_ModCRT1Regs(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001292 struct xgi_hw_device_info *HwDeviceExtension,
1293 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001294{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001295 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001296 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1297 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001298
Peter Huewea3d675c2012-02-09 21:11:47 +01001299 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001300 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001301 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001302
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001303 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001304 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301305 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001306
1307 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1308
Peter Huewea3d675c2012-02-09 21:11:47 +01001309 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001310 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001311 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001312 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001313 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001314 }
1315
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001316 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001317}
1318
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001319static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1320{
1321 unsigned char tempal, tempah, tempbl, i;
1322
Aaro Koskinen58839b02011-03-13 12:26:23 +02001323 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001324 tempal = tempah & 0x0F;
1325 tempah = tempah & 0xF0;
1326 i = 0;
1327 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1328
1329 while (tempbl != 0xFF) {
1330 if (tempbl & 0x80) { /* OEMUtil */
1331 tempal = tempah;
1332 tempbl = tempbl & ~(0x80);
1333 }
1334
1335 if (tempal == tempbl)
1336 break;
1337
1338 i++;
1339
1340 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1341 }
1342
1343 return i;
1344}
1345
1346static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1347{
1348 unsigned short tempah, tempal, tempbl, i;
1349
1350 tempal = pVBInfo->LCDResInfo;
1351 tempah = pVBInfo->LCDTypeInfo;
1352
1353 i = 0;
1354 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1355
1356 while (tempbl != 0xFF) {
1357 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1358 tempal = tempah;
1359 tempbl &= ~0x80;
1360 }
1361
1362 if (tempal == tempbl)
1363 break;
1364
1365 i++;
1366 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1367 }
1368
1369 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001370 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001371 pVBInfo->LCDTypeInfo = 0;
1372 i = 0;
1373 }
1374
1375 return i;
1376}
1377
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001378static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1379 unsigned short *VSyncWidth,
1380 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001381{
1382 unsigned short Index;
1383
1384 Index = XGI_GetLCDCapPtr(pVBInfo);
1385 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1386 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001387}
1388
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001389static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001390 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001391{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301392 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1393 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001394 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001395
Aaro Koskinenb3979922012-11-04 21:14:52 +02001396 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001397 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001398
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001399 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1400 push1 = tempbx;
1401 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001402
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001403 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001404 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1405 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001406 tempax = 1024;
1407 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001408 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1409 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001410 tempax = 1280;
1411 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001412 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001413 tempax = 1400;
1414 tempbx = 1050;
1415 } else {
1416 tempax = 1600;
1417 tempbx = 1200;
1418 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001419
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001420 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1421 pVBInfo->HDE = tempax;
1422 pVBInfo->VDE = tempbx;
1423 pVBInfo->VGAHDE = tempax;
1424 pVBInfo->VGAVDE = tempbx;
1425 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001426
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001427 tempax = pVBInfo->HT;
1428
Peter Huewe826215d2013-02-05 00:29:46 +01001429 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001430
1431 tempcx = pVBInfo->HDE;
1432 tempbx = tempbx & 0x0fff;
1433 tempcx += tempbx;
1434
1435 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001436 tempcx -= tempax;
1437
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001438 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001439
Aya Mahfouz46283372015-02-26 11:27:44 +02001440 tempcx >>= 3;
1441 tempbx >>= 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001442
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001443 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1444 (unsigned short) (tempbx & 0xff));
1445 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1446 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001447
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001448 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001449
Peter Huewe826215d2013-02-05 00:29:46 +01001450 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001451
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001452 tempcx = push2;
1453
1454 if (pVBInfo->LCDInfo & EnableScalingLCD)
1455 tempcx = LCDPtr1->LCDHSync;
1456
1457 tempcx += tempbx;
1458
1459 if (tempcx >= tempax)
1460 tempcx -= tempax;
1461
1462 tempax = tempbx & 0x07;
Aya Mahfouz46283372015-02-26 11:27:44 +02001463 tempax >>= 5;
1464 tempcx >>= 3;
1465 tempbx >>= 3;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001466
1467 tempcx &= 0x1f;
1468 tempax |= tempcx;
1469
1470 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1471 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1472 (unsigned short) (tempbx & 0xff));
1473
1474 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001475 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001476 tempcx = pVBInfo->VDE;
1477
1478 tempbx = tempbx & 0x0fff;
1479 tempcx += tempbx;
1480 if (tempcx >= tempax)
1481 tempcx -= tempax;
1482
1483 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1484 (unsigned short) (tempbx & 0xff));
1485 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1486 (unsigned short) (tempcx & 0xff));
1487
1488 tempbx = (tempbx >> 8) & 0x07;
1489 tempcx = (tempcx >> 8) & 0x07;
1490
1491 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1492 (unsigned short) ((tempcx << 3)
1493 | tempbx));
1494
1495 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001496 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001497
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001498 tempcx = push1;
1499
1500 if (pVBInfo->LCDInfo & EnableScalingLCD)
1501 tempcx = LCDPtr1->LCDVSync;
1502
1503 tempcx += tempbx;
1504 if (tempcx >= tempax)
1505 tempcx -= tempax;
1506
1507 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1508 (unsigned short) (tempbx & 0xff));
1509 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1510 (unsigned short) (tempcx & 0x0f));
1511
1512 tempax = ((tempbx >> 8) & 0x07) << 3;
1513
1514 tempbx = pVBInfo->VGAVDE;
1515 if (tempbx != pVBInfo->VDE)
1516 tempax |= 0x40;
1517
Peter Huewea3d675c2012-02-09 21:11:47 +01001518 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001519 tempax |= 0x40;
1520
1521 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1522 tempax);
1523
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001524 tempbx = pVBInfo->VDE;
1525 tempax = pVBInfo->VGAVDE;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001526
1527 temp = tempax; /* 0430 ylshieh */
1528 temp1 = (temp << 18) / tempbx;
1529
1530 tempdx = (unsigned short) ((temp << 18) % tempbx);
1531
1532 if (tempdx != 0)
1533 temp1 += 1;
1534
1535 temp2 = temp1;
1536 push3 = temp2;
1537
1538 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1539 (unsigned short) (temp2 & 0xff));
1540 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1541 (unsigned short) ((temp2 >> 8) & 0xff));
1542
1543 tempbx = (unsigned short) (temp2 >> 16);
1544 tempax = tempbx & 0x03;
1545
1546 tempbx = pVBInfo->VGAVDE;
1547 if (tempbx == pVBInfo->VDE)
1548 tempax |= 0x04;
1549
1550 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1551
1552 if (pVBInfo->VBType & VB_XGI301C) {
1553 temp2 = push3;
1554 xgifb_reg_set(pVBInfo->Part4Port,
1555 0x3c,
1556 (unsigned short) (temp2 & 0xff));
1557 xgifb_reg_set(pVBInfo->Part4Port,
1558 0x3b,
1559 (unsigned short) ((temp2 >> 8) &
1560 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001561 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001562 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1563 ~0xc0,
1564 (unsigned short) ((tempbx &
1565 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001566
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001567 tempcx = pVBInfo->VGAVDE;
1568 if (tempcx == pVBInfo->VDE)
1569 xgifb_reg_and_or(pVBInfo->Part4Port,
1570 0x30, ~0x0c, 0x00);
1571 else
1572 xgifb_reg_and_or(pVBInfo->Part4Port,
1573 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301574 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001575
1576 tempcx = pVBInfo->VGAHDE;
1577 tempbx = pVBInfo->HDE;
1578
1579 temp1 = tempcx << 16;
1580
1581 tempax = (unsigned short) (temp1 / tempbx);
1582
1583 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1584 tempax = 65535;
1585
1586 temp3 = tempax;
1587 temp1 = pVBInfo->VGAHDE << 16;
1588
1589 temp1 /= temp3;
Aya Mahfouz46283372015-02-26 11:27:44 +02001590 temp3 <<= 16;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001591 temp1 -= 1;
1592
1593 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1594
1595 tempax = (unsigned short) (temp3 & 0xff);
1596 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1597
1598 temp1 = pVBInfo->VGAVDE << 18;
1599 temp1 = temp1 / push3;
1600 tempbx = (unsigned short) (temp1 & 0xffff);
1601
Peter Huewe255aabd2012-02-09 21:11:44 +01001602 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001603 tempbx -= 1;
1604
1605 tempax = ((tempbx >> 8) & 0xff) << 3;
1606 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1607 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1608 (unsigned short) (tempax & 0xff));
1609 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1610 (unsigned short) (tempbx & 0xff));
1611
Aya Mahfouz46283372015-02-26 11:27:44 +02001612 temp3 >>= 16;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001613
1614 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +02001615 temp3 >>= 1;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001616
1617 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1618 (unsigned short) ((temp3 >> 8) & 0xff));
1619 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1620 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001621}
1622
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001623/* --------------------------------------------------------------------- */
1624/* Function : XGI_GETLCDVCLKPtr */
1625/* Input : */
1626/* Output : al -> VCLK Index */
1627/* Description : */
1628/* --------------------------------------------------------------------- */
1629static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1630 struct vb_device_info *pVBInfo)
1631{
1632 unsigned short index;
1633
Peter Huewea3d675c2012-02-09 21:11:47 +01001634 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001635 index = XGI_GetLCDCapPtr1(pVBInfo);
1636
1637 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1638 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1639 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1640 } else { /* LCDA */
1641 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1642 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1643 }
1644 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001645}
1646
1647static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001648 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001649{
1650
1651 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001652 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001653
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001654 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001655 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001656
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001657 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1658 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001659 index = XGI_GetLCDCapPtr(pVBInfo);
1660 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1661
Peter Huewea3d675c2012-02-09 21:11:47 +01001662 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001663 return tempal;
1664
1665 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001666 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001667 (VB_SIS301B |
1668 VB_SIS302B |
1669 VB_SIS301LV |
1670 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001671 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001672 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001673 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001674 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001675 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001676 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001677 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001678 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001679 tempal = TVCLKBASE_315 +
1680 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001681
1682 }
1683 return tempal;
1684 }
1685
Peter Huewe599801f2012-02-09 21:11:45 +01001686 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001687 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001688 return tempal;
1689 }
1690
Peter Huewe599801f2012-02-09 21:11:45 +01001691 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001692 tempal = YPbPr525pVCLK;
1693 return tempal;
1694 }
1695
1696 tempal = NTSC1024VCLK;
1697
1698 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001699 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001700 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001701 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001702 }
1703
1704 if (pVBInfo->VBInfo & SetCRT2ToTV)
1705 return tempal;
1706 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001707 } /* {End of VB} */
1708
Peter Huewe516354e2013-02-15 20:37:11 +01001709 inb((pVBInfo->P3ca + 0x02));
Aaro Koskinena39325d2012-11-04 21:14:53 +02001710 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001711 return tempal;
1712}
1713
1714static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1715 unsigned char *di_1, struct vb_device_info *pVBInfo)
1716{
Peter Huewe6896b942012-02-09 21:11:46 +01001717 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1718 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001719 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1720 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001721 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001722 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001723 }
1724 } else {
1725 *di_0 = XGI_VCLKData[tempal].SR2B;
1726 *di_1 = XGI_VCLKData[tempal].SR2C;
1727 }
1728}
1729
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001730static void XGI_SetCRT2ECLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301731 unsigned short RefreshRateTableIndex,
1732 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001733{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301734 unsigned char di_0, di_1, tempal;
1735 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001736
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001737 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301738 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1739 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001740
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301741 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001742 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301743 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001744 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301745 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001746 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1747 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301748 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001749 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1750 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301751 }
1752 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001753}
1754
Aaro Koskinenb053af12013-07-16 23:13:28 +03001755static void XGI_UpdateModeInfo(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001756{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301757 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001758
Peter Huewe6896b942012-02-09 21:11:46 +01001759 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1760 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301761 tempcl = 0;
1762 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001763 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001764
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301765 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001766 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301767 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001768 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301769 if (!(temp & 0x40))
1770 tempcl |= ActiveCRT1;
1771 }
1772 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001773
Aaro Koskinen58839b02011-03-13 12:26:23 +02001774 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301775 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001776
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301777 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001778 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001779 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301780 if (tempax & 0x04)
1781 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001782
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301783 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001784
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301785 if (!(tempcl & ActiveLCD))
1786 if (temp == 0x01)
1787 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001788
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301789 if (temp == 0x04)
1790 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001791
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301792 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001793 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001794
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301795 if (!(temp & 0x08))
1796 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301798 if (!(temp & 0x04))
1799 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301801 if (temp & 0x02)
1802 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001803
Peter Huewe599801f2012-02-09 21:11:45 +01001804 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301805 if (temp & 0x01)
1806 tempch |= ActiveHiTV;
1807 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001808
Peter Huewe599801f2012-02-09 21:11:45 +01001809 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001810 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301811 pVBInfo->Part2Port,
1812 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301814 if (temp & 0x10)
1815 tempch |= ActiveYPbPr;
1816 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301818 if (tempch != 0)
1819 tempcl |= ActiveTV;
1820 }
1821 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001822
Aaro Koskinen58839b02011-03-13 12:26:23 +02001823 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301824 if (tempcl & ActiveLCD) {
1825 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1826 if (temp & ActiveTV)
1827 tempcl |= ActiveTV;
1828 }
1829 }
1830 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001831 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001832 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001833
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301834 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001835 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301836 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001837}
1838
Bill Pemberton80adad82010-06-17 13:10:51 -04001839void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001840{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301841 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001842
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001843 tempbx = VB_SIS302B;
1844 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1845 if (flag == 0x02)
1846 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001847
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001848 tempbx = VB_SIS301;
1849 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1850 if (flag < 0xB0)
1851 goto finish;
1852
1853 tempbx = VB_SIS301B;
1854 if (flag < 0xC0)
1855 goto bigger_than_0xB0;
1856
1857 tempbx = VB_XGI301C;
1858 if (flag < 0xD0)
1859 goto bigger_than_0xB0;
1860
1861 tempbx = VB_SIS301LV;
1862 if (flag < 0xE0)
1863 goto bigger_than_0xB0;
1864
1865 tempbx = VB_SIS302LV;
1866 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1867 if (tempah != 0xFF)
1868 tempbx = VB_XGI301C;
1869
1870bigger_than_0xB0:
1871 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1872 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1873 if (!(flag & 0x02))
1874 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301875 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001876
1877finish:
1878 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001879}
1880
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001881static void XGI_GetVBInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301882 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001883{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301884 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001885
Aaro Koskinenb3979922012-11-04 21:14:52 +02001886 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301887 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001888 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301889 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001890
Miguel Gómezf9317352012-07-06 12:40:48 +02001891 if (!(pVBInfo->VBType & 0xFFFF))
1892 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001893
Miguel Gómezf9317352012-07-06 12:40:48 +02001894 /* Check Display Device */
1895 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1896 tempbx = tempbx | temp;
1897 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1898 push = temp;
Aya Mahfouz46283372015-02-26 11:27:44 +02001899 push <<= 8;
Miguel Gómezf9317352012-07-06 12:40:48 +02001900 tempax = temp << 8;
1901 tempbx = tempbx | tempax;
Janani Ravichandran7aa546e2016-02-11 17:30:16 -05001902 temp = SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1903 | SetInSlaveMode | DisableCRT2Display;
Miguel Gómezf9317352012-07-06 12:40:48 +02001904 temp = 0xFFFF ^ temp;
1905 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001906
Miguel Gómezf9317352012-07-06 12:40:48 +02001907 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001908
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001909 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1910 VB_XGI301C)) {
1911 if (temp & EnableDualEdge) {
1912 tempbx |= SetCRT2ToDualEdge;
1913 if (temp & SetToLCDA)
1914 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02001915 }
1916 }
1917
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001918 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
1919 if (temp & SetYPbPr) {
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001920 /* shampoo add for new scratch */
1921 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
1922 temp &= YPbPrMode;
1923 tempbx |= SetCRT2ToHiVision;
Miguel Gómezf9317352012-07-06 12:40:48 +02001924
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001925 if (temp != YPbPrMode1080i) {
1926 tempbx &= (~SetCRT2ToHiVision);
1927 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301928 }
1929 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001930 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001931
Miguel Gómezf9317352012-07-06 12:40:48 +02001932 tempax = push; /* restore CR31 */
1933
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001934 temp = 0x09FC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001935
Miguel Gómezf9317352012-07-06 12:40:48 +02001936 if (!(tempbx & temp)) {
1937 tempax |= DisableCRT2Display;
1938 tempbx = 0;
1939 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001940
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001941 if (!(pVBInfo->VBType & VB_NoLCD)) {
1942 if (tempbx & XGI_SetCRT2ToLCDA) {
1943 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001944 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001945 SwitchCRT2));
1946 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001947 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
1948 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02001949 }
1950 }
1951
1952 /* shampoo add */
1953 /* for driver abnormal */
1954 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
Aaro Koskinenee768752013-05-29 23:59:16 +03001955 if (tempbx & SetCRT2ToRAMDAC) {
1956 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
1957 SwitchCRT2 | SetSimuScanMode);
1958 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301959 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001960 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001961
Miguel Gómezf9317352012-07-06 12:40:48 +02001962 if (!(pVBInfo->VBType & VB_NoLCD)) {
1963 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001964 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001965 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01001966 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301967 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001968 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001969
Miguel Gómezf9317352012-07-06 12:40:48 +02001970 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001971 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02001972 SetSimuScanMode);
1973 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
1974 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001975
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001976 if (tempbx & SetCRT2ToYPbPr525750)
1977 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001978
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001979 if (tempbx & SetCRT2ToHiVision)
1980 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
1981 SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001982
Miguel Gómezf9317352012-07-06 12:40:48 +02001983 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
1984 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
1985 tempbx = DisableCRT2Display;
1986 }
1987
1988 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001989 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001990 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001991 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02001992 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001993
Miguel Gómezf9317352012-07-06 12:40:48 +02001994 /* LCD+TV can't support in slave mode
1995 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001996 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
1997 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02001998 SetCRT2ToDualEdge);
1999 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302000 }
2001 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002002
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302003 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002004}
2005
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002006static void XGI_GetTVInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302007 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002008{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002009 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002010
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302011 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002012 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2013 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002014
Peter Huewe5fc699f2013-02-03 04:08:45 +01002015 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2016 if (tempbx & TVSetPAL) {
2017 tempbx &= (SetCHTVOverScan |
2018 TVSetPALM |
2019 TVSetPALN |
2020 TVSetPAL);
2021 if (tempbx & TVSetPALM)
2022 /* set to NTSC if PAL-M */
2023 tempbx &= ~TVSetPAL;
2024 } else
2025 tempbx &= (SetCHTVOverScan |
2026 TVSetNTSCJ |
2027 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002028
Aaro Koskinena8b35292013-02-09 00:03:45 +02002029 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2030 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002031
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002032 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2033 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2034 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002035
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002036 if (index1 == YPbPrMode525i)
2037 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002038
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002039 if (index1 == YPbPrMode525p)
2040 tempbx = tempbx | TVSetYPbPr525p;
2041 if (index1 == YPbPrMode750p)
2042 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302043 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002044
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03002045 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2046 tempbx = tempbx | TVSetHiVision | TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002047
Aaro Koskinena8b35292013-02-09 00:03:45 +02002048 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2049 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2050 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002051
Aaro Koskinena8b35292013-02-09 00:03:45 +02002052 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2053 /* NTSC 1024x768, */
2054 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002055
Aaro Koskinena8b35292013-02-09 00:03:45 +02002056 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002057
Aaro Koskinena8b35292013-02-09 00:03:45 +02002058 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2059 if (pVBInfo->VBInfo & SetInSlaveMode)
2060 tempbx &= (~RPLLDIV2XO);
2061 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2062 tempbx &= (~RPLLDIV2XO);
2063 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2064 VB_SIS301LV | VB_SIS302LV |
2065 VB_XGI301C))) {
2066 if (tempbx & TVSimuMode)
2067 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302068 }
2069 }
2070 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002071}
2072
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002073static unsigned char XGI_GetLCDInfo(unsigned short ModeIdIndex,
2074 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002075{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002076 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302078 pVBInfo->LCDResInfo = 0;
2079 pVBInfo->LCDTypeInfo = 0;
2080 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002081
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002082 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002083 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002084 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302085 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002086
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302087 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002088 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002089
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002090 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002091 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302092 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002093 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002094 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302095 tempax &= 0x0F;
2096 else
Aya Mahfouz46283372015-02-26 11:27:44 +02002097 tempax >>= 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302099 if ((resinfo == 6) || (resinfo == 9)) {
2100 if (tempax >= 3)
2101 tempbx |= PanelRef75Hz;
2102 } else if ((resinfo == 7) || (resinfo == 8)) {
2103 if (tempax >= 4)
2104 tempbx |= PanelRef75Hz;
2105 }
2106 }
2107 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302109 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302111 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002112
Peter Huewea3d675c2012-02-09 21:11:47 +01002113 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302114 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302116 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002117
Aaro Koskinen58839b02011-03-13 12:26:23 +02002118 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302120 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302122 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302124 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302126 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002127
Aaro Koskinen718e7152013-02-09 00:03:46 +02002128 if (((pVBInfo->VBType & VB_SIS302LV) ||
2129 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2130 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002131
Aaro Koskinen718e7152013-02-09 00:03:46 +02002132 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2133 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2134 (!(tempbx & EnableScalingLCD)))
2135 /*
2136 * set to center in 1280x1024 LCDB
2137 * for Panel_1400x1050
2138 */
2139 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302141 if (pVBInfo->VBInfo & SetInSlaveMode) {
2142 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002143 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302144 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002145 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302146 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002147
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302148 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302150 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002151}
2152
Bill Pemberton108afbf2010-06-17 13:10:47 -04002153unsigned char XGI_SearchModeID(unsigned short ModeNo,
Aaro Koskinen334ab072013-07-16 23:13:30 +03002154 unsigned short *ModeIdIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002155{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002156 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002157 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002158 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002159 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002160 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302161 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302163 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002164}
2165
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002166static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2167{
2168 unsigned char ujRet = 0;
2169 unsigned char i = 0;
2170
2171 for (i = 0; i < 8; i++) {
Aya Mahfouz46283372015-02-26 11:27:44 +02002172 ujRet <<= 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002173 ujRet |= (ujDate >> i) & 1;
2174 }
2175
2176 return ujRet;
2177}
2178
2179/*----------------------------------------------------------------------------*/
2180/* output */
2181/* bl[5] : LVDS signal */
2182/* bl[1] : LVDS backlight */
2183/* bl[0] : LVDS VDD */
2184/*----------------------------------------------------------------------------*/
2185static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2186{
2187 unsigned char CR4A, temp;
2188
Aaro Koskinen58839b02011-03-13 12:26:23 +02002189 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002190 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002191
Aaro Koskinen58839b02011-03-13 12:26:23 +02002192 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002193
2194 temp = XG21GPIODataTransfer(temp);
2195 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002196 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002197 return temp;
2198}
2199
2200/*----------------------------------------------------------------------------*/
2201/* output */
2202/* bl[5] : LVDS signal */
2203/* bl[1] : LVDS backlight */
2204/* bl[0] : LVDS VDD */
2205/*----------------------------------------------------------------------------*/
2206static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2207{
2208 unsigned char CR4A, CRB4, temp;
2209
Aaro Koskinen58839b02011-03-13 12:26:23 +02002210 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002211 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002212
Aaro Koskinen58839b02011-03-13 12:26:23 +02002213 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002214
2215 temp &= 0x0C;
2216 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002217 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002218 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002219 temp |= ((CRB4 & 0x04) << 3);
2220 return temp;
2221}
2222
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002223/*----------------------------------------------------------------------------*/
2224/* input */
2225/* bl[5] : 1;LVDS signal on */
2226/* bl[1] : 1;LVDS backlight on */
2227/* bl[0] : 1:LVDS VDD on */
2228/* bh: 100000b : clear bit 5, to set bit5 */
2229/* 000010b : clear bit 1, to set bit1 */
2230/* 000001b : clear bit 0, to set bit0 */
2231/*----------------------------------------------------------------------------*/
2232static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2233 struct vb_device_info *pVBInfo)
2234{
2235 unsigned char CR4A, temp;
2236
2237 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2238 tempbh &= 0x23;
2239 tempbl &= 0x23;
2240 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2241
2242 if (tempbh & 0x20) {
2243 temp = (tempbl >> 4) & 0x02;
2244
2245 /* CR B4[1] */
2246 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2247
2248 }
2249
2250 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2251
2252 temp = XG21GPIODataTransfer(temp);
2253 temp &= ~tempbh;
2254 temp |= tempbl;
2255 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2256}
2257
Aaro Koskinen776115a2011-11-27 23:03:10 +02002258static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2259 struct vb_device_info *pVBInfo)
2260{
2261 unsigned char CR4A, temp;
2262 unsigned short tempbh0, tempbl0;
2263
2264 tempbh0 = tempbh;
2265 tempbl0 = tempbl;
2266 tempbh0 &= 0x20;
2267 tempbl0 &= 0x20;
2268 tempbh0 >>= 3;
2269 tempbl0 >>= 3;
2270
2271 if (tempbh & 0x20) {
2272 temp = (tempbl >> 4) & 0x02;
2273
2274 /* CR B4[1] */
2275 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2276
2277 }
2278 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2279
2280 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2281 tempbh &= 0x03;
2282 tempbl &= 0x03;
2283 tempbh <<= 2;
2284 tempbl <<= 2; /* GPIOC,GPIOD */
2285 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2286 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2287}
2288
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002289static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2290 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302291 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002292{
2293
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002294 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302295 if (pXGIHWDE->jChipType == XG21) {
2296 if (pVBInfo->IF_DEF_LVDS == 1) {
2297 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002298 /* LVDS VDD on */
2299 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002300 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302301 }
2302 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002303 /* LVDS signal on */
2304 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002305 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002306 /* LVDS backlight on */
2307 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302308 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002309 /* DVO/DVI signal on */
2310 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302311 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002312
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302313 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002314
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302315 if (pXGIHWDE->jChipType == XG27) {
2316 if (pVBInfo->IF_DEF_LVDS == 1) {
2317 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002318 /* LVDS VDD on */
2319 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002320 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302321 }
2322 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002323 /* LVDS signal on */
2324 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002325 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002326 /* LVDS backlight on */
2327 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302328 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002329 /* DVO/DVI signal on */
2330 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302331 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002332
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302333 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002334}
2335
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002336void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2337 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302338 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002339{
2340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302341 if (pXGIHWDE->jChipType == XG21) {
2342 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002343 /* LVDS backlight off */
2344 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002345 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302346 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002347 /* DVO/DVI signal off */
2348 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302349 }
2350 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002351
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302352 if (pXGIHWDE->jChipType == XG27) {
2353 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002354 /* LVDS backlight off */
2355 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002356 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302357 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002358
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302359 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002360 /* DVO/DVI signal off */
2361 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302362 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002363
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002364 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002365}
2366
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002367static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002368{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002369 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302370 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002371
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002372 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302373 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002374}
2375
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002376static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002377{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002378 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002379}
2380
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002381static void XGI_SaveCRT2Info(unsigned short ModeNo,
2382 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002383{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302384 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002385
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002386 /* reserve CR34 for CRT1 Mode No */
2387 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302388 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2389 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002390 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002391}
2392
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002393static void XGI_GetCRT2ResInfo(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002394 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002395{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302396 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002397
Aaro Koskinenb3979922012-11-04 21:14:52 +02002398 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002399 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2400 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002401 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002402 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002403
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002404 if (modeflag & HalfDCLK)
2405 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002406
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002407 if (modeflag & DoubleScanMode)
2408 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002409
Miguel Gómez3339db82012-07-06 12:40:49 +02002410 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2411 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002412
Aaro Koskinen22006832013-02-09 00:03:47 +02002413 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2414 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2415 if (yres == 1024)
2416 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302417 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002418 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002419
Aaro Koskinen22006832013-02-09 00:03:47 +02002420 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2421 if (yres == 400)
2422 yres = 405;
2423 else if (yres == 350)
2424 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002425
Aaro Koskinen22006832013-02-09 00:03:47 +02002426 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2427 if (yres == 360)
2428 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002429 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002430 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002431
Aaro Koskinen22006832013-02-09 00:03:47 +02002432 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2433 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2434 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2435 if (yres == 350)
2436 yres = 357;
2437 else if (yres == 400)
2438 yres = 420;
2439 else if (yres == 480)
2440 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002441 }
2442 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302443 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002444
Miguel Gómez3339db82012-07-06 12:40:49 +02002445 if (xres == 720)
2446 xres = 640;
2447
2448exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302449 pVBInfo->VGAHDE = xres;
2450 pVBInfo->HDE = xres;
2451 pVBInfo->VGAVDE = yres;
2452 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002453}
2454
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002455static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002456{
2457
Peter Huewea3d675c2012-02-09 21:11:47 +01002458 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002459 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302460 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002461
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302462 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002463}
2464
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002465static void XGI_GetRAMDAC2DATA(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002466 unsigned short RefreshRateTableIndex,
2467 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002468{
2469 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002470 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002471
2472 pVBInfo->RVBHCMAX = 1;
2473 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002474 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002475 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002476 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002477 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2478 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002479 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002480 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002481 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002482 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002483 tempcx &= 0x0100;
Aya Mahfouz46283372015-02-26 11:27:44 +02002484 tempcx <<= 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002485 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002486 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002487
2488 if (temp1 & 0x01)
2489 tempbx |= 0x0100;
2490
2491 if (temp1 & 0x20)
2492 tempbx |= 0x0200;
2493 tempax += 5;
2494
2495 if (modeflag & Charx8Dot)
2496 tempax *= 8;
2497 else
2498 tempax *= 9;
2499
2500 pVBInfo->VGAHT = tempax;
2501 pVBInfo->HT = tempax;
2502 tempbx++;
2503 pVBInfo->VGAVT = tempbx;
2504 pVBInfo->VT = tempbx;
2505}
2506
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002507static void XGI_GetCRT2Data(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302508 unsigned short RefreshRateTableIndex,
2509 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002510{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002511 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002512
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002513 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002514
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002515 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002516 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2517 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302518 pVBInfo->NewFlickerMode = 0;
2519 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002520
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302521 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002522 XGI_GetRAMDAC2DATA(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302523 return;
2524 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002525
Peter Huewea3d675c2012-02-09 21:11:47 +01002526 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002527 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03002528 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002529
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302530 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2531 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2532 pVBInfo->VGAHT = LCDPtr->VGAHT;
2533 pVBInfo->VGAVT = LCDPtr->VGAVT;
2534 pVBInfo->HT = LCDPtr->LCDHT;
2535 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002536
Peter Huewe255aabd2012-02-09 21:11:44 +01002537 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302538 tempax = 1024;
2539 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002540
Peter Huewea3d675c2012-02-09 21:11:47 +01002541 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302542 if (pVBInfo->VGAVDE == 357)
2543 tempbx = 527;
2544 else if (pVBInfo->VGAVDE == 420)
2545 tempbx = 620;
2546 else if (pVBInfo->VGAVDE == 525)
2547 tempbx = 775;
2548 else if (pVBInfo->VGAVDE == 600)
2549 tempbx = 775;
Peter Huewe7580d7f2013-05-18 00:19:54 +02002550 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002551 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302552 tempax = 1024;
2553 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002554 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302555 tempax = 1280;
2556 if (pVBInfo->VGAVDE == 360)
2557 tempbx = 768;
2558 else if (pVBInfo->VGAVDE == 375)
2559 tempbx = 800;
2560 else if (pVBInfo->VGAVDE == 405)
2561 tempbx = 864;
2562 else
2563 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002564 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302565 tempax = 1280;
2566 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002567 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302568 tempax = 1280;
2569 if (pVBInfo->VGAVDE == 350)
2570 tempbx = 700;
2571 else if (pVBInfo->VGAVDE == 400)
2572 tempbx = 800;
2573 else if (pVBInfo->VGAVDE == 1024)
2574 tempbx = 960;
2575 else
2576 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002577 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302578 tempax = 1400;
2579 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002580
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302581 if (pVBInfo->VGAVDE == 1024) {
2582 tempax = 1280;
2583 tempbx = 1024;
2584 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002585 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302586 tempax = 1600;
2587 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002588 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302589 if (pVBInfo->VGAVDE == 350)
2590 tempbx = 875;
2591 else if (pVBInfo->VGAVDE == 400)
2592 tempbx = 1000;
2593 }
2594 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002595
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302596 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2597 tempax = pVBInfo->VGAHDE;
2598 tempbx = pVBInfo->VGAVDE;
2599 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002600
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302601 pVBInfo->HDE = tempax;
2602 pVBInfo->VDE = tempbx;
2603 return;
2604 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002605
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302606 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002607 struct SiS_TVData const *TVPtr;
2608
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002609 TVPtr = XGI_GetTVPtr(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinen24572542012-09-11 00:15:21 +03002610 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002611
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302612 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2613 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2614 pVBInfo->VGAHT = TVPtr->VGAHT;
2615 pVBInfo->VGAVT = TVPtr->VGAVT;
2616 pVBInfo->HDE = TVPtr->TVHDE;
2617 pVBInfo->VDE = TVPtr->TVVDE;
2618 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2619 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002620
Peter Huewe599801f2012-02-09 21:11:45 +01002621 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302622 if (resinfo == 0x08)
2623 pVBInfo->NewFlickerMode = 0x40;
2624 else if (resinfo == 0x09)
2625 pVBInfo->NewFlickerMode = 0x40;
2626 else if (resinfo == 0x12)
2627 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002628
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302629 if (pVBInfo->VGAVDE == 350)
2630 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002631
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302632 tempax = ExtHiTVHT;
2633 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002634
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302635 if (pVBInfo->VBInfo & SetInSlaveMode) {
2636 if (pVBInfo->TVInfo & TVSimuMode) {
2637 tempax = StHiTVHT;
2638 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002639
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302640 if (!(modeflag & Charx8Dot)) {
2641 tempax = StHiTextTVHT;
2642 tempbx = StHiTextTVVT;
2643 }
2644 }
2645 }
Peter Huewe599801f2012-02-09 21:11:45 +01002646 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2647 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302648 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2649 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2650 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002651
Peter Huewe599801f2012-02-09 21:11:45 +01002652 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302653 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2654 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002655 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302656 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2657 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2658 if (pVBInfo->TVInfo & NTSC1024x768)
2659 tempax = NTSC1024x768HT;
2660 }
2661 } else {
2662 tempax = PALHT;
2663 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002664 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302665 tempax = NTSCHT;
2666 tempbx = NTSCVT;
2667 if (pVBInfo->TVInfo & NTSC1024x768)
2668 tempax = NTSC1024x768HT;
2669 }
2670 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002671
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302672 pVBInfo->HT = tempax;
2673 pVBInfo->VT = tempbx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302674 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002675}
2676
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002677static void XGI_SetCRT2VCLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302678 unsigned short RefreshRateTableIndex,
2679 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002680{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002681 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002682
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002683 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302684 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2685 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002686
Peter Huewe6896b942012-02-09 21:11:46 +01002687 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302688 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002689 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2690 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2691 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302692 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002693 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2694 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302695 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002696
Aaro Koskinen8104e322011-03-13 12:26:22 +02002697 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002698
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302699 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002700 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302701 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002702 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002703}
2704
Aaro Koskinen334ab072013-07-16 23:13:30 +03002705static unsigned short XGI_GetColorDepth(unsigned short ModeIdIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002706{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002707 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2708 short index;
2709 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302710
Aaro Koskinenb3979922012-11-04 21:14:52 +02002711 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002712 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302713
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002714 if (index < 0)
2715 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302716
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002717 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302718}
2719
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002720static unsigned short XGI_GetOffset(unsigned short ModeNo,
2721 unsigned short ModeIdIndex,
Aaro Koskinen334ab072013-07-16 23:13:30 +03002722 unsigned short RefreshRateTableIndex)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302723{
2724 unsigned short temp, colordepth, modeinfo, index, infoflag,
2725 ColorDepth[] = { 0x01, 0x02, 0x04 };
2726
Aaro Koskinenb3979922012-11-04 21:14:52 +02002727 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002728 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302729
2730 index = (modeinfo >> 8) & 0xFF;
2731
Aaro Koskinen224114c2012-11-04 21:14:59 +02002732 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302733
2734 if (infoflag & InterlaceMode)
Aya Mahfouz46283372015-02-26 11:27:44 +02002735 temp <<= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302736
Aaro Koskinen334ab072013-07-16 23:13:30 +03002737 colordepth = XGI_GetColorDepth(ModeIdIndex);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302738
2739 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2740 temp = ModeNo - 0x7C;
2741 colordepth = ColorDepth[temp];
2742 temp = 0x6B;
2743 if (infoflag & InterlaceMode)
Aya Mahfouz46283372015-02-26 11:27:44 +02002744 temp <<= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302745 }
Peter Huewe053004b2013-02-15 20:37:12 +01002746 return temp * colordepth;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302747}
2748
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002749static void XGI_SetCRT2Offset(unsigned short ModeNo,
2750 unsigned short ModeIdIndex,
2751 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002752 struct vb_device_info *pVBInfo)
2753{
2754 unsigned short offset;
2755 unsigned char temp;
2756
2757 if (pVBInfo->VBInfo & SetInSlaveMode)
2758 return;
2759
Aaro Koskinen334ab072013-07-16 23:13:30 +03002760 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002761 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002762 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002763 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002764 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002765 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002766 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002767}
2768
Randy Dunlap89229672010-08-10 08:46:44 -07002769static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002770{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002771 /* threshold high ,disable auto threshold */
2772 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2773 /* threshold low default 04h */
2774 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002775}
2776
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002777static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302778 unsigned short RefreshRateTableIndex,
2779 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002780{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002781 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002782
Aaro Koskinenb053af12013-07-16 23:13:28 +03002783 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302784 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302786 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002787 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002788
Aaro Koskinen8104e322011-03-13 12:26:22 +02002789 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2790 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002791}
2792
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002793static void XGI_SetGroup1(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302794 unsigned short RefreshRateTableIndex,
2795 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002796{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302797 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002798 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002799
Aaro Koskinena39325d2012-11-04 21:14:53 +02002800 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002801 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002802 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002803
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302804 /* bainy change table name */
2805 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002806 /* BTVGA2HT 0x08,0x09 */
2807 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002808 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302809 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002810 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002811 /* BTVGA2HDEE 0x0A,0x0C */
2812 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002813 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302814 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2815 pushbx = pVBInfo->VGAHDE / 2 + 16;
Aya Mahfouz46283372015-02-26 11:27:44 +02002816 tempcx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302817 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2818 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302820 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002821 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2822 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002823 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302824 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002825 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302826 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002827 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302828 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2829 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2830 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002831
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302832 tempbx += 4;
2833 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002834
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302835 if (tempcx > (pVBInfo->VGAHT / 2))
2836 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002837
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302838 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002839
Aaro Koskinen8104e322011-03-13 12:26:22 +02002840 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302841 } else {
2842 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002843 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302844 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002845 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002846 /* BTVGA2HDEE 0x0A,0x0C */
2847 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002848 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302849 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2850 pushbx = pVBInfo->VGAHDE + 16;
Aya Mahfouz46283372015-02-26 11:27:44 +02002851 tempcx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302852 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2853 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002854
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302855 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002856 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2857 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002858 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302859 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002860 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302861 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002862 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302863 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2864 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2865 tempbx += 16;
2866 tempcx += 16;
2867 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002868
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302869 if (tempcx > pVBInfo->VGAHT)
2870 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302872 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002873 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302874 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002875
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302876 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2877 tempbx = pushbx;
2878 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2879 tempax |= (tempbx & 0xFF00);
2880 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002881 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302882 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002883 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Janani Ravichandran7aa546e2016-02-11 17:30:16 -05002884 tempcx = pVBInfo->VGAVT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302885 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002886
Aaro Koskinen8104e322011-03-13 12:26:22 +02002887 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302888 tempbx = pVBInfo->VGAVDE - 1;
2889 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002890 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302891 temp = ((tempbx & 0xFF00) << 3) >> 8;
2892 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002893 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002894
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002895 /* BTVGA2VRS 0x10,0x11 */
2896 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
2897 /* BTVGA2VRE 0x11 */
2898 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002899
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302900 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002901 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
2902 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002903
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302904 if (temp & 0x04)
2905 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002906
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302907 if (temp & 0x080)
2908 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002909
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002910 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002911
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302912 if (temp & 0x08)
2913 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002914
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002915 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302916 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
2917 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002918
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302919 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002920 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302921 temp = ((tempbx & 0xFF00) >> 8) << 4;
Janani Ravichandran7aa546e2016-02-11 17:30:16 -05002922 temp = (tempcx & 0x000F) | (temp);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002923 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302924 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002925
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302926 if (modeflag & DoubleScanMode)
2927 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302929 if (modeflag & HalfDCLK)
2930 tempax |= 0x40;
2931
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002932 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002933}
2934
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002935static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
2936{
2937 unsigned long tempax, tempbx;
2938
2939 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
2940 & 0xFFFF;
2941 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
2942 tempax = (tempax * pVBInfo->HT) / tempbx;
2943
2944 return (unsigned short) tempax;
2945}
2946
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002947static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302948 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002949{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302950 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002951 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002952
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002953 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002954 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2955 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002956
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302957 if (!(pVBInfo->VBInfo & SetInSlaveMode))
2958 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002959
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302960 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002961 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302962 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002963
Peter Huewe6896b942012-02-09 21:11:46 +01002964 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302965 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002966
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302967 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002968
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302969 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +02002970 tempax >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002971
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302972 tempax = (tempax / tempcx) - 1;
2973 tempbx |= ((tempax & 0x00FF) << 8);
2974 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002975 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002976
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302977 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002978
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302979 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01002980 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
2981 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302982 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002983
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002984 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
2985 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302986 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302987 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002988
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002989 /* 0x05 Horizontal Display Start */
2990 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
2991 /* 0x06 Horizontal Blank end */
2992 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002993
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302994 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
2995 if (pVBInfo->VBInfo & SetCRT2ToTV)
2996 tempax = pVBInfo->VGAHT;
2997 else
2998 tempax = XGI_GetVGAHT2(pVBInfo);
2999 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003000
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303001 if (tempax >= pVBInfo->VGAHT)
3002 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303004 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +02003005 tempax >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003006
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303007 tempax = (tempax / tempcx) - 5;
3008 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003009 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303010 temp = (tempbx & 0x00FF) - 1;
3011 if (!(modeflag & HalfDCLK)) {
3012 temp -= 6;
3013 if (pVBInfo->TVInfo & TVSimuMode) {
3014 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003015 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303016 }
3017 }
3018 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303019 tempbx = (tempbx & 0xFF00) >> 8;
3020 tempcx = (tempcx + tempbx) >> 1;
3021 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003022
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303023 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3024 temp -= 1;
3025 if (!(modeflag & HalfDCLK)) {
3026 if ((modeflag & Charx8Dot)) {
3027 temp += 4;
3028 if (pVBInfo->VGAHDE >= 800)
3029 temp -= 6;
3030 }
3031 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003032 } else if (!(modeflag & HalfDCLK)) {
3033 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003034 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003035 pVBInfo->VGAHDE >= 800) {
3036 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003037 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003038 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003039 (pVBInfo->LCDInfo & LCDNonExpanding))
3040 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303041 }
3042 }
3043 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003044
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003045 /* 0x07 Horizontal Retrace Start */
3046 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3047 /* 0x08 Horizontal Retrace End */
3048 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303050 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3051 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003052 if (ModeNo == 0x50) {
Peter Huewe85b38472013-05-13 23:41:49 +02003053 if (pVBInfo->TVInfo == SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003054 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303055 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003056 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303057 0x08, 0x03);
3058 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003059 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303060 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003061 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303062 0x08, 0x02);
3063 }
3064 }
3065 }
3066 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003067
Aaro Koskinen8104e322011-03-13 12:26:22 +02003068 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003069 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003070 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003071
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303072 tempbx = pVBInfo->VGAVT;
3073 push1 = tempbx;
3074 tempcx = 0x121;
3075 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003076
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303077 if (tempbx == 357)
3078 tempbx = 350;
3079 if (tempbx == 360)
3080 tempbx = 350;
3081 if (tempbx == 375)
3082 tempbx = 350;
3083 if (tempbx == 405)
3084 tempbx = 400;
3085 if (tempbx == 525)
3086 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003087
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303088 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303090 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003091 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003092 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303093 if (tempbx == 350)
3094 tempbx += 5;
3095 if (tempbx == 480)
3096 tempbx += 5;
3097 }
3098 }
3099 }
3100 tempbx--;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303101 tempbx--;
3102 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003103 /* 0x10 vertical Blank Start */
3104 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303105 tempbx = push2;
3106 tempbx--;
3107 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003108 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003109
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303110 if (tempbx & 0x0100)
3111 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303113 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303115 if (modeflag & DoubleScanMode)
3116 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303118 if (tempbx & 0x0200)
3119 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303121 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003122 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303124 if (tempbx & 0x0400)
3125 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003126
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003127 /* 0x11 Vertival Blank End */
3128 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303129
3130 tempax = push1;
3131 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
Aya Mahfouz46283372015-02-26 11:27:44 +02003132 tempax >>= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303133 push1 = tempax; /* push ax */
3134
3135 if (resinfo != 0x09) {
Aya Mahfouz46283372015-02-26 11:27:44 +02003136 tempax <<= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303137 tempbx += tempax;
3138 }
3139
Peter Huewe599801f2012-02-09 21:11:45 +01003140 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003141 if ((pVBInfo->VBType & VB_SIS301LV) &&
3142 !(pVBInfo->TVInfo & TVSetHiVision)) {
3143 if ((pVBInfo->TVInfo & TVSimuMode) &&
3144 (pVBInfo->TVInfo & TVSetPAL)) {
3145 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3146 !(pVBInfo->TVInfo &
3147 (TVSetYPbPr525p |
3148 TVSetYPbPr750p |
3149 TVSetHiVision)))
3150 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303151 }
3152 } else {
3153 tempbx -= 10;
3154 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003155 } else if (pVBInfo->TVInfo & TVSimuMode) {
3156 if (pVBInfo->TVInfo & TVSetPAL) {
3157 if (pVBInfo->VBType & VB_SIS301LV) {
3158 if (!(pVBInfo->TVInfo &
3159 (TVSetYPbPr525p |
3160 TVSetYPbPr750p |
3161 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303162 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003163 } else {
3164 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303165 }
3166 }
3167 }
3168 tempax = push1;
Aya Mahfouz46283372015-02-26 11:27:44 +02003169 tempax >>= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303170 tempax++;
3171 tempax += tempbx;
3172 push1 = tempax; /* push ax */
3173
Peter Huewe599801f2012-02-09 21:11:45 +01003174 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303175 if (tempbx <= 513) {
3176 if (tempax >= 513)
3177 tempbx = 513;
3178 }
3179 }
3180
3181 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003182 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303183 tempbx--;
3184 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003185 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303186
3187 if (tempbx & 0x0100)
3188 tempcx |= 0x0008;
3189
3190 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003191 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303192
3193 tempbx++;
3194
3195 if (tempbx & 0x0100)
3196 tempcx |= 0x0004;
3197
3198 if (tempbx & 0x0200)
3199 tempcx |= 0x0080;
3200
3201 if (tempbx & 0x0400)
3202 tempcx |= 0x0C00;
3203
3204 tempbx = push1; /* pop ax */
3205 temp = tempbx & 0x00FF;
3206 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003207 /* 0x0D vertical Retrace End */
3208 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303209
3210 if (tempbx & 0x0010)
3211 tempcx |= 0x2000;
3212
3213 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003214 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303215 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003216 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303217 tempax = modeflag;
3218 temp = (tempax & 0xFF00) >> 8;
3219
3220 temp = (temp >> 1) & 0x09;
3221
Peter Huewe6896b942012-02-09 21:11:46 +01003222 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303223 temp |= 0x01;
3224
Aaro Koskinen8104e322011-03-13 12:26:22 +02003225 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3226 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3227 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303228
3229 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3230 temp = 0x80;
3231 else
3232 temp = 0x00;
3233
Aaro Koskinen8104e322011-03-13 12:26:22 +02003234 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003235}
3236
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003237static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303238 struct vb_device_info *pVBInfo)
3239{
3240 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003241 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003242 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303243
3244 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3245
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003246 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003247 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303248
3249 tempax = 0;
3250
3251 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3252 tempax |= 0x0800;
3253
3254 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3255 tempax |= 0x0400;
3256
3257 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3258 tempax |= 0x0200;
3259
Peter Huewe599801f2012-02-09 21:11:45 +01003260 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303261 tempax |= 0x1000;
3262
Peter Huewe599801f2012-02-09 21:11:45 +01003263 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303264 tempax |= 0x0100;
3265
Peter Huewe599801f2012-02-09 21:11:45 +01003266 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303267 tempax &= 0xfe00;
3268
3269 tempax = (tempax & 0xff00) >> 8;
3270
Aaro Koskinen8104e322011-03-13 12:26:22 +02003271 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003272 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303273
Peter Huewe599801f2012-02-09 21:11:45 +01003274 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003275 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303276
Peter Huewe599801f2012-02-09 21:11:45 +01003277 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003278 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303279
3280 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003281 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303282
3283 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003284 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303285
3286 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003287 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303288 }
3289
Peter Huewe599801f2012-02-09 21:11:45 +01003290 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3291 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003292 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303293
Peter Huewe599801f2012-02-09 21:11:45 +01003294 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003295 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303296
Peter Huewe599801f2012-02-09 21:11:45 +01003297 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003298 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303299 }
3300
3301 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003302 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303303
3304 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003305 /* di->temp2[j] */
3306 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303307
3308 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003309 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303310
3311 temp = pVBInfo->NewFlickerMode;
3312 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003313 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303314
Peter Huewe599801f2012-02-09 21:11:45 +01003315 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303316 tempax = 520;
3317 else
3318 tempax = 440;
3319
3320 if (pVBInfo->VDE <= tempax) {
3321 tempax -= pVBInfo->VDE;
Aya Mahfouz46283372015-02-26 11:27:44 +02003322 tempax >>= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303323 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3324 push1 = tempax;
3325 temp = (tempax & 0xFF00) >> 8;
3326 temp += (unsigned short) TimingPoint[0];
3327
Peter Huewe6896b942012-02-09 21:11:46 +01003328 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3329 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303330 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3331 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003332 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303333 tempcx = pVBInfo->VGAHDE;
3334 if (tempcx >= 1024) {
3335 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003336 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303337 temp = 0x19; /* PAL */
3338 }
3339 }
3340 }
3341
Aaro Koskinen8104e322011-03-13 12:26:22 +02003342 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303343 tempax = push1;
3344 temp = (tempax & 0xFF00) >> 8;
3345 temp += TimingPoint[1];
3346
Peter Huewe6896b942012-02-09 21:11:46 +01003347 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3348 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303349 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3350 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003351 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303352 tempcx = pVBInfo->VGAHDE;
3353 if (tempcx >= 1024) {
3354 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003355 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303356 temp = 0x52; /* PAL */
3357 }
3358 }
3359 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003360 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303361 }
3362
3363 /* 301b */
3364 tempcx = pVBInfo->HT;
3365
3366 if (XGI_IsLCDDualLink(pVBInfo))
Aya Mahfouz46283372015-02-26 11:27:44 +02003367 tempcx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303368
3369 tempcx -= 2;
3370 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003371 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303372
3373 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003374 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303375
3376 tempcx = pVBInfo->HT >> 1;
3377 push1 = tempcx; /* push cx */
3378 tempcx += 7;
3379
Peter Huewe599801f2012-02-09 21:11:45 +01003380 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303381 tempcx -= 4;
3382
3383 temp = tempcx & 0x00FF;
Aya Mahfouz46283372015-02-26 11:27:44 +02003384 temp <<= 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003385 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303386
3387 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3388 tempbx += tempcx;
3389 push2 = tempbx;
3390 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003391 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303392 temp = (tempbx & 0xFF00) >> 8;
Aya Mahfouz46283372015-02-26 11:27:44 +02003393 temp <<= 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003394 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303395
3396 tempbx = push2;
3397 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003398 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303399 tempbx = tempbx - 4;
3400 tempcx = tempbx;
3401 }
3402
3403 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003404 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303405
3406 j += 2;
3407 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3408 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003409 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303410 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003411 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303412
3413 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003414 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303415 tempcx -= 4;
3416
3417 temp = tempcx & 0xFF;
Aya Mahfouz46283372015-02-26 11:27:44 +02003418 temp <<= 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003419 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303420
3421 tempcx = push1; /* pop cx */
3422 j += 2;
3423 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3424 tempcx -= temp;
3425 temp = tempcx & 0x00FF;
Aya Mahfouz46283372015-02-26 11:27:44 +02003426 temp <<= 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003427 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303428
3429 tempcx -= 11;
3430
3431 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3432 tempax = XGI_GetVGAHT2(pVBInfo);
3433 tempcx = tempax - 1;
3434 }
3435 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003436 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303437
3438 tempbx = pVBInfo->VDE;
3439
3440 if (pVBInfo->VGAVDE == 360)
3441 tempbx = 746;
3442 if (pVBInfo->VGAVDE == 375)
3443 tempbx = 746;
3444 if (pVBInfo->VGAVDE == 405)
3445 tempbx = 853;
3446
3447 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003448 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003449 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003450 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003451 (TVSetYPbPr525p | TVSetYPbPr750p)))
Aya Mahfouz46283372015-02-26 11:27:44 +02003452 tempbx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303453 } else
Aya Mahfouz46283372015-02-26 11:27:44 +02003454 tempbx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303455 }
3456
3457 tempbx -= 2;
3458 temp = tempbx & 0x00FF;
3459
Peter Huewe599801f2012-02-09 21:11:45 +01003460 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003461 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003462 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303463 if (pVBInfo->VBInfo & SetInSlaveMode) {
3464 if (ModeNo == 0x2f)
3465 temp += 1;
3466 }
3467 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003468 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3469 if (ModeNo == 0x2f)
3470 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303471 }
3472 }
3473
Aaro Koskinen8104e322011-03-13 12:26:22 +02003474 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303475
3476 temp = (tempcx & 0xFF00) >> 8;
3477 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3478
Peter Huewe599801f2012-02-09 21:11:45 +01003479 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003480 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003481 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303482 temp |= 0x10;
3483
3484 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3485 temp |= 0x20;
3486 }
3487 } else {
3488 temp |= 0x10;
3489 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3490 temp |= 0x20;
3491 }
3492 }
3493
Aaro Koskinen8104e322011-03-13 12:26:22 +02003494 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495
Peter Huewe6896b942012-02-09 21:11:46 +01003496 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3497 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303498 tempbx = pVBInfo->VDE;
3499 tempcx = tempbx - 2;
3500
3501 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003502 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3503 | TVSetYPbPr750p)))
Aya Mahfouz46283372015-02-26 11:27:44 +02003504 tempbx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303505 }
3506
Peter Huewe6896b942012-02-09 21:11:46 +01003507 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303508 temp = 0;
3509 if (tempcx & 0x0400)
3510 temp |= 0x20;
3511
3512 if (tempbx & 0x0400)
3513 temp |= 0x40;
3514
Aaro Koskinen8104e322011-03-13 12:26:22 +02003515 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303516 }
3517
3518 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003519 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303520 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003521 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303522 }
3523
3524 tempbx = tempbx & 0x00FF;
3525
3526 if (!(modeflag & HalfDCLK)) {
3527 tempcx = pVBInfo->VGAHDE;
3528 if (tempcx >= pVBInfo->HDE) {
3529 tempbx |= 0x2000;
3530 tempax &= 0x00FF;
3531 }
3532 }
3533
3534 tempcx = 0x0101;
3535
3536 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3537 if (pVBInfo->VGAHDE >= 1024) {
3538 tempcx = 0x1920;
3539 if (pVBInfo->VGAHDE >= 1280) {
3540 tempcx = 0x1420;
3541 tempbx = tempbx & 0xDFFF;
3542 }
3543 }
3544 }
3545
3546 if (!(tempbx & 0x2000)) {
3547 if (modeflag & HalfDCLK)
3548 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3549
3550 push1 = tempbx;
3551 tempeax = pVBInfo->VGAHDE;
3552 tempebx = (tempcx & 0xFF00) >> 8;
3553 longtemp = tempeax * tempebx;
3554 tempecx = tempcx & 0x00FF;
3555 longtemp = longtemp / tempecx;
3556
3557 /* 301b */
3558 tempecx = 8 * 1024;
3559
Peter Huewe6896b942012-02-09 21:11:46 +01003560 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3561 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303562 tempecx = tempecx * 8;
3563 }
3564
3565 longtemp = longtemp * tempecx;
3566 tempecx = pVBInfo->HDE;
3567 temp2 = longtemp % tempecx;
3568 tempeax = longtemp / tempecx;
3569 if (temp2 != 0)
3570 tempeax += 1;
3571
3572 tempax = (unsigned short) tempeax;
3573
3574 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003575 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3576 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303577 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3578 }
3579 /* end 301b */
3580
3581 tempbx = push1;
3582 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3583 | (tempbx & 0x00FF));
3584 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3585 | (tempax & 0x00FF));
3586 temp = (tempax & 0xFF00) >> 8;
3587 } else {
3588 temp = (tempax & 0x00FF) >> 8;
3589 }
3590
Aaro Koskinen8104e322011-03-13 12:26:22 +02003591 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303592 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003593 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303594 temp = tempcx & 0x00FF;
3595
3596 if (tempbx & 0x2000)
3597 temp = 0;
3598
3599 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3600 temp |= 0x18;
3601
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003602 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003603 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303604 tempbx = 0x0382;
3605 tempcx = 0x007e;
3606 } else {
3607 tempbx = 0x0369;
3608 tempcx = 0x0061;
3609 }
3610
3611 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003612 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303613 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003614 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303615
3616 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
Aya Mahfouz46283372015-02-26 11:27:44 +02003617 temp <<= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303618 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3619
Peter Huewe599801f2012-02-09 21:11:45 +01003620 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303621 temp |= 0x10;
3622
Peter Huewe599801f2012-02-09 21:11:45 +01003623 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303624 temp |= 0x20;
3625
Peter Huewe599801f2012-02-09 21:11:45 +01003626 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303627 temp |= 0x60;
3628 }
3629
Aaro Koskinen8104e322011-03-13 12:26:22 +02003630 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003631 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003632 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303633
Peter Huewe599801f2012-02-09 21:11:45 +01003634 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303635 if (pVBInfo->TVInfo & NTSC1024x768) {
3636 TimingPoint = XGI_NTSC1024AdjTime;
3637 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003638 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303639 TimingPoint[j]);
3640 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003641 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303642 }
3643 }
3644
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003645 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303646 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003647 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003648 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303649 0x08); /* PALM Mode */
3650 }
3651
Peter Huewe599801f2012-02-09 21:11:45 +01003652 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003653 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303654 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003655 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303656
Aaro Koskinendc505562011-03-13 12:26:26 +02003657 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303658 }
3659
Peter Huewe599801f2012-02-09 21:11:45 +01003660 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303661 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003662 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303663 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303664}
3665
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003666static void XGI_SetLCDRegs(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303667 struct vb_device_info *pVBInfo)
3668{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003669 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3670 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303671
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003672 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303673
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003674 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303675 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3676 return;
3677
3678 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3679
3680 if (XGI_IsLCDDualLink(pVBInfo))
Aya Mahfouz46283372015-02-26 11:27:44 +02003681 tempbx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303682
3683 tempbx -= 1;
3684 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003685 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303686 temp = (tempbx & 0xFF00) >> 8;
Aya Mahfouz46283372015-02-26 11:27:44 +02003687 temp <<= 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003688 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303689 temp = 0x01;
3690
Aaro Koskinen8104e322011-03-13 12:26:22 +02003691 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303692 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303693 tempbx--;
3694 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003695 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303696 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003697 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303698
3699 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303700 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003701 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303702 temp = (tempcx & 0xFF00) >> 8;
Aya Mahfouz46283372015-02-26 11:27:44 +02003703 temp <<= 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003704 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003705 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3706 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3707 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3708 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303709
Justin P. Mattock558f7582012-10-02 21:17:11 -07003710 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003711 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003712 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03003713 pVBInfo);
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003714 else
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003715 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03003716 pVBInfo);
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003717
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303718 tempah = pVBInfo->LCDResInfo;
3719 tempah &= PanelResInfo;
3720
Peter Huewe255aabd2012-02-09 21:11:44 +01003721 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303722 tempbx = 1024;
3723 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003724 } else if ((tempah == Panel_1280x1024) ||
3725 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303726 tempbx = 1280;
3727 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003728 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303729 tempbx = 1400;
3730 tempcx = 1050;
3731 } else {
3732 tempbx = 1600;
3733 tempcx = 1200;
3734 }
3735
3736 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3737 tempbx = pVBInfo->HDE;
3738 tempcx = pVBInfo->VDE;
3739 }
3740
3741 pushbx = tempbx;
3742 tempax = pVBInfo->VT;
3743 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3744 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3745 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3746 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3747 tempbx = pVBInfo->LCDVDES;
3748 tempcx += tempbx;
3749
3750 if (tempcx >= tempax)
3751 tempcx -= tempax; /* lcdvdes */
3752
3753 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003754 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303755 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003756 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303757 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3758 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3759 tempah = tempch;
Aya Mahfouz46283372015-02-26 11:27:44 +02003760 tempah <<= 3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303761 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003762 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303763
3764 /* getlcdsync() */
3765 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3766 tempcx = tempbx;
3767 tempax = pVBInfo->VT;
3768 tempbx = pVBInfo->LCDVRS;
3769
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303770 tempcx += tempbx;
3771 if (tempcx >= tempax)
3772 tempcx -= tempax;
3773
3774 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003775 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303776 temp = (tempbx & 0xFF00) >> 8;
Aya Mahfouz46283372015-02-26 11:27:44 +02003777 temp <<= 4;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303778 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003779 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303780 tempcx = pushbx;
3781 tempax = pVBInfo->HT;
3782 tempbx = pVBInfo->LCDHDES;
3783 tempbx &= 0x0FFF;
3784
3785 if (XGI_IsLCDDualLink(pVBInfo)) {
Aya Mahfouz46283372015-02-26 11:27:44 +02003786 tempax >>= 1;
3787 tempbx >>= 1;
3788 tempcx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303789 }
3790
Peter Huewe6896b942012-02-09 21:11:46 +01003791 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303792 tempbx += 1;
3793
3794 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3795 tempbx += 1;
3796
3797 tempcx += tempbx;
3798
3799 if (tempcx >= tempax)
3800 tempcx -= tempax;
3801
3802 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003803 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303804 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003805 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303806 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003807 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303808 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003809 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303810
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303811 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3812 tempcx = tempax;
3813 tempax = pVBInfo->HT;
3814 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303815 if (XGI_IsLCDDualLink(pVBInfo)) {
Aya Mahfouz46283372015-02-26 11:27:44 +02003816 tempax >>= 1;
3817 tempbx >>= 1;
3818 tempcx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303819 }
3820
Peter Huewe6896b942012-02-09 21:11:46 +01003821 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303822 tempbx += 1;
3823
3824 tempcx += tempbx;
3825
3826 if (tempcx >= tempax)
3827 tempcx -= tempax;
3828
3829 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003830 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303831
3832 temp = (tempbx & 0xFF00) >> 8;
Aya Mahfouz46283372015-02-26 11:27:44 +02003833 temp <<= 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003834 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303835 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003836 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303837
Peter Huewea3d675c2012-02-09 21:11:47 +01003838 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303839 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003840 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3841 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303842 | VB_XGI301C)) {
3843 temp = 0xC6;
3844 } else
3845 temp = 0xC4;
3846
Aaro Koskinen8104e322011-03-13 12:26:22 +02003847 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3848 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303849 }
3850
3851 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01003852 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3853 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303854 | VB_XGI301C)) {
3855 temp = 0x4F;
3856 } else
3857 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003858 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303859 }
3860 }
3861}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003862
3863/* --------------------------------------------------------------------- */
3864/* Function : XGI_GetTap4Ptr */
3865/* Input : */
3866/* Output : di -> Tap4 Reg. Setting Pointer */
3867/* Description : */
3868/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003869static struct XGI301C_Tap4TimingStruct const
3870*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003871{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303872 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003873 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303875 if (tempcx == 0) {
3876 tempax = pVBInfo->VGAHDE;
3877 tempbx = pVBInfo->HDE;
3878 } else {
3879 tempax = pVBInfo->VGAVDE;
3880 tempbx = pVBInfo->VDE;
3881 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003882
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003883 if (tempax <= tempbx)
3884 return &xgifb_tap4_timing[0];
Thomas Gummerer9c8c8312014-09-05 17:09:34 +02003885 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003886
Peter Huewe599801f2012-02-09 21:11:45 +01003887 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303888 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003889
Peter Huewe599801f2012-02-09 21:11:45 +01003890 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3891 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
3892 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003893 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01003894 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303895 Tap4TimingPtr = YPbPr750pTap4Timing;
3896 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003897
Peter Huewe599801f2012-02-09 21:11:45 +01003898 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003899 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003900
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303901 i = 0;
3902 while (Tap4TimingPtr[i].DE != 0xFFFF) {
3903 if (Tap4TimingPtr[i].DE == tempax)
3904 break;
3905 i++;
3906 }
3907 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003908}
3909
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003910static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003911{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303912 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003913 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003914
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303915 if (!(pVBInfo->VBType & VB_XGI301C))
3916 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003917
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303918 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
3919 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003920 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003921
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003922 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003923 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003924 /* Set Vertical Scaling */
3925 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303926 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003927 xgifb_reg_set(pVBInfo->Part2Port,
3928 i,
3929 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303930 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003931
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003932 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003933 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003934 /* Enable V.Scaling */
3935 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303936 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003937 /* Enable H.Scaling */
3938 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003939}
3940
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003941static void XGI_SetGroup3(unsigned short ModeIdIndex,
3942 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003943{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303944 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003945 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303946 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003947
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003948 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003949 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003950
Aaro Koskinen8104e322011-03-13 12:26:22 +02003951 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01003952 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003953 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3954 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303955 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003956 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
3957 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303958 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003959
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303960 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
3961 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003962
Peter Huewe599801f2012-02-09 21:11:45 +01003963 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003964 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3965 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
3966 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303967 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003968
Peter Huewe599801f2012-02-09 21:11:45 +01003969 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
3970 & SetCRT2ToYPbPr525750)) {
3971 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303972 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003973
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003974 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303975 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003976 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303977 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003978 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303979 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003980
Peter Huewe599801f2012-02-09 21:11:45 +01003981 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003982 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003983
Peter Huewe599801f2012-02-09 21:11:45 +01003984 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003985 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003986
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303987 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003988 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003989
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303990 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01003991 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003992 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303993 }
3994 }
Aaro Koskinen2351d1f2013-05-29 23:59:13 +03003995}
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303996
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003997static void XGI_SetGroup4(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303998 unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303999 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004000{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304001 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004002
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304003 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004004
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004005 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004006 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304007 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004008 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004009
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304010 tempbx = pVBInfo->RVBHCMAX;
4011 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004012 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304013 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4014 tempcx = pVBInfo->VGAHT - 1;
4015 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004016 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004017
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304018 temp = ((tempcx & 0xFF00) >> 8) << 3;
4019 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004020
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304021 tempcx = pVBInfo->VGAVT - 1;
4022 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4023 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304025 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004026 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304027 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004028 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004029 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304030 tempcx = pVBInfo->VBInfo;
4031 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004032
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304033 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +02004034 tempbx >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304036 if (XGI_IsLCDDualLink(pVBInfo))
Aya Mahfouz46283372015-02-26 11:27:44 +02004037 tempbx >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004038
Peter Huewe599801f2012-02-09 21:11:45 +01004039 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304040 temp = 0;
4041 if (tempbx <= 1024)
4042 temp = 0xA0;
4043 if (tempbx == 1280)
4044 temp = 0xC0;
4045 } else if (tempcx & SetCRT2ToTV) {
4046 temp = 0xA0;
4047 if (tempbx <= 800)
4048 temp = 0x80;
4049 } else {
4050 temp = 0x80;
4051 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4052 temp = 0;
4053 if (tempbx > 800)
4054 temp = 0x60;
4055 }
4056 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004057
Peter Huewe599801f2012-02-09 21:11:45 +01004058 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304059 temp = 0x00;
4060 if (pVBInfo->VGAHDE == 1280)
4061 temp = 0x40;
4062 if (pVBInfo->VGAHDE == 1024)
4063 temp = 0x20;
4064 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004065 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004066
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304067 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004068
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304069 tempcx = pVBInfo->RVBHRS;
4070 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004071 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004072
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304073 tempeax = pVBInfo->VGAVDE;
4074 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304076 if (tempeax <= tempebx) {
Janani Ravichandran7aa546e2016-02-11 17:30:16 -05004077 tempcx = tempcx & (~0x4000);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304078 tempeax = pVBInfo->VGAVDE;
4079 } else {
4080 tempeax -= tempebx;
4081 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004082
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304083 templong = (tempeax * 256 * 1024) % tempebx;
4084 tempeax = (tempeax * 256 * 1024) / tempebx;
4085 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004086
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304087 if (templong != 0)
4088 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304090 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004091 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304093 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004094 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304095 tempbx = (unsigned short) (tempebx >> 16);
4096 temp = tempbx & 0x00FF;
Aya Mahfouz46283372015-02-26 11:27:44 +02004097 temp <<= 4;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304098 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004099 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304101 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004102 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4103 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304104 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004105 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304106 tempax = pVBInfo->VGAHDE;
4107 if (modeflag & HalfDCLK)
Aya Mahfouz46283372015-02-26 11:27:44 +02004108 tempax >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004109
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304110 if (XGI_IsLCDDualLink(pVBInfo))
Aya Mahfouz46283372015-02-26 11:27:44 +02004111 tempax >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304113 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4114 if (tempax > 800)
4115 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004116 } else if (pVBInfo->VGAHDE > 800) {
4117 if (pVBInfo->VGAHDE == 1024)
4118 tempax = (tempax * 25 / 32) - 1;
4119 else
4120 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304121 }
4122 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304124 temp = (tempax & 0xFF00) >> 8;
Jiayi Ye1d06bb42014-10-25 10:58:28 +08004125 temp = (temp & 0x0003) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004126 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Janani Ravichandran7aa546e2016-02-11 17:30:16 -05004127 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004128 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004129
Peter Huewe599801f2012-02-09 21:11:45 +01004130 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304131 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004132 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004133
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304134 }
4135 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304137 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4138 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004139 | TVSetYPbPr525p | TVSetYPbPr750p
4140 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304141 temp |= 0x0001;
4142 if ((pVBInfo->VBInfo & SetInSlaveMode)
4143 && (!(pVBInfo->TVInfo
4144 & TVSimuMode)))
4145 temp &= (~0x0001);
4146 }
4147 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004148
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004149 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304150 tempbx = pVBInfo->HT;
4151 if (XGI_IsLCDDualLink(pVBInfo))
Aya Mahfouz46283372015-02-26 11:27:44 +02004152 tempbx >>= 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304153 tempbx = (tempbx >> 1) - 2;
4154 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004155 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304156 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004157 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304158 }
4159 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004160
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004161 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004162}
4163
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004164static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4165{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004166 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004167}
4168
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004169static void XGI_SetGroup5(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004170{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304171 if (pVBInfo->ModeType == ModeVGA) {
4172 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004173 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304174 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304175 }
4176 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004177}
4178
Aaro Koskinenb053af12013-07-16 23:13:28 +03004179static void XGI_DisableGatingCRT(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004180{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004181 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004182}
4183
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004184static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
Aaro Koskinen334ab072013-07-16 23:13:30 +03004185 unsigned short ModeNo, unsigned short ModeIdIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004186{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004187 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004188
Aaro Koskinenb3979922012-11-04 21:14:52 +02004189 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004190 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4191 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004192 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004193 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004194
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304195 if (!(modeflag & Charx8Dot)) {
4196 xres /= 9;
4197 xres *= 8;
4198 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004199
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004200 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4201 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004202
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004203 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4204 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004205
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004206 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304207 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004208
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004209 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304210 return 0;
4211
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004212 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4213 yres != xgifb_info->lvds_data.LVDSVDE) {
Aaro Koskinen334ab072013-07-16 23:13:30 +03004214 colordepth = XGI_GetColorDepth(ModeIdIndex);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004215 if (colordepth > 2)
4216 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304217 }
4218 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004219}
4220
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004221static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4222 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004223 unsigned short ModeIdIndex,
4224 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004225{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304226 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004227 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304228 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4229 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4230 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004231
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004232 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004233 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304234 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004235 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004236
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004237 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004238
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004239 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004240 /* SR35[7] FP VSync polarity */
4241 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4242 /* SR30[5] FP HSync polarity */
4243 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004244
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004245 if (chip_id == XG27)
4246 XGI_SetXG27FPBits(pVBInfo);
4247 else
4248 XGI_SetXG21FPBits(pVBInfo);
4249
Aaro Koskinenb3979922012-11-04 21:14:52 +02004250 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004251 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4252 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004253 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004254 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304256 if (!(modeflag & Charx8Dot))
4257 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004258
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004259 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004260
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004261 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004262
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304263 if (LVDSHBS > LVDSHT)
4264 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004265
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004266 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304267 if (LVDSHRS > LVDSHT)
4268 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004269
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004270 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304271 if (LVDSHRE > LVDSHT)
4272 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004273
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004274 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004275
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004276 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004277
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004278 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004279 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304280 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004281
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304282 if (LVDSVBS > LVDSVT)
4283 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004284
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004285 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304286 if (LVDSVRS > LVDSVT)
4287 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004288
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004289 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304290 if (LVDSVRE > LVDSVT)
4291 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004292
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004293 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004294
Peter Huewe9388ad92013-02-15 20:37:10 +01004295 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004296 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004297
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304298 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004299 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004300
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304301 /* HT SR0B[1:0] CR00 */
4302 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004303 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004304 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004305
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304306 /* HBS SR0B[5:4] CR02 */
4307 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004308 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004309 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004310
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304311 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4312 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004313 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4314 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4315 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004316
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304317 /* HRS SR0B[7:6] CR04 */
4318 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004319 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004320 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004321
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304322 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4323 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004324 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004325 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004326
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304327 /* HRE SR0C[2] CR05[4:0] */
4328 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004329 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4330 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304332 /* Panel HRE SR2F[7:2] */
4333 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004334 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304336 /* VT SR0A[0] CR07[5][0] CR06 */
4337 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004338 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4339 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4340 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004341 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004342
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304343 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4344 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004345 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4346 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4347 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004348 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004349
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304350 /* VBE SR0A[4] CR16 */
4351 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004352 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004353 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004354
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304355 /* VRS SR0A[3] CR7[7][2] CR10 */
4356 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004357 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4358 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4359 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004360 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004361
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004362 if (chip_id == XG27) {
4363 /* Panel VRS SR35[2:0] SR34[7:0] */
4364 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4365 (value & 0x700) >> 8);
4366 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4367 } else {
4368 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4369 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4370 (value & 0x600) >> 9);
4371 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4372 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4373 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004374
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304375 /* VRE SR0A[5] CR11[3:0] */
4376 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004377 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4378 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304380 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004381 if (chip_id == XG27)
4382 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4383 (value << 2) & 0xFC);
4384 else
4385 /* SR3F[7] has to be 0, h/w bug */
4386 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4387 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004388
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304389 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004390
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004391 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004392 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004393 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004394 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004395 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304396 value += 0x10;
4397 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004398
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304399 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004400 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004401 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004402 /* set data, panning = 0, shift left 1 dot*/
4403 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004404
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004405 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004406 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304407
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004408 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304409 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004410
4411}
4412
4413/* --------------------------------------------------------------------- */
4414/* Function : XGI_IsLCDON */
4415/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004416/* Output : 0 : Skip PSC Control */
4417/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004418/* Description : */
4419/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004420static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004421{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304422 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004423
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304424 tempax = pVBInfo->VBInfo;
4425 if (tempax & SetCRT2ToDualEdge)
4426 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004427 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304428 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004429
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304430 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004431}
4432
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004433static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4434 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304435 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004436{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004437 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004438
Peter Huewe6896b942012-02-09 21:11:46 +01004439 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4440 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304441 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004442 if (!(pVBInfo->VBInfo &
4443 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004444 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004445 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304446 tempah = 0x7F; /* Disable Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304447 }
4448 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004449
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004450 /* disable part4_1f */
4451 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004452
Peter Huewe6896b942012-02-09 21:11:46 +01004453 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004454 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004455 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
Peter Huewe06cc47b2013-02-03 22:54:38 +01004456 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004457 /* LVDS Driver power down */
4458 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304459 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004460
Aaro Koskinend1724632013-05-29 23:59:09 +03004461 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA |
4462 SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004463 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004464
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004465 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4466 /* Power down */
4467 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004468
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004469 /* disable TV as primary VGA swap */
4470 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004471
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304472 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004473 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004474
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004475 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004476 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004477 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004478 (pVBInfo->VBInfo &
4479 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004480 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004481
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004482 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004483 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004484 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004485 (pVBInfo->VBInfo &
4486 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4487 /* save Part1 index 0 */
4488 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4489 /* BTDAC = 1, avoid VB reset */
4490 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4491 /* disable CRT2 */
4492 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4493 /* restore Part1 index 0 */
4494 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304495 }
4496 } else { /* {301} */
4497 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004498 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4499 /* Disable CRT2 */
4500 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4501 /* Disable TV asPrimary VGA swap */
4502 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304503 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004504
Peter Huewea3d675c2012-02-09 21:11:47 +01004505 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304506 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004507 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304508 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004509}
4510
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004511/* --------------------------------------------------------------------- */
4512/* Function : XGI_GetTVPtrIndex */
4513/* Input : */
4514/* Output : */
4515/* Description : bx 0 : ExtNTSC */
4516/* 1 : StNTSC */
4517/* 2 : ExtPAL */
4518/* 3 : StPAL */
4519/* 4 : ExtHiTV */
4520/* 5 : StHiTV */
4521/* 6 : Ext525i */
4522/* 7 : St525i */
4523/* 8 : Ext525p */
4524/* 9 : St525p */
4525/* A : Ext750p */
4526/* B : St750p */
4527/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004528static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004529{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304530 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004531
Peter Huewe599801f2012-02-09 21:11:45 +01004532 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304533 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004534 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304535 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004536 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304537 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004538 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304539 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004540 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304541 tempbx = 10;
4542 if (pVBInfo->TVInfo & TVSimuMode)
4543 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004544
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304545 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004546}
4547
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004548/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004549/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004550/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004551/* Output : bx 0 : NTSC */
4552/* 1 : PAL */
4553/* 2 : PALM */
4554/* 3 : PALN */
4555/* 4 : NTSC1024x768 */
4556/* 5 : PAL-M 1024x768 */
4557/* 6-7: reserved */
4558/* cl 0 : YFilter1 */
4559/* 1 : YFilter2 */
4560/* ch 0 : 301A */
4561/* 1 : 301B/302B/301LV/302LV */
4562/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004563/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004564static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4565 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004566{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004567 *tempbx = 0;
4568 *tempcl = 0;
4569 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004570
Peter Huewe599801f2012-02-09 21:11:45 +01004571 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004572 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004573
Peter Huewe599801f2012-02-09 21:11:45 +01004574 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004575 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004576
Peter Huewe599801f2012-02-09 21:11:45 +01004577 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004578 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004579
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004580 if (pVBInfo->TVInfo & NTSC1024x768) {
4581 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004582 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004583 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304584 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004585
Peter Huewe6896b942012-02-09 21:11:46 +01004586 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4587 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004588 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4589 & TVSimuMode)) {
4590 *tempbx += 8;
4591 *tempcl += 1;
4592 }
4593 }
4594
Peter Huewe6896b942012-02-09 21:11:46 +01004595 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4596 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004597 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004598}
4599
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004600static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004601{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304602 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004603
Peter Huewe6896b942012-02-09 21:11:46 +01004604 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4605 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004606 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304607 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304608 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004609 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004610
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304611 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Aya Mahfouz46283372015-02-26 11:27:44 +02004612 tempbl >>= 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004613 if (pVBInfo->VBInfo &
4614 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004615 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004616
Peter Huewea3d675c2012-02-09 21:11:47 +01004617 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304618 tempbl = tempbh;
4619 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004620
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304621 tempbl &= 0x0F;
4622 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004623 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304625 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4626 | SetCRT2ToTV)) { /* Channel B */
4627 tempah &= 0xF0;
4628 tempah |= tempbl;
4629 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004630
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004631 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4632 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304633 tempah &= 0x0F;
4634 tempah |= tempbh;
4635 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004636 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304637 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304638 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004639}
4640
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004641static void XGI_SetLCDCap_A(unsigned short tempcx,
4642 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004643{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304644 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004645
Aaro Koskinen58839b02011-03-13 12:26:23 +02004646 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304648 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004649 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004650 /* Enable Dither */
4651 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004652 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304653 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004654 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304655 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004656 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304657 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004658}
4659
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004660/* --------------------------------------------------------------------- */
4661/* Function : XGI_SetLCDCap_B */
4662/* Input : cx -> LCD Capability */
4663/* Output : */
4664/* Description : */
4665/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004666static void XGI_SetLCDCap_B(unsigned short tempcx,
4667 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004668{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304669 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004670 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304671 (unsigned short) (((tempcx & 0x00ff) >> 6)
4672 | 0x0c));
4673 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004674 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304675 (unsigned short) (((tempcx & 0x00ff) >> 6)
4676 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004677}
4678
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004679static void XGI_LongWait(struct vb_device_info *pVBInfo)
4680{
4681 unsigned short i;
4682
4683 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4684
4685 if (!(i & 0xC0)) {
4686 for (i = 0; i < 0xFFFF; i++) {
4687 if (!(inb(pVBInfo->P3da) & 0x08))
4688 break;
4689 }
4690
4691 for (i = 0; i < 0xFFFF; i++) {
4692 if ((inb(pVBInfo->P3da) & 0x08))
4693 break;
4694 }
4695 }
4696}
4697
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004698static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004699{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304700 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004701
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304702 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004703
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004704 /* disable down spectrum D[4] */
4705 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304706 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004707 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304708 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004709
Aaro Koskinen8104e322011-03-13 12:26:22 +02004710 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304711 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004712 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304713 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004714 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304715 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004716 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304717 pVBInfo->LCDCapList[index].Spectrum_34);
4718 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004719 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004720}
4721
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004722static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4723{
4724 unsigned short tempcx;
4725
4726 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4727
Peter Huewef951dd02013-02-05 00:29:47 +01004728 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4729 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004730 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004731 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004732 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004733 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004734 (unsigned char) (tempcx & 0x1F));
4735 }
4736 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004737 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004738 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4739 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4740 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004741
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004742 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4743 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004744 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004745 XGI_SetLCDCap_A(tempcx, pVBInfo);
4746
Peter Huewe6896b942012-02-09 21:11:46 +01004747 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004748 if (tempcx & EnableSpectrum)
4749 SetSpectrum(pVBInfo);
4750 }
4751 } else {
4752 /* LVDS,CH7017 */
4753 XGI_SetLCDCap_A(tempcx, pVBInfo);
4754 }
4755}
4756
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004757/* --------------------------------------------------------------------- */
4758/* Function : XGI_SetAntiFlicker */
4759/* Input : */
4760/* Output : */
4761/* Description : Set TV Customized Param. */
4762/* --------------------------------------------------------------------- */
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004763static void XGI_SetAntiFlicker(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004764{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004765 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004766
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304767 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004768
Peter Huewe599801f2012-02-09 21:11:45 +01004769 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304770 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004771
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304772 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4773 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304774 tempah = TVAntiFlickList[tempbx];
Aya Mahfouz46283372015-02-26 11:27:44 +02004775 tempah <<= 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004776
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004777 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004778}
4779
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004780static void XGI_SetEdgeEnhance(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004781{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03004782 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304784 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304786 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4787 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304788 tempah = TVEdgeList[tempbx];
Aya Mahfouz46283372015-02-26 11:27:44 +02004789 tempah <<= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004790
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004791 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004792}
4793
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004794static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004795{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304796 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304798 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004799
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304800 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304802 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4803 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004804
Aaro Koskinen8104e322011-03-13 12:26:22 +02004805 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304806 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004807 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304808 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004809 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304810 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004811 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304812 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004813}
4814
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004815static void XGI_SetYFilter(unsigned short ModeIdIndex,
4816 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004817{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304818 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02004819 unsigned char const *filterPtr;
4820 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304822 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004823
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304824 switch (tempbx) {
4825 case 0x00:
4826 case 0x04:
4827 filterPtr = NTSCYFilter1;
4828 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304830 case 0x01:
4831 filterPtr = PALYFilter1;
4832 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004833
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304834 case 0x02:
4835 case 0x05:
4836 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304837 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03004838 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304839 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004840
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304841 case 0x08:
4842 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304843 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304844 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304845 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03004846 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304847 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004848
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304849 default:
4850 return;
4851 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004852
Aaro Koskinenb3979922012-11-04 21:14:52 +02004853 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304854 if (tempcl == 0)
4855 index = tempal * 4;
4856 else
4857 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004858
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304859 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004860 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
4861 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
4862 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
4863 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304864 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004865 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
4866 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
4867 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
4868 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304869 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004870
Peter Huewe6896b942012-02-09 21:11:46 +01004871 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4872 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004873 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
4874 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
4875 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304876 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004877}
4878
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004879/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004880/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004881/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004882/* Output : */
4883/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004884/* --------------------------------------------------------------------- */
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004885static void XGI_OEM310Setting(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004886 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004887{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004888 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004889
Peter Huewea3d675c2012-02-09 21:11:47 +01004890 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004891 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004892
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004893 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004894 XGI_SetPhaseIncr(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004895 XGI_SetYFilter(ModeIdIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004896 XGI_SetAntiFlicker(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004897
Peter Huewe6896b942012-02-09 21:11:46 +01004898 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004899 XGI_SetEdgeEnhance(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304900 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004901}
4902
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004903/* --------------------------------------------------------------------- */
4904/* Function : XGI_SetCRT2ModeRegs */
4905/* Input : */
4906/* Output : */
4907/* Description : Origin code for crt2group */
4908/* --------------------------------------------------------------------- */
Aaro Koskinenb053af12013-07-16 23:13:28 +03004909static void XGI_SetCRT2ModeRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004910{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304911 unsigned short tempbl;
4912 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004913
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304914 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304916 tempah = 0;
4917 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02004918 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304919 tempah &= ~0x10; /* BTRAMDAC */
4920 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004921
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304922 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
4923 | SetCRT2ToLCD)) {
4924 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004925 tempcl = pVBInfo->ModeType;
4926 tempcl -= ModeVGA;
4927 if (tempcl >= 0) {
4928 /* BT Color */
Janani Ravichandran7aa546e2016-02-11 17:30:16 -05004929 tempah = 0x008 >> tempcl;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004930 if (tempah == 0)
4931 tempah = 1;
4932 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304933 }
4934 if (pVBInfo->VBInfo & SetInSlaveMode)
4935 tempah ^= 0x50; /* BTDAC */
4936 }
4937 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004938
Aaro Koskinen8104e322011-03-13 12:26:22 +02004939 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304940 tempah = 0x08;
4941 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004942
Miguel Gómeze123e462012-07-06 12:40:52 +02004943 if (pVBInfo->VBInfo & DisableCRT2Display)
4944 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004945
Miguel Gómeze123e462012-07-06 12:40:52 +02004946 tempah = 0x00;
4947 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004948
Miguel Gómeze123e462012-07-06 12:40:52 +02004949 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
4950 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4951 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004952
Miguel Gómeze123e462012-07-06 12:40:52 +02004953 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
4954 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
4955 tempbl &= 0xf7;
4956 tempah |= 0x01;
4957 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304958 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004959
Miguel Gómeze123e462012-07-06 12:40:52 +02004960 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4961 tempbl &= 0xf7;
4962 tempah |= 0x01;
4963 }
4964
4965 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
4966 goto reg_and_or;
4967
4968 tempbl &= 0xf8;
4969 tempah = 0x01;
4970
4971 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4972 tempah |= 0x02;
4973
4974 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
4975 tempah = tempah ^ 0x05;
4976 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4977 tempah = tempah ^ 0x01;
4978 }
4979
4980 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
4981 tempah |= 0x08;
4982
4983reg_and_or:
4984 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
4985
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304986 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01004987 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304988 tempah &= (~0x08);
4989 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
4990 & SetInSlaveMode))) {
4991 tempah |= 0x010;
4992 }
4993 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304995 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304996 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004997 if (pVBInfo->VBInfo & DriverMode)
4998 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304999 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005000
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005001 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305002 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305004 if (pVBInfo->LCDInfo & SetLCDDualLink)
5005 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005006
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305007 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305008 if (pVBInfo->TVInfo & RPLLDIV2XO)
5009 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305010 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005011
Peter Huewe255aabd2012-02-09 21:11:44 +01005012 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5013 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305014 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005015
Peter Huewe255aabd2012-02-09 21:11:44 +01005016 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305017 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005018
Aaro Koskinen8104e322011-03-13 12:26:22 +02005019 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305020 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005021
Peter Huewe6896b942012-02-09 21:11:46 +01005022 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5023 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305024 tempah = 0;
5025 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005026
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305027 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5028 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005029 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305030 tempah |= 0x04; /* shampoo 0129 */
5031 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005032
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005033 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305034 tempah = 0x00;
5035 tempbl = 0xcf;
5036 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5037 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5038 tempah |= 0x30;
5039 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005040
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005041 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305042 tempah = 0;
5043 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305045 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5046 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5047 tempah |= 0xc0;
5048 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005049 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305050 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305052 tempah = 0;
5053 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005054 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305055 tempbl = 0xff;
5056 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5057 tempah |= 0x80;
5058 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005059
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005060 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005061
Peter Huewe6896b942012-02-09 21:11:46 +01005062 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305063 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005064 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5065 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305066 }
5067 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005068}
5069
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005070
Aaro Koskinenb053af12013-07-16 23:13:28 +03005071void XGI_UnLockCRT2(struct vb_device_info *pVBInfo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305072{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005073 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005074}
5075
Aaro Koskinenb053af12013-07-16 23:13:28 +03005076void XGI_LockCRT2(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005077{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005078 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005079}
5080
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005081unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5082 unsigned short ModeNo, unsigned short ModeIdIndex,
5083 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005084{
Peter Huewef2c22602013-02-03 22:54:30 +01005085 const u8 LCDARefreshIndex[] = {
5086 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005087
Peter Hueweef9a6b92013-02-03 04:08:43 +01005088 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005089
Aaro Koskinen58839b02011-03-13 12:26:23 +02005090 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aya Mahfouz46283372015-02-26 11:27:44 +02005091 index >>= pVBInfo->SelectCRT2Rate;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005092 index &= 0x0F;
5093
5094 if (pVBInfo->LCDInfo & LCDNonExpanding)
5095 index = 0;
5096
5097 if (index > 0)
5098 index--;
5099
5100 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005101 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005102 temp = LCDARefreshIndex[pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005103
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005104 if (index > temp)
5105 index = temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005106 }
5107 }
5108
Aaro Koskinenb3979922012-11-04 21:14:52 +02005109 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005110 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005111 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005112 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5113 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005114 index++;
5115 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005116 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005117 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5118 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005119 index++;
5120 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005121 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5122 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005123 index++;
5124 }
5125 }
5126
5127 i = 0;
5128 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005129 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005130 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005131 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005132 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005133 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005134 if (temp < pVBInfo->ModeType)
5135 break;
5136 i++;
5137 index--;
5138
5139 } while (index != 0xFFFF);
5140 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5141 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005142 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005143 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005144 if (temp & InterlaceMode)
5145 i++;
5146 }
5147 }
5148 i--;
5149 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005150 temp = XGI_AjustCRT2Rate(ModeIdIndex, RefreshRateTableIndex,
5151 &i, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005152 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005153 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005154}
5155
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005156static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305157 struct xgi_hw_device_info *HwDeviceExtension,
5158 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005159{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005160 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005161
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005162 pVBInfo->SetFlag |= ProgrammingCRT2;
5163 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5164 ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005165 XGI_GetLVDSResInfo(ModeIdIndex, pVBInfo);
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03005166 XGI_GetLVDSData(ModeIdIndex, pVBInfo);
5167 XGI_ModCRT1Regs(ModeIdIndex, HwDeviceExtension, pVBInfo);
5168 XGI_SetLVDSRegs(ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005169 XGI_SetCRT2ECLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005170}
5171
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005172static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005173 struct xgi_hw_device_info *HwDeviceExtension,
5174 struct vb_device_info *pVBInfo)
5175{
Peter Huewea9e29e62013-02-03 04:08:44 +01005176 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005177
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005178 pVBInfo->SetFlag |= ProgrammingCRT2;
Aaro Koskinen334ab072013-07-16 23:13:30 +03005179 XGI_SearchModeID(ModeNo, &ModeIdIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005180 pVBInfo->SelectCRT2Rate = 4;
5181 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5182 ModeIdIndex, pVBInfo);
5183 XGI_SaveCRT2Info(ModeNo, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005184 XGI_GetCRT2ResInfo(ModeIdIndex, pVBInfo);
5185 XGI_GetCRT2Data(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005186 XGI_PreSetGroup1(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5187 XGI_SetGroup1(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03005188 XGI_SetLockRegs(ModeNo, ModeIdIndex, pVBInfo);
5189 XGI_SetGroup2(ModeNo, ModeIdIndex, pVBInfo);
5190 XGI_SetLCDRegs(ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005191 XGI_SetTap4Regs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005192 XGI_SetGroup3(ModeIdIndex, pVBInfo);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005193 XGI_SetGroup4(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005194 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005195 XGI_SetGroup5(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005196 XGI_AutoThreshold(pVBInfo);
5197 return 1;
5198}
5199
5200void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5201{
5202 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5203 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5204 0x05, 0x00 };
5205
5206 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5207
5208 unsigned char CR17, CR63, SR31;
5209 unsigned short temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005210
5211 int i;
Vitor Braga694683f2014-03-30 00:44:59 -03005212
Aaro Koskinen8104e322011-03-13 12:26:22 +02005213 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005214
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005215 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005216 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005217 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005218 pVBInfo->P3d4, 0x53) | 0x02));
5219
Peter Huewe9388ad92013-02-15 20:37:10 +01005220 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5221 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5222 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005223
Aaro Koskinen8104e322011-03-13 12:26:22 +02005224 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5225 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005226
Peter Huewe9388ad92013-02-15 20:37:10 +01005227 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005228 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005229
Peter Huewe9388ad92013-02-15 20:37:10 +01005230 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005231 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005232
Peter Huewe9388ad92013-02-15 20:37:10 +01005233 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005234 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005235 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005236 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005237
Aaro Koskinen8104e322011-03-13 12:26:22 +02005238 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005239
5240 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005241 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005242
5243 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005244 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005245 CRTCData[i]);
5246
5247 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005248 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005249 CRTCData[i]);
5250
5251 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005252 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005253 CRTCData[i]);
5254
Aaro Koskinen8104e322011-03-13 12:26:22 +02005255 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005256 & 0xE0));
5257
Aaro Koskinen8104e322011-03-13 12:26:22 +02005258 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5259 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5260 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005261
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005262 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005263
Ebru Akagunduzf88d8182013-10-07 22:25:28 +03005264 for (i = 0; i < 256 * 3; i++)
Peter Huewe771f3ee2013-02-15 20:37:13 +01005265 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005266
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005267 mdelay(1);
5268
5269 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005270 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005271
5272 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005273 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005274 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005275 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005276
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005277 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005278 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005279
Ebru Akagunduzf88d8182013-10-07 22:25:28 +03005280 for (i = 0; i < 256 * 3; i++)
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005281 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005282
Aaro Koskinen8104e322011-03-13 12:26:22 +02005283 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5284 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5285 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005286
Peter Huewe9388ad92013-02-15 20:37:10 +01005287 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005288 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005289 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005290}
5291
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005292static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5293 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005294 struct vb_device_info *pVBInfo)
5295{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005296 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005297
Peter Huewe6896b942012-02-09 21:11:46 +01005298 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5299 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinena2526d12013-05-29 23:59:10 +03005300 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Aaro Koskinend1724632013-05-29 23:59:09 +03005301 /* Power on */
5302 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005303
Aaro Koskinenb8e34b32013-05-29 23:59:08 +03005304 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
5305 SetCRT2ToRAMDAC)) {
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005306 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5307 tempah &= 0xDF;
5308 if (pVBInfo->VBInfo & SetInSlaveMode) {
5309 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
5310 tempah |= 0x20;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005311 }
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005312 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5313 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5314
5315 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5316
5317 if (!(tempah & 0x80))
5318 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5319 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005320 }
5321
Aaro Koskinena2526d12013-05-29 23:59:10 +03005322 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005323 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005324 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005325 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen056b5402013-05-29 23:59:11 +03005326 if (pVBInfo->VBInfo &
5327 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
5328 /* LVDS PLL power on */
5329 xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
5330 0x7F);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005331 /* LVDS Driver power on */
5332 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005333 }
5334 }
5335
5336 tempah = 0x00;
5337
5338 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5339 tempah = 0xc0;
5340
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005341 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5342 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5343 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5344 tempah = tempah & 0x40;
5345 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5346 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005347 }
5348 }
5349
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005350 /* EnablePart4_1F */
5351 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005352
Aaro Koskinenb053af12013-07-16 23:13:28 +03005353 XGI_DisableGatingCRT(pVBInfo);
Aaro Koskinend1724632013-05-29 23:59:09 +03005354 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005355 } /* 301 */
5356 else { /* LVDS */
5357 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005358 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005359 /* enable CRT2 */
5360 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005361
Peter Huewe9388ad92013-02-15 20:37:10 +01005362 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005363 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005364 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005365
Aaro Koskinendc505562011-03-13 12:26:26 +02005366 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005367 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005368 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005369}
5370
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005371static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5372 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005373 unsigned short ModeNo, unsigned short ModeIdIndex,
5374 struct vb_device_info *pVBInfo)
5375{
Aaro Koskinena1579612012-04-07 01:14:05 +03005376 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005377
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005378 XGI_SetSeqRegs(pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005379 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005380 XGI_SetCRTCRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005381 XGI_SetATTRegs(ModeIdIndex, pVBInfo);
Aaro Koskinena1579612012-04-07 01:14:05 +03005382 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005383 XGI_ClearExt1Regs(pVBInfo);
5384
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005385 if (HwDeviceExtension->jChipType == XG27) {
5386 if (pVBInfo->IF_DEF_LVDS == 0)
5387 XGI_SetDefaultVCLK(pVBInfo);
5388 }
5389
5390 temp = ~ProgrammingCRT2;
5391 pVBInfo->SetFlag &= temp;
5392 pVBInfo->SelectCRT2Rate = 0;
5393
Peter Huewe6896b942012-02-09 21:11:46 +01005394 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5395 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005396 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005397 | SetInSlaveMode)) {
5398 pVBInfo->SetFlag |= ProgrammingCRT2;
5399 }
5400 }
5401
5402 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5403 ModeIdIndex, pVBInfo);
5404 if (RefreshRateTableIndex != 0xFFFF) {
5405 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005406 XGI_SetCRT1CRTC(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005407 pVBInfo, HwDeviceExtension);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005408 XGI_SetCRT1DE(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005409 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5410 HwDeviceExtension, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005411 XGI_SetCRT1VCLK(ModeIdIndex, HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005412 RefreshRateTableIndex, pVBInfo);
5413 }
5414
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005415 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005416 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005417 if (temp & 0xA0) {
5418
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005419 if (HwDeviceExtension->jChipType == XG27)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005420 XGI_SetXG27CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005421 else
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005422 XGI_SetXG21CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005423
5424 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5425 RefreshRateTableIndex);
5426
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005427 xgifb_set_lcd(HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005428 pVBInfo, RefreshRateTableIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005429
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005430 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005431 xgifb_set_lvds(xgifb_info,
5432 HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005433 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005434 }
5435 }
5436
5437 pVBInfo->SetFlag &= (~ProgrammingCRT2);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005438 XGI_SetCRT1FIFO(HwDeviceExtension, pVBInfo);
5439 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeIdIndex,
5440 RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005441 XGI_LoadDAC(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005442}
5443
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005444unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5445 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005446 unsigned short ModeNo)
5447{
5448 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005449 struct vb_device_info VBINF;
5450 struct vb_device_info *pVBInfo = &VBINF;
Chaitanya Hazarey0292bd42014-05-23 12:24:37 -07005451
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005452 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005453
Aaro Koskinenee768752013-05-29 23:59:16 +03005454 if (HwDeviceExtension->jChipType >= XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005455 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005456
Aaro Koskinen56810a92013-01-21 02:57:47 +02005457 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005458
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005459 /* for x86 Linux, XG21 LVDS */
5460 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005461 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005462 pVBInfo->IF_DEF_LVDS = 1;
5463 }
5464 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005465 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5466 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005467 pVBInfo->IF_DEF_LVDS = 1;
5468 }
5469 }
5470
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005471 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005472 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005473 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005474 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005475
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005476 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005477 XGI_UnLockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005478
Aaro Koskinen334ab072013-07-16 23:13:30 +03005479 XGI_SearchModeID(ModeNo, &ModeIdIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005480
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005481 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinenb053af12013-07-16 23:13:28 +03005482 XGI_GetVBInfo(ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005483 XGI_GetTVInfo(ModeIdIndex, pVBInfo);
5484 XGI_GetLCDInfo(ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005485 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005486
Peter Huewee44adfd2013-02-03 22:54:39 +01005487 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5488 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005489 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005490 ModeIdIndex, pVBInfo);
5491
Peter Huewea3d675c2012-02-09 21:11:47 +01005492 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005493 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5494 HwDeviceExtension, pVBInfo);
5495 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005496 }
5497
Peter Huewe6896b942012-02-09 21:11:46 +01005498 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005499 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005500 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005501 case VB_CHIP_302:
5502 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5503 pVBInfo); /*add for CRT2 */
5504 break;
5505
5506 default:
5507 break;
5508 }
5509 }
5510
Aaro Koskinenb053af12013-07-16 23:13:28 +03005511 XGI_SetCRT2ModeRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005512 XGI_OEM310Setting(ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005513 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005514 } /* !XG20 */
5515 else {
5516 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005517 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Aaro Koskinen334ab072013-07-16 23:13:30 +03005518 ModeIdIndex))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005519 return 0;
5520
Aaro Koskinenb3979922012-11-04 21:14:52 +02005521 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005522 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005523
5524 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005525 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005526
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005527 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005528
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005529 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5530 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005531
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005532 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005533 }
5534
Aaro Koskinenb053af12013-07-16 23:13:28 +03005535 XGI_UpdateModeInfo(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005536
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005537 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005538 XGI_LockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005539
5540 return 1;
5541}