blob: 137725cbfd220313c8a6a8a18d2ed21d469d54ed [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"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005#include "vb_util.h"
6#include "vb_table.h"
Miguel Gómeze0541022012-06-18 13:12:05 +02007#include "vb_setmode.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02008
9#define IndexMask 0xff
Peter Huewe95072592012-06-14 00:21:48 +020010#define TVCLKBASE_315_25 (TVCLKBASE_315 + 25)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020011
Aaro Koskinen624554d2011-10-11 21:47:35 +030012static const unsigned short XGINew_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040013 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
14 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
15 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
16 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
17 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
18 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
19 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
20 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
21 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
22 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020023
Bill Pemberton80adad82010-06-17 13:10:51 -040024void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020025{
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030026 pVBInfo->MCLKData = XGI340New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053027 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030028 pVBInfo->StResInfo = XGI330_StResInfo;
29 pVBInfo->ModeResInfo = XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020030
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053031 pVBInfo->LCDResInfo = 0;
32 pVBInfo->LCDTypeInfo = 0;
33 pVBInfo->LCDInfo = 0;
34 pVBInfo->VBInfo = 0;
35 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020036
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053037 pVBInfo->SR15 = XGI340_SR13;
38 pVBInfo->CR40 = XGI340_cr41;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053039 pVBInfo->CR6B = XGI340_CR6B;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053040 pVBInfo->AGPReg = XGI340_AGPReg;
41 pVBInfo->SR16 = XGI340_SR16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020042
Peter Huewe6d12dae2012-06-14 00:21:52 +020043 pVBInfo->SR21 = 0xa3;
44 pVBInfo->SR22 = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020045
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053046 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010047 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053048 pVBInfo->LCDCapList = XGI_LCDDLCapList;
49 else
50 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053052 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020053 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053055 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040056 unsigned char temp;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030057 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053058 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020059 pVBInfo->XGINew_CR97 = 0xc1;
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040060 pVBInfo->SR15 = XG27_SR13;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020061
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040062 /*Z11m DDR*/
63 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
64 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
65 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020066 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053067 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020068
69}
70
Kenji Toyama1d7f6562011-04-23 19:36:49 +080071static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080072 unsigned short ModeIdIndex,
73 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020074{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053075 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053076 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020077
Aaro Koskinenb3979922012-11-04 21:14:52 +020078 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020079
Aaro Koskinen8104e322011-03-13 12:26:22 +020080 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020081 tempah = XGI330_StandTable.SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020082
Peter Huewea3d675c2012-02-09 21:11:47 +010083 i = XGI_SetCRT2ToLCDA;
84 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053085 tempah |= 0x01;
Aaro Koskinend3ae5762012-09-11 00:15:27 +030086 } else if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
87 if (pVBInfo->VBInfo & SetInSlaveMode)
88 tempah |= 0x01;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053089 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020090
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053091 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +020092 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020093
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053094 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080095 /* Get SR2,3,4 from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020096 SRdata = XGI330_StandTable.SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +020097 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053098 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020099}
100
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200101static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800102 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200103{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530104 unsigned char CRTCdata;
105 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200106
Aaro Koskinen58839b02011-03-13 12:26:23 +0200107 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530108 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200109 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530111 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800112 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200113 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200114 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530115 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200116}
117
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800118static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800119 unsigned short ModeIdIndex,
120 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200121{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530122 unsigned char ARdata;
123 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200124
Aaro Koskinenb3979922012-11-04 21:14:52 +0200125 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530127 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200128 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200129
130 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
131 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
132 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300133 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200134 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300135 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530136 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530137 }
138 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200139
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200140 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200141 outb(i, pVBInfo->P3c0); /* set index */
142 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530143 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200144
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200145 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200146 outb(0x14, pVBInfo->P3c0); /* set index */
147 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200148 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200149 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200150}
151
Aaro Koskinena1579612012-04-07 01:14:05 +0300152static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200153{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530154 unsigned char GRdata;
155 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200156
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530157 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800158 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200159 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200160 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530161 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530163 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200164 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530165 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200166 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530167 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200168}
169
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200170static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200171{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530172 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530174 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200175 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200176}
177
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200178static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200179{
180
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200181 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200182 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
183 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200184
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200185 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200186 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
187 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200188
Aaro Koskinendc505562011-03-13 12:26:26 +0200189 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530190 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200191}
192
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200193static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530194 unsigned short ModeIdIndex,
195 unsigned short RefreshRateTableIndex, unsigned short *i,
196 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200197{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530198 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200199
Aaro Koskinenb3979922012-11-04 21:14:52 +0200200 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
201 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200202 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530203 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530205 if (pVBInfo->IF_DEF_LVDS == 0) {
206 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
207 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200208
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530209 if (pVBInfo->VBType & VB_XGI301C)
210 tempax |= SupportCRT2in301C;
211 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200212
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800213 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100214 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530215 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200216
Miguel Gómez3b175622012-07-06 12:40:46 +0200217 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
218 pVBInfo->LCDResInfo != Panel_1280x960 &&
219 (pVBInfo->LCDInfo & LCDNonExpanding) &&
220 resinfo >= 9)
221 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530222 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200223
Peter Huewe599801f2012-02-09 21:11:45 +0100224 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300225 tempax |= SupportHiVision;
226 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
227 ((resinfo == 4) ||
228 (resinfo == 3 &&
229 (pVBInfo->SetFlag & TVSimuMode)) ||
230 (resinfo > 7)))
Miguel Gómez3b175622012-07-06 12:40:46 +0200231 return 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300232 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800233 SetCRT2ToSVIDEO |
234 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100235 SetCRT2ToYPbPr525750 |
236 SetCRT2ToHiVision)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300237 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200238
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300239 if (pVBInfo->VBType & (VB_SIS301B |
240 VB_SIS302B |
241 VB_SIS301LV |
242 VB_SIS302LV |
243 VB_XGI301C))
244 tempax |= SupportTV1024;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200245
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300246 if (!(pVBInfo->VBInfo & TVSetPAL) &&
247 (modeflag & NoSupportSimuTV) &&
248 (pVBInfo->VBInfo & SetInSlaveMode) &&
249 (!(pVBInfo->VBInfo & SetNotSimuMode)))
250 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530251 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300252 } else if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* for LVDS */
253 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200254
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300255 if (resinfo > 0x08)
256 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200257
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300258 if (pVBInfo->LCDResInfo < Panel_1024x768) {
259 if (resinfo > 0x07)
260 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200261
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300262 if (resinfo == 0x04)
263 return 0; /* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530264 }
265 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200266
Aaro Koskinena39325d2012-11-04 21:14:53 +0200267 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800268 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200269 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800270 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530271 if (infoflag & tempax)
272 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530274 if ((*i) == 0)
275 break;
276 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200277
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530278 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200279 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800280 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200281 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530282 != tempbx) {
283 return 0;
284 }
285
286 if (infoflag & tempax)
287 return 1;
288 }
289 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200290}
291
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200292static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530293 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200294{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530295 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200296
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800297 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200298 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530299 sync &= 0xC0;
300 temp = 0x2F;
301 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200302 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200303}
304
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200305static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530306 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200307{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530308 unsigned char data, data1, pushax;
309 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200310
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800311 /* unlock cr0-7 */
312 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530313 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200314 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200315
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200316 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200317 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200318
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530319 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200320 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200321 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530322 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200323
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530324 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200325 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200326 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530327 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200328
Aaro Koskinen58839b02011-03-13 12:26:23 +0200329 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530330 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200331 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530332 data &= 0xE0;
333 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200334 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530336 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200337 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530338 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200339 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200340 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530341 data1 = data;
342 data1 &= 0xE0;
343 data &= 0x1F;
344 if (data == 0) {
345 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200346 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530347 0x0c);
348 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200349 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530350 data = pushax;
351 }
352 data = data - 1;
353 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200354 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200355 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530356 data = data >> 5;
357 data = data + 3;
358 if (data > 7)
359 data = data - 7;
360 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200361 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530362 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200363}
364
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800365static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
366 unsigned short ModeNo,
367 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200368{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530369 unsigned char data;
370 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200371
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530372 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200373 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200374 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530375 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200376
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530377 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200378 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200379 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530380 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200381
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530382 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200383 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200384 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530385 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200386
Aaro Koskinen58839b02011-03-13 12:26:23 +0200387 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530388 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200389 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530390 data &= 0x3F;
391 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200392 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200393
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200394 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530395 data &= 0x80;
396 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200397
Aaro Koskinenb3979922012-11-04 21:14:52 +0200398 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530399 i &= DoubleScanMode;
400 if (i)
401 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200402
Aaro Koskinen58839b02011-03-13 12:26:23 +0200403 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530404 j &= 0x5F;
405 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200406 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200407}
408
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200409static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
410 unsigned short RefreshRateTableIndex,
411 struct vb_device_info *pVBInfo,
412 struct xgi_hw_device_info *HwDeviceExtension)
413{
414 unsigned char index, data;
415 unsigned short i;
416
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800417 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200418 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200419 index = index & IndexMask;
420
Aaro Koskinen58839b02011-03-13 12:26:23 +0200421 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200422 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200423 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200424
425 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200426 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200427 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200428
429 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200430 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200431 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200432
433 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
434
435 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
436
437 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200438 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200439}
440
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200441/* --------------------------------------------------------------------- */
442/* Function : XGI_SetXG21CRTC */
443/* Input : Stand or enhance CRTC table */
444/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
445/* Description : Set LCD timing */
446/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200447static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530448 unsigned short RefreshRateTableIndex,
449 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200450{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300451 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530452 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200453
Aaro Koskinena39325d2012-11-04 21:14:53 +0200454 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300455 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200456 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300457 Tempcx = Tempax; /* Tempcx: HRS */
458 /* SR2E[7:0]->HRS */
459 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200460
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200461 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300462 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
463 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
464 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
465 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800466
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200467 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300468 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200469
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200470 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300471 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
472 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
473 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200474
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300475 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
476 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200477
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300478 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
479 if (Tempax < Tempcx) /* HRE < HRS */
480 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200481
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300482 Temp2 &= 0xFF;
483 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
484 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
485 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
486 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
487 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
488 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
489 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200490
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300491 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200492 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300493 Tempbx = Tempax; /* Tempbx: VRS */
494 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
495 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
496 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200497 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300498 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
499 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
500 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
501 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
502 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200503
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300504 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
505 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
506 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
507 Tempax &= 0x80;
508 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
509 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
510 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200511 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300512 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
513 Temp2 = Tempax;
514 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
515 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200516
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300517 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200518 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300519 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
520 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200521 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300522 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
523 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
524 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
525 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
526 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200527
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300528 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
529 if (Tempax < Temp3) /* VRE < VRS */
530 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200531
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300532 Temp2 &= 0xFF;
533 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
534 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
535 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
536 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
537 Tempbx = (unsigned char) Temp1;
538 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
539 Tempax &= 0x7F;
540 /* SR3F D[7:2]->VRE D[1:0]->VRS */
541 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200542}
543
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800544static void XGI_SetXG27CRTC(unsigned short ModeNo,
545 unsigned short ModeIdIndex,
546 unsigned short RefreshRateTableIndex,
547 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200548{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300549 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200550
Aaro Koskinena39325d2012-11-04 21:14:53 +0200551 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300552 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200553 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300554 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
555 /* SR2E[7:0]->HRS */
556 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200557
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300558 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200559 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300560 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
561 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200562
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200563 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300564 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
565 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200566
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200567 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300568 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
569 Tempax <<= 3; /* Tempax[5]: HRE[5] */
570 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200571
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300572 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
573 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200574
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300575 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200576 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300577 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
578 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
579 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200580
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200581 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300582 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
583 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
584 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
585 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
586 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
587 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200588
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300589 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200590 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300591 /* SR34[7:0]->VRS[7:0] */
592 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200593
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300594 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
595 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200596 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300597 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
598 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
599 Tempax >>= 2; /* Tempax[0]: VRS[8] */
600 /* SR35[0]: VRS[8] */
601 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
602 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
603 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
604 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200605 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300606 Tempax &= 0x08; /* SR0A[3] VRS[10] */
607 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200608
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300609 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200610 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300611 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
612 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200613 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300614 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
615 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
616 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
617 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
618 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
619 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200620
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300621 if (Tempbx <= Tempcx) /* VRE <= VRS */
622 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200623
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300624 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
625 Tempax = (Tempbx << 2) & 0xFF;
626 /* SR3F[7:2]:VRE[5:0] */
627 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
628 Tempax = Tempcx >> 8;
629 /* SR35[2:0]:VRS[10:8] */
630 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200631}
632
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200633static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
634{
635 unsigned char temp;
636
637 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
638 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
639 temp = (temp & 3) << 6;
640 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
641 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
642 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
643 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
644
645}
646
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300647static void xgifb_set_lcd(int chip_id,
648 struct vb_device_info *pVBInfo,
649 unsigned short RefreshRateTableIndex,
650 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200651{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300652 unsigned short Data, Temp;
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400653 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200654
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530655 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200656
Aaro Koskinen8104e322011-03-13 12:26:22 +0200657 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
658 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
659 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
660 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300661
662 if (chip_id == XG27) {
663 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
664 if ((Temp & 0x03) == 0) { /* dual 12 */
665 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
666 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
667 }
668 }
669
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300670 if (chip_id == XG27) {
671 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530672 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300673 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
674 if (Temp & 0x01) {
675 /* 18 bits FP */
676 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
677 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
678 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530679 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200680
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200681 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200682
Aaro Koskinendc505562011-03-13 12:26:26 +0200683 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
684 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200685
Aaro Koskinena39325d2012-11-04 21:14:53 +0200686 Data = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300687 if (Data & 0x4000)
688 /* Hsync polarity */
689 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
690 if (Data & 0x8000)
691 /* Vsync polarity */
692 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200693}
694
695/* --------------------------------------------------------------------- */
696/* Function : XGI_UpdateXG21CRTC */
697/* Input : */
698/* Output : CRT1 CRTC */
699/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
700/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800701static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
702 struct vb_device_info *pVBInfo,
703 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200704{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300705 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200706
Aaro Koskinendc505562011-03-13 12:26:26 +0200707 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300708 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200709 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300710 RES640x480x60))
711 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200712 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800713 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300714 index = 13;
715 else if (ModeNo == 0x2F)
716 index = 14;
717 else if (ModeNo == 0x50)
718 index = 15;
719 else if (ModeNo == 0x59)
720 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200721
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530722 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200723 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200724 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200725 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200726 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200727 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200728 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200729 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200730 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530731 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200732}
733
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200734static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530735 unsigned short ModeNo, unsigned short ModeIdIndex,
736 unsigned short RefreshRateTableIndex,
737 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200738{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400739 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200740
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530741 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200742
Aaro Koskinenb3979922012-11-04 21:14:52 +0200743 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200744
Aaro Koskinenb3979922012-11-04 21:14:52 +0200745 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300746 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
747 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200748
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530749 if (modeflag & HalfDCLK)
750 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200751
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300752 if (modeflag & HalfDCLK)
753 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200754
Aaro Koskinena39325d2012-11-04 21:14:53 +0200755 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200756
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300757 if (temp & InterlaceMode)
758 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200759
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300760 if (modeflag & DoubleScanMode)
761 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200762
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530763 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200764
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530765 tempax /= tempcx;
766 tempax -= 1;
767 tempbx -= 1;
768 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200769 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
770 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530771 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200772 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
773 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200774 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530775 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200776 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530777 tempax = 0;
778 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200779
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530780 if (tempbx & 0x01)
781 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200782
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530783 if (tempbx & 0x02)
784 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200785
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200786 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200787 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530788 data &= 0xFF;
789 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200790
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530791 if (tempbx & 0x04)
792 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200793
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200794 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200795 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200796}
797
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800798static void XGI_SetCRT1Offset(unsigned short ModeNo,
799 unsigned short ModeIdIndex,
800 unsigned short RefreshRateTableIndex,
801 struct xgi_hw_device_info *HwDeviceExtension,
802 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200803{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530804 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200805
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530806 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200807 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530808 temp = temp >> 8;
809 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200810
Aaro Koskinena39325d2012-11-04 21:14:53 +0200811 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530812 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530814 if (temp2)
815 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530817 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200818
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530819 switch (temp2) {
820 case 0:
821 temp2 = 1;
822 break;
823 case 1:
824 temp2 = 2;
825 break;
826 case 2:
827 temp2 = 4;
828 break;
829 case 3:
830 temp2 = 4;
831 break;
832 case 4:
833 temp2 = 6;
834 break;
835 case 5:
836 temp2 = 8;
837 break;
838 default:
839 break;
840 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200841
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530842 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
843 temp = temp * temp2 + temp2 / 2;
844 else
845 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530847 /* SetOffset */
848 DisplayUnit = temp;
849 temp2 = temp;
850 temp = temp >> 8; /* ah */
851 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200852 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530853 i &= 0xF0;
854 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200855 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200856
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530857 temp = (unsigned char) temp2;
858 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200859 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200860
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530861 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200862 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530863 temp2 &= InterlaceMode;
864 if (temp2)
865 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530867 DisplayUnit = DisplayUnit << 5;
868 ah = (DisplayUnit & 0xff00) >> 8;
869 al = DisplayUnit & 0x00ff;
870 if (al == 0)
871 ah += 1;
872 else
873 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530875 if (HwDeviceExtension->jChipType >= XG20)
876 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
877 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200878
Aaro Koskinen8104e322011-03-13 12:26:22 +0200879 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200880}
881
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200882static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
883 unsigned short ModeIdIndex,
884 unsigned short RefreshRateTableIndex,
885 struct xgi_hw_device_info *HwDeviceExtension,
886 struct vb_device_info *pVBInfo)
887{
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200888 unsigned short CRT2Index, VCLKIndex;
889 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200890
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300891 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200892 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
893 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200894 CRT2Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200895
896 if (pVBInfo->IF_DEF_LVDS == 0) {
897 CRT2Index = CRT2Index >> 6; /* for LCD */
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200898 if (pVBInfo->VBInfo &
899 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
Peter Huewe255aabd2012-02-09 21:11:44 +0100900 if (pVBInfo->LCDResInfo != Panel_1024x768)
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200901 /* LCDXlat2VCLK */
902 VCLKIndex = VCLK108_2_315 + 5;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200903 else
Peter Huewef477d3e2012-06-14 00:21:47 +0200904 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
Peter Huewe599801f2012-02-09 21:11:45 +0100905 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200906 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200907 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200908 else
Peter Huewe95072592012-06-14 00:21:48 +0200909 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200910
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200911 if (pVBInfo->SetFlag & TVSimuMode) {
912 if (modeflag & Charx8Dot) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200913 VCLKIndex = TVCLKBASE_315_25 +
914 HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200915 } else {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200916 VCLKIndex = TVCLKBASE_315_25 +
917 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200918 }
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200919 }
920
921 /* 301lv */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300922 if (pVBInfo->VBType & VB_SIS301LV) {
923 if (pVBInfo->SetFlag & RPLLDIV2XO)
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200924 VCLKIndex = YPbPr525iVCLK_2;
925 else
926 VCLKIndex = YPbPr525iVCLK;
927 }
928 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200929 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200930 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200931 else
Peter Huewe95072592012-06-14 00:21:48 +0200932 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200933 } else { /* for CRT2 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300934 /* di+Ext_CRTVCLK */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200935 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800936 Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300937 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200938 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300939 } else if ((pVBInfo->LCDResInfo == Panel_800x600) ||
940 (pVBInfo->LCDResInfo == Panel_320x480)) { /* LVDS */
941 VCLKIndex = VCLK40; /* LVDSXlat1VCLK */
942 } else {
943 VCLKIndex = VCLK65_315 + 2; /* LVDSXlat2VCLK, LVDSXlat3VCLK */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200944 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200945
946 return VCLKIndex;
947}
948
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800949static void XGI_SetCRT1VCLK(unsigned short ModeNo,
950 unsigned short ModeIdIndex,
951 struct xgi_hw_device_info *HwDeviceExtension,
952 unsigned short RefreshRateTableIndex,
953 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200954{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400955 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530956 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530958 if (pVBInfo->IF_DEF_LVDS == 1) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200959 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200960 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200961 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200962 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
963 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200964 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +0100965 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
966 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +0100967 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530968 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
969 RefreshRateTableIndex, HwDeviceExtension,
970 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200971 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200972 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200973 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200974 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200975 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200976 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
977 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530978 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200979 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200980 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200981 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200982 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
983 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200984 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530985 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200986
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530987 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200988 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800989 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200990 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200991 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200992 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530993 index = data;
994 index &= 0xE0;
995 data &= 0x1F;
996 data = data << 1;
997 data += 1;
998 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200999 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301000 }
1001 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001002}
1003
Aaro Koskinene85f2032011-11-27 23:03:07 +02001004static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1005{
1006 unsigned char temp;
1007
1008 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1009 temp = (temp & 1) << 6;
1010 /* SR06[6] 18bit Dither */
1011 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1012 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1013 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1014
1015}
1016
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001017static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301018 struct xgi_hw_device_info *HwDeviceExtension,
1019 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001020{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301021 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001022
Aaro Koskinen58839b02011-03-13 12:26:23 +02001023 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301024 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001025 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001026
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001027 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1028 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1029 data &= 0xC0;
1030 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1031 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1032 data |= 0x01;
1033 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301035 if (HwDeviceExtension->jChipType == XG21)
1036 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001037}
1038
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001039static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1040 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1041 struct vb_device_info *pVBInfo)
1042{
1043 unsigned short data, data2 = 0;
1044 short VCLK;
1045
1046 unsigned char index;
1047
Aaro Koskinena39325d2012-11-04 21:14:53 +02001048 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001049 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +02001050 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001051
Aaro Koskinen58839b02011-03-13 12:26:23 +02001052 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001053 data &= 0xf3;
1054 if (VCLK >= 200)
1055 data |= 0x0c; /* VCLK > 200 */
1056
1057 if (HwDeviceExtension->jChipType >= XG20)
1058 data &= ~0x04; /* 2 pixel mode */
1059
Aaro Koskinen8104e322011-03-13 12:26:22 +02001060 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001061
1062 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001063 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001064 data &= 0xE7;
1065 if (VCLK < 200)
1066 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001067 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001068 }
1069
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001070 data2 = 0x00;
1071
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001072 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001073 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001074 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001075
1076}
1077
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001078static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301079 unsigned short ModeNo, unsigned short ModeIdIndex,
1080 unsigned short RefreshRateTableIndex,
1081 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001082{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301083 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1084 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001085
Aaro Koskinenb3979922012-11-04 21:14:52 +02001086 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001087 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001088
Aaro Koskinen58839b02011-03-13 12:26:23 +02001089 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001090 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001091
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001092 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301093 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001094 data2 |= 0x02;
1095 data3 = pVBInfo->ModeType - ModeVGA;
1096 data3 = data3 << 2;
1097 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301098 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301100 if (data)
1101 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001102
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001103 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001104 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001105 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301107 data = 0x0000;
1108 if (infoflag & InterlaceMode) {
1109 if (xres == 1024)
1110 data = 0x0035;
1111 else if (xres == 1280)
1112 data = 0x0048;
1113 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301115 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001116 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301117 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001118 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301120 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001121 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301123 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301125 if (modeflag & LineCompareOff)
1126 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001127
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001128 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301129 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001130 data = data ^ 0x60;
1131 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001132 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001133
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301134 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1135 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001136
Aaro Koskinen58839b02011-03-13 12:26:23 +02001137 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001138
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301139 if (HwDeviceExtension->jChipType == XG27) {
1140 if (data & 0x40)
1141 data = 0x2c;
1142 else
1143 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001144 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001145 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301146 } else if (HwDeviceExtension->jChipType >= XG20) {
1147 if (data & 0x40)
1148 data = 0x33;
1149 else
1150 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001151 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1152 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301153 } else {
1154 if (data & 0x40)
1155 data = 0x2c;
1156 else
1157 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001158 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301159 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001160
1161}
1162
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001163static void XGI_WriteDAC(unsigned short dl,
1164 unsigned short ah,
1165 unsigned short al,
1166 unsigned short dh,
1167 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001168{
1169 unsigned short temp, bh, bl;
1170
1171 bh = ah;
1172 bl = al;
1173
1174 if (dl != 0) {
1175 temp = bh;
1176 bh = dh;
1177 dh = temp;
1178 if (dl == 1) {
1179 temp = bl;
1180 bl = dh;
1181 dh = temp;
1182 } else {
1183 temp = bl;
1184 bl = bh;
1185 bh = temp;
1186 }
1187 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001188 outb((unsigned short) dh, pVBInfo->P3c9);
1189 outb((unsigned short) bh, pVBInfo->P3c9);
1190 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001191}
1192
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001193static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301194 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001195{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001196 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1197 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001198
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001199 outb(0xFF, pVBInfo->P3c6);
1200 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001201
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001202 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301203 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301205 for (k = 0; k < 3; k++) {
1206 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001207
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301208 if (data & 0x01)
1209 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301211 if (data & 0x02)
1212 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001213
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001214 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301215 data = data >> 2;
1216 }
1217 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001218
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001219 for (i = 16; i < 32; i++) {
1220 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001221
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001222 for (k = 0; k < 3; k++)
1223 outb(data, pVBInfo->P3c9);
1224 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001225
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001226 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001227
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001228 for (m = 0; m < 9; m++) {
1229 di = si;
1230 bx = si + 0x04;
1231 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001232
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001233 for (n = 0; n < 3; n++) {
1234 for (o = 0; o < 5; o++) {
1235 dh = table[si];
1236 ah = table[di];
1237 al = table[bx];
1238 si++;
1239 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301240 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001241
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001242 si -= 2;
1243
1244 for (o = 0; o < 3; o++) {
1245 dh = table[bx];
1246 ah = table[di];
1247 al = table[si];
1248 si--;
1249 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1250 }
1251
1252 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301253 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001254
1255 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301256 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001257}
1258
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001259static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1260 unsigned short ModeIdIndex,
1261 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001262{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301263 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001264
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001265 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001266 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001267
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001268 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001269 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001270
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001271 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1272 yres = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001273
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001274 if (modeflag & HalfDCLK)
1275 xres = xres << 1;
1276
1277 if (modeflag & DoubleScanMode)
1278 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301280 if (xres == 720)
1281 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001282
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301283 pVBInfo->VGAHDE = xres;
1284 pVBInfo->HDE = xres;
1285 pVBInfo->VGAVDE = yres;
1286 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001287}
1288
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001289static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001290 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001291 unsigned short ModeIdIndex,
1292 unsigned short RefreshRateTableIndex,
1293 struct vb_device_info *pVBInfo)
1294{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001295 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001296
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001297 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001298
Aaro Koskinenb3979922012-11-04 21:14:52 +02001299 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001300
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001301 i = 0;
1302
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001303 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001304 tempdx = pVBInfo->LCDResInfo;
1305 if (tempbx & 0x0080) { /* OEMUtil */
1306 tempbx &= (~0x0080);
1307 tempdx = pVBInfo->LCDTypeInfo;
1308 }
1309
1310 if (pVBInfo->LCDInfo & EnableScalingLCD)
1311 tempdx &= (~PanelResInfo);
1312
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001313 if (table[i].PANELID == tempdx) {
1314 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001315 tempdx = pVBInfo->LCDInfo;
1316
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001317 if (modeflag & HalfDCLK)
1318 tempdx |= SetLCDLowResolution;
1319
1320 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001321 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001322 break;
1323 }
1324 i++;
1325 }
1326
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001327 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001328}
1329
Aaro Koskinen24572542012-09-11 00:15:21 +03001330static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001331 unsigned short ModeIdIndex,
1332 unsigned short RefreshRateTableIndex,
1333 struct vb_device_info *pVBInfo)
1334{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001335 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001336
Aaro Koskinenb3979922012-11-04 21:14:52 +02001337 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001338 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001339 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001340 tempdx = pVBInfo->TVInfo;
1341
1342 if (pVBInfo->VBInfo & SetInSlaveMode)
1343 tempdx = tempdx | SetTVLockMode;
1344
1345 if (modeflag & HalfDCLK)
1346 tempdx = tempdx | SetTVLowResolution;
1347
1348 i = 0;
1349
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001350 while (XGI_TVDataTable[i].MASK != 0xffff) {
1351 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1352 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001353 break;
1354 i++;
1355 }
1356
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001357 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001358}
1359
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001360static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301361 unsigned short RefreshRateTableIndex,
1362 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001363{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001364 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001365
Aaro Koskinen6008f872012-11-04 21:14:49 +02001366 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1367 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001368
Aaro Koskinen6008f872012-11-04 21:14:49 +02001369 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1370 RefreshRateTableIndex, pVBInfo);
1371 pVBInfo->VGAHT = LCDPtr->VGAHT;
1372 pVBInfo->VGAVT = LCDPtr->VGAVT;
1373 pVBInfo->HT = LCDPtr->LCDHT;
1374 pVBInfo->VT = LCDPtr->LCDVT;
1375
1376 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1377 return;
1378
1379 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1380 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1381 pVBInfo->HDE = 1024;
1382 pVBInfo->VDE = 768;
1383 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1384 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1385 pVBInfo->HDE = 1280;
1386 pVBInfo->VDE = 1024;
1387 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1388 pVBInfo->HDE = 1400;
1389 pVBInfo->VDE = 1050;
1390 } else {
1391 pVBInfo->HDE = 1600;
1392 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301393 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001394}
1395
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001396static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301397 unsigned short RefreshRateTableIndex,
1398 struct xgi_hw_device_info *HwDeviceExtension,
1399 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001400{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301401 unsigned char index;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001402 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001403 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1404 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001405
Aaro Koskinena39325d2012-11-04 21:14:53 +02001406 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301407 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001408
Peter Huewea3d675c2012-02-09 21:11:47 +01001409 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001410 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001411 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001412
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001413 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001414 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301415 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001416
1417 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1418
Peter Huewea3d675c2012-02-09 21:11:47 +01001419 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001420 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1421 ModeIdIndex, RefreshRateTableIndex,
1422 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001423 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001424 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001425 }
1426
1427 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001428}
1429
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001430static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1431{
1432 unsigned char tempal, tempah, tempbl, i;
1433
Aaro Koskinen58839b02011-03-13 12:26:23 +02001434 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001435 tempal = tempah & 0x0F;
1436 tempah = tempah & 0xF0;
1437 i = 0;
1438 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1439
1440 while (tempbl != 0xFF) {
1441 if (tempbl & 0x80) { /* OEMUtil */
1442 tempal = tempah;
1443 tempbl = tempbl & ~(0x80);
1444 }
1445
1446 if (tempal == tempbl)
1447 break;
1448
1449 i++;
1450
1451 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1452 }
1453
1454 return i;
1455}
1456
1457static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1458{
1459 unsigned short tempah, tempal, tempbl, i;
1460
1461 tempal = pVBInfo->LCDResInfo;
1462 tempah = pVBInfo->LCDTypeInfo;
1463
1464 i = 0;
1465 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1466
1467 while (tempbl != 0xFF) {
1468 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1469 tempal = tempah;
1470 tempbl &= ~0x80;
1471 }
1472
1473 if (tempal == tempbl)
1474 break;
1475
1476 i++;
1477 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1478 }
1479
1480 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001481 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001482 pVBInfo->LCDTypeInfo = 0;
1483 i = 0;
1484 }
1485
1486 return i;
1487}
1488
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001489static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1490 unsigned short *VSyncWidth,
1491 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001492{
1493 unsigned short Index;
1494
1495 Index = XGI_GetLCDCapPtr(pVBInfo);
1496 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1497 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1498
1499 return;
1500}
1501
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001502static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301503 unsigned short RefreshRateTableIndex,
1504 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001505{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301506 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1507 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001508 struct XGI_LCDDesStruct const *LCDPtr = NULL;
1509 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001510
Aaro Koskinenb3979922012-11-04 21:14:52 +02001511 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen66cface2011-08-31 21:46:13 +03001512 if (pVBInfo->LCDInfo & EnableScalingLCD)
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001513 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1514 ModeIdIndex, RefreshRateTableIndex,
1515 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03001516 else
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001517 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1518 ModeIdIndex, RefreshRateTableIndex,
1519 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001520
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001521 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1522 push1 = tempbx;
1523 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001524
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001525 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001526 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1527 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001528 tempax = 1024;
1529 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001530 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1531 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001532 tempax = 1280;
1533 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001534 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001535 tempax = 1400;
1536 tempbx = 1050;
1537 } else {
1538 tempax = 1600;
1539 tempbx = 1200;
1540 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001541
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001542 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1543 pVBInfo->HDE = tempax;
1544 pVBInfo->VDE = tempbx;
1545 pVBInfo->VGAHDE = tempax;
1546 pVBInfo->VGAVDE = tempbx;
1547 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001548
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001549 tempax = pVBInfo->HT;
1550
1551 if (pVBInfo->LCDInfo & EnableScalingLCD)
1552 tempbx = LCDPtr1->LCDHDES;
1553 else
1554 tempbx = LCDPtr->LCDHDES;
1555
1556 tempcx = pVBInfo->HDE;
1557 tempbx = tempbx & 0x0fff;
1558 tempcx += tempbx;
1559
1560 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001561 tempcx -= tempax;
1562
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001563 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001564
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001565 tempcx = tempcx >> 3;
1566 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001567
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001568 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1569 (unsigned short) (tempbx & 0xff));
1570 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1571 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001572
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001573 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001574
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001575 if (pVBInfo->LCDInfo & EnableScalingLCD)
1576 tempbx = LCDPtr1->LCDHRS;
1577 else
1578 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001579
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001580 tempcx = push2;
1581
1582 if (pVBInfo->LCDInfo & EnableScalingLCD)
1583 tempcx = LCDPtr1->LCDHSync;
1584
1585 tempcx += tempbx;
1586
1587 if (tempcx >= tempax)
1588 tempcx -= tempax;
1589
1590 tempax = tempbx & 0x07;
1591 tempax = tempax >> 5;
1592 tempcx = tempcx >> 3;
1593 tempbx = tempbx >> 3;
1594
1595 tempcx &= 0x1f;
1596 tempax |= tempcx;
1597
1598 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1599 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1600 (unsigned short) (tempbx & 0xff));
1601
1602 tempax = pVBInfo->VT;
1603 if (pVBInfo->LCDInfo & EnableScalingLCD)
1604 tempbx = LCDPtr1->LCDVDES;
1605 else
1606 tempbx = LCDPtr->LCDVDES;
1607 tempcx = pVBInfo->VDE;
1608
1609 tempbx = tempbx & 0x0fff;
1610 tempcx += tempbx;
1611 if (tempcx >= tempax)
1612 tempcx -= tempax;
1613
1614 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1615 (unsigned short) (tempbx & 0xff));
1616 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1617 (unsigned short) (tempcx & 0xff));
1618
1619 tempbx = (tempbx >> 8) & 0x07;
1620 tempcx = (tempcx >> 8) & 0x07;
1621
1622 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1623 (unsigned short) ((tempcx << 3)
1624 | tempbx));
1625
1626 tempax = pVBInfo->VT;
1627 if (pVBInfo->LCDInfo & EnableScalingLCD)
1628 tempbx = LCDPtr1->LCDVRS;
1629 else
1630 tempbx = LCDPtr->LCDVRS;
1631
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001632 tempcx = push1;
1633
1634 if (pVBInfo->LCDInfo & EnableScalingLCD)
1635 tempcx = LCDPtr1->LCDVSync;
1636
1637 tempcx += tempbx;
1638 if (tempcx >= tempax)
1639 tempcx -= tempax;
1640
1641 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1642 (unsigned short) (tempbx & 0xff));
1643 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1644 (unsigned short) (tempcx & 0x0f));
1645
1646 tempax = ((tempbx >> 8) & 0x07) << 3;
1647
1648 tempbx = pVBInfo->VGAVDE;
1649 if (tempbx != pVBInfo->VDE)
1650 tempax |= 0x40;
1651
Peter Huewea3d675c2012-02-09 21:11:47 +01001652 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001653 tempax |= 0x40;
1654
1655 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1656 tempax);
1657
1658 tempcx = pVBInfo->VGAVT;
1659 tempbx = pVBInfo->VDE;
1660 tempax = pVBInfo->VGAVDE;
1661 tempcx -= tempax;
1662
1663 temp = tempax; /* 0430 ylshieh */
1664 temp1 = (temp << 18) / tempbx;
1665
1666 tempdx = (unsigned short) ((temp << 18) % tempbx);
1667
1668 if (tempdx != 0)
1669 temp1 += 1;
1670
1671 temp2 = temp1;
1672 push3 = temp2;
1673
1674 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1675 (unsigned short) (temp2 & 0xff));
1676 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1677 (unsigned short) ((temp2 >> 8) & 0xff));
1678
1679 tempbx = (unsigned short) (temp2 >> 16);
1680 tempax = tempbx & 0x03;
1681
1682 tempbx = pVBInfo->VGAVDE;
1683 if (tempbx == pVBInfo->VDE)
1684 tempax |= 0x04;
1685
1686 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1687
1688 if (pVBInfo->VBType & VB_XGI301C) {
1689 temp2 = push3;
1690 xgifb_reg_set(pVBInfo->Part4Port,
1691 0x3c,
1692 (unsigned short) (temp2 & 0xff));
1693 xgifb_reg_set(pVBInfo->Part4Port,
1694 0x3b,
1695 (unsigned short) ((temp2 >> 8) &
1696 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001697 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001698 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1699 ~0xc0,
1700 (unsigned short) ((tempbx &
1701 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001702
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001703 tempcx = pVBInfo->VGAVDE;
1704 if (tempcx == pVBInfo->VDE)
1705 xgifb_reg_and_or(pVBInfo->Part4Port,
1706 0x30, ~0x0c, 0x00);
1707 else
1708 xgifb_reg_and_or(pVBInfo->Part4Port,
1709 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301710 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001711
1712 tempcx = pVBInfo->VGAHDE;
1713 tempbx = pVBInfo->HDE;
1714
1715 temp1 = tempcx << 16;
1716
1717 tempax = (unsigned short) (temp1 / tempbx);
1718
1719 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1720 tempax = 65535;
1721
1722 temp3 = tempax;
1723 temp1 = pVBInfo->VGAHDE << 16;
1724
1725 temp1 /= temp3;
1726 temp3 = temp3 << 16;
1727 temp1 -= 1;
1728
1729 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1730
1731 tempax = (unsigned short) (temp3 & 0xff);
1732 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1733
1734 temp1 = pVBInfo->VGAVDE << 18;
1735 temp1 = temp1 / push3;
1736 tempbx = (unsigned short) (temp1 & 0xffff);
1737
Peter Huewe255aabd2012-02-09 21:11:44 +01001738 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001739 tempbx -= 1;
1740
1741 tempax = ((tempbx >> 8) & 0xff) << 3;
1742 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1743 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1744 (unsigned short) (tempax & 0xff));
1745 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1746 (unsigned short) (tempbx & 0xff));
1747
1748 temp3 = temp3 >> 16;
1749
1750 if (modeflag & HalfDCLK)
1751 temp3 = temp3 >> 1;
1752
1753 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1754 (unsigned short) ((temp3 >> 8) & 0xff));
1755 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1756 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001757}
1758
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001759/* --------------------------------------------------------------------- */
1760/* Function : XGI_GETLCDVCLKPtr */
1761/* Input : */
1762/* Output : al -> VCLK Index */
1763/* Description : */
1764/* --------------------------------------------------------------------- */
1765static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1766 struct vb_device_info *pVBInfo)
1767{
1768 unsigned short index;
1769
Peter Huewea3d675c2012-02-09 21:11:47 +01001770 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001771 index = XGI_GetLCDCapPtr1(pVBInfo);
1772
1773 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1774 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1775 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1776 } else { /* LCDA */
1777 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1778 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1779 }
1780 }
1781 return;
1782}
1783
1784static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1785 unsigned short ModeNo, unsigned short ModeIdIndex,
1786 struct vb_device_info *pVBInfo)
1787{
1788
1789 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001790 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001791
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001792 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001793 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001794
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001795 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1796 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001797 index = XGI_GetLCDCapPtr(pVBInfo);
1798 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1799
Peter Huewea3d675c2012-02-09 21:11:47 +01001800 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001801 return tempal;
1802
1803 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001804 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001805 (VB_SIS301B |
1806 VB_SIS302B |
1807 VB_SIS301LV |
1808 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001809 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001810 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001811 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001812 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001813 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001814 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001815 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001816 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001817 tempal = TVCLKBASE_315 +
1818 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001819
1820 }
1821 return tempal;
1822 }
1823
Peter Huewe599801f2012-02-09 21:11:45 +01001824 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001825 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001826 return tempal;
1827 }
1828
Peter Huewe599801f2012-02-09 21:11:45 +01001829 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001830 tempal = YPbPr525pVCLK;
1831 return tempal;
1832 }
1833
1834 tempal = NTSC1024VCLK;
1835
1836 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001837 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001838 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001839 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001840 }
1841
1842 if (pVBInfo->VBInfo & SetCRT2ToTV)
1843 return tempal;
1844 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001845 } /* {End of VB} */
1846
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001847 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001848 tempal = tempal >> 2;
1849 tempal &= 0x03;
1850
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001851 /* for Dot8 Scaling LCD */
1852 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001853 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
1854
Aaro Koskinena39325d2012-11-04 21:14:53 +02001855 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001856 return tempal;
1857}
1858
1859static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1860 unsigned char *di_1, struct vb_device_info *pVBInfo)
1861{
Peter Huewe6896b942012-02-09 21:11:46 +01001862 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1863 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001864 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1865 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001866 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001867 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001868 }
1869 } else {
1870 *di_0 = XGI_VCLKData[tempal].SR2B;
1871 *di_1 = XGI_VCLKData[tempal].SR2C;
1872 }
1873}
1874
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001875static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301876 unsigned short RefreshRateTableIndex,
1877 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001878{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301879 unsigned char di_0, di_1, tempal;
1880 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301882 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1883 pVBInfo);
1884 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1885 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301887 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001888 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301889 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001890 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301891 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001892 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1893 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301894 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001895 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1896 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301897 }
1898 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001899}
1900
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001901static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301902 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001903{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301904 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001905
Peter Huewe6896b942012-02-09 21:11:46 +01001906 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1907 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301908 tempcl = 0;
1909 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001910 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001911
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301912 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001913 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301914 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001915 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301916 if (!(temp & 0x40))
1917 tempcl |= ActiveCRT1;
1918 }
1919 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001920
Aaro Koskinen58839b02011-03-13 12:26:23 +02001921 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301922 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001923
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301924 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001925 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001926 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301927 if (tempax & 0x04)
1928 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001929
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301930 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001931
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301932 if (!(tempcl & ActiveLCD))
1933 if (temp == 0x01)
1934 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001935
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301936 if (temp == 0x04)
1937 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301939 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001940 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001941
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301942 if (!(temp & 0x08))
1943 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001944
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301945 if (!(temp & 0x04))
1946 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001947
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301948 if (temp & 0x02)
1949 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001950
Peter Huewe599801f2012-02-09 21:11:45 +01001951 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301952 if (temp & 0x01)
1953 tempch |= ActiveHiTV;
1954 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001955
Peter Huewe599801f2012-02-09 21:11:45 +01001956 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001957 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301958 pVBInfo->Part2Port,
1959 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001960
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301961 if (temp & 0x10)
1962 tempch |= ActiveYPbPr;
1963 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001964
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301965 if (tempch != 0)
1966 tempcl |= ActiveTV;
1967 }
1968 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001969
Aaro Koskinen58839b02011-03-13 12:26:23 +02001970 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301971 if (tempcl & ActiveLCD) {
1972 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1973 if (temp & ActiveTV)
1974 tempcl |= ActiveTV;
1975 }
1976 }
1977 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001978 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001979 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001980
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301981 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001982 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301983 } else {
1984 return;
1985 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001986}
1987
Bill Pemberton80adad82010-06-17 13:10:51 -04001988void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001989{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301990 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001991
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001992 if (pVBInfo->IF_DEF_LVDS != 0)
1993 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001994
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001995 tempbx = VB_SIS302B;
1996 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1997 if (flag == 0x02)
1998 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001999
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002000 tempbx = VB_SIS301;
2001 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
2002 if (flag < 0xB0)
2003 goto finish;
2004
2005 tempbx = VB_SIS301B;
2006 if (flag < 0xC0)
2007 goto bigger_than_0xB0;
2008
2009 tempbx = VB_XGI301C;
2010 if (flag < 0xD0)
2011 goto bigger_than_0xB0;
2012
2013 tempbx = VB_SIS301LV;
2014 if (flag < 0xE0)
2015 goto bigger_than_0xB0;
2016
2017 tempbx = VB_SIS302LV;
2018 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
2019 if (tempah != 0xFF)
2020 tempbx = VB_XGI301C;
2021
2022bigger_than_0xB0:
2023 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
2024 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
2025 if (!(flag & 0x02))
2026 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302027 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002028
2029finish:
2030 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002031}
2032
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002033static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302034 struct xgi_hw_device_info *HwDeviceExtension,
2035 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002036{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302037 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002038
Aaro Koskinenb3979922012-11-04 21:14:52 +02002039 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302040 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01002041 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302042 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002043
Miguel Gómezf9317352012-07-06 12:40:48 +02002044 if (!(pVBInfo->VBType & 0xFFFF))
2045 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002046
Miguel Gómezf9317352012-07-06 12:40:48 +02002047 /* Check Display Device */
2048 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
2049 tempbx = tempbx | temp;
2050 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
2051 push = temp;
2052 push = push << 8;
2053 tempax = temp << 8;
2054 tempbx = tempbx | tempax;
2055 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
2056 | SetInSlaveMode | DisableCRT2Display);
2057 temp = 0xFFFF ^ temp;
2058 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002059
Miguel Gómezf9317352012-07-06 12:40:48 +02002060 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002061
Aaro Koskinen4d8f5ca2012-09-11 00:15:17 +03002062 if (pVBInfo->IF_DEF_LVDS == 0) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002063 if (pVBInfo->VBType &
2064 (VB_SIS302B |
2065 VB_SIS301LV |
2066 VB_SIS302LV |
2067 VB_XGI301C)) {
2068 if (temp & EnableDualEdge) {
2069 tempbx |= SetCRT2ToDualEdge;
2070 if (temp & SetToLCDA)
2071 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02002072 }
2073 }
2074 }
2075
2076 if (pVBInfo->IF_DEF_YPbPr == 1) {
2077 if (((pVBInfo->IF_DEF_LVDS == 0) &&
2078 ((pVBInfo->VBType & VB_SIS301LV) ||
2079 (pVBInfo->VBType & VB_SIS302LV) ||
2080 (pVBInfo->VBType & VB_XGI301C)))) {
2081 if (temp & SetYPbPr) {
2082 if (pVBInfo->IF_DEF_HiVision == 1) {
2083 /* shampoo add for new
2084 * scratch */
2085 temp = xgifb_reg_get(
2086 pVBInfo->P3d4,
2087 0x35);
2088 temp &= YPbPrMode;
2089 tempbx |= SetCRT2ToHiVision;
2090
2091 if (temp != YPbPrMode1080i) {
2092 tempbx &=
2093 (~SetCRT2ToHiVision);
2094 tempbx |=
2095 SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302096 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302097 }
2098 }
2099 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002100 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002101
Miguel Gómezf9317352012-07-06 12:40:48 +02002102 tempax = push; /* restore CR31 */
2103
2104 if (pVBInfo->IF_DEF_LVDS == 0) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302105 if (pVBInfo->IF_DEF_YPbPr == 1) {
Miguel Gómezf9317352012-07-06 12:40:48 +02002106 if (pVBInfo->IF_DEF_HiVision == 1)
2107 temp = 0x09FC;
2108 else
2109 temp = 0x097C;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002110 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2111 temp = 0x01FC;
Miguel Gómezf9317352012-07-06 12:40:48 +02002112 } else {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002113 temp = 0x017C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302114 }
Justin P. Mattock558f7582012-10-02 21:17:11 -07002115 } else { /* 3rd party chip */
Miguel Gómezf9317352012-07-06 12:40:48 +02002116 temp = SetCRT2ToLCD;
2117 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002118
Miguel Gómezf9317352012-07-06 12:40:48 +02002119 if (!(tempbx & temp)) {
2120 tempax |= DisableCRT2Display;
2121 tempbx = 0;
2122 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002123
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002124 if (!(pVBInfo->VBType & VB_NoLCD)) {
2125 if (tempbx & XGI_SetCRT2ToLCDA) {
2126 if (tempbx & SetSimuScanMode)
2127 tempbx &= (~(SetCRT2ToLCD |
2128 SetCRT2ToRAMDAC |
2129 SwitchCRT2));
2130 else
2131 tempbx &= (~(SetCRT2ToLCD |
2132 SetCRT2ToRAMDAC |
2133 SetCRT2ToTV |
2134 SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002135 }
2136 }
2137
2138 /* shampoo add */
2139 /* for driver abnormal */
2140 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2141 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2142 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002143 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002144 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002145 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002146 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002147 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302148 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002149 } else {
2150 tempbx &= (~(SetCRT2ToRAMDAC |
2151 SetCRT2ToLCD |
2152 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302153 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002154 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002155
Miguel Gómezf9317352012-07-06 12:40:48 +02002156 if (!(pVBInfo->VBType & VB_NoLCD)) {
2157 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002158 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002159 SetCRT2ToLCD |
Peter Huewe6896b942012-02-09 21:11:46 +01002160 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002161 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002162 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302163 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002164 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002165
Miguel Gómezf9317352012-07-06 12:40:48 +02002166 if (tempbx & SetCRT2ToSCART) {
2167 tempbx &= (0xFF00 |
2168 SetCRT2ToSCART |
2169 SwitchCRT2 |
2170 SetSimuScanMode);
2171 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2172 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002173
Miguel Gómezf9317352012-07-06 12:40:48 +02002174 if (pVBInfo->IF_DEF_YPbPr == 1) {
2175 if (tempbx & SetCRT2ToYPbPr525750)
2176 tempbx &= (0xFF00 |
2177 SwitchCRT2 |
2178 SetSimuScanMode);
2179 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002180
Miguel Gómezf9317352012-07-06 12:40:48 +02002181 if (pVBInfo->IF_DEF_HiVision == 1) {
2182 if (tempbx & SetCRT2ToHiVision)
2183 tempbx &= (0xFF00 |
2184 SetCRT2ToHiVision |
2185 SwitchCRT2 |
2186 SetSimuScanMode);
2187 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002188
Miguel Gómezf9317352012-07-06 12:40:48 +02002189 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2190 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2191 tempbx = DisableCRT2Display;
2192 }
2193
2194 if (!(tempbx & DisableCRT2Display)) {
2195 if ((!(tempbx & DriverMode)) ||
2196 (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002197 if (!(tempbx & XGI_SetCRT2ToLCDA))
2198 tempbx |= (SetInSlaveMode |
2199 SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002200 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002201
Miguel Gómezf9317352012-07-06 12:40:48 +02002202 /* LCD+TV can't support in slave mode
2203 * (Force LCDA+TV->LCDB) */
2204 if ((tempbx & SetInSlaveMode) &&
2205 (tempbx & XGI_SetCRT2ToLCDA)) {
2206 tempbx ^= (SetCRT2ToLCD |
2207 XGI_SetCRT2ToLCDA |
2208 SetCRT2ToDualEdge);
2209 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302210 }
2211 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302213 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002214}
2215
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002216static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302217 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002218{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302219 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002220
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302221 tempbx = 0;
2222 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302224 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002225 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2226 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302228 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002229 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302230 tempbx = temp;
Peter Huewe599801f2012-02-09 21:11:45 +01002231 if (tempbx & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002232 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002233 TVSetPALM |
2234 TVSetPALN |
2235 TVSetPAL);
2236 if (tempbx & TVSetPALM)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002237 /* set to NTSC if PAL-M */
Peter Huewe599801f2012-02-09 21:11:45 +01002238 tempbx &= ~TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302239 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002240 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002241 TVSetNTSCJ |
2242 TVSetPAL);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302243 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002244
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302245 if (pVBInfo->IF_DEF_LVDS == 0) {
2246 if (pVBInfo->VBInfo & SetCRT2ToSCART)
Peter Huewe599801f2012-02-09 21:11:45 +01002247 tempbx |= TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302248 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002249
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302250 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002251 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002252 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302253 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002254
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302255 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002256 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002257
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302258 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002259 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302260 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002261 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302262 }
2263 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002264
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302265 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002266 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2267 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302268 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002269
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302270 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002271 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2272 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302273 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002274
Peter Huewe599801f2012-02-09 21:11:45 +01002275 if (!(tempbx & TVSetPAL) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002276 (modeflag > 13) &&
2277 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302278 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302280 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002281
Peter Huewe599801f2012-02-09 21:11:45 +01002282 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302283 if (pVBInfo->VBInfo & SetInSlaveMode)
2284 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002285 } else if (tempbx &
2286 (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302287 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002288 } else if (!(pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002289 (VB_SIS301B |
2290 VB_SIS302B |
2291 VB_SIS301LV |
2292 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002293 VB_XGI301C))) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002294 if (tempbx & TVSimuMode)
2295 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302296 }
2297 }
2298 }
2299 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002300}
2301
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002302static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2303 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002304{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302305 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002306
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302307 pVBInfo->LCDResInfo = 0;
2308 pVBInfo->LCDTypeInfo = 0;
2309 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002310
Aaro Koskinenb3979922012-11-04 21:14:52 +02002311 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002312 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002313 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002314 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302315 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002316
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302317 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002318 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002319
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002320 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002321 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302322 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002323 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002324 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302325 tempax &= 0x0F;
2326 else
2327 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002328
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302329 if ((resinfo == 6) || (resinfo == 9)) {
2330 if (tempax >= 3)
2331 tempbx |= PanelRef75Hz;
2332 } else if ((resinfo == 7) || (resinfo == 8)) {
2333 if (tempax >= 4)
2334 tempbx |= PanelRef75Hz;
2335 }
2336 }
2337 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002338
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302339 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302341 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002342
Peter Huewea3d675c2012-02-09 21:11:47 +01002343 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302344 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302346 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002347
Aaro Koskinen58839b02011-03-13 12:26:23 +02002348 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002349
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302350 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002351
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302352 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302354 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002355
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302356 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002357
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302358 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Peter Huewe6896b942012-02-09 21:11:46 +01002359 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType
Peter Huewea3d675c2012-02-09 21:11:47 +01002360 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302361 tempbx |= SetLCDDualLink;
2362 }
2363 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002364
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302365 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002366 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002367 & SetCRT2ToLCD) && (resinfo == 9) &&
2368 (!(tempbx & EnableScalingLCD)))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02002369 /*
2370 * set to center in 1280x1024 LCDB
2371 * for Panel_1400x1050
2372 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002373 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302374 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002375
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302376 if (pVBInfo->VBInfo & SetInSlaveMode) {
2377 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002378 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302379 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002380 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302381 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302383 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002384
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302385 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002386}
2387
Bill Pemberton108afbf2010-06-17 13:10:47 -04002388unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302389 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002390{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002391 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002392 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002393 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002394 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002395 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302396 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002397
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302398 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002399}
2400
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002401static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2402{
2403 unsigned char ujRet = 0;
2404 unsigned char i = 0;
2405
2406 for (i = 0; i < 8; i++) {
2407 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002408 ujRet |= (ujDate >> i) & 1;
2409 }
2410
2411 return ujRet;
2412}
2413
2414/*----------------------------------------------------------------------------*/
2415/* output */
2416/* bl[5] : LVDS signal */
2417/* bl[1] : LVDS backlight */
2418/* bl[0] : LVDS VDD */
2419/*----------------------------------------------------------------------------*/
2420static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2421{
2422 unsigned char CR4A, temp;
2423
Aaro Koskinen58839b02011-03-13 12:26:23 +02002424 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002425 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002426
Aaro Koskinen58839b02011-03-13 12:26:23 +02002427 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002428
2429 temp = XG21GPIODataTransfer(temp);
2430 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002431 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002432 return temp;
2433}
2434
2435/*----------------------------------------------------------------------------*/
2436/* output */
2437/* bl[5] : LVDS signal */
2438/* bl[1] : LVDS backlight */
2439/* bl[0] : LVDS VDD */
2440/*----------------------------------------------------------------------------*/
2441static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2442{
2443 unsigned char CR4A, CRB4, temp;
2444
Aaro Koskinen58839b02011-03-13 12:26:23 +02002445 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002446 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002447
Aaro Koskinen58839b02011-03-13 12:26:23 +02002448 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002449
2450 temp &= 0x0C;
2451 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002452 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002453 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002454 temp |= ((CRB4 & 0x04) << 3);
2455 return temp;
2456}
2457
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002458/*----------------------------------------------------------------------------*/
2459/* input */
2460/* bl[5] : 1;LVDS signal on */
2461/* bl[1] : 1;LVDS backlight on */
2462/* bl[0] : 1:LVDS VDD on */
2463/* bh: 100000b : clear bit 5, to set bit5 */
2464/* 000010b : clear bit 1, to set bit1 */
2465/* 000001b : clear bit 0, to set bit0 */
2466/*----------------------------------------------------------------------------*/
2467static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2468 struct vb_device_info *pVBInfo)
2469{
2470 unsigned char CR4A, temp;
2471
2472 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2473 tempbh &= 0x23;
2474 tempbl &= 0x23;
2475 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2476
2477 if (tempbh & 0x20) {
2478 temp = (tempbl >> 4) & 0x02;
2479
2480 /* CR B4[1] */
2481 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2482
2483 }
2484
2485 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2486
2487 temp = XG21GPIODataTransfer(temp);
2488 temp &= ~tempbh;
2489 temp |= tempbl;
2490 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2491}
2492
Aaro Koskinen776115a2011-11-27 23:03:10 +02002493static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2494 struct vb_device_info *pVBInfo)
2495{
2496 unsigned char CR4A, temp;
2497 unsigned short tempbh0, tempbl0;
2498
2499 tempbh0 = tempbh;
2500 tempbl0 = tempbl;
2501 tempbh0 &= 0x20;
2502 tempbl0 &= 0x20;
2503 tempbh0 >>= 3;
2504 tempbl0 >>= 3;
2505
2506 if (tempbh & 0x20) {
2507 temp = (tempbl >> 4) & 0x02;
2508
2509 /* CR B4[1] */
2510 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2511
2512 }
2513 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2514
2515 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2516 tempbh &= 0x03;
2517 tempbl &= 0x03;
2518 tempbh <<= 2;
2519 tempbl <<= 2; /* GPIOC,GPIOD */
2520 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2521 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2522}
2523
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002524static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2525 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302526 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002527{
2528
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002529 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302530 if (pXGIHWDE->jChipType == XG21) {
2531 if (pVBInfo->IF_DEF_LVDS == 1) {
2532 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002533 /* LVDS VDD on */
2534 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002535 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302536 }
2537 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002538 /* LVDS signal on */
2539 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002540 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002541 /* LVDS backlight on */
2542 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302543 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002544 /* DVO/DVI signal on */
2545 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302546 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002547
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302548 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002549
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302550 if (pXGIHWDE->jChipType == XG27) {
2551 if (pVBInfo->IF_DEF_LVDS == 1) {
2552 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002553 /* LVDS VDD on */
2554 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002555 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302556 }
2557 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002558 /* LVDS signal on */
2559 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002560 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002561 /* LVDS backlight on */
2562 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302563 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002564 /* DVO/DVI signal on */
2565 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302566 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002567
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302568 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002569}
2570
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002571void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2572 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302573 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002574{
2575
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302576 if (pXGIHWDE->jChipType == XG21) {
2577 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002578 /* LVDS backlight off */
2579 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002580 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302581 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002582 /* DVO/DVI signal off */
2583 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302584 }
2585 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002586
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302587 if (pXGIHWDE->jChipType == XG27) {
2588 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002589 /* LVDS backlight off */
2590 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002591 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302592 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002593
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302594 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002595 /* DVO/DVI signal off */
2596 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302597 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002598
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002599 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002600}
2601
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002602static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002603{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002604 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302605 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002606
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002607 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302608 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002609}
2610
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002611static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002612{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002613 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002614}
2615
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002616static void XGI_SaveCRT2Info(unsigned short ModeNo,
2617 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002618{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302619 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002620
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002621 /* reserve CR34 for CRT1 Mode No */
2622 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302623 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2624 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002625 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002626}
2627
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002628static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2629 unsigned short ModeIdIndex,
2630 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002631{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302632 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002633
Aaro Koskinenb3979922012-11-04 21:14:52 +02002634 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002635 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
2636 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
2637 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002638 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002639
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002640 if (modeflag & HalfDCLK)
2641 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002642
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002643 if (modeflag & DoubleScanMode)
2644 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002645
Miguel Gómez3339db82012-07-06 12:40:49 +02002646 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2647 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002648
Miguel Gómez3339db82012-07-06 12:40:49 +02002649 if (pVBInfo->IF_DEF_LVDS == 0) {
2650 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2651 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2652 if (yres == 1024)
2653 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302654 }
2655 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002656
Miguel Gómez3339db82012-07-06 12:40:49 +02002657 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2658 if (yres == 400)
2659 yres = 405;
2660 else if (yres == 350)
2661 yres = 360;
2662
2663 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2664 if (yres == 360)
2665 yres = 375;
2666 }
2667 }
2668
2669 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2670 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2671 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2672 if (yres == 350)
2673 yres = 357;
2674 else if (yres == 400)
2675 yres = 420;
2676 else if (yres == 480)
2677 yres = 525;
2678 }
2679 }
2680 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302681 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002682
Miguel Gómez3339db82012-07-06 12:40:49 +02002683 if (xres == 720)
2684 xres = 640;
2685
2686exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302687 pVBInfo->VGAHDE = xres;
2688 pVBInfo->HDE = xres;
2689 pVBInfo->VGAVDE = yres;
2690 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002691}
2692
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002693static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002694{
2695
Peter Huewea3d675c2012-02-09 21:11:47 +01002696 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002697 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302698 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002699
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302700 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002701}
2702
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002703static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2704 unsigned short ModeIdIndex,
2705 unsigned short RefreshRateTableIndex,
2706 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002707{
2708 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002709 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002710
2711 pVBInfo->RVBHCMAX = 1;
2712 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002713 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002714 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002715 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002716 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2717 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002718 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002719 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002720 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002721 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002722 tempcx &= 0x0100;
2723 tempcx = tempcx << 2;
2724 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002725 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002726
2727 if (temp1 & 0x01)
2728 tempbx |= 0x0100;
2729
2730 if (temp1 & 0x20)
2731 tempbx |= 0x0200;
2732 tempax += 5;
2733
2734 if (modeflag & Charx8Dot)
2735 tempax *= 8;
2736 else
2737 tempax *= 9;
2738
2739 pVBInfo->VGAHT = tempax;
2740 pVBInfo->HT = tempax;
2741 tempbx++;
2742 pVBInfo->VGAVT = tempbx;
2743 pVBInfo->VT = tempbx;
2744}
2745
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002746static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302747 unsigned short RefreshRateTableIndex,
2748 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002749{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002750 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002751
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002752 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002753
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002754 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002755 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2756 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302757 pVBInfo->NewFlickerMode = 0;
2758 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002759
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302760 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2761 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2762 pVBInfo);
2763 return;
2764 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002765
Peter Huewea3d675c2012-02-09 21:11:47 +01002766 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002767 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002768 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002769
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302770 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2771 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2772 pVBInfo->VGAHT = LCDPtr->VGAHT;
2773 pVBInfo->VGAVT = LCDPtr->VGAVT;
2774 pVBInfo->HT = LCDPtr->LCDHT;
2775 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002776
Peter Huewe255aabd2012-02-09 21:11:44 +01002777 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302778 tempax = 1024;
2779 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002780
Peter Huewea3d675c2012-02-09 21:11:47 +01002781 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302782 if (pVBInfo->VGAVDE == 357)
2783 tempbx = 527;
2784 else if (pVBInfo->VGAVDE == 420)
2785 tempbx = 620;
2786 else if (pVBInfo->VGAVDE == 525)
2787 tempbx = 775;
2788 else if (pVBInfo->VGAVDE == 600)
2789 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302790 else
2791 tempbx = 768;
2792 } else
2793 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002794 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302795 tempax = 1024;
2796 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002797 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302798 tempax = 1280;
2799 if (pVBInfo->VGAVDE == 360)
2800 tempbx = 768;
2801 else if (pVBInfo->VGAVDE == 375)
2802 tempbx = 800;
2803 else if (pVBInfo->VGAVDE == 405)
2804 tempbx = 864;
2805 else
2806 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002807 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302808 tempax = 1280;
2809 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002810 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302811 tempax = 1280;
2812 if (pVBInfo->VGAVDE == 350)
2813 tempbx = 700;
2814 else if (pVBInfo->VGAVDE == 400)
2815 tempbx = 800;
2816 else if (pVBInfo->VGAVDE == 1024)
2817 tempbx = 960;
2818 else
2819 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002820 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302821 tempax = 1400;
2822 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002823
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302824 if (pVBInfo->VGAVDE == 1024) {
2825 tempax = 1280;
2826 tempbx = 1024;
2827 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002828 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302829 tempax = 1600;
2830 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002831 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302832 if (pVBInfo->VGAVDE == 350)
2833 tempbx = 875;
2834 else if (pVBInfo->VGAVDE == 400)
2835 tempbx = 1000;
2836 }
2837 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002838
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302839 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2840 tempax = pVBInfo->VGAHDE;
2841 tempbx = pVBInfo->VGAVDE;
2842 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002843
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302844 pVBInfo->HDE = tempax;
2845 pVBInfo->VDE = tempbx;
2846 return;
2847 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002848
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302849 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002850 struct SiS_TVData const *TVPtr;
2851
2852 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2853 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002854
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302855 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2856 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2857 pVBInfo->VGAHT = TVPtr->VGAHT;
2858 pVBInfo->VGAVT = TVPtr->VGAVT;
2859 pVBInfo->HDE = TVPtr->TVHDE;
2860 pVBInfo->VDE = TVPtr->TVVDE;
2861 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2862 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002863
Peter Huewe599801f2012-02-09 21:11:45 +01002864 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302865 if (resinfo == 0x08)
2866 pVBInfo->NewFlickerMode = 0x40;
2867 else if (resinfo == 0x09)
2868 pVBInfo->NewFlickerMode = 0x40;
2869 else if (resinfo == 0x12)
2870 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302872 if (pVBInfo->VGAVDE == 350)
2873 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302875 tempax = ExtHiTVHT;
2876 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002877
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302878 if (pVBInfo->VBInfo & SetInSlaveMode) {
2879 if (pVBInfo->TVInfo & TVSimuMode) {
2880 tempax = StHiTVHT;
2881 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002882
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302883 if (!(modeflag & Charx8Dot)) {
2884 tempax = StHiTextTVHT;
2885 tempbx = StHiTextTVVT;
2886 }
2887 }
2888 }
Peter Huewe599801f2012-02-09 21:11:45 +01002889 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2890 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302891 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2892 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2893 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002894
Peter Huewe599801f2012-02-09 21:11:45 +01002895 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302896 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2897 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002898 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302899 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2900 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2901 if (pVBInfo->TVInfo & NTSC1024x768)
2902 tempax = NTSC1024x768HT;
2903 }
2904 } else {
2905 tempax = PALHT;
2906 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002907 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302908 tempax = NTSCHT;
2909 tempbx = NTSCVT;
2910 if (pVBInfo->TVInfo & NTSC1024x768)
2911 tempax = NTSC1024x768HT;
2912 }
2913 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002914
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302915 pVBInfo->HT = tempax;
2916 pVBInfo->VT = tempbx;
2917 return;
2918 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002919}
2920
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002921static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302922 unsigned short RefreshRateTableIndex,
2923 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002924{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002925 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002926
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302927 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2928 pVBInfo);
2929 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2930 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002931
Peter Huewe6896b942012-02-09 21:11:46 +01002932 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302933 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002934 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2935 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2936 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302937 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002938 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2939 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302940 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002941
Aaro Koskinen8104e322011-03-13 12:26:22 +02002942 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302944 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002945 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302946 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002947 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002948}
2949
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002950static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2951 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002952{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002953 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2954 short index;
2955 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302956
Aaro Koskinenb3979922012-11-04 21:14:52 +02002957 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002958 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302959
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002960 if (index < 0)
2961 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302962
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002963 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302964}
2965
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002966static unsigned short XGI_GetOffset(unsigned short ModeNo,
2967 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302968 unsigned short RefreshRateTableIndex,
2969 struct xgi_hw_device_info *HwDeviceExtension,
2970 struct vb_device_info *pVBInfo)
2971{
2972 unsigned short temp, colordepth, modeinfo, index, infoflag,
2973 ColorDepth[] = { 0x01, 0x02, 0x04 };
2974
Aaro Koskinenb3979922012-11-04 21:14:52 +02002975 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002976 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302977
2978 index = (modeinfo >> 8) & 0xFF;
2979
2980 temp = pVBInfo->ScreenOffset[index];
2981
2982 if (infoflag & InterlaceMode)
2983 temp = temp << 1;
2984
2985 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2986
2987 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2988 temp = ModeNo - 0x7C;
2989 colordepth = ColorDepth[temp];
2990 temp = 0x6B;
2991 if (infoflag & InterlaceMode)
2992 temp = temp << 1;
2993 return temp * colordepth;
2994 } else {
2995 return temp * colordepth;
2996 }
2997}
2998
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002999static void XGI_SetCRT2Offset(unsigned short ModeNo,
3000 unsigned short ModeIdIndex,
3001 unsigned short RefreshRateTableIndex,
3002 struct xgi_hw_device_info *HwDeviceExtension,
3003 struct vb_device_info *pVBInfo)
3004{
3005 unsigned short offset;
3006 unsigned char temp;
3007
3008 if (pVBInfo->VBInfo & SetInSlaveMode)
3009 return;
3010
3011 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3012 HwDeviceExtension, pVBInfo);
3013 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003014 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003015 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003016 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003017 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003018 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003019}
3020
Randy Dunlap89229672010-08-10 08:46:44 -07003021static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003022{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003023 /* threshold high ,disable auto threshold */
3024 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
3025 /* threshold low default 04h */
3026 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003027}
3028
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003029static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303030 struct xgi_hw_device_info *HwDeviceExtension,
3031 unsigned short RefreshRateTableIndex,
3032 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003033{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303034 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003035
Aaro Koskinena39325d2012-11-04 21:14:53 +02003036 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003037 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02003038 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303040 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3041 HwDeviceExtension, pVBInfo);
3042 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303044 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003045 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003046
Aaro Koskinen8104e322011-03-13 12:26:22 +02003047 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
3048 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003049}
3050
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003051static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303052 struct xgi_hw_device_info *HwDeviceExtension,
3053 unsigned short RefreshRateTableIndex,
3054 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003055{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303056 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
3057 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003058
Aaro Koskinena39325d2012-11-04 21:14:53 +02003059 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003060 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02003061 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
3062 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003063
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303064 /* bainy change table name */
3065 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003066 /* BTVGA2HT 0x08,0x09 */
3067 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003068 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303069 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003070 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003071 /* BTVGA2HDEE 0x0A,0x0C */
3072 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003073 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303074 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
3075 pushbx = pVBInfo->VGAHDE / 2 + 16;
3076 tempcx = tempcx >> 1;
3077 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3078 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303080 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003081 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
3082 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003083 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303084 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003085 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303086 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003087 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303088 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3089 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3090 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303092 tempbx += 4;
3093 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003094
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303095 if (tempcx > (pVBInfo->VGAHT / 2))
3096 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303098 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003099
Aaro Koskinen8104e322011-03-13 12:26:22 +02003100 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303101 } else {
3102 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003103 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303104 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003105 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003106 /* BTVGA2HDEE 0x0A,0x0C */
3107 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003108 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303109 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
3110 pushbx = pVBInfo->VGAHDE + 16;
3111 tempcx = tempcx >> 1;
3112 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3113 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303115 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003116 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
3117 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003118 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303119 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003120 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303121 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003122 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303123 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3124 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3125 tempbx += 16;
3126 tempcx += 16;
3127 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303129 if (tempcx > pVBInfo->VGAHT)
3130 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303132 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003133 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303134 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303136 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3137 tempbx = pushbx;
3138 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3139 tempax |= (tempbx & 0xFF00);
3140 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003141 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303142 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003143 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303144 tempcx = (pVBInfo->VGAVT - 1);
3145 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003146
Aaro Koskinen8104e322011-03-13 12:26:22 +02003147 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303148 tempbx = pVBInfo->VGAVDE - 1;
3149 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003150 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303151 temp = ((tempbx & 0xFF00) << 3) >> 8;
3152 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003153 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003154
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303155 tempax = pVBInfo->VGAVDE;
3156 tempbx = pVBInfo->VGAVDE;
3157 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003158 /* BTVGA2VRS 0x10,0x11 */
3159 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3160 /* BTVGA2VRE 0x11 */
3161 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303163 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003164 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
3165 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303167 if (temp & 0x04)
3168 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303170 if (temp & 0x080)
3171 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003172
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003173 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303175 if (temp & 0x08)
3176 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003177
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003178 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303179 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3180 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003181
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303182 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003183 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303184 temp = ((tempbx & 0xFF00) >> 8) << 4;
3185 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003186 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303187 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003188
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303189 if (modeflag & DoubleScanMode)
3190 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303192 if (modeflag & HalfDCLK)
3193 tempax |= 0x40;
3194
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003195 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003196}
3197
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003198static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3199{
3200 unsigned long tempax, tempbx;
3201
3202 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3203 & 0xFFFF;
3204 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3205 tempax = (tempax * pVBInfo->HT) / tempbx;
3206
3207 return (unsigned short) tempax;
3208}
3209
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003210static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303211 struct xgi_hw_device_info *HwDeviceExtension,
3212 unsigned short RefreshRateTableIndex,
3213 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003214{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303215 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
3216 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003217
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003218 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003219 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3220 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003221 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003222 CRT1Index &= IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303224 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3225 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303227 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003228 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303229 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003230
Peter Huewe6896b942012-02-09 21:11:46 +01003231 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303232 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303234 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003235
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303236 if (modeflag & HalfDCLK)
3237 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303239 tempax = (tempax / tempcx) - 1;
3240 tempbx |= ((tempax & 0x00FF) << 8);
3241 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003242 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303244 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303246 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003247 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3248 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303249 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003250
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003251 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3252 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303253 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303254 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003255
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003256 /* 0x05 Horizontal Display Start */
3257 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3258 /* 0x06 Horizontal Blank end */
3259 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003260
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303261 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3262 if (pVBInfo->VBInfo & SetCRT2ToTV)
3263 tempax = pVBInfo->VGAHT;
3264 else
3265 tempax = XGI_GetVGAHT2(pVBInfo);
3266 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003267
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303268 if (tempax >= pVBInfo->VGAHT)
3269 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003270
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303271 if (modeflag & HalfDCLK)
3272 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303274 tempax = (tempax / tempcx) - 5;
3275 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003276 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303277 temp = (tempbx & 0x00FF) - 1;
3278 if (!(modeflag & HalfDCLK)) {
3279 temp -= 6;
3280 if (pVBInfo->TVInfo & TVSimuMode) {
3281 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003282 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303283 }
3284 }
3285 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303286 tempbx = (tempbx & 0xFF00) >> 8;
3287 tempcx = (tempcx + tempbx) >> 1;
3288 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303290 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3291 temp -= 1;
3292 if (!(modeflag & HalfDCLK)) {
3293 if ((modeflag & Charx8Dot)) {
3294 temp += 4;
3295 if (pVBInfo->VGAHDE >= 800)
3296 temp -= 6;
3297 }
3298 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003299 } else if (!(modeflag & HalfDCLK)) {
3300 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003301 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003302 pVBInfo->VGAHDE >= 800) {
3303 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003304 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003305 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003306 (pVBInfo->LCDInfo & LCDNonExpanding))
3307 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303308 }
3309 }
3310 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003311
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003312 /* 0x07 Horizontal Retrace Start */
3313 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3314 /* 0x08 Horizontal Retrace End */
3315 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003316
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303317 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3318 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003319 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303320 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003321 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303322 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003323 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303324 0x08, 0x03);
3325 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003326 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303327 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003328 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303329 0x08, 0x02);
3330 }
3331 }
3332 }
3333 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003334
Aaro Koskinen8104e322011-03-13 12:26:22 +02003335 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003336 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003337 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003338
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303339 tempbx = pVBInfo->VGAVT;
3340 push1 = tempbx;
3341 tempcx = 0x121;
3342 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303344 if (tempbx == 357)
3345 tempbx = 350;
3346 if (tempbx == 360)
3347 tempbx = 350;
3348 if (tempbx == 375)
3349 tempbx = 350;
3350 if (tempbx == 405)
3351 tempbx = 400;
3352 if (tempbx == 525)
3353 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003354
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303355 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003356
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303357 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003358 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003359 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303360 if (tempbx == 350)
3361 tempbx += 5;
3362 if (tempbx == 480)
3363 tempbx += 5;
3364 }
3365 }
3366 }
3367 tempbx--;
3368 temp = tempbx & 0x00FF;
3369 tempbx--;
3370 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003371 /* 0x10 vertical Blank Start */
3372 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303373 tempbx = push2;
3374 tempbx--;
3375 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003376 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003377
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303378 if (tempbx & 0x0100)
3379 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003380
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303381 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303383 if (modeflag & DoubleScanMode)
3384 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003385
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303386 if (tempbx & 0x0200)
3387 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003388
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303389 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003390 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003391
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303392 if (tempbx & 0x0400)
3393 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003394
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003395 /* 0x11 Vertival Blank End */
3396 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303397
3398 tempax = push1;
3399 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3400 tempax = tempax >> 2;
3401 push1 = tempax; /* push ax */
3402
3403 if (resinfo != 0x09) {
3404 tempax = tempax << 1;
3405 tempbx += tempax;
3406 }
3407
Peter Huewe599801f2012-02-09 21:11:45 +01003408 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003409 if ((pVBInfo->VBType & VB_SIS301LV) &&
3410 !(pVBInfo->TVInfo & TVSetHiVision)) {
3411 if ((pVBInfo->TVInfo & TVSimuMode) &&
3412 (pVBInfo->TVInfo & TVSetPAL)) {
3413 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3414 !(pVBInfo->TVInfo &
3415 (TVSetYPbPr525p |
3416 TVSetYPbPr750p |
3417 TVSetHiVision)))
3418 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303419 }
3420 } else {
3421 tempbx -= 10;
3422 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003423 } else if (pVBInfo->TVInfo & TVSimuMode) {
3424 if (pVBInfo->TVInfo & TVSetPAL) {
3425 if (pVBInfo->VBType & VB_SIS301LV) {
3426 if (!(pVBInfo->TVInfo &
3427 (TVSetYPbPr525p |
3428 TVSetYPbPr750p |
3429 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303430 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003431 } else {
3432 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303433 }
3434 }
3435 }
3436 tempax = push1;
3437 tempax = tempax >> 2;
3438 tempax++;
3439 tempax += tempbx;
3440 push1 = tempax; /* push ax */
3441
Peter Huewe599801f2012-02-09 21:11:45 +01003442 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303443 if (tempbx <= 513) {
3444 if (tempax >= 513)
3445 tempbx = 513;
3446 }
3447 }
3448
3449 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003450 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303451 tempbx--;
3452 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003453 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303454
3455 if (tempbx & 0x0100)
3456 tempcx |= 0x0008;
3457
3458 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003459 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303460
3461 tempbx++;
3462
3463 if (tempbx & 0x0100)
3464 tempcx |= 0x0004;
3465
3466 if (tempbx & 0x0200)
3467 tempcx |= 0x0080;
3468
3469 if (tempbx & 0x0400)
3470 tempcx |= 0x0C00;
3471
3472 tempbx = push1; /* pop ax */
3473 temp = tempbx & 0x00FF;
3474 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003475 /* 0x0D vertical Retrace End */
3476 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303477
3478 if (tempbx & 0x0010)
3479 tempcx |= 0x2000;
3480
3481 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003482 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303483 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003484 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303485 tempax = modeflag;
3486 temp = (tempax & 0xFF00) >> 8;
3487
3488 temp = (temp >> 1) & 0x09;
3489
Peter Huewe6896b942012-02-09 21:11:46 +01003490 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303491 temp |= 0x01;
3492
Aaro Koskinen8104e322011-03-13 12:26:22 +02003493 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3494 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3495 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303496
3497 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3498 temp = 0x80;
3499 else
3500 temp = 0x00;
3501
Aaro Koskinen8104e322011-03-13 12:26:22 +02003502 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303503
3504 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003505}
3506
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003507static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303508 unsigned short RefreshRateTableIndex,
3509 struct xgi_hw_device_info *HwDeviceExtension,
3510 struct vb_device_info *pVBInfo)
3511{
3512 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
3513 modeflag, resinfo, crt2crtc;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003514 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303515
3516 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3517
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003518 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003519 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3520 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003521 crt2crtc = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303522
3523 tempax = 0;
3524
3525 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3526 tempax |= 0x0800;
3527
3528 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3529 tempax |= 0x0400;
3530
3531 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3532 tempax |= 0x0200;
3533
Peter Huewe599801f2012-02-09 21:11:45 +01003534 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303535 tempax |= 0x1000;
3536
Peter Huewe599801f2012-02-09 21:11:45 +01003537 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303538 tempax |= 0x0100;
3539
Peter Huewe599801f2012-02-09 21:11:45 +01003540 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303541 tempax &= 0xfe00;
3542
3543 tempax = (tempax & 0xff00) >> 8;
3544
Aaro Koskinen8104e322011-03-13 12:26:22 +02003545 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003546 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303547
Peter Huewe599801f2012-02-09 21:11:45 +01003548 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003549 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303550
Peter Huewe599801f2012-02-09 21:11:45 +01003551 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003552 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303553
3554 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003555 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303556
3557 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003558 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303559
3560 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003561 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303562 }
3563
Peter Huewe599801f2012-02-09 21:11:45 +01003564 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3565 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003566 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303567
Peter Huewe599801f2012-02-09 21:11:45 +01003568 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003569 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303570
Peter Huewe599801f2012-02-09 21:11:45 +01003571 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003572 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303573 }
3574
3575 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003576 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303577
3578 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003579 /* di->temp2[j] */
3580 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303581
3582 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003583 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303584
3585 temp = pVBInfo->NewFlickerMode;
3586 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003587 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303588
Peter Huewe599801f2012-02-09 21:11:45 +01003589 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303590 tempax = 950;
3591
Peter Huewe599801f2012-02-09 21:11:45 +01003592 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303593 tempax = 520;
3594 else
3595 tempax = 440;
3596
3597 if (pVBInfo->VDE <= tempax) {
3598 tempax -= pVBInfo->VDE;
3599 tempax = tempax >> 2;
3600 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3601 push1 = tempax;
3602 temp = (tempax & 0xFF00) >> 8;
3603 temp += (unsigned short) TimingPoint[0];
3604
Peter Huewe6896b942012-02-09 21:11:46 +01003605 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3606 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303607 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3608 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003609 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303610 tempcx = pVBInfo->VGAHDE;
3611 if (tempcx >= 1024) {
3612 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003613 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303614 temp = 0x19; /* PAL */
3615 }
3616 }
3617 }
3618
Aaro Koskinen8104e322011-03-13 12:26:22 +02003619 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303620 tempax = push1;
3621 temp = (tempax & 0xFF00) >> 8;
3622 temp += TimingPoint[1];
3623
Peter Huewe6896b942012-02-09 21:11:46 +01003624 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3625 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303626 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3627 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003628 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303629 tempcx = pVBInfo->VGAHDE;
3630 if (tempcx >= 1024) {
3631 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003632 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303633 temp = 0x52; /* PAL */
3634 }
3635 }
3636 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003637 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303638 }
3639
3640 /* 301b */
3641 tempcx = pVBInfo->HT;
3642
3643 if (XGI_IsLCDDualLink(pVBInfo))
3644 tempcx = tempcx >> 1;
3645
3646 tempcx -= 2;
3647 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003648 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303649
3650 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003651 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303652
3653 tempcx = pVBInfo->HT >> 1;
3654 push1 = tempcx; /* push cx */
3655 tempcx += 7;
3656
Peter Huewe599801f2012-02-09 21:11:45 +01003657 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303658 tempcx -= 4;
3659
3660 temp = tempcx & 0x00FF;
3661 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003662 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303663
3664 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3665 tempbx += tempcx;
3666 push2 = tempbx;
3667 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003668 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303669 temp = (tempbx & 0xFF00) >> 8;
3670 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003671 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303672
3673 tempbx = push2;
3674 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003675 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303676 tempbx = tempbx - 4;
3677 tempcx = tempbx;
3678 }
3679
3680 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003681 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303682
3683 j += 2;
3684 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3685 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003686 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303687 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003688 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303689
3690 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003691 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303692 tempcx -= 4;
3693
3694 temp = tempcx & 0xFF;
3695 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003696 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303697
3698 tempcx = push1; /* pop cx */
3699 j += 2;
3700 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3701 tempcx -= temp;
3702 temp = tempcx & 0x00FF;
3703 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003704 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303705
3706 tempcx -= 11;
3707
3708 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3709 tempax = XGI_GetVGAHT2(pVBInfo);
3710 tempcx = tempax - 1;
3711 }
3712 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003713 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303714
3715 tempbx = pVBInfo->VDE;
3716
3717 if (pVBInfo->VGAVDE == 360)
3718 tempbx = 746;
3719 if (pVBInfo->VGAVDE == 375)
3720 tempbx = 746;
3721 if (pVBInfo->VGAVDE == 405)
3722 tempbx = 853;
3723
3724 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003725 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003726 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003727 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003728 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303729 tempbx = tempbx >> 1;
3730 } else
3731 tempbx = tempbx >> 1;
3732 }
3733
3734 tempbx -= 2;
3735 temp = tempbx & 0x00FF;
3736
Peter Huewe599801f2012-02-09 21:11:45 +01003737 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003738 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003739 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303740 if (pVBInfo->VBInfo & SetInSlaveMode) {
3741 if (ModeNo == 0x2f)
3742 temp += 1;
3743 }
3744 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003745 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3746 if (ModeNo == 0x2f)
3747 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303748 }
3749 }
3750
Aaro Koskinen8104e322011-03-13 12:26:22 +02003751 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303752
3753 temp = (tempcx & 0xFF00) >> 8;
3754 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3755
Peter Huewe599801f2012-02-09 21:11:45 +01003756 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003757 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003758 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303759 temp |= 0x10;
3760
3761 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3762 temp |= 0x20;
3763 }
3764 } else {
3765 temp |= 0x10;
3766 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3767 temp |= 0x20;
3768 }
3769 }
3770
Aaro Koskinen8104e322011-03-13 12:26:22 +02003771 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303772
Peter Huewe6896b942012-02-09 21:11:46 +01003773 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3774 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303775 tempbx = pVBInfo->VDE;
3776 tempcx = tempbx - 2;
3777
3778 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003779 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3780 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303781 tempbx = tempbx >> 1;
3782 }
3783
Peter Huewe6896b942012-02-09 21:11:46 +01003784 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303785 temp = 0;
3786 if (tempcx & 0x0400)
3787 temp |= 0x20;
3788
3789 if (tempbx & 0x0400)
3790 temp |= 0x40;
3791
Aaro Koskinen8104e322011-03-13 12:26:22 +02003792 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303793 }
3794
3795 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003796 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303797 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003798 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303799 }
3800
3801 tempbx = tempbx & 0x00FF;
3802
3803 if (!(modeflag & HalfDCLK)) {
3804 tempcx = pVBInfo->VGAHDE;
3805 if (tempcx >= pVBInfo->HDE) {
3806 tempbx |= 0x2000;
3807 tempax &= 0x00FF;
3808 }
3809 }
3810
3811 tempcx = 0x0101;
3812
3813 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3814 if (pVBInfo->VGAHDE >= 1024) {
3815 tempcx = 0x1920;
3816 if (pVBInfo->VGAHDE >= 1280) {
3817 tempcx = 0x1420;
3818 tempbx = tempbx & 0xDFFF;
3819 }
3820 }
3821 }
3822
3823 if (!(tempbx & 0x2000)) {
3824 if (modeflag & HalfDCLK)
3825 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3826
3827 push1 = tempbx;
3828 tempeax = pVBInfo->VGAHDE;
3829 tempebx = (tempcx & 0xFF00) >> 8;
3830 longtemp = tempeax * tempebx;
3831 tempecx = tempcx & 0x00FF;
3832 longtemp = longtemp / tempecx;
3833
3834 /* 301b */
3835 tempecx = 8 * 1024;
3836
Peter Huewe6896b942012-02-09 21:11:46 +01003837 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3838 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303839 tempecx = tempecx * 8;
3840 }
3841
3842 longtemp = longtemp * tempecx;
3843 tempecx = pVBInfo->HDE;
3844 temp2 = longtemp % tempecx;
3845 tempeax = longtemp / tempecx;
3846 if (temp2 != 0)
3847 tempeax += 1;
3848
3849 tempax = (unsigned short) tempeax;
3850
3851 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003852 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3853 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303854 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3855 }
3856 /* end 301b */
3857
3858 tempbx = push1;
3859 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3860 | (tempbx & 0x00FF));
3861 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3862 | (tempax & 0x00FF));
3863 temp = (tempax & 0xFF00) >> 8;
3864 } else {
3865 temp = (tempax & 0x00FF) >> 8;
3866 }
3867
Aaro Koskinen8104e322011-03-13 12:26:22 +02003868 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303869 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003870 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303871 temp = tempcx & 0x00FF;
3872
3873 if (tempbx & 0x2000)
3874 temp = 0;
3875
3876 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3877 temp |= 0x18;
3878
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003879 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003880 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303881 tempbx = 0x0382;
3882 tempcx = 0x007e;
3883 } else {
3884 tempbx = 0x0369;
3885 tempcx = 0x0061;
3886 }
3887
3888 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003889 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303890 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003891 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303892
3893 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3894 temp = temp << 2;
3895 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3896
Peter Huewe599801f2012-02-09 21:11:45 +01003897 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303898 temp |= 0x10;
3899
Peter Huewe599801f2012-02-09 21:11:45 +01003900 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303901 temp |= 0x20;
3902
Peter Huewe599801f2012-02-09 21:11:45 +01003903 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303904 temp |= 0x60;
3905 }
3906
Aaro Koskinen8104e322011-03-13 12:26:22 +02003907 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003908 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003909 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303910
Peter Huewe599801f2012-02-09 21:11:45 +01003911 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303912 if (pVBInfo->TVInfo & NTSC1024x768) {
3913 TimingPoint = XGI_NTSC1024AdjTime;
3914 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003915 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303916 TimingPoint[j]);
3917 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003918 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303919 }
3920 }
3921
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003922 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303923 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003924 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003925 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303926 0x08); /* PALM Mode */
3927 }
3928
Peter Huewe599801f2012-02-09 21:11:45 +01003929 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003930 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303931 0x01);
3932 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003933 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303934
Aaro Koskinendc505562011-03-13 12:26:26 +02003935 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303936 }
3937
Peter Huewe599801f2012-02-09 21:11:45 +01003938 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303939 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003940 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303941 }
3942
3943 if (pVBInfo->VBInfo & SetCRT2ToTV)
3944 return;
3945}
3946
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003947static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303948 struct xgi_hw_device_info *HwDeviceExtension,
3949 unsigned short RefreshRateTableIndex,
3950 struct vb_device_info *pVBInfo)
3951{
3952 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
3953 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
3954
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003955 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303956
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003957 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003958 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3959 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003960 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003961 CRT1Index &= IndexMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303962
3963 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3964 return;
3965
3966 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3967
3968 if (XGI_IsLCDDualLink(pVBInfo))
3969 tempbx = tempbx >> 1;
3970
3971 tempbx -= 1;
3972 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003973 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303974 temp = (tempbx & 0xFF00) >> 8;
3975 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003976 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303977 temp = 0x01;
3978
Aaro Koskinen8104e322011-03-13 12:26:22 +02003979 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303980 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
3981 push1 = tempbx;
3982 tempbx--;
3983 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003984 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303985 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003986 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303987
3988 tempcx = pVBInfo->VT - 1;
3989 push2 = tempcx + 1;
3990 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003991 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303992 temp = (tempcx & 0xFF00) >> 8;
3993 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003994 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003995 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3996 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3997 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3998 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303999
Justin P. Mattock558f7582012-10-02 21:17:11 -07004000 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02004001 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
4002 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
4003 RefreshRateTableIndex, pVBInfo);
4004 else
4005 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
4006 ModeIdIndex, RefreshRateTableIndex,
4007 pVBInfo);
4008
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304009 tempah = pVBInfo->LCDResInfo;
4010 tempah &= PanelResInfo;
4011
Peter Huewe255aabd2012-02-09 21:11:44 +01004012 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304013 tempbx = 1024;
4014 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01004015 } else if ((tempah == Panel_1280x1024) ||
4016 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304017 tempbx = 1280;
4018 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01004019 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304020 tempbx = 1400;
4021 tempcx = 1050;
4022 } else {
4023 tempbx = 1600;
4024 tempcx = 1200;
4025 }
4026
4027 if (pVBInfo->LCDInfo & EnableScalingLCD) {
4028 tempbx = pVBInfo->HDE;
4029 tempcx = pVBInfo->VDE;
4030 }
4031
4032 pushbx = tempbx;
4033 tempax = pVBInfo->VT;
4034 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
4035 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
4036 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
4037 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
4038 tempbx = pVBInfo->LCDVDES;
4039 tempcx += tempbx;
4040
4041 if (tempcx >= tempax)
4042 tempcx -= tempax; /* lcdvdes */
4043
4044 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004045 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304046 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004047 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304048 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
4049 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
4050 tempah = tempch;
4051 tempah = tempah << 3;
4052 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004053 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304054
4055 /* getlcdsync() */
4056 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4057 tempcx = tempbx;
4058 tempax = pVBInfo->VT;
4059 tempbx = pVBInfo->LCDVRS;
4060
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304061 tempcx += tempbx;
4062 if (tempcx >= tempax)
4063 tempcx -= tempax;
4064
4065 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004066 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304067 temp = (tempbx & 0xFF00) >> 8;
4068 temp = temp << 4;
4069 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004070 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304071 tempcx = pushbx;
4072 tempax = pVBInfo->HT;
4073 tempbx = pVBInfo->LCDHDES;
4074 tempbx &= 0x0FFF;
4075
4076 if (XGI_IsLCDDualLink(pVBInfo)) {
4077 tempax = tempax >> 1;
4078 tempbx = tempbx >> 1;
4079 tempcx = tempcx >> 1;
4080 }
4081
Peter Huewe6896b942012-02-09 21:11:46 +01004082 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304083 tempbx += 1;
4084
4085 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
4086 tempbx += 1;
4087
4088 tempcx += tempbx;
4089
4090 if (tempcx >= tempax)
4091 tempcx -= tempax;
4092
4093 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004094 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304095 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004096 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304097 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004098 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304099 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004100 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304102 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4103 tempcx = tempax;
4104 tempax = pVBInfo->HT;
4105 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304106 if (XGI_IsLCDDualLink(pVBInfo)) {
4107 tempax = tempax >> 1;
4108 tempbx = tempbx >> 1;
4109 tempcx = tempcx >> 1;
4110 }
4111
Peter Huewe6896b942012-02-09 21:11:46 +01004112 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304113 tempbx += 1;
4114
4115 tempcx += tempbx;
4116
4117 if (tempcx >= tempax)
4118 tempcx -= tempax;
4119
4120 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004121 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304122
4123 temp = (tempbx & 0xFF00) >> 8;
4124 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004125 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304126 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004127 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304128
Peter Huewea3d675c2012-02-09 21:11:47 +01004129 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304130 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01004131 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4132 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304133 | VB_XGI301C)) {
4134 temp = 0xC6;
4135 } else
4136 temp = 0xC4;
4137
Aaro Koskinen8104e322011-03-13 12:26:22 +02004138 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4139 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304140 }
4141
4142 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004143 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4144 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304145 | VB_XGI301C)) {
4146 temp = 0x4F;
4147 } else
4148 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004149 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304150 }
4151 }
4152}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004153
4154/* --------------------------------------------------------------------- */
4155/* Function : XGI_GetTap4Ptr */
4156/* Input : */
4157/* Output : di -> Tap4 Reg. Setting Pointer */
4158/* Description : */
4159/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004160static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304161 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004162{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304163 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304165 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304167 if (tempcx == 0) {
4168 tempax = pVBInfo->VGAHDE;
4169 tempbx = pVBInfo->HDE;
4170 } else {
4171 tempax = pVBInfo->VGAVDE;
4172 tempbx = pVBInfo->VDE;
4173 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004174
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004175 if (tempax <= tempbx)
4176 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304177 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004178 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004179
Peter Huewe599801f2012-02-09 21:11:45 +01004180 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304181 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004182
Peter Huewe599801f2012-02-09 21:11:45 +01004183 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4184 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4185 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004186 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004187 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304188 Tap4TimingPtr = YPbPr750pTap4Timing;
4189 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004190
Peter Huewe599801f2012-02-09 21:11:45 +01004191 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004192 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004193
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304194 i = 0;
4195 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4196 if (Tap4TimingPtr[i].DE == tempax)
4197 break;
4198 i++;
4199 }
4200 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004201}
4202
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004203static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004204{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304205 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004206
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304207 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004208
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304209 if (!(pVBInfo->VBType & VB_XGI301C))
4210 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004211
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304212 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4213 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004214 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004215
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004216 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004217 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004218 /* Set Vertical Scaling */
4219 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304220 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004221 xgifb_reg_set(pVBInfo->Part2Port,
4222 i,
4223 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304224 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004225
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004226 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004227 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004228 /* Enable V.Scaling */
4229 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304230 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004231 /* Enable H.Scaling */
4232 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004233}
4234
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004235static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304236 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004237{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304238 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004239 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304240 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004241
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004242 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004243 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004244
Aaro Koskinen8104e322011-03-13 12:26:22 +02004245 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004246 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004247 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4248 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304249 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004250 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4251 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304252 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304254 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4255 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004256
Peter Huewe599801f2012-02-09 21:11:45 +01004257 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004258 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4259 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4260 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304261 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004262
Peter Huewe599801f2012-02-09 21:11:45 +01004263 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4264 & SetCRT2ToYPbPr525750)) {
4265 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304266 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004267
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004268 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304269 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004270 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304271 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004272 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304273 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004274
Peter Huewe599801f2012-02-09 21:11:45 +01004275 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004276 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004277
Peter Huewe599801f2012-02-09 21:11:45 +01004278 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004279 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004280
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304281 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004282 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004283
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304284 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004285 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004286 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304287 }
4288 }
4289 return;
4290} /* {end of XGI_SetGroup3} */
4291
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004292static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304293 unsigned short RefreshRateTableIndex,
4294 struct xgi_hw_device_info *HwDeviceExtension,
4295 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004296{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304297 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004298
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304299 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004300
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004301 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004302 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304303 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004304 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004305
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304306 tempbx = pVBInfo->RVBHCMAX;
4307 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004308 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304309 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4310 tempcx = pVBInfo->VGAHT - 1;
4311 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004312 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004313
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304314 temp = ((tempcx & 0xFF00) >> 8) << 3;
4315 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004316
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304317 tempcx = pVBInfo->VGAVT - 1;
4318 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4319 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004320
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304321 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004322 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304323 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004324 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004325 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304326 tempcx = pVBInfo->VBInfo;
4327 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004328
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304329 if (modeflag & HalfDCLK)
4330 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304332 if (XGI_IsLCDDualLink(pVBInfo))
4333 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004334
Peter Huewe599801f2012-02-09 21:11:45 +01004335 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304336 temp = 0;
4337 if (tempbx <= 1024)
4338 temp = 0xA0;
4339 if (tempbx == 1280)
4340 temp = 0xC0;
4341 } else if (tempcx & SetCRT2ToTV) {
4342 temp = 0xA0;
4343 if (tempbx <= 800)
4344 temp = 0x80;
4345 } else {
4346 temp = 0x80;
4347 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4348 temp = 0;
4349 if (tempbx > 800)
4350 temp = 0x60;
4351 }
4352 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004353
Peter Huewe599801f2012-02-09 21:11:45 +01004354 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304355 temp = 0x00;
4356 if (pVBInfo->VGAHDE == 1280)
4357 temp = 0x40;
4358 if (pVBInfo->VGAHDE == 1024)
4359 temp = 0x20;
4360 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004361 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004362
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304363 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004364
Peter Huewe599801f2012-02-09 21:11:45 +01004365 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304366 if (!(temp & 0xE000))
4367 tempbx = tempbx >> 1;
4368 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004369
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304370 tempcx = pVBInfo->RVBHRS;
4371 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004372 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004373
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304374 tempeax = pVBInfo->VGAVDE;
4375 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004376
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304377 if (tempeax <= tempebx) {
4378 tempcx = (tempcx & (~0x4000));
4379 tempeax = pVBInfo->VGAVDE;
4380 } else {
4381 tempeax -= tempebx;
4382 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004383
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304384 templong = (tempeax * 256 * 1024) % tempebx;
4385 tempeax = (tempeax * 256 * 1024) / tempebx;
4386 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004387
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304388 if (templong != 0)
4389 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004390
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304391 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004392 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004393
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304394 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004395 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304396 tempbx = (unsigned short) (tempebx >> 16);
4397 temp = tempbx & 0x00FF;
4398 temp = temp << 4;
4399 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004400 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004401
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304402 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004403 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4404 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304405 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004406 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304407 tempax = pVBInfo->VGAHDE;
4408 if (modeflag & HalfDCLK)
4409 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004410
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304411 if (XGI_IsLCDDualLink(pVBInfo))
4412 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304414 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4415 if (tempax > 800)
4416 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004417 } else if (pVBInfo->VGAHDE > 800) {
4418 if (pVBInfo->VGAHDE == 1024)
4419 tempax = (tempax * 25 / 32) - 1;
4420 else
4421 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304422 }
4423 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004424
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304425 temp = (tempax & 0xFF00) >> 8;
4426 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004427 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304428 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004429 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004430
Peter Huewe599801f2012-02-09 21:11:45 +01004431 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304432 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004433 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004434
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304435 }
4436 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004437
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304438 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4439 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004440 | TVSetYPbPr525p | TVSetYPbPr750p
4441 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304442 temp |= 0x0001;
4443 if ((pVBInfo->VBInfo & SetInSlaveMode)
4444 && (!(pVBInfo->TVInfo
4445 & TVSimuMode)))
4446 temp &= (~0x0001);
4447 }
4448 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004449
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004450 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304451 tempbx = pVBInfo->HT;
4452 if (XGI_IsLCDDualLink(pVBInfo))
4453 tempbx = tempbx >> 1;
4454 tempbx = (tempbx >> 1) - 2;
4455 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004456 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304457 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004458 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304459 }
4460 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004461
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004462 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004463}
4464
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004465static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4466{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004467 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004468}
4469
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004470static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304471 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004472{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304473 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004474
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304475 Pindex = pVBInfo->Part5Port;
4476 Pdata = pVBInfo->Part5Port + 1;
4477 if (pVBInfo->ModeType == ModeVGA) {
4478 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004479 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304480 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304481 }
4482 }
4483 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004484}
4485
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004486static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304487 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004488{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004489 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004490}
4491
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004492static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304493 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004494{
4495
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004496 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004497}
4498
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004499static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4500 unsigned short ModeNo, unsigned short ModeIdIndex,
4501 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004502{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004503 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004504
Aaro Koskinenb3979922012-11-04 21:14:52 +02004505 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004506 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
4507 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
4508 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004509 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004510
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304511 if (!(modeflag & Charx8Dot)) {
4512 xres /= 9;
4513 xres *= 8;
4514 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004515
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004516 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4517 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004518
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004519 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4520 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004521
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004522 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304523 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004524
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004525 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304526 return 0;
4527
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004528 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4529 yres != xgifb_info->lvds_data.LVDSVDE) {
4530 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4531 if (colordepth > 2)
4532 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304533 }
4534 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004535}
4536
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004537static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4538 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004539 unsigned short ModeNo,
4540 unsigned short ModeIdIndex,
4541 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004542{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304543 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004544 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304545 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4546 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4547 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004548
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004549 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004550 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004552 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004553
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004554 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004555
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004556 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004557 /* SR35[7] FP VSync polarity */
4558 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4559 /* SR30[5] FP HSync polarity */
4560 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004561
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004562 if (chip_id == XG27)
4563 XGI_SetXG27FPBits(pVBInfo);
4564 else
4565 XGI_SetXG21FPBits(pVBInfo);
4566
Aaro Koskinenb3979922012-11-04 21:14:52 +02004567 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004568 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
4569 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
4570 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004571 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004572
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304573 if (!(modeflag & Charx8Dot))
4574 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004575
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004576 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004577
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004578 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004579
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304580 if (LVDSHBS > LVDSHT)
4581 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004582
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004583 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304584 if (LVDSHRS > LVDSHT)
4585 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004586
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004587 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304588 if (LVDSHRE > LVDSHT)
4589 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004590
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004591 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004592
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004593 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004594
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004595 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004596 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304597 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004598
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304599 if (LVDSVBS > LVDSVT)
4600 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004601
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004602 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304603 if (LVDSVRS > LVDSVT)
4604 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004605
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004606 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304607 if (LVDSVRE > LVDSVT)
4608 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004609
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004610 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004611
Aaro Koskinen58839b02011-03-13 12:26:23 +02004612 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004613 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004614
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304615 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004616 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004617
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304618 /* HT SR0B[1:0] CR00 */
4619 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004620 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004621 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004622
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304623 /* HBS SR0B[5:4] CR02 */
4624 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004625 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004626 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004627
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304628 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4629 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004630 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4631 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4632 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004633
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304634 /* HRS SR0B[7:6] CR04 */
4635 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004636 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004637 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004638
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304639 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4640 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004641 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004642 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004643
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304644 /* HRE SR0C[2] CR05[4:0] */
4645 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004646 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4647 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004648
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304649 /* Panel HRE SR2F[7:2] */
4650 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004651 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004652
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304653 /* VT SR0A[0] CR07[5][0] CR06 */
4654 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004655 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4656 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4657 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004658 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004659
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304660 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4661 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004662 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4663 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4664 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004665 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004666
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304667 /* VBE SR0A[4] CR16 */
4668 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004669 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004670 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004671
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304672 /* VRS SR0A[3] CR7[7][2] CR10 */
4673 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004674 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4675 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4676 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004677 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004678
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004679 if (chip_id == XG27) {
4680 /* Panel VRS SR35[2:0] SR34[7:0] */
4681 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4682 (value & 0x700) >> 8);
4683 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4684 } else {
4685 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4686 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4687 (value & 0x600) >> 9);
4688 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4689 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4690 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004691
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304692 /* VRE SR0A[5] CR11[3:0] */
4693 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004694 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4695 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004696
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304697 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004698 if (chip_id == XG27)
4699 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4700 (value << 2) & 0xFC);
4701 else
4702 /* SR3F[7] has to be 0, h/w bug */
4703 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4704 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004705
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304706 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004707
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004708 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004709 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004710 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004711 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004712 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304713 value += 0x10;
4714 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004715
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304716 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004717 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004718 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004719 /* set data, panning = 0, shift left 1 dot*/
4720 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004721
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004722 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004723 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304724
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004725 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304726 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004727
4728}
4729
4730/* --------------------------------------------------------------------- */
4731/* Function : XGI_IsLCDON */
4732/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004733/* Output : 0 : Skip PSC Control */
4734/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004735/* Description : */
4736/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004737static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004738{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304739 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004740
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304741 tempax = pVBInfo->VBInfo;
4742 if (tempax & SetCRT2ToDualEdge)
4743 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004744 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304745 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004746
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304747 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004748}
4749
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004750/* --------------------------------------------------------------------- */
4751/* Function : XGI_DisableChISLCD */
4752/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004753/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004754/* Description : */
4755/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004756static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004757{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304758 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004759
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304760 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004761 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004762
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304763 if (tempbx & (EnableChA | DisableChA)) {
4764 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4765 return 0;
4766 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004767
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304768 if (!(tempbx & (EnableChB | DisableChB)))
4769 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004770
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304771 if (tempah & 0x01) /* Chk LCDB Mode */
4772 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004773
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304774 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004775}
4776
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004777/* --------------------------------------------------------------------- */
4778/* Function : XGI_EnableChISLCD */
4779/* Input : */
4780/* Output : 0 -> Not LCD mode */
4781/* Description : */
4782/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004783static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004784{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304785 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004786
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304787 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004788 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004789
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304790 if (tempbx & (EnableChA | DisableChA)) {
4791 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4792 return 0;
4793 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004794
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304795 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04004796 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304798 if (tempah & 0x01) /* Chk LCDB Mode */
4799 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304801 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004802}
4803
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004804static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4805 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304806 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004807{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004808 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004809
Peter Huewe6896b942012-02-09 21:11:46 +01004810 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4811 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304812 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004813 if (!(pVBInfo->VBInfo &
4814 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004815 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304816 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
4817 tempah = 0x7F; /* Disable Channel A */
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004818 if (!(pVBInfo->VBInfo &
4819 XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004820 /* Disable Channel B */
4821 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004822
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304823 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004824 /* force to disable Cahnnel */
4825 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004826
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304827 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004828 /* Force to disable Channel B */
4829 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304830 }
4831 }
4832 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004833
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004834 /* disable part4_1f */
4835 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004836
Peter Huewe6896b942012-02-09 21:11:46 +01004837 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004838 if (((pVBInfo->VBInfo &
4839 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4840 || (XGI_DisableChISLCD(pVBInfo))
4841 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004842 /* LVDS Driver power down */
4843 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304844 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304846 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004847 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304848 | SetSimuScanMode))) {
4849 if (pVBInfo->SetFlag & GatingCRT)
4850 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004851 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304852 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004853
Peter Huewea3d675c2012-02-09 21:11:47 +01004854 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304855 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004856 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004857 /* Power down */
4858 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304859 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004860
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004861 /* disable TV as primary VGA swap */
4862 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004863
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304864 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004865 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004866
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004867 if ((pVBInfo->SetFlag & DisableChB) ||
4868 (pVBInfo->VBInfo &
4869 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004870 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004871 (pVBInfo->VBInfo &
4872 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004873 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004874
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004875 if ((pVBInfo->SetFlag & DisableChB) ||
4876 (pVBInfo->VBInfo &
4877 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004878 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004879 (pVBInfo->VBInfo &
4880 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4881 /* save Part1 index 0 */
4882 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4883 /* BTDAC = 1, avoid VB reset */
4884 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4885 /* disable CRT2 */
4886 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4887 /* restore Part1 index 0 */
4888 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304889 }
4890 } else { /* {301} */
4891 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004892 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4893 /* Disable CRT2 */
4894 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4895 /* Disable TV asPrimary VGA swap */
4896 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304897 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004898
Peter Huewea3d675c2012-02-09 21:11:47 +01004899 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304900 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004901 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304902 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004903}
4904
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004905/* --------------------------------------------------------------------- */
4906/* Function : XGI_GetTVPtrIndex */
4907/* Input : */
4908/* Output : */
4909/* Description : bx 0 : ExtNTSC */
4910/* 1 : StNTSC */
4911/* 2 : ExtPAL */
4912/* 3 : StPAL */
4913/* 4 : ExtHiTV */
4914/* 5 : StHiTV */
4915/* 6 : Ext525i */
4916/* 7 : St525i */
4917/* 8 : Ext525p */
4918/* 9 : St525p */
4919/* A : Ext750p */
4920/* B : St750p */
4921/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004922static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004923{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304924 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004925
Peter Huewe599801f2012-02-09 21:11:45 +01004926 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304927 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004928 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304929 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004930 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304931 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004932 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304933 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004934 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304935 tempbx = 10;
4936 if (pVBInfo->TVInfo & TVSimuMode)
4937 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304939 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004940}
4941
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004942/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004943/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004944/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004945/* Output : bx 0 : NTSC */
4946/* 1 : PAL */
4947/* 2 : PALM */
4948/* 3 : PALN */
4949/* 4 : NTSC1024x768 */
4950/* 5 : PAL-M 1024x768 */
4951/* 6-7: reserved */
4952/* cl 0 : YFilter1 */
4953/* 1 : YFilter2 */
4954/* ch 0 : 301A */
4955/* 1 : 301B/302B/301LV/302LV */
4956/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004957/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004958static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4959 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004960{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004961 *tempbx = 0;
4962 *tempcl = 0;
4963 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004964
Peter Huewe599801f2012-02-09 21:11:45 +01004965 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004966 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004967
Peter Huewe599801f2012-02-09 21:11:45 +01004968 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004969 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004970
Peter Huewe599801f2012-02-09 21:11:45 +01004971 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004972 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004973
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004974 if (pVBInfo->TVInfo & NTSC1024x768) {
4975 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004976 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004977 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304978 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004979
Peter Huewe6896b942012-02-09 21:11:46 +01004980 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4981 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004982 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4983 & TVSimuMode)) {
4984 *tempbx += 8;
4985 *tempcl += 1;
4986 }
4987 }
4988
Peter Huewe6896b942012-02-09 21:11:46 +01004989 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4990 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004991 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004992}
4993
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004994static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004995{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304996 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004997
Peter Huewe6896b942012-02-09 21:11:46 +01004998 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4999 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005000 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305001 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305002 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02005003 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005004
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305005 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5006 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005007 if (pVBInfo->VBInfo &
5008 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02005009 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005010
Peter Huewea3d675c2012-02-09 21:11:47 +01005011 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305012 tempbl = tempbh;
5013 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005014
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305015 tempbl &= 0x0F;
5016 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02005017 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005018
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305019 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
5020 | SetCRT2ToTV)) { /* Channel B */
5021 tempah &= 0xF0;
5022 tempah |= tempbl;
5023 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005024
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005025 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5026 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305027 tempah &= 0x0F;
5028 tempah |= tempbh;
5029 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005030 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305031 }
5032 } else if (pVBInfo->IF_DEF_LVDS == 1) {
5033 tempbl = 0;
5034 tempbh = 0;
5035 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02005036 tempah = XGI301LCDDelay;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305037 tempah &= 0x0f;
5038 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005039 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305040 tempah);
5041 }
5042 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005043}
5044
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005045static void XGI_SetLCDCap_A(unsigned short tempcx,
5046 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005047{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305048 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005049
Aaro Koskinen58839b02011-03-13 12:26:23 +02005050 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305052 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005053 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005054 /* Enable Dither */
5055 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005056 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305057 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005058 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305059 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005060 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305061 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005062}
5063
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005064/* --------------------------------------------------------------------- */
5065/* Function : XGI_SetLCDCap_B */
5066/* Input : cx -> LCD Capability */
5067/* Output : */
5068/* Description : */
5069/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005070static void XGI_SetLCDCap_B(unsigned short tempcx,
5071 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005072{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305073 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005074 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305075 (unsigned short) (((tempcx & 0x00ff) >> 6)
5076 | 0x0c));
5077 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005078 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305079 (unsigned short) (((tempcx & 0x00ff) >> 6)
5080 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005081}
5082
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02005083static void XGI_LongWait(struct vb_device_info *pVBInfo)
5084{
5085 unsigned short i;
5086
5087 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5088
5089 if (!(i & 0xC0)) {
5090 for (i = 0; i < 0xFFFF; i++) {
5091 if (!(inb(pVBInfo->P3da) & 0x08))
5092 break;
5093 }
5094
5095 for (i = 0; i < 0xFFFF; i++) {
5096 if ((inb(pVBInfo->P3da) & 0x08))
5097 break;
5098 }
5099 }
5100}
5101
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005102static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005103{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305104 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305106 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005107
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005108 /* disable down spectrum D[4] */
5109 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305110 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005111 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305112 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005113
Aaro Koskinen8104e322011-03-13 12:26:22 +02005114 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305115 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005116 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305117 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005118 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305119 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005120 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305121 pVBInfo->LCDCapList[index].Spectrum_34);
5122 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005123 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005124}
5125
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005126static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5127{
5128 unsigned short tempcx;
5129
5130 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5131
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005132 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005133 (VB_SIS301B |
5134 VB_SIS302B |
5135 VB_SIS301LV |
5136 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005137 VB_XGI301C)) { /* 301LV/302LV only */
5138 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005139 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005140 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005141 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005142 (unsigned char) (tempcx & 0x1F));
5143 }
5144 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005145 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005146 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
5147 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
5148 | EnablePLLSPLOW)) >> 8));
5149 }
5150
Peter Huewe6896b942012-02-09 21:11:46 +01005151 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5152 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005153 if (pVBInfo->VBInfo & SetCRT2ToLCD)
5154 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01005155 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005156 XGI_SetLCDCap_A(tempcx, pVBInfo);
5157
Peter Huewe6896b942012-02-09 21:11:46 +01005158 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005159 if (tempcx & EnableSpectrum)
5160 SetSpectrum(pVBInfo);
5161 }
5162 } else {
5163 /* LVDS,CH7017 */
5164 XGI_SetLCDCap_A(tempcx, pVBInfo);
5165 }
5166}
5167
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005168/* --------------------------------------------------------------------- */
5169/* Function : XGI_SetAntiFlicker */
5170/* Input : */
5171/* Output : */
5172/* Description : Set TV Customized Param. */
5173/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005174static void XGI_SetAntiFlicker(unsigned short ModeNo,
5175 unsigned short ModeIdIndex,
5176 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005177{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03005178 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305180 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005181
Peter Huewe599801f2012-02-09 21:11:45 +01005182 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305183 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005184
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305185 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5186 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305187 tempah = TVAntiFlickList[tempbx];
5188 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005189
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005190 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005191}
5192
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005193static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5194 unsigned short ModeIdIndex,
5195 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005196{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03005197 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305199 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005200
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305201 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5202 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305203 tempah = TVEdgeList[tempbx];
5204 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005205
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005206 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005207}
5208
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005209static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005210{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305211 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305213 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305215 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005216
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305217 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5218 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005219
Aaro Koskinen8104e322011-03-13 12:26:22 +02005220 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305221 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005222 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305223 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005224 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305225 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005226 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305227 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005228}
5229
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005230static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305231 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005232{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305233 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005234
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305235 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305237 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305239 switch (tempbx) {
5240 case 0x00:
5241 case 0x04:
5242 filterPtr = NTSCYFilter1;
5243 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005244
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305245 case 0x01:
5246 filterPtr = PALYFilter1;
5247 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305249 case 0x02:
5250 case 0x05:
5251 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305252 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005253 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305254 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305256 case 0x08:
5257 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305258 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305259 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305260 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005261 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305262 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005263
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305264 default:
5265 return;
5266 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005267
Aaro Koskinenb3979922012-11-04 21:14:52 +02005268 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305269 if (tempcl == 0)
5270 index = tempal * 4;
5271 else
5272 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305274 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005275 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5276 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5277 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5278 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305279 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005280 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5281 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5282 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5283 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305284 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005285
Peter Huewe6896b942012-02-09 21:11:46 +01005286 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5287 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005288 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5289 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5290 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305291 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005292}
5293
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005294/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005295/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005296/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005297/* Output : */
5298/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005299/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005300static void XGI_OEM310Setting(unsigned short ModeNo,
5301 unsigned short ModeIdIndex,
5302 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005303{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005304 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005305
Peter Huewea3d675c2012-02-09 21:11:47 +01005306 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005307 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005308
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005309 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005310 XGI_SetPhaseIncr(pVBInfo);
5311 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5312 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005313
Peter Huewe6896b942012-02-09 21:11:46 +01005314 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005315 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305316 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005317}
5318
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005319/* --------------------------------------------------------------------- */
5320/* Function : XGI_SetCRT2ModeRegs */
5321/* Input : */
5322/* Output : */
5323/* Description : Origin code for crt2group */
5324/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005325static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305326 struct xgi_hw_device_info *HwDeviceExtension,
5327 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005328{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305329 unsigned short tempbl;
5330 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305332 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005333
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305334 tempah = 0;
5335 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005336 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305337 tempah &= ~0x10; /* BTRAMDAC */
5338 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005339
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305340 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5341 | SetCRT2ToLCD)) {
5342 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005343 tempcl = pVBInfo->ModeType;
5344 tempcl -= ModeVGA;
5345 if (tempcl >= 0) {
5346 /* BT Color */
5347 tempah = (0x008 >> tempcl);
5348 if (tempah == 0)
5349 tempah = 1;
5350 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305351 }
5352 if (pVBInfo->VBInfo & SetInSlaveMode)
5353 tempah ^= 0x50; /* BTDAC */
5354 }
5355 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005356
Aaro Koskinen8104e322011-03-13 12:26:22 +02005357 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305358 tempah = 0x08;
5359 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005360
Miguel Gómeze123e462012-07-06 12:40:52 +02005361 if (pVBInfo->VBInfo & DisableCRT2Display)
5362 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005363
Miguel Gómeze123e462012-07-06 12:40:52 +02005364 tempah = 0x00;
5365 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005366
Miguel Gómeze123e462012-07-06 12:40:52 +02005367 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5368 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5369 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005370
Miguel Gómeze123e462012-07-06 12:40:52 +02005371 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5372 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5373 tempbl &= 0xf7;
5374 tempah |= 0x01;
5375 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305376 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005377
Miguel Gómeze123e462012-07-06 12:40:52 +02005378 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5379 tempbl &= 0xf7;
5380 tempah |= 0x01;
5381 }
5382
5383 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5384 goto reg_and_or;
5385
5386 tempbl &= 0xf8;
5387 tempah = 0x01;
5388
5389 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5390 tempah |= 0x02;
5391
5392 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5393 tempah = tempah ^ 0x05;
5394 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5395 tempah = tempah ^ 0x01;
5396 }
5397
5398 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5399 tempah |= 0x08;
5400
5401reg_and_or:
5402 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5403
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305404 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005405 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305406 tempah &= (~0x08);
5407 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5408 & SetInSlaveMode))) {
5409 tempah |= 0x010;
5410 }
5411 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005412
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305413 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305414 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005415 if (pVBInfo->VBInfo & DriverMode)
5416 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305417 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005418
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005419 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305420 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005421
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305422 if (pVBInfo->LCDInfo & SetLCDDualLink)
5423 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005424
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305425 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305426 if (pVBInfo->TVInfo & RPLLDIV2XO)
5427 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305428 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005429
Peter Huewe255aabd2012-02-09 21:11:44 +01005430 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5431 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305432 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005433
Peter Huewe255aabd2012-02-09 21:11:44 +01005434 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305435 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005436
Aaro Koskinen8104e322011-03-13 12:26:22 +02005437 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005439
Peter Huewe6896b942012-02-09 21:11:46 +01005440 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5441 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305442 tempah = 0;
5443 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005444
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305445 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5446 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005447 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305448 tempah |= 0x04; /* shampoo 0129 */
5449 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005450
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005451 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305452 tempah = 0x00;
5453 tempbl = 0xcf;
5454 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5455 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5456 tempah |= 0x30;
5457 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005458
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005459 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305460 tempah = 0;
5461 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005462
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305463 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5464 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5465 tempah |= 0xc0;
5466 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005467 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305468 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005469
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305470 tempah = 0;
5471 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005472 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305473 tempbl = 0xff;
5474 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5475 tempah |= 0x80;
5476 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005477
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005478 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005479
Peter Huewe6896b942012-02-09 21:11:46 +01005480 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305481 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005482 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5483 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305484 }
5485 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005486}
5487
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005488
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305489void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5490 struct vb_device_info *pVBInfo)
5491{
5492
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005493 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005494
5495}
5496
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305497void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5498 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005499{
5500
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005501 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005502
5503}
5504
Bill Pemberton80adad82010-06-17 13:10:51 -04005505unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005506{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305507 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005508
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305509 if (pVBInfo->IF_DEF_LVDS == 1) {
5510 return 1;
5511 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005512 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305513 if ((flag == 1) || (flag == 2))
5514 return 1; /* 301b */
5515 else
5516 return 0;
5517 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005518}
5519
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005520unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5521 unsigned short ModeNo, unsigned short ModeIdIndex,
5522 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005523{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005524 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
5525 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
5526 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005527
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005528 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005529
Aaro Koskinenb3979922012-11-04 21:14:52 +02005530 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005531
Aaro Koskinen58839b02011-03-13 12:26:23 +02005532 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005533 index = index >> pVBInfo->SelectCRT2Rate;
5534 index &= 0x0F;
5535
5536 if (pVBInfo->LCDInfo & LCDNonExpanding)
5537 index = 0;
5538
5539 if (index > 0)
5540 index--;
5541
5542 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005543 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005544 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01005545 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
5546 | VB_SIS301LV | VB_SIS302LV
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005547 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005548 /* 301b */
5549 temp = LCDARefreshIndex[
5550 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005551 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005552 temp = LCDRefreshIndex[
5553 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005554
5555 if (index > temp)
5556 index = temp;
5557 } else {
5558 index = 0;
5559 }
5560 }
5561 }
5562
Aaro Koskinenb3979922012-11-04 21:14:52 +02005563 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005564 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005565 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005566 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5567 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005568 index++;
5569 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005570 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005571 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5572 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005573 index++;
5574 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005575 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5576 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005577 index++;
5578 }
5579 }
5580
5581 i = 0;
5582 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005583 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005584 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005585 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005586 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005587 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005588 if (temp < pVBInfo->ModeType)
5589 break;
5590 i++;
5591 index--;
5592
5593 } while (index != 0xFFFF);
5594 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5595 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005596 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005597 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005598 if (temp & InterlaceMode)
5599 i++;
5600 }
5601 }
5602 i--;
5603 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5604 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5605 RefreshRateTableIndex, &i, pVBInfo);
5606 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005607 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005608}
5609
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005610static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305611 struct xgi_hw_device_info *HwDeviceExtension,
5612 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005613{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005614 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005615
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005616 pVBInfo->SetFlag |= ProgrammingCRT2;
5617 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5618 ModeIdIndex, pVBInfo);
5619 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5620 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5621 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5622 HwDeviceExtension, pVBInfo);
5623 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5624 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005625}
5626
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005627static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005628 struct xgi_hw_device_info *HwDeviceExtension,
5629 struct vb_device_info *pVBInfo)
5630{
5631 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
5632
5633 tempbx = pVBInfo->VBInfo;
5634 pVBInfo->SetFlag |= ProgrammingCRT2;
5635 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5636 pVBInfo->SelectCRT2Rate = 4;
5637 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5638 ModeIdIndex, pVBInfo);
5639 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5640 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5641 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5642 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5643 RefreshRateTableIndex, pVBInfo);
5644 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5645 RefreshRateTableIndex, pVBInfo);
5646 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5647 RefreshRateTableIndex, pVBInfo);
5648 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5649 HwDeviceExtension, pVBInfo);
5650 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5651 RefreshRateTableIndex, pVBInfo);
5652 XGI_SetTap4Regs(pVBInfo);
5653 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5654 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5655 HwDeviceExtension, pVBInfo);
5656 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5657 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5658 XGI_AutoThreshold(pVBInfo);
5659 return 1;
5660}
5661
5662void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5663{
5664 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5665 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5666 0x05, 0x00 };
5667
5668 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5669
5670 unsigned char CR17, CR63, SR31;
5671 unsigned short temp;
5672 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
5673
5674 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005675 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005676
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005677 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005678 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005679 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005680 pVBInfo->P3d4, 0x53) | 0x02));
5681
Aaro Koskinen58839b02011-03-13 12:26:23 +02005682 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
5683 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
5684 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005685
Aaro Koskinen8104e322011-03-13 12:26:22 +02005686 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5687 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005688
Aaro Koskinen58839b02011-03-13 12:26:23 +02005689 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005690 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005691
Aaro Koskinen58839b02011-03-13 12:26:23 +02005692 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005693 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005694
Aaro Koskinen58839b02011-03-13 12:26:23 +02005695 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005696 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02005697 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005698 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005699
Aaro Koskinen8104e322011-03-13 12:26:22 +02005700 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005701
5702 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005703 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005704
5705 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005706 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005707 CRTCData[i]);
5708
5709 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005710 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005711 CRTCData[i]);
5712
5713 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005714 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005715 CRTCData[i]);
5716
Aaro Koskinen8104e322011-03-13 12:26:22 +02005717 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005718 & 0xE0));
5719
Aaro Koskinen8104e322011-03-13 12:26:22 +02005720 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5721 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5722 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005723
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005724 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005725
5726 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005727 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
5728 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
5729 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005730 }
5731
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005732 mdelay(1);
5733
5734 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005735 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005736
5737 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005738 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005739 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005740 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005741
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005742 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005743 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005744
5745 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005746 outb(0, (pVBInfo->P3c8 + 1));
5747 outb(0, (pVBInfo->P3c8 + 1));
5748 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005749 }
5750
Aaro Koskinen8104e322011-03-13 12:26:22 +02005751 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5752 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5753 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005754
Aaro Koskinen58839b02011-03-13 12:26:23 +02005755 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005756 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005757 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005758}
5759
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005760static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5761 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005762 struct vb_device_info *pVBInfo)
5763{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005764 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005765
Peter Huewe6896b942012-02-09 21:11:46 +01005766 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5767 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005768 if (!(pVBInfo->SetFlag & DisableChA)) {
5769 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005770 /* Power on */
5771 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03005772 } else if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5773 /* Power on */
5774 xgifb_reg_set(pVBInfo->Part1Port,
5775 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005776 }
5777 }
5778
5779 if (!(pVBInfo->SetFlag & DisableChB)) {
5780 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5781 & (SetCRT2ToLCD | SetCRT2ToTV
5782 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005783 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005784 pVBInfo->P3c4, 0x32);
5785 tempah &= 0xDF;
5786 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005787 if (!(pVBInfo->VBInfo &
5788 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005789 tempah |= 0x20;
5790 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005791 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005792 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005793
Aaro Koskinen58839b02011-03-13 12:26:23 +02005794 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005795 pVBInfo->Part1Port, 0x2E);
5796
5797 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005798 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005799 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005800 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005801 }
5802 }
5803
5804 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
5805 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005806 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005807 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005808 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005809 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005810 if (XGI_EnableChISLCD(pVBInfo) ||
5811 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01005812 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005813 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02005814 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005815 pVBInfo->Part4Port,
5816 0x2A,
5817 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005818 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005819 /* LVDS Driver power on */
5820 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005821 }
5822 }
5823
5824 tempah = 0x00;
5825
5826 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5827 tempah = 0xc0;
5828
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005829 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5830 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5831 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5832 tempah = tempah & 0x40;
5833 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5834 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005835
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005836 if (pVBInfo->SetFlag & DisableChB)
5837 tempah &= 0xBF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005838
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005839 if (pVBInfo->SetFlag & DisableChA)
5840 tempah &= 0x7F;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005841
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005842 if (pVBInfo->SetFlag & EnableChB)
5843 tempah |= 0x40;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005844
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005845 if (pVBInfo->SetFlag & EnableChA)
5846 tempah |= 0x80;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005847 }
5848 }
5849
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005850 /* EnablePart4_1F */
5851 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005852
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005853 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005854 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005855 XGI_DisableGatingCRT(HwDeviceExtension,
5856 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005857 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
5858 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005859 }
5860 }
5861 } /* 301 */
5862 else { /* LVDS */
5863 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005864 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005865 /* enable CRT2 */
5866 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005867
Aaro Koskinen58839b02011-03-13 12:26:23 +02005868 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005869 0x2E);
5870 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005871 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005872
Aaro Koskinendc505562011-03-13 12:26:26 +02005873 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005874 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005875 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005876}
5877
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005878static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5879 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005880 unsigned short ModeNo, unsigned short ModeIdIndex,
5881 struct vb_device_info *pVBInfo)
5882{
Aaro Koskinena1579612012-04-07 01:14:05 +03005883 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005884
Aaro Koskinena1579612012-04-07 01:14:05 +03005885 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005886 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005887 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5888 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5889 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005890 XGI_ClearExt1Regs(pVBInfo);
5891
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005892 if (HwDeviceExtension->jChipType == XG27) {
5893 if (pVBInfo->IF_DEF_LVDS == 0)
5894 XGI_SetDefaultVCLK(pVBInfo);
5895 }
5896
5897 temp = ~ProgrammingCRT2;
5898 pVBInfo->SetFlag &= temp;
5899 pVBInfo->SelectCRT2Rate = 0;
5900
Peter Huewe6896b942012-02-09 21:11:46 +01005901 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5902 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005903 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005904 | SetInSlaveMode)) {
5905 pVBInfo->SetFlag |= ProgrammingCRT2;
5906 }
5907 }
5908
5909 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5910 ModeIdIndex, pVBInfo);
5911 if (RefreshRateTableIndex != 0xFFFF) {
5912 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5913 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5914 pVBInfo, HwDeviceExtension);
5915 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5916 RefreshRateTableIndex, pVBInfo);
5917 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5918 HwDeviceExtension, pVBInfo);
5919 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5920 RefreshRateTableIndex, pVBInfo);
5921 }
5922
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005923 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005924 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005925 if (temp & 0xA0) {
5926
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005927 if (HwDeviceExtension->jChipType == XG27)
5928 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5929 RefreshRateTableIndex, pVBInfo);
5930 else
5931 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5932 RefreshRateTableIndex, pVBInfo);
5933
5934 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5935 RefreshRateTableIndex);
5936
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005937 xgifb_set_lcd(HwDeviceExtension->jChipType,
5938 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005939
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005940 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005941 xgifb_set_lvds(xgifb_info,
5942 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005943 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005944 }
5945 }
5946
5947 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5948 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5949 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5950 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005951 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005952}
5953
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005954unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5955 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005956 unsigned short ModeNo)
5957{
5958 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005959 struct vb_device_info VBINF;
5960 struct vb_device_info *pVBInfo = &VBINF;
Dmitry Eremin-Solenikov9a801f22012-03-19 21:50:13 +04005961 pVBInfo->BaseAddr = xgifb_info->vga_base;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005962 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005963
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005964 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005965 pVBInfo->IF_DEF_YPbPr = 0;
5966 pVBInfo->IF_DEF_HiVision = 0;
5967 pVBInfo->IF_DEF_CRT2Monitor = 0;
5968 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005969 } else {
5970 pVBInfo->IF_DEF_YPbPr = 1;
5971 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005972 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005973 }
5974
5975 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
5976 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
5977 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
5978 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
5979 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
5980 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
5981 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
5982 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
5983 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
5984 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
5985 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
5986 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
5987 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
Peter Huewe6896b942012-02-09 21:11:46 +01005988 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
5989 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
5990 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
5991 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
5992 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005993
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005994 /* for x86 Linux, XG21 LVDS */
5995 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005996 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005997 pVBInfo->IF_DEF_LVDS = 1;
5998 }
5999 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006000 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
6001 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006002 pVBInfo->IF_DEF_LVDS = 1;
6003 }
6004 }
6005
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006006 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006007 XGI_GetVBType(pVBInfo);
6008
6009 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02006010 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006011 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006012 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006013
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006014 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006015 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
6016
6017 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6018
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006019 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006020 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
6021 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
6022 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006023 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006024
Peter Huewea3d675c2012-02-09 21:11:47 +01006025 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006026 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006027 ModeIdIndex, pVBInfo);
6028
Peter Huewea3d675c2012-02-09 21:11:47 +01006029 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006030 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6031 HwDeviceExtension, pVBInfo);
6032 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03006033 } else if (!(pVBInfo->VBInfo & SwitchCRT2)) {
6034 XGI_SetCRT1Group(xgifb_info,
6035 HwDeviceExtension, ModeNo,
6036 ModeIdIndex, pVBInfo);
6037 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
6038 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6039 HwDeviceExtension,
6040 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006041 }
6042 }
6043
Peter Huewe6896b942012-02-09 21:11:46 +01006044 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006045 switch (HwDeviceExtension->ujVBChipID) {
6046 case VB_CHIP_301:
6047 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6048 pVBInfo); /*add for CRT2 */
6049 break;
6050
6051 case VB_CHIP_302:
6052 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6053 pVBInfo); /*add for CRT2 */
6054 break;
6055
6056 default:
6057 break;
6058 }
6059 }
6060
6061 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
6062 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006063 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006064 } /* !XG20 */
6065 else {
6066 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006067 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006068 ModeIdIndex,
6069 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006070 return 0;
6071
Aaro Koskinenb3979922012-11-04 21:14:52 +02006072 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01006073 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006074
6075 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03006076 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006077
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006078 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006079
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006080 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6081 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006082
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006083 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006084 }
6085
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006086 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
6087
Miguel Gómez3bcc2462012-07-06 12:40:53 +02006088 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006089 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006090
6091 return 1;
6092}