blob: 2f9046439b0d359dd99084653decdff56898886f [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
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053035 pVBInfo->SR15 = XGI340_SR13;
36 pVBInfo->CR40 = XGI340_cr41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053038 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010039 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053040 pVBInfo->LCDCapList = XGI_LCDDLCapList;
41 else
42 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053044 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020045 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053047 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040048 unsigned char temp;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030049 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053050 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020051 pVBInfo->XGINew_CR97 = 0xc1;
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040052 pVBInfo->SR15 = XG27_SR13;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020053
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040054 /*Z11m DDR*/
55 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
56 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
57 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020058 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053059 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020060
61}
62
Kenji Toyama1d7f6562011-04-23 19:36:49 +080063static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080064 unsigned short ModeIdIndex,
65 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020066{
Peter Huewe76a58992013-02-03 22:54:34 +010067 unsigned char SRdata, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020068
Aaro Koskinen8104e322011-03-13 12:26:22 +020069 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020070
Peter Huewe76a58992013-02-03 22:54:34 +010071 for (i = 0; i < 4; i++) {
72 /* Get SR1,2,3,4 from file */
73 /* SR1 is with screen off 0x20 */
74 SRdata = XGI330_StandTable.SR[i];
75 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053076 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020077}
78
Aaro Koskinen063b9c42011-03-08 22:16:13 +020079static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080080 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
Aaro Koskinen58839b02011-03-13 12:26:23 +020085 CRTCdata = (unsigned char) 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
Kenji Toyama1d7f6562011-04-23 19:36:49 +080096static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080097 unsigned short ModeIdIndex,
98 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020099{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530100 unsigned char ARdata;
101 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200102
Aaro Koskinenb3979922012-11-04 21:14:52 +0200103 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530105 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200106 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200107
108 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
109 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
110 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300111 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200112 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300113 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530115 }
116 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200117
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200118 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200119 outb(i, pVBInfo->P3c0); /* set index */
120 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200122
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200123 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200124 outb(0x14, pVBInfo->P3c0); /* set index */
125 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200126 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200127 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200128}
129
Aaro Koskinena1579612012-04-07 01:14:05 +0300130static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200131{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530132 unsigned char GRdata;
133 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530135 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800136 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200137 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200138 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530139 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530141 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200142 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530143 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200144 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530145 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200146}
147
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200148static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200149{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530150 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200151
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530152 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200153 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200154}
155
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200156static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200157{
158
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200159 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200160 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
161 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200162
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200163 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200164 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
165 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200166
Aaro Koskinendc505562011-03-13 12:26:26 +0200167 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530168 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200169}
170
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200171static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530172 unsigned short ModeIdIndex,
173 unsigned short RefreshRateTableIndex, unsigned short *i,
174 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200175{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530176 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200177
Aaro Koskinenb3979922012-11-04 21:14:52 +0200178 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
179 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200180 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530181 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200182
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530183 if (pVBInfo->IF_DEF_LVDS == 0) {
184 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
185 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530187 if (pVBInfo->VBType & VB_XGI301C)
188 tempax |= SupportCRT2in301C;
189 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200190
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800191 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100192 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530193 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200194
Miguel Gómez3b175622012-07-06 12:40:46 +0200195 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
196 pVBInfo->LCDResInfo != Panel_1280x960 &&
197 (pVBInfo->LCDInfo & LCDNonExpanding) &&
198 resinfo >= 9)
199 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530200 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200201
Peter Huewe599801f2012-02-09 21:11:45 +0100202 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300203 tempax |= SupportHiVision;
204 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
205 ((resinfo == 4) ||
206 (resinfo == 3 &&
207 (pVBInfo->SetFlag & TVSimuMode)) ||
208 (resinfo > 7)))
Miguel Gómez3b175622012-07-06 12:40:46 +0200209 return 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300210 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800211 SetCRT2ToSVIDEO |
212 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100213 SetCRT2ToYPbPr525750 |
214 SetCRT2ToHiVision)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300215 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200216
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300217 if (pVBInfo->VBType & (VB_SIS301B |
218 VB_SIS302B |
219 VB_SIS301LV |
220 VB_SIS302LV |
221 VB_XGI301C))
222 tempax |= SupportTV1024;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200223
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300224 if (!(pVBInfo->VBInfo & TVSetPAL) &&
225 (modeflag & NoSupportSimuTV) &&
226 (pVBInfo->VBInfo & SetInSlaveMode) &&
227 (!(pVBInfo->VBInfo & SetNotSimuMode)))
228 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530229 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300230 } else if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* for LVDS */
231 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200232
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300233 if (resinfo > 0x08)
234 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200235
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300236 if (pVBInfo->LCDResInfo < Panel_1024x768) {
237 if (resinfo > 0x07)
238 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200239
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300240 if (resinfo == 0x04)
241 return 0; /* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530242 }
243 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200244
Aaro Koskinena39325d2012-11-04 21:14:53 +0200245 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800246 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200247 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800248 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530249 if (infoflag & tempax)
250 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530252 if ((*i) == 0)
253 break;
254 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530256 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200257 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800258 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200259 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530260 != tempbx) {
261 return 0;
262 }
263
264 if (infoflag & tempax)
265 return 1;
266 }
267 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200268}
269
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200270static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530271 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200272{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530273 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200274
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800275 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200276 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530277 sync &= 0xC0;
278 temp = 0x2F;
279 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200280 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200281}
282
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200283static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530284 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200285{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530286 unsigned char data, data1, pushax;
287 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200288
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800289 /* unlock cr0-7 */
290 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530291 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200292 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200293
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200294 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200295 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530297 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200298 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200299 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530300 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200301
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530302 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200303 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200304 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530305 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200306
Aaro Koskinen58839b02011-03-13 12:26:23 +0200307 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530308 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200309 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530310 data &= 0xE0;
311 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200312 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200313
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530314 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200315 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530316 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200317 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200318 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530319 data1 = data;
320 data1 &= 0xE0;
321 data &= 0x1F;
322 if (data == 0) {
323 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200324 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530325 0x0c);
326 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200327 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530328 data = pushax;
329 }
330 data = data - 1;
331 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200332 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200333 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530334 data = data >> 5;
335 data = data + 3;
336 if (data > 7)
337 data = data - 7;
338 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200339 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530340 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200341}
342
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800343static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
344 unsigned short ModeNo,
345 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200346{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530347 unsigned char data;
348 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200349
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530350 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200351 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200352 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530353 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200354
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530355 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200356 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200357 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530358 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200359
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530360 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200361 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200362 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530363 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200364
Aaro Koskinen58839b02011-03-13 12:26:23 +0200365 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530366 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200367 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530368 data &= 0x3F;
369 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200370 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200371
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200372 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530373 data &= 0x80;
374 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200375
Aaro Koskinenb3979922012-11-04 21:14:52 +0200376 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530377 i &= DoubleScanMode;
378 if (i)
379 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200380
Aaro Koskinen58839b02011-03-13 12:26:23 +0200381 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530382 j &= 0x5F;
383 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200384 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200385}
386
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200387static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
388 unsigned short RefreshRateTableIndex,
389 struct vb_device_info *pVBInfo,
390 struct xgi_hw_device_info *HwDeviceExtension)
391{
392 unsigned char index, data;
393 unsigned short i;
394
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800395 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200396 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200397 index = index & IndexMask;
398
Aaro Koskinen58839b02011-03-13 12:26:23 +0200399 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200400 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200401 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200402
403 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200404 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200405 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200406
407 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200408 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200409 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200410
411 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
412
413 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
414
415 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200416 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200417}
418
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200419/* --------------------------------------------------------------------- */
420/* Function : XGI_SetXG21CRTC */
421/* Input : Stand or enhance CRTC table */
422/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
423/* Description : Set LCD timing */
424/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200425static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530426 unsigned short RefreshRateTableIndex,
427 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200428{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300429 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530430 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200431
Aaro Koskinena39325d2012-11-04 21:14:53 +0200432 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300433 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200434 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300435 Tempcx = Tempax; /* Tempcx: HRS */
436 /* SR2E[7:0]->HRS */
437 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200438
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200439 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300440 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
441 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
442 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
443 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800444
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200445 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300446 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200447
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200448 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300449 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
450 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
451 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200452
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300453 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
454 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200455
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300456 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
457 if (Tempax < Tempcx) /* HRE < HRS */
458 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200459
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300460 Temp2 &= 0xFF;
461 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
462 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
463 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
464 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
465 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
466 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
467 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200468
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300469 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200470 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300471 Tempbx = Tempax; /* Tempbx: VRS */
472 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
473 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
474 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200475 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300476 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
477 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
478 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
479 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
480 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200481
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300482 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
483 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
484 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
485 Tempax &= 0x80;
486 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
487 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
488 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200489 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300490 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
491 Temp2 = Tempax;
492 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
493 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200494
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300495 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200496 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300497 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
498 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200499 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300500 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
501 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
502 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
503 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
504 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200505
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300506 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
507 if (Tempax < Temp3) /* VRE < VRS */
508 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200509
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300510 Temp2 &= 0xFF;
511 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
512 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
513 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
514 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
515 Tempbx = (unsigned char) Temp1;
516 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
517 Tempax &= 0x7F;
518 /* SR3F D[7:2]->VRE D[1:0]->VRS */
519 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200520}
521
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800522static void XGI_SetXG27CRTC(unsigned short ModeNo,
523 unsigned short ModeIdIndex,
524 unsigned short RefreshRateTableIndex,
525 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200526{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300527 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200528
Aaro Koskinena39325d2012-11-04 21:14:53 +0200529 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300530 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200531 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300532 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
533 /* SR2E[7:0]->HRS */
534 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200535
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300536 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200537 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300538 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
539 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200540
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200541 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300542 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
543 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200544
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200545 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300546 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
547 Tempax <<= 3; /* Tempax[5]: HRE[5] */
548 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200549
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300550 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
551 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200552
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300553 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200554 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300555 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
556 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
557 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200558
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200559 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300560 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
561 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
562 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
563 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
564 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
565 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200566
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300567 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200568 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300569 /* SR34[7:0]->VRS[7:0] */
570 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200571
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300572 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
573 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200574 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300575 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
576 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
577 Tempax >>= 2; /* Tempax[0]: VRS[8] */
578 /* SR35[0]: VRS[8] */
579 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
580 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
581 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
582 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200583 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300584 Tempax &= 0x08; /* SR0A[3] VRS[10] */
585 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200586
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300587 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200588 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300589 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
590 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200591 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300592 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
593 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
594 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
595 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
596 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
597 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200598
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300599 if (Tempbx <= Tempcx) /* VRE <= VRS */
600 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200601
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300602 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
603 Tempax = (Tempbx << 2) & 0xFF;
604 /* SR3F[7:2]:VRE[5:0] */
605 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
606 Tempax = Tempcx >> 8;
607 /* SR35[2:0]:VRS[10:8] */
608 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200609}
610
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200611static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
612{
613 unsigned char temp;
614
615 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
616 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
617 temp = (temp & 3) << 6;
618 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
619 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
620 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
621 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
622
623}
624
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300625static void xgifb_set_lcd(int chip_id,
626 struct vb_device_info *pVBInfo,
627 unsigned short RefreshRateTableIndex,
628 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200629{
Peter Huewee2e544c2013-02-03 04:08:46 +0100630 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200631
Aaro Koskinen8104e322011-03-13 12:26:22 +0200632 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
633 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
634 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
635 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300636
637 if (chip_id == XG27) {
Peter Huewee2e544c2013-02-03 04:08:46 +0100638 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
639 if ((temp & 0x03) == 0) { /* dual 12 */
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300640 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
641 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
642 }
643 }
644
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300645 if (chip_id == XG27) {
646 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530647 } else {
Peter Huewee2e544c2013-02-03 04:08:46 +0100648 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
649 if (temp & 0x01) {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300650 /* 18 bits FP */
651 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
652 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
653 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530654 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200655
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200656 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200657
Aaro Koskinendc505562011-03-13 12:26:26 +0200658 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
659 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200660
Peter Huewee2e544c2013-02-03 04:08:46 +0100661 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
662 if (temp & 0x4000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300663 /* Hsync polarity */
664 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Peter Huewee2e544c2013-02-03 04:08:46 +0100665 if (temp & 0x8000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300666 /* Vsync polarity */
667 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200668}
669
670/* --------------------------------------------------------------------- */
671/* Function : XGI_UpdateXG21CRTC */
672/* Input : */
673/* Output : CRT1 CRTC */
674/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
675/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800676static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
677 struct vb_device_info *pVBInfo,
678 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200679{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300680 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200681
Aaro Koskinendc505562011-03-13 12:26:26 +0200682 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300683 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200684 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300685 RES640x480x60))
686 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200687 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800688 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300689 index = 13;
690 else if (ModeNo == 0x2F)
691 index = 14;
692 else if (ModeNo == 0x50)
693 index = 15;
694 else if (ModeNo == 0x59)
695 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200696
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530697 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200698 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200699 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200700 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200701 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200702 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200703 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200704 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200705 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530706 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200707}
708
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200709static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530710 unsigned short ModeNo, unsigned short ModeIdIndex,
711 unsigned short RefreshRateTableIndex,
712 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200713{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400714 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200715
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530716 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200717
Aaro Koskinenb3979922012-11-04 21:14:52 +0200718 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200719
Aaro Koskinenb3979922012-11-04 21:14:52 +0200720 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinene8e6c752012-11-04 21:15:00 +0200721 tempax = XGI330_ModeResInfo[resindex].HTotal;
722 tempbx = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200723
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530724 if (modeflag & HalfDCLK)
725 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200726
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300727 if (modeflag & HalfDCLK)
728 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200729
Aaro Koskinena39325d2012-11-04 21:14:53 +0200730 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200731
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300732 if (temp & InterlaceMode)
733 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200734
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300735 if (modeflag & DoubleScanMode)
736 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200737
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530738 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200739
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530740 tempax /= tempcx;
741 tempax -= 1;
742 tempbx -= 1;
743 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200744 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
745 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530746 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200747 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
748 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200749 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530750 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200751 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530752 tempax = 0;
753 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200754
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530755 if (tempbx & 0x01)
756 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200757
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530758 if (tempbx & 0x02)
759 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200760
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200761 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200762 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530763 data &= 0xFF;
764 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200765
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530766 if (tempbx & 0x04)
767 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200768
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200769 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200770 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200771}
772
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800773static void XGI_SetCRT1Offset(unsigned short ModeNo,
774 unsigned short ModeIdIndex,
775 unsigned short RefreshRateTableIndex,
776 struct xgi_hw_device_info *HwDeviceExtension,
777 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200778{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530779 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200780
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530781 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200782 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530783 temp = temp >> 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200784 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200785
Aaro Koskinena39325d2012-11-04 21:14:53 +0200786 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530787 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200788
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530789 if (temp2)
790 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200791
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530792 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200793
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530794 switch (temp2) {
795 case 0:
796 temp2 = 1;
797 break;
798 case 1:
799 temp2 = 2;
800 break;
801 case 2:
802 temp2 = 4;
803 break;
804 case 3:
805 temp2 = 4;
806 break;
807 case 4:
808 temp2 = 6;
809 break;
810 case 5:
811 temp2 = 8;
812 break;
813 default:
814 break;
815 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530817 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
818 temp = temp * temp2 + temp2 / 2;
819 else
820 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530822 /* SetOffset */
823 DisplayUnit = temp;
824 temp2 = temp;
825 temp = temp >> 8; /* ah */
826 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200827 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530828 i &= 0xF0;
829 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200830 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200831
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530832 temp = (unsigned char) temp2;
833 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200834 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530836 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200837 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530838 temp2 &= InterlaceMode;
839 if (temp2)
840 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200841
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530842 DisplayUnit = DisplayUnit << 5;
843 ah = (DisplayUnit & 0xff00) >> 8;
844 al = DisplayUnit & 0x00ff;
845 if (al == 0)
846 ah += 1;
847 else
848 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200849
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530850 if (HwDeviceExtension->jChipType >= XG20)
851 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
852 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200853
Aaro Koskinen8104e322011-03-13 12:26:22 +0200854 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200855}
856
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200857static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
858 unsigned short ModeIdIndex,
859 unsigned short RefreshRateTableIndex,
860 struct xgi_hw_device_info *HwDeviceExtension,
861 struct vb_device_info *pVBInfo)
862{
Peter Hueweef9a6b92013-02-03 04:08:43 +0100863 unsigned short VCLKIndex, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200864
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300865 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200866 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200867
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200868 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
869 if (pVBInfo->LCDResInfo != Panel_1024x768)
870 /* LCDXlat2VCLK */
871 VCLKIndex = VCLK108_2_315 + 5;
872 else
873 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
874 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
875 if (pVBInfo->SetFlag & RPLLDIV2XO)
876 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
877 else
878 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200879
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200880 if (pVBInfo->SetFlag & TVSimuMode) {
881 if (modeflag & Charx8Dot) {
882 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
883 } else {
884 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200885 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200886 }
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200887
888 /* 301lv */
889 if (pVBInfo->VBType & VB_SIS301LV) {
890 if (pVBInfo->SetFlag & RPLLDIV2XO)
891 VCLKIndex = YPbPr525iVCLK_2;
892 else
893 VCLKIndex = YPbPr525iVCLK;
894 }
895 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
896 if (pVBInfo->SetFlag & RPLLDIV2XO)
897 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
898 else
899 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
900 } else { /* for CRT2 */
901 /* di+Ext_CRTVCLK */
902 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
903 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200904 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200905
906 return VCLKIndex;
907}
908
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800909static void XGI_SetCRT1VCLK(unsigned short ModeNo,
910 unsigned short ModeIdIndex,
911 struct xgi_hw_device_info *HwDeviceExtension,
912 unsigned short RefreshRateTableIndex,
913 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200914{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400915 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530916 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200917
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530918 if (pVBInfo->IF_DEF_LVDS == 1) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200919 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200920 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200921 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200922 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
923 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200924 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +0100925 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
926 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +0100927 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530928 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
929 RefreshRateTableIndex, HwDeviceExtension,
930 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200931 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200932 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200933 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200934 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200935 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200936 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
937 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530938 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200939 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200940 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200941 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200942 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
943 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200944 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530945 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200946
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530947 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200948 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800949 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200950 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200951 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200952 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530953 index = data;
954 index &= 0xE0;
955 data &= 0x1F;
956 data = data << 1;
957 data += 1;
958 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200959 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530960 }
961 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200962}
963
Aaro Koskinene85f2032011-11-27 23:03:07 +0200964static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
965{
966 unsigned char temp;
967
968 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
969 temp = (temp & 1) << 6;
970 /* SR06[6] 18bit Dither */
971 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
972 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
973 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
974
975}
976
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200977static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530978 struct xgi_hw_device_info *HwDeviceExtension,
979 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200980{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530981 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200982
Aaro Koskinen58839b02011-03-13 12:26:23 +0200983 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530984 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200985 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200986
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300987 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
988 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
989 data &= 0xC0;
990 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
991 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
992 data |= 0x01;
993 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530995 if (HwDeviceExtension->jChipType == XG21)
996 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200997}
998
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200999static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1000 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1001 struct vb_device_info *pVBInfo)
1002{
1003 unsigned short data, data2 = 0;
1004 short VCLK;
1005
1006 unsigned char index;
1007
Aaro Koskinena39325d2012-11-04 21:14:53 +02001008 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001009 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +02001010 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001011
Aaro Koskinen58839b02011-03-13 12:26:23 +02001012 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001013 data &= 0xf3;
1014 if (VCLK >= 200)
1015 data |= 0x0c; /* VCLK > 200 */
1016
1017 if (HwDeviceExtension->jChipType >= XG20)
1018 data &= ~0x04; /* 2 pixel mode */
1019
Aaro Koskinen8104e322011-03-13 12:26:22 +02001020 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001021
1022 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001023 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001024 data &= 0xE7;
1025 if (VCLK < 200)
1026 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001027 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001028 }
1029
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001030 data2 = 0x00;
1031
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001032 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001033 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001034 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001035
1036}
1037
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001038static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301039 unsigned short ModeNo, unsigned short ModeIdIndex,
1040 unsigned short RefreshRateTableIndex,
1041 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001042{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301043 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1044 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001045
Aaro Koskinenb3979922012-11-04 21:14:52 +02001046 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001047 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001048
Aaro Koskinen58839b02011-03-13 12:26:23 +02001049 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001050 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001051
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001052 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301053 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001054 data2 |= 0x02;
1055 data3 = pVBInfo->ModeType - ModeVGA;
1056 data3 = data3 << 2;
1057 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301058 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001059
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301060 if (data)
1061 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001062
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001063 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001064 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001065 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001066
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301067 data = 0x0000;
1068 if (infoflag & InterlaceMode) {
1069 if (xres == 1024)
1070 data = 0x0035;
1071 else if (xres == 1280)
1072 data = 0x0048;
1073 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001074
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001075 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1076 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301078 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001079 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001080
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301081 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001082
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301083 if (modeflag & LineCompareOff)
1084 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001085
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001086 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301087 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001088 data = data ^ 0x60;
1089 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001090 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301092 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1093 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001094
Aaro Koskinen58839b02011-03-13 12:26:23 +02001095 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001096
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301097 if (HwDeviceExtension->jChipType == XG27) {
1098 if (data & 0x40)
1099 data = 0x2c;
1100 else
1101 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001102 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001103 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301104 } else if (HwDeviceExtension->jChipType >= XG20) {
1105 if (data & 0x40)
1106 data = 0x33;
1107 else
1108 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001109 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1110 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301111 } else {
1112 if (data & 0x40)
1113 data = 0x2c;
1114 else
1115 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001116 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301117 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001118
1119}
1120
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001121static void XGI_WriteDAC(unsigned short dl,
1122 unsigned short ah,
1123 unsigned short al,
1124 unsigned short dh,
1125 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001126{
1127 unsigned short temp, bh, bl;
1128
1129 bh = ah;
1130 bl = al;
1131
1132 if (dl != 0) {
1133 temp = bh;
1134 bh = dh;
1135 dh = temp;
1136 if (dl == 1) {
1137 temp = bl;
1138 bl = dh;
1139 dh = temp;
1140 } else {
1141 temp = bl;
1142 bl = bh;
1143 bh = temp;
1144 }
1145 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001146 outb((unsigned short) dh, pVBInfo->P3c9);
1147 outb((unsigned short) bh, pVBInfo->P3c9);
1148 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001149}
1150
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001151static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301152 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001153{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001154 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1155 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001156
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001157 outb(0xFF, pVBInfo->P3c6);
1158 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001159
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001160 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301161 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301163 for (k = 0; k < 3; k++) {
1164 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001165
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301166 if (data & 0x01)
1167 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301169 if (data & 0x02)
1170 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001171
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001172 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301173 data = data >> 2;
1174 }
1175 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001176
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001177 for (i = 16; i < 32; i++) {
1178 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001179
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001180 for (k = 0; k < 3; k++)
1181 outb(data, pVBInfo->P3c9);
1182 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001183
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001184 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001185
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001186 for (m = 0; m < 9; m++) {
1187 di = si;
1188 bx = si + 0x04;
1189 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001190
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001191 for (n = 0; n < 3; n++) {
1192 for (o = 0; o < 5; o++) {
1193 dh = table[si];
1194 ah = table[di];
1195 al = table[bx];
1196 si++;
1197 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301198 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001199
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001200 si -= 2;
1201
1202 for (o = 0; o < 3; o++) {
1203 dh = table[bx];
1204 ah = table[di];
1205 al = table[si];
1206 si--;
1207 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1208 }
1209
1210 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301211 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001212
1213 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301214 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001215}
1216
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001217static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1218 unsigned short ModeIdIndex,
1219 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001220{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301221 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001222
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001223 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001224 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001225
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001226 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001227 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001228
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001229 xres = XGI330_ModeResInfo[resindex].HTotal;
1230 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001231
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001232 if (modeflag & HalfDCLK)
1233 xres = xres << 1;
1234
1235 if (modeflag & DoubleScanMode)
1236 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301238 if (xres == 720)
1239 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001240
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301241 pVBInfo->VGAHDE = xres;
1242 pVBInfo->HDE = xres;
1243 pVBInfo->VGAVDE = yres;
1244 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001245}
1246
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001247static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001248 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001249 unsigned short ModeIdIndex,
1250 unsigned short RefreshRateTableIndex,
1251 struct vb_device_info *pVBInfo)
1252{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001253 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001254
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001255 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001256
Aaro Koskinenb3979922012-11-04 21:14:52 +02001257 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001258
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001259 i = 0;
1260
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001261 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001262 tempdx = pVBInfo->LCDResInfo;
1263 if (tempbx & 0x0080) { /* OEMUtil */
1264 tempbx &= (~0x0080);
1265 tempdx = pVBInfo->LCDTypeInfo;
1266 }
1267
1268 if (pVBInfo->LCDInfo & EnableScalingLCD)
1269 tempdx &= (~PanelResInfo);
1270
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001271 if (table[i].PANELID == tempdx) {
1272 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001273 tempdx = pVBInfo->LCDInfo;
1274
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001275 if (modeflag & HalfDCLK)
1276 tempdx |= SetLCDLowResolution;
1277
1278 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001279 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001280 break;
1281 }
1282 i++;
1283 }
1284
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001285 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001286}
1287
Aaro Koskinen24572542012-09-11 00:15:21 +03001288static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001289 unsigned short ModeIdIndex,
1290 unsigned short RefreshRateTableIndex,
1291 struct vb_device_info *pVBInfo)
1292{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001293 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001294
Aaro Koskinenb3979922012-11-04 21:14:52 +02001295 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001296 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001297 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001298 tempdx = pVBInfo->TVInfo;
1299
1300 if (pVBInfo->VBInfo & SetInSlaveMode)
1301 tempdx = tempdx | SetTVLockMode;
1302
1303 if (modeflag & HalfDCLK)
1304 tempdx = tempdx | SetTVLowResolution;
1305
1306 i = 0;
1307
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001308 while (XGI_TVDataTable[i].MASK != 0xffff) {
1309 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1310 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001311 break;
1312 i++;
1313 }
1314
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001315 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001316}
1317
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001318static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301319 unsigned short RefreshRateTableIndex,
1320 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001321{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001322 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001323
Aaro Koskinen6008f872012-11-04 21:14:49 +02001324 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1325 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001326
Aaro Koskinen6008f872012-11-04 21:14:49 +02001327 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1328 RefreshRateTableIndex, pVBInfo);
1329 pVBInfo->VGAHT = LCDPtr->VGAHT;
1330 pVBInfo->VGAVT = LCDPtr->VGAVT;
1331 pVBInfo->HT = LCDPtr->LCDHT;
1332 pVBInfo->VT = LCDPtr->LCDVT;
1333
1334 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1335 return;
1336
1337 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1338 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1339 pVBInfo->HDE = 1024;
1340 pVBInfo->VDE = 768;
1341 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1342 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1343 pVBInfo->HDE = 1280;
1344 pVBInfo->VDE = 1024;
1345 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1346 pVBInfo->HDE = 1400;
1347 pVBInfo->VDE = 1050;
1348 } else {
1349 pVBInfo->HDE = 1600;
1350 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301351 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001352}
1353
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001354static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301355 unsigned short RefreshRateTableIndex,
1356 struct xgi_hw_device_info *HwDeviceExtension,
1357 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001358{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001359 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001360 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1361 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001362
Peter Huewea3d675c2012-02-09 21:11:47 +01001363 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001364 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001365 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001366
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001367 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001368 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301369 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001370
1371 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1372
Peter Huewea3d675c2012-02-09 21:11:47 +01001373 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001374 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1375 ModeIdIndex, RefreshRateTableIndex,
1376 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001377 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001378 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001379 }
1380
1381 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001382}
1383
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001384static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1385{
1386 unsigned char tempal, tempah, tempbl, i;
1387
Aaro Koskinen58839b02011-03-13 12:26:23 +02001388 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001389 tempal = tempah & 0x0F;
1390 tempah = tempah & 0xF0;
1391 i = 0;
1392 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1393
1394 while (tempbl != 0xFF) {
1395 if (tempbl & 0x80) { /* OEMUtil */
1396 tempal = tempah;
1397 tempbl = tempbl & ~(0x80);
1398 }
1399
1400 if (tempal == tempbl)
1401 break;
1402
1403 i++;
1404
1405 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1406 }
1407
1408 return i;
1409}
1410
1411static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1412{
1413 unsigned short tempah, tempal, tempbl, i;
1414
1415 tempal = pVBInfo->LCDResInfo;
1416 tempah = pVBInfo->LCDTypeInfo;
1417
1418 i = 0;
1419 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1420
1421 while (tempbl != 0xFF) {
1422 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1423 tempal = tempah;
1424 tempbl &= ~0x80;
1425 }
1426
1427 if (tempal == tempbl)
1428 break;
1429
1430 i++;
1431 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1432 }
1433
1434 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001435 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001436 pVBInfo->LCDTypeInfo = 0;
1437 i = 0;
1438 }
1439
1440 return i;
1441}
1442
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001443static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1444 unsigned short *VSyncWidth,
1445 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001446{
1447 unsigned short Index;
1448
1449 Index = XGI_GetLCDCapPtr(pVBInfo);
1450 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1451 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1452
1453 return;
1454}
1455
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001456static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301457 unsigned short RefreshRateTableIndex,
1458 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001459{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301460 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1461 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001462 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001463
Aaro Koskinenb3979922012-11-04 21:14:52 +02001464 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe826215d2013-02-05 00:29:46 +01001465 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo, ModeIdIndex,
1466 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001467
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001468 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1469 push1 = tempbx;
1470 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001471
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001472 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001473 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1474 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001475 tempax = 1024;
1476 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001477 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1478 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001479 tempax = 1280;
1480 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001481 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001482 tempax = 1400;
1483 tempbx = 1050;
1484 } else {
1485 tempax = 1600;
1486 tempbx = 1200;
1487 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001488
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001489 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1490 pVBInfo->HDE = tempax;
1491 pVBInfo->VDE = tempbx;
1492 pVBInfo->VGAHDE = tempax;
1493 pVBInfo->VGAVDE = tempbx;
1494 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001495
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001496 tempax = pVBInfo->HT;
1497
Peter Huewe826215d2013-02-05 00:29:46 +01001498 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001499
1500 tempcx = pVBInfo->HDE;
1501 tempbx = tempbx & 0x0fff;
1502 tempcx += tempbx;
1503
1504 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001505 tempcx -= tempax;
1506
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001507 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001508
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001509 tempcx = tempcx >> 3;
1510 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001511
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001512 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1513 (unsigned short) (tempbx & 0xff));
1514 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1515 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001516
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001517 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001518
Peter Huewe826215d2013-02-05 00:29:46 +01001519 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001520
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001521 tempcx = push2;
1522
1523 if (pVBInfo->LCDInfo & EnableScalingLCD)
1524 tempcx = LCDPtr1->LCDHSync;
1525
1526 tempcx += tempbx;
1527
1528 if (tempcx >= tempax)
1529 tempcx -= tempax;
1530
1531 tempax = tempbx & 0x07;
1532 tempax = tempax >> 5;
1533 tempcx = tempcx >> 3;
1534 tempbx = tempbx >> 3;
1535
1536 tempcx &= 0x1f;
1537 tempax |= tempcx;
1538
1539 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1540 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1541 (unsigned short) (tempbx & 0xff));
1542
1543 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001544 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001545 tempcx = pVBInfo->VDE;
1546
1547 tempbx = tempbx & 0x0fff;
1548 tempcx += tempbx;
1549 if (tempcx >= tempax)
1550 tempcx -= tempax;
1551
1552 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1553 (unsigned short) (tempbx & 0xff));
1554 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1555 (unsigned short) (tempcx & 0xff));
1556
1557 tempbx = (tempbx >> 8) & 0x07;
1558 tempcx = (tempcx >> 8) & 0x07;
1559
1560 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1561 (unsigned short) ((tempcx << 3)
1562 | tempbx));
1563
1564 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001565 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001566
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001567 tempcx = push1;
1568
1569 if (pVBInfo->LCDInfo & EnableScalingLCD)
1570 tempcx = LCDPtr1->LCDVSync;
1571
1572 tempcx += tempbx;
1573 if (tempcx >= tempax)
1574 tempcx -= tempax;
1575
1576 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1577 (unsigned short) (tempbx & 0xff));
1578 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1579 (unsigned short) (tempcx & 0x0f));
1580
1581 tempax = ((tempbx >> 8) & 0x07) << 3;
1582
1583 tempbx = pVBInfo->VGAVDE;
1584 if (tempbx != pVBInfo->VDE)
1585 tempax |= 0x40;
1586
Peter Huewea3d675c2012-02-09 21:11:47 +01001587 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001588 tempax |= 0x40;
1589
1590 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1591 tempax);
1592
1593 tempcx = pVBInfo->VGAVT;
1594 tempbx = pVBInfo->VDE;
1595 tempax = pVBInfo->VGAVDE;
1596 tempcx -= tempax;
1597
1598 temp = tempax; /* 0430 ylshieh */
1599 temp1 = (temp << 18) / tempbx;
1600
1601 tempdx = (unsigned short) ((temp << 18) % tempbx);
1602
1603 if (tempdx != 0)
1604 temp1 += 1;
1605
1606 temp2 = temp1;
1607 push3 = temp2;
1608
1609 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1610 (unsigned short) (temp2 & 0xff));
1611 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1612 (unsigned short) ((temp2 >> 8) & 0xff));
1613
1614 tempbx = (unsigned short) (temp2 >> 16);
1615 tempax = tempbx & 0x03;
1616
1617 tempbx = pVBInfo->VGAVDE;
1618 if (tempbx == pVBInfo->VDE)
1619 tempax |= 0x04;
1620
1621 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1622
1623 if (pVBInfo->VBType & VB_XGI301C) {
1624 temp2 = push3;
1625 xgifb_reg_set(pVBInfo->Part4Port,
1626 0x3c,
1627 (unsigned short) (temp2 & 0xff));
1628 xgifb_reg_set(pVBInfo->Part4Port,
1629 0x3b,
1630 (unsigned short) ((temp2 >> 8) &
1631 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001632 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001633 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1634 ~0xc0,
1635 (unsigned short) ((tempbx &
1636 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001637
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001638 tempcx = pVBInfo->VGAVDE;
1639 if (tempcx == pVBInfo->VDE)
1640 xgifb_reg_and_or(pVBInfo->Part4Port,
1641 0x30, ~0x0c, 0x00);
1642 else
1643 xgifb_reg_and_or(pVBInfo->Part4Port,
1644 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301645 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001646
1647 tempcx = pVBInfo->VGAHDE;
1648 tempbx = pVBInfo->HDE;
1649
1650 temp1 = tempcx << 16;
1651
1652 tempax = (unsigned short) (temp1 / tempbx);
1653
1654 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1655 tempax = 65535;
1656
1657 temp3 = tempax;
1658 temp1 = pVBInfo->VGAHDE << 16;
1659
1660 temp1 /= temp3;
1661 temp3 = temp3 << 16;
1662 temp1 -= 1;
1663
1664 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1665
1666 tempax = (unsigned short) (temp3 & 0xff);
1667 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1668
1669 temp1 = pVBInfo->VGAVDE << 18;
1670 temp1 = temp1 / push3;
1671 tempbx = (unsigned short) (temp1 & 0xffff);
1672
Peter Huewe255aabd2012-02-09 21:11:44 +01001673 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001674 tempbx -= 1;
1675
1676 tempax = ((tempbx >> 8) & 0xff) << 3;
1677 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1678 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1679 (unsigned short) (tempax & 0xff));
1680 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1681 (unsigned short) (tempbx & 0xff));
1682
1683 temp3 = temp3 >> 16;
1684
1685 if (modeflag & HalfDCLK)
1686 temp3 = temp3 >> 1;
1687
1688 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1689 (unsigned short) ((temp3 >> 8) & 0xff));
1690 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1691 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001692}
1693
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001694/* --------------------------------------------------------------------- */
1695/* Function : XGI_GETLCDVCLKPtr */
1696/* Input : */
1697/* Output : al -> VCLK Index */
1698/* Description : */
1699/* --------------------------------------------------------------------- */
1700static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1701 struct vb_device_info *pVBInfo)
1702{
1703 unsigned short index;
1704
Peter Huewea3d675c2012-02-09 21:11:47 +01001705 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001706 index = XGI_GetLCDCapPtr1(pVBInfo);
1707
1708 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1709 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1710 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1711 } else { /* LCDA */
1712 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1713 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1714 }
1715 }
1716 return;
1717}
1718
1719static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1720 unsigned short ModeNo, unsigned short ModeIdIndex,
1721 struct vb_device_info *pVBInfo)
1722{
1723
1724 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001725 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001726
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001727 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001728 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001729
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001730 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1731 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001732 index = XGI_GetLCDCapPtr(pVBInfo);
1733 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1734
Peter Huewea3d675c2012-02-09 21:11:47 +01001735 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001736 return tempal;
1737
1738 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001739 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001740 (VB_SIS301B |
1741 VB_SIS302B |
1742 VB_SIS301LV |
1743 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001744 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001745 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001746 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001747 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001748 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001749 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001750 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001751 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001752 tempal = TVCLKBASE_315 +
1753 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001754
1755 }
1756 return tempal;
1757 }
1758
Peter Huewe599801f2012-02-09 21:11:45 +01001759 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001760 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001761 return tempal;
1762 }
1763
Peter Huewe599801f2012-02-09 21:11:45 +01001764 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001765 tempal = YPbPr525pVCLK;
1766 return tempal;
1767 }
1768
1769 tempal = NTSC1024VCLK;
1770
1771 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001772 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001773 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001774 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001775 }
1776
1777 if (pVBInfo->VBInfo & SetCRT2ToTV)
1778 return tempal;
1779 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001780 } /* {End of VB} */
1781
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001782 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001783 tempal = tempal >> 2;
1784 tempal &= 0x03;
1785
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001786 /* for Dot8 Scaling LCD */
1787 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001788 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
1789
Aaro Koskinena39325d2012-11-04 21:14:53 +02001790 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001791 return tempal;
1792}
1793
1794static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1795 unsigned char *di_1, struct vb_device_info *pVBInfo)
1796{
Peter Huewe6896b942012-02-09 21:11:46 +01001797 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1798 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001799 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1800 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001801 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001802 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001803 }
1804 } else {
1805 *di_0 = XGI_VCLKData[tempal].SR2B;
1806 *di_1 = XGI_VCLKData[tempal].SR2C;
1807 }
1808}
1809
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001810static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301811 unsigned short RefreshRateTableIndex,
1812 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001813{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301814 unsigned char di_0, di_1, tempal;
1815 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301817 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1818 pVBInfo);
1819 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1820 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301822 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001823 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301824 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001825 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301826 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001827 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1828 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301829 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001830 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1831 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301832 }
1833 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001834}
1835
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001836static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301837 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001838{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301839 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001840
Peter Huewe6896b942012-02-09 21:11:46 +01001841 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1842 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301843 tempcl = 0;
1844 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001845 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301847 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001848 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301849 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001850 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301851 if (!(temp & 0x40))
1852 tempcl |= ActiveCRT1;
1853 }
1854 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001855
Aaro Koskinen58839b02011-03-13 12:26:23 +02001856 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301857 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001858
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301859 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001860 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001861 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301862 if (tempax & 0x04)
1863 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001864
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301865 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301867 if (!(tempcl & ActiveLCD))
1868 if (temp == 0x01)
1869 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001870
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301871 if (temp == 0x04)
1872 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001873
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301874 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001875 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001876
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301877 if (!(temp & 0x08))
1878 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001879
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301880 if (!(temp & 0x04))
1881 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001882
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301883 if (temp & 0x02)
1884 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001885
Peter Huewe599801f2012-02-09 21:11:45 +01001886 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301887 if (temp & 0x01)
1888 tempch |= ActiveHiTV;
1889 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001890
Peter Huewe599801f2012-02-09 21:11:45 +01001891 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001892 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301893 pVBInfo->Part2Port,
1894 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001895
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301896 if (temp & 0x10)
1897 tempch |= ActiveYPbPr;
1898 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001899
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301900 if (tempch != 0)
1901 tempcl |= ActiveTV;
1902 }
1903 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001904
Aaro Koskinen58839b02011-03-13 12:26:23 +02001905 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301906 if (tempcl & ActiveLCD) {
1907 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1908 if (temp & ActiveTV)
1909 tempcl |= ActiveTV;
1910 }
1911 }
1912 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001913 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001914 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301916 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001917 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301918 } else {
1919 return;
1920 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001921}
1922
Bill Pemberton80adad82010-06-17 13:10:51 -04001923void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001924{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301925 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001926
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001927 if (pVBInfo->IF_DEF_LVDS != 0)
1928 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001929
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001930 tempbx = VB_SIS302B;
1931 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1932 if (flag == 0x02)
1933 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001934
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001935 tempbx = VB_SIS301;
1936 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1937 if (flag < 0xB0)
1938 goto finish;
1939
1940 tempbx = VB_SIS301B;
1941 if (flag < 0xC0)
1942 goto bigger_than_0xB0;
1943
1944 tempbx = VB_XGI301C;
1945 if (flag < 0xD0)
1946 goto bigger_than_0xB0;
1947
1948 tempbx = VB_SIS301LV;
1949 if (flag < 0xE0)
1950 goto bigger_than_0xB0;
1951
1952 tempbx = VB_SIS302LV;
1953 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1954 if (tempah != 0xFF)
1955 tempbx = VB_XGI301C;
1956
1957bigger_than_0xB0:
1958 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1959 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1960 if (!(flag & 0x02))
1961 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301962 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001963
1964finish:
1965 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001966}
1967
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02001968static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301969 struct xgi_hw_device_info *HwDeviceExtension,
1970 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001971{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301972 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001973
Aaro Koskinenb3979922012-11-04 21:14:52 +02001974 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301975 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001976 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301977 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001978
Miguel Gómezf9317352012-07-06 12:40:48 +02001979 if (!(pVBInfo->VBType & 0xFFFF))
1980 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001981
Miguel Gómezf9317352012-07-06 12:40:48 +02001982 /* Check Display Device */
1983 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1984 tempbx = tempbx | temp;
1985 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1986 push = temp;
1987 push = push << 8;
1988 tempax = temp << 8;
1989 tempbx = tempbx | tempax;
1990 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1991 | SetInSlaveMode | DisableCRT2Display);
1992 temp = 0xFFFF ^ temp;
1993 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001994
Miguel Gómezf9317352012-07-06 12:40:48 +02001995 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001996
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001997 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1998 VB_XGI301C)) {
1999 if (temp & EnableDualEdge) {
2000 tempbx |= SetCRT2ToDualEdge;
2001 if (temp & SetToLCDA)
2002 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02002003 }
2004 }
2005
2006 if (pVBInfo->IF_DEF_YPbPr == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002007 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
Miguel Gómezf9317352012-07-06 12:40:48 +02002008 if (temp & SetYPbPr) {
2009 if (pVBInfo->IF_DEF_HiVision == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002010 /* shampoo add for new scratch */
2011 temp = xgifb_reg_get(pVBInfo->P3d4,
2012 0x35);
Miguel Gómezf9317352012-07-06 12:40:48 +02002013 temp &= YPbPrMode;
2014 tempbx |= SetCRT2ToHiVision;
2015
2016 if (temp != YPbPrMode1080i) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002017 tempbx &= (~SetCRT2ToHiVision);
2018 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302019 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302020 }
2021 }
2022 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002023 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002024
Miguel Gómezf9317352012-07-06 12:40:48 +02002025 tempax = push; /* restore CR31 */
2026
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002027 if (pVBInfo->IF_DEF_YPbPr == 1) {
2028 if (pVBInfo->IF_DEF_HiVision == 1)
2029 temp = 0x09FC;
2030 else
2031 temp = 0x097C;
2032 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2033 temp = 0x01FC;
2034 } else {
2035 temp = 0x017C;
Miguel Gómezf9317352012-07-06 12:40:48 +02002036 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002037
Miguel Gómezf9317352012-07-06 12:40:48 +02002038 if (!(tempbx & temp)) {
2039 tempax |= DisableCRT2Display;
2040 tempbx = 0;
2041 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002042
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002043 if (!(pVBInfo->VBType & VB_NoLCD)) {
2044 if (tempbx & XGI_SetCRT2ToLCDA) {
2045 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002046 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002047 SwitchCRT2));
2048 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002049 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
2050 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002051 }
2052 }
2053
2054 /* shampoo add */
2055 /* for driver abnormal */
2056 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2057 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2058 if (tempbx & SetCRT2ToRAMDAC) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002059 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
2060 SwitchCRT2 | SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002061 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302062 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002063 } else {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002064 tempbx &= (~(SetCRT2ToRAMDAC | SetCRT2ToLCD |
Miguel Gómezf9317352012-07-06 12:40:48 +02002065 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302066 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002067 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002068
Miguel Gómezf9317352012-07-06 12:40:48 +02002069 if (!(pVBInfo->VBType & VB_NoLCD)) {
2070 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002071 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002072 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002073 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302074 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002075 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002076
Miguel Gómezf9317352012-07-06 12:40:48 +02002077 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002078 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002079 SetSimuScanMode);
2080 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2081 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002082
Miguel Gómezf9317352012-07-06 12:40:48 +02002083 if (pVBInfo->IF_DEF_YPbPr == 1) {
2084 if (tempbx & SetCRT2ToYPbPr525750)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002085 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002086 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002087
Miguel Gómezf9317352012-07-06 12:40:48 +02002088 if (pVBInfo->IF_DEF_HiVision == 1) {
2089 if (tempbx & SetCRT2ToHiVision)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002090 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002091 SetSimuScanMode);
2092 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002093
Miguel Gómezf9317352012-07-06 12:40:48 +02002094 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2095 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2096 tempbx = DisableCRT2Display;
2097 }
2098
2099 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002100 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002101 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002102 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002103 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002104
Miguel Gómezf9317352012-07-06 12:40:48 +02002105 /* LCD+TV can't support in slave mode
2106 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002107 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2108 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002109 SetCRT2ToDualEdge);
2110 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302111 }
2112 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302114 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002115}
2116
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002117static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302118 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002119{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002120 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302122 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002123 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2124 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002125
Peter Huewe5fc699f2013-02-03 04:08:45 +01002126 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2127 if (tempbx & TVSetPAL) {
2128 tempbx &= (SetCHTVOverScan |
2129 TVSetPALM |
2130 TVSetPALN |
2131 TVSetPAL);
2132 if (tempbx & TVSetPALM)
2133 /* set to NTSC if PAL-M */
2134 tempbx &= ~TVSetPAL;
2135 } else
2136 tempbx &= (SetCHTVOverScan |
2137 TVSetNTSCJ |
2138 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002139
Aaro Koskinena8b35292013-02-09 00:03:45 +02002140 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2141 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002142
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302143 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002144 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002145 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302146 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002147
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302148 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002149 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302151 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002152 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302153 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002154 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302155 }
2156 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302158 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002159 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2160 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302161 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002162
Aaro Koskinena8b35292013-02-09 00:03:45 +02002163 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2164 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2165 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002166
Aaro Koskinena8b35292013-02-09 00:03:45 +02002167 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2168 /* NTSC 1024x768, */
2169 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002170
Aaro Koskinena8b35292013-02-09 00:03:45 +02002171 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002172
Aaro Koskinena8b35292013-02-09 00:03:45 +02002173 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2174 if (pVBInfo->VBInfo & SetInSlaveMode)
2175 tempbx &= (~RPLLDIV2XO);
2176 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2177 tempbx &= (~RPLLDIV2XO);
2178 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2179 VB_SIS301LV | VB_SIS302LV |
2180 VB_XGI301C))) {
2181 if (tempbx & TVSimuMode)
2182 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302183 }
2184 }
2185 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002186}
2187
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002188static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2189 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002190{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002191 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302193 pVBInfo->LCDResInfo = 0;
2194 pVBInfo->LCDTypeInfo = 0;
2195 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002196
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002197 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002198 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002199 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302200 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302202 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002203 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002204
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002205 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002206 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302207 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002208 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002209 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302210 tempax &= 0x0F;
2211 else
2212 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002213
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302214 if ((resinfo == 6) || (resinfo == 9)) {
2215 if (tempax >= 3)
2216 tempbx |= PanelRef75Hz;
2217 } else if ((resinfo == 7) || (resinfo == 8)) {
2218 if (tempax >= 4)
2219 tempbx |= PanelRef75Hz;
2220 }
2221 }
2222 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302224 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002225
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302226 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002227
Peter Huewea3d675c2012-02-09 21:11:47 +01002228 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302229 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002230
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302231 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002232
Aaro Koskinen58839b02011-03-13 12:26:23 +02002233 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002234
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302235 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302237 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302239 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002240
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302241 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002242
Aaro Koskinen718e7152013-02-09 00:03:46 +02002243 if (((pVBInfo->VBType & VB_SIS302LV) ||
2244 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2245 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002246
Aaro Koskinen718e7152013-02-09 00:03:46 +02002247 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2248 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2249 (!(tempbx & EnableScalingLCD)))
2250 /*
2251 * set to center in 1280x1024 LCDB
2252 * for Panel_1400x1050
2253 */
2254 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302256 if (pVBInfo->VBInfo & SetInSlaveMode) {
2257 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002258 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302259 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002260 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302261 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002262
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302263 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002264
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302265 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002266}
2267
Bill Pemberton108afbf2010-06-17 13:10:47 -04002268unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302269 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002270{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002271 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002272 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002273 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002274 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002275 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302276 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002277
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302278 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002279}
2280
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002281static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2282{
2283 unsigned char ujRet = 0;
2284 unsigned char i = 0;
2285
2286 for (i = 0; i < 8; i++) {
2287 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002288 ujRet |= (ujDate >> i) & 1;
2289 }
2290
2291 return ujRet;
2292}
2293
2294/*----------------------------------------------------------------------------*/
2295/* output */
2296/* bl[5] : LVDS signal */
2297/* bl[1] : LVDS backlight */
2298/* bl[0] : LVDS VDD */
2299/*----------------------------------------------------------------------------*/
2300static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2301{
2302 unsigned char CR4A, temp;
2303
Aaro Koskinen58839b02011-03-13 12:26:23 +02002304 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002305 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002306
Aaro Koskinen58839b02011-03-13 12:26:23 +02002307 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002308
2309 temp = XG21GPIODataTransfer(temp);
2310 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002311 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002312 return temp;
2313}
2314
2315/*----------------------------------------------------------------------------*/
2316/* output */
2317/* bl[5] : LVDS signal */
2318/* bl[1] : LVDS backlight */
2319/* bl[0] : LVDS VDD */
2320/*----------------------------------------------------------------------------*/
2321static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2322{
2323 unsigned char CR4A, CRB4, temp;
2324
Aaro Koskinen58839b02011-03-13 12:26:23 +02002325 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002326 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002327
Aaro Koskinen58839b02011-03-13 12:26:23 +02002328 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002329
2330 temp &= 0x0C;
2331 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002332 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002333 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002334 temp |= ((CRB4 & 0x04) << 3);
2335 return temp;
2336}
2337
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002338/*----------------------------------------------------------------------------*/
2339/* input */
2340/* bl[5] : 1;LVDS signal on */
2341/* bl[1] : 1;LVDS backlight on */
2342/* bl[0] : 1:LVDS VDD on */
2343/* bh: 100000b : clear bit 5, to set bit5 */
2344/* 000010b : clear bit 1, to set bit1 */
2345/* 000001b : clear bit 0, to set bit0 */
2346/*----------------------------------------------------------------------------*/
2347static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2348 struct vb_device_info *pVBInfo)
2349{
2350 unsigned char CR4A, temp;
2351
2352 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2353 tempbh &= 0x23;
2354 tempbl &= 0x23;
2355 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2356
2357 if (tempbh & 0x20) {
2358 temp = (tempbl >> 4) & 0x02;
2359
2360 /* CR B4[1] */
2361 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2362
2363 }
2364
2365 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2366
2367 temp = XG21GPIODataTransfer(temp);
2368 temp &= ~tempbh;
2369 temp |= tempbl;
2370 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2371}
2372
Aaro Koskinen776115a2011-11-27 23:03:10 +02002373static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2374 struct vb_device_info *pVBInfo)
2375{
2376 unsigned char CR4A, temp;
2377 unsigned short tempbh0, tempbl0;
2378
2379 tempbh0 = tempbh;
2380 tempbl0 = tempbl;
2381 tempbh0 &= 0x20;
2382 tempbl0 &= 0x20;
2383 tempbh0 >>= 3;
2384 tempbl0 >>= 3;
2385
2386 if (tempbh & 0x20) {
2387 temp = (tempbl >> 4) & 0x02;
2388
2389 /* CR B4[1] */
2390 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2391
2392 }
2393 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2394
2395 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2396 tempbh &= 0x03;
2397 tempbl &= 0x03;
2398 tempbh <<= 2;
2399 tempbl <<= 2; /* GPIOC,GPIOD */
2400 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2401 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2402}
2403
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002404static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2405 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302406 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002407{
2408
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002409 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302410 if (pXGIHWDE->jChipType == XG21) {
2411 if (pVBInfo->IF_DEF_LVDS == 1) {
2412 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002413 /* LVDS VDD on */
2414 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002415 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302416 }
2417 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002418 /* LVDS signal on */
2419 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002420 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002421 /* LVDS backlight on */
2422 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302423 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002424 /* DVO/DVI signal on */
2425 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302426 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002427
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302428 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002429
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302430 if (pXGIHWDE->jChipType == XG27) {
2431 if (pVBInfo->IF_DEF_LVDS == 1) {
2432 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002433 /* LVDS VDD on */
2434 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002435 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302436 }
2437 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002438 /* LVDS signal on */
2439 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002440 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002441 /* LVDS backlight on */
2442 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302443 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002444 /* DVO/DVI signal on */
2445 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302446 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002447
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302448 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002449}
2450
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002451void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2452 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302453 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002454{
2455
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302456 if (pXGIHWDE->jChipType == XG21) {
2457 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002458 /* LVDS backlight off */
2459 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002460 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302461 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002462 /* DVO/DVI signal off */
2463 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302464 }
2465 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002466
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302467 if (pXGIHWDE->jChipType == XG27) {
2468 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002469 /* LVDS backlight off */
2470 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002471 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302472 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002473
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302474 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002475 /* DVO/DVI signal off */
2476 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302477 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002478
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002479 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002480}
2481
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002482static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002483{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002484 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302485 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002486
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002487 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302488 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002489}
2490
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002491static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002492{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002493 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002494}
2495
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002496static void XGI_SaveCRT2Info(unsigned short ModeNo,
2497 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002498{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302499 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002500
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002501 /* reserve CR34 for CRT1 Mode No */
2502 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302503 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2504 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002505 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002506}
2507
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002508static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2509 unsigned short ModeIdIndex,
2510 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002511{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302512 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002513
Aaro Koskinenb3979922012-11-04 21:14:52 +02002514 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002515 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2516 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002517 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002518 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002519
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002520 if (modeflag & HalfDCLK)
2521 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002522
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002523 if (modeflag & DoubleScanMode)
2524 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002525
Miguel Gómez3339db82012-07-06 12:40:49 +02002526 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2527 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002528
Aaro Koskinen22006832013-02-09 00:03:47 +02002529 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2530 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2531 if (yres == 1024)
2532 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302533 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002534 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002535
Aaro Koskinen22006832013-02-09 00:03:47 +02002536 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2537 if (yres == 400)
2538 yres = 405;
2539 else if (yres == 350)
2540 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002541
Aaro Koskinen22006832013-02-09 00:03:47 +02002542 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2543 if (yres == 360)
2544 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002545 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002546 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002547
Aaro Koskinen22006832013-02-09 00:03:47 +02002548 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2549 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2550 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2551 if (yres == 350)
2552 yres = 357;
2553 else if (yres == 400)
2554 yres = 420;
2555 else if (yres == 480)
2556 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002557 }
2558 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302559 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002560
Miguel Gómez3339db82012-07-06 12:40:49 +02002561 if (xres == 720)
2562 xres = 640;
2563
2564exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302565 pVBInfo->VGAHDE = xres;
2566 pVBInfo->HDE = xres;
2567 pVBInfo->VGAVDE = yres;
2568 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002569}
2570
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002571static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002572{
2573
Peter Huewea3d675c2012-02-09 21:11:47 +01002574 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002575 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302576 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002577
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302578 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002579}
2580
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002581static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2582 unsigned short ModeIdIndex,
2583 unsigned short RefreshRateTableIndex,
2584 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002585{
2586 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002587 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002588
2589 pVBInfo->RVBHCMAX = 1;
2590 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002591 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002592 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002593 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002594 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2595 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002596 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002597 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002598 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002599 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002600 tempcx &= 0x0100;
2601 tempcx = tempcx << 2;
2602 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002603 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002604
2605 if (temp1 & 0x01)
2606 tempbx |= 0x0100;
2607
2608 if (temp1 & 0x20)
2609 tempbx |= 0x0200;
2610 tempax += 5;
2611
2612 if (modeflag & Charx8Dot)
2613 tempax *= 8;
2614 else
2615 tempax *= 9;
2616
2617 pVBInfo->VGAHT = tempax;
2618 pVBInfo->HT = tempax;
2619 tempbx++;
2620 pVBInfo->VGAVT = tempbx;
2621 pVBInfo->VT = tempbx;
2622}
2623
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002624static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302625 unsigned short RefreshRateTableIndex,
2626 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002627{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002628 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002629
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002630 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002631
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002632 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002633 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2634 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302635 pVBInfo->NewFlickerMode = 0;
2636 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302638 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2639 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2640 pVBInfo);
2641 return;
2642 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002643
Peter Huewea3d675c2012-02-09 21:11:47 +01002644 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002645 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002646 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302648 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2649 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2650 pVBInfo->VGAHT = LCDPtr->VGAHT;
2651 pVBInfo->VGAVT = LCDPtr->VGAVT;
2652 pVBInfo->HT = LCDPtr->LCDHT;
2653 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002654
Peter Huewe255aabd2012-02-09 21:11:44 +01002655 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302656 tempax = 1024;
2657 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002658
Peter Huewea3d675c2012-02-09 21:11:47 +01002659 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302660 if (pVBInfo->VGAVDE == 357)
2661 tempbx = 527;
2662 else if (pVBInfo->VGAVDE == 420)
2663 tempbx = 620;
2664 else if (pVBInfo->VGAVDE == 525)
2665 tempbx = 775;
2666 else if (pVBInfo->VGAVDE == 600)
2667 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302668 else
2669 tempbx = 768;
2670 } else
2671 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002672 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302673 tempax = 1024;
2674 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002675 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302676 tempax = 1280;
2677 if (pVBInfo->VGAVDE == 360)
2678 tempbx = 768;
2679 else if (pVBInfo->VGAVDE == 375)
2680 tempbx = 800;
2681 else if (pVBInfo->VGAVDE == 405)
2682 tempbx = 864;
2683 else
2684 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002685 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302686 tempax = 1280;
2687 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002688 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302689 tempax = 1280;
2690 if (pVBInfo->VGAVDE == 350)
2691 tempbx = 700;
2692 else if (pVBInfo->VGAVDE == 400)
2693 tempbx = 800;
2694 else if (pVBInfo->VGAVDE == 1024)
2695 tempbx = 960;
2696 else
2697 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002698 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302699 tempax = 1400;
2700 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002701
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302702 if (pVBInfo->VGAVDE == 1024) {
2703 tempax = 1280;
2704 tempbx = 1024;
2705 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002706 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302707 tempax = 1600;
2708 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002709 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302710 if (pVBInfo->VGAVDE == 350)
2711 tempbx = 875;
2712 else if (pVBInfo->VGAVDE == 400)
2713 tempbx = 1000;
2714 }
2715 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002716
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302717 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2718 tempax = pVBInfo->VGAHDE;
2719 tempbx = pVBInfo->VGAVDE;
2720 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002721
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302722 pVBInfo->HDE = tempax;
2723 pVBInfo->VDE = tempbx;
2724 return;
2725 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002726
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302727 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002728 struct SiS_TVData const *TVPtr;
2729
2730 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2731 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002732
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302733 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2734 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2735 pVBInfo->VGAHT = TVPtr->VGAHT;
2736 pVBInfo->VGAVT = TVPtr->VGAVT;
2737 pVBInfo->HDE = TVPtr->TVHDE;
2738 pVBInfo->VDE = TVPtr->TVVDE;
2739 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2740 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002741
Peter Huewe599801f2012-02-09 21:11:45 +01002742 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302743 if (resinfo == 0x08)
2744 pVBInfo->NewFlickerMode = 0x40;
2745 else if (resinfo == 0x09)
2746 pVBInfo->NewFlickerMode = 0x40;
2747 else if (resinfo == 0x12)
2748 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002749
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302750 if (pVBInfo->VGAVDE == 350)
2751 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002752
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302753 tempax = ExtHiTVHT;
2754 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002755
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302756 if (pVBInfo->VBInfo & SetInSlaveMode) {
2757 if (pVBInfo->TVInfo & TVSimuMode) {
2758 tempax = StHiTVHT;
2759 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002760
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302761 if (!(modeflag & Charx8Dot)) {
2762 tempax = StHiTextTVHT;
2763 tempbx = StHiTextTVVT;
2764 }
2765 }
2766 }
Peter Huewe599801f2012-02-09 21:11:45 +01002767 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2768 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302769 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2770 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2771 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002772
Peter Huewe599801f2012-02-09 21:11:45 +01002773 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302774 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2775 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002776 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302777 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2778 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2779 if (pVBInfo->TVInfo & NTSC1024x768)
2780 tempax = NTSC1024x768HT;
2781 }
2782 } else {
2783 tempax = PALHT;
2784 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002785 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302786 tempax = NTSCHT;
2787 tempbx = NTSCVT;
2788 if (pVBInfo->TVInfo & NTSC1024x768)
2789 tempax = NTSC1024x768HT;
2790 }
2791 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002792
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302793 pVBInfo->HT = tempax;
2794 pVBInfo->VT = tempbx;
2795 return;
2796 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002797}
2798
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002799static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302800 unsigned short RefreshRateTableIndex,
2801 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002802{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002803 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002804
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302805 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2806 pVBInfo);
2807 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2808 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002809
Peter Huewe6896b942012-02-09 21:11:46 +01002810 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302811 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002812 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2813 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2814 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302815 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002816 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2817 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302818 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002819
Aaro Koskinen8104e322011-03-13 12:26:22 +02002820 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302822 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002823 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302824 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002825 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002826}
2827
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002828static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2829 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002830{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002831 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2832 short index;
2833 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302834
Aaro Koskinenb3979922012-11-04 21:14:52 +02002835 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002836 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302837
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002838 if (index < 0)
2839 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302840
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002841 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302842}
2843
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002844static unsigned short XGI_GetOffset(unsigned short ModeNo,
2845 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302846 unsigned short RefreshRateTableIndex,
2847 struct xgi_hw_device_info *HwDeviceExtension,
2848 struct vb_device_info *pVBInfo)
2849{
2850 unsigned short temp, colordepth, modeinfo, index, infoflag,
2851 ColorDepth[] = { 0x01, 0x02, 0x04 };
2852
Aaro Koskinenb3979922012-11-04 21:14:52 +02002853 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002854 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302855
2856 index = (modeinfo >> 8) & 0xFF;
2857
Aaro Koskinen224114c2012-11-04 21:14:59 +02002858 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302859
2860 if (infoflag & InterlaceMode)
2861 temp = temp << 1;
2862
2863 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2864
2865 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2866 temp = ModeNo - 0x7C;
2867 colordepth = ColorDepth[temp];
2868 temp = 0x6B;
2869 if (infoflag & InterlaceMode)
2870 temp = temp << 1;
2871 return temp * colordepth;
2872 } else {
2873 return temp * colordepth;
2874 }
2875}
2876
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002877static void XGI_SetCRT2Offset(unsigned short ModeNo,
2878 unsigned short ModeIdIndex,
2879 unsigned short RefreshRateTableIndex,
2880 struct xgi_hw_device_info *HwDeviceExtension,
2881 struct vb_device_info *pVBInfo)
2882{
2883 unsigned short offset;
2884 unsigned char temp;
2885
2886 if (pVBInfo->VBInfo & SetInSlaveMode)
2887 return;
2888
2889 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2890 HwDeviceExtension, pVBInfo);
2891 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002892 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002893 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002894 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002895 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002896 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002897}
2898
Randy Dunlap89229672010-08-10 08:46:44 -07002899static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002900{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002901 /* threshold high ,disable auto threshold */
2902 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2903 /* threshold low default 04h */
2904 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002905}
2906
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002907static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302908 struct xgi_hw_device_info *HwDeviceExtension,
2909 unsigned short RefreshRateTableIndex,
2910 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002911{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002912 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002913
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302914 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2915 HwDeviceExtension, pVBInfo);
2916 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002917
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302918 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002919 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002920
Aaro Koskinen8104e322011-03-13 12:26:22 +02002921 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2922 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002923}
2924
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002925static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302926 struct xgi_hw_device_info *HwDeviceExtension,
2927 unsigned short RefreshRateTableIndex,
2928 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002929{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302930 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002931 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002932
Aaro Koskinena39325d2012-11-04 21:14:53 +02002933 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002934 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002935 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002936
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302937 /* bainy change table name */
2938 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002939 /* BTVGA2HT 0x08,0x09 */
2940 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002941 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302942 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002943 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002944 /* BTVGA2HDEE 0x0A,0x0C */
2945 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002946 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302947 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2948 pushbx = pVBInfo->VGAHDE / 2 + 16;
2949 tempcx = tempcx >> 1;
2950 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2951 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002952
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302953 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002954 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2955 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002956 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302957 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002958 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302959 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002960 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302961 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2962 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2963 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002964
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302965 tempbx += 4;
2966 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002967
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302968 if (tempcx > (pVBInfo->VGAHT / 2))
2969 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002970
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302971 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002972
Aaro Koskinen8104e322011-03-13 12:26:22 +02002973 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302974 } else {
2975 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002976 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302977 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002978 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002979 /* BTVGA2HDEE 0x0A,0x0C */
2980 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002981 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302982 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2983 pushbx = pVBInfo->VGAHDE + 16;
2984 tempcx = tempcx >> 1;
2985 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2986 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002987
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302988 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002989 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2990 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002991 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302992 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002993 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302994 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002995 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302996 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2997 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2998 tempbx += 16;
2999 tempcx += 16;
3000 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303002 if (tempcx > pVBInfo->VGAHT)
3003 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003004
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303005 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003006 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303007 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003008
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303009 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3010 tempbx = pushbx;
3011 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3012 tempax |= (tempbx & 0xFF00);
3013 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003014 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303015 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003016 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303017 tempcx = (pVBInfo->VGAVT - 1);
3018 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003019
Aaro Koskinen8104e322011-03-13 12:26:22 +02003020 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303021 tempbx = pVBInfo->VGAVDE - 1;
3022 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003023 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303024 temp = ((tempbx & 0xFF00) << 3) >> 8;
3025 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003026 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003027
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303028 tempax = pVBInfo->VGAVDE;
3029 tempbx = pVBInfo->VGAVDE;
3030 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003031 /* BTVGA2VRS 0x10,0x11 */
3032 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3033 /* BTVGA2VRE 0x11 */
3034 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303036 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003037 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
3038 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303040 if (temp & 0x04)
3041 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003042
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303043 if (temp & 0x080)
3044 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003045
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003046 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003047
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303048 if (temp & 0x08)
3049 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003050
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003051 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303052 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3053 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303055 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003056 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303057 temp = ((tempbx & 0xFF00) >> 8) << 4;
3058 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003059 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303060 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003061
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303062 if (modeflag & DoubleScanMode)
3063 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003064
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303065 if (modeflag & HalfDCLK)
3066 tempax |= 0x40;
3067
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003068 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003069}
3070
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003071static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3072{
3073 unsigned long tempax, tempbx;
3074
3075 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3076 & 0xFFFF;
3077 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3078 tempax = (tempax * pVBInfo->HT) / tempbx;
3079
3080 return (unsigned short) tempax;
3081}
3082
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003083static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303084 struct xgi_hw_device_info *HwDeviceExtension,
3085 unsigned short RefreshRateTableIndex,
3086 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003087{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303088 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003089 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003090
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003091 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003092 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3093 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003094
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303095 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3096 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303098 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003099 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303100 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003101
Peter Huewe6896b942012-02-09 21:11:46 +01003102 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303103 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303105 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303107 if (modeflag & HalfDCLK)
3108 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003109
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303110 tempax = (tempax / tempcx) - 1;
3111 tempbx |= ((tempax & 0x00FF) << 8);
3112 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003113 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303115 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003116
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303117 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003118 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3119 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303120 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003121
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003122 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3123 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303124 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303125 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003126
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003127 /* 0x05 Horizontal Display Start */
3128 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3129 /* 0x06 Horizontal Blank end */
3130 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303132 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3133 if (pVBInfo->VBInfo & SetCRT2ToTV)
3134 tempax = pVBInfo->VGAHT;
3135 else
3136 tempax = XGI_GetVGAHT2(pVBInfo);
3137 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003138
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303139 if (tempax >= pVBInfo->VGAHT)
3140 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303142 if (modeflag & HalfDCLK)
3143 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003144
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303145 tempax = (tempax / tempcx) - 5;
3146 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003147 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303148 temp = (tempbx & 0x00FF) - 1;
3149 if (!(modeflag & HalfDCLK)) {
3150 temp -= 6;
3151 if (pVBInfo->TVInfo & TVSimuMode) {
3152 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003153 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303154 }
3155 }
3156 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303157 tempbx = (tempbx & 0xFF00) >> 8;
3158 tempcx = (tempcx + tempbx) >> 1;
3159 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303161 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3162 temp -= 1;
3163 if (!(modeflag & HalfDCLK)) {
3164 if ((modeflag & Charx8Dot)) {
3165 temp += 4;
3166 if (pVBInfo->VGAHDE >= 800)
3167 temp -= 6;
3168 }
3169 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003170 } else if (!(modeflag & HalfDCLK)) {
3171 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003172 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003173 pVBInfo->VGAHDE >= 800) {
3174 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003175 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003176 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003177 (pVBInfo->LCDInfo & LCDNonExpanding))
3178 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303179 }
3180 }
3181 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003182
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003183 /* 0x07 Horizontal Retrace Start */
3184 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3185 /* 0x08 Horizontal Retrace End */
3186 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303188 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3189 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003190 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303191 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003192 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303193 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003194 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303195 0x08, 0x03);
3196 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003197 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303198 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003199 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303200 0x08, 0x02);
3201 }
3202 }
3203 }
3204 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003205
Aaro Koskinen8104e322011-03-13 12:26:22 +02003206 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003207 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003208 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003209
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303210 tempbx = pVBInfo->VGAVT;
3211 push1 = tempbx;
3212 tempcx = 0x121;
3213 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303215 if (tempbx == 357)
3216 tempbx = 350;
3217 if (tempbx == 360)
3218 tempbx = 350;
3219 if (tempbx == 375)
3220 tempbx = 350;
3221 if (tempbx == 405)
3222 tempbx = 400;
3223 if (tempbx == 525)
3224 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003225
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303226 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303228 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003229 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003230 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303231 if (tempbx == 350)
3232 tempbx += 5;
3233 if (tempbx == 480)
3234 tempbx += 5;
3235 }
3236 }
3237 }
3238 tempbx--;
3239 temp = tempbx & 0x00FF;
3240 tempbx--;
3241 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003242 /* 0x10 vertical Blank Start */
3243 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303244 tempbx = push2;
3245 tempbx--;
3246 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003247 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303249 if (tempbx & 0x0100)
3250 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303252 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303254 if (modeflag & DoubleScanMode)
3255 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303257 if (tempbx & 0x0200)
3258 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003259
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303260 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003261 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003262
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303263 if (tempbx & 0x0400)
3264 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003265
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003266 /* 0x11 Vertival Blank End */
3267 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303268
3269 tempax = push1;
3270 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3271 tempax = tempax >> 2;
3272 push1 = tempax; /* push ax */
3273
3274 if (resinfo != 0x09) {
3275 tempax = tempax << 1;
3276 tempbx += tempax;
3277 }
3278
Peter Huewe599801f2012-02-09 21:11:45 +01003279 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003280 if ((pVBInfo->VBType & VB_SIS301LV) &&
3281 !(pVBInfo->TVInfo & TVSetHiVision)) {
3282 if ((pVBInfo->TVInfo & TVSimuMode) &&
3283 (pVBInfo->TVInfo & TVSetPAL)) {
3284 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3285 !(pVBInfo->TVInfo &
3286 (TVSetYPbPr525p |
3287 TVSetYPbPr750p |
3288 TVSetHiVision)))
3289 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303290 }
3291 } else {
3292 tempbx -= 10;
3293 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003294 } else if (pVBInfo->TVInfo & TVSimuMode) {
3295 if (pVBInfo->TVInfo & TVSetPAL) {
3296 if (pVBInfo->VBType & VB_SIS301LV) {
3297 if (!(pVBInfo->TVInfo &
3298 (TVSetYPbPr525p |
3299 TVSetYPbPr750p |
3300 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303301 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003302 } else {
3303 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303304 }
3305 }
3306 }
3307 tempax = push1;
3308 tempax = tempax >> 2;
3309 tempax++;
3310 tempax += tempbx;
3311 push1 = tempax; /* push ax */
3312
Peter Huewe599801f2012-02-09 21:11:45 +01003313 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303314 if (tempbx <= 513) {
3315 if (tempax >= 513)
3316 tempbx = 513;
3317 }
3318 }
3319
3320 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003321 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303322 tempbx--;
3323 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003324 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303325
3326 if (tempbx & 0x0100)
3327 tempcx |= 0x0008;
3328
3329 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003330 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303331
3332 tempbx++;
3333
3334 if (tempbx & 0x0100)
3335 tempcx |= 0x0004;
3336
3337 if (tempbx & 0x0200)
3338 tempcx |= 0x0080;
3339
3340 if (tempbx & 0x0400)
3341 tempcx |= 0x0C00;
3342
3343 tempbx = push1; /* pop ax */
3344 temp = tempbx & 0x00FF;
3345 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003346 /* 0x0D vertical Retrace End */
3347 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303348
3349 if (tempbx & 0x0010)
3350 tempcx |= 0x2000;
3351
3352 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003353 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303354 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003355 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303356 tempax = modeflag;
3357 temp = (tempax & 0xFF00) >> 8;
3358
3359 temp = (temp >> 1) & 0x09;
3360
Peter Huewe6896b942012-02-09 21:11:46 +01003361 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303362 temp |= 0x01;
3363
Aaro Koskinen8104e322011-03-13 12:26:22 +02003364 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3365 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3366 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303367
3368 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3369 temp = 0x80;
3370 else
3371 temp = 0x00;
3372
Aaro Koskinen8104e322011-03-13 12:26:22 +02003373 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303374
3375 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003376}
3377
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003378static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303379 unsigned short RefreshRateTableIndex,
3380 struct xgi_hw_device_info *HwDeviceExtension,
3381 struct vb_device_info *pVBInfo)
3382{
3383 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003384 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003385 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303386
3387 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3388
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003389 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003390 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303391
3392 tempax = 0;
3393
3394 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3395 tempax |= 0x0800;
3396
3397 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3398 tempax |= 0x0400;
3399
3400 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3401 tempax |= 0x0200;
3402
Peter Huewe599801f2012-02-09 21:11:45 +01003403 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303404 tempax |= 0x1000;
3405
Peter Huewe599801f2012-02-09 21:11:45 +01003406 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303407 tempax |= 0x0100;
3408
Peter Huewe599801f2012-02-09 21:11:45 +01003409 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303410 tempax &= 0xfe00;
3411
3412 tempax = (tempax & 0xff00) >> 8;
3413
Aaro Koskinen8104e322011-03-13 12:26:22 +02003414 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003415 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303416
Peter Huewe599801f2012-02-09 21:11:45 +01003417 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003418 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303419
Peter Huewe599801f2012-02-09 21:11:45 +01003420 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003421 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303422
3423 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003424 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303425
3426 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003427 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303428
3429 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003430 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303431 }
3432
Peter Huewe599801f2012-02-09 21:11:45 +01003433 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3434 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003435 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303436
Peter Huewe599801f2012-02-09 21:11:45 +01003437 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003438 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303439
Peter Huewe599801f2012-02-09 21:11:45 +01003440 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003441 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303442 }
3443
3444 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003445 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303446
3447 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003448 /* di->temp2[j] */
3449 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303450
3451 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003452 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303453
3454 temp = pVBInfo->NewFlickerMode;
3455 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003456 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303457
Peter Huewe599801f2012-02-09 21:11:45 +01003458 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303459 tempax = 950;
3460
Peter Huewe599801f2012-02-09 21:11:45 +01003461 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303462 tempax = 520;
3463 else
3464 tempax = 440;
3465
3466 if (pVBInfo->VDE <= tempax) {
3467 tempax -= pVBInfo->VDE;
3468 tempax = tempax >> 2;
3469 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3470 push1 = tempax;
3471 temp = (tempax & 0xFF00) >> 8;
3472 temp += (unsigned short) TimingPoint[0];
3473
Peter Huewe6896b942012-02-09 21:11:46 +01003474 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3475 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303476 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3477 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003478 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303479 tempcx = pVBInfo->VGAHDE;
3480 if (tempcx >= 1024) {
3481 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003482 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303483 temp = 0x19; /* PAL */
3484 }
3485 }
3486 }
3487
Aaro Koskinen8104e322011-03-13 12:26:22 +02003488 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303489 tempax = push1;
3490 temp = (tempax & 0xFF00) >> 8;
3491 temp += TimingPoint[1];
3492
Peter Huewe6896b942012-02-09 21:11:46 +01003493 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3494 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3496 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003497 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303498 tempcx = pVBInfo->VGAHDE;
3499 if (tempcx >= 1024) {
3500 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003501 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303502 temp = 0x52; /* PAL */
3503 }
3504 }
3505 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003506 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303507 }
3508
3509 /* 301b */
3510 tempcx = pVBInfo->HT;
3511
3512 if (XGI_IsLCDDualLink(pVBInfo))
3513 tempcx = tempcx >> 1;
3514
3515 tempcx -= 2;
3516 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003517 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303518
3519 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003520 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303521
3522 tempcx = pVBInfo->HT >> 1;
3523 push1 = tempcx; /* push cx */
3524 tempcx += 7;
3525
Peter Huewe599801f2012-02-09 21:11:45 +01003526 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303527 tempcx -= 4;
3528
3529 temp = tempcx & 0x00FF;
3530 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003531 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303532
3533 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3534 tempbx += tempcx;
3535 push2 = tempbx;
3536 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003537 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303538 temp = (tempbx & 0xFF00) >> 8;
3539 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003540 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303541
3542 tempbx = push2;
3543 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003544 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303545 tempbx = tempbx - 4;
3546 tempcx = tempbx;
3547 }
3548
3549 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003550 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303551
3552 j += 2;
3553 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3554 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003555 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303556 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003557 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303558
3559 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003560 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303561 tempcx -= 4;
3562
3563 temp = tempcx & 0xFF;
3564 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003565 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303566
3567 tempcx = push1; /* pop cx */
3568 j += 2;
3569 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3570 tempcx -= temp;
3571 temp = tempcx & 0x00FF;
3572 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003573 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303574
3575 tempcx -= 11;
3576
3577 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3578 tempax = XGI_GetVGAHT2(pVBInfo);
3579 tempcx = tempax - 1;
3580 }
3581 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003582 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303583
3584 tempbx = pVBInfo->VDE;
3585
3586 if (pVBInfo->VGAVDE == 360)
3587 tempbx = 746;
3588 if (pVBInfo->VGAVDE == 375)
3589 tempbx = 746;
3590 if (pVBInfo->VGAVDE == 405)
3591 tempbx = 853;
3592
3593 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003594 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003595 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003596 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003597 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303598 tempbx = tempbx >> 1;
3599 } else
3600 tempbx = tempbx >> 1;
3601 }
3602
3603 tempbx -= 2;
3604 temp = tempbx & 0x00FF;
3605
Peter Huewe599801f2012-02-09 21:11:45 +01003606 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003607 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003608 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303609 if (pVBInfo->VBInfo & SetInSlaveMode) {
3610 if (ModeNo == 0x2f)
3611 temp += 1;
3612 }
3613 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003614 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3615 if (ModeNo == 0x2f)
3616 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303617 }
3618 }
3619
Aaro Koskinen8104e322011-03-13 12:26:22 +02003620 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303621
3622 temp = (tempcx & 0xFF00) >> 8;
3623 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3624
Peter Huewe599801f2012-02-09 21:11:45 +01003625 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003626 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003627 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303628 temp |= 0x10;
3629
3630 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3631 temp |= 0x20;
3632 }
3633 } else {
3634 temp |= 0x10;
3635 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3636 temp |= 0x20;
3637 }
3638 }
3639
Aaro Koskinen8104e322011-03-13 12:26:22 +02003640 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303641
Peter Huewe6896b942012-02-09 21:11:46 +01003642 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3643 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303644 tempbx = pVBInfo->VDE;
3645 tempcx = tempbx - 2;
3646
3647 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003648 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3649 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303650 tempbx = tempbx >> 1;
3651 }
3652
Peter Huewe6896b942012-02-09 21:11:46 +01003653 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303654 temp = 0;
3655 if (tempcx & 0x0400)
3656 temp |= 0x20;
3657
3658 if (tempbx & 0x0400)
3659 temp |= 0x40;
3660
Aaro Koskinen8104e322011-03-13 12:26:22 +02003661 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303662 }
3663
3664 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003665 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303666 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003667 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303668 }
3669
3670 tempbx = tempbx & 0x00FF;
3671
3672 if (!(modeflag & HalfDCLK)) {
3673 tempcx = pVBInfo->VGAHDE;
3674 if (tempcx >= pVBInfo->HDE) {
3675 tempbx |= 0x2000;
3676 tempax &= 0x00FF;
3677 }
3678 }
3679
3680 tempcx = 0x0101;
3681
3682 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3683 if (pVBInfo->VGAHDE >= 1024) {
3684 tempcx = 0x1920;
3685 if (pVBInfo->VGAHDE >= 1280) {
3686 tempcx = 0x1420;
3687 tempbx = tempbx & 0xDFFF;
3688 }
3689 }
3690 }
3691
3692 if (!(tempbx & 0x2000)) {
3693 if (modeflag & HalfDCLK)
3694 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3695
3696 push1 = tempbx;
3697 tempeax = pVBInfo->VGAHDE;
3698 tempebx = (tempcx & 0xFF00) >> 8;
3699 longtemp = tempeax * tempebx;
3700 tempecx = tempcx & 0x00FF;
3701 longtemp = longtemp / tempecx;
3702
3703 /* 301b */
3704 tempecx = 8 * 1024;
3705
Peter Huewe6896b942012-02-09 21:11:46 +01003706 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3707 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303708 tempecx = tempecx * 8;
3709 }
3710
3711 longtemp = longtemp * tempecx;
3712 tempecx = pVBInfo->HDE;
3713 temp2 = longtemp % tempecx;
3714 tempeax = longtemp / tempecx;
3715 if (temp2 != 0)
3716 tempeax += 1;
3717
3718 tempax = (unsigned short) tempeax;
3719
3720 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003721 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3722 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303723 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3724 }
3725 /* end 301b */
3726
3727 tempbx = push1;
3728 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3729 | (tempbx & 0x00FF));
3730 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3731 | (tempax & 0x00FF));
3732 temp = (tempax & 0xFF00) >> 8;
3733 } else {
3734 temp = (tempax & 0x00FF) >> 8;
3735 }
3736
Aaro Koskinen8104e322011-03-13 12:26:22 +02003737 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303738 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003739 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303740 temp = tempcx & 0x00FF;
3741
3742 if (tempbx & 0x2000)
3743 temp = 0;
3744
3745 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3746 temp |= 0x18;
3747
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003748 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003749 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303750 tempbx = 0x0382;
3751 tempcx = 0x007e;
3752 } else {
3753 tempbx = 0x0369;
3754 tempcx = 0x0061;
3755 }
3756
3757 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003758 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303759 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003760 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303761
3762 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3763 temp = temp << 2;
3764 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3765
Peter Huewe599801f2012-02-09 21:11:45 +01003766 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303767 temp |= 0x10;
3768
Peter Huewe599801f2012-02-09 21:11:45 +01003769 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303770 temp |= 0x20;
3771
Peter Huewe599801f2012-02-09 21:11:45 +01003772 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303773 temp |= 0x60;
3774 }
3775
Aaro Koskinen8104e322011-03-13 12:26:22 +02003776 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003777 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003778 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303779
Peter Huewe599801f2012-02-09 21:11:45 +01003780 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303781 if (pVBInfo->TVInfo & NTSC1024x768) {
3782 TimingPoint = XGI_NTSC1024AdjTime;
3783 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003784 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303785 TimingPoint[j]);
3786 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003787 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303788 }
3789 }
3790
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003791 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303792 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003793 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003794 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303795 0x08); /* PALM Mode */
3796 }
3797
Peter Huewe599801f2012-02-09 21:11:45 +01003798 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003799 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303800 0x01);
3801 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003802 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303803
Aaro Koskinendc505562011-03-13 12:26:26 +02003804 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303805 }
3806
Peter Huewe599801f2012-02-09 21:11:45 +01003807 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303808 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003809 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303810 }
3811
3812 if (pVBInfo->VBInfo & SetCRT2ToTV)
3813 return;
3814}
3815
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003816static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303817 struct xgi_hw_device_info *HwDeviceExtension,
3818 unsigned short RefreshRateTableIndex,
3819 struct vb_device_info *pVBInfo)
3820{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003821 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3822 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303823
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003824 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303825
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003826 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303827 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3828 return;
3829
3830 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3831
3832 if (XGI_IsLCDDualLink(pVBInfo))
3833 tempbx = tempbx >> 1;
3834
3835 tempbx -= 1;
3836 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003837 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303838 temp = (tempbx & 0xFF00) >> 8;
3839 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003840 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303841 temp = 0x01;
3842
Aaro Koskinen8104e322011-03-13 12:26:22 +02003843 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303844 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303845 tempbx--;
3846 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003847 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303848 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003849 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303850
3851 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303852 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003853 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303854 temp = (tempcx & 0xFF00) >> 8;
3855 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003856 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003857 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3858 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3859 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3860 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303861
Justin P. Mattock558f7582012-10-02 21:17:11 -07003862 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003863 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
3864 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
3865 RefreshRateTableIndex, pVBInfo);
3866 else
3867 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
3868 ModeIdIndex, RefreshRateTableIndex,
3869 pVBInfo);
3870
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303871 tempah = pVBInfo->LCDResInfo;
3872 tempah &= PanelResInfo;
3873
Peter Huewe255aabd2012-02-09 21:11:44 +01003874 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303875 tempbx = 1024;
3876 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003877 } else if ((tempah == Panel_1280x1024) ||
3878 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303879 tempbx = 1280;
3880 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003881 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303882 tempbx = 1400;
3883 tempcx = 1050;
3884 } else {
3885 tempbx = 1600;
3886 tempcx = 1200;
3887 }
3888
3889 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3890 tempbx = pVBInfo->HDE;
3891 tempcx = pVBInfo->VDE;
3892 }
3893
3894 pushbx = tempbx;
3895 tempax = pVBInfo->VT;
3896 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3897 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3898 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3899 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3900 tempbx = pVBInfo->LCDVDES;
3901 tempcx += tempbx;
3902
3903 if (tempcx >= tempax)
3904 tempcx -= tempax; /* lcdvdes */
3905
3906 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003907 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303908 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003909 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303910 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3911 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3912 tempah = tempch;
3913 tempah = tempah << 3;
3914 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003915 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303916
3917 /* getlcdsync() */
3918 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3919 tempcx = tempbx;
3920 tempax = pVBInfo->VT;
3921 tempbx = pVBInfo->LCDVRS;
3922
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303923 tempcx += tempbx;
3924 if (tempcx >= tempax)
3925 tempcx -= tempax;
3926
3927 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003928 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303929 temp = (tempbx & 0xFF00) >> 8;
3930 temp = temp << 4;
3931 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003932 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303933 tempcx = pushbx;
3934 tempax = pVBInfo->HT;
3935 tempbx = pVBInfo->LCDHDES;
3936 tempbx &= 0x0FFF;
3937
3938 if (XGI_IsLCDDualLink(pVBInfo)) {
3939 tempax = tempax >> 1;
3940 tempbx = tempbx >> 1;
3941 tempcx = tempcx >> 1;
3942 }
3943
Peter Huewe6896b942012-02-09 21:11:46 +01003944 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303945 tempbx += 1;
3946
3947 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3948 tempbx += 1;
3949
3950 tempcx += tempbx;
3951
3952 if (tempcx >= tempax)
3953 tempcx -= tempax;
3954
3955 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003956 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303957 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003958 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303959 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003960 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303961 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003962 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303963
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303964 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3965 tempcx = tempax;
3966 tempax = pVBInfo->HT;
3967 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303968 if (XGI_IsLCDDualLink(pVBInfo)) {
3969 tempax = tempax >> 1;
3970 tempbx = tempbx >> 1;
3971 tempcx = tempcx >> 1;
3972 }
3973
Peter Huewe6896b942012-02-09 21:11:46 +01003974 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303975 tempbx += 1;
3976
3977 tempcx += tempbx;
3978
3979 if (tempcx >= tempax)
3980 tempcx -= tempax;
3981
3982 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003983 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303984
3985 temp = (tempbx & 0xFF00) >> 8;
3986 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003987 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303988 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003989 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303990
Peter Huewea3d675c2012-02-09 21:11:47 +01003991 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303992 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003993 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3994 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303995 | VB_XGI301C)) {
3996 temp = 0xC6;
3997 } else
3998 temp = 0xC4;
3999
Aaro Koskinen8104e322011-03-13 12:26:22 +02004000 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4001 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304002 }
4003
4004 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004005 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4006 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304007 | VB_XGI301C)) {
4008 temp = 0x4F;
4009 } else
4010 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004011 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304012 }
4013 }
4014}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004015
4016/* --------------------------------------------------------------------- */
4017/* Function : XGI_GetTap4Ptr */
4018/* Input : */
4019/* Output : di -> Tap4 Reg. Setting Pointer */
4020/* Description : */
4021/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004022static struct XGI301C_Tap4TimingStruct const
4023*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004024{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304025 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004026 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004027
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304028 if (tempcx == 0) {
4029 tempax = pVBInfo->VGAHDE;
4030 tempbx = pVBInfo->HDE;
4031 } else {
4032 tempax = pVBInfo->VGAVDE;
4033 tempbx = pVBInfo->VDE;
4034 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004035
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004036 if (tempax <= tempbx)
4037 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304038 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004039 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004040
Peter Huewe599801f2012-02-09 21:11:45 +01004041 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304042 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004043
Peter Huewe599801f2012-02-09 21:11:45 +01004044 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4045 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4046 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004047 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004048 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304049 Tap4TimingPtr = YPbPr750pTap4Timing;
4050 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004051
Peter Huewe599801f2012-02-09 21:11:45 +01004052 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004053 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304055 i = 0;
4056 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4057 if (Tap4TimingPtr[i].DE == tempax)
4058 break;
4059 i++;
4060 }
4061 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004062}
4063
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004064static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004065{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304066 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004067 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004068
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304069 if (!(pVBInfo->VBType & VB_XGI301C))
4070 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004071
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304072 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4073 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004074 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004075
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004076 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004077 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004078 /* Set Vertical Scaling */
4079 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304080 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004081 xgifb_reg_set(pVBInfo->Part2Port,
4082 i,
4083 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304084 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004085
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004086 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004087 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004088 /* Enable V.Scaling */
4089 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304090 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004091 /* Enable H.Scaling */
4092 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004093}
4094
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004095static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304096 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004097{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304098 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004099 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304100 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004101
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004102 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004103 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004104
Aaro Koskinen8104e322011-03-13 12:26:22 +02004105 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004106 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004107 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4108 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304109 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004110 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4111 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304112 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304114 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4115 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004116
Peter Huewe599801f2012-02-09 21:11:45 +01004117 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004118 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4119 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4120 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004122
Peter Huewe599801f2012-02-09 21:11:45 +01004123 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4124 & SetCRT2ToYPbPr525750)) {
4125 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304126 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004127
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004128 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304129 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004130 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304131 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004132 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304133 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004134
Peter Huewe599801f2012-02-09 21:11:45 +01004135 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004136 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004137
Peter Huewe599801f2012-02-09 21:11:45 +01004138 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004139 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304141 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004142 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304144 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004145 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004146 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304147 }
4148 }
4149 return;
4150} /* {end of XGI_SetGroup3} */
4151
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004152static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304153 unsigned short RefreshRateTableIndex,
4154 struct xgi_hw_device_info *HwDeviceExtension,
4155 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004156{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304157 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004158
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304159 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004160
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004161 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004162 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304163 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004164 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004165
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304166 tempbx = pVBInfo->RVBHCMAX;
4167 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004168 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304169 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4170 tempcx = pVBInfo->VGAHT - 1;
4171 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004172 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304174 temp = ((tempcx & 0xFF00) >> 8) << 3;
4175 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004176
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304177 tempcx = pVBInfo->VGAVT - 1;
4178 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4179 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004180
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304181 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004182 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304183 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004184 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004185 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304186 tempcx = pVBInfo->VBInfo;
4187 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004188
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304189 if (modeflag & HalfDCLK)
4190 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304192 if (XGI_IsLCDDualLink(pVBInfo))
4193 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004194
Peter Huewe599801f2012-02-09 21:11:45 +01004195 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304196 temp = 0;
4197 if (tempbx <= 1024)
4198 temp = 0xA0;
4199 if (tempbx == 1280)
4200 temp = 0xC0;
4201 } else if (tempcx & SetCRT2ToTV) {
4202 temp = 0xA0;
4203 if (tempbx <= 800)
4204 temp = 0x80;
4205 } else {
4206 temp = 0x80;
4207 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4208 temp = 0;
4209 if (tempbx > 800)
4210 temp = 0x60;
4211 }
4212 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004213
Peter Huewe599801f2012-02-09 21:11:45 +01004214 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304215 temp = 0x00;
4216 if (pVBInfo->VGAHDE == 1280)
4217 temp = 0x40;
4218 if (pVBInfo->VGAHDE == 1024)
4219 temp = 0x20;
4220 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004221 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304223 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004224
Peter Huewe599801f2012-02-09 21:11:45 +01004225 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304226 if (!(temp & 0xE000))
4227 tempbx = tempbx >> 1;
4228 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004229
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304230 tempcx = pVBInfo->RVBHRS;
4231 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004232 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304234 tempeax = pVBInfo->VGAVDE;
4235 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304237 if (tempeax <= tempebx) {
4238 tempcx = (tempcx & (~0x4000));
4239 tempeax = pVBInfo->VGAVDE;
4240 } else {
4241 tempeax -= tempebx;
4242 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304244 templong = (tempeax * 256 * 1024) % tempebx;
4245 tempeax = (tempeax * 256 * 1024) / tempebx;
4246 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004247
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304248 if (templong != 0)
4249 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004250
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304251 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004252 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304254 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004255 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304256 tempbx = (unsigned short) (tempebx >> 16);
4257 temp = tempbx & 0x00FF;
4258 temp = temp << 4;
4259 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004260 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004261
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304262 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004263 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4264 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304265 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004266 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304267 tempax = pVBInfo->VGAHDE;
4268 if (modeflag & HalfDCLK)
4269 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004270
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304271 if (XGI_IsLCDDualLink(pVBInfo))
4272 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304274 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4275 if (tempax > 800)
4276 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004277 } else if (pVBInfo->VGAHDE > 800) {
4278 if (pVBInfo->VGAHDE == 1024)
4279 tempax = (tempax * 25 / 32) - 1;
4280 else
4281 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304282 }
4283 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004284
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304285 temp = (tempax & 0xFF00) >> 8;
4286 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004287 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304288 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004289 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004290
Peter Huewe599801f2012-02-09 21:11:45 +01004291 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304292 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004293 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004294
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304295 }
4296 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004297
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304298 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4299 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004300 | TVSetYPbPr525p | TVSetYPbPr750p
4301 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304302 temp |= 0x0001;
4303 if ((pVBInfo->VBInfo & SetInSlaveMode)
4304 && (!(pVBInfo->TVInfo
4305 & TVSimuMode)))
4306 temp &= (~0x0001);
4307 }
4308 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004309
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004310 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304311 tempbx = pVBInfo->HT;
4312 if (XGI_IsLCDDualLink(pVBInfo))
4313 tempbx = tempbx >> 1;
4314 tempbx = (tempbx >> 1) - 2;
4315 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004316 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304317 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004318 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304319 }
4320 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004321
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004322 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004323}
4324
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004325static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4326{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004327 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004328}
4329
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004330static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304331 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004332{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304333 if (pVBInfo->ModeType == ModeVGA) {
4334 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004335 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304336 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304337 }
4338 }
4339 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004340}
4341
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004342static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304343 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004344{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004345 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004346}
4347
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004348static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304349 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004350{
4351
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004352 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004353}
4354
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004355static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4356 unsigned short ModeNo, unsigned short ModeIdIndex,
4357 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004358{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004359 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004360
Aaro Koskinenb3979922012-11-04 21:14:52 +02004361 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004362 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4363 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004364 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004365 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004366
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304367 if (!(modeflag & Charx8Dot)) {
4368 xres /= 9;
4369 xres *= 8;
4370 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004371
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004372 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4373 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004374
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004375 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4376 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004377
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004378 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304379 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004380
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004381 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304382 return 0;
4383
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004384 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4385 yres != xgifb_info->lvds_data.LVDSVDE) {
4386 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4387 if (colordepth > 2)
4388 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304389 }
4390 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004391}
4392
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004393static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4394 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004395 unsigned short ModeNo,
4396 unsigned short ModeIdIndex,
4397 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004398{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304399 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004400 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304401 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4402 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4403 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004404
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004405 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004406 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304407 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004408 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004409
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004410 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004411
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004412 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004413 /* SR35[7] FP VSync polarity */
4414 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4415 /* SR30[5] FP HSync polarity */
4416 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004417
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004418 if (chip_id == XG27)
4419 XGI_SetXG27FPBits(pVBInfo);
4420 else
4421 XGI_SetXG21FPBits(pVBInfo);
4422
Aaro Koskinenb3979922012-11-04 21:14:52 +02004423 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004424 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4425 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004426 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004427 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004428
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304429 if (!(modeflag & Charx8Dot))
4430 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004431
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004432 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004433
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004434 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004435
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304436 if (LVDSHBS > LVDSHT)
4437 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004438
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004439 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304440 if (LVDSHRS > LVDSHT)
4441 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004442
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004443 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304444 if (LVDSHRE > LVDSHT)
4445 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004446
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004447 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004448
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004449 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004450
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004451 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004452 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304453 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304455 if (LVDSVBS > LVDSVT)
4456 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004457
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004458 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304459 if (LVDSVRS > LVDSVT)
4460 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004461
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004462 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304463 if (LVDSVRE > LVDSVT)
4464 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004465
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004466 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004467
Aaro Koskinen58839b02011-03-13 12:26:23 +02004468 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004469 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004470
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304471 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004472 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004473
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304474 /* HT SR0B[1:0] CR00 */
4475 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004476 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004477 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004478
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304479 /* HBS SR0B[5:4] CR02 */
4480 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004481 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004482 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004483
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304484 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4485 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004486 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4487 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4488 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004489
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304490 /* HRS SR0B[7:6] CR04 */
4491 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004492 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004493 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304495 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4496 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004497 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004498 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004499
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304500 /* HRE SR0C[2] CR05[4:0] */
4501 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004502 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4503 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004504
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304505 /* Panel HRE SR2F[7:2] */
4506 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004507 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004508
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304509 /* VT SR0A[0] CR07[5][0] CR06 */
4510 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004511 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4512 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4513 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004514 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004515
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304516 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4517 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004518 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4519 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4520 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004521 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004522
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304523 /* VBE SR0A[4] CR16 */
4524 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004525 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004526 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004527
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304528 /* VRS SR0A[3] CR7[7][2] CR10 */
4529 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004530 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4531 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4532 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004533 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004534
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004535 if (chip_id == XG27) {
4536 /* Panel VRS SR35[2:0] SR34[7:0] */
4537 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4538 (value & 0x700) >> 8);
4539 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4540 } else {
4541 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4542 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4543 (value & 0x600) >> 9);
4544 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4545 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4546 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004547
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304548 /* VRE SR0A[5] CR11[3:0] */
4549 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004550 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4551 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004552
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304553 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004554 if (chip_id == XG27)
4555 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4556 (value << 2) & 0xFC);
4557 else
4558 /* SR3F[7] has to be 0, h/w bug */
4559 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4560 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004561
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304562 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004563
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004564 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004565 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004566 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004567 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004568 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304569 value += 0x10;
4570 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004571
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304572 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004573 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004574 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004575 /* set data, panning = 0, shift left 1 dot*/
4576 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004577
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004578 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004579 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304580
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004581 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304582 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004583
4584}
4585
4586/* --------------------------------------------------------------------- */
4587/* Function : XGI_IsLCDON */
4588/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004589/* Output : 0 : Skip PSC Control */
4590/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004591/* Description : */
4592/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004593static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004594{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304595 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004596
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304597 tempax = pVBInfo->VBInfo;
4598 if (tempax & SetCRT2ToDualEdge)
4599 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004600 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304601 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004602
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304603 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004604}
4605
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004606/* --------------------------------------------------------------------- */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004607/* Function : XGI_EnableChISLCD */
4608/* Input : */
4609/* Output : 0 -> Not LCD mode */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004610/* Description : if bool enable = true -> enable, else disable */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004611/* --------------------------------------------------------------------- */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004612static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo,
4613 bool enable)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004614{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304615 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004616
Peter Huewe06cc47b2013-02-03 22:54:38 +01004617 if (enable)
4618 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
4619 else
4620 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
4621
Aaro Koskinen58839b02011-03-13 12:26:23 +02004622 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004623
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304624 if (tempbx & (EnableChA | DisableChA)) {
4625 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4626 return 0;
4627 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004628
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304629 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04004630 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004631
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304632 if (tempah & 0x01) /* Chk LCDB Mode */
4633 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004634
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304635 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004636}
4637
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004638static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4639 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304640 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004641{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004642 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004643
Peter Huewe6896b942012-02-09 21:11:46 +01004644 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4645 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304646 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004647 if (!(pVBInfo->VBInfo &
4648 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004649 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304650 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
4651 tempah = 0x7F; /* Disable Channel A */
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004652 if (!(pVBInfo->VBInfo &
4653 XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004654 /* Disable Channel B */
4655 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004656
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304657 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004658 /* force to disable Cahnnel */
4659 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004660
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304661 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004662 /* Force to disable Channel B */
4663 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304664 }
4665 }
4666 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004667
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004668 /* disable part4_1f */
4669 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004670
Peter Huewe6896b942012-02-09 21:11:46 +01004671 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004672 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004673 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
4674 (XGI_EnableChISLCD(pVBInfo, false)) ||
4675 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004676 /* LVDS Driver power down */
4677 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304678 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004679
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304680 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004681 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304682 | SetSimuScanMode))) {
4683 if (pVBInfo->SetFlag & GatingCRT)
4684 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004685 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304686 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004687
Peter Huewea3d675c2012-02-09 21:11:47 +01004688 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304689 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004690 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004691 /* Power down */
4692 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304693 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004694
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004695 /* disable TV as primary VGA swap */
4696 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004697
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304698 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004699 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004700
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004701 if ((pVBInfo->SetFlag & DisableChB) ||
4702 (pVBInfo->VBInfo &
4703 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004704 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004705 (pVBInfo->VBInfo &
4706 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004707 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004708
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004709 if ((pVBInfo->SetFlag & DisableChB) ||
4710 (pVBInfo->VBInfo &
4711 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004712 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004713 (pVBInfo->VBInfo &
4714 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4715 /* save Part1 index 0 */
4716 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4717 /* BTDAC = 1, avoid VB reset */
4718 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4719 /* disable CRT2 */
4720 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4721 /* restore Part1 index 0 */
4722 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304723 }
4724 } else { /* {301} */
4725 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004726 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4727 /* Disable CRT2 */
4728 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4729 /* Disable TV asPrimary VGA swap */
4730 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304731 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004732
Peter Huewea3d675c2012-02-09 21:11:47 +01004733 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304734 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004735 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304736 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004737}
4738
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004739/* --------------------------------------------------------------------- */
4740/* Function : XGI_GetTVPtrIndex */
4741/* Input : */
4742/* Output : */
4743/* Description : bx 0 : ExtNTSC */
4744/* 1 : StNTSC */
4745/* 2 : ExtPAL */
4746/* 3 : StPAL */
4747/* 4 : ExtHiTV */
4748/* 5 : StHiTV */
4749/* 6 : Ext525i */
4750/* 7 : St525i */
4751/* 8 : Ext525p */
4752/* 9 : St525p */
4753/* A : Ext750p */
4754/* B : St750p */
4755/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004756static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004757{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304758 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004759
Peter Huewe599801f2012-02-09 21:11:45 +01004760 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304761 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004762 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304763 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004764 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304765 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004766 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304767 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004768 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304769 tempbx = 10;
4770 if (pVBInfo->TVInfo & TVSimuMode)
4771 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004772
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304773 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004774}
4775
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004776/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004777/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004778/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004779/* Output : bx 0 : NTSC */
4780/* 1 : PAL */
4781/* 2 : PALM */
4782/* 3 : PALN */
4783/* 4 : NTSC1024x768 */
4784/* 5 : PAL-M 1024x768 */
4785/* 6-7: reserved */
4786/* cl 0 : YFilter1 */
4787/* 1 : YFilter2 */
4788/* ch 0 : 301A */
4789/* 1 : 301B/302B/301LV/302LV */
4790/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004791/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004792static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4793 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004794{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004795 *tempbx = 0;
4796 *tempcl = 0;
4797 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004798
Peter Huewe599801f2012-02-09 21:11:45 +01004799 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004800 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004801
Peter Huewe599801f2012-02-09 21:11:45 +01004802 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004803 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004804
Peter Huewe599801f2012-02-09 21:11:45 +01004805 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004806 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004807
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004808 if (pVBInfo->TVInfo & NTSC1024x768) {
4809 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004810 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004811 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304812 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004813
Peter Huewe6896b942012-02-09 21:11:46 +01004814 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4815 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004816 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4817 & TVSimuMode)) {
4818 *tempbx += 8;
4819 *tempcl += 1;
4820 }
4821 }
4822
Peter Huewe6896b942012-02-09 21:11:46 +01004823 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4824 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004825 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004826}
4827
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004828static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004829{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304830 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004831
Peter Huewe6896b942012-02-09 21:11:46 +01004832 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4833 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004834 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304835 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304836 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004837 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004838
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304839 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4840 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004841 if (pVBInfo->VBInfo &
4842 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004843 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004844
Peter Huewea3d675c2012-02-09 21:11:47 +01004845 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304846 tempbl = tempbh;
4847 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004848
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304849 tempbl &= 0x0F;
4850 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004851 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004852
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304853 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4854 | SetCRT2ToTV)) { /* Channel B */
4855 tempah &= 0xF0;
4856 tempah |= tempbl;
4857 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004858
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004859 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4860 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304861 tempah &= 0x0F;
4862 tempah |= tempbh;
4863 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004864 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304865 }
4866 } else if (pVBInfo->IF_DEF_LVDS == 1) {
4867 tempbl = 0;
4868 tempbh = 0;
4869 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004870 tempah = XGI301LCDDelay;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304871 tempah &= 0x0f;
4872 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004873 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304874 tempah);
4875 }
4876 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004877}
4878
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004879static void XGI_SetLCDCap_A(unsigned short tempcx,
4880 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004881{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304882 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004883
Aaro Koskinen58839b02011-03-13 12:26:23 +02004884 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004885
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304886 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004887 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004888 /* Enable Dither */
4889 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004890 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304891 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004892 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304893 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004894 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304895 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004896}
4897
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004898/* --------------------------------------------------------------------- */
4899/* Function : XGI_SetLCDCap_B */
4900/* Input : cx -> LCD Capability */
4901/* Output : */
4902/* Description : */
4903/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004904static void XGI_SetLCDCap_B(unsigned short tempcx,
4905 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004906{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304907 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004908 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304909 (unsigned short) (((tempcx & 0x00ff) >> 6)
4910 | 0x0c));
4911 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004912 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304913 (unsigned short) (((tempcx & 0x00ff) >> 6)
4914 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004915}
4916
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004917static void XGI_LongWait(struct vb_device_info *pVBInfo)
4918{
4919 unsigned short i;
4920
4921 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4922
4923 if (!(i & 0xC0)) {
4924 for (i = 0; i < 0xFFFF; i++) {
4925 if (!(inb(pVBInfo->P3da) & 0x08))
4926 break;
4927 }
4928
4929 for (i = 0; i < 0xFFFF; i++) {
4930 if ((inb(pVBInfo->P3da) & 0x08))
4931 break;
4932 }
4933 }
4934}
4935
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004936static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004937{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304938 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004939
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304940 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004941
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004942 /* disable down spectrum D[4] */
4943 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304944 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004945 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304946 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004947
Aaro Koskinen8104e322011-03-13 12:26:22 +02004948 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304949 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004950 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304951 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004952 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304953 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004954 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304955 pVBInfo->LCDCapList[index].Spectrum_34);
4956 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004957 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004958}
4959
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004960static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4961{
4962 unsigned short tempcx;
4963
4964 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4965
Peter Huewef951dd02013-02-05 00:29:47 +01004966 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4967 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004968 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004969 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004970 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004971 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004972 (unsigned char) (tempcx & 0x1F));
4973 }
4974 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004975 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004976 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4977 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4978 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004979
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004980 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4981 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004982 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004983 XGI_SetLCDCap_A(tempcx, pVBInfo);
4984
Peter Huewe6896b942012-02-09 21:11:46 +01004985 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004986 if (tempcx & EnableSpectrum)
4987 SetSpectrum(pVBInfo);
4988 }
4989 } else {
4990 /* LVDS,CH7017 */
4991 XGI_SetLCDCap_A(tempcx, pVBInfo);
4992 }
4993}
4994
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004995/* --------------------------------------------------------------------- */
4996/* Function : XGI_SetAntiFlicker */
4997/* Input : */
4998/* Output : */
4999/* Description : Set TV Customized Param. */
5000/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005001static void XGI_SetAntiFlicker(unsigned short ModeNo,
5002 unsigned short ModeIdIndex,
5003 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005004{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03005005 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005006
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305007 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005008
Peter Huewe599801f2012-02-09 21:11:45 +01005009 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305010 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005011
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305012 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5013 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305014 tempah = TVAntiFlickList[tempbx];
5015 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005016
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005017 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005018}
5019
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005020static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5021 unsigned short ModeIdIndex,
5022 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005023{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03005024 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005025
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305026 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005027
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305028 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5029 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305030 tempah = TVEdgeList[tempbx];
5031 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005032
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005033 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005034}
5035
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005036static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005037{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305038 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305040 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005041
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305042 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305044 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5045 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005046
Aaro Koskinen8104e322011-03-13 12:26:22 +02005047 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305048 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005049 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305050 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005051 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305052 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005053 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305054 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005055}
5056
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005057static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305058 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005059{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305060 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02005061 unsigned char const *filterPtr;
5062 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005063
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305064 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005065
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305066 switch (tempbx) {
5067 case 0x00:
5068 case 0x04:
5069 filterPtr = NTSCYFilter1;
5070 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005071
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305072 case 0x01:
5073 filterPtr = PALYFilter1;
5074 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305076 case 0x02:
5077 case 0x05:
5078 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305079 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005080 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305081 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005082
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305083 case 0x08:
5084 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305085 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305086 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305087 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005088 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305089 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005090
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305091 default:
5092 return;
5093 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005094
Aaro Koskinenb3979922012-11-04 21:14:52 +02005095 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305096 if (tempcl == 0)
5097 index = tempal * 4;
5098 else
5099 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305101 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005102 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5103 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5104 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5105 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305106 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005107 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5108 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5109 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5110 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305111 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005112
Peter Huewe6896b942012-02-09 21:11:46 +01005113 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5114 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005115 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5116 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5117 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305118 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005119}
5120
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005121/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005122/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005123/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005124/* Output : */
5125/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005126/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005127static void XGI_OEM310Setting(unsigned short ModeNo,
5128 unsigned short ModeIdIndex,
5129 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005130{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005131 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005132
Peter Huewea3d675c2012-02-09 21:11:47 +01005133 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005134 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005135
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005136 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005137 XGI_SetPhaseIncr(pVBInfo);
5138 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5139 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005140
Peter Huewe6896b942012-02-09 21:11:46 +01005141 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005142 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305143 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005144}
5145
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005146/* --------------------------------------------------------------------- */
5147/* Function : XGI_SetCRT2ModeRegs */
5148/* Input : */
5149/* Output : */
5150/* Description : Origin code for crt2group */
5151/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005152static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305153 struct xgi_hw_device_info *HwDeviceExtension,
5154 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005155{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305156 unsigned short tempbl;
5157 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005158
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305159 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305161 tempah = 0;
5162 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005163 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305164 tempah &= ~0x10; /* BTRAMDAC */
5165 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305167 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5168 | SetCRT2ToLCD)) {
5169 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005170 tempcl = pVBInfo->ModeType;
5171 tempcl -= ModeVGA;
5172 if (tempcl >= 0) {
5173 /* BT Color */
5174 tempah = (0x008 >> tempcl);
5175 if (tempah == 0)
5176 tempah = 1;
5177 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305178 }
5179 if (pVBInfo->VBInfo & SetInSlaveMode)
5180 tempah ^= 0x50; /* BTDAC */
5181 }
5182 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005183
Aaro Koskinen8104e322011-03-13 12:26:22 +02005184 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305185 tempah = 0x08;
5186 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005187
Miguel Gómeze123e462012-07-06 12:40:52 +02005188 if (pVBInfo->VBInfo & DisableCRT2Display)
5189 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005190
Miguel Gómeze123e462012-07-06 12:40:52 +02005191 tempah = 0x00;
5192 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005193
Miguel Gómeze123e462012-07-06 12:40:52 +02005194 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5195 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5196 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005197
Miguel Gómeze123e462012-07-06 12:40:52 +02005198 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5199 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5200 tempbl &= 0xf7;
5201 tempah |= 0x01;
5202 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305203 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005204
Miguel Gómeze123e462012-07-06 12:40:52 +02005205 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5206 tempbl &= 0xf7;
5207 tempah |= 0x01;
5208 }
5209
5210 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5211 goto reg_and_or;
5212
5213 tempbl &= 0xf8;
5214 tempah = 0x01;
5215
5216 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5217 tempah |= 0x02;
5218
5219 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5220 tempah = tempah ^ 0x05;
5221 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5222 tempah = tempah ^ 0x01;
5223 }
5224
5225 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5226 tempah |= 0x08;
5227
5228reg_and_or:
5229 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5230
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305231 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005232 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305233 tempah &= (~0x08);
5234 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5235 & SetInSlaveMode))) {
5236 tempah |= 0x010;
5237 }
5238 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305240 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305241 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005242 if (pVBInfo->VBInfo & DriverMode)
5243 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305244 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005245
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005246 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305247 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305249 if (pVBInfo->LCDInfo & SetLCDDualLink)
5250 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305252 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305253 if (pVBInfo->TVInfo & RPLLDIV2XO)
5254 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305255 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005256
Peter Huewe255aabd2012-02-09 21:11:44 +01005257 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5258 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305259 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005260
Peter Huewe255aabd2012-02-09 21:11:44 +01005261 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305262 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005263
Aaro Koskinen8104e322011-03-13 12:26:22 +02005264 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305265 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005266
Peter Huewe6896b942012-02-09 21:11:46 +01005267 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5268 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305269 tempah = 0;
5270 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005271
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305272 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5273 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005274 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305275 tempah |= 0x04; /* shampoo 0129 */
5276 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005277
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005278 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305279 tempah = 0x00;
5280 tempbl = 0xcf;
5281 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5282 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5283 tempah |= 0x30;
5284 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005285
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005286 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305287 tempah = 0;
5288 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305290 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5291 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5292 tempah |= 0xc0;
5293 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005294 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305295 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305297 tempah = 0;
5298 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005299 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305300 tempbl = 0xff;
5301 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5302 tempah |= 0x80;
5303 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005304
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005305 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005306
Peter Huewe6896b942012-02-09 21:11:46 +01005307 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305308 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005309 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5310 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305311 }
5312 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005313}
5314
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005315
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305316void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5317 struct vb_device_info *pVBInfo)
5318{
5319
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005320 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005321
5322}
5323
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305324void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5325 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005326{
5327
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005328 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005329
5330}
5331
Bill Pemberton80adad82010-06-17 13:10:51 -04005332unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005333{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305334 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305336 if (pVBInfo->IF_DEF_LVDS == 1) {
5337 return 1;
5338 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005339 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305340 if ((flag == 1) || (flag == 2))
5341 return 1; /* 301b */
5342 else
5343 return 0;
5344 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005345}
5346
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005347unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5348 unsigned short ModeNo, unsigned short ModeIdIndex,
5349 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005350{
Peter Huewef2c22602013-02-03 22:54:30 +01005351 const u8 LCDARefreshIndex[] = {
5352 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005353
Peter Hueweef9a6b92013-02-03 04:08:43 +01005354 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005355
Aaro Koskinen58839b02011-03-13 12:26:23 +02005356 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005357 index = index >> pVBInfo->SelectCRT2Rate;
5358 index &= 0x0F;
5359
5360 if (pVBInfo->LCDInfo & LCDNonExpanding)
5361 index = 0;
5362
5363 if (index > 0)
5364 index--;
5365
5366 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005367 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005368 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewef2c22602013-02-03 22:54:30 +01005369 temp = LCDARefreshIndex[
5370 pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005371
5372 if (index > temp)
5373 index = temp;
5374 } else {
5375 index = 0;
5376 }
5377 }
5378 }
5379
Aaro Koskinenb3979922012-11-04 21:14:52 +02005380 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005381 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005382 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005383 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5384 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005385 index++;
5386 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005387 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005388 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5389 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005390 index++;
5391 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005392 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5393 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005394 index++;
5395 }
5396 }
5397
5398 i = 0;
5399 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005400 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005401 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005402 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005403 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005404 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005405 if (temp < pVBInfo->ModeType)
5406 break;
5407 i++;
5408 index--;
5409
5410 } while (index != 0xFFFF);
5411 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5412 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005413 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005414 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005415 if (temp & InterlaceMode)
5416 i++;
5417 }
5418 }
5419 i--;
5420 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5421 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5422 RefreshRateTableIndex, &i, pVBInfo);
5423 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005424 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005425}
5426
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005427static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305428 struct xgi_hw_device_info *HwDeviceExtension,
5429 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005430{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005431 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005432
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005433 pVBInfo->SetFlag |= ProgrammingCRT2;
5434 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5435 ModeIdIndex, pVBInfo);
5436 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5437 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5438 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5439 HwDeviceExtension, pVBInfo);
5440 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5441 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005442}
5443
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005444static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005445 struct xgi_hw_device_info *HwDeviceExtension,
5446 struct vb_device_info *pVBInfo)
5447{
Peter Huewea9e29e62013-02-03 04:08:44 +01005448 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005449
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005450 pVBInfo->SetFlag |= ProgrammingCRT2;
5451 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5452 pVBInfo->SelectCRT2Rate = 4;
5453 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5454 ModeIdIndex, pVBInfo);
5455 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5456 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5457 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5458 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5459 RefreshRateTableIndex, pVBInfo);
5460 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5461 RefreshRateTableIndex, pVBInfo);
5462 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5463 RefreshRateTableIndex, pVBInfo);
5464 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5465 HwDeviceExtension, pVBInfo);
5466 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5467 RefreshRateTableIndex, pVBInfo);
5468 XGI_SetTap4Regs(pVBInfo);
5469 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5470 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5471 HwDeviceExtension, pVBInfo);
5472 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5473 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5474 XGI_AutoThreshold(pVBInfo);
5475 return 1;
5476}
5477
5478void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5479{
5480 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5481 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5482 0x05, 0x00 };
5483
5484 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5485
5486 unsigned char CR17, CR63, SR31;
5487 unsigned short temp;
5488 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
5489
5490 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005491 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005492
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005493 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005494 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005495 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005496 pVBInfo->P3d4, 0x53) | 0x02));
5497
Aaro Koskinen58839b02011-03-13 12:26:23 +02005498 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
5499 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
5500 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005501
Aaro Koskinen8104e322011-03-13 12:26:22 +02005502 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5503 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005504
Aaro Koskinen58839b02011-03-13 12:26:23 +02005505 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005506 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005507
Aaro Koskinen58839b02011-03-13 12:26:23 +02005508 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005509 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005510
Aaro Koskinen58839b02011-03-13 12:26:23 +02005511 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005512 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02005513 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005514 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005515
Aaro Koskinen8104e322011-03-13 12:26:22 +02005516 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005517
5518 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005519 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005520
5521 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005522 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005523 CRTCData[i]);
5524
5525 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005526 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005527 CRTCData[i]);
5528
5529 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005530 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005531 CRTCData[i]);
5532
Aaro Koskinen8104e322011-03-13 12:26:22 +02005533 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005534 & 0xE0));
5535
Aaro Koskinen8104e322011-03-13 12:26:22 +02005536 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5537 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5538 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005539
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005540 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005541
5542 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005543 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
5544 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
5545 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005546 }
5547
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005548 mdelay(1);
5549
5550 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005551 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005552
5553 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005554 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005555 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005556 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005557
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005558 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005559 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005560
5561 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005562 outb(0, (pVBInfo->P3c8 + 1));
5563 outb(0, (pVBInfo->P3c8 + 1));
5564 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005565 }
5566
Aaro Koskinen8104e322011-03-13 12:26:22 +02005567 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5568 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5569 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005570
Aaro Koskinen58839b02011-03-13 12:26:23 +02005571 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005572 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005573 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005574}
5575
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005576static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5577 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005578 struct vb_device_info *pVBInfo)
5579{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005580 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005581
Peter Huewe6896b942012-02-09 21:11:46 +01005582 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5583 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005584 if (!(pVBInfo->SetFlag & DisableChA)) {
5585 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005586 /* Power on */
5587 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03005588 } else if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5589 /* Power on */
5590 xgifb_reg_set(pVBInfo->Part1Port,
5591 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005592 }
5593 }
5594
5595 if (!(pVBInfo->SetFlag & DisableChB)) {
5596 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5597 & (SetCRT2ToLCD | SetCRT2ToTV
5598 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005599 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005600 pVBInfo->P3c4, 0x32);
5601 tempah &= 0xDF;
5602 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005603 if (!(pVBInfo->VBInfo &
5604 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005605 tempah |= 0x20;
5606 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005607 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005608 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005609
Aaro Koskinen58839b02011-03-13 12:26:23 +02005610 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005611 pVBInfo->Part1Port, 0x2E);
5612
5613 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005614 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005615 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005616 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005617 }
5618 }
5619
5620 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
5621 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005622 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005623 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005624 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Peter Huewe06cc47b2013-02-03 22:54:38 +01005625 if (!XGI_EnableChISLCD(pVBInfo, false)) {
5626 if (XGI_EnableChISLCD(pVBInfo, true) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005627 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01005628 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005629 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02005630 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005631 pVBInfo->Part4Port,
5632 0x2A,
5633 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005634 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005635 /* LVDS Driver power on */
5636 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005637 }
5638 }
5639
5640 tempah = 0x00;
5641
5642 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5643 tempah = 0xc0;
5644
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005645 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5646 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5647 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5648 tempah = tempah & 0x40;
5649 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5650 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005651
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005652 if (pVBInfo->SetFlag & DisableChB)
5653 tempah &= 0xBF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005654
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005655 if (pVBInfo->SetFlag & DisableChA)
5656 tempah &= 0x7F;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005657
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005658 if (pVBInfo->SetFlag & EnableChB)
5659 tempah |= 0x40;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005660
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005661 if (pVBInfo->SetFlag & EnableChA)
5662 tempah |= 0x80;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005663 }
5664 }
5665
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005666 /* EnablePart4_1F */
5667 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005668
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005669 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005670 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005671 XGI_DisableGatingCRT(HwDeviceExtension,
5672 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005673 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
5674 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005675 }
5676 }
5677 } /* 301 */
5678 else { /* LVDS */
5679 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005680 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005681 /* enable CRT2 */
5682 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005683
Aaro Koskinen58839b02011-03-13 12:26:23 +02005684 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005685 0x2E);
5686 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005687 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005688
Aaro Koskinendc505562011-03-13 12:26:26 +02005689 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005690 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005691 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005692}
5693
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005694static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5695 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005696 unsigned short ModeNo, unsigned short ModeIdIndex,
5697 struct vb_device_info *pVBInfo)
5698{
Aaro Koskinena1579612012-04-07 01:14:05 +03005699 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005700
Aaro Koskinena1579612012-04-07 01:14:05 +03005701 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005702 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005703 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5704 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5705 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005706 XGI_ClearExt1Regs(pVBInfo);
5707
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005708 if (HwDeviceExtension->jChipType == XG27) {
5709 if (pVBInfo->IF_DEF_LVDS == 0)
5710 XGI_SetDefaultVCLK(pVBInfo);
5711 }
5712
5713 temp = ~ProgrammingCRT2;
5714 pVBInfo->SetFlag &= temp;
5715 pVBInfo->SelectCRT2Rate = 0;
5716
Peter Huewe6896b942012-02-09 21:11:46 +01005717 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5718 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005719 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005720 | SetInSlaveMode)) {
5721 pVBInfo->SetFlag |= ProgrammingCRT2;
5722 }
5723 }
5724
5725 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5726 ModeIdIndex, pVBInfo);
5727 if (RefreshRateTableIndex != 0xFFFF) {
5728 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5729 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5730 pVBInfo, HwDeviceExtension);
5731 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5732 RefreshRateTableIndex, pVBInfo);
5733 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5734 HwDeviceExtension, pVBInfo);
5735 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5736 RefreshRateTableIndex, pVBInfo);
5737 }
5738
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005739 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005740 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005741 if (temp & 0xA0) {
5742
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005743 if (HwDeviceExtension->jChipType == XG27)
5744 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5745 RefreshRateTableIndex, pVBInfo);
5746 else
5747 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5748 RefreshRateTableIndex, pVBInfo);
5749
5750 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5751 RefreshRateTableIndex);
5752
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005753 xgifb_set_lcd(HwDeviceExtension->jChipType,
5754 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005755
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005756 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005757 xgifb_set_lvds(xgifb_info,
5758 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005759 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005760 }
5761 }
5762
5763 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5764 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5765 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5766 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005767 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005768}
5769
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005770unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5771 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005772 unsigned short ModeNo)
5773{
5774 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005775 struct vb_device_info VBINF;
5776 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005777 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005778
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005779 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005780 pVBInfo->IF_DEF_YPbPr = 0;
5781 pVBInfo->IF_DEF_HiVision = 0;
5782 pVBInfo->IF_DEF_CRT2Monitor = 0;
5783 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005784 } else {
5785 pVBInfo->IF_DEF_YPbPr = 1;
5786 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005787 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005788 }
5789
Aaro Koskinen56810a92013-01-21 02:57:47 +02005790 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005791
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005792 /* for x86 Linux, XG21 LVDS */
5793 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005794 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005795 pVBInfo->IF_DEF_LVDS = 1;
5796 }
5797 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005798 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5799 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005800 pVBInfo->IF_DEF_LVDS = 1;
5801 }
5802 }
5803
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005804 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005805 XGI_GetVBType(pVBInfo);
5806
5807 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005808 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005809 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005810 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005811
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005812 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005813 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
5814
5815 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5816
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005817 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005818 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
5819 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
5820 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005821 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005822
Peter Huewee44adfd2013-02-03 22:54:39 +01005823 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5824 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005825 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005826 ModeIdIndex, pVBInfo);
5827
Peter Huewea3d675c2012-02-09 21:11:47 +01005828 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005829 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5830 HwDeviceExtension, pVBInfo);
5831 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005832 }
5833
Peter Huewe6896b942012-02-09 21:11:46 +01005834 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005835 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005836 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005837 case VB_CHIP_302:
5838 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5839 pVBInfo); /*add for CRT2 */
5840 break;
5841
5842 default:
5843 break;
5844 }
5845 }
5846
5847 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
5848 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005849 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005850 } /* !XG20 */
5851 else {
5852 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005853 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005854 ModeIdIndex,
5855 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005856 return 0;
5857
Aaro Koskinenb3979922012-11-04 21:14:52 +02005858 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005859 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005860
5861 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005862 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005863
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005864 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005865
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005866 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5867 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005868
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005869 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005870 }
5871
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005872 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
5873
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005874 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005875 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005876
5877 return 1;
5878}