blob: c5faa8984f1ba04f2644de02ee617c5ed4cc6b5b [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
868 if (pVBInfo->IF_DEF_LVDS == 0) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200869 if (pVBInfo->VBInfo &
870 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
Peter Huewe255aabd2012-02-09 21:11:44 +0100871 if (pVBInfo->LCDResInfo != Panel_1024x768)
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200872 /* LCDXlat2VCLK */
873 VCLKIndex = VCLK108_2_315 + 5;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200874 else
Peter Huewef477d3e2012-06-14 00:21:47 +0200875 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
Peter Huewe599801f2012-02-09 21:11:45 +0100876 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200877 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200878 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200879 else
Peter Huewe95072592012-06-14 00:21:48 +0200880 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200881
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200882 if (pVBInfo->SetFlag & TVSimuMode) {
883 if (modeflag & Charx8Dot) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200884 VCLKIndex = TVCLKBASE_315_25 +
885 HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200886 } else {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200887 VCLKIndex = TVCLKBASE_315_25 +
888 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200889 }
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200890 }
891
892 /* 301lv */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300893 if (pVBInfo->VBType & VB_SIS301LV) {
894 if (pVBInfo->SetFlag & RPLLDIV2XO)
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200895 VCLKIndex = YPbPr525iVCLK_2;
896 else
897 VCLKIndex = YPbPr525iVCLK;
898 }
899 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200900 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200901 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200902 else
Peter Huewe95072592012-06-14 00:21:48 +0200903 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200904 } else { /* for CRT2 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300905 /* di+Ext_CRTVCLK */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200906 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800907 Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300908 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200909 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300910 } else if ((pVBInfo->LCDResInfo == Panel_800x600) ||
911 (pVBInfo->LCDResInfo == Panel_320x480)) { /* LVDS */
912 VCLKIndex = VCLK40; /* LVDSXlat1VCLK */
913 } else {
914 VCLKIndex = VCLK65_315 + 2; /* LVDSXlat2VCLK, LVDSXlat3VCLK */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200915 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200916
917 return VCLKIndex;
918}
919
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800920static void XGI_SetCRT1VCLK(unsigned short ModeNo,
921 unsigned short ModeIdIndex,
922 struct xgi_hw_device_info *HwDeviceExtension,
923 unsigned short RefreshRateTableIndex,
924 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200925{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400926 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530927 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530929 if (pVBInfo->IF_DEF_LVDS == 1) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200930 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
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 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
934 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200935 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +0100936 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
937 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +0100938 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530939 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
940 RefreshRateTableIndex, HwDeviceExtension,
941 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200942 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200943 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200944 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200945 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200946 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200947 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
948 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530949 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200950 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200951 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200952 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200953 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
954 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200955 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530956 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530958 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200959 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800960 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200961 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200962 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200963 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530964 index = data;
965 index &= 0xE0;
966 data &= 0x1F;
967 data = data << 1;
968 data += 1;
969 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200970 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530971 }
972 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200973}
974
Aaro Koskinene85f2032011-11-27 23:03:07 +0200975static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
976{
977 unsigned char temp;
978
979 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
980 temp = (temp & 1) << 6;
981 /* SR06[6] 18bit Dither */
982 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
983 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
984 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
985
986}
987
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200988static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530989 struct xgi_hw_device_info *HwDeviceExtension,
990 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200991{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530992 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200993
Aaro Koskinen58839b02011-03-13 12:26:23 +0200994 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530995 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200996 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200997
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300998 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
999 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1000 data &= 0xC0;
1001 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1002 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1003 data |= 0x01;
1004 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001005
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301006 if (HwDeviceExtension->jChipType == XG21)
1007 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001008}
1009
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001010static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1011 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1012 struct vb_device_info *pVBInfo)
1013{
1014 unsigned short data, data2 = 0;
1015 short VCLK;
1016
1017 unsigned char index;
1018
Aaro Koskinena39325d2012-11-04 21:14:53 +02001019 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001020 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +02001021 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001022
Aaro Koskinen58839b02011-03-13 12:26:23 +02001023 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001024 data &= 0xf3;
1025 if (VCLK >= 200)
1026 data |= 0x0c; /* VCLK > 200 */
1027
1028 if (HwDeviceExtension->jChipType >= XG20)
1029 data &= ~0x04; /* 2 pixel mode */
1030
Aaro Koskinen8104e322011-03-13 12:26:22 +02001031 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001032
1033 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001034 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001035 data &= 0xE7;
1036 if (VCLK < 200)
1037 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001038 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001039 }
1040
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001041 data2 = 0x00;
1042
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001043 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001044 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001045 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001046
1047}
1048
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001049static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301050 unsigned short ModeNo, unsigned short ModeIdIndex,
1051 unsigned short RefreshRateTableIndex,
1052 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001053{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301054 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1055 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001056
Aaro Koskinenb3979922012-11-04 21:14:52 +02001057 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001058 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001059
Aaro Koskinen58839b02011-03-13 12:26:23 +02001060 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001061 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001062
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001063 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301064 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001065 data2 |= 0x02;
1066 data3 = pVBInfo->ModeType - ModeVGA;
1067 data3 = data3 << 2;
1068 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301069 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301071 if (data)
1072 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001073
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001074 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001075 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001076 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301078 data = 0x0000;
1079 if (infoflag & InterlaceMode) {
1080 if (xres == 1024)
1081 data = 0x0035;
1082 else if (xres == 1280)
1083 data = 0x0048;
1084 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001085
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001086 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1087 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301089 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001090 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301092 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001093
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301094 if (modeflag & LineCompareOff)
1095 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001096
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001097 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301098 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001099 data = data ^ 0x60;
1100 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001101 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001102
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301103 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1104 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001105
Aaro Koskinen58839b02011-03-13 12:26:23 +02001106 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001107
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301108 if (HwDeviceExtension->jChipType == XG27) {
1109 if (data & 0x40)
1110 data = 0x2c;
1111 else
1112 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001113 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001114 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301115 } else if (HwDeviceExtension->jChipType >= XG20) {
1116 if (data & 0x40)
1117 data = 0x33;
1118 else
1119 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001120 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1121 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301122 } else {
1123 if (data & 0x40)
1124 data = 0x2c;
1125 else
1126 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001127 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301128 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001129
1130}
1131
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001132static void XGI_WriteDAC(unsigned short dl,
1133 unsigned short ah,
1134 unsigned short al,
1135 unsigned short dh,
1136 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001137{
1138 unsigned short temp, bh, bl;
1139
1140 bh = ah;
1141 bl = al;
1142
1143 if (dl != 0) {
1144 temp = bh;
1145 bh = dh;
1146 dh = temp;
1147 if (dl == 1) {
1148 temp = bl;
1149 bl = dh;
1150 dh = temp;
1151 } else {
1152 temp = bl;
1153 bl = bh;
1154 bh = temp;
1155 }
1156 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001157 outb((unsigned short) dh, pVBInfo->P3c9);
1158 outb((unsigned short) bh, pVBInfo->P3c9);
1159 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001160}
1161
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001162static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301163 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001164{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001165 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1166 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001167
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001168 outb(0xFF, pVBInfo->P3c6);
1169 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001170
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001171 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301172 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301174 for (k = 0; k < 3; k++) {
1175 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001176
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301177 if (data & 0x01)
1178 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301180 if (data & 0x02)
1181 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001182
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001183 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301184 data = data >> 2;
1185 }
1186 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001187
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001188 for (i = 16; i < 32; i++) {
1189 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001190
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001191 for (k = 0; k < 3; k++)
1192 outb(data, pVBInfo->P3c9);
1193 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001194
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001195 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001196
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001197 for (m = 0; m < 9; m++) {
1198 di = si;
1199 bx = si + 0x04;
1200 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001201
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001202 for (n = 0; n < 3; n++) {
1203 for (o = 0; o < 5; o++) {
1204 dh = table[si];
1205 ah = table[di];
1206 al = table[bx];
1207 si++;
1208 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301209 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001210
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001211 si -= 2;
1212
1213 for (o = 0; o < 3; o++) {
1214 dh = table[bx];
1215 ah = table[di];
1216 al = table[si];
1217 si--;
1218 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1219 }
1220
1221 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301222 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001223
1224 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301225 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001226}
1227
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001228static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1229 unsigned short ModeIdIndex,
1230 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001231{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301232 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001233
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001234 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001235 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001236
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001237 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001238 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001239
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001240 xres = XGI330_ModeResInfo[resindex].HTotal;
1241 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001242
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001243 if (modeflag & HalfDCLK)
1244 xres = xres << 1;
1245
1246 if (modeflag & DoubleScanMode)
1247 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301249 if (xres == 720)
1250 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301252 pVBInfo->VGAHDE = xres;
1253 pVBInfo->HDE = xres;
1254 pVBInfo->VGAVDE = yres;
1255 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001256}
1257
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001258static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001259 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001260 unsigned short ModeIdIndex,
1261 unsigned short RefreshRateTableIndex,
1262 struct vb_device_info *pVBInfo)
1263{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001264 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001265
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001266 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001267
Aaro Koskinenb3979922012-11-04 21:14:52 +02001268 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001269
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001270 i = 0;
1271
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001272 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001273 tempdx = pVBInfo->LCDResInfo;
1274 if (tempbx & 0x0080) { /* OEMUtil */
1275 tempbx &= (~0x0080);
1276 tempdx = pVBInfo->LCDTypeInfo;
1277 }
1278
1279 if (pVBInfo->LCDInfo & EnableScalingLCD)
1280 tempdx &= (~PanelResInfo);
1281
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001282 if (table[i].PANELID == tempdx) {
1283 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001284 tempdx = pVBInfo->LCDInfo;
1285
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001286 if (modeflag & HalfDCLK)
1287 tempdx |= SetLCDLowResolution;
1288
1289 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001290 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001291 break;
1292 }
1293 i++;
1294 }
1295
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001296 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001297}
1298
Aaro Koskinen24572542012-09-11 00:15:21 +03001299static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001300 unsigned short ModeIdIndex,
1301 unsigned short RefreshRateTableIndex,
1302 struct vb_device_info *pVBInfo)
1303{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001304 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001305
Aaro Koskinenb3979922012-11-04 21:14:52 +02001306 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001307 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001308 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001309 tempdx = pVBInfo->TVInfo;
1310
1311 if (pVBInfo->VBInfo & SetInSlaveMode)
1312 tempdx = tempdx | SetTVLockMode;
1313
1314 if (modeflag & HalfDCLK)
1315 tempdx = tempdx | SetTVLowResolution;
1316
1317 i = 0;
1318
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001319 while (XGI_TVDataTable[i].MASK != 0xffff) {
1320 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1321 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001322 break;
1323 i++;
1324 }
1325
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001326 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001327}
1328
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001329static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301330 unsigned short RefreshRateTableIndex,
1331 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001332{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001333 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001334
Aaro Koskinen6008f872012-11-04 21:14:49 +02001335 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1336 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001337
Aaro Koskinen6008f872012-11-04 21:14:49 +02001338 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1339 RefreshRateTableIndex, pVBInfo);
1340 pVBInfo->VGAHT = LCDPtr->VGAHT;
1341 pVBInfo->VGAVT = LCDPtr->VGAVT;
1342 pVBInfo->HT = LCDPtr->LCDHT;
1343 pVBInfo->VT = LCDPtr->LCDVT;
1344
1345 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1346 return;
1347
1348 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1349 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1350 pVBInfo->HDE = 1024;
1351 pVBInfo->VDE = 768;
1352 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1353 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1354 pVBInfo->HDE = 1280;
1355 pVBInfo->VDE = 1024;
1356 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1357 pVBInfo->HDE = 1400;
1358 pVBInfo->VDE = 1050;
1359 } else {
1360 pVBInfo->HDE = 1600;
1361 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301362 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001363}
1364
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001365static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301366 unsigned short RefreshRateTableIndex,
1367 struct xgi_hw_device_info *HwDeviceExtension,
1368 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001369{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001370 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001371 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1372 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001373
Peter Huewea3d675c2012-02-09 21:11:47 +01001374 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001375 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001376 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001377
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001378 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001379 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301380 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001381
1382 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1383
Peter Huewea3d675c2012-02-09 21:11:47 +01001384 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001385 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1386 ModeIdIndex, RefreshRateTableIndex,
1387 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001388 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001389 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001390 }
1391
1392 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001393}
1394
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001395static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1396{
1397 unsigned char tempal, tempah, tempbl, i;
1398
Aaro Koskinen58839b02011-03-13 12:26:23 +02001399 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001400 tempal = tempah & 0x0F;
1401 tempah = tempah & 0xF0;
1402 i = 0;
1403 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1404
1405 while (tempbl != 0xFF) {
1406 if (tempbl & 0x80) { /* OEMUtil */
1407 tempal = tempah;
1408 tempbl = tempbl & ~(0x80);
1409 }
1410
1411 if (tempal == tempbl)
1412 break;
1413
1414 i++;
1415
1416 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1417 }
1418
1419 return i;
1420}
1421
1422static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1423{
1424 unsigned short tempah, tempal, tempbl, i;
1425
1426 tempal = pVBInfo->LCDResInfo;
1427 tempah = pVBInfo->LCDTypeInfo;
1428
1429 i = 0;
1430 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1431
1432 while (tempbl != 0xFF) {
1433 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1434 tempal = tempah;
1435 tempbl &= ~0x80;
1436 }
1437
1438 if (tempal == tempbl)
1439 break;
1440
1441 i++;
1442 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1443 }
1444
1445 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001446 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001447 pVBInfo->LCDTypeInfo = 0;
1448 i = 0;
1449 }
1450
1451 return i;
1452}
1453
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001454static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1455 unsigned short *VSyncWidth,
1456 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001457{
1458 unsigned short Index;
1459
1460 Index = XGI_GetLCDCapPtr(pVBInfo);
1461 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1462 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1463
1464 return;
1465}
1466
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001467static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301468 unsigned short RefreshRateTableIndex,
1469 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001470{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301471 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1472 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001473 struct XGI_LCDDesStruct const *LCDPtr = NULL;
1474 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001475
Aaro Koskinenb3979922012-11-04 21:14:52 +02001476 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen66cface2011-08-31 21:46:13 +03001477 if (pVBInfo->LCDInfo & EnableScalingLCD)
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001478 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1479 ModeIdIndex, RefreshRateTableIndex,
1480 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03001481 else
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001482 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1483 ModeIdIndex, RefreshRateTableIndex,
1484 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001485
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001486 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1487 push1 = tempbx;
1488 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001489
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001490 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001491 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1492 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001493 tempax = 1024;
1494 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001495 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1496 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001497 tempax = 1280;
1498 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001499 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001500 tempax = 1400;
1501 tempbx = 1050;
1502 } else {
1503 tempax = 1600;
1504 tempbx = 1200;
1505 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001506
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001507 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1508 pVBInfo->HDE = tempax;
1509 pVBInfo->VDE = tempbx;
1510 pVBInfo->VGAHDE = tempax;
1511 pVBInfo->VGAVDE = tempbx;
1512 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001513
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001514 tempax = pVBInfo->HT;
1515
1516 if (pVBInfo->LCDInfo & EnableScalingLCD)
1517 tempbx = LCDPtr1->LCDHDES;
1518 else
1519 tempbx = LCDPtr->LCDHDES;
1520
1521 tempcx = pVBInfo->HDE;
1522 tempbx = tempbx & 0x0fff;
1523 tempcx += tempbx;
1524
1525 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001526 tempcx -= tempax;
1527
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001528 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001529
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001530 tempcx = tempcx >> 3;
1531 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001532
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001533 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1534 (unsigned short) (tempbx & 0xff));
1535 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1536 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001537
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001538 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001539
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001540 if (pVBInfo->LCDInfo & EnableScalingLCD)
1541 tempbx = LCDPtr1->LCDHRS;
1542 else
1543 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001544
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001545 tempcx = push2;
1546
1547 if (pVBInfo->LCDInfo & EnableScalingLCD)
1548 tempcx = LCDPtr1->LCDHSync;
1549
1550 tempcx += tempbx;
1551
1552 if (tempcx >= tempax)
1553 tempcx -= tempax;
1554
1555 tempax = tempbx & 0x07;
1556 tempax = tempax >> 5;
1557 tempcx = tempcx >> 3;
1558 tempbx = tempbx >> 3;
1559
1560 tempcx &= 0x1f;
1561 tempax |= tempcx;
1562
1563 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1564 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1565 (unsigned short) (tempbx & 0xff));
1566
1567 tempax = pVBInfo->VT;
1568 if (pVBInfo->LCDInfo & EnableScalingLCD)
1569 tempbx = LCDPtr1->LCDVDES;
1570 else
1571 tempbx = LCDPtr->LCDVDES;
1572 tempcx = pVBInfo->VDE;
1573
1574 tempbx = tempbx & 0x0fff;
1575 tempcx += tempbx;
1576 if (tempcx >= tempax)
1577 tempcx -= tempax;
1578
1579 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1580 (unsigned short) (tempbx & 0xff));
1581 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1582 (unsigned short) (tempcx & 0xff));
1583
1584 tempbx = (tempbx >> 8) & 0x07;
1585 tempcx = (tempcx >> 8) & 0x07;
1586
1587 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1588 (unsigned short) ((tempcx << 3)
1589 | tempbx));
1590
1591 tempax = pVBInfo->VT;
1592 if (pVBInfo->LCDInfo & EnableScalingLCD)
1593 tempbx = LCDPtr1->LCDVRS;
1594 else
1595 tempbx = LCDPtr->LCDVRS;
1596
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001597 tempcx = push1;
1598
1599 if (pVBInfo->LCDInfo & EnableScalingLCD)
1600 tempcx = LCDPtr1->LCDVSync;
1601
1602 tempcx += tempbx;
1603 if (tempcx >= tempax)
1604 tempcx -= tempax;
1605
1606 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1607 (unsigned short) (tempbx & 0xff));
1608 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1609 (unsigned short) (tempcx & 0x0f));
1610
1611 tempax = ((tempbx >> 8) & 0x07) << 3;
1612
1613 tempbx = pVBInfo->VGAVDE;
1614 if (tempbx != pVBInfo->VDE)
1615 tempax |= 0x40;
1616
Peter Huewea3d675c2012-02-09 21:11:47 +01001617 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001618 tempax |= 0x40;
1619
1620 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1621 tempax);
1622
1623 tempcx = pVBInfo->VGAVT;
1624 tempbx = pVBInfo->VDE;
1625 tempax = pVBInfo->VGAVDE;
1626 tempcx -= tempax;
1627
1628 temp = tempax; /* 0430 ylshieh */
1629 temp1 = (temp << 18) / tempbx;
1630
1631 tempdx = (unsigned short) ((temp << 18) % tempbx);
1632
1633 if (tempdx != 0)
1634 temp1 += 1;
1635
1636 temp2 = temp1;
1637 push3 = temp2;
1638
1639 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1640 (unsigned short) (temp2 & 0xff));
1641 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1642 (unsigned short) ((temp2 >> 8) & 0xff));
1643
1644 tempbx = (unsigned short) (temp2 >> 16);
1645 tempax = tempbx & 0x03;
1646
1647 tempbx = pVBInfo->VGAVDE;
1648 if (tempbx == pVBInfo->VDE)
1649 tempax |= 0x04;
1650
1651 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1652
1653 if (pVBInfo->VBType & VB_XGI301C) {
1654 temp2 = push3;
1655 xgifb_reg_set(pVBInfo->Part4Port,
1656 0x3c,
1657 (unsigned short) (temp2 & 0xff));
1658 xgifb_reg_set(pVBInfo->Part4Port,
1659 0x3b,
1660 (unsigned short) ((temp2 >> 8) &
1661 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001662 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001663 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1664 ~0xc0,
1665 (unsigned short) ((tempbx &
1666 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001667
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001668 tempcx = pVBInfo->VGAVDE;
1669 if (tempcx == pVBInfo->VDE)
1670 xgifb_reg_and_or(pVBInfo->Part4Port,
1671 0x30, ~0x0c, 0x00);
1672 else
1673 xgifb_reg_and_or(pVBInfo->Part4Port,
1674 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301675 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001676
1677 tempcx = pVBInfo->VGAHDE;
1678 tempbx = pVBInfo->HDE;
1679
1680 temp1 = tempcx << 16;
1681
1682 tempax = (unsigned short) (temp1 / tempbx);
1683
1684 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1685 tempax = 65535;
1686
1687 temp3 = tempax;
1688 temp1 = pVBInfo->VGAHDE << 16;
1689
1690 temp1 /= temp3;
1691 temp3 = temp3 << 16;
1692 temp1 -= 1;
1693
1694 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1695
1696 tempax = (unsigned short) (temp3 & 0xff);
1697 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1698
1699 temp1 = pVBInfo->VGAVDE << 18;
1700 temp1 = temp1 / push3;
1701 tempbx = (unsigned short) (temp1 & 0xffff);
1702
Peter Huewe255aabd2012-02-09 21:11:44 +01001703 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001704 tempbx -= 1;
1705
1706 tempax = ((tempbx >> 8) & 0xff) << 3;
1707 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1708 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1709 (unsigned short) (tempax & 0xff));
1710 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1711 (unsigned short) (tempbx & 0xff));
1712
1713 temp3 = temp3 >> 16;
1714
1715 if (modeflag & HalfDCLK)
1716 temp3 = temp3 >> 1;
1717
1718 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1719 (unsigned short) ((temp3 >> 8) & 0xff));
1720 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1721 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001722}
1723
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001724/* --------------------------------------------------------------------- */
1725/* Function : XGI_GETLCDVCLKPtr */
1726/* Input : */
1727/* Output : al -> VCLK Index */
1728/* Description : */
1729/* --------------------------------------------------------------------- */
1730static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1731 struct vb_device_info *pVBInfo)
1732{
1733 unsigned short index;
1734
Peter Huewea3d675c2012-02-09 21:11:47 +01001735 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001736 index = XGI_GetLCDCapPtr1(pVBInfo);
1737
1738 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1739 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1740 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1741 } else { /* LCDA */
1742 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1743 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1744 }
1745 }
1746 return;
1747}
1748
1749static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1750 unsigned short ModeNo, unsigned short ModeIdIndex,
1751 struct vb_device_info *pVBInfo)
1752{
1753
1754 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001755 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001756
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001757 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001758 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001759
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001760 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1761 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001762 index = XGI_GetLCDCapPtr(pVBInfo);
1763 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1764
Peter Huewea3d675c2012-02-09 21:11:47 +01001765 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001766 return tempal;
1767
1768 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001769 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001770 (VB_SIS301B |
1771 VB_SIS302B |
1772 VB_SIS301LV |
1773 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001774 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001775 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001776 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001777 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001778 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001779 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001780 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001781 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001782 tempal = TVCLKBASE_315 +
1783 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001784
1785 }
1786 return tempal;
1787 }
1788
Peter Huewe599801f2012-02-09 21:11:45 +01001789 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001790 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001791 return tempal;
1792 }
1793
Peter Huewe599801f2012-02-09 21:11:45 +01001794 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001795 tempal = YPbPr525pVCLK;
1796 return tempal;
1797 }
1798
1799 tempal = NTSC1024VCLK;
1800
1801 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001802 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001803 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001804 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001805 }
1806
1807 if (pVBInfo->VBInfo & SetCRT2ToTV)
1808 return tempal;
1809 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001810 } /* {End of VB} */
1811
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001812 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001813 tempal = tempal >> 2;
1814 tempal &= 0x03;
1815
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001816 /* for Dot8 Scaling LCD */
1817 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001818 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
1819
Aaro Koskinena39325d2012-11-04 21:14:53 +02001820 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001821 return tempal;
1822}
1823
1824static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1825 unsigned char *di_1, struct vb_device_info *pVBInfo)
1826{
Peter Huewe6896b942012-02-09 21:11:46 +01001827 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1828 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001829 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1830 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001831 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001832 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001833 }
1834 } else {
1835 *di_0 = XGI_VCLKData[tempal].SR2B;
1836 *di_1 = XGI_VCLKData[tempal].SR2C;
1837 }
1838}
1839
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001840static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301841 unsigned short RefreshRateTableIndex,
1842 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001843{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301844 unsigned char di_0, di_1, tempal;
1845 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301847 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1848 pVBInfo);
1849 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1850 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001851
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301852 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001853 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301854 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001855 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301856 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001857 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1858 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301859 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001860 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1861 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301862 }
1863 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001864}
1865
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001866static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301867 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001868{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301869 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001870
Peter Huewe6896b942012-02-09 21:11:46 +01001871 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1872 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301873 tempcl = 0;
1874 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001875 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001876
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301877 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001878 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301879 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001880 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301881 if (!(temp & 0x40))
1882 tempcl |= ActiveCRT1;
1883 }
1884 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001885
Aaro Koskinen58839b02011-03-13 12:26:23 +02001886 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301887 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001888
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301889 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001890 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001891 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301892 if (tempax & 0x04)
1893 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001894
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301895 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001896
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301897 if (!(tempcl & ActiveLCD))
1898 if (temp == 0x01)
1899 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001900
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301901 if (temp == 0x04)
1902 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001903
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301904 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001905 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001906
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301907 if (!(temp & 0x08))
1908 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001909
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301910 if (!(temp & 0x04))
1911 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001912
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301913 if (temp & 0x02)
1914 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001915
Peter Huewe599801f2012-02-09 21:11:45 +01001916 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301917 if (temp & 0x01)
1918 tempch |= ActiveHiTV;
1919 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001920
Peter Huewe599801f2012-02-09 21:11:45 +01001921 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001922 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301923 pVBInfo->Part2Port,
1924 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001925
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301926 if (temp & 0x10)
1927 tempch |= ActiveYPbPr;
1928 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001929
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301930 if (tempch != 0)
1931 tempcl |= ActiveTV;
1932 }
1933 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001934
Aaro Koskinen58839b02011-03-13 12:26:23 +02001935 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301936 if (tempcl & ActiveLCD) {
1937 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1938 if (temp & ActiveTV)
1939 tempcl |= ActiveTV;
1940 }
1941 }
1942 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001943 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001944 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001945
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301946 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001947 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301948 } else {
1949 return;
1950 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001951}
1952
Bill Pemberton80adad82010-06-17 13:10:51 -04001953void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001954{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301955 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001956
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001957 if (pVBInfo->IF_DEF_LVDS != 0)
1958 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001959
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001960 tempbx = VB_SIS302B;
1961 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1962 if (flag == 0x02)
1963 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001964
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001965 tempbx = VB_SIS301;
1966 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1967 if (flag < 0xB0)
1968 goto finish;
1969
1970 tempbx = VB_SIS301B;
1971 if (flag < 0xC0)
1972 goto bigger_than_0xB0;
1973
1974 tempbx = VB_XGI301C;
1975 if (flag < 0xD0)
1976 goto bigger_than_0xB0;
1977
1978 tempbx = VB_SIS301LV;
1979 if (flag < 0xE0)
1980 goto bigger_than_0xB0;
1981
1982 tempbx = VB_SIS302LV;
1983 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1984 if (tempah != 0xFF)
1985 tempbx = VB_XGI301C;
1986
1987bigger_than_0xB0:
1988 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1989 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1990 if (!(flag & 0x02))
1991 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301992 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001993
1994finish:
1995 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001996}
1997
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02001998static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301999 struct xgi_hw_device_info *HwDeviceExtension,
2000 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002001{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302002 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002003
Aaro Koskinenb3979922012-11-04 21:14:52 +02002004 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302005 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01002006 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302007 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002008
Miguel Gómezf9317352012-07-06 12:40:48 +02002009 if (!(pVBInfo->VBType & 0xFFFF))
2010 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002011
Miguel Gómezf9317352012-07-06 12:40:48 +02002012 /* Check Display Device */
2013 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
2014 tempbx = tempbx | temp;
2015 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
2016 push = temp;
2017 push = push << 8;
2018 tempax = temp << 8;
2019 tempbx = tempbx | tempax;
2020 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
2021 | SetInSlaveMode | DisableCRT2Display);
2022 temp = 0xFFFF ^ temp;
2023 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002024
Miguel Gómezf9317352012-07-06 12:40:48 +02002025 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002026
Aaro Koskinen4d8f5ca2012-09-11 00:15:17 +03002027 if (pVBInfo->IF_DEF_LVDS == 0) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002028 if (pVBInfo->VBType &
2029 (VB_SIS302B |
2030 VB_SIS301LV |
2031 VB_SIS302LV |
2032 VB_XGI301C)) {
2033 if (temp & EnableDualEdge) {
2034 tempbx |= SetCRT2ToDualEdge;
2035 if (temp & SetToLCDA)
2036 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02002037 }
2038 }
2039 }
2040
2041 if (pVBInfo->IF_DEF_YPbPr == 1) {
2042 if (((pVBInfo->IF_DEF_LVDS == 0) &&
2043 ((pVBInfo->VBType & VB_SIS301LV) ||
2044 (pVBInfo->VBType & VB_SIS302LV) ||
2045 (pVBInfo->VBType & VB_XGI301C)))) {
2046 if (temp & SetYPbPr) {
2047 if (pVBInfo->IF_DEF_HiVision == 1) {
2048 /* shampoo add for new
2049 * scratch */
2050 temp = xgifb_reg_get(
2051 pVBInfo->P3d4,
2052 0x35);
2053 temp &= YPbPrMode;
2054 tempbx |= SetCRT2ToHiVision;
2055
2056 if (temp != YPbPrMode1080i) {
2057 tempbx &=
2058 (~SetCRT2ToHiVision);
2059 tempbx |=
2060 SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302061 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302062 }
2063 }
2064 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002065 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002066
Miguel Gómezf9317352012-07-06 12:40:48 +02002067 tempax = push; /* restore CR31 */
2068
2069 if (pVBInfo->IF_DEF_LVDS == 0) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302070 if (pVBInfo->IF_DEF_YPbPr == 1) {
Miguel Gómezf9317352012-07-06 12:40:48 +02002071 if (pVBInfo->IF_DEF_HiVision == 1)
2072 temp = 0x09FC;
2073 else
2074 temp = 0x097C;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002075 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2076 temp = 0x01FC;
Miguel Gómezf9317352012-07-06 12:40:48 +02002077 } else {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002078 temp = 0x017C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302079 }
Justin P. Mattock558f7582012-10-02 21:17:11 -07002080 } else { /* 3rd party chip */
Miguel Gómezf9317352012-07-06 12:40:48 +02002081 temp = SetCRT2ToLCD;
2082 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002083
Miguel Gómezf9317352012-07-06 12:40:48 +02002084 if (!(tempbx & temp)) {
2085 tempax |= DisableCRT2Display;
2086 tempbx = 0;
2087 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002088
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002089 if (!(pVBInfo->VBType & VB_NoLCD)) {
2090 if (tempbx & XGI_SetCRT2ToLCDA) {
2091 if (tempbx & SetSimuScanMode)
2092 tempbx &= (~(SetCRT2ToLCD |
2093 SetCRT2ToRAMDAC |
2094 SwitchCRT2));
2095 else
2096 tempbx &= (~(SetCRT2ToLCD |
2097 SetCRT2ToRAMDAC |
2098 SetCRT2ToTV |
2099 SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002100 }
2101 }
2102
2103 /* shampoo add */
2104 /* for driver abnormal */
2105 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2106 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2107 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002108 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002109 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002110 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002111 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002112 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302113 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002114 } else {
2115 tempbx &= (~(SetCRT2ToRAMDAC |
2116 SetCRT2ToLCD |
2117 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302118 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002119 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002120
Miguel Gómezf9317352012-07-06 12:40:48 +02002121 if (!(pVBInfo->VBType & VB_NoLCD)) {
2122 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002123 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002124 SetCRT2ToLCD |
Peter Huewe6896b942012-02-09 21:11:46 +01002125 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002126 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002127 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302128 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002129 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002130
Miguel Gómezf9317352012-07-06 12:40:48 +02002131 if (tempbx & SetCRT2ToSCART) {
2132 tempbx &= (0xFF00 |
2133 SetCRT2ToSCART |
2134 SwitchCRT2 |
2135 SetSimuScanMode);
2136 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2137 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002138
Miguel Gómezf9317352012-07-06 12:40:48 +02002139 if (pVBInfo->IF_DEF_YPbPr == 1) {
2140 if (tempbx & SetCRT2ToYPbPr525750)
2141 tempbx &= (0xFF00 |
2142 SwitchCRT2 |
2143 SetSimuScanMode);
2144 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002145
Miguel Gómezf9317352012-07-06 12:40:48 +02002146 if (pVBInfo->IF_DEF_HiVision == 1) {
2147 if (tempbx & SetCRT2ToHiVision)
2148 tempbx &= (0xFF00 |
2149 SetCRT2ToHiVision |
2150 SwitchCRT2 |
2151 SetSimuScanMode);
2152 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002153
Miguel Gómezf9317352012-07-06 12:40:48 +02002154 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2155 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2156 tempbx = DisableCRT2Display;
2157 }
2158
2159 if (!(tempbx & DisableCRT2Display)) {
2160 if ((!(tempbx & DriverMode)) ||
2161 (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002162 if (!(tempbx & XGI_SetCRT2ToLCDA))
2163 tempbx |= (SetInSlaveMode |
2164 SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002165 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002166
Miguel Gómezf9317352012-07-06 12:40:48 +02002167 /* LCD+TV can't support in slave mode
2168 * (Force LCDA+TV->LCDB) */
2169 if ((tempbx & SetInSlaveMode) &&
2170 (tempbx & XGI_SetCRT2ToLCDA)) {
2171 tempbx ^= (SetCRT2ToLCD |
2172 XGI_SetCRT2ToLCDA |
2173 SetCRT2ToDualEdge);
2174 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302175 }
2176 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002177
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302178 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002179}
2180
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002181static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302182 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002183{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002184 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002185
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302186 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002187 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2188 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002189
Peter Huewe5fc699f2013-02-03 04:08:45 +01002190 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2191 if (tempbx & TVSetPAL) {
2192 tempbx &= (SetCHTVOverScan |
2193 TVSetPALM |
2194 TVSetPALN |
2195 TVSetPAL);
2196 if (tempbx & TVSetPALM)
2197 /* set to NTSC if PAL-M */
2198 tempbx &= ~TVSetPAL;
2199 } else
2200 tempbx &= (SetCHTVOverScan |
2201 TVSetNTSCJ |
2202 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302204 if (pVBInfo->IF_DEF_LVDS == 0) {
2205 if (pVBInfo->VBInfo & SetCRT2ToSCART)
Peter Huewe599801f2012-02-09 21:11:45 +01002206 tempbx |= TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302207 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002208
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302209 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002210 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002211 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302212 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002213
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302214 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002215 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002216
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302217 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002218 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302219 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002220 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302221 }
2222 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302224 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002225 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2226 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302227 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302229 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002230 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2231 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302232 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002233
Peter Huewe599801f2012-02-09 21:11:45 +01002234 if (!(tempbx & TVSetPAL) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002235 (modeflag > 13) &&
2236 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302237 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302239 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002240
Peter Huewe599801f2012-02-09 21:11:45 +01002241 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302242 if (pVBInfo->VBInfo & SetInSlaveMode)
2243 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002244 } else if (tempbx &
2245 (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302246 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002247 } else if (!(pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002248 (VB_SIS301B |
2249 VB_SIS302B |
2250 VB_SIS301LV |
2251 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002252 VB_XGI301C))) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002253 if (tempbx & TVSimuMode)
2254 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302255 }
2256 }
2257 }
2258 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002259}
2260
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002261static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2262 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002263{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002264 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002265
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302266 pVBInfo->LCDResInfo = 0;
2267 pVBInfo->LCDTypeInfo = 0;
2268 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002269
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002270 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002271 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002272 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302273 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002274
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302275 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002276 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002277
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002278 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002279 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302280 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002281 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002282 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302283 tempax &= 0x0F;
2284 else
2285 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002286
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302287 if ((resinfo == 6) || (resinfo == 9)) {
2288 if (tempax >= 3)
2289 tempbx |= PanelRef75Hz;
2290 } else if ((resinfo == 7) || (resinfo == 8)) {
2291 if (tempax >= 4)
2292 tempbx |= PanelRef75Hz;
2293 }
2294 }
2295 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302297 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002298
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302299 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002300
Peter Huewea3d675c2012-02-09 21:11:47 +01002301 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302302 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002303
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302304 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002305
Aaro Koskinen58839b02011-03-13 12:26:23 +02002306 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002307
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302308 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002309
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302310 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002311
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302312 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002313
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302314 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002315
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302316 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Peter Huewe6896b942012-02-09 21:11:46 +01002317 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType
Peter Huewea3d675c2012-02-09 21:11:47 +01002318 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302319 tempbx |= SetLCDDualLink;
2320 }
2321 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002322
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302323 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002324 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002325 & SetCRT2ToLCD) && (resinfo == 9) &&
2326 (!(tempbx & EnableScalingLCD)))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02002327 /*
2328 * set to center in 1280x1024 LCDB
2329 * for Panel_1400x1050
2330 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002331 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302332 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002333
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302334 if (pVBInfo->VBInfo & SetInSlaveMode) {
2335 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002336 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302337 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002338 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302339 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302341 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002342
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302343 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002344}
2345
Bill Pemberton108afbf2010-06-17 13:10:47 -04002346unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302347 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002348{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002349 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002350 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002351 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002352 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002353 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302354 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002355
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302356 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002357}
2358
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002359static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2360{
2361 unsigned char ujRet = 0;
2362 unsigned char i = 0;
2363
2364 for (i = 0; i < 8; i++) {
2365 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002366 ujRet |= (ujDate >> i) & 1;
2367 }
2368
2369 return ujRet;
2370}
2371
2372/*----------------------------------------------------------------------------*/
2373/* output */
2374/* bl[5] : LVDS signal */
2375/* bl[1] : LVDS backlight */
2376/* bl[0] : LVDS VDD */
2377/*----------------------------------------------------------------------------*/
2378static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2379{
2380 unsigned char CR4A, temp;
2381
Aaro Koskinen58839b02011-03-13 12:26:23 +02002382 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002383 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002384
Aaro Koskinen58839b02011-03-13 12:26:23 +02002385 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002386
2387 temp = XG21GPIODataTransfer(temp);
2388 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002389 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002390 return temp;
2391}
2392
2393/*----------------------------------------------------------------------------*/
2394/* output */
2395/* bl[5] : LVDS signal */
2396/* bl[1] : LVDS backlight */
2397/* bl[0] : LVDS VDD */
2398/*----------------------------------------------------------------------------*/
2399static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2400{
2401 unsigned char CR4A, CRB4, temp;
2402
Aaro Koskinen58839b02011-03-13 12:26:23 +02002403 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002404 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002405
Aaro Koskinen58839b02011-03-13 12:26:23 +02002406 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002407
2408 temp &= 0x0C;
2409 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002410 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002411 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002412 temp |= ((CRB4 & 0x04) << 3);
2413 return temp;
2414}
2415
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002416/*----------------------------------------------------------------------------*/
2417/* input */
2418/* bl[5] : 1;LVDS signal on */
2419/* bl[1] : 1;LVDS backlight on */
2420/* bl[0] : 1:LVDS VDD on */
2421/* bh: 100000b : clear bit 5, to set bit5 */
2422/* 000010b : clear bit 1, to set bit1 */
2423/* 000001b : clear bit 0, to set bit0 */
2424/*----------------------------------------------------------------------------*/
2425static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2426 struct vb_device_info *pVBInfo)
2427{
2428 unsigned char CR4A, temp;
2429
2430 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2431 tempbh &= 0x23;
2432 tempbl &= 0x23;
2433 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2434
2435 if (tempbh & 0x20) {
2436 temp = (tempbl >> 4) & 0x02;
2437
2438 /* CR B4[1] */
2439 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2440
2441 }
2442
2443 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2444
2445 temp = XG21GPIODataTransfer(temp);
2446 temp &= ~tempbh;
2447 temp |= tempbl;
2448 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2449}
2450
Aaro Koskinen776115a2011-11-27 23:03:10 +02002451static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2452 struct vb_device_info *pVBInfo)
2453{
2454 unsigned char CR4A, temp;
2455 unsigned short tempbh0, tempbl0;
2456
2457 tempbh0 = tempbh;
2458 tempbl0 = tempbl;
2459 tempbh0 &= 0x20;
2460 tempbl0 &= 0x20;
2461 tempbh0 >>= 3;
2462 tempbl0 >>= 3;
2463
2464 if (tempbh & 0x20) {
2465 temp = (tempbl >> 4) & 0x02;
2466
2467 /* CR B4[1] */
2468 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2469
2470 }
2471 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2472
2473 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2474 tempbh &= 0x03;
2475 tempbl &= 0x03;
2476 tempbh <<= 2;
2477 tempbl <<= 2; /* GPIOC,GPIOD */
2478 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2479 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2480}
2481
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002482static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2483 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302484 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002485{
2486
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002487 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302488 if (pXGIHWDE->jChipType == XG21) {
2489 if (pVBInfo->IF_DEF_LVDS == 1) {
2490 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002491 /* LVDS VDD on */
2492 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002493 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302494 }
2495 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002496 /* LVDS signal on */
2497 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002498 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002499 /* LVDS backlight on */
2500 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302501 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002502 /* DVO/DVI signal on */
2503 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302504 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002505
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302506 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002507
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302508 if (pXGIHWDE->jChipType == XG27) {
2509 if (pVBInfo->IF_DEF_LVDS == 1) {
2510 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002511 /* LVDS VDD on */
2512 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002513 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302514 }
2515 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002516 /* LVDS signal on */
2517 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002518 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002519 /* LVDS backlight on */
2520 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302521 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002522 /* DVO/DVI signal on */
2523 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302524 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002525
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302526 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002527}
2528
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002529void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2530 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302531 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002532{
2533
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302534 if (pXGIHWDE->jChipType == XG21) {
2535 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002536 /* LVDS backlight off */
2537 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002538 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302539 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002540 /* DVO/DVI signal off */
2541 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302542 }
2543 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002544
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302545 if (pXGIHWDE->jChipType == XG27) {
2546 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002547 /* LVDS backlight off */
2548 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002549 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302550 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002551
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302552 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002553 /* DVO/DVI signal off */
2554 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302555 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002556
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002557 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002558}
2559
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002560static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002561{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002562 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302563 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002564
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002565 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302566 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002567}
2568
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002569static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002570{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002571 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002572}
2573
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002574static void XGI_SaveCRT2Info(unsigned short ModeNo,
2575 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002576{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302577 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002578
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002579 /* reserve CR34 for CRT1 Mode No */
2580 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302581 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2582 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002583 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002584}
2585
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002586static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2587 unsigned short ModeIdIndex,
2588 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002589{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302590 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002591
Aaro Koskinenb3979922012-11-04 21:14:52 +02002592 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002593 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2594 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002595 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002596 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002597
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002598 if (modeflag & HalfDCLK)
2599 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002600
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002601 if (modeflag & DoubleScanMode)
2602 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002603
Miguel Gómez3339db82012-07-06 12:40:49 +02002604 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2605 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002606
Miguel Gómez3339db82012-07-06 12:40:49 +02002607 if (pVBInfo->IF_DEF_LVDS == 0) {
2608 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2609 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2610 if (yres == 1024)
2611 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302612 }
2613 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002614
Miguel Gómez3339db82012-07-06 12:40:49 +02002615 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2616 if (yres == 400)
2617 yres = 405;
2618 else if (yres == 350)
2619 yres = 360;
2620
2621 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2622 if (yres == 360)
2623 yres = 375;
2624 }
2625 }
2626
2627 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2628 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2629 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2630 if (yres == 350)
2631 yres = 357;
2632 else if (yres == 400)
2633 yres = 420;
2634 else if (yres == 480)
2635 yres = 525;
2636 }
2637 }
2638 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302639 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002640
Miguel Gómez3339db82012-07-06 12:40:49 +02002641 if (xres == 720)
2642 xres = 640;
2643
2644exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302645 pVBInfo->VGAHDE = xres;
2646 pVBInfo->HDE = xres;
2647 pVBInfo->VGAVDE = yres;
2648 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002649}
2650
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002651static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002652{
2653
Peter Huewea3d675c2012-02-09 21:11:47 +01002654 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002655 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302656 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002657
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302658 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002659}
2660
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002661static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2662 unsigned short ModeIdIndex,
2663 unsigned short RefreshRateTableIndex,
2664 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002665{
2666 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002667 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002668
2669 pVBInfo->RVBHCMAX = 1;
2670 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002671 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002672 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002673 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002674 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2675 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002676 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002677 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002678 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002679 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002680 tempcx &= 0x0100;
2681 tempcx = tempcx << 2;
2682 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002683 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002684
2685 if (temp1 & 0x01)
2686 tempbx |= 0x0100;
2687
2688 if (temp1 & 0x20)
2689 tempbx |= 0x0200;
2690 tempax += 5;
2691
2692 if (modeflag & Charx8Dot)
2693 tempax *= 8;
2694 else
2695 tempax *= 9;
2696
2697 pVBInfo->VGAHT = tempax;
2698 pVBInfo->HT = tempax;
2699 tempbx++;
2700 pVBInfo->VGAVT = tempbx;
2701 pVBInfo->VT = tempbx;
2702}
2703
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002704static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302705 unsigned short RefreshRateTableIndex,
2706 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002707{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002708 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002709
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002710 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002711
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002712 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002713 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2714 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302715 pVBInfo->NewFlickerMode = 0;
2716 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002717
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302718 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2719 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2720 pVBInfo);
2721 return;
2722 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002723
Peter Huewea3d675c2012-02-09 21:11:47 +01002724 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002725 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002726 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002727
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302728 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2729 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2730 pVBInfo->VGAHT = LCDPtr->VGAHT;
2731 pVBInfo->VGAVT = LCDPtr->VGAVT;
2732 pVBInfo->HT = LCDPtr->LCDHT;
2733 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002734
Peter Huewe255aabd2012-02-09 21:11:44 +01002735 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302736 tempax = 1024;
2737 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002738
Peter Huewea3d675c2012-02-09 21:11:47 +01002739 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302740 if (pVBInfo->VGAVDE == 357)
2741 tempbx = 527;
2742 else if (pVBInfo->VGAVDE == 420)
2743 tempbx = 620;
2744 else if (pVBInfo->VGAVDE == 525)
2745 tempbx = 775;
2746 else if (pVBInfo->VGAVDE == 600)
2747 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302748 else
2749 tempbx = 768;
2750 } else
2751 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002752 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302753 tempax = 1024;
2754 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002755 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302756 tempax = 1280;
2757 if (pVBInfo->VGAVDE == 360)
2758 tempbx = 768;
2759 else if (pVBInfo->VGAVDE == 375)
2760 tempbx = 800;
2761 else if (pVBInfo->VGAVDE == 405)
2762 tempbx = 864;
2763 else
2764 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002765 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302766 tempax = 1280;
2767 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002768 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302769 tempax = 1280;
2770 if (pVBInfo->VGAVDE == 350)
2771 tempbx = 700;
2772 else if (pVBInfo->VGAVDE == 400)
2773 tempbx = 800;
2774 else if (pVBInfo->VGAVDE == 1024)
2775 tempbx = 960;
2776 else
2777 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002778 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302779 tempax = 1400;
2780 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002781
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302782 if (pVBInfo->VGAVDE == 1024) {
2783 tempax = 1280;
2784 tempbx = 1024;
2785 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002786 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302787 tempax = 1600;
2788 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002789 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302790 if (pVBInfo->VGAVDE == 350)
2791 tempbx = 875;
2792 else if (pVBInfo->VGAVDE == 400)
2793 tempbx = 1000;
2794 }
2795 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302797 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2798 tempax = pVBInfo->VGAHDE;
2799 tempbx = pVBInfo->VGAVDE;
2800 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302802 pVBInfo->HDE = tempax;
2803 pVBInfo->VDE = tempbx;
2804 return;
2805 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002806
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302807 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002808 struct SiS_TVData const *TVPtr;
2809
2810 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2811 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002812
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302813 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2814 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2815 pVBInfo->VGAHT = TVPtr->VGAHT;
2816 pVBInfo->VGAVT = TVPtr->VGAVT;
2817 pVBInfo->HDE = TVPtr->TVHDE;
2818 pVBInfo->VDE = TVPtr->TVVDE;
2819 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2820 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002821
Peter Huewe599801f2012-02-09 21:11:45 +01002822 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302823 if (resinfo == 0x08)
2824 pVBInfo->NewFlickerMode = 0x40;
2825 else if (resinfo == 0x09)
2826 pVBInfo->NewFlickerMode = 0x40;
2827 else if (resinfo == 0x12)
2828 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302830 if (pVBInfo->VGAVDE == 350)
2831 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302833 tempax = ExtHiTVHT;
2834 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302836 if (pVBInfo->VBInfo & SetInSlaveMode) {
2837 if (pVBInfo->TVInfo & TVSimuMode) {
2838 tempax = StHiTVHT;
2839 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002840
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302841 if (!(modeflag & Charx8Dot)) {
2842 tempax = StHiTextTVHT;
2843 tempbx = StHiTextTVVT;
2844 }
2845 }
2846 }
Peter Huewe599801f2012-02-09 21:11:45 +01002847 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2848 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302849 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2850 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2851 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002852
Peter Huewe599801f2012-02-09 21:11:45 +01002853 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302854 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2855 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002856 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302857 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2858 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2859 if (pVBInfo->TVInfo & NTSC1024x768)
2860 tempax = NTSC1024x768HT;
2861 }
2862 } else {
2863 tempax = PALHT;
2864 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002865 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302866 tempax = NTSCHT;
2867 tempbx = NTSCVT;
2868 if (pVBInfo->TVInfo & NTSC1024x768)
2869 tempax = NTSC1024x768HT;
2870 }
2871 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002872
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302873 pVBInfo->HT = tempax;
2874 pVBInfo->VT = tempbx;
2875 return;
2876 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002877}
2878
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002879static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302880 unsigned short RefreshRateTableIndex,
2881 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002882{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002883 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302885 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2886 pVBInfo);
2887 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2888 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002889
Peter Huewe6896b942012-02-09 21:11:46 +01002890 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302891 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002892 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2893 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2894 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302895 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002896 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2897 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302898 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002899
Aaro Koskinen8104e322011-03-13 12:26:22 +02002900 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002901
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302902 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002903 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302904 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002905 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002906}
2907
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002908static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2909 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002910{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002911 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2912 short index;
2913 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302914
Aaro Koskinenb3979922012-11-04 21:14:52 +02002915 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002916 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302917
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002918 if (index < 0)
2919 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302920
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002921 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302922}
2923
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002924static unsigned short XGI_GetOffset(unsigned short ModeNo,
2925 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302926 unsigned short RefreshRateTableIndex,
2927 struct xgi_hw_device_info *HwDeviceExtension,
2928 struct vb_device_info *pVBInfo)
2929{
2930 unsigned short temp, colordepth, modeinfo, index, infoflag,
2931 ColorDepth[] = { 0x01, 0x02, 0x04 };
2932
Aaro Koskinenb3979922012-11-04 21:14:52 +02002933 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002934 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302935
2936 index = (modeinfo >> 8) & 0xFF;
2937
Aaro Koskinen224114c2012-11-04 21:14:59 +02002938 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302939
2940 if (infoflag & InterlaceMode)
2941 temp = temp << 1;
2942
2943 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2944
2945 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2946 temp = ModeNo - 0x7C;
2947 colordepth = ColorDepth[temp];
2948 temp = 0x6B;
2949 if (infoflag & InterlaceMode)
2950 temp = temp << 1;
2951 return temp * colordepth;
2952 } else {
2953 return temp * colordepth;
2954 }
2955}
2956
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002957static void XGI_SetCRT2Offset(unsigned short ModeNo,
2958 unsigned short ModeIdIndex,
2959 unsigned short RefreshRateTableIndex,
2960 struct xgi_hw_device_info *HwDeviceExtension,
2961 struct vb_device_info *pVBInfo)
2962{
2963 unsigned short offset;
2964 unsigned char temp;
2965
2966 if (pVBInfo->VBInfo & SetInSlaveMode)
2967 return;
2968
2969 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2970 HwDeviceExtension, pVBInfo);
2971 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002972 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002973 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002974 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002975 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002976 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002977}
2978
Randy Dunlap89229672010-08-10 08:46:44 -07002979static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002980{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002981 /* threshold high ,disable auto threshold */
2982 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2983 /* threshold low default 04h */
2984 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002985}
2986
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002987static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302988 struct xgi_hw_device_info *HwDeviceExtension,
2989 unsigned short RefreshRateTableIndex,
2990 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002991{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002992 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002993
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302994 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2995 HwDeviceExtension, pVBInfo);
2996 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002997
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302998 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002999 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003000
Aaro Koskinen8104e322011-03-13 12:26:22 +02003001 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
3002 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003003}
3004
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003005static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303006 struct xgi_hw_device_info *HwDeviceExtension,
3007 unsigned short RefreshRateTableIndex,
3008 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003009{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303010 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003011 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003012
Aaro Koskinena39325d2012-11-04 21:14:53 +02003013 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003014 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02003015 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303017 /* bainy change table name */
3018 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003019 /* BTVGA2HT 0x08,0x09 */
3020 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003021 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303022 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003023 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003024 /* BTVGA2HDEE 0x0A,0x0C */
3025 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003026 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303027 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
3028 pushbx = pVBInfo->VGAHDE / 2 + 16;
3029 tempcx = tempcx >> 1;
3030 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3031 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003032
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303033 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003034 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
3035 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003036 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303037 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003038 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303039 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003040 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303041 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3042 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3043 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303045 tempbx += 4;
3046 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003047
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303048 if (tempcx > (pVBInfo->VGAHT / 2))
3049 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003050
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303051 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003052
Aaro Koskinen8104e322011-03-13 12:26:22 +02003053 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303054 } else {
3055 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003056 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303057 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003058 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003059 /* BTVGA2HDEE 0x0A,0x0C */
3060 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003061 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303062 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
3063 pushbx = pVBInfo->VGAHDE + 16;
3064 tempcx = tempcx >> 1;
3065 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3066 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003067
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303068 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003069 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
3070 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003071 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303072 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003073 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303074 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003075 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303076 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3077 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3078 tempbx += 16;
3079 tempcx += 16;
3080 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003081
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303082 if (tempcx > pVBInfo->VGAHT)
3083 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003084
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303085 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003086 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303087 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303089 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3090 tempbx = pushbx;
3091 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3092 tempax |= (tempbx & 0xFF00);
3093 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003094 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303095 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003096 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303097 tempcx = (pVBInfo->VGAVT - 1);
3098 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003099
Aaro Koskinen8104e322011-03-13 12:26:22 +02003100 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303101 tempbx = pVBInfo->VGAVDE - 1;
3102 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003103 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303104 temp = ((tempbx & 0xFF00) << 3) >> 8;
3105 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003106 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003107
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303108 tempax = pVBInfo->VGAVDE;
3109 tempbx = pVBInfo->VGAVDE;
3110 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003111 /* BTVGA2VRS 0x10,0x11 */
3112 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3113 /* BTVGA2VRE 0x11 */
3114 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303116 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003117 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
3118 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303120 if (temp & 0x04)
3121 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303123 if (temp & 0x080)
3124 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003125
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003126 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303128 if (temp & 0x08)
3129 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003130
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003131 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303132 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3133 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303135 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003136 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303137 temp = ((tempbx & 0xFF00) >> 8) << 4;
3138 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003139 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303140 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303142 if (modeflag & DoubleScanMode)
3143 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003144
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303145 if (modeflag & HalfDCLK)
3146 tempax |= 0x40;
3147
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003148 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003149}
3150
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003151static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3152{
3153 unsigned long tempax, tempbx;
3154
3155 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3156 & 0xFFFF;
3157 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3158 tempax = (tempax * pVBInfo->HT) / tempbx;
3159
3160 return (unsigned short) tempax;
3161}
3162
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003163static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303164 struct xgi_hw_device_info *HwDeviceExtension,
3165 unsigned short RefreshRateTableIndex,
3166 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003167{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303168 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003169 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003170
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003171 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003172 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3173 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303175 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3176 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003177
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303178 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003179 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303180 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003181
Peter Huewe6896b942012-02-09 21:11:46 +01003182 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303183 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003184
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303185 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303187 if (modeflag & HalfDCLK)
3188 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303190 tempax = (tempax / tempcx) - 1;
3191 tempbx |= ((tempax & 0x00FF) << 8);
3192 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003193 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003194
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303195 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003196
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303197 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003198 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3199 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303200 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003201
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003202 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3203 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303204 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303205 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003206
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003207 /* 0x05 Horizontal Display Start */
3208 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3209 /* 0x06 Horizontal Blank end */
3210 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003211
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303212 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3213 if (pVBInfo->VBInfo & SetCRT2ToTV)
3214 tempax = pVBInfo->VGAHT;
3215 else
3216 tempax = XGI_GetVGAHT2(pVBInfo);
3217 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303219 if (tempax >= pVBInfo->VGAHT)
3220 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003221
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303222 if (modeflag & HalfDCLK)
3223 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303225 tempax = (tempax / tempcx) - 5;
3226 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003227 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303228 temp = (tempbx & 0x00FF) - 1;
3229 if (!(modeflag & HalfDCLK)) {
3230 temp -= 6;
3231 if (pVBInfo->TVInfo & TVSimuMode) {
3232 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003233 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303234 }
3235 }
3236 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303237 tempbx = (tempbx & 0xFF00) >> 8;
3238 tempcx = (tempcx + tempbx) >> 1;
3239 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003240
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303241 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3242 temp -= 1;
3243 if (!(modeflag & HalfDCLK)) {
3244 if ((modeflag & Charx8Dot)) {
3245 temp += 4;
3246 if (pVBInfo->VGAHDE >= 800)
3247 temp -= 6;
3248 }
3249 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003250 } else if (!(modeflag & HalfDCLK)) {
3251 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003252 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003253 pVBInfo->VGAHDE >= 800) {
3254 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003255 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003256 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003257 (pVBInfo->LCDInfo & LCDNonExpanding))
3258 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303259 }
3260 }
3261 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003262
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003263 /* 0x07 Horizontal Retrace Start */
3264 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3265 /* 0x08 Horizontal Retrace End */
3266 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003267
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303268 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3269 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003270 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303271 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003272 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303273 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003274 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303275 0x08, 0x03);
3276 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003277 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303278 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003279 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303280 0x08, 0x02);
3281 }
3282 }
3283 }
3284 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003285
Aaro Koskinen8104e322011-03-13 12:26:22 +02003286 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003287 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003288 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303290 tempbx = pVBInfo->VGAVT;
3291 push1 = tempbx;
3292 tempcx = 0x121;
3293 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003294
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303295 if (tempbx == 357)
3296 tempbx = 350;
3297 if (tempbx == 360)
3298 tempbx = 350;
3299 if (tempbx == 375)
3300 tempbx = 350;
3301 if (tempbx == 405)
3302 tempbx = 400;
3303 if (tempbx == 525)
3304 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003305
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303306 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003307
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303308 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003309 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003310 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303311 if (tempbx == 350)
3312 tempbx += 5;
3313 if (tempbx == 480)
3314 tempbx += 5;
3315 }
3316 }
3317 }
3318 tempbx--;
3319 temp = tempbx & 0x00FF;
3320 tempbx--;
3321 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003322 /* 0x10 vertical Blank Start */
3323 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303324 tempbx = push2;
3325 tempbx--;
3326 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003327 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003328
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303329 if (tempbx & 0x0100)
3330 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303332 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003333
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303334 if (modeflag & DoubleScanMode)
3335 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003336
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303337 if (tempbx & 0x0200)
3338 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003339
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303340 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003341 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003342
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303343 if (tempbx & 0x0400)
3344 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003345
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003346 /* 0x11 Vertival Blank End */
3347 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303348
3349 tempax = push1;
3350 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3351 tempax = tempax >> 2;
3352 push1 = tempax; /* push ax */
3353
3354 if (resinfo != 0x09) {
3355 tempax = tempax << 1;
3356 tempbx += tempax;
3357 }
3358
Peter Huewe599801f2012-02-09 21:11:45 +01003359 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003360 if ((pVBInfo->VBType & VB_SIS301LV) &&
3361 !(pVBInfo->TVInfo & TVSetHiVision)) {
3362 if ((pVBInfo->TVInfo & TVSimuMode) &&
3363 (pVBInfo->TVInfo & TVSetPAL)) {
3364 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3365 !(pVBInfo->TVInfo &
3366 (TVSetYPbPr525p |
3367 TVSetYPbPr750p |
3368 TVSetHiVision)))
3369 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303370 }
3371 } else {
3372 tempbx -= 10;
3373 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003374 } else if (pVBInfo->TVInfo & TVSimuMode) {
3375 if (pVBInfo->TVInfo & TVSetPAL) {
3376 if (pVBInfo->VBType & VB_SIS301LV) {
3377 if (!(pVBInfo->TVInfo &
3378 (TVSetYPbPr525p |
3379 TVSetYPbPr750p |
3380 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303381 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003382 } else {
3383 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303384 }
3385 }
3386 }
3387 tempax = push1;
3388 tempax = tempax >> 2;
3389 tempax++;
3390 tempax += tempbx;
3391 push1 = tempax; /* push ax */
3392
Peter Huewe599801f2012-02-09 21:11:45 +01003393 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303394 if (tempbx <= 513) {
3395 if (tempax >= 513)
3396 tempbx = 513;
3397 }
3398 }
3399
3400 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003401 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303402 tempbx--;
3403 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003404 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303405
3406 if (tempbx & 0x0100)
3407 tempcx |= 0x0008;
3408
3409 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003410 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303411
3412 tempbx++;
3413
3414 if (tempbx & 0x0100)
3415 tempcx |= 0x0004;
3416
3417 if (tempbx & 0x0200)
3418 tempcx |= 0x0080;
3419
3420 if (tempbx & 0x0400)
3421 tempcx |= 0x0C00;
3422
3423 tempbx = push1; /* pop ax */
3424 temp = tempbx & 0x00FF;
3425 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003426 /* 0x0D vertical Retrace End */
3427 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303428
3429 if (tempbx & 0x0010)
3430 tempcx |= 0x2000;
3431
3432 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003433 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303434 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003435 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303436 tempax = modeflag;
3437 temp = (tempax & 0xFF00) >> 8;
3438
3439 temp = (temp >> 1) & 0x09;
3440
Peter Huewe6896b942012-02-09 21:11:46 +01003441 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303442 temp |= 0x01;
3443
Aaro Koskinen8104e322011-03-13 12:26:22 +02003444 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3445 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3446 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303447
3448 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3449 temp = 0x80;
3450 else
3451 temp = 0x00;
3452
Aaro Koskinen8104e322011-03-13 12:26:22 +02003453 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303454
3455 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003456}
3457
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003458static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303459 unsigned short RefreshRateTableIndex,
3460 struct xgi_hw_device_info *HwDeviceExtension,
3461 struct vb_device_info *pVBInfo)
3462{
3463 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003464 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003465 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303466
3467 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3468
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003469 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003470 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303471
3472 tempax = 0;
3473
3474 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3475 tempax |= 0x0800;
3476
3477 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3478 tempax |= 0x0400;
3479
3480 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3481 tempax |= 0x0200;
3482
Peter Huewe599801f2012-02-09 21:11:45 +01003483 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303484 tempax |= 0x1000;
3485
Peter Huewe599801f2012-02-09 21:11:45 +01003486 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303487 tempax |= 0x0100;
3488
Peter Huewe599801f2012-02-09 21:11:45 +01003489 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303490 tempax &= 0xfe00;
3491
3492 tempax = (tempax & 0xff00) >> 8;
3493
Aaro Koskinen8104e322011-03-13 12:26:22 +02003494 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003495 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303496
Peter Huewe599801f2012-02-09 21:11:45 +01003497 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003498 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303499
Peter Huewe599801f2012-02-09 21:11:45 +01003500 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003501 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303502
3503 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003504 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303505
3506 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003507 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303508
3509 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003510 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303511 }
3512
Peter Huewe599801f2012-02-09 21:11:45 +01003513 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3514 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003515 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303516
Peter Huewe599801f2012-02-09 21:11:45 +01003517 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003518 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303519
Peter Huewe599801f2012-02-09 21:11:45 +01003520 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003521 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303522 }
3523
3524 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003525 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303526
3527 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003528 /* di->temp2[j] */
3529 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303530
3531 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003532 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303533
3534 temp = pVBInfo->NewFlickerMode;
3535 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003536 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303537
Peter Huewe599801f2012-02-09 21:11:45 +01003538 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303539 tempax = 950;
3540
Peter Huewe599801f2012-02-09 21:11:45 +01003541 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303542 tempax = 520;
3543 else
3544 tempax = 440;
3545
3546 if (pVBInfo->VDE <= tempax) {
3547 tempax -= pVBInfo->VDE;
3548 tempax = tempax >> 2;
3549 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3550 push1 = tempax;
3551 temp = (tempax & 0xFF00) >> 8;
3552 temp += (unsigned short) TimingPoint[0];
3553
Peter Huewe6896b942012-02-09 21:11:46 +01003554 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3555 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303556 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3557 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003558 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303559 tempcx = pVBInfo->VGAHDE;
3560 if (tempcx >= 1024) {
3561 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003562 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303563 temp = 0x19; /* PAL */
3564 }
3565 }
3566 }
3567
Aaro Koskinen8104e322011-03-13 12:26:22 +02003568 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303569 tempax = push1;
3570 temp = (tempax & 0xFF00) >> 8;
3571 temp += TimingPoint[1];
3572
Peter Huewe6896b942012-02-09 21:11:46 +01003573 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3574 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303575 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3576 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003577 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303578 tempcx = pVBInfo->VGAHDE;
3579 if (tempcx >= 1024) {
3580 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003581 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303582 temp = 0x52; /* PAL */
3583 }
3584 }
3585 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003586 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303587 }
3588
3589 /* 301b */
3590 tempcx = pVBInfo->HT;
3591
3592 if (XGI_IsLCDDualLink(pVBInfo))
3593 tempcx = tempcx >> 1;
3594
3595 tempcx -= 2;
3596 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003597 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303598
3599 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003600 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303601
3602 tempcx = pVBInfo->HT >> 1;
3603 push1 = tempcx; /* push cx */
3604 tempcx += 7;
3605
Peter Huewe599801f2012-02-09 21:11:45 +01003606 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303607 tempcx -= 4;
3608
3609 temp = tempcx & 0x00FF;
3610 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003611 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303612
3613 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3614 tempbx += tempcx;
3615 push2 = tempbx;
3616 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003617 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303618 temp = (tempbx & 0xFF00) >> 8;
3619 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003620 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303621
3622 tempbx = push2;
3623 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003624 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303625 tempbx = tempbx - 4;
3626 tempcx = tempbx;
3627 }
3628
3629 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003630 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303631
3632 j += 2;
3633 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3634 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003635 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303636 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003637 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303638
3639 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003640 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303641 tempcx -= 4;
3642
3643 temp = tempcx & 0xFF;
3644 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003645 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303646
3647 tempcx = push1; /* pop cx */
3648 j += 2;
3649 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3650 tempcx -= temp;
3651 temp = tempcx & 0x00FF;
3652 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003653 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303654
3655 tempcx -= 11;
3656
3657 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3658 tempax = XGI_GetVGAHT2(pVBInfo);
3659 tempcx = tempax - 1;
3660 }
3661 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003662 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303663
3664 tempbx = pVBInfo->VDE;
3665
3666 if (pVBInfo->VGAVDE == 360)
3667 tempbx = 746;
3668 if (pVBInfo->VGAVDE == 375)
3669 tempbx = 746;
3670 if (pVBInfo->VGAVDE == 405)
3671 tempbx = 853;
3672
3673 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003674 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003675 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003676 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003677 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303678 tempbx = tempbx >> 1;
3679 } else
3680 tempbx = tempbx >> 1;
3681 }
3682
3683 tempbx -= 2;
3684 temp = tempbx & 0x00FF;
3685
Peter Huewe599801f2012-02-09 21:11:45 +01003686 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003687 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003688 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303689 if (pVBInfo->VBInfo & SetInSlaveMode) {
3690 if (ModeNo == 0x2f)
3691 temp += 1;
3692 }
3693 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003694 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3695 if (ModeNo == 0x2f)
3696 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303697 }
3698 }
3699
Aaro Koskinen8104e322011-03-13 12:26:22 +02003700 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303701
3702 temp = (tempcx & 0xFF00) >> 8;
3703 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3704
Peter Huewe599801f2012-02-09 21:11:45 +01003705 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003706 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003707 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303708 temp |= 0x10;
3709
3710 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3711 temp |= 0x20;
3712 }
3713 } else {
3714 temp |= 0x10;
3715 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3716 temp |= 0x20;
3717 }
3718 }
3719
Aaro Koskinen8104e322011-03-13 12:26:22 +02003720 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303721
Peter Huewe6896b942012-02-09 21:11:46 +01003722 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3723 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303724 tempbx = pVBInfo->VDE;
3725 tempcx = tempbx - 2;
3726
3727 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003728 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3729 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303730 tempbx = tempbx >> 1;
3731 }
3732
Peter Huewe6896b942012-02-09 21:11:46 +01003733 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303734 temp = 0;
3735 if (tempcx & 0x0400)
3736 temp |= 0x20;
3737
3738 if (tempbx & 0x0400)
3739 temp |= 0x40;
3740
Aaro Koskinen8104e322011-03-13 12:26:22 +02003741 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303742 }
3743
3744 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003745 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303746 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003747 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303748 }
3749
3750 tempbx = tempbx & 0x00FF;
3751
3752 if (!(modeflag & HalfDCLK)) {
3753 tempcx = pVBInfo->VGAHDE;
3754 if (tempcx >= pVBInfo->HDE) {
3755 tempbx |= 0x2000;
3756 tempax &= 0x00FF;
3757 }
3758 }
3759
3760 tempcx = 0x0101;
3761
3762 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3763 if (pVBInfo->VGAHDE >= 1024) {
3764 tempcx = 0x1920;
3765 if (pVBInfo->VGAHDE >= 1280) {
3766 tempcx = 0x1420;
3767 tempbx = tempbx & 0xDFFF;
3768 }
3769 }
3770 }
3771
3772 if (!(tempbx & 0x2000)) {
3773 if (modeflag & HalfDCLK)
3774 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3775
3776 push1 = tempbx;
3777 tempeax = pVBInfo->VGAHDE;
3778 tempebx = (tempcx & 0xFF00) >> 8;
3779 longtemp = tempeax * tempebx;
3780 tempecx = tempcx & 0x00FF;
3781 longtemp = longtemp / tempecx;
3782
3783 /* 301b */
3784 tempecx = 8 * 1024;
3785
Peter Huewe6896b942012-02-09 21:11:46 +01003786 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3787 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303788 tempecx = tempecx * 8;
3789 }
3790
3791 longtemp = longtemp * tempecx;
3792 tempecx = pVBInfo->HDE;
3793 temp2 = longtemp % tempecx;
3794 tempeax = longtemp / tempecx;
3795 if (temp2 != 0)
3796 tempeax += 1;
3797
3798 tempax = (unsigned short) tempeax;
3799
3800 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003801 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3802 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303803 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3804 }
3805 /* end 301b */
3806
3807 tempbx = push1;
3808 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3809 | (tempbx & 0x00FF));
3810 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3811 | (tempax & 0x00FF));
3812 temp = (tempax & 0xFF00) >> 8;
3813 } else {
3814 temp = (tempax & 0x00FF) >> 8;
3815 }
3816
Aaro Koskinen8104e322011-03-13 12:26:22 +02003817 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303818 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003819 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303820 temp = tempcx & 0x00FF;
3821
3822 if (tempbx & 0x2000)
3823 temp = 0;
3824
3825 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3826 temp |= 0x18;
3827
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003828 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003829 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303830 tempbx = 0x0382;
3831 tempcx = 0x007e;
3832 } else {
3833 tempbx = 0x0369;
3834 tempcx = 0x0061;
3835 }
3836
3837 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003838 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303839 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003840 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303841
3842 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3843 temp = temp << 2;
3844 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3845
Peter Huewe599801f2012-02-09 21:11:45 +01003846 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303847 temp |= 0x10;
3848
Peter Huewe599801f2012-02-09 21:11:45 +01003849 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303850 temp |= 0x20;
3851
Peter Huewe599801f2012-02-09 21:11:45 +01003852 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303853 temp |= 0x60;
3854 }
3855
Aaro Koskinen8104e322011-03-13 12:26:22 +02003856 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003857 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003858 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303859
Peter Huewe599801f2012-02-09 21:11:45 +01003860 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303861 if (pVBInfo->TVInfo & NTSC1024x768) {
3862 TimingPoint = XGI_NTSC1024AdjTime;
3863 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003864 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303865 TimingPoint[j]);
3866 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003867 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303868 }
3869 }
3870
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003871 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303872 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003873 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003874 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303875 0x08); /* PALM Mode */
3876 }
3877
Peter Huewe599801f2012-02-09 21:11:45 +01003878 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003879 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303880 0x01);
3881 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003882 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303883
Aaro Koskinendc505562011-03-13 12:26:26 +02003884 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303885 }
3886
Peter Huewe599801f2012-02-09 21:11:45 +01003887 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303888 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003889 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303890 }
3891
3892 if (pVBInfo->VBInfo & SetCRT2ToTV)
3893 return;
3894}
3895
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003896static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303897 struct xgi_hw_device_info *HwDeviceExtension,
3898 unsigned short RefreshRateTableIndex,
3899 struct vb_device_info *pVBInfo)
3900{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003901 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3902 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303903
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003904 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303905
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003906 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303907 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3908 return;
3909
3910 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3911
3912 if (XGI_IsLCDDualLink(pVBInfo))
3913 tempbx = tempbx >> 1;
3914
3915 tempbx -= 1;
3916 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003917 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303918 temp = (tempbx & 0xFF00) >> 8;
3919 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003920 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303921 temp = 0x01;
3922
Aaro Koskinen8104e322011-03-13 12:26:22 +02003923 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303924 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303925 tempbx--;
3926 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003927 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303928 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003929 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303930
3931 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303932 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003933 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303934 temp = (tempcx & 0xFF00) >> 8;
3935 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003936 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003937 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3938 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3939 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3940 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303941
Justin P. Mattock558f7582012-10-02 21:17:11 -07003942 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003943 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
3944 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
3945 RefreshRateTableIndex, pVBInfo);
3946 else
3947 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
3948 ModeIdIndex, RefreshRateTableIndex,
3949 pVBInfo);
3950
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303951 tempah = pVBInfo->LCDResInfo;
3952 tempah &= PanelResInfo;
3953
Peter Huewe255aabd2012-02-09 21:11:44 +01003954 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303955 tempbx = 1024;
3956 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003957 } else if ((tempah == Panel_1280x1024) ||
3958 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303959 tempbx = 1280;
3960 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003961 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303962 tempbx = 1400;
3963 tempcx = 1050;
3964 } else {
3965 tempbx = 1600;
3966 tempcx = 1200;
3967 }
3968
3969 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3970 tempbx = pVBInfo->HDE;
3971 tempcx = pVBInfo->VDE;
3972 }
3973
3974 pushbx = tempbx;
3975 tempax = pVBInfo->VT;
3976 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3977 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3978 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3979 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3980 tempbx = pVBInfo->LCDVDES;
3981 tempcx += tempbx;
3982
3983 if (tempcx >= tempax)
3984 tempcx -= tempax; /* lcdvdes */
3985
3986 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003987 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303988 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003989 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303990 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3991 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3992 tempah = tempch;
3993 tempah = tempah << 3;
3994 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003995 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303996
3997 /* getlcdsync() */
3998 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3999 tempcx = tempbx;
4000 tempax = pVBInfo->VT;
4001 tempbx = pVBInfo->LCDVRS;
4002
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304003 tempcx += tempbx;
4004 if (tempcx >= tempax)
4005 tempcx -= tempax;
4006
4007 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004008 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304009 temp = (tempbx & 0xFF00) >> 8;
4010 temp = temp << 4;
4011 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004012 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304013 tempcx = pushbx;
4014 tempax = pVBInfo->HT;
4015 tempbx = pVBInfo->LCDHDES;
4016 tempbx &= 0x0FFF;
4017
4018 if (XGI_IsLCDDualLink(pVBInfo)) {
4019 tempax = tempax >> 1;
4020 tempbx = tempbx >> 1;
4021 tempcx = tempcx >> 1;
4022 }
4023
Peter Huewe6896b942012-02-09 21:11:46 +01004024 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304025 tempbx += 1;
4026
4027 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
4028 tempbx += 1;
4029
4030 tempcx += tempbx;
4031
4032 if (tempcx >= tempax)
4033 tempcx -= tempax;
4034
4035 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004036 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304037 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004038 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304039 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004040 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304041 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004042 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304044 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4045 tempcx = tempax;
4046 tempax = pVBInfo->HT;
4047 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304048 if (XGI_IsLCDDualLink(pVBInfo)) {
4049 tempax = tempax >> 1;
4050 tempbx = tempbx >> 1;
4051 tempcx = tempcx >> 1;
4052 }
4053
Peter Huewe6896b942012-02-09 21:11:46 +01004054 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304055 tempbx += 1;
4056
4057 tempcx += tempbx;
4058
4059 if (tempcx >= tempax)
4060 tempcx -= tempax;
4061
4062 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004063 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304064
4065 temp = (tempbx & 0xFF00) >> 8;
4066 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004067 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304068 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004069 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304070
Peter Huewea3d675c2012-02-09 21:11:47 +01004071 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304072 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01004073 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4074 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304075 | VB_XGI301C)) {
4076 temp = 0xC6;
4077 } else
4078 temp = 0xC4;
4079
Aaro Koskinen8104e322011-03-13 12:26:22 +02004080 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4081 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304082 }
4083
4084 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004085 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4086 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304087 | VB_XGI301C)) {
4088 temp = 0x4F;
4089 } else
4090 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004091 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304092 }
4093 }
4094}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004095
4096/* --------------------------------------------------------------------- */
4097/* Function : XGI_GetTap4Ptr */
4098/* Input : */
4099/* Output : di -> Tap4 Reg. Setting Pointer */
4100/* Description : */
4101/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004102static struct XGI301C_Tap4TimingStruct const
4103*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004104{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304105 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004106 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004107
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304108 if (tempcx == 0) {
4109 tempax = pVBInfo->VGAHDE;
4110 tempbx = pVBInfo->HDE;
4111 } else {
4112 tempax = pVBInfo->VGAVDE;
4113 tempbx = pVBInfo->VDE;
4114 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004115
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004116 if (tempax <= tempbx)
4117 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304118 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004119 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004120
Peter Huewe599801f2012-02-09 21:11:45 +01004121 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304122 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004123
Peter Huewe599801f2012-02-09 21:11:45 +01004124 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4125 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4126 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004127 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004128 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304129 Tap4TimingPtr = YPbPr750pTap4Timing;
4130 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004131
Peter Huewe599801f2012-02-09 21:11:45 +01004132 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004133 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304135 i = 0;
4136 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4137 if (Tap4TimingPtr[i].DE == tempax)
4138 break;
4139 i++;
4140 }
4141 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004142}
4143
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004144static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004145{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304146 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004147 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004148
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304149 if (!(pVBInfo->VBType & VB_XGI301C))
4150 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004151
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304152 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4153 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004154 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004155
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004156 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004157 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004158 /* Set Vertical Scaling */
4159 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304160 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004161 xgifb_reg_set(pVBInfo->Part2Port,
4162 i,
4163 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304164 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004165
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004166 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004167 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004168 /* Enable V.Scaling */
4169 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304170 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004171 /* Enable H.Scaling */
4172 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004173}
4174
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004175static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304176 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004177{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304178 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004179 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304180 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004181
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004182 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004183 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004184
Aaro Koskinen8104e322011-03-13 12:26:22 +02004185 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004186 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004187 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4188 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304189 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004190 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4191 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304192 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004193
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304194 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4195 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004196
Peter Huewe599801f2012-02-09 21:11:45 +01004197 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004198 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4199 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4200 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304201 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004202
Peter Huewe599801f2012-02-09 21:11:45 +01004203 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4204 & SetCRT2ToYPbPr525750)) {
4205 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304206 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004207
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004208 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304209 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004210 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304211 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004212 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304213 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004214
Peter Huewe599801f2012-02-09 21:11:45 +01004215 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004216 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004217
Peter Huewe599801f2012-02-09 21:11:45 +01004218 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004219 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004220
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304221 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004222 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304224 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004225 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004226 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304227 }
4228 }
4229 return;
4230} /* {end of XGI_SetGroup3} */
4231
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004232static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304233 unsigned short RefreshRateTableIndex,
4234 struct xgi_hw_device_info *HwDeviceExtension,
4235 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004236{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304237 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304239 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004240
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004241 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004242 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304243 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004244 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304246 tempbx = pVBInfo->RVBHCMAX;
4247 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004248 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304249 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4250 tempcx = pVBInfo->VGAHT - 1;
4251 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004252 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304254 temp = ((tempcx & 0xFF00) >> 8) << 3;
4255 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304257 tempcx = pVBInfo->VGAVT - 1;
4258 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4259 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004260
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304261 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004262 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304263 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004264 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004265 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304266 tempcx = pVBInfo->VBInfo;
4267 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004268
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304269 if (modeflag & HalfDCLK)
4270 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004271
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304272 if (XGI_IsLCDDualLink(pVBInfo))
4273 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004274
Peter Huewe599801f2012-02-09 21:11:45 +01004275 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304276 temp = 0;
4277 if (tempbx <= 1024)
4278 temp = 0xA0;
4279 if (tempbx == 1280)
4280 temp = 0xC0;
4281 } else if (tempcx & SetCRT2ToTV) {
4282 temp = 0xA0;
4283 if (tempbx <= 800)
4284 temp = 0x80;
4285 } else {
4286 temp = 0x80;
4287 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4288 temp = 0;
4289 if (tempbx > 800)
4290 temp = 0x60;
4291 }
4292 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004293
Peter Huewe599801f2012-02-09 21:11:45 +01004294 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304295 temp = 0x00;
4296 if (pVBInfo->VGAHDE == 1280)
4297 temp = 0x40;
4298 if (pVBInfo->VGAHDE == 1024)
4299 temp = 0x20;
4300 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004301 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004302
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304303 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004304
Peter Huewe599801f2012-02-09 21:11:45 +01004305 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304306 if (!(temp & 0xE000))
4307 tempbx = tempbx >> 1;
4308 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004309
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304310 tempcx = pVBInfo->RVBHRS;
4311 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004312 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004313
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304314 tempeax = pVBInfo->VGAVDE;
4315 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004316
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304317 if (tempeax <= tempebx) {
4318 tempcx = (tempcx & (~0x4000));
4319 tempeax = pVBInfo->VGAVDE;
4320 } else {
4321 tempeax -= tempebx;
4322 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004323
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304324 templong = (tempeax * 256 * 1024) % tempebx;
4325 tempeax = (tempeax * 256 * 1024) / tempebx;
4326 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004327
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304328 if (templong != 0)
4329 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304331 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004332 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004333
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304334 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004335 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304336 tempbx = (unsigned short) (tempebx >> 16);
4337 temp = tempbx & 0x00FF;
4338 temp = temp << 4;
4339 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004340 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004341
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304342 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004343 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4344 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304345 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004346 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304347 tempax = pVBInfo->VGAHDE;
4348 if (modeflag & HalfDCLK)
4349 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004350
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304351 if (XGI_IsLCDDualLink(pVBInfo))
4352 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304354 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4355 if (tempax > 800)
4356 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004357 } else if (pVBInfo->VGAHDE > 800) {
4358 if (pVBInfo->VGAHDE == 1024)
4359 tempax = (tempax * 25 / 32) - 1;
4360 else
4361 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304362 }
4363 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004364
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304365 temp = (tempax & 0xFF00) >> 8;
4366 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004367 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304368 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004369 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004370
Peter Huewe599801f2012-02-09 21:11:45 +01004371 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304372 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004373 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004374
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304375 }
4376 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004377
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304378 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4379 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004380 | TVSetYPbPr525p | TVSetYPbPr750p
4381 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304382 temp |= 0x0001;
4383 if ((pVBInfo->VBInfo & SetInSlaveMode)
4384 && (!(pVBInfo->TVInfo
4385 & TVSimuMode)))
4386 temp &= (~0x0001);
4387 }
4388 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004389
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004390 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304391 tempbx = pVBInfo->HT;
4392 if (XGI_IsLCDDualLink(pVBInfo))
4393 tempbx = tempbx >> 1;
4394 tempbx = (tempbx >> 1) - 2;
4395 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004396 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304397 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004398 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304399 }
4400 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004401
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004402 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004403}
4404
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004405static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4406{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004407 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004408}
4409
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004410static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304411 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004412{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304413 if (pVBInfo->ModeType == ModeVGA) {
4414 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004415 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304416 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304417 }
4418 }
4419 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004420}
4421
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004422static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304423 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004424{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004425 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004426}
4427
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004428static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304429 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004430{
4431
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004432 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004433}
4434
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004435static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4436 unsigned short ModeNo, unsigned short ModeIdIndex,
4437 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004438{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004439 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004440
Aaro Koskinenb3979922012-11-04 21:14:52 +02004441 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004442 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4443 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004444 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004445 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004446
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304447 if (!(modeflag & Charx8Dot)) {
4448 xres /= 9;
4449 xres *= 8;
4450 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004451
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004452 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4453 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004454
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004455 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4456 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004457
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004458 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304459 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004460
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004461 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304462 return 0;
4463
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004464 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4465 yres != xgifb_info->lvds_data.LVDSVDE) {
4466 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4467 if (colordepth > 2)
4468 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304469 }
4470 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004471}
4472
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004473static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4474 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004475 unsigned short ModeNo,
4476 unsigned short ModeIdIndex,
4477 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004478{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304479 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004480 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304481 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4482 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4483 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004484
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004485 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004486 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304487 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004488 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004489
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004490 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004491
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004492 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004493 /* SR35[7] FP VSync polarity */
4494 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4495 /* SR30[5] FP HSync polarity */
4496 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004497
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004498 if (chip_id == XG27)
4499 XGI_SetXG27FPBits(pVBInfo);
4500 else
4501 XGI_SetXG21FPBits(pVBInfo);
4502
Aaro Koskinenb3979922012-11-04 21:14:52 +02004503 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004504 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4505 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004506 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004507 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004508
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304509 if (!(modeflag & Charx8Dot))
4510 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004511
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004512 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004513
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004514 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004515
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304516 if (LVDSHBS > LVDSHT)
4517 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004518
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004519 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304520 if (LVDSHRS > LVDSHT)
4521 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004522
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004523 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304524 if (LVDSHRE > LVDSHT)
4525 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004526
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004527 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004528
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004529 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004530
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004531 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004532 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304533 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004534
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304535 if (LVDSVBS > LVDSVT)
4536 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004537
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004538 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304539 if (LVDSVRS > LVDSVT)
4540 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004541
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004542 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304543 if (LVDSVRE > LVDSVT)
4544 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004545
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004546 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004547
Aaro Koskinen58839b02011-03-13 12:26:23 +02004548 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004549 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004550
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004552 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004553
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304554 /* HT SR0B[1:0] CR00 */
4555 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004556 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004557 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004558
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304559 /* HBS SR0B[5:4] CR02 */
4560 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004561 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004562 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004563
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304564 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4565 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004566 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4567 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4568 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004569
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304570 /* HRS SR0B[7:6] CR04 */
4571 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004572 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004573 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004574
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304575 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4576 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004577 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004578 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004579
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304580 /* HRE SR0C[2] CR05[4:0] */
4581 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004582 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4583 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004584
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304585 /* Panel HRE SR2F[7:2] */
4586 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004587 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004588
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304589 /* VT SR0A[0] CR07[5][0] CR06 */
4590 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004591 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4592 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4593 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004594 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004595
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304596 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4597 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004598 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4599 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4600 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004601 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004602
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304603 /* VBE SR0A[4] CR16 */
4604 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004605 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004606 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004607
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304608 /* VRS SR0A[3] CR7[7][2] CR10 */
4609 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004610 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4611 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4612 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004613 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004614
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004615 if (chip_id == XG27) {
4616 /* Panel VRS SR35[2:0] SR34[7:0] */
4617 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4618 (value & 0x700) >> 8);
4619 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4620 } else {
4621 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4622 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4623 (value & 0x600) >> 9);
4624 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4625 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4626 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004627
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304628 /* VRE SR0A[5] CR11[3:0] */
4629 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004630 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4631 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004632
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304633 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004634 if (chip_id == XG27)
4635 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4636 (value << 2) & 0xFC);
4637 else
4638 /* SR3F[7] has to be 0, h/w bug */
4639 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4640 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004641
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304642 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004643
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004644 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004645 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004646 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004647 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004648 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304649 value += 0x10;
4650 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004651
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304652 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004653 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004654 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004655 /* set data, panning = 0, shift left 1 dot*/
4656 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004657
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004658 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004659 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304660
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004661 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304662 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004663
4664}
4665
4666/* --------------------------------------------------------------------- */
4667/* Function : XGI_IsLCDON */
4668/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004669/* Output : 0 : Skip PSC Control */
4670/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004671/* Description : */
4672/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004673static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004674{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304675 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004676
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304677 tempax = pVBInfo->VBInfo;
4678 if (tempax & SetCRT2ToDualEdge)
4679 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004680 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304681 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004682
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304683 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004684}
4685
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004686/* --------------------------------------------------------------------- */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004687/* Function : XGI_EnableChISLCD */
4688/* Input : */
4689/* Output : 0 -> Not LCD mode */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004690/* Description : if bool enable = true -> enable, else disable */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004691/* --------------------------------------------------------------------- */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004692static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo,
4693 bool enable)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004694{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304695 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004696
Peter Huewe06cc47b2013-02-03 22:54:38 +01004697 if (enable)
4698 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
4699 else
4700 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
4701
Aaro Koskinen58839b02011-03-13 12:26:23 +02004702 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004703
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304704 if (tempbx & (EnableChA | DisableChA)) {
4705 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4706 return 0;
4707 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004708
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304709 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04004710 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304712 if (tempah & 0x01) /* Chk LCDB Mode */
4713 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004714
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304715 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004716}
4717
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004718static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4719 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304720 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004721{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004722 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004723
Peter Huewe6896b942012-02-09 21:11:46 +01004724 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4725 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304726 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004727 if (!(pVBInfo->VBInfo &
4728 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004729 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304730 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
4731 tempah = 0x7F; /* Disable Channel A */
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004732 if (!(pVBInfo->VBInfo &
4733 XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004734 /* Disable Channel B */
4735 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004736
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304737 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004738 /* force to disable Cahnnel */
4739 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004740
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304741 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004742 /* Force to disable Channel B */
4743 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304744 }
4745 }
4746 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004747
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004748 /* disable part4_1f */
4749 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004750
Peter Huewe6896b942012-02-09 21:11:46 +01004751 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004752 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004753 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
4754 (XGI_EnableChISLCD(pVBInfo, false)) ||
4755 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004756 /* LVDS Driver power down */
4757 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304758 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004759
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304760 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004761 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304762 | SetSimuScanMode))) {
4763 if (pVBInfo->SetFlag & GatingCRT)
4764 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004765 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304766 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004767
Peter Huewea3d675c2012-02-09 21:11:47 +01004768 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304769 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004770 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004771 /* Power down */
4772 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304773 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004774
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004775 /* disable TV as primary VGA swap */
4776 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004777
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304778 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004779 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004780
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004781 if ((pVBInfo->SetFlag & DisableChB) ||
4782 (pVBInfo->VBInfo &
4783 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004784 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004785 (pVBInfo->VBInfo &
4786 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004787 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004788
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004789 if ((pVBInfo->SetFlag & DisableChB) ||
4790 (pVBInfo->VBInfo &
4791 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004792 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004793 (pVBInfo->VBInfo &
4794 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4795 /* save Part1 index 0 */
4796 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4797 /* BTDAC = 1, avoid VB reset */
4798 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4799 /* disable CRT2 */
4800 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4801 /* restore Part1 index 0 */
4802 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304803 }
4804 } else { /* {301} */
4805 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004806 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4807 /* Disable CRT2 */
4808 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4809 /* Disable TV asPrimary VGA swap */
4810 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304811 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004812
Peter Huewea3d675c2012-02-09 21:11:47 +01004813 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304814 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004815 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304816 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004817}
4818
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004819/* --------------------------------------------------------------------- */
4820/* Function : XGI_GetTVPtrIndex */
4821/* Input : */
4822/* Output : */
4823/* Description : bx 0 : ExtNTSC */
4824/* 1 : StNTSC */
4825/* 2 : ExtPAL */
4826/* 3 : StPAL */
4827/* 4 : ExtHiTV */
4828/* 5 : StHiTV */
4829/* 6 : Ext525i */
4830/* 7 : St525i */
4831/* 8 : Ext525p */
4832/* 9 : St525p */
4833/* A : Ext750p */
4834/* B : St750p */
4835/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004836static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004837{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304838 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004839
Peter Huewe599801f2012-02-09 21:11:45 +01004840 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304841 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004842 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304843 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004844 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304845 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004846 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304847 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004848 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304849 tempbx = 10;
4850 if (pVBInfo->TVInfo & TVSimuMode)
4851 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004852
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304853 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004854}
4855
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004856/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004857/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004858/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004859/* Output : bx 0 : NTSC */
4860/* 1 : PAL */
4861/* 2 : PALM */
4862/* 3 : PALN */
4863/* 4 : NTSC1024x768 */
4864/* 5 : PAL-M 1024x768 */
4865/* 6-7: reserved */
4866/* cl 0 : YFilter1 */
4867/* 1 : YFilter2 */
4868/* ch 0 : 301A */
4869/* 1 : 301B/302B/301LV/302LV */
4870/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004871/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004872static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4873 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004874{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004875 *tempbx = 0;
4876 *tempcl = 0;
4877 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004878
Peter Huewe599801f2012-02-09 21:11:45 +01004879 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004880 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004881
Peter Huewe599801f2012-02-09 21:11:45 +01004882 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004883 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004884
Peter Huewe599801f2012-02-09 21:11:45 +01004885 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004886 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004887
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004888 if (pVBInfo->TVInfo & NTSC1024x768) {
4889 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004890 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004891 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304892 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004893
Peter Huewe6896b942012-02-09 21:11:46 +01004894 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4895 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004896 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4897 & TVSimuMode)) {
4898 *tempbx += 8;
4899 *tempcl += 1;
4900 }
4901 }
4902
Peter Huewe6896b942012-02-09 21:11:46 +01004903 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4904 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004905 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004906}
4907
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004908static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004909{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304910 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004911
Peter Huewe6896b942012-02-09 21:11:46 +01004912 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4913 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004914 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304915 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304916 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004917 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004918
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304919 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4920 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004921 if (pVBInfo->VBInfo &
4922 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004923 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004924
Peter Huewea3d675c2012-02-09 21:11:47 +01004925 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304926 tempbl = tempbh;
4927 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304929 tempbl &= 0x0F;
4930 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004931 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004932
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304933 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4934 | SetCRT2ToTV)) { /* Channel B */
4935 tempah &= 0xF0;
4936 tempah |= tempbl;
4937 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004938
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004939 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4940 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304941 tempah &= 0x0F;
4942 tempah |= tempbh;
4943 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004944 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304945 }
4946 } else if (pVBInfo->IF_DEF_LVDS == 1) {
4947 tempbl = 0;
4948 tempbh = 0;
4949 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004950 tempah = XGI301LCDDelay;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304951 tempah &= 0x0f;
4952 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004953 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304954 tempah);
4955 }
4956 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004957}
4958
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004959static void XGI_SetLCDCap_A(unsigned short tempcx,
4960 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004961{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304962 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004963
Aaro Koskinen58839b02011-03-13 12:26:23 +02004964 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304966 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004967 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004968 /* Enable Dither */
4969 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004970 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304971 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004972 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304973 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004974 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304975 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004976}
4977
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004978/* --------------------------------------------------------------------- */
4979/* Function : XGI_SetLCDCap_B */
4980/* Input : cx -> LCD Capability */
4981/* Output : */
4982/* Description : */
4983/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004984static void XGI_SetLCDCap_B(unsigned short tempcx,
4985 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004986{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304987 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004988 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304989 (unsigned short) (((tempcx & 0x00ff) >> 6)
4990 | 0x0c));
4991 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004992 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304993 (unsigned short) (((tempcx & 0x00ff) >> 6)
4994 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004995}
4996
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004997static void XGI_LongWait(struct vb_device_info *pVBInfo)
4998{
4999 unsigned short i;
5000
5001 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5002
5003 if (!(i & 0xC0)) {
5004 for (i = 0; i < 0xFFFF; i++) {
5005 if (!(inb(pVBInfo->P3da) & 0x08))
5006 break;
5007 }
5008
5009 for (i = 0; i < 0xFFFF; i++) {
5010 if ((inb(pVBInfo->P3da) & 0x08))
5011 break;
5012 }
5013 }
5014}
5015
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005016static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005017{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305018 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005019
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305020 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005021
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005022 /* disable down spectrum D[4] */
5023 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305024 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005025 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305026 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005027
Aaro Koskinen8104e322011-03-13 12:26:22 +02005028 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305029 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005030 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305031 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005032 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305033 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005034 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305035 pVBInfo->LCDCapList[index].Spectrum_34);
5036 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005037 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005038}
5039
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005040static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5041{
5042 unsigned short tempcx;
5043
5044 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5045
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005046 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005047 (VB_SIS301B |
5048 VB_SIS302B |
5049 VB_SIS301LV |
5050 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005051 VB_XGI301C)) { /* 301LV/302LV only */
5052 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005053 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005054 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005055 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005056 (unsigned char) (tempcx & 0x1F));
5057 }
5058 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005059 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005060 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
5061 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
5062 | EnablePLLSPLOW)) >> 8));
5063 }
5064
Peter Huewe6896b942012-02-09 21:11:46 +01005065 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5066 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005067 if (pVBInfo->VBInfo & SetCRT2ToLCD)
5068 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01005069 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005070 XGI_SetLCDCap_A(tempcx, pVBInfo);
5071
Peter Huewe6896b942012-02-09 21:11:46 +01005072 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005073 if (tempcx & EnableSpectrum)
5074 SetSpectrum(pVBInfo);
5075 }
5076 } else {
5077 /* LVDS,CH7017 */
5078 XGI_SetLCDCap_A(tempcx, pVBInfo);
5079 }
5080}
5081
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005082/* --------------------------------------------------------------------- */
5083/* Function : XGI_SetAntiFlicker */
5084/* Input : */
5085/* Output : */
5086/* Description : Set TV Customized Param. */
5087/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005088static void XGI_SetAntiFlicker(unsigned short ModeNo,
5089 unsigned short ModeIdIndex,
5090 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005091{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03005092 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005093
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305094 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005095
Peter Huewe599801f2012-02-09 21:11:45 +01005096 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305097 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305099 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5100 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305101 tempah = TVAntiFlickList[tempbx];
5102 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005103
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005104 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005105}
5106
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005107static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5108 unsigned short ModeIdIndex,
5109 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005110{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03005111 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305113 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305115 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5116 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305117 tempah = TVEdgeList[tempbx];
5118 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005119
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005120 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005121}
5122
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005123static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005124{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305125 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305127 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305129 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005130
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305131 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5132 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005133
Aaro Koskinen8104e322011-03-13 12:26:22 +02005134 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305135 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005136 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305137 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005138 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305139 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005140 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305141 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005142}
5143
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005144static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305145 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005146{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305147 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02005148 unsigned char const *filterPtr;
5149 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305151 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005152
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305153 switch (tempbx) {
5154 case 0x00:
5155 case 0x04:
5156 filterPtr = NTSCYFilter1;
5157 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005158
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305159 case 0x01:
5160 filterPtr = PALYFilter1;
5161 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305163 case 0x02:
5164 case 0x05:
5165 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305166 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005167 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305168 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305170 case 0x08:
5171 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305172 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305173 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305174 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005175 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305176 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005177
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305178 default:
5179 return;
5180 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005181
Aaro Koskinenb3979922012-11-04 21:14:52 +02005182 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305183 if (tempcl == 0)
5184 index = tempal * 4;
5185 else
5186 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305188 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005189 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5190 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5191 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5192 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305193 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005194 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5195 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5196 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5197 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305198 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005199
Peter Huewe6896b942012-02-09 21:11:46 +01005200 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5201 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005202 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5203 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5204 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305205 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005206}
5207
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005208/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005209/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005210/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005211/* Output : */
5212/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005213/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005214static void XGI_OEM310Setting(unsigned short ModeNo,
5215 unsigned short ModeIdIndex,
5216 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005217{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005218 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005219
Peter Huewea3d675c2012-02-09 21:11:47 +01005220 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005221 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005222
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005223 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005224 XGI_SetPhaseIncr(pVBInfo);
5225 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5226 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005227
Peter Huewe6896b942012-02-09 21:11:46 +01005228 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005229 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305230 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005231}
5232
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005233/* --------------------------------------------------------------------- */
5234/* Function : XGI_SetCRT2ModeRegs */
5235/* Input : */
5236/* Output : */
5237/* Description : Origin code for crt2group */
5238/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005239static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305240 struct xgi_hw_device_info *HwDeviceExtension,
5241 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005242{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305243 unsigned short tempbl;
5244 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305246 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005247
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305248 tempah = 0;
5249 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005250 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305251 tempah &= ~0x10; /* BTRAMDAC */
5252 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305254 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5255 | SetCRT2ToLCD)) {
5256 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005257 tempcl = pVBInfo->ModeType;
5258 tempcl -= ModeVGA;
5259 if (tempcl >= 0) {
5260 /* BT Color */
5261 tempah = (0x008 >> tempcl);
5262 if (tempah == 0)
5263 tempah = 1;
5264 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305265 }
5266 if (pVBInfo->VBInfo & SetInSlaveMode)
5267 tempah ^= 0x50; /* BTDAC */
5268 }
5269 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005270
Aaro Koskinen8104e322011-03-13 12:26:22 +02005271 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305272 tempah = 0x08;
5273 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005274
Miguel Gómeze123e462012-07-06 12:40:52 +02005275 if (pVBInfo->VBInfo & DisableCRT2Display)
5276 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005277
Miguel Gómeze123e462012-07-06 12:40:52 +02005278 tempah = 0x00;
5279 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005280
Miguel Gómeze123e462012-07-06 12:40:52 +02005281 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5282 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5283 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005284
Miguel Gómeze123e462012-07-06 12:40:52 +02005285 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5286 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5287 tempbl &= 0xf7;
5288 tempah |= 0x01;
5289 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305290 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005291
Miguel Gómeze123e462012-07-06 12:40:52 +02005292 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5293 tempbl &= 0xf7;
5294 tempah |= 0x01;
5295 }
5296
5297 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5298 goto reg_and_or;
5299
5300 tempbl &= 0xf8;
5301 tempah = 0x01;
5302
5303 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5304 tempah |= 0x02;
5305
5306 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5307 tempah = tempah ^ 0x05;
5308 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5309 tempah = tempah ^ 0x01;
5310 }
5311
5312 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5313 tempah |= 0x08;
5314
5315reg_and_or:
5316 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5317
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305318 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005319 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305320 tempah &= (~0x08);
5321 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5322 & SetInSlaveMode))) {
5323 tempah |= 0x010;
5324 }
5325 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005326
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305327 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305328 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005329 if (pVBInfo->VBInfo & DriverMode)
5330 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305331 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005332
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005333 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305334 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305336 if (pVBInfo->LCDInfo & SetLCDDualLink)
5337 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005338
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305339 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305340 if (pVBInfo->TVInfo & RPLLDIV2XO)
5341 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305342 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005343
Peter Huewe255aabd2012-02-09 21:11:44 +01005344 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5345 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305346 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005347
Peter Huewe255aabd2012-02-09 21:11:44 +01005348 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305349 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005350
Aaro Koskinen8104e322011-03-13 12:26:22 +02005351 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305352 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005353
Peter Huewe6896b942012-02-09 21:11:46 +01005354 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5355 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305356 tempah = 0;
5357 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005358
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305359 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5360 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005361 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305362 tempah |= 0x04; /* shampoo 0129 */
5363 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005364
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005365 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305366 tempah = 0x00;
5367 tempbl = 0xcf;
5368 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5369 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5370 tempah |= 0x30;
5371 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005372
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005373 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305374 tempah = 0;
5375 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005376
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305377 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5378 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5379 tempah |= 0xc0;
5380 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005381 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305382 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005383
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305384 tempah = 0;
5385 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005386 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305387 tempbl = 0xff;
5388 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5389 tempah |= 0x80;
5390 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005391
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005392 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005393
Peter Huewe6896b942012-02-09 21:11:46 +01005394 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305395 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005396 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5397 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305398 }
5399 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005400}
5401
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005402
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305403void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5404 struct vb_device_info *pVBInfo)
5405{
5406
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005407 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005408
5409}
5410
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305411void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5412 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005413{
5414
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005415 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005416
5417}
5418
Bill Pemberton80adad82010-06-17 13:10:51 -04005419unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005420{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305421 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005422
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305423 if (pVBInfo->IF_DEF_LVDS == 1) {
5424 return 1;
5425 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005426 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305427 if ((flag == 1) || (flag == 2))
5428 return 1; /* 301b */
5429 else
5430 return 0;
5431 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005432}
5433
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005434unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5435 unsigned short ModeNo, unsigned short ModeIdIndex,
5436 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005437{
Peter Huewef2c22602013-02-03 22:54:30 +01005438 const u8 LCDARefreshIndex[] = {
5439 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005440
Peter Hueweef9a6b92013-02-03 04:08:43 +01005441 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005442
Aaro Koskinen58839b02011-03-13 12:26:23 +02005443 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005444 index = index >> pVBInfo->SelectCRT2Rate;
5445 index &= 0x0F;
5446
5447 if (pVBInfo->LCDInfo & LCDNonExpanding)
5448 index = 0;
5449
5450 if (index > 0)
5451 index--;
5452
5453 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005454 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005455 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewef2c22602013-02-03 22:54:30 +01005456 temp = LCDARefreshIndex[
5457 pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005458
5459 if (index > temp)
5460 index = temp;
5461 } else {
5462 index = 0;
5463 }
5464 }
5465 }
5466
Aaro Koskinenb3979922012-11-04 21:14:52 +02005467 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005468 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005469 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005470 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5471 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005472 index++;
5473 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005474 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005475 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5476 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005477 index++;
5478 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005479 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5480 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005481 index++;
5482 }
5483 }
5484
5485 i = 0;
5486 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005487 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005488 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005489 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005490 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005491 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005492 if (temp < pVBInfo->ModeType)
5493 break;
5494 i++;
5495 index--;
5496
5497 } while (index != 0xFFFF);
5498 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5499 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005500 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005501 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005502 if (temp & InterlaceMode)
5503 i++;
5504 }
5505 }
5506 i--;
5507 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5508 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5509 RefreshRateTableIndex, &i, pVBInfo);
5510 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005511 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005512}
5513
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005514static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305515 struct xgi_hw_device_info *HwDeviceExtension,
5516 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005517{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005518 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005519
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005520 pVBInfo->SetFlag |= ProgrammingCRT2;
5521 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5522 ModeIdIndex, pVBInfo);
5523 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5524 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5525 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5526 HwDeviceExtension, pVBInfo);
5527 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5528 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005529}
5530
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005531static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005532 struct xgi_hw_device_info *HwDeviceExtension,
5533 struct vb_device_info *pVBInfo)
5534{
Peter Huewea9e29e62013-02-03 04:08:44 +01005535 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005536
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005537 pVBInfo->SetFlag |= ProgrammingCRT2;
5538 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5539 pVBInfo->SelectCRT2Rate = 4;
5540 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5541 ModeIdIndex, pVBInfo);
5542 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5543 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5544 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5545 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5546 RefreshRateTableIndex, pVBInfo);
5547 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5548 RefreshRateTableIndex, pVBInfo);
5549 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5550 RefreshRateTableIndex, pVBInfo);
5551 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5552 HwDeviceExtension, pVBInfo);
5553 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5554 RefreshRateTableIndex, pVBInfo);
5555 XGI_SetTap4Regs(pVBInfo);
5556 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5557 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5558 HwDeviceExtension, pVBInfo);
5559 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5560 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5561 XGI_AutoThreshold(pVBInfo);
5562 return 1;
5563}
5564
5565void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5566{
5567 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5568 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5569 0x05, 0x00 };
5570
5571 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5572
5573 unsigned char CR17, CR63, SR31;
5574 unsigned short temp;
5575 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
5576
5577 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005578 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005579
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005580 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005581 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005582 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005583 pVBInfo->P3d4, 0x53) | 0x02));
5584
Aaro Koskinen58839b02011-03-13 12:26:23 +02005585 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
5586 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
5587 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005588
Aaro Koskinen8104e322011-03-13 12:26:22 +02005589 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5590 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005591
Aaro Koskinen58839b02011-03-13 12:26:23 +02005592 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005593 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005594
Aaro Koskinen58839b02011-03-13 12:26:23 +02005595 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005596 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005597
Aaro Koskinen58839b02011-03-13 12:26:23 +02005598 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005599 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02005600 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005601 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005602
Aaro Koskinen8104e322011-03-13 12:26:22 +02005603 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005604
5605 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005606 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005607
5608 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005609 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005610 CRTCData[i]);
5611
5612 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005613 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005614 CRTCData[i]);
5615
5616 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005617 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005618 CRTCData[i]);
5619
Aaro Koskinen8104e322011-03-13 12:26:22 +02005620 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005621 & 0xE0));
5622
Aaro Koskinen8104e322011-03-13 12:26:22 +02005623 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5624 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5625 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005626
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005627 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005628
5629 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005630 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
5631 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
5632 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005633 }
5634
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005635 mdelay(1);
5636
5637 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005638 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005639
5640 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005641 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005642 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005643 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005644
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005645 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005646 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005647
5648 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005649 outb(0, (pVBInfo->P3c8 + 1));
5650 outb(0, (pVBInfo->P3c8 + 1));
5651 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005652 }
5653
Aaro Koskinen8104e322011-03-13 12:26:22 +02005654 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5655 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5656 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005657
Aaro Koskinen58839b02011-03-13 12:26:23 +02005658 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005659 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005660 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005661}
5662
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005663static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5664 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005665 struct vb_device_info *pVBInfo)
5666{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005667 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005668
Peter Huewe6896b942012-02-09 21:11:46 +01005669 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5670 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005671 if (!(pVBInfo->SetFlag & DisableChA)) {
5672 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005673 /* Power on */
5674 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03005675 } else if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5676 /* Power on */
5677 xgifb_reg_set(pVBInfo->Part1Port,
5678 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005679 }
5680 }
5681
5682 if (!(pVBInfo->SetFlag & DisableChB)) {
5683 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5684 & (SetCRT2ToLCD | SetCRT2ToTV
5685 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005686 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005687 pVBInfo->P3c4, 0x32);
5688 tempah &= 0xDF;
5689 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005690 if (!(pVBInfo->VBInfo &
5691 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005692 tempah |= 0x20;
5693 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005694 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005695 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005696
Aaro Koskinen58839b02011-03-13 12:26:23 +02005697 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005698 pVBInfo->Part1Port, 0x2E);
5699
5700 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005701 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005702 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005703 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005704 }
5705 }
5706
5707 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
5708 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005709 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005710 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005711 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Peter Huewe06cc47b2013-02-03 22:54:38 +01005712 if (!XGI_EnableChISLCD(pVBInfo, false)) {
5713 if (XGI_EnableChISLCD(pVBInfo, true) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005714 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01005715 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005716 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02005717 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005718 pVBInfo->Part4Port,
5719 0x2A,
5720 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005721 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005722 /* LVDS Driver power on */
5723 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005724 }
5725 }
5726
5727 tempah = 0x00;
5728
5729 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5730 tempah = 0xc0;
5731
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005732 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5733 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5734 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5735 tempah = tempah & 0x40;
5736 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5737 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005738
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005739 if (pVBInfo->SetFlag & DisableChB)
5740 tempah &= 0xBF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005741
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005742 if (pVBInfo->SetFlag & DisableChA)
5743 tempah &= 0x7F;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005744
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005745 if (pVBInfo->SetFlag & EnableChB)
5746 tempah |= 0x40;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005747
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005748 if (pVBInfo->SetFlag & EnableChA)
5749 tempah |= 0x80;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005750 }
5751 }
5752
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005753 /* EnablePart4_1F */
5754 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005755
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005756 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005757 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005758 XGI_DisableGatingCRT(HwDeviceExtension,
5759 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005760 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
5761 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005762 }
5763 }
5764 } /* 301 */
5765 else { /* LVDS */
5766 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005767 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005768 /* enable CRT2 */
5769 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005770
Aaro Koskinen58839b02011-03-13 12:26:23 +02005771 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005772 0x2E);
5773 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005774 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005775
Aaro Koskinendc505562011-03-13 12:26:26 +02005776 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005777 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005778 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005779}
5780
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005781static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5782 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005783 unsigned short ModeNo, unsigned short ModeIdIndex,
5784 struct vb_device_info *pVBInfo)
5785{
Aaro Koskinena1579612012-04-07 01:14:05 +03005786 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005787
Aaro Koskinena1579612012-04-07 01:14:05 +03005788 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005789 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005790 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5791 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5792 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005793 XGI_ClearExt1Regs(pVBInfo);
5794
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005795 if (HwDeviceExtension->jChipType == XG27) {
5796 if (pVBInfo->IF_DEF_LVDS == 0)
5797 XGI_SetDefaultVCLK(pVBInfo);
5798 }
5799
5800 temp = ~ProgrammingCRT2;
5801 pVBInfo->SetFlag &= temp;
5802 pVBInfo->SelectCRT2Rate = 0;
5803
Peter Huewe6896b942012-02-09 21:11:46 +01005804 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5805 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005806 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005807 | SetInSlaveMode)) {
5808 pVBInfo->SetFlag |= ProgrammingCRT2;
5809 }
5810 }
5811
5812 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5813 ModeIdIndex, pVBInfo);
5814 if (RefreshRateTableIndex != 0xFFFF) {
5815 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5816 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5817 pVBInfo, HwDeviceExtension);
5818 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5819 RefreshRateTableIndex, pVBInfo);
5820 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5821 HwDeviceExtension, pVBInfo);
5822 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5823 RefreshRateTableIndex, pVBInfo);
5824 }
5825
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005826 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005827 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005828 if (temp & 0xA0) {
5829
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005830 if (HwDeviceExtension->jChipType == XG27)
5831 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5832 RefreshRateTableIndex, pVBInfo);
5833 else
5834 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5835 RefreshRateTableIndex, pVBInfo);
5836
5837 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5838 RefreshRateTableIndex);
5839
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005840 xgifb_set_lcd(HwDeviceExtension->jChipType,
5841 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005842
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005843 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005844 xgifb_set_lvds(xgifb_info,
5845 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005846 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005847 }
5848 }
5849
5850 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5851 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5852 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5853 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005854 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005855}
5856
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005857unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5858 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005859 unsigned short ModeNo)
5860{
5861 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005862 struct vb_device_info VBINF;
5863 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005864 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005865
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005866 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005867 pVBInfo->IF_DEF_YPbPr = 0;
5868 pVBInfo->IF_DEF_HiVision = 0;
5869 pVBInfo->IF_DEF_CRT2Monitor = 0;
5870 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005871 } else {
5872 pVBInfo->IF_DEF_YPbPr = 1;
5873 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005874 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005875 }
5876
Aaro Koskinen56810a92013-01-21 02:57:47 +02005877 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005878
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005879 /* for x86 Linux, XG21 LVDS */
5880 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005881 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005882 pVBInfo->IF_DEF_LVDS = 1;
5883 }
5884 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005885 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5886 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005887 pVBInfo->IF_DEF_LVDS = 1;
5888 }
5889 }
5890
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005891 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005892 XGI_GetVBType(pVBInfo);
5893
5894 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005895 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005896 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005897 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005898
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005899 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005900 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
5901
5902 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5903
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005904 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005905 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
5906 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
5907 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005908 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005909
Peter Huewea3d675c2012-02-09 21:11:47 +01005910 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005911 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005912 ModeIdIndex, pVBInfo);
5913
Peter Huewea3d675c2012-02-09 21:11:47 +01005914 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005915 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5916 HwDeviceExtension, pVBInfo);
5917 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03005918 } else if (!(pVBInfo->VBInfo & SwitchCRT2)) {
5919 XGI_SetCRT1Group(xgifb_info,
5920 HwDeviceExtension, ModeNo,
5921 ModeIdIndex, pVBInfo);
5922 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5923 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5924 HwDeviceExtension,
5925 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005926 }
5927 }
5928
Peter Huewe6896b942012-02-09 21:11:46 +01005929 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005930 switch (HwDeviceExtension->ujVBChipID) {
5931 case VB_CHIP_301:
5932 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5933 pVBInfo); /*add for CRT2 */
5934 break;
5935
5936 case VB_CHIP_302:
5937 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5938 pVBInfo); /*add for CRT2 */
5939 break;
5940
5941 default:
5942 break;
5943 }
5944 }
5945
5946 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
5947 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005948 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005949 } /* !XG20 */
5950 else {
5951 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005952 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005953 ModeIdIndex,
5954 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005955 return 0;
5956
Aaro Koskinenb3979922012-11-04 21:14:52 +02005957 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005958 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005959
5960 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005961 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005962
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005963 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005964
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005965 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5966 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005967
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005968 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005969 }
5970
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005971 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
5972
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005973 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005974 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005975
5976 return 1;
5977}