blob: 7ee42ac8e3ab171f1bdfbb8e350e57acef3b0fea [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;
27 pVBInfo->ECLKData = XGI340_ECLKData;
28 pVBInfo->VCLKData = XGI_VCLKData;
Aaro Koskinene8cb03d2012-09-11 00:15:31 +030029 pVBInfo->VBVCLKData = XGI_VBVCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053030 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030031 pVBInfo->StResInfo = XGI330_StResInfo;
32 pVBInfo->ModeResInfo = XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053034 pVBInfo->LCDResInfo = 0;
35 pVBInfo->LCDTypeInfo = 0;
36 pVBInfo->LCDInfo = 0;
37 pVBInfo->VBInfo = 0;
38 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053040 pVBInfo->SR15 = XGI340_SR13;
41 pVBInfo->CR40 = XGI340_cr41;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053042 pVBInfo->CR6B = XGI340_CR6B;
43 pVBInfo->CR6E = XGI340_CR6E;
44 pVBInfo->CR6F = XGI340_CR6F;
45 pVBInfo->CR89 = XGI340_CR89;
46 pVBInfo->AGPReg = XGI340_AGPReg;
47 pVBInfo->SR16 = XGI340_SR16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020048
Peter Huewe6d12dae2012-06-14 00:21:52 +020049 pVBInfo->SR21 = 0xa3;
50 pVBInfo->SR22 = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020051
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030052 pVBInfo->UpdateCRT1 = XGI_UpdateCRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053054 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010055 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053056 pVBInfo->LCDCapList = XGI_LCDDLCapList;
57 else
58 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020059
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053060 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020061 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020062
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053063 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040064 unsigned char temp;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030065 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053066 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020067 pVBInfo->XGINew_CR97 = 0xc1;
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040068 pVBInfo->SR15 = XG27_SR13;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020069
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040070 /*Z11m DDR*/
71 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
72 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
73 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020074 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053075 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020076
77}
78
Kenji Toyama1d7f6562011-04-23 19:36:49 +080079static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080080 unsigned short ModeIdIndex,
81 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020082{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053083 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053084 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020085
Aaro Koskinenb3979922012-11-04 21:14:52 +020086 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020087
Aaro Koskinen8104e322011-03-13 12:26:22 +020088 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020089 tempah = XGI330_StandTable.SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020090
Peter Huewea3d675c2012-02-09 21:11:47 +010091 i = XGI_SetCRT2ToLCDA;
92 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053093 tempah |= 0x01;
Aaro Koskinend3ae5762012-09-11 00:15:27 +030094 } else if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
95 if (pVBInfo->VBInfo & SetInSlaveMode)
96 tempah |= 0x01;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053097 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053099 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200100 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530102 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800103 /* Get SR2,3,4 from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200104 SRdata = XGI330_StandTable.SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200105 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530106 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200107}
108
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200109static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800110 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200111{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530112 unsigned char CRTCdata;
113 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200114
Aaro Koskinen58839b02011-03-13 12:26:23 +0200115 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530116 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200117 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200118
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530119 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800120 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200121 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200122 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530123 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200124}
125
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800126static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800127 unsigned short ModeIdIndex,
128 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200129{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530130 unsigned char ARdata;
131 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200132
Aaro Koskinenb3979922012-11-04 21:14:52 +0200133 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530135 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200136 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200137
138 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
139 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
140 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300141 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200142 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300143 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530144 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530145 }
146 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200147
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200148 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200149 outb(i, pVBInfo->P3c0); /* set index */
150 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530151 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200152
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200153 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200154 outb(0x14, pVBInfo->P3c0); /* set index */
155 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200156 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200157 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200158}
159
Aaro Koskinena1579612012-04-07 01:14:05 +0300160static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200161{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530162 unsigned char GRdata;
163 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530165 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800166 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200167 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200168 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530169 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200170
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530171 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200172 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530173 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200174 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530175 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200176}
177
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200178static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200179{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530180 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200181
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530182 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200183 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200184}
185
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200186static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200187{
188
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200189 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200190 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
191 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200192
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200193 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200194 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
195 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200196
Aaro Koskinendc505562011-03-13 12:26:26 +0200197 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530198 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200199}
200
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200201static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530202 unsigned short ModeIdIndex,
203 unsigned short RefreshRateTableIndex, unsigned short *i,
204 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200205{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530206 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200207
Aaro Koskinenb3979922012-11-04 21:14:52 +0200208 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
209 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200210 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530211 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530213 if (pVBInfo->IF_DEF_LVDS == 0) {
214 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
215 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200216
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530217 if (pVBInfo->VBType & VB_XGI301C)
218 tempax |= SupportCRT2in301C;
219 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200220
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800221 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100222 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530223 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200224
Miguel Gómez3b175622012-07-06 12:40:46 +0200225 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
226 pVBInfo->LCDResInfo != Panel_1280x960 &&
227 (pVBInfo->LCDInfo & LCDNonExpanding) &&
228 resinfo >= 9)
229 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530230 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200231
Peter Huewe599801f2012-02-09 21:11:45 +0100232 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300233 tempax |= SupportHiVision;
234 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
235 ((resinfo == 4) ||
236 (resinfo == 3 &&
237 (pVBInfo->SetFlag & TVSimuMode)) ||
238 (resinfo > 7)))
Miguel Gómez3b175622012-07-06 12:40:46 +0200239 return 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300240 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800241 SetCRT2ToSVIDEO |
242 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100243 SetCRT2ToYPbPr525750 |
244 SetCRT2ToHiVision)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300245 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200246
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300247 if (pVBInfo->VBType & (VB_SIS301B |
248 VB_SIS302B |
249 VB_SIS301LV |
250 VB_SIS302LV |
251 VB_XGI301C))
252 tempax |= SupportTV1024;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200253
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300254 if (!(pVBInfo->VBInfo & TVSetPAL) &&
255 (modeflag & NoSupportSimuTV) &&
256 (pVBInfo->VBInfo & SetInSlaveMode) &&
257 (!(pVBInfo->VBInfo & SetNotSimuMode)))
258 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530259 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300260 } else if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* for LVDS */
261 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200262
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300263 if (resinfo > 0x08)
264 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200265
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300266 if (pVBInfo->LCDResInfo < Panel_1024x768) {
267 if (resinfo > 0x07)
268 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200269
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300270 if (resinfo == 0x04)
271 return 0; /* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530272 }
273 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200274
Aaro Koskinena39325d2012-11-04 21:14:53 +0200275 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800276 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200277 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800278 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530279 if (infoflag & tempax)
280 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200281
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530282 if ((*i) == 0)
283 break;
284 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200285
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530286 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200287 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800288 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200289 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530290 != tempbx) {
291 return 0;
292 }
293
294 if (infoflag & tempax)
295 return 1;
296 }
297 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200298}
299
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200300static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530301 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200302{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530303 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200304
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800305 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200306 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530307 sync &= 0xC0;
308 temp = 0x2F;
309 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200310 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200311}
312
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200313static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530314 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200315{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530316 unsigned char data, data1, pushax;
317 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200318
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800319 /* unlock cr0-7 */
320 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530321 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200322 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200323
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200324 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200325 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200326
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530327 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200328 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200329 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530330 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530332 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200333 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200334 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530335 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200336
Aaro Koskinen58839b02011-03-13 12:26:23 +0200337 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530338 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200339 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530340 data &= 0xE0;
341 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200342 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530344 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200345 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530346 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200347 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200348 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530349 data1 = data;
350 data1 &= 0xE0;
351 data &= 0x1F;
352 if (data == 0) {
353 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200354 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530355 0x0c);
356 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200357 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530358 data = pushax;
359 }
360 data = data - 1;
361 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200362 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200363 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530364 data = data >> 5;
365 data = data + 3;
366 if (data > 7)
367 data = data - 7;
368 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200369 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530370 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200371}
372
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800373static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
374 unsigned short ModeNo,
375 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200376{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530377 unsigned char data;
378 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530380 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200381 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200382 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530383 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200384
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530385 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200386 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200387 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530388 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200389
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530390 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200391 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200392 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530393 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200394
Aaro Koskinen58839b02011-03-13 12:26:23 +0200395 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530396 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200397 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530398 data &= 0x3F;
399 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200400 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200401
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200402 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530403 data &= 0x80;
404 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200405
Aaro Koskinenb3979922012-11-04 21:14:52 +0200406 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530407 i &= DoubleScanMode;
408 if (i)
409 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200410
Aaro Koskinen58839b02011-03-13 12:26:23 +0200411 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530412 j &= 0x5F;
413 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200414 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200415}
416
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200417static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
418 unsigned short RefreshRateTableIndex,
419 struct vb_device_info *pVBInfo,
420 struct xgi_hw_device_info *HwDeviceExtension)
421{
422 unsigned char index, data;
423 unsigned short i;
424
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800425 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200426 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200427 index = index & IndexMask;
428
Aaro Koskinen58839b02011-03-13 12:26:23 +0200429 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200430 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200431 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200432
433 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200434 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200435 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200436
437 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200438 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200439 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200440
441 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
442
443 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
444
445 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200446 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200447}
448
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200449/* --------------------------------------------------------------------- */
450/* Function : XGI_SetXG21CRTC */
451/* Input : Stand or enhance CRTC table */
452/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
453/* Description : Set LCD timing */
454/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200455static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530456 unsigned short RefreshRateTableIndex,
457 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200458{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300459 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530460 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200461
Aaro Koskinena39325d2012-11-04 21:14:53 +0200462 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300463 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200464 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300465 Tempcx = Tempax; /* Tempcx: HRS */
466 /* SR2E[7:0]->HRS */
467 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200468
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200469 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300470 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
471 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
472 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
473 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800474
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200475 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300476 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200477
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200478 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300479 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
480 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
481 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200482
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300483 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
484 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200485
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300486 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
487 if (Tempax < Tempcx) /* HRE < HRS */
488 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200489
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300490 Temp2 &= 0xFF;
491 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
492 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
493 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
494 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
495 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
496 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
497 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200498
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300499 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200500 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300501 Tempbx = Tempax; /* Tempbx: VRS */
502 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
503 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
504 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200505 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300506 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
507 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
508 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
509 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
510 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200511
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300512 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
513 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
514 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
515 Tempax &= 0x80;
516 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
517 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
518 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200519 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300520 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
521 Temp2 = Tempax;
522 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
523 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200524
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300525 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200526 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300527 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
528 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200529 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300530 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
531 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
532 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
533 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
534 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200535
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300536 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
537 if (Tempax < Temp3) /* VRE < VRS */
538 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200539
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300540 Temp2 &= 0xFF;
541 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
542 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
543 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
544 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
545 Tempbx = (unsigned char) Temp1;
546 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
547 Tempax &= 0x7F;
548 /* SR3F D[7:2]->VRE D[1:0]->VRS */
549 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200550}
551
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800552static void XGI_SetXG27CRTC(unsigned short ModeNo,
553 unsigned short ModeIdIndex,
554 unsigned short RefreshRateTableIndex,
555 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200556{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300557 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200558
Aaro Koskinena39325d2012-11-04 21:14:53 +0200559 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300560 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200561 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300562 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
563 /* SR2E[7:0]->HRS */
564 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200565
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300566 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200567 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300568 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
569 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200570
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200571 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300572 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
573 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200574
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200575 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300576 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
577 Tempax <<= 3; /* Tempax[5]: HRE[5] */
578 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200579
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300580 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
581 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200582
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300583 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200584 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300585 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
586 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
587 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200588
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200589 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300590 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
591 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
592 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
593 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
594 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
595 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200596
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300597 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200598 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300599 /* SR34[7:0]->VRS[7:0] */
600 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200601
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300602 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
603 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200604 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300605 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
606 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
607 Tempax >>= 2; /* Tempax[0]: VRS[8] */
608 /* SR35[0]: VRS[8] */
609 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
610 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
611 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
612 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200613 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300614 Tempax &= 0x08; /* SR0A[3] VRS[10] */
615 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200616
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300617 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200618 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300619 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
620 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200621 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300622 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
623 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
624 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
625 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
626 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
627 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200628
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300629 if (Tempbx <= Tempcx) /* VRE <= VRS */
630 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200631
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300632 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
633 Tempax = (Tempbx << 2) & 0xFF;
634 /* SR3F[7:2]:VRE[5:0] */
635 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
636 Tempax = Tempcx >> 8;
637 /* SR35[2:0]:VRS[10:8] */
638 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200639}
640
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200641static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
642{
643 unsigned char temp;
644
645 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
646 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
647 temp = (temp & 3) << 6;
648 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
649 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
650 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
651 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
652
653}
654
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300655static void xgifb_set_lcd(int chip_id,
656 struct vb_device_info *pVBInfo,
657 unsigned short RefreshRateTableIndex,
658 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200659{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300660 unsigned short Data, Temp;
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400661 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200662
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530663 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200664
Aaro Koskinen8104e322011-03-13 12:26:22 +0200665 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
666 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
667 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
668 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300669
670 if (chip_id == XG27) {
671 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
672 if ((Temp & 0x03) == 0) { /* dual 12 */
673 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
674 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
675 }
676 }
677
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300678 if (chip_id == XG27) {
679 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530680 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300681 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
682 if (Temp & 0x01) {
683 /* 18 bits FP */
684 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
685 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
686 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530687 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200688
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200689 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200690
Aaro Koskinendc505562011-03-13 12:26:26 +0200691 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
692 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200693
Aaro Koskinena39325d2012-11-04 21:14:53 +0200694 Data = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300695 if (Data & 0x4000)
696 /* Hsync polarity */
697 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
698 if (Data & 0x8000)
699 /* Vsync polarity */
700 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200701}
702
703/* --------------------------------------------------------------------- */
704/* Function : XGI_UpdateXG21CRTC */
705/* Input : */
706/* Output : CRT1 CRTC */
707/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
708/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800709static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
710 struct vb_device_info *pVBInfo,
711 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200712{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300713 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200714
Aaro Koskinendc505562011-03-13 12:26:26 +0200715 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300716 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200717 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300718 RES640x480x60))
719 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200720 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800721 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300722 index = 13;
723 else if (ModeNo == 0x2F)
724 index = 14;
725 else if (ModeNo == 0x50)
726 index = 15;
727 else if (ModeNo == 0x59)
728 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200729
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530730 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200731 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530732 pVBInfo->UpdateCRT1[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200733 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530734 pVBInfo->UpdateCRT1[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200735 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530736 pVBInfo->UpdateCRT1[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200737 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530738 pVBInfo->UpdateCRT1[index].CR16);
739 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200740}
741
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200742static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530743 unsigned short ModeNo, unsigned short ModeIdIndex,
744 unsigned short RefreshRateTableIndex,
745 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200746{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400747 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200748
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530749 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200750
Aaro Koskinenb3979922012-11-04 21:14:52 +0200751 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200752
Aaro Koskinenb3979922012-11-04 21:14:52 +0200753 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300754 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
755 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200756
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530757 if (modeflag & HalfDCLK)
758 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200759
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300760 if (modeflag & HalfDCLK)
761 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200762
Aaro Koskinena39325d2012-11-04 21:14:53 +0200763 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200764
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300765 if (temp & InterlaceMode)
766 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200767
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300768 if (modeflag & DoubleScanMode)
769 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200770
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530771 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200772
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530773 tempax /= tempcx;
774 tempax -= 1;
775 tempbx -= 1;
776 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200777 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
778 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530779 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200780 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
781 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200782 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530783 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200784 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530785 tempax = 0;
786 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200787
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530788 if (tempbx & 0x01)
789 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200790
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530791 if (tempbx & 0x02)
792 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200793
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200794 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200795 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530796 data &= 0xFF;
797 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200798
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530799 if (tempbx & 0x04)
800 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200801
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200802 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200803 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200804}
805
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800806static void XGI_SetCRT1Offset(unsigned short ModeNo,
807 unsigned short ModeIdIndex,
808 unsigned short RefreshRateTableIndex,
809 struct xgi_hw_device_info *HwDeviceExtension,
810 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200811{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530812 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530814 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200815 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530816 temp = temp >> 8;
817 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200818
Aaro Koskinena39325d2012-11-04 21:14:53 +0200819 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530820 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530822 if (temp2)
823 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200824
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530825 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200826
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530827 switch (temp2) {
828 case 0:
829 temp2 = 1;
830 break;
831 case 1:
832 temp2 = 2;
833 break;
834 case 2:
835 temp2 = 4;
836 break;
837 case 3:
838 temp2 = 4;
839 break;
840 case 4:
841 temp2 = 6;
842 break;
843 case 5:
844 temp2 = 8;
845 break;
846 default:
847 break;
848 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200849
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530850 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
851 temp = temp * temp2 + temp2 / 2;
852 else
853 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200854
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530855 /* SetOffset */
856 DisplayUnit = temp;
857 temp2 = temp;
858 temp = temp >> 8; /* ah */
859 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200860 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530861 i &= 0xF0;
862 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200863 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200864
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530865 temp = (unsigned char) temp2;
866 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200867 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200868
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530869 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200870 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530871 temp2 &= InterlaceMode;
872 if (temp2)
873 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530875 DisplayUnit = DisplayUnit << 5;
876 ah = (DisplayUnit & 0xff00) >> 8;
877 al = DisplayUnit & 0x00ff;
878 if (al == 0)
879 ah += 1;
880 else
881 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200882
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530883 if (HwDeviceExtension->jChipType >= XG20)
884 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
885 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200886
Aaro Koskinen8104e322011-03-13 12:26:22 +0200887 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200888}
889
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200890static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
891 unsigned short ModeIdIndex,
892 unsigned short RefreshRateTableIndex,
893 struct xgi_hw_device_info *HwDeviceExtension,
894 struct vb_device_info *pVBInfo)
895{
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200896 unsigned short CRT2Index, VCLKIndex;
897 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200898
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300899 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200900 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
901 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200902 CRT2Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200903
904 if (pVBInfo->IF_DEF_LVDS == 0) {
905 CRT2Index = CRT2Index >> 6; /* for LCD */
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200906 if (pVBInfo->VBInfo &
907 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
Peter Huewe255aabd2012-02-09 21:11:44 +0100908 if (pVBInfo->LCDResInfo != Panel_1024x768)
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200909 /* LCDXlat2VCLK */
910 VCLKIndex = VCLK108_2_315 + 5;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200911 else
Peter Huewef477d3e2012-06-14 00:21:47 +0200912 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
Peter Huewe599801f2012-02-09 21:11:45 +0100913 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200914 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200915 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200916 else
Peter Huewe95072592012-06-14 00:21:48 +0200917 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200918
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200919 if (pVBInfo->SetFlag & TVSimuMode) {
920 if (modeflag & Charx8Dot) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200921 VCLKIndex = TVCLKBASE_315_25 +
922 HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200923 } else {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200924 VCLKIndex = TVCLKBASE_315_25 +
925 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200926 }
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200927 }
928
929 /* 301lv */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300930 if (pVBInfo->VBType & VB_SIS301LV) {
931 if (pVBInfo->SetFlag & RPLLDIV2XO)
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200932 VCLKIndex = YPbPr525iVCLK_2;
933 else
934 VCLKIndex = YPbPr525iVCLK;
935 }
936 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200937 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200938 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200939 else
Peter Huewe95072592012-06-14 00:21:48 +0200940 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200941 } else { /* for CRT2 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300942 /* di+Ext_CRTVCLK */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200943 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800944 Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300945 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200946 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300947 } else if ((pVBInfo->LCDResInfo == Panel_800x600) ||
948 (pVBInfo->LCDResInfo == Panel_320x480)) { /* LVDS */
949 VCLKIndex = VCLK40; /* LVDSXlat1VCLK */
950 } else {
951 VCLKIndex = VCLK65_315 + 2; /* LVDSXlat2VCLK, LVDSXlat3VCLK */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200952 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200953
954 return VCLKIndex;
955}
956
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800957static void XGI_SetCRT1VCLK(unsigned short ModeNo,
958 unsigned short ModeIdIndex,
959 struct xgi_hw_device_info *HwDeviceExtension,
960 unsigned short RefreshRateTableIndex,
961 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200962{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400963 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530964 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530966 if (pVBInfo->IF_DEF_LVDS == 1) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200967 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200968 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200969 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
970 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530971 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200972 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530973 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200974 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +0100975 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
976 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +0100977 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530978 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
979 RefreshRateTableIndex, HwDeviceExtension,
980 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200981 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200982 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530983 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200984 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530985 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200986 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
987 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530988 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200989 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200990 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200991 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
992 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530993 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200994 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530995 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200996 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530997 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200998
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530999 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02001000 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001001 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001002 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001003 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001004 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301005 index = data;
1006 index &= 0xE0;
1007 data &= 0x1F;
1008 data = data << 1;
1009 data += 1;
1010 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001011 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301012 }
1013 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001014}
1015
Aaro Koskinene85f2032011-11-27 23:03:07 +02001016static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1017{
1018 unsigned char temp;
1019
1020 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1021 temp = (temp & 1) << 6;
1022 /* SR06[6] 18bit Dither */
1023 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1024 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1025 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1026
1027}
1028
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001029static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301030 struct xgi_hw_device_info *HwDeviceExtension,
1031 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001032{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301033 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001034
Aaro Koskinen58839b02011-03-13 12:26:23 +02001035 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301036 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001037 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001038
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001039 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1040 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1041 data &= 0xC0;
1042 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1043 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1044 data |= 0x01;
1045 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301047 if (HwDeviceExtension->jChipType == XG21)
1048 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001049}
1050
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001051static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1052 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1053 struct vb_device_info *pVBInfo)
1054{
1055 unsigned short data, data2 = 0;
1056 short VCLK;
1057
1058 unsigned char index;
1059
Aaro Koskinena39325d2012-11-04 21:14:53 +02001060 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001061 index &= IndexMask;
1062 VCLK = pVBInfo->VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001063
Aaro Koskinen58839b02011-03-13 12:26:23 +02001064 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001065 data &= 0xf3;
1066 if (VCLK >= 200)
1067 data |= 0x0c; /* VCLK > 200 */
1068
1069 if (HwDeviceExtension->jChipType >= XG20)
1070 data &= ~0x04; /* 2 pixel mode */
1071
Aaro Koskinen8104e322011-03-13 12:26:22 +02001072 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001073
1074 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001075 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001076 data &= 0xE7;
1077 if (VCLK < 200)
1078 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001079 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001080 }
1081
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001082 data2 = 0x00;
1083
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001084 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001085 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001086 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001087
1088}
1089
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001090static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301091 unsigned short ModeNo, unsigned short ModeIdIndex,
1092 unsigned short RefreshRateTableIndex,
1093 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001094{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301095 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1096 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001097
Aaro Koskinenb3979922012-11-04 21:14:52 +02001098 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001099 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001100
Aaro Koskinen58839b02011-03-13 12:26:23 +02001101 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001102 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001103
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001104 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301105 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001106 data2 |= 0x02;
1107 data3 = pVBInfo->ModeType - ModeVGA;
1108 data3 = data3 << 2;
1109 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301110 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301112 if (data)
1113 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001114
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001115 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001116 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001117 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001118
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301119 data = 0x0000;
1120 if (infoflag & InterlaceMode) {
1121 if (xres == 1024)
1122 data = 0x0035;
1123 else if (xres == 1280)
1124 data = 0x0048;
1125 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301127 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001128 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301129 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001130 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301132 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001133 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301135 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301137 if (modeflag & LineCompareOff)
1138 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001139
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001140 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301141 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001142 data = data ^ 0x60;
1143 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001144 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301146 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1147 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001148
Aaro Koskinen58839b02011-03-13 12:26:23 +02001149 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301151 if (HwDeviceExtension->jChipType == XG27) {
1152 if (data & 0x40)
1153 data = 0x2c;
1154 else
1155 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001156 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001157 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301158 } else if (HwDeviceExtension->jChipType >= XG20) {
1159 if (data & 0x40)
1160 data = 0x33;
1161 else
1162 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001163 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1164 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301165 } else {
1166 if (data & 0x40)
1167 data = 0x2c;
1168 else
1169 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001170 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301171 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001172
1173}
1174
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001175static void XGI_WriteDAC(unsigned short dl,
1176 unsigned short ah,
1177 unsigned short al,
1178 unsigned short dh,
1179 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001180{
1181 unsigned short temp, bh, bl;
1182
1183 bh = ah;
1184 bl = al;
1185
1186 if (dl != 0) {
1187 temp = bh;
1188 bh = dh;
1189 dh = temp;
1190 if (dl == 1) {
1191 temp = bl;
1192 bl = dh;
1193 dh = temp;
1194 } else {
1195 temp = bl;
1196 bl = bh;
1197 bh = temp;
1198 }
1199 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001200 outb((unsigned short) dh, pVBInfo->P3c9);
1201 outb((unsigned short) bh, pVBInfo->P3c9);
1202 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001203}
1204
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001205static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301206 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001207{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001208 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1209 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001210
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001211 outb(0xFF, pVBInfo->P3c6);
1212 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001213
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001214 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301215 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001216
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301217 for (k = 0; k < 3; k++) {
1218 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001219
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301220 if (data & 0x01)
1221 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301223 if (data & 0x02)
1224 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001225
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001226 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301227 data = data >> 2;
1228 }
1229 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001230
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001231 for (i = 16; i < 32; i++) {
1232 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001233
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001234 for (k = 0; k < 3; k++)
1235 outb(data, pVBInfo->P3c9);
1236 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001237
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001238 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001239
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001240 for (m = 0; m < 9; m++) {
1241 di = si;
1242 bx = si + 0x04;
1243 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001244
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001245 for (n = 0; n < 3; n++) {
1246 for (o = 0; o < 5; o++) {
1247 dh = table[si];
1248 ah = table[di];
1249 al = table[bx];
1250 si++;
1251 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301252 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001253
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001254 si -= 2;
1255
1256 for (o = 0; o < 3; o++) {
1257 dh = table[bx];
1258 ah = table[di];
1259 al = table[si];
1260 si--;
1261 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1262 }
1263
1264 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301265 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001266
1267 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301268 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001269}
1270
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001271static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1272 unsigned short ModeIdIndex,
1273 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001274{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301275 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001276
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001277 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001278 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001279
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001280 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001281 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001282
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001283 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1284 yres = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001285
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001286 if (modeflag & HalfDCLK)
1287 xres = xres << 1;
1288
1289 if (modeflag & DoubleScanMode)
1290 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001291
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301292 if (xres == 720)
1293 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001294
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301295 pVBInfo->VGAHDE = xres;
1296 pVBInfo->HDE = xres;
1297 pVBInfo->VGAVDE = yres;
1298 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001299}
1300
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001301static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001302 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001303 unsigned short ModeIdIndex,
1304 unsigned short RefreshRateTableIndex,
1305 struct vb_device_info *pVBInfo)
1306{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001307 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001308
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001309 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001310
Aaro Koskinenb3979922012-11-04 21:14:52 +02001311 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001312
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001313 i = 0;
1314
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001315 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001316 tempdx = pVBInfo->LCDResInfo;
1317 if (tempbx & 0x0080) { /* OEMUtil */
1318 tempbx &= (~0x0080);
1319 tempdx = pVBInfo->LCDTypeInfo;
1320 }
1321
1322 if (pVBInfo->LCDInfo & EnableScalingLCD)
1323 tempdx &= (~PanelResInfo);
1324
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001325 if (table[i].PANELID == tempdx) {
1326 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001327 tempdx = pVBInfo->LCDInfo;
1328
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001329 if (modeflag & HalfDCLK)
1330 tempdx |= SetLCDLowResolution;
1331
1332 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001333 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001334 break;
1335 }
1336 i++;
1337 }
1338
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001339 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001340}
1341
Aaro Koskinen24572542012-09-11 00:15:21 +03001342static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001343 unsigned short ModeIdIndex,
1344 unsigned short RefreshRateTableIndex,
1345 struct vb_device_info *pVBInfo)
1346{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001347 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001348
Aaro Koskinenb3979922012-11-04 21:14:52 +02001349 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001350 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001351 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001352 tempdx = pVBInfo->TVInfo;
1353
1354 if (pVBInfo->VBInfo & SetInSlaveMode)
1355 tempdx = tempdx | SetTVLockMode;
1356
1357 if (modeflag & HalfDCLK)
1358 tempdx = tempdx | SetTVLowResolution;
1359
1360 i = 0;
1361
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001362 while (XGI_TVDataTable[i].MASK != 0xffff) {
1363 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1364 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001365 break;
1366 i++;
1367 }
1368
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001369 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001370}
1371
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001372static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301373 unsigned short RefreshRateTableIndex,
1374 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001375{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001376 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001377
Aaro Koskinen6008f872012-11-04 21:14:49 +02001378 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1379 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001380
Aaro Koskinen6008f872012-11-04 21:14:49 +02001381 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1382 RefreshRateTableIndex, pVBInfo);
1383 pVBInfo->VGAHT = LCDPtr->VGAHT;
1384 pVBInfo->VGAVT = LCDPtr->VGAVT;
1385 pVBInfo->HT = LCDPtr->LCDHT;
1386 pVBInfo->VT = LCDPtr->LCDVT;
1387
1388 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1389 return;
1390
1391 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1392 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1393 pVBInfo->HDE = 1024;
1394 pVBInfo->VDE = 768;
1395 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1396 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1397 pVBInfo->HDE = 1280;
1398 pVBInfo->VDE = 1024;
1399 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1400 pVBInfo->HDE = 1400;
1401 pVBInfo->VDE = 1050;
1402 } else {
1403 pVBInfo->HDE = 1600;
1404 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301405 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001406}
1407
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001408static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301409 unsigned short RefreshRateTableIndex,
1410 struct xgi_hw_device_info *HwDeviceExtension,
1411 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001412{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301413 unsigned char index;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001414 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001415 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1416 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001417
Aaro Koskinena39325d2012-11-04 21:14:53 +02001418 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301419 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001420
Peter Huewea3d675c2012-02-09 21:11:47 +01001421 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001422 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001423 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001424
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001425 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001426 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301427 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001428
1429 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1430
Peter Huewea3d675c2012-02-09 21:11:47 +01001431 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001432 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1433 ModeIdIndex, RefreshRateTableIndex,
1434 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001435 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001436 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001437 }
1438
1439 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001440}
1441
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001442static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1443{
1444 unsigned char tempal, tempah, tempbl, i;
1445
Aaro Koskinen58839b02011-03-13 12:26:23 +02001446 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001447 tempal = tempah & 0x0F;
1448 tempah = tempah & 0xF0;
1449 i = 0;
1450 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1451
1452 while (tempbl != 0xFF) {
1453 if (tempbl & 0x80) { /* OEMUtil */
1454 tempal = tempah;
1455 tempbl = tempbl & ~(0x80);
1456 }
1457
1458 if (tempal == tempbl)
1459 break;
1460
1461 i++;
1462
1463 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1464 }
1465
1466 return i;
1467}
1468
1469static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1470{
1471 unsigned short tempah, tempal, tempbl, i;
1472
1473 tempal = pVBInfo->LCDResInfo;
1474 tempah = pVBInfo->LCDTypeInfo;
1475
1476 i = 0;
1477 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1478
1479 while (tempbl != 0xFF) {
1480 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1481 tempal = tempah;
1482 tempbl &= ~0x80;
1483 }
1484
1485 if (tempal == tempbl)
1486 break;
1487
1488 i++;
1489 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1490 }
1491
1492 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001493 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001494 pVBInfo->LCDTypeInfo = 0;
1495 i = 0;
1496 }
1497
1498 return i;
1499}
1500
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001501static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1502 unsigned short *VSyncWidth,
1503 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001504{
1505 unsigned short Index;
1506
1507 Index = XGI_GetLCDCapPtr(pVBInfo);
1508 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1509 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1510
1511 return;
1512}
1513
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001514static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301515 unsigned short RefreshRateTableIndex,
1516 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001517{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301518 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1519 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001520 struct XGI_LCDDesStruct const *LCDPtr = NULL;
1521 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001522
Aaro Koskinenb3979922012-11-04 21:14:52 +02001523 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen66cface2011-08-31 21:46:13 +03001524 if (pVBInfo->LCDInfo & EnableScalingLCD)
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001525 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1526 ModeIdIndex, RefreshRateTableIndex,
1527 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03001528 else
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001529 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1530 ModeIdIndex, RefreshRateTableIndex,
1531 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001532
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001533 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1534 push1 = tempbx;
1535 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001536
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001537 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001538 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1539 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001540 tempax = 1024;
1541 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001542 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1543 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001544 tempax = 1280;
1545 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001546 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001547 tempax = 1400;
1548 tempbx = 1050;
1549 } else {
1550 tempax = 1600;
1551 tempbx = 1200;
1552 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001553
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001554 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1555 pVBInfo->HDE = tempax;
1556 pVBInfo->VDE = tempbx;
1557 pVBInfo->VGAHDE = tempax;
1558 pVBInfo->VGAVDE = tempbx;
1559 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001560
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001561 tempax = pVBInfo->HT;
1562
1563 if (pVBInfo->LCDInfo & EnableScalingLCD)
1564 tempbx = LCDPtr1->LCDHDES;
1565 else
1566 tempbx = LCDPtr->LCDHDES;
1567
1568 tempcx = pVBInfo->HDE;
1569 tempbx = tempbx & 0x0fff;
1570 tempcx += tempbx;
1571
1572 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001573 tempcx -= tempax;
1574
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001575 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001576
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001577 tempcx = tempcx >> 3;
1578 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001579
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001580 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1581 (unsigned short) (tempbx & 0xff));
1582 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1583 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001584
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001585 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001586
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001587 if (pVBInfo->LCDInfo & EnableScalingLCD)
1588 tempbx = LCDPtr1->LCDHRS;
1589 else
1590 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001591
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001592 tempcx = push2;
1593
1594 if (pVBInfo->LCDInfo & EnableScalingLCD)
1595 tempcx = LCDPtr1->LCDHSync;
1596
1597 tempcx += tempbx;
1598
1599 if (tempcx >= tempax)
1600 tempcx -= tempax;
1601
1602 tempax = tempbx & 0x07;
1603 tempax = tempax >> 5;
1604 tempcx = tempcx >> 3;
1605 tempbx = tempbx >> 3;
1606
1607 tempcx &= 0x1f;
1608 tempax |= tempcx;
1609
1610 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1611 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1612 (unsigned short) (tempbx & 0xff));
1613
1614 tempax = pVBInfo->VT;
1615 if (pVBInfo->LCDInfo & EnableScalingLCD)
1616 tempbx = LCDPtr1->LCDVDES;
1617 else
1618 tempbx = LCDPtr->LCDVDES;
1619 tempcx = pVBInfo->VDE;
1620
1621 tempbx = tempbx & 0x0fff;
1622 tempcx += tempbx;
1623 if (tempcx >= tempax)
1624 tempcx -= tempax;
1625
1626 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1627 (unsigned short) (tempbx & 0xff));
1628 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1629 (unsigned short) (tempcx & 0xff));
1630
1631 tempbx = (tempbx >> 8) & 0x07;
1632 tempcx = (tempcx >> 8) & 0x07;
1633
1634 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1635 (unsigned short) ((tempcx << 3)
1636 | tempbx));
1637
1638 tempax = pVBInfo->VT;
1639 if (pVBInfo->LCDInfo & EnableScalingLCD)
1640 tempbx = LCDPtr1->LCDVRS;
1641 else
1642 tempbx = LCDPtr->LCDVRS;
1643
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001644 tempcx = push1;
1645
1646 if (pVBInfo->LCDInfo & EnableScalingLCD)
1647 tempcx = LCDPtr1->LCDVSync;
1648
1649 tempcx += tempbx;
1650 if (tempcx >= tempax)
1651 tempcx -= tempax;
1652
1653 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1654 (unsigned short) (tempbx & 0xff));
1655 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1656 (unsigned short) (tempcx & 0x0f));
1657
1658 tempax = ((tempbx >> 8) & 0x07) << 3;
1659
1660 tempbx = pVBInfo->VGAVDE;
1661 if (tempbx != pVBInfo->VDE)
1662 tempax |= 0x40;
1663
Peter Huewea3d675c2012-02-09 21:11:47 +01001664 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001665 tempax |= 0x40;
1666
1667 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1668 tempax);
1669
1670 tempcx = pVBInfo->VGAVT;
1671 tempbx = pVBInfo->VDE;
1672 tempax = pVBInfo->VGAVDE;
1673 tempcx -= tempax;
1674
1675 temp = tempax; /* 0430 ylshieh */
1676 temp1 = (temp << 18) / tempbx;
1677
1678 tempdx = (unsigned short) ((temp << 18) % tempbx);
1679
1680 if (tempdx != 0)
1681 temp1 += 1;
1682
1683 temp2 = temp1;
1684 push3 = temp2;
1685
1686 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1687 (unsigned short) (temp2 & 0xff));
1688 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1689 (unsigned short) ((temp2 >> 8) & 0xff));
1690
1691 tempbx = (unsigned short) (temp2 >> 16);
1692 tempax = tempbx & 0x03;
1693
1694 tempbx = pVBInfo->VGAVDE;
1695 if (tempbx == pVBInfo->VDE)
1696 tempax |= 0x04;
1697
1698 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1699
1700 if (pVBInfo->VBType & VB_XGI301C) {
1701 temp2 = push3;
1702 xgifb_reg_set(pVBInfo->Part4Port,
1703 0x3c,
1704 (unsigned short) (temp2 & 0xff));
1705 xgifb_reg_set(pVBInfo->Part4Port,
1706 0x3b,
1707 (unsigned short) ((temp2 >> 8) &
1708 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001709 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001710 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1711 ~0xc0,
1712 (unsigned short) ((tempbx &
1713 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001714
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001715 tempcx = pVBInfo->VGAVDE;
1716 if (tempcx == pVBInfo->VDE)
1717 xgifb_reg_and_or(pVBInfo->Part4Port,
1718 0x30, ~0x0c, 0x00);
1719 else
1720 xgifb_reg_and_or(pVBInfo->Part4Port,
1721 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301722 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001723
1724 tempcx = pVBInfo->VGAHDE;
1725 tempbx = pVBInfo->HDE;
1726
1727 temp1 = tempcx << 16;
1728
1729 tempax = (unsigned short) (temp1 / tempbx);
1730
1731 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1732 tempax = 65535;
1733
1734 temp3 = tempax;
1735 temp1 = pVBInfo->VGAHDE << 16;
1736
1737 temp1 /= temp3;
1738 temp3 = temp3 << 16;
1739 temp1 -= 1;
1740
1741 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1742
1743 tempax = (unsigned short) (temp3 & 0xff);
1744 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1745
1746 temp1 = pVBInfo->VGAVDE << 18;
1747 temp1 = temp1 / push3;
1748 tempbx = (unsigned short) (temp1 & 0xffff);
1749
Peter Huewe255aabd2012-02-09 21:11:44 +01001750 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001751 tempbx -= 1;
1752
1753 tempax = ((tempbx >> 8) & 0xff) << 3;
1754 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1755 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1756 (unsigned short) (tempax & 0xff));
1757 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1758 (unsigned short) (tempbx & 0xff));
1759
1760 temp3 = temp3 >> 16;
1761
1762 if (modeflag & HalfDCLK)
1763 temp3 = temp3 >> 1;
1764
1765 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1766 (unsigned short) ((temp3 >> 8) & 0xff));
1767 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1768 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001769}
1770
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001771/* --------------------------------------------------------------------- */
1772/* Function : XGI_GETLCDVCLKPtr */
1773/* Input : */
1774/* Output : al -> VCLK Index */
1775/* Description : */
1776/* --------------------------------------------------------------------- */
1777static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1778 struct vb_device_info *pVBInfo)
1779{
1780 unsigned short index;
1781
Peter Huewea3d675c2012-02-09 21:11:47 +01001782 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001783 index = XGI_GetLCDCapPtr1(pVBInfo);
1784
1785 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1786 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1787 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1788 } else { /* LCDA */
1789 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1790 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1791 }
1792 }
1793 return;
1794}
1795
1796static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1797 unsigned short ModeNo, unsigned short ModeIdIndex,
1798 struct vb_device_info *pVBInfo)
1799{
1800
1801 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001802 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001803
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001804 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001805 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001806
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001807 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1808 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001809 index = XGI_GetLCDCapPtr(pVBInfo);
1810 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1811
Peter Huewea3d675c2012-02-09 21:11:47 +01001812 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001813 return tempal;
1814
1815 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001816 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001817 (VB_SIS301B |
1818 VB_SIS302B |
1819 VB_SIS301LV |
1820 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001821 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001822 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001823 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001824 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001825 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001826 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001827 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001828 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001829 tempal = TVCLKBASE_315 +
1830 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001831
1832 }
1833 return tempal;
1834 }
1835
Peter Huewe599801f2012-02-09 21:11:45 +01001836 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001837 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001838 return tempal;
1839 }
1840
Peter Huewe599801f2012-02-09 21:11:45 +01001841 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001842 tempal = YPbPr525pVCLK;
1843 return tempal;
1844 }
1845
1846 tempal = NTSC1024VCLK;
1847
1848 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001849 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001850 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001851 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001852 }
1853
1854 if (pVBInfo->VBInfo & SetCRT2ToTV)
1855 return tempal;
1856 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001857 } /* {End of VB} */
1858
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001859 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001860 tempal = tempal >> 2;
1861 tempal &= 0x03;
1862
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001863 /* for Dot8 Scaling LCD */
1864 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001865 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
1866
Aaro Koskinena39325d2012-11-04 21:14:53 +02001867 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001868 return tempal;
1869}
1870
1871static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1872 unsigned char *di_1, struct vb_device_info *pVBInfo)
1873{
Peter Huewe6896b942012-02-09 21:11:46 +01001874 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1875 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001876 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1877 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001878 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001879 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001880 }
1881 } else {
1882 *di_0 = XGI_VCLKData[tempal].SR2B;
1883 *di_1 = XGI_VCLKData[tempal].SR2C;
1884 }
1885}
1886
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001887static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301888 unsigned short RefreshRateTableIndex,
1889 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001890{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301891 unsigned char di_0, di_1, tempal;
1892 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001893
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301894 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1895 pVBInfo);
1896 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1897 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001898
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301899 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001900 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301901 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001902 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301903 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001904 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1905 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301906 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001907 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1908 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301909 }
1910 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001911}
1912
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001913static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301914 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001915{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301916 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001917
Peter Huewe6896b942012-02-09 21:11:46 +01001918 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1919 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301920 tempcl = 0;
1921 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001922 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001923
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301924 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001925 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301926 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001927 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301928 if (!(temp & 0x40))
1929 tempcl |= ActiveCRT1;
1930 }
1931 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001932
Aaro Koskinen58839b02011-03-13 12:26:23 +02001933 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301934 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001935
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301936 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001937 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001938 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301939 if (tempax & 0x04)
1940 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001941
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301942 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301944 if (!(tempcl & ActiveLCD))
1945 if (temp == 0x01)
1946 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001947
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301948 if (temp == 0x04)
1949 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001950
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301951 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001952 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001953
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301954 if (!(temp & 0x08))
1955 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001956
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301957 if (!(temp & 0x04))
1958 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001959
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301960 if (temp & 0x02)
1961 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001962
Peter Huewe599801f2012-02-09 21:11:45 +01001963 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301964 if (temp & 0x01)
1965 tempch |= ActiveHiTV;
1966 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001967
Peter Huewe599801f2012-02-09 21:11:45 +01001968 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001969 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301970 pVBInfo->Part2Port,
1971 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301973 if (temp & 0x10)
1974 tempch |= ActiveYPbPr;
1975 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001976
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301977 if (tempch != 0)
1978 tempcl |= ActiveTV;
1979 }
1980 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001981
Aaro Koskinen58839b02011-03-13 12:26:23 +02001982 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301983 if (tempcl & ActiveLCD) {
1984 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1985 if (temp & ActiveTV)
1986 tempcl |= ActiveTV;
1987 }
1988 }
1989 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001990 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001991 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001992
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301993 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001994 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301995 } else {
1996 return;
1997 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001998}
1999
Bill Pemberton80adad82010-06-17 13:10:51 -04002000void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002001{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302002 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002003
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002004 if (pVBInfo->IF_DEF_LVDS != 0)
2005 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002006
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002007 tempbx = VB_SIS302B;
2008 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
2009 if (flag == 0x02)
2010 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002011
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002012 tempbx = VB_SIS301;
2013 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
2014 if (flag < 0xB0)
2015 goto finish;
2016
2017 tempbx = VB_SIS301B;
2018 if (flag < 0xC0)
2019 goto bigger_than_0xB0;
2020
2021 tempbx = VB_XGI301C;
2022 if (flag < 0xD0)
2023 goto bigger_than_0xB0;
2024
2025 tempbx = VB_SIS301LV;
2026 if (flag < 0xE0)
2027 goto bigger_than_0xB0;
2028
2029 tempbx = VB_SIS302LV;
2030 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
2031 if (tempah != 0xFF)
2032 tempbx = VB_XGI301C;
2033
2034bigger_than_0xB0:
2035 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
2036 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
2037 if (!(flag & 0x02))
2038 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302039 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002040
2041finish:
2042 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002043}
2044
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002045static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302046 struct xgi_hw_device_info *HwDeviceExtension,
2047 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002048{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302049 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002050
Aaro Koskinenb3979922012-11-04 21:14:52 +02002051 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302052 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01002053 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302054 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002055
Miguel Gómezf9317352012-07-06 12:40:48 +02002056 if (!(pVBInfo->VBType & 0xFFFF))
2057 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002058
Miguel Gómezf9317352012-07-06 12:40:48 +02002059 /* Check Display Device */
2060 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
2061 tempbx = tempbx | temp;
2062 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
2063 push = temp;
2064 push = push << 8;
2065 tempax = temp << 8;
2066 tempbx = tempbx | tempax;
2067 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
2068 | SetInSlaveMode | DisableCRT2Display);
2069 temp = 0xFFFF ^ temp;
2070 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002071
Miguel Gómezf9317352012-07-06 12:40:48 +02002072 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002073
Aaro Koskinen4d8f5ca2012-09-11 00:15:17 +03002074 if (pVBInfo->IF_DEF_LVDS == 0) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002075 if (pVBInfo->VBType &
2076 (VB_SIS302B |
2077 VB_SIS301LV |
2078 VB_SIS302LV |
2079 VB_XGI301C)) {
2080 if (temp & EnableDualEdge) {
2081 tempbx |= SetCRT2ToDualEdge;
2082 if (temp & SetToLCDA)
2083 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02002084 }
2085 }
2086 }
2087
2088 if (pVBInfo->IF_DEF_YPbPr == 1) {
2089 if (((pVBInfo->IF_DEF_LVDS == 0) &&
2090 ((pVBInfo->VBType & VB_SIS301LV) ||
2091 (pVBInfo->VBType & VB_SIS302LV) ||
2092 (pVBInfo->VBType & VB_XGI301C)))) {
2093 if (temp & SetYPbPr) {
2094 if (pVBInfo->IF_DEF_HiVision == 1) {
2095 /* shampoo add for new
2096 * scratch */
2097 temp = xgifb_reg_get(
2098 pVBInfo->P3d4,
2099 0x35);
2100 temp &= YPbPrMode;
2101 tempbx |= SetCRT2ToHiVision;
2102
2103 if (temp != YPbPrMode1080i) {
2104 tempbx &=
2105 (~SetCRT2ToHiVision);
2106 tempbx |=
2107 SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302108 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302109 }
2110 }
2111 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002112 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002113
Miguel Gómezf9317352012-07-06 12:40:48 +02002114 tempax = push; /* restore CR31 */
2115
2116 if (pVBInfo->IF_DEF_LVDS == 0) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302117 if (pVBInfo->IF_DEF_YPbPr == 1) {
Miguel Gómezf9317352012-07-06 12:40:48 +02002118 if (pVBInfo->IF_DEF_HiVision == 1)
2119 temp = 0x09FC;
2120 else
2121 temp = 0x097C;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002122 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2123 temp = 0x01FC;
Miguel Gómezf9317352012-07-06 12:40:48 +02002124 } else {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002125 temp = 0x017C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302126 }
Justin P. Mattock558f7582012-10-02 21:17:11 -07002127 } else { /* 3rd party chip */
Miguel Gómezf9317352012-07-06 12:40:48 +02002128 temp = SetCRT2ToLCD;
2129 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002130
Miguel Gómezf9317352012-07-06 12:40:48 +02002131 if (!(tempbx & temp)) {
2132 tempax |= DisableCRT2Display;
2133 tempbx = 0;
2134 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002135
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002136 if (!(pVBInfo->VBType & VB_NoLCD)) {
2137 if (tempbx & XGI_SetCRT2ToLCDA) {
2138 if (tempbx & SetSimuScanMode)
2139 tempbx &= (~(SetCRT2ToLCD |
2140 SetCRT2ToRAMDAC |
2141 SwitchCRT2));
2142 else
2143 tempbx &= (~(SetCRT2ToLCD |
2144 SetCRT2ToRAMDAC |
2145 SetCRT2ToTV |
2146 SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002147 }
2148 }
2149
2150 /* shampoo add */
2151 /* for driver abnormal */
2152 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2153 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2154 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002155 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002156 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002157 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002158 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002159 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302160 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002161 } else {
2162 tempbx &= (~(SetCRT2ToRAMDAC |
2163 SetCRT2ToLCD |
2164 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302165 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002166 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002167
Miguel Gómezf9317352012-07-06 12:40:48 +02002168 if (!(pVBInfo->VBType & VB_NoLCD)) {
2169 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002170 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002171 SetCRT2ToLCD |
Peter Huewe6896b942012-02-09 21:11:46 +01002172 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002173 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002174 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302175 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002176 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002177
Miguel Gómezf9317352012-07-06 12:40:48 +02002178 if (tempbx & SetCRT2ToSCART) {
2179 tempbx &= (0xFF00 |
2180 SetCRT2ToSCART |
2181 SwitchCRT2 |
2182 SetSimuScanMode);
2183 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2184 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002185
Miguel Gómezf9317352012-07-06 12:40:48 +02002186 if (pVBInfo->IF_DEF_YPbPr == 1) {
2187 if (tempbx & SetCRT2ToYPbPr525750)
2188 tempbx &= (0xFF00 |
2189 SwitchCRT2 |
2190 SetSimuScanMode);
2191 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002192
Miguel Gómezf9317352012-07-06 12:40:48 +02002193 if (pVBInfo->IF_DEF_HiVision == 1) {
2194 if (tempbx & SetCRT2ToHiVision)
2195 tempbx &= (0xFF00 |
2196 SetCRT2ToHiVision |
2197 SwitchCRT2 |
2198 SetSimuScanMode);
2199 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002200
Miguel Gómezf9317352012-07-06 12:40:48 +02002201 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2202 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2203 tempbx = DisableCRT2Display;
2204 }
2205
2206 if (!(tempbx & DisableCRT2Display)) {
2207 if ((!(tempbx & DriverMode)) ||
2208 (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002209 if (!(tempbx & XGI_SetCRT2ToLCDA))
2210 tempbx |= (SetInSlaveMode |
2211 SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002212 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002213
Miguel Gómezf9317352012-07-06 12:40:48 +02002214 /* LCD+TV can't support in slave mode
2215 * (Force LCDA+TV->LCDB) */
2216 if ((tempbx & SetInSlaveMode) &&
2217 (tempbx & XGI_SetCRT2ToLCDA)) {
2218 tempbx ^= (SetCRT2ToLCD |
2219 XGI_SetCRT2ToLCDA |
2220 SetCRT2ToDualEdge);
2221 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302222 }
2223 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302225 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002226}
2227
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002228static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302229 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002230{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302231 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302233 tempbx = 0;
2234 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002235
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302236 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002237 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2238 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302240 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002241 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302242 tempbx = temp;
Peter Huewe599801f2012-02-09 21:11:45 +01002243 if (tempbx & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002244 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002245 TVSetPALM |
2246 TVSetPALN |
2247 TVSetPAL);
2248 if (tempbx & TVSetPALM)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002249 /* set to NTSC if PAL-M */
Peter Huewe599801f2012-02-09 21:11:45 +01002250 tempbx &= ~TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302251 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002252 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002253 TVSetNTSCJ |
2254 TVSetPAL);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302255 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302257 if (pVBInfo->IF_DEF_LVDS == 0) {
2258 if (pVBInfo->VBInfo & SetCRT2ToSCART)
Peter Huewe599801f2012-02-09 21:11:45 +01002259 tempbx |= TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302260 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002261
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302262 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002263 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002264 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302265 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002266
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302267 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002268 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002269
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302270 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002271 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302272 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002273 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302274 }
2275 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002276
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302277 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002278 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2279 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302280 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002281
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302282 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002283 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2284 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302285 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002286
Peter Huewe599801f2012-02-09 21:11:45 +01002287 if (!(tempbx & TVSetPAL) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002288 (modeflag > 13) &&
2289 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302290 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002291
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302292 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002293
Peter Huewe599801f2012-02-09 21:11:45 +01002294 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302295 if (pVBInfo->VBInfo & SetInSlaveMode)
2296 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002297 } else if (tempbx &
2298 (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302299 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002300 } else if (!(pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002301 (VB_SIS301B |
2302 VB_SIS302B |
2303 VB_SIS301LV |
2304 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002305 VB_XGI301C))) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002306 if (tempbx & TVSimuMode)
2307 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302308 }
2309 }
2310 }
2311 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002312}
2313
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002314static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2315 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002316{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302317 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002318
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302319 pVBInfo->LCDResInfo = 0;
2320 pVBInfo->LCDTypeInfo = 0;
2321 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002322
Aaro Koskinenb3979922012-11-04 21:14:52 +02002323 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002324 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002325 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002326 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302327 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002328
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302329 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002330 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002331
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002332 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002333 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302334 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002335 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002336 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302337 tempax &= 0x0F;
2338 else
2339 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302341 if ((resinfo == 6) || (resinfo == 9)) {
2342 if (tempax >= 3)
2343 tempbx |= PanelRef75Hz;
2344 } else if ((resinfo == 7) || (resinfo == 8)) {
2345 if (tempax >= 4)
2346 tempbx |= PanelRef75Hz;
2347 }
2348 }
2349 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002350
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302351 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002352
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302353 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002354
Peter Huewea3d675c2012-02-09 21:11:47 +01002355 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302356 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002357
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302358 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002359
Aaro Koskinen58839b02011-03-13 12:26:23 +02002360 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002361
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302362 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002363
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302364 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002365
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302366 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302368 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002369
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302370 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Peter Huewe6896b942012-02-09 21:11:46 +01002371 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType
Peter Huewea3d675c2012-02-09 21:11:47 +01002372 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302373 tempbx |= SetLCDDualLink;
2374 }
2375 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002376
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302377 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002378 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002379 & SetCRT2ToLCD) && (resinfo == 9) &&
2380 (!(tempbx & EnableScalingLCD)))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02002381 /*
2382 * set to center in 1280x1024 LCDB
2383 * for Panel_1400x1050
2384 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002385 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302386 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002387
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302388 if (pVBInfo->VBInfo & SetInSlaveMode) {
2389 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002390 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302391 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002392 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302393 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002394
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302395 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002396
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302397 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002398}
2399
Bill Pemberton108afbf2010-06-17 13:10:47 -04002400unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302401 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002402{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002403 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002404 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002405 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002406 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002407 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302408 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002409
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302410 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002411}
2412
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002413static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2414{
2415 unsigned char ujRet = 0;
2416 unsigned char i = 0;
2417
2418 for (i = 0; i < 8; i++) {
2419 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002420 ujRet |= (ujDate >> i) & 1;
2421 }
2422
2423 return ujRet;
2424}
2425
2426/*----------------------------------------------------------------------------*/
2427/* output */
2428/* bl[5] : LVDS signal */
2429/* bl[1] : LVDS backlight */
2430/* bl[0] : LVDS VDD */
2431/*----------------------------------------------------------------------------*/
2432static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2433{
2434 unsigned char CR4A, temp;
2435
Aaro Koskinen58839b02011-03-13 12:26:23 +02002436 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002437 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002438
Aaro Koskinen58839b02011-03-13 12:26:23 +02002439 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002440
2441 temp = XG21GPIODataTransfer(temp);
2442 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002443 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002444 return temp;
2445}
2446
2447/*----------------------------------------------------------------------------*/
2448/* output */
2449/* bl[5] : LVDS signal */
2450/* bl[1] : LVDS backlight */
2451/* bl[0] : LVDS VDD */
2452/*----------------------------------------------------------------------------*/
2453static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2454{
2455 unsigned char CR4A, CRB4, temp;
2456
Aaro Koskinen58839b02011-03-13 12:26:23 +02002457 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002458 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002459
Aaro Koskinen58839b02011-03-13 12:26:23 +02002460 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002461
2462 temp &= 0x0C;
2463 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002464 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002465 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002466 temp |= ((CRB4 & 0x04) << 3);
2467 return temp;
2468}
2469
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002470/*----------------------------------------------------------------------------*/
2471/* input */
2472/* bl[5] : 1;LVDS signal on */
2473/* bl[1] : 1;LVDS backlight on */
2474/* bl[0] : 1:LVDS VDD on */
2475/* bh: 100000b : clear bit 5, to set bit5 */
2476/* 000010b : clear bit 1, to set bit1 */
2477/* 000001b : clear bit 0, to set bit0 */
2478/*----------------------------------------------------------------------------*/
2479static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2480 struct vb_device_info *pVBInfo)
2481{
2482 unsigned char CR4A, temp;
2483
2484 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2485 tempbh &= 0x23;
2486 tempbl &= 0x23;
2487 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2488
2489 if (tempbh & 0x20) {
2490 temp = (tempbl >> 4) & 0x02;
2491
2492 /* CR B4[1] */
2493 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2494
2495 }
2496
2497 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2498
2499 temp = XG21GPIODataTransfer(temp);
2500 temp &= ~tempbh;
2501 temp |= tempbl;
2502 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2503}
2504
Aaro Koskinen776115a2011-11-27 23:03:10 +02002505static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2506 struct vb_device_info *pVBInfo)
2507{
2508 unsigned char CR4A, temp;
2509 unsigned short tempbh0, tempbl0;
2510
2511 tempbh0 = tempbh;
2512 tempbl0 = tempbl;
2513 tempbh0 &= 0x20;
2514 tempbl0 &= 0x20;
2515 tempbh0 >>= 3;
2516 tempbl0 >>= 3;
2517
2518 if (tempbh & 0x20) {
2519 temp = (tempbl >> 4) & 0x02;
2520
2521 /* CR B4[1] */
2522 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2523
2524 }
2525 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2526
2527 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2528 tempbh &= 0x03;
2529 tempbl &= 0x03;
2530 tempbh <<= 2;
2531 tempbl <<= 2; /* GPIOC,GPIOD */
2532 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2533 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2534}
2535
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002536static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2537 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302538 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002539{
2540
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002541 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302542 if (pXGIHWDE->jChipType == XG21) {
2543 if (pVBInfo->IF_DEF_LVDS == 1) {
2544 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002545 /* LVDS VDD on */
2546 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002547 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302548 }
2549 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002550 /* LVDS signal on */
2551 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002552 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002553 /* LVDS backlight on */
2554 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302555 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002556 /* DVO/DVI signal on */
2557 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302558 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002559
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302560 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002561
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302562 if (pXGIHWDE->jChipType == XG27) {
2563 if (pVBInfo->IF_DEF_LVDS == 1) {
2564 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002565 /* LVDS VDD on */
2566 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002567 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302568 }
2569 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002570 /* LVDS signal on */
2571 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002572 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002573 /* LVDS backlight on */
2574 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302575 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002576 /* DVO/DVI signal on */
2577 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302578 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002579
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302580 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002581}
2582
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002583void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2584 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302585 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002586{
2587
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302588 if (pXGIHWDE->jChipType == XG21) {
2589 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002590 /* LVDS backlight off */
2591 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002592 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302593 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002594 /* DVO/DVI signal off */
2595 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302596 }
2597 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002598
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302599 if (pXGIHWDE->jChipType == XG27) {
2600 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002601 /* LVDS backlight off */
2602 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002603 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302604 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002605
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302606 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002607 /* DVO/DVI signal off */
2608 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302609 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002610
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002611 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002612}
2613
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002614static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002615{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002616 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302617 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002618
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002619 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302620 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002621}
2622
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002623static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002624{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002625 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002626}
2627
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002628static void XGI_SaveCRT2Info(unsigned short ModeNo,
2629 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002630{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302631 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002632
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002633 /* reserve CR34 for CRT1 Mode No */
2634 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302635 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2636 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002637 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002638}
2639
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002640static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2641 unsigned short ModeIdIndex,
2642 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002643{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302644 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002645
Aaro Koskinenb3979922012-11-04 21:14:52 +02002646 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002647 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
2648 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
2649 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002650 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002651
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002652 if (modeflag & HalfDCLK)
2653 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002654
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002655 if (modeflag & DoubleScanMode)
2656 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002657
Miguel Gómez3339db82012-07-06 12:40:49 +02002658 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2659 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002660
Miguel Gómez3339db82012-07-06 12:40:49 +02002661 if (pVBInfo->IF_DEF_LVDS == 0) {
2662 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2663 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2664 if (yres == 1024)
2665 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302666 }
2667 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002668
Miguel Gómez3339db82012-07-06 12:40:49 +02002669 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2670 if (yres == 400)
2671 yres = 405;
2672 else if (yres == 350)
2673 yres = 360;
2674
2675 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2676 if (yres == 360)
2677 yres = 375;
2678 }
2679 }
2680
2681 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2682 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2683 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2684 if (yres == 350)
2685 yres = 357;
2686 else if (yres == 400)
2687 yres = 420;
2688 else if (yres == 480)
2689 yres = 525;
2690 }
2691 }
2692 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302693 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002694
Miguel Gómez3339db82012-07-06 12:40:49 +02002695 if (xres == 720)
2696 xres = 640;
2697
2698exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302699 pVBInfo->VGAHDE = xres;
2700 pVBInfo->HDE = xres;
2701 pVBInfo->VGAVDE = yres;
2702 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002703}
2704
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002705static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002706{
2707
Peter Huewea3d675c2012-02-09 21:11:47 +01002708 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002709 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302710 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302712 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002713}
2714
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002715static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2716 unsigned short ModeIdIndex,
2717 unsigned short RefreshRateTableIndex,
2718 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002719{
2720 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002721 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002722
2723 pVBInfo->RVBHCMAX = 1;
2724 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002725 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002726 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002727 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002728 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2729 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002730 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002731 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002732 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002733 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002734 tempcx &= 0x0100;
2735 tempcx = tempcx << 2;
2736 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002737 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002738
2739 if (temp1 & 0x01)
2740 tempbx |= 0x0100;
2741
2742 if (temp1 & 0x20)
2743 tempbx |= 0x0200;
2744 tempax += 5;
2745
2746 if (modeflag & Charx8Dot)
2747 tempax *= 8;
2748 else
2749 tempax *= 9;
2750
2751 pVBInfo->VGAHT = tempax;
2752 pVBInfo->HT = tempax;
2753 tempbx++;
2754 pVBInfo->VGAVT = tempbx;
2755 pVBInfo->VT = tempbx;
2756}
2757
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002758static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302759 unsigned short RefreshRateTableIndex,
2760 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002761{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002762 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002763
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002764 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002765
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002766 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002767 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2768 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302769 pVBInfo->NewFlickerMode = 0;
2770 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002771
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302772 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2773 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2774 pVBInfo);
2775 return;
2776 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002777
Peter Huewea3d675c2012-02-09 21:11:47 +01002778 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002779 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002780 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002781
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302782 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2783 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2784 pVBInfo->VGAHT = LCDPtr->VGAHT;
2785 pVBInfo->VGAVT = LCDPtr->VGAVT;
2786 pVBInfo->HT = LCDPtr->LCDHT;
2787 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002788
Peter Huewe255aabd2012-02-09 21:11:44 +01002789 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302790 tempax = 1024;
2791 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002792
Peter Huewea3d675c2012-02-09 21:11:47 +01002793 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302794 if (pVBInfo->VGAVDE == 357)
2795 tempbx = 527;
2796 else if (pVBInfo->VGAVDE == 420)
2797 tempbx = 620;
2798 else if (pVBInfo->VGAVDE == 525)
2799 tempbx = 775;
2800 else if (pVBInfo->VGAVDE == 600)
2801 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302802 else
2803 tempbx = 768;
2804 } else
2805 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002806 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302807 tempax = 1024;
2808 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002809 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302810 tempax = 1280;
2811 if (pVBInfo->VGAVDE == 360)
2812 tempbx = 768;
2813 else if (pVBInfo->VGAVDE == 375)
2814 tempbx = 800;
2815 else if (pVBInfo->VGAVDE == 405)
2816 tempbx = 864;
2817 else
2818 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002819 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302820 tempax = 1280;
2821 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002822 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302823 tempax = 1280;
2824 if (pVBInfo->VGAVDE == 350)
2825 tempbx = 700;
2826 else if (pVBInfo->VGAVDE == 400)
2827 tempbx = 800;
2828 else if (pVBInfo->VGAVDE == 1024)
2829 tempbx = 960;
2830 else
2831 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002832 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302833 tempax = 1400;
2834 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302836 if (pVBInfo->VGAVDE == 1024) {
2837 tempax = 1280;
2838 tempbx = 1024;
2839 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002840 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302841 tempax = 1600;
2842 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002843 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302844 if (pVBInfo->VGAVDE == 350)
2845 tempbx = 875;
2846 else if (pVBInfo->VGAVDE == 400)
2847 tempbx = 1000;
2848 }
2849 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002850
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302851 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2852 tempax = pVBInfo->VGAHDE;
2853 tempbx = pVBInfo->VGAVDE;
2854 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002855
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302856 pVBInfo->HDE = tempax;
2857 pVBInfo->VDE = tempbx;
2858 return;
2859 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002860
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302861 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002862 struct SiS_TVData const *TVPtr;
2863
2864 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2865 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302867 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2868 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2869 pVBInfo->VGAHT = TVPtr->VGAHT;
2870 pVBInfo->VGAVT = TVPtr->VGAVT;
2871 pVBInfo->HDE = TVPtr->TVHDE;
2872 pVBInfo->VDE = TVPtr->TVVDE;
2873 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2874 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002875
Peter Huewe599801f2012-02-09 21:11:45 +01002876 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302877 if (resinfo == 0x08)
2878 pVBInfo->NewFlickerMode = 0x40;
2879 else if (resinfo == 0x09)
2880 pVBInfo->NewFlickerMode = 0x40;
2881 else if (resinfo == 0x12)
2882 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002883
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302884 if (pVBInfo->VGAVDE == 350)
2885 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302887 tempax = ExtHiTVHT;
2888 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002889
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302890 if (pVBInfo->VBInfo & SetInSlaveMode) {
2891 if (pVBInfo->TVInfo & TVSimuMode) {
2892 tempax = StHiTVHT;
2893 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002894
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302895 if (!(modeflag & Charx8Dot)) {
2896 tempax = StHiTextTVHT;
2897 tempbx = StHiTextTVVT;
2898 }
2899 }
2900 }
Peter Huewe599801f2012-02-09 21:11:45 +01002901 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2902 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302903 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2904 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2905 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002906
Peter Huewe599801f2012-02-09 21:11:45 +01002907 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302908 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2909 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002910 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302911 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2912 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2913 if (pVBInfo->TVInfo & NTSC1024x768)
2914 tempax = NTSC1024x768HT;
2915 }
2916 } else {
2917 tempax = PALHT;
2918 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002919 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302920 tempax = NTSCHT;
2921 tempbx = NTSCVT;
2922 if (pVBInfo->TVInfo & NTSC1024x768)
2923 tempax = NTSC1024x768HT;
2924 }
2925 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002926
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302927 pVBInfo->HT = tempax;
2928 pVBInfo->VT = tempbx;
2929 return;
2930 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002931}
2932
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002933static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302934 unsigned short RefreshRateTableIndex,
2935 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002936{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002937 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302939 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2940 pVBInfo);
2941 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2942 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002943
Peter Huewe6896b942012-02-09 21:11:46 +01002944 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302945 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002946 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2947 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2948 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302949 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002950 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2951 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302952 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002953
Aaro Koskinen8104e322011-03-13 12:26:22 +02002954 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002955
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302956 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002957 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302958 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002959 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002960}
2961
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002962static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2963 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002964{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002965 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2966 short index;
2967 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302968
Aaro Koskinenb3979922012-11-04 21:14:52 +02002969 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002970 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302971
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002972 if (index < 0)
2973 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302974
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002975 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302976}
2977
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002978static unsigned short XGI_GetOffset(unsigned short ModeNo,
2979 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302980 unsigned short RefreshRateTableIndex,
2981 struct xgi_hw_device_info *HwDeviceExtension,
2982 struct vb_device_info *pVBInfo)
2983{
2984 unsigned short temp, colordepth, modeinfo, index, infoflag,
2985 ColorDepth[] = { 0x01, 0x02, 0x04 };
2986
Aaro Koskinenb3979922012-11-04 21:14:52 +02002987 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002988 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302989
2990 index = (modeinfo >> 8) & 0xFF;
2991
2992 temp = pVBInfo->ScreenOffset[index];
2993
2994 if (infoflag & InterlaceMode)
2995 temp = temp << 1;
2996
2997 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2998
2999 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
3000 temp = ModeNo - 0x7C;
3001 colordepth = ColorDepth[temp];
3002 temp = 0x6B;
3003 if (infoflag & InterlaceMode)
3004 temp = temp << 1;
3005 return temp * colordepth;
3006 } else {
3007 return temp * colordepth;
3008 }
3009}
3010
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003011static void XGI_SetCRT2Offset(unsigned short ModeNo,
3012 unsigned short ModeIdIndex,
3013 unsigned short RefreshRateTableIndex,
3014 struct xgi_hw_device_info *HwDeviceExtension,
3015 struct vb_device_info *pVBInfo)
3016{
3017 unsigned short offset;
3018 unsigned char temp;
3019
3020 if (pVBInfo->VBInfo & SetInSlaveMode)
3021 return;
3022
3023 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3024 HwDeviceExtension, pVBInfo);
3025 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003026 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003027 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003028 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003029 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003030 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003031}
3032
Randy Dunlap89229672010-08-10 08:46:44 -07003033static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003034{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003035 /* threshold high ,disable auto threshold */
3036 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
3037 /* threshold low default 04h */
3038 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003039}
3040
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003041static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303042 struct xgi_hw_device_info *HwDeviceExtension,
3043 unsigned short RefreshRateTableIndex,
3044 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003045{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303046 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003047
Aaro Koskinena39325d2012-11-04 21:14:53 +02003048 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003049 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02003050 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303052 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3053 HwDeviceExtension, pVBInfo);
3054 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003055
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303056 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003057 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003058
Aaro Koskinen8104e322011-03-13 12:26:22 +02003059 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
3060 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003061}
3062
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003063static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303064 struct xgi_hw_device_info *HwDeviceExtension,
3065 unsigned short RefreshRateTableIndex,
3066 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003067{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303068 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
3069 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003070
Aaro Koskinena39325d2012-11-04 21:14:53 +02003071 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003072 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02003073 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
3074 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303076 /* bainy change table name */
3077 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003078 /* BTVGA2HT 0x08,0x09 */
3079 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003080 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303081 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003082 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003083 /* BTVGA2HDEE 0x0A,0x0C */
3084 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003085 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303086 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
3087 pushbx = pVBInfo->VGAHDE / 2 + 16;
3088 tempcx = tempcx >> 1;
3089 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3090 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303092 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003093 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
3094 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003095 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303096 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003097 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303098 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003099 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303100 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3101 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3102 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303104 tempbx += 4;
3105 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303107 if (tempcx > (pVBInfo->VGAHT / 2))
3108 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003109
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303110 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003111
Aaro Koskinen8104e322011-03-13 12:26:22 +02003112 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303113 } else {
3114 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003115 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303116 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003117 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003118 /* BTVGA2HDEE 0x0A,0x0C */
3119 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003120 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303121 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
3122 pushbx = pVBInfo->VGAHDE + 16;
3123 tempcx = tempcx >> 1;
3124 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3125 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303127 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003128 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
3129 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003130 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303131 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003132 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303133 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003134 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303135 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3136 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3137 tempbx += 16;
3138 tempcx += 16;
3139 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303141 if (tempcx > pVBInfo->VGAHT)
3142 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303144 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003145 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303146 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003147
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303148 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3149 tempbx = pushbx;
3150 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3151 tempax |= (tempbx & 0xFF00);
3152 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003153 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303154 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003155 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303156 tempcx = (pVBInfo->VGAVT - 1);
3157 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003158
Aaro Koskinen8104e322011-03-13 12:26:22 +02003159 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303160 tempbx = pVBInfo->VGAVDE - 1;
3161 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003162 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303163 temp = ((tempbx & 0xFF00) << 3) >> 8;
3164 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003165 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303167 tempax = pVBInfo->VGAVDE;
3168 tempbx = pVBInfo->VGAVDE;
3169 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003170 /* BTVGA2VRS 0x10,0x11 */
3171 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3172 /* BTVGA2VRE 0x11 */
3173 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303175 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003176 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
3177 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003178
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303179 if (temp & 0x04)
3180 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003181
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303182 if (temp & 0x080)
3183 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003184
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003185 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303187 if (temp & 0x08)
3188 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003189
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003190 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303191 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3192 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003193
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303194 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003195 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303196 temp = ((tempbx & 0xFF00) >> 8) << 4;
3197 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003198 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303199 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003200
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303201 if (modeflag & DoubleScanMode)
3202 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303204 if (modeflag & HalfDCLK)
3205 tempax |= 0x40;
3206
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003207 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003208}
3209
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003210static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3211{
3212 unsigned long tempax, tempbx;
3213
3214 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3215 & 0xFFFF;
3216 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3217 tempax = (tempax * pVBInfo->HT) / tempbx;
3218
3219 return (unsigned short) tempax;
3220}
3221
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003222static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303223 struct xgi_hw_device_info *HwDeviceExtension,
3224 unsigned short RefreshRateTableIndex,
3225 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003226{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303227 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
3228 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003229
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003230 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003231 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3232 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003233 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003234 CRT1Index &= IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003235
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303236 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3237 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303239 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003240 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303241 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003242
Peter Huewe6896b942012-02-09 21:11:46 +01003243 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303244 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303246 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003247
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303248 if (modeflag & HalfDCLK)
3249 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003250
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303251 tempax = (tempax / tempcx) - 1;
3252 tempbx |= ((tempax & 0x00FF) << 8);
3253 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003254 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303256 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003257
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303258 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003259 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3260 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303261 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003262
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003263 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3264 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303265 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303266 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003267
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003268 /* 0x05 Horizontal Display Start */
3269 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3270 /* 0x06 Horizontal Blank end */
3271 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003272
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303273 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3274 if (pVBInfo->VBInfo & SetCRT2ToTV)
3275 tempax = pVBInfo->VGAHT;
3276 else
3277 tempax = XGI_GetVGAHT2(pVBInfo);
3278 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303280 if (tempax >= pVBInfo->VGAHT)
3281 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003282
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303283 if (modeflag & HalfDCLK)
3284 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003285
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303286 tempax = (tempax / tempcx) - 5;
3287 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003288 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303289 temp = (tempbx & 0x00FF) - 1;
3290 if (!(modeflag & HalfDCLK)) {
3291 temp -= 6;
3292 if (pVBInfo->TVInfo & TVSimuMode) {
3293 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003294 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303295 }
3296 }
3297 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303298 tempbx = (tempbx & 0xFF00) >> 8;
3299 tempcx = (tempcx + tempbx) >> 1;
3300 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003301
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303302 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3303 temp -= 1;
3304 if (!(modeflag & HalfDCLK)) {
3305 if ((modeflag & Charx8Dot)) {
3306 temp += 4;
3307 if (pVBInfo->VGAHDE >= 800)
3308 temp -= 6;
3309 }
3310 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003311 } else if (!(modeflag & HalfDCLK)) {
3312 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003313 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003314 pVBInfo->VGAHDE >= 800) {
3315 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003316 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003317 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003318 (pVBInfo->LCDInfo & LCDNonExpanding))
3319 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303320 }
3321 }
3322 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003323
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003324 /* 0x07 Horizontal Retrace Start */
3325 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3326 /* 0x08 Horizontal Retrace End */
3327 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003328
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303329 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3330 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003331 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303332 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003333 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303334 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003335 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303336 0x08, 0x03);
3337 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003338 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303339 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003340 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303341 0x08, 0x02);
3342 }
3343 }
3344 }
3345 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003346
Aaro Koskinen8104e322011-03-13 12:26:22 +02003347 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003348 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003349 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003350
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303351 tempbx = pVBInfo->VGAVT;
3352 push1 = tempbx;
3353 tempcx = 0x121;
3354 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003355
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303356 if (tempbx == 357)
3357 tempbx = 350;
3358 if (tempbx == 360)
3359 tempbx = 350;
3360 if (tempbx == 375)
3361 tempbx = 350;
3362 if (tempbx == 405)
3363 tempbx = 400;
3364 if (tempbx == 525)
3365 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003366
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303367 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003368
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303369 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003370 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003371 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303372 if (tempbx == 350)
3373 tempbx += 5;
3374 if (tempbx == 480)
3375 tempbx += 5;
3376 }
3377 }
3378 }
3379 tempbx--;
3380 temp = tempbx & 0x00FF;
3381 tempbx--;
3382 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003383 /* 0x10 vertical Blank Start */
3384 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303385 tempbx = push2;
3386 tempbx--;
3387 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003388 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003389
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303390 if (tempbx & 0x0100)
3391 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303393 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003394
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303395 if (modeflag & DoubleScanMode)
3396 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003397
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303398 if (tempbx & 0x0200)
3399 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003400
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303401 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003402 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003403
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303404 if (tempbx & 0x0400)
3405 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003406
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003407 /* 0x11 Vertival Blank End */
3408 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303409
3410 tempax = push1;
3411 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3412 tempax = tempax >> 2;
3413 push1 = tempax; /* push ax */
3414
3415 if (resinfo != 0x09) {
3416 tempax = tempax << 1;
3417 tempbx += tempax;
3418 }
3419
Peter Huewe599801f2012-02-09 21:11:45 +01003420 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003421 if ((pVBInfo->VBType & VB_SIS301LV) &&
3422 !(pVBInfo->TVInfo & TVSetHiVision)) {
3423 if ((pVBInfo->TVInfo & TVSimuMode) &&
3424 (pVBInfo->TVInfo & TVSetPAL)) {
3425 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3426 !(pVBInfo->TVInfo &
3427 (TVSetYPbPr525p |
3428 TVSetYPbPr750p |
3429 TVSetHiVision)))
3430 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303431 }
3432 } else {
3433 tempbx -= 10;
3434 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003435 } else if (pVBInfo->TVInfo & TVSimuMode) {
3436 if (pVBInfo->TVInfo & TVSetPAL) {
3437 if (pVBInfo->VBType & VB_SIS301LV) {
3438 if (!(pVBInfo->TVInfo &
3439 (TVSetYPbPr525p |
3440 TVSetYPbPr750p |
3441 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303442 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003443 } else {
3444 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303445 }
3446 }
3447 }
3448 tempax = push1;
3449 tempax = tempax >> 2;
3450 tempax++;
3451 tempax += tempbx;
3452 push1 = tempax; /* push ax */
3453
Peter Huewe599801f2012-02-09 21:11:45 +01003454 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303455 if (tempbx <= 513) {
3456 if (tempax >= 513)
3457 tempbx = 513;
3458 }
3459 }
3460
3461 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003462 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303463 tempbx--;
3464 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003465 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303466
3467 if (tempbx & 0x0100)
3468 tempcx |= 0x0008;
3469
3470 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003471 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303472
3473 tempbx++;
3474
3475 if (tempbx & 0x0100)
3476 tempcx |= 0x0004;
3477
3478 if (tempbx & 0x0200)
3479 tempcx |= 0x0080;
3480
3481 if (tempbx & 0x0400)
3482 tempcx |= 0x0C00;
3483
3484 tempbx = push1; /* pop ax */
3485 temp = tempbx & 0x00FF;
3486 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003487 /* 0x0D vertical Retrace End */
3488 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303489
3490 if (tempbx & 0x0010)
3491 tempcx |= 0x2000;
3492
3493 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003494 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003496 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303497 tempax = modeflag;
3498 temp = (tempax & 0xFF00) >> 8;
3499
3500 temp = (temp >> 1) & 0x09;
3501
Peter Huewe6896b942012-02-09 21:11:46 +01003502 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303503 temp |= 0x01;
3504
Aaro Koskinen8104e322011-03-13 12:26:22 +02003505 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3506 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3507 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303508
3509 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3510 temp = 0x80;
3511 else
3512 temp = 0x00;
3513
Aaro Koskinen8104e322011-03-13 12:26:22 +02003514 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303515
3516 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003517}
3518
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003519static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303520 unsigned short RefreshRateTableIndex,
3521 struct xgi_hw_device_info *HwDeviceExtension,
3522 struct vb_device_info *pVBInfo)
3523{
3524 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
3525 modeflag, resinfo, crt2crtc;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003526 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303527
3528 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3529
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003530 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003531 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3532 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003533 crt2crtc = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303534
3535 tempax = 0;
3536
3537 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3538 tempax |= 0x0800;
3539
3540 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3541 tempax |= 0x0400;
3542
3543 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3544 tempax |= 0x0200;
3545
Peter Huewe599801f2012-02-09 21:11:45 +01003546 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303547 tempax |= 0x1000;
3548
Peter Huewe599801f2012-02-09 21:11:45 +01003549 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303550 tempax |= 0x0100;
3551
Peter Huewe599801f2012-02-09 21:11:45 +01003552 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303553 tempax &= 0xfe00;
3554
3555 tempax = (tempax & 0xff00) >> 8;
3556
Aaro Koskinen8104e322011-03-13 12:26:22 +02003557 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003558 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303559
Peter Huewe599801f2012-02-09 21:11:45 +01003560 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003561 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303562
Peter Huewe599801f2012-02-09 21:11:45 +01003563 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003564 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303565
3566 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003567 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303568
3569 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003570 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303571
3572 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003573 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303574 }
3575
Peter Huewe599801f2012-02-09 21:11:45 +01003576 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3577 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003578 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303579
Peter Huewe599801f2012-02-09 21:11:45 +01003580 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003581 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303582
Peter Huewe599801f2012-02-09 21:11:45 +01003583 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003584 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303585 }
3586
3587 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003588 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303589
3590 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003591 /* di->temp2[j] */
3592 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303593
3594 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003595 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303596
3597 temp = pVBInfo->NewFlickerMode;
3598 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003599 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303600
Peter Huewe599801f2012-02-09 21:11:45 +01003601 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303602 tempax = 950;
3603
Peter Huewe599801f2012-02-09 21:11:45 +01003604 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303605 tempax = 520;
3606 else
3607 tempax = 440;
3608
3609 if (pVBInfo->VDE <= tempax) {
3610 tempax -= pVBInfo->VDE;
3611 tempax = tempax >> 2;
3612 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3613 push1 = tempax;
3614 temp = (tempax & 0xFF00) >> 8;
3615 temp += (unsigned short) TimingPoint[0];
3616
Peter Huewe6896b942012-02-09 21:11:46 +01003617 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3618 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303619 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3620 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003621 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303622 tempcx = pVBInfo->VGAHDE;
3623 if (tempcx >= 1024) {
3624 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003625 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303626 temp = 0x19; /* PAL */
3627 }
3628 }
3629 }
3630
Aaro Koskinen8104e322011-03-13 12:26:22 +02003631 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303632 tempax = push1;
3633 temp = (tempax & 0xFF00) >> 8;
3634 temp += TimingPoint[1];
3635
Peter Huewe6896b942012-02-09 21:11:46 +01003636 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3637 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303638 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3639 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003640 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303641 tempcx = pVBInfo->VGAHDE;
3642 if (tempcx >= 1024) {
3643 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003644 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303645 temp = 0x52; /* PAL */
3646 }
3647 }
3648 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003649 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303650 }
3651
3652 /* 301b */
3653 tempcx = pVBInfo->HT;
3654
3655 if (XGI_IsLCDDualLink(pVBInfo))
3656 tempcx = tempcx >> 1;
3657
3658 tempcx -= 2;
3659 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003660 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303661
3662 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003663 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303664
3665 tempcx = pVBInfo->HT >> 1;
3666 push1 = tempcx; /* push cx */
3667 tempcx += 7;
3668
Peter Huewe599801f2012-02-09 21:11:45 +01003669 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303670 tempcx -= 4;
3671
3672 temp = tempcx & 0x00FF;
3673 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003674 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303675
3676 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3677 tempbx += tempcx;
3678 push2 = tempbx;
3679 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003680 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303681 temp = (tempbx & 0xFF00) >> 8;
3682 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003683 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303684
3685 tempbx = push2;
3686 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003687 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303688 tempbx = tempbx - 4;
3689 tempcx = tempbx;
3690 }
3691
3692 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003693 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303694
3695 j += 2;
3696 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3697 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003698 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303699 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003700 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303701
3702 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003703 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303704 tempcx -= 4;
3705
3706 temp = tempcx & 0xFF;
3707 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003708 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303709
3710 tempcx = push1; /* pop cx */
3711 j += 2;
3712 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3713 tempcx -= temp;
3714 temp = tempcx & 0x00FF;
3715 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003716 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303717
3718 tempcx -= 11;
3719
3720 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3721 tempax = XGI_GetVGAHT2(pVBInfo);
3722 tempcx = tempax - 1;
3723 }
3724 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003725 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303726
3727 tempbx = pVBInfo->VDE;
3728
3729 if (pVBInfo->VGAVDE == 360)
3730 tempbx = 746;
3731 if (pVBInfo->VGAVDE == 375)
3732 tempbx = 746;
3733 if (pVBInfo->VGAVDE == 405)
3734 tempbx = 853;
3735
3736 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003737 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003738 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003739 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003740 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303741 tempbx = tempbx >> 1;
3742 } else
3743 tempbx = tempbx >> 1;
3744 }
3745
3746 tempbx -= 2;
3747 temp = tempbx & 0x00FF;
3748
Peter Huewe599801f2012-02-09 21:11:45 +01003749 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003750 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003751 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303752 if (pVBInfo->VBInfo & SetInSlaveMode) {
3753 if (ModeNo == 0x2f)
3754 temp += 1;
3755 }
3756 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003757 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3758 if (ModeNo == 0x2f)
3759 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303760 }
3761 }
3762
Aaro Koskinen8104e322011-03-13 12:26:22 +02003763 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303764
3765 temp = (tempcx & 0xFF00) >> 8;
3766 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3767
Peter Huewe599801f2012-02-09 21:11:45 +01003768 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003769 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003770 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303771 temp |= 0x10;
3772
3773 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3774 temp |= 0x20;
3775 }
3776 } else {
3777 temp |= 0x10;
3778 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3779 temp |= 0x20;
3780 }
3781 }
3782
Aaro Koskinen8104e322011-03-13 12:26:22 +02003783 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303784
Peter Huewe6896b942012-02-09 21:11:46 +01003785 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3786 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303787 tempbx = pVBInfo->VDE;
3788 tempcx = tempbx - 2;
3789
3790 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003791 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3792 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303793 tempbx = tempbx >> 1;
3794 }
3795
Peter Huewe6896b942012-02-09 21:11:46 +01003796 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303797 temp = 0;
3798 if (tempcx & 0x0400)
3799 temp |= 0x20;
3800
3801 if (tempbx & 0x0400)
3802 temp |= 0x40;
3803
Aaro Koskinen8104e322011-03-13 12:26:22 +02003804 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303805 }
3806
3807 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003808 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303809 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003810 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303811 }
3812
3813 tempbx = tempbx & 0x00FF;
3814
3815 if (!(modeflag & HalfDCLK)) {
3816 tempcx = pVBInfo->VGAHDE;
3817 if (tempcx >= pVBInfo->HDE) {
3818 tempbx |= 0x2000;
3819 tempax &= 0x00FF;
3820 }
3821 }
3822
3823 tempcx = 0x0101;
3824
3825 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3826 if (pVBInfo->VGAHDE >= 1024) {
3827 tempcx = 0x1920;
3828 if (pVBInfo->VGAHDE >= 1280) {
3829 tempcx = 0x1420;
3830 tempbx = tempbx & 0xDFFF;
3831 }
3832 }
3833 }
3834
3835 if (!(tempbx & 0x2000)) {
3836 if (modeflag & HalfDCLK)
3837 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3838
3839 push1 = tempbx;
3840 tempeax = pVBInfo->VGAHDE;
3841 tempebx = (tempcx & 0xFF00) >> 8;
3842 longtemp = tempeax * tempebx;
3843 tempecx = tempcx & 0x00FF;
3844 longtemp = longtemp / tempecx;
3845
3846 /* 301b */
3847 tempecx = 8 * 1024;
3848
Peter Huewe6896b942012-02-09 21:11:46 +01003849 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3850 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303851 tempecx = tempecx * 8;
3852 }
3853
3854 longtemp = longtemp * tempecx;
3855 tempecx = pVBInfo->HDE;
3856 temp2 = longtemp % tempecx;
3857 tempeax = longtemp / tempecx;
3858 if (temp2 != 0)
3859 tempeax += 1;
3860
3861 tempax = (unsigned short) tempeax;
3862
3863 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003864 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3865 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303866 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3867 }
3868 /* end 301b */
3869
3870 tempbx = push1;
3871 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3872 | (tempbx & 0x00FF));
3873 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3874 | (tempax & 0x00FF));
3875 temp = (tempax & 0xFF00) >> 8;
3876 } else {
3877 temp = (tempax & 0x00FF) >> 8;
3878 }
3879
Aaro Koskinen8104e322011-03-13 12:26:22 +02003880 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303881 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003882 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303883 temp = tempcx & 0x00FF;
3884
3885 if (tempbx & 0x2000)
3886 temp = 0;
3887
3888 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3889 temp |= 0x18;
3890
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003891 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003892 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303893 tempbx = 0x0382;
3894 tempcx = 0x007e;
3895 } else {
3896 tempbx = 0x0369;
3897 tempcx = 0x0061;
3898 }
3899
3900 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003901 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303902 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003903 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303904
3905 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3906 temp = temp << 2;
3907 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3908
Peter Huewe599801f2012-02-09 21:11:45 +01003909 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303910 temp |= 0x10;
3911
Peter Huewe599801f2012-02-09 21:11:45 +01003912 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303913 temp |= 0x20;
3914
Peter Huewe599801f2012-02-09 21:11:45 +01003915 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303916 temp |= 0x60;
3917 }
3918
Aaro Koskinen8104e322011-03-13 12:26:22 +02003919 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003920 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003921 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303922
Peter Huewe599801f2012-02-09 21:11:45 +01003923 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303924 if (pVBInfo->TVInfo & NTSC1024x768) {
3925 TimingPoint = XGI_NTSC1024AdjTime;
3926 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003927 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303928 TimingPoint[j]);
3929 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003930 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303931 }
3932 }
3933
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003934 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303935 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003936 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003937 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303938 0x08); /* PALM Mode */
3939 }
3940
Peter Huewe599801f2012-02-09 21:11:45 +01003941 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003942 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303943 0x01);
3944 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003945 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303946
Aaro Koskinendc505562011-03-13 12:26:26 +02003947 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303948 }
3949
Peter Huewe599801f2012-02-09 21:11:45 +01003950 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303951 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003952 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303953 }
3954
3955 if (pVBInfo->VBInfo & SetCRT2ToTV)
3956 return;
3957}
3958
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003959static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303960 struct xgi_hw_device_info *HwDeviceExtension,
3961 unsigned short RefreshRateTableIndex,
3962 struct vb_device_info *pVBInfo)
3963{
3964 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
3965 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
3966
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003967 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303968
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003969 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003970 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3971 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003972 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003973 CRT1Index &= IndexMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303974
3975 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3976 return;
3977
3978 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3979
3980 if (XGI_IsLCDDualLink(pVBInfo))
3981 tempbx = tempbx >> 1;
3982
3983 tempbx -= 1;
3984 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003985 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303986 temp = (tempbx & 0xFF00) >> 8;
3987 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003988 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303989 temp = 0x01;
3990
Aaro Koskinen8104e322011-03-13 12:26:22 +02003991 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303992 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
3993 push1 = tempbx;
3994 tempbx--;
3995 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003996 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303997 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003998 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303999
4000 tempcx = pVBInfo->VT - 1;
4001 push2 = tempcx + 1;
4002 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004003 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304004 temp = (tempcx & 0xFF00) >> 8;
4005 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004006 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004007 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
4008 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
4009 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
4010 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304011
Justin P. Mattock558f7582012-10-02 21:17:11 -07004012 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02004013 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
4014 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
4015 RefreshRateTableIndex, pVBInfo);
4016 else
4017 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
4018 ModeIdIndex, RefreshRateTableIndex,
4019 pVBInfo);
4020
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304021 tempah = pVBInfo->LCDResInfo;
4022 tempah &= PanelResInfo;
4023
Peter Huewe255aabd2012-02-09 21:11:44 +01004024 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304025 tempbx = 1024;
4026 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01004027 } else if ((tempah == Panel_1280x1024) ||
4028 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304029 tempbx = 1280;
4030 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01004031 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304032 tempbx = 1400;
4033 tempcx = 1050;
4034 } else {
4035 tempbx = 1600;
4036 tempcx = 1200;
4037 }
4038
4039 if (pVBInfo->LCDInfo & EnableScalingLCD) {
4040 tempbx = pVBInfo->HDE;
4041 tempcx = pVBInfo->VDE;
4042 }
4043
4044 pushbx = tempbx;
4045 tempax = pVBInfo->VT;
4046 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
4047 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
4048 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
4049 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
4050 tempbx = pVBInfo->LCDVDES;
4051 tempcx += tempbx;
4052
4053 if (tempcx >= tempax)
4054 tempcx -= tempax; /* lcdvdes */
4055
4056 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004057 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304058 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004059 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304060 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
4061 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
4062 tempah = tempch;
4063 tempah = tempah << 3;
4064 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004065 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304066
4067 /* getlcdsync() */
4068 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4069 tempcx = tempbx;
4070 tempax = pVBInfo->VT;
4071 tempbx = pVBInfo->LCDVRS;
4072
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304073 tempcx += tempbx;
4074 if (tempcx >= tempax)
4075 tempcx -= tempax;
4076
4077 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004078 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304079 temp = (tempbx & 0xFF00) >> 8;
4080 temp = temp << 4;
4081 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004082 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304083 tempcx = pushbx;
4084 tempax = pVBInfo->HT;
4085 tempbx = pVBInfo->LCDHDES;
4086 tempbx &= 0x0FFF;
4087
4088 if (XGI_IsLCDDualLink(pVBInfo)) {
4089 tempax = tempax >> 1;
4090 tempbx = tempbx >> 1;
4091 tempcx = tempcx >> 1;
4092 }
4093
Peter Huewe6896b942012-02-09 21:11:46 +01004094 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304095 tempbx += 1;
4096
4097 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
4098 tempbx += 1;
4099
4100 tempcx += tempbx;
4101
4102 if (tempcx >= tempax)
4103 tempcx -= tempax;
4104
4105 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004106 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304107 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004108 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304109 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004110 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304111 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004112 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304114 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4115 tempcx = tempax;
4116 tempax = pVBInfo->HT;
4117 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304118 if (XGI_IsLCDDualLink(pVBInfo)) {
4119 tempax = tempax >> 1;
4120 tempbx = tempbx >> 1;
4121 tempcx = tempcx >> 1;
4122 }
4123
Peter Huewe6896b942012-02-09 21:11:46 +01004124 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304125 tempbx += 1;
4126
4127 tempcx += tempbx;
4128
4129 if (tempcx >= tempax)
4130 tempcx -= tempax;
4131
4132 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004133 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304134
4135 temp = (tempbx & 0xFF00) >> 8;
4136 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004137 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304138 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004139 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304140
Peter Huewea3d675c2012-02-09 21:11:47 +01004141 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304142 if (pVBInfo->VGAVDE == 525) {
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 = 0xC6;
4147 } else
4148 temp = 0xC4;
4149
Aaro Koskinen8104e322011-03-13 12:26:22 +02004150 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4151 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304152 }
4153
4154 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004155 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4156 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304157 | VB_XGI301C)) {
4158 temp = 0x4F;
4159 } else
4160 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004161 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304162 }
4163 }
4164}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004165
4166/* --------------------------------------------------------------------- */
4167/* Function : XGI_GetTap4Ptr */
4168/* Input : */
4169/* Output : di -> Tap4 Reg. Setting Pointer */
4170/* Description : */
4171/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004172static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304173 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004174{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304175 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004176
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304177 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004178
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304179 if (tempcx == 0) {
4180 tempax = pVBInfo->VGAHDE;
4181 tempbx = pVBInfo->HDE;
4182 } else {
4183 tempax = pVBInfo->VGAVDE;
4184 tempbx = pVBInfo->VDE;
4185 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004186
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004187 if (tempax <= tempbx)
4188 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304189 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004190 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004191
Peter Huewe599801f2012-02-09 21:11:45 +01004192 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304193 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004194
Peter Huewe599801f2012-02-09 21:11:45 +01004195 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4196 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4197 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004198 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004199 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304200 Tap4TimingPtr = YPbPr750pTap4Timing;
4201 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004202
Peter Huewe599801f2012-02-09 21:11:45 +01004203 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004204 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004205
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304206 i = 0;
4207 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4208 if (Tap4TimingPtr[i].DE == tempax)
4209 break;
4210 i++;
4211 }
4212 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004213}
4214
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004215static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004216{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304217 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304219 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004220
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304221 if (!(pVBInfo->VBType & VB_XGI301C))
4222 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304224 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4225 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004226 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004227
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004228 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004229 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004230 /* Set Vertical Scaling */
4231 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304232 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004233 xgifb_reg_set(pVBInfo->Part2Port,
4234 i,
4235 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304236 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004237
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004238 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004239 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004240 /* Enable V.Scaling */
4241 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304242 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004243 /* Enable H.Scaling */
4244 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004245}
4246
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004247static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304248 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004249{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304250 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004251 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304252 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004253
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004254 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004255 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004256
Aaro Koskinen8104e322011-03-13 12:26:22 +02004257 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004258 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004259 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4260 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304261 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004262 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4263 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304264 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004265
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304266 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4267 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004268
Peter Huewe599801f2012-02-09 21:11:45 +01004269 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004270 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4271 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4272 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
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->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4276 & SetCRT2ToYPbPr525750)) {
4277 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304278 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004279
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004280 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304281 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004282 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304283 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004284 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304285 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004286
Peter Huewe599801f2012-02-09 21:11:45 +01004287 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004288 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004289
Peter Huewe599801f2012-02-09 21:11:45 +01004290 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004291 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004292
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304293 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004294 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004295
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304296 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004297 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004298 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304299 }
4300 }
4301 return;
4302} /* {end of XGI_SetGroup3} */
4303
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004304static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304305 unsigned short RefreshRateTableIndex,
4306 struct xgi_hw_device_info *HwDeviceExtension,
4307 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004308{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304309 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004310
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304311 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004312
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004313 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004314 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304315 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004316 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004317
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304318 tempbx = pVBInfo->RVBHCMAX;
4319 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004320 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304321 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4322 tempcx = pVBInfo->VGAHT - 1;
4323 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004324 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004325
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304326 temp = ((tempcx & 0xFF00) >> 8) << 3;
4327 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004328
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304329 tempcx = pVBInfo->VGAVT - 1;
4330 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4331 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004332
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304333 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004334 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304335 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004336 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004337 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304338 tempcx = pVBInfo->VBInfo;
4339 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304341 if (modeflag & HalfDCLK)
4342 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304344 if (XGI_IsLCDDualLink(pVBInfo))
4345 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004346
Peter Huewe599801f2012-02-09 21:11:45 +01004347 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304348 temp = 0;
4349 if (tempbx <= 1024)
4350 temp = 0xA0;
4351 if (tempbx == 1280)
4352 temp = 0xC0;
4353 } else if (tempcx & SetCRT2ToTV) {
4354 temp = 0xA0;
4355 if (tempbx <= 800)
4356 temp = 0x80;
4357 } else {
4358 temp = 0x80;
4359 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4360 temp = 0;
4361 if (tempbx > 800)
4362 temp = 0x60;
4363 }
4364 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004365
Peter Huewe599801f2012-02-09 21:11:45 +01004366 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304367 temp = 0x00;
4368 if (pVBInfo->VGAHDE == 1280)
4369 temp = 0x40;
4370 if (pVBInfo->VGAHDE == 1024)
4371 temp = 0x20;
4372 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004373 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004374
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304375 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004376
Peter Huewe599801f2012-02-09 21:11:45 +01004377 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304378 if (!(temp & 0xE000))
4379 tempbx = tempbx >> 1;
4380 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004381
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304382 tempcx = pVBInfo->RVBHRS;
4383 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004384 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004385
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304386 tempeax = pVBInfo->VGAVDE;
4387 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004388
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304389 if (tempeax <= tempebx) {
4390 tempcx = (tempcx & (~0x4000));
4391 tempeax = pVBInfo->VGAVDE;
4392 } else {
4393 tempeax -= tempebx;
4394 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004395
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304396 templong = (tempeax * 256 * 1024) % tempebx;
4397 tempeax = (tempeax * 256 * 1024) / tempebx;
4398 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004399
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304400 if (templong != 0)
4401 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004402
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304403 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004404 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004405
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304406 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004407 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304408 tempbx = (unsigned short) (tempebx >> 16);
4409 temp = tempbx & 0x00FF;
4410 temp = temp << 4;
4411 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004412 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304414 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004415 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4416 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304417 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004418 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304419 tempax = pVBInfo->VGAHDE;
4420 if (modeflag & HalfDCLK)
4421 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004422
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304423 if (XGI_IsLCDDualLink(pVBInfo))
4424 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004425
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304426 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4427 if (tempax > 800)
4428 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004429 } else if (pVBInfo->VGAHDE > 800) {
4430 if (pVBInfo->VGAHDE == 1024)
4431 tempax = (tempax * 25 / 32) - 1;
4432 else
4433 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304434 }
4435 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004436
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304437 temp = (tempax & 0xFF00) >> 8;
4438 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004439 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304440 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004441 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004442
Peter Huewe599801f2012-02-09 21:11:45 +01004443 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304444 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004445 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004446
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304447 }
4448 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004449
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304450 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4451 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004452 | TVSetYPbPr525p | TVSetYPbPr750p
4453 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304454 temp |= 0x0001;
4455 if ((pVBInfo->VBInfo & SetInSlaveMode)
4456 && (!(pVBInfo->TVInfo
4457 & TVSimuMode)))
4458 temp &= (~0x0001);
4459 }
4460 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004461
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004462 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304463 tempbx = pVBInfo->HT;
4464 if (XGI_IsLCDDualLink(pVBInfo))
4465 tempbx = tempbx >> 1;
4466 tempbx = (tempbx >> 1) - 2;
4467 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004468 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304469 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004470 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304471 }
4472 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004473
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004474 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004475}
4476
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004477static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4478{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004479 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004480}
4481
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004482static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304483 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004484{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304485 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004486
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304487 Pindex = pVBInfo->Part5Port;
4488 Pdata = pVBInfo->Part5Port + 1;
4489 if (pVBInfo->ModeType == ModeVGA) {
4490 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004491 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304492 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304493 }
4494 }
4495 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004496}
4497
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004498static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304499 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004500{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004501 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004502}
4503
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004504static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304505 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004506{
4507
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004508 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004509}
4510
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004511static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4512 unsigned short ModeNo, unsigned short ModeIdIndex,
4513 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004514{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004515 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004516
Aaro Koskinenb3979922012-11-04 21:14:52 +02004517 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004518 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
4519 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
4520 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004521 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004522
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304523 if (!(modeflag & Charx8Dot)) {
4524 xres /= 9;
4525 xres *= 8;
4526 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004527
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004528 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4529 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004530
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004531 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4532 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004533
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004534 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304535 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004536
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004537 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304538 return 0;
4539
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004540 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4541 yres != xgifb_info->lvds_data.LVDSVDE) {
4542 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4543 if (colordepth > 2)
4544 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304545 }
4546 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004547}
4548
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004549static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4550 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004551 unsigned short ModeNo,
4552 unsigned short ModeIdIndex,
4553 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004554{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304555 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004556 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304557 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4558 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4559 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004560
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004561 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004562 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304563 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004564 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004565
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004566 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004567
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004568 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004569 /* SR35[7] FP VSync polarity */
4570 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4571 /* SR30[5] FP HSync polarity */
4572 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004573
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004574 if (chip_id == XG27)
4575 XGI_SetXG27FPBits(pVBInfo);
4576 else
4577 XGI_SetXG21FPBits(pVBInfo);
4578
Aaro Koskinenb3979922012-11-04 21:14:52 +02004579 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004580 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
4581 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
4582 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004583 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004584
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304585 if (!(modeflag & Charx8Dot))
4586 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004587
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004588 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004589
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004590 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004591
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304592 if (LVDSHBS > LVDSHT)
4593 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004594
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004595 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304596 if (LVDSHRS > LVDSHT)
4597 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004598
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004599 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304600 if (LVDSHRE > LVDSHT)
4601 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004602
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004603 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004604
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004605 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004606
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004607 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004608 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304609 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004610
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304611 if (LVDSVBS > LVDSVT)
4612 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004613
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004614 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304615 if (LVDSVRS > LVDSVT)
4616 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004617
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004618 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304619 if (LVDSVRE > LVDSVT)
4620 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004621
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004622 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004623
Aaro Koskinen58839b02011-03-13 12:26:23 +02004624 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004625 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004626
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304627 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004628 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004629
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304630 /* HT SR0B[1:0] CR00 */
4631 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004632 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004633 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004634
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304635 /* HBS SR0B[5:4] CR02 */
4636 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004637 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004638 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004639
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304640 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4641 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004642 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4643 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4644 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304646 /* HRS SR0B[7:6] CR04 */
4647 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004648 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004649 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004650
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304651 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4652 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004653 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004654 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004655
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304656 /* HRE SR0C[2] CR05[4:0] */
4657 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004658 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4659 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004660
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304661 /* Panel HRE SR2F[7:2] */
4662 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004663 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004664
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304665 /* VT SR0A[0] CR07[5][0] CR06 */
4666 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004667 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4668 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4669 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004670 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004671
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304672 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4673 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004674 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4675 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4676 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004677 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004678
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304679 /* VBE SR0A[4] CR16 */
4680 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004681 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004682 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004683
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304684 /* VRS SR0A[3] CR7[7][2] CR10 */
4685 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004686 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4687 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4688 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004689 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004690
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004691 if (chip_id == XG27) {
4692 /* Panel VRS SR35[2:0] SR34[7:0] */
4693 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4694 (value & 0x700) >> 8);
4695 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4696 } else {
4697 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4698 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4699 (value & 0x600) >> 9);
4700 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4701 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4702 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004703
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304704 /* VRE SR0A[5] CR11[3:0] */
4705 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004706 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4707 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004708
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304709 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004710 if (chip_id == XG27)
4711 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4712 (value << 2) & 0xFC);
4713 else
4714 /* SR3F[7] has to be 0, h/w bug */
4715 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4716 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004717
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304718 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004719
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004720 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004721 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004722 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004723 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004724 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304725 value += 0x10;
4726 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004727
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304728 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004729 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004730 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004731 /* set data, panning = 0, shift left 1 dot*/
4732 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004733
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004734 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004735 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304736
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004737 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304738 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004739
4740}
4741
4742/* --------------------------------------------------------------------- */
4743/* Function : XGI_IsLCDON */
4744/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004745/* Output : 0 : Skip PSC Control */
4746/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004747/* Description : */
4748/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004749static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004750{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304751 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004752
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304753 tempax = pVBInfo->VBInfo;
4754 if (tempax & SetCRT2ToDualEdge)
4755 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004756 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304757 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004758
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304759 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004760}
4761
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004762/* --------------------------------------------------------------------- */
4763/* Function : XGI_DisableChISLCD */
4764/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004765/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004766/* Description : */
4767/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004768static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004769{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304770 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004771
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304772 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004773 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004774
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304775 if (tempbx & (EnableChA | DisableChA)) {
4776 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4777 return 0;
4778 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004779
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304780 if (!(tempbx & (EnableChB | DisableChB)))
4781 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004782
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304783 if (tempah & 0x01) /* Chk LCDB Mode */
4784 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304786 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004787}
4788
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004789/* --------------------------------------------------------------------- */
4790/* Function : XGI_EnableChISLCD */
4791/* Input : */
4792/* Output : 0 -> Not LCD mode */
4793/* Description : */
4794/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004795static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004796{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304797 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004798
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304799 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004800 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304802 if (tempbx & (EnableChA | DisableChA)) {
4803 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4804 return 0;
4805 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004806
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304807 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04004808 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004809
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304810 if (tempah & 0x01) /* Chk LCDB Mode */
4811 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004812
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304813 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004814}
4815
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004816static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4817 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304818 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004819{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004820 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004821
Peter Huewe6896b942012-02-09 21:11:46 +01004822 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4823 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304824 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004825 if (!(pVBInfo->VBInfo &
4826 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004827 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304828 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
4829 tempah = 0x7F; /* Disable Channel A */
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004830 if (!(pVBInfo->VBInfo &
4831 XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004832 /* Disable Channel B */
4833 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004834
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304835 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004836 /* force to disable Cahnnel */
4837 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004838
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304839 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004840 /* Force to disable Channel B */
4841 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304842 }
4843 }
4844 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004845
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004846 /* disable part4_1f */
4847 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004848
Peter Huewe6896b942012-02-09 21:11:46 +01004849 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004850 if (((pVBInfo->VBInfo &
4851 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4852 || (XGI_DisableChISLCD(pVBInfo))
4853 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004854 /* LVDS Driver power down */
4855 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304856 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004857
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304858 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004859 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304860 | SetSimuScanMode))) {
4861 if (pVBInfo->SetFlag & GatingCRT)
4862 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004863 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304864 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004865
Peter Huewea3d675c2012-02-09 21:11:47 +01004866 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304867 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004868 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004869 /* Power down */
4870 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304871 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004872
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004873 /* disable TV as primary VGA swap */
4874 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004875
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304876 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004877 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004878
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004879 if ((pVBInfo->SetFlag & DisableChB) ||
4880 (pVBInfo->VBInfo &
4881 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004882 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004883 (pVBInfo->VBInfo &
4884 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004885 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004886
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004887 if ((pVBInfo->SetFlag & DisableChB) ||
4888 (pVBInfo->VBInfo &
4889 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004890 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004891 (pVBInfo->VBInfo &
4892 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4893 /* save Part1 index 0 */
4894 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4895 /* BTDAC = 1, avoid VB reset */
4896 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4897 /* disable CRT2 */
4898 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4899 /* restore Part1 index 0 */
4900 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304901 }
4902 } else { /* {301} */
4903 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004904 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4905 /* Disable CRT2 */
4906 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4907 /* Disable TV asPrimary VGA swap */
4908 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304909 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004910
Peter Huewea3d675c2012-02-09 21:11:47 +01004911 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304912 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004913 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304914 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004915}
4916
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004917/* --------------------------------------------------------------------- */
4918/* Function : XGI_GetTVPtrIndex */
4919/* Input : */
4920/* Output : */
4921/* Description : bx 0 : ExtNTSC */
4922/* 1 : StNTSC */
4923/* 2 : ExtPAL */
4924/* 3 : StPAL */
4925/* 4 : ExtHiTV */
4926/* 5 : StHiTV */
4927/* 6 : Ext525i */
4928/* 7 : St525i */
4929/* 8 : Ext525p */
4930/* 9 : St525p */
4931/* A : Ext750p */
4932/* B : St750p */
4933/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004934static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004935{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304936 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004937
Peter Huewe599801f2012-02-09 21:11:45 +01004938 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304939 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004940 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304941 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004942 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304943 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004944 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304945 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004946 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304947 tempbx = 10;
4948 if (pVBInfo->TVInfo & TVSimuMode)
4949 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004950
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304951 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004952}
4953
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004954/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004955/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004956/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004957/* Output : bx 0 : NTSC */
4958/* 1 : PAL */
4959/* 2 : PALM */
4960/* 3 : PALN */
4961/* 4 : NTSC1024x768 */
4962/* 5 : PAL-M 1024x768 */
4963/* 6-7: reserved */
4964/* cl 0 : YFilter1 */
4965/* 1 : YFilter2 */
4966/* ch 0 : 301A */
4967/* 1 : 301B/302B/301LV/302LV */
4968/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004969/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004970static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4971 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004972{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004973 *tempbx = 0;
4974 *tempcl = 0;
4975 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004976
Peter Huewe599801f2012-02-09 21:11:45 +01004977 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004978 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004979
Peter Huewe599801f2012-02-09 21:11:45 +01004980 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004981 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004982
Peter Huewe599801f2012-02-09 21:11:45 +01004983 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004984 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004985
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004986 if (pVBInfo->TVInfo & NTSC1024x768) {
4987 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004988 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004989 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304990 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004991
Peter Huewe6896b942012-02-09 21:11:46 +01004992 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4993 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004994 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4995 & TVSimuMode)) {
4996 *tempbx += 8;
4997 *tempcl += 1;
4998 }
4999 }
5000
Peter Huewe6896b942012-02-09 21:11:46 +01005001 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5002 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005003 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005004}
5005
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005006static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005007{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305008 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005009
Peter Huewe6896b942012-02-09 21:11:46 +01005010 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5011 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005012 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305013 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305014 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02005015 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305017 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5018 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005019 if (pVBInfo->VBInfo &
5020 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02005021 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005022
Peter Huewea3d675c2012-02-09 21:11:47 +01005023 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305024 tempbl = tempbh;
5025 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005026
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305027 tempbl &= 0x0F;
5028 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02005029 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005030
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305031 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
5032 | SetCRT2ToTV)) { /* Channel B */
5033 tempah &= 0xF0;
5034 tempah |= tempbl;
5035 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005036
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005037 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5038 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305039 tempah &= 0x0F;
5040 tempah |= tempbh;
5041 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005042 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305043 }
5044 } else if (pVBInfo->IF_DEF_LVDS == 1) {
5045 tempbl = 0;
5046 tempbh = 0;
5047 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02005048 tempah = XGI301LCDDelay;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305049 tempah &= 0x0f;
5050 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005051 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305052 tempah);
5053 }
5054 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005055}
5056
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005057static void XGI_SetLCDCap_A(unsigned short tempcx,
5058 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005059{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305060 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005061
Aaro Koskinen58839b02011-03-13 12:26:23 +02005062 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005063
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305064 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005065 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005066 /* Enable Dither */
5067 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005068 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305069 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005070 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305071 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005072 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305073 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005074}
5075
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005076/* --------------------------------------------------------------------- */
5077/* Function : XGI_SetLCDCap_B */
5078/* Input : cx -> LCD Capability */
5079/* Output : */
5080/* Description : */
5081/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005082static void XGI_SetLCDCap_B(unsigned short tempcx,
5083 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005084{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305085 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005086 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305087 (unsigned short) (((tempcx & 0x00ff) >> 6)
5088 | 0x0c));
5089 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005090 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305091 (unsigned short) (((tempcx & 0x00ff) >> 6)
5092 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005093}
5094
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02005095static void XGI_LongWait(struct vb_device_info *pVBInfo)
5096{
5097 unsigned short i;
5098
5099 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5100
5101 if (!(i & 0xC0)) {
5102 for (i = 0; i < 0xFFFF; i++) {
5103 if (!(inb(pVBInfo->P3da) & 0x08))
5104 break;
5105 }
5106
5107 for (i = 0; i < 0xFFFF; i++) {
5108 if ((inb(pVBInfo->P3da) & 0x08))
5109 break;
5110 }
5111 }
5112}
5113
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005114static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005115{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305116 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305118 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005119
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005120 /* disable down spectrum D[4] */
5121 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305122 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005123 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305124 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005125
Aaro Koskinen8104e322011-03-13 12:26:22 +02005126 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305127 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005128 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305129 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005130 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305131 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005132 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305133 pVBInfo->LCDCapList[index].Spectrum_34);
5134 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005135 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005136}
5137
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005138static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5139{
5140 unsigned short tempcx;
5141
5142 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5143
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005144 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005145 (VB_SIS301B |
5146 VB_SIS302B |
5147 VB_SIS301LV |
5148 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005149 VB_XGI301C)) { /* 301LV/302LV only */
5150 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005151 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005152 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005153 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005154 (unsigned char) (tempcx & 0x1F));
5155 }
5156 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005157 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005158 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
5159 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
5160 | EnablePLLSPLOW)) >> 8));
5161 }
5162
Peter Huewe6896b942012-02-09 21:11:46 +01005163 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5164 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005165 if (pVBInfo->VBInfo & SetCRT2ToLCD)
5166 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01005167 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005168 XGI_SetLCDCap_A(tempcx, pVBInfo);
5169
Peter Huewe6896b942012-02-09 21:11:46 +01005170 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005171 if (tempcx & EnableSpectrum)
5172 SetSpectrum(pVBInfo);
5173 }
5174 } else {
5175 /* LVDS,CH7017 */
5176 XGI_SetLCDCap_A(tempcx, pVBInfo);
5177 }
5178}
5179
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005180/* --------------------------------------------------------------------- */
5181/* Function : XGI_SetAntiFlicker */
5182/* Input : */
5183/* Output : */
5184/* Description : Set TV Customized Param. */
5185/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005186static void XGI_SetAntiFlicker(unsigned short ModeNo,
5187 unsigned short ModeIdIndex,
5188 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005189{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03005190 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305192 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005193
Peter Huewe599801f2012-02-09 21:11:45 +01005194 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305195 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005196
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305197 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5198 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305199 tempah = TVAntiFlickList[tempbx];
5200 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005201
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005202 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005203}
5204
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005205static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5206 unsigned short ModeIdIndex,
5207 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005208{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03005209 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305211 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305213 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5214 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305215 tempah = TVEdgeList[tempbx];
5216 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005217
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005218 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005219}
5220
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005221static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005222{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305223 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305225 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305227 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305229 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5230 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005231
Aaro Koskinen8104e322011-03-13 12:26:22 +02005232 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305233 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005234 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305235 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005236 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305237 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005238 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305239 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005240}
5241
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005242static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305243 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005244{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305245 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005246
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305247 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305249 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005250
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305251 switch (tempbx) {
5252 case 0x00:
5253 case 0x04:
5254 filterPtr = NTSCYFilter1;
5255 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305257 case 0x01:
5258 filterPtr = PALYFilter1;
5259 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005260
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305261 case 0x02:
5262 case 0x05:
5263 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305264 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005265 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305266 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005267
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305268 case 0x08:
5269 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305270 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305271 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305272 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005273 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305274 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005275
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305276 default:
5277 return;
5278 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005279
Aaro Koskinenb3979922012-11-04 21:14:52 +02005280 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305281 if (tempcl == 0)
5282 index = tempal * 4;
5283 else
5284 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005285
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305286 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005287 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5288 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5289 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5290 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305291 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005292 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5293 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5294 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5295 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305296 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005297
Peter Huewe6896b942012-02-09 21:11:46 +01005298 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5299 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005300 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5301 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5302 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305303 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005304}
5305
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005306/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005307/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005308/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005309/* Output : */
5310/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005311/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005312static void XGI_OEM310Setting(unsigned short ModeNo,
5313 unsigned short ModeIdIndex,
5314 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005315{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005316 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005317
Peter Huewea3d675c2012-02-09 21:11:47 +01005318 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005319 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005320
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005321 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005322 XGI_SetPhaseIncr(pVBInfo);
5323 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5324 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005325
Peter Huewe6896b942012-02-09 21:11:46 +01005326 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005327 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305328 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005329}
5330
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005331/* --------------------------------------------------------------------- */
5332/* Function : XGI_SetCRT2ModeRegs */
5333/* Input : */
5334/* Output : */
5335/* Description : Origin code for crt2group */
5336/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005337static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305338 struct xgi_hw_device_info *HwDeviceExtension,
5339 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005340{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305341 unsigned short tempbl;
5342 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305344 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305346 tempah = 0;
5347 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005348 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305349 tempah &= ~0x10; /* BTRAMDAC */
5350 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005351
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305352 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5353 | SetCRT2ToLCD)) {
5354 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005355 tempcl = pVBInfo->ModeType;
5356 tempcl -= ModeVGA;
5357 if (tempcl >= 0) {
5358 /* BT Color */
5359 tempah = (0x008 >> tempcl);
5360 if (tempah == 0)
5361 tempah = 1;
5362 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305363 }
5364 if (pVBInfo->VBInfo & SetInSlaveMode)
5365 tempah ^= 0x50; /* BTDAC */
5366 }
5367 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005368
Aaro Koskinen8104e322011-03-13 12:26:22 +02005369 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305370 tempah = 0x08;
5371 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005372
Miguel Gómeze123e462012-07-06 12:40:52 +02005373 if (pVBInfo->VBInfo & DisableCRT2Display)
5374 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005375
Miguel Gómeze123e462012-07-06 12:40:52 +02005376 tempah = 0x00;
5377 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005378
Miguel Gómeze123e462012-07-06 12:40:52 +02005379 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5380 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5381 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005382
Miguel Gómeze123e462012-07-06 12:40:52 +02005383 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5384 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5385 tempbl &= 0xf7;
5386 tempah |= 0x01;
5387 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305388 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005389
Miguel Gómeze123e462012-07-06 12:40:52 +02005390 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5391 tempbl &= 0xf7;
5392 tempah |= 0x01;
5393 }
5394
5395 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5396 goto reg_and_or;
5397
5398 tempbl &= 0xf8;
5399 tempah = 0x01;
5400
5401 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5402 tempah |= 0x02;
5403
5404 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5405 tempah = tempah ^ 0x05;
5406 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5407 tempah = tempah ^ 0x01;
5408 }
5409
5410 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5411 tempah |= 0x08;
5412
5413reg_and_or:
5414 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5415
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305416 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005417 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305418 tempah &= (~0x08);
5419 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5420 & SetInSlaveMode))) {
5421 tempah |= 0x010;
5422 }
5423 tempah |= 0x080;
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 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005427 if (pVBInfo->VBInfo & DriverMode)
5428 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305429 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005430
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005431 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305432 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005433
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305434 if (pVBInfo->LCDInfo & SetLCDDualLink)
5435 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005436
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305437 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305438 if (pVBInfo->TVInfo & RPLLDIV2XO)
5439 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305440 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005441
Peter Huewe255aabd2012-02-09 21:11:44 +01005442 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5443 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305444 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005445
Peter Huewe255aabd2012-02-09 21:11:44 +01005446 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305447 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005448
Aaro Koskinen8104e322011-03-13 12:26:22 +02005449 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305450 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005451
Peter Huewe6896b942012-02-09 21:11:46 +01005452 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5453 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305454 tempah = 0;
5455 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005456
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305457 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5458 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005459 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305460 tempah |= 0x04; /* shampoo 0129 */
5461 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005462
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005463 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305464 tempah = 0x00;
5465 tempbl = 0xcf;
5466 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5467 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5468 tempah |= 0x30;
5469 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005470
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005471 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305472 tempah = 0;
5473 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005474
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305475 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5476 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5477 tempah |= 0xc0;
5478 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005479 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305480 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005481
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305482 tempah = 0;
5483 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005484 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305485 tempbl = 0xff;
5486 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5487 tempah |= 0x80;
5488 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005489
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005490 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005491
Peter Huewe6896b942012-02-09 21:11:46 +01005492 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305493 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005494 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5495 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305496 }
5497 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005498}
5499
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005500
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305501void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5502 struct vb_device_info *pVBInfo)
5503{
5504
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005505 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005506
5507}
5508
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305509void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5510 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005511{
5512
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005513 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005514
5515}
5516
Bill Pemberton80adad82010-06-17 13:10:51 -04005517unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005518{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305519 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005520
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305521 if (pVBInfo->IF_DEF_LVDS == 1) {
5522 return 1;
5523 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005524 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305525 if ((flag == 1) || (flag == 2))
5526 return 1; /* 301b */
5527 else
5528 return 0;
5529 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005530}
5531
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005532unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5533 unsigned short ModeNo, unsigned short ModeIdIndex,
5534 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005535{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005536 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
5537 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
5538 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005539
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005540 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005541
Aaro Koskinenb3979922012-11-04 21:14:52 +02005542 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005543
Aaro Koskinen58839b02011-03-13 12:26:23 +02005544 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005545 index = index >> pVBInfo->SelectCRT2Rate;
5546 index &= 0x0F;
5547
5548 if (pVBInfo->LCDInfo & LCDNonExpanding)
5549 index = 0;
5550
5551 if (index > 0)
5552 index--;
5553
5554 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005555 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005556 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01005557 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
5558 | VB_SIS301LV | VB_SIS302LV
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005559 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005560 /* 301b */
5561 temp = LCDARefreshIndex[
5562 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005563 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005564 temp = LCDRefreshIndex[
5565 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005566
5567 if (index > temp)
5568 index = temp;
5569 } else {
5570 index = 0;
5571 }
5572 }
5573 }
5574
Aaro Koskinenb3979922012-11-04 21:14:52 +02005575 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005576 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005577 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005578 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5579 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005580 index++;
5581 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005582 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005583 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5584 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005585 index++;
5586 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005587 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5588 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005589 index++;
5590 }
5591 }
5592
5593 i = 0;
5594 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005595 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005596 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005597 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005598 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005599 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005600 if (temp < pVBInfo->ModeType)
5601 break;
5602 i++;
5603 index--;
5604
5605 } while (index != 0xFFFF);
5606 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5607 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005608 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005609 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005610 if (temp & InterlaceMode)
5611 i++;
5612 }
5613 }
5614 i--;
5615 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5616 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5617 RefreshRateTableIndex, &i, pVBInfo);
5618 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005619 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005620}
5621
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005622static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305623 struct xgi_hw_device_info *HwDeviceExtension,
5624 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005625{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005626 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005627
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005628 pVBInfo->SetFlag |= ProgrammingCRT2;
5629 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5630 ModeIdIndex, pVBInfo);
5631 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5632 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5633 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5634 HwDeviceExtension, pVBInfo);
5635 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5636 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005637}
5638
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005639static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005640 struct xgi_hw_device_info *HwDeviceExtension,
5641 struct vb_device_info *pVBInfo)
5642{
5643 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
5644
5645 tempbx = pVBInfo->VBInfo;
5646 pVBInfo->SetFlag |= ProgrammingCRT2;
5647 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5648 pVBInfo->SelectCRT2Rate = 4;
5649 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5650 ModeIdIndex, pVBInfo);
5651 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5652 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5653 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5654 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5655 RefreshRateTableIndex, pVBInfo);
5656 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5657 RefreshRateTableIndex, pVBInfo);
5658 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5659 RefreshRateTableIndex, pVBInfo);
5660 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5661 HwDeviceExtension, pVBInfo);
5662 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5663 RefreshRateTableIndex, pVBInfo);
5664 XGI_SetTap4Regs(pVBInfo);
5665 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5666 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5667 HwDeviceExtension, pVBInfo);
5668 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5669 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5670 XGI_AutoThreshold(pVBInfo);
5671 return 1;
5672}
5673
5674void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5675{
5676 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5677 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5678 0x05, 0x00 };
5679
5680 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5681
5682 unsigned char CR17, CR63, SR31;
5683 unsigned short temp;
5684 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
5685
5686 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005687 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005688
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005689 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005690 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005691 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005692 pVBInfo->P3d4, 0x53) | 0x02));
5693
Aaro Koskinen58839b02011-03-13 12:26:23 +02005694 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
5695 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
5696 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005697
Aaro Koskinen8104e322011-03-13 12:26:22 +02005698 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5699 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005700
Aaro Koskinen58839b02011-03-13 12:26:23 +02005701 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005702 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005703
Aaro Koskinen58839b02011-03-13 12:26:23 +02005704 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005705 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005706
Aaro Koskinen58839b02011-03-13 12:26:23 +02005707 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005708 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02005709 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005710 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005711
Aaro Koskinen8104e322011-03-13 12:26:22 +02005712 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005713
5714 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005715 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005716
5717 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005718 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005719 CRTCData[i]);
5720
5721 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005722 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005723 CRTCData[i]);
5724
5725 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005726 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005727 CRTCData[i]);
5728
Aaro Koskinen8104e322011-03-13 12:26:22 +02005729 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005730 & 0xE0));
5731
Aaro Koskinen8104e322011-03-13 12:26:22 +02005732 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5733 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5734 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005735
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005736 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005737
5738 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005739 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
5740 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
5741 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005742 }
5743
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005744 mdelay(1);
5745
5746 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005747 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005748
5749 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005750 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005751 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005752 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005753
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005754 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005755 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005756
5757 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005758 outb(0, (pVBInfo->P3c8 + 1));
5759 outb(0, (pVBInfo->P3c8 + 1));
5760 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005761 }
5762
Aaro Koskinen8104e322011-03-13 12:26:22 +02005763 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5764 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5765 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005766
Aaro Koskinen58839b02011-03-13 12:26:23 +02005767 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005768 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005769 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005770}
5771
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005772static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5773 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005774 struct vb_device_info *pVBInfo)
5775{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005776 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005777
Peter Huewe6896b942012-02-09 21:11:46 +01005778 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5779 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005780 if (!(pVBInfo->SetFlag & DisableChA)) {
5781 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005782 /* Power on */
5783 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03005784 } else if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5785 /* Power on */
5786 xgifb_reg_set(pVBInfo->Part1Port,
5787 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005788 }
5789 }
5790
5791 if (!(pVBInfo->SetFlag & DisableChB)) {
5792 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5793 & (SetCRT2ToLCD | SetCRT2ToTV
5794 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005795 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005796 pVBInfo->P3c4, 0x32);
5797 tempah &= 0xDF;
5798 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005799 if (!(pVBInfo->VBInfo &
5800 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005801 tempah |= 0x20;
5802 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005803 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005804 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005805
Aaro Koskinen58839b02011-03-13 12:26:23 +02005806 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005807 pVBInfo->Part1Port, 0x2E);
5808
5809 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005810 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005811 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005812 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005813 }
5814 }
5815
5816 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
5817 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005818 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005819 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005820 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005821 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005822 if (XGI_EnableChISLCD(pVBInfo) ||
5823 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01005824 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005825 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02005826 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005827 pVBInfo->Part4Port,
5828 0x2A,
5829 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005830 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005831 /* LVDS Driver power on */
5832 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005833 }
5834 }
5835
5836 tempah = 0x00;
5837
5838 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5839 tempah = 0xc0;
5840
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005841 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5842 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5843 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5844 tempah = tempah & 0x40;
5845 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5846 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005847
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005848 if (pVBInfo->SetFlag & DisableChB)
5849 tempah &= 0xBF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005850
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005851 if (pVBInfo->SetFlag & DisableChA)
5852 tempah &= 0x7F;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005853
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005854 if (pVBInfo->SetFlag & EnableChB)
5855 tempah |= 0x40;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005856
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005857 if (pVBInfo->SetFlag & EnableChA)
5858 tempah |= 0x80;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005859 }
5860 }
5861
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005862 /* EnablePart4_1F */
5863 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005864
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005865 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005866 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005867 XGI_DisableGatingCRT(HwDeviceExtension,
5868 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005869 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
5870 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005871 }
5872 }
5873 } /* 301 */
5874 else { /* LVDS */
5875 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005876 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005877 /* enable CRT2 */
5878 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005879
Aaro Koskinen58839b02011-03-13 12:26:23 +02005880 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005881 0x2E);
5882 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005883 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005884
Aaro Koskinendc505562011-03-13 12:26:26 +02005885 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005886 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005887 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005888}
5889
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005890static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5891 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005892 unsigned short ModeNo, unsigned short ModeIdIndex,
5893 struct vb_device_info *pVBInfo)
5894{
Aaro Koskinena1579612012-04-07 01:14:05 +03005895 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005896
Aaro Koskinena1579612012-04-07 01:14:05 +03005897 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005898 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005899 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5900 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5901 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005902 XGI_ClearExt1Regs(pVBInfo);
5903
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005904 if (HwDeviceExtension->jChipType == XG27) {
5905 if (pVBInfo->IF_DEF_LVDS == 0)
5906 XGI_SetDefaultVCLK(pVBInfo);
5907 }
5908
5909 temp = ~ProgrammingCRT2;
5910 pVBInfo->SetFlag &= temp;
5911 pVBInfo->SelectCRT2Rate = 0;
5912
Peter Huewe6896b942012-02-09 21:11:46 +01005913 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5914 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005915 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005916 | SetInSlaveMode)) {
5917 pVBInfo->SetFlag |= ProgrammingCRT2;
5918 }
5919 }
5920
5921 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5922 ModeIdIndex, pVBInfo);
5923 if (RefreshRateTableIndex != 0xFFFF) {
5924 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5925 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5926 pVBInfo, HwDeviceExtension);
5927 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5928 RefreshRateTableIndex, pVBInfo);
5929 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5930 HwDeviceExtension, pVBInfo);
5931 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5932 RefreshRateTableIndex, pVBInfo);
5933 }
5934
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005935 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005936 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005937 if (temp & 0xA0) {
5938
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005939 if (HwDeviceExtension->jChipType == XG27)
5940 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5941 RefreshRateTableIndex, pVBInfo);
5942 else
5943 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5944 RefreshRateTableIndex, pVBInfo);
5945
5946 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5947 RefreshRateTableIndex);
5948
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005949 xgifb_set_lcd(HwDeviceExtension->jChipType,
5950 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005951
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005952 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005953 xgifb_set_lvds(xgifb_info,
5954 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005955 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005956 }
5957 }
5958
5959 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5960 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5961 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5962 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005963 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005964}
5965
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005966unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5967 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005968 unsigned short ModeNo)
5969{
5970 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005971 struct vb_device_info VBINF;
5972 struct vb_device_info *pVBInfo = &VBINF;
Dmitry Eremin-Solenikov9a801f22012-03-19 21:50:13 +04005973 pVBInfo->BaseAddr = xgifb_info->vga_base;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005974 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005975
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005976 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005977 pVBInfo->IF_DEF_YPbPr = 0;
5978 pVBInfo->IF_DEF_HiVision = 0;
5979 pVBInfo->IF_DEF_CRT2Monitor = 0;
5980 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005981 } else {
5982 pVBInfo->IF_DEF_YPbPr = 1;
5983 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005984 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005985 }
5986
5987 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
5988 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
5989 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
5990 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
5991 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
5992 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
5993 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
5994 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
5995 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
5996 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
5997 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
5998 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
5999 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
Peter Huewe6896b942012-02-09 21:11:46 +01006000 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
6001 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
6002 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
6003 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
6004 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006005
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006006 /* for x86 Linux, XG21 LVDS */
6007 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006008 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006009 pVBInfo->IF_DEF_LVDS = 1;
6010 }
6011 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006012 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
6013 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006014 pVBInfo->IF_DEF_LVDS = 1;
6015 }
6016 }
6017
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006018 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006019 XGI_GetVBType(pVBInfo);
6020
6021 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02006022 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006023 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006024 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006025
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006026 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006027 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
6028
6029 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6030
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006031 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006032 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
6033 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
6034 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006035 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006036
Peter Huewea3d675c2012-02-09 21:11:47 +01006037 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006038 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006039 ModeIdIndex, pVBInfo);
6040
Peter Huewea3d675c2012-02-09 21:11:47 +01006041 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006042 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6043 HwDeviceExtension, pVBInfo);
6044 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03006045 } else if (!(pVBInfo->VBInfo & SwitchCRT2)) {
6046 XGI_SetCRT1Group(xgifb_info,
6047 HwDeviceExtension, ModeNo,
6048 ModeIdIndex, pVBInfo);
6049 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
6050 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6051 HwDeviceExtension,
6052 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006053 }
6054 }
6055
Peter Huewe6896b942012-02-09 21:11:46 +01006056 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006057 switch (HwDeviceExtension->ujVBChipID) {
6058 case VB_CHIP_301:
6059 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6060 pVBInfo); /*add for CRT2 */
6061 break;
6062
6063 case VB_CHIP_302:
6064 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6065 pVBInfo); /*add for CRT2 */
6066 break;
6067
6068 default:
6069 break;
6070 }
6071 }
6072
6073 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
6074 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006075 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006076 } /* !XG20 */
6077 else {
6078 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006079 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006080 ModeIdIndex,
6081 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006082 return 0;
6083
Aaro Koskinenb3979922012-11-04 21:14:52 +02006084 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01006085 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006086
6087 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03006088 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006089
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006090 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006091
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006092 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6093 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006094
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006095 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006096 }
6097
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006098 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
6099
Miguel Gómez3bcc2462012-07-06 12:40:53 +02006100 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006101 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006102
6103 return 1;
6104}