blob: c311ad3c3687c739a558fc9baea8d9393aef756a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $XFree86$ */
2/* $XdotOrg$ */
3/*
4 * Mode initializing code (CRT1 section) for
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005 * for SiS 300/305/540/630/730,
6 * SiS 315/550/[M]650/651/[M]661[FGM]X/[M]74x[GX]/330/[M]76x[GX],
7 * XGI Volari V3XT/V5/V8, Z7
8 * (Universal module for Linux kernel framebuffer and X.org/XFree86 4.x)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
Thomas Winischhofer544393f2005-09-09 13:04:45 -070010 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
12 * If distributed as part of the Linux kernel, the following license terms
13 * apply:
14 *
15 * * This program is free software; you can redistribute it and/or modify
16 * * it under the terms of the GNU General Public License as published by
17 * * the Free Software Foundation; either version 2 of the named License,
18 * * or any later version.
19 * *
20 * * This program is distributed in the hope that it will be useful,
21 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * * GNU General Public License for more details.
24 * *
25 * * You should have received a copy of the GNU General Public License
26 * * along with this program; if not, write to the Free Software
27 * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
28 *
29 * Otherwise, the following license terms apply:
30 *
31 * * Redistribution and use in source and binary forms, with or without
32 * * modification, are permitted provided that the following conditions
33 * * are met:
34 * * 1) Redistributions of source code must retain the above copyright
35 * * notice, this list of conditions and the following disclaimer.
36 * * 2) Redistributions in binary form must reproduce the above copyright
37 * * notice, this list of conditions and the following disclaimer in the
38 * * documentation and/or other materials provided with the distribution.
39 * * 3) The name of the author may not be used to endorse or promote products
40 * * derived from this software without specific prior written permission.
41 * *
42 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
43 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
45 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
46 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
51 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 *
53 * Author: Thomas Winischhofer <thomas@winischhofer.net>
54 *
55 * Formerly based on non-functional code-fragements for 300 series by SiS, Inc.
56 * Used by permission.
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -070058
59#ifdef HAVE_CONFIG_H
60#include "config.h"
61#endif
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include "init.h"
64
65#ifdef SIS300
66#include "300vtbl.h"
67#endif
68
69#ifdef SIS315H
70#include "310vtbl.h"
71#endif
72
73#if defined(ALLOC_PRAGMA)
74#pragma alloc_text(PAGE,SiSSetMode)
75#endif
76
77/*********************************************/
78/* POINTER INITIALIZATION */
79/*********************************************/
80
81#if defined(SIS300) || defined(SIS315H)
82static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -070083InitCommonPointer(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Thomas Winischhofer544393f2005-09-09 13:04:45 -070085 SiS_Pr->SiS_SModeIDTable = SiS_SModeIDTable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 SiS_Pr->SiS_StResInfo = SiS_StResInfo;
87 SiS_Pr->SiS_ModeResInfo = SiS_ModeResInfo;
88 SiS_Pr->SiS_StandTable = SiS_StandTable;
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 SiS_Pr->SiS_NTSCTiming = SiS_NTSCTiming;
91 SiS_Pr->SiS_PALTiming = SiS_PALTiming;
92 SiS_Pr->SiS_HiTVSt1Timing = SiS_HiTVSt1Timing;
93 SiS_Pr->SiS_HiTVSt2Timing = SiS_HiTVSt2Timing;
94
95 SiS_Pr->SiS_HiTVExtTiming = SiS_HiTVExtTiming;
96 SiS_Pr->SiS_HiTVGroup3Data = SiS_HiTVGroup3Data;
97 SiS_Pr->SiS_HiTVGroup3Simu = SiS_HiTVGroup3Simu;
98#if 0
99 SiS_Pr->SiS_HiTVTextTiming = SiS_HiTVTextTiming;
100 SiS_Pr->SiS_HiTVGroup3Text = SiS_HiTVGroup3Text;
101#endif
102
103 SiS_Pr->SiS_StPALData = SiS_StPALData;
104 SiS_Pr->SiS_ExtPALData = SiS_ExtPALData;
105 SiS_Pr->SiS_StNTSCData = SiS_StNTSCData;
106 SiS_Pr->SiS_ExtNTSCData = SiS_ExtNTSCData;
107 SiS_Pr->SiS_St1HiTVData = SiS_StHiTVData;
108 SiS_Pr->SiS_St2HiTVData = SiS_St2HiTVData;
109 SiS_Pr->SiS_ExtHiTVData = SiS_ExtHiTVData;
110 SiS_Pr->SiS_St525iData = SiS_StNTSCData;
111 SiS_Pr->SiS_St525pData = SiS_St525pData;
112 SiS_Pr->SiS_St750pData = SiS_St750pData;
113 SiS_Pr->SiS_Ext525iData = SiS_ExtNTSCData;
114 SiS_Pr->SiS_Ext525pData = SiS_ExtNTSCData;
115 SiS_Pr->SiS_Ext750pData = SiS_Ext750pData;
116
117 SiS_Pr->pSiS_OutputSelect = &SiS_OutputSelect;
118 SiS_Pr->pSiS_SoftSetting = &SiS_SoftSetting;
119
120 SiS_Pr->SiS_LCD1280x720Data = SiS_LCD1280x720Data;
121 SiS_Pr->SiS_StLCD1280x768_2Data = SiS_StLCD1280x768_2Data;
122 SiS_Pr->SiS_ExtLCD1280x768_2Data = SiS_ExtLCD1280x768_2Data;
123 SiS_Pr->SiS_LCD1280x800Data = SiS_LCD1280x800Data;
124 SiS_Pr->SiS_LCD1280x800_2Data = SiS_LCD1280x800_2Data;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700125 SiS_Pr->SiS_LCD1280x854Data = SiS_LCD1280x854Data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 SiS_Pr->SiS_LCD1280x960Data = SiS_LCD1280x960Data;
127 SiS_Pr->SiS_StLCD1400x1050Data = SiS_StLCD1400x1050Data;
128 SiS_Pr->SiS_ExtLCD1400x1050Data = SiS_ExtLCD1400x1050Data;
129 SiS_Pr->SiS_LCD1680x1050Data = SiS_LCD1680x1050Data;
130 SiS_Pr->SiS_StLCD1600x1200Data = SiS_StLCD1600x1200Data;
131 SiS_Pr->SiS_ExtLCD1600x1200Data = SiS_ExtLCD1600x1200Data;
132 SiS_Pr->SiS_NoScaleData = SiS_NoScaleData;
133
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700134 SiS_Pr->SiS_LVDS320x240Data_1 = SiS_LVDS320x240Data_1;
135 SiS_Pr->SiS_LVDS320x240Data_2 = SiS_LVDS320x240Data_2;
136 SiS_Pr->SiS_LVDS640x480Data_1 = SiS_LVDS640x480Data_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 SiS_Pr->SiS_LVDS800x600Data_1 = SiS_LVDS800x600Data_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 SiS_Pr->SiS_LVDS1024x600Data_1 = SiS_LVDS1024x600Data_1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700139 SiS_Pr->SiS_LVDS1024x768Data_1 = SiS_LVDS1024x768Data_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700141 SiS_Pr->SiS_LVDSCRT1320x240_1 = SiS_LVDSCRT1320x240_1;
142 SiS_Pr->SiS_LVDSCRT1320x240_2 = SiS_LVDSCRT1320x240_2;
143 SiS_Pr->SiS_LVDSCRT1320x240_2_H = SiS_LVDSCRT1320x240_2_H;
144 SiS_Pr->SiS_LVDSCRT1320x240_3 = SiS_LVDSCRT1320x240_3;
145 SiS_Pr->SiS_LVDSCRT1320x240_3_H = SiS_LVDSCRT1320x240_3_H;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 SiS_Pr->SiS_LVDSCRT1640x480_1 = SiS_LVDSCRT1640x480_1;
147 SiS_Pr->SiS_LVDSCRT1640x480_1_H = SiS_LVDSCRT1640x480_1_H;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700148#if 0
149 SiS_Pr->SiS_LVDSCRT11024x600_1 = SiS_LVDSCRT11024x600_1;
150 SiS_Pr->SiS_LVDSCRT11024x600_1_H = SiS_LVDSCRT11024x600_1_H;
151 SiS_Pr->SiS_LVDSCRT11024x600_2 = SiS_LVDSCRT11024x600_2;
152 SiS_Pr->SiS_LVDSCRT11024x600_2_H = SiS_LVDSCRT11024x600_2_H;
153#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 SiS_Pr->SiS_CHTVUNTSCData = SiS_CHTVUNTSCData;
156 SiS_Pr->SiS_CHTVONTSCData = SiS_CHTVONTSCData;
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 SiS_Pr->SiS_PanelMinLVDS = Panel_800x600; /* lowest value LVDS/LCDA */
159 SiS_Pr->SiS_PanelMin301 = Panel_1024x768; /* lowest value 301 */
160}
161#endif
162
163#ifdef SIS300
164static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700165InitTo300Pointer(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700167 InitCommonPointer(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 SiS_Pr->SiS_VBModeIDTable = SiS300_VBModeIDTable;
170 SiS_Pr->SiS_EModeIDTable = SiS300_EModeIDTable;
171 SiS_Pr->SiS_RefIndex = SiS300_RefIndex;
172 SiS_Pr->SiS_CRT1Table = SiS300_CRT1Table;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700173 if(SiS_Pr->ChipType == SIS_300) {
174 SiS_Pr->SiS_MCLKData_0 = SiS300_MCLKData_300; /* 300 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700176 SiS_Pr->SiS_MCLKData_0 = SiS300_MCLKData_630; /* 630, 730 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
178 SiS_Pr->SiS_VCLKData = SiS300_VCLKData;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700179 SiS_Pr->SiS_VBVCLKData = (struct SiS_VBVCLKData *)SiS300_VCLKData;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 SiS_Pr->SiS_SR15 = SiS300_SR15;
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 SiS_Pr->SiS_PanelDelayTbl = SiS300_PanelDelayTbl;
184 SiS_Pr->SiS_PanelDelayTblLVDS = SiS300_PanelDelayTbl;
185
186 SiS_Pr->SiS_ExtLCD1024x768Data = SiS300_ExtLCD1024x768Data;
187 SiS_Pr->SiS_St2LCD1024x768Data = SiS300_St2LCD1024x768Data;
188 SiS_Pr->SiS_ExtLCD1280x1024Data = SiS300_ExtLCD1280x1024Data;
189 SiS_Pr->SiS_St2LCD1280x1024Data = SiS300_St2LCD1280x1024Data;
190
191 SiS_Pr->SiS_CRT2Part2_1024x768_1 = SiS300_CRT2Part2_1024x768_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 SiS_Pr->SiS_CRT2Part2_1024x768_2 = SiS300_CRT2Part2_1024x768_2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 SiS_Pr->SiS_CRT2Part2_1024x768_3 = SiS300_CRT2Part2_1024x768_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 SiS_Pr->SiS_CHTVUPALData = SiS300_CHTVUPALData;
196 SiS_Pr->SiS_CHTVOPALData = SiS300_CHTVOPALData;
197 SiS_Pr->SiS_CHTVUPALMData = SiS_CHTVUNTSCData; /* not supported on 300 series */
198 SiS_Pr->SiS_CHTVOPALMData = SiS_CHTVONTSCData; /* not supported on 300 series */
199 SiS_Pr->SiS_CHTVUPALNData = SiS300_CHTVUPALData; /* not supported on 300 series */
200 SiS_Pr->SiS_CHTVOPALNData = SiS300_CHTVOPALData; /* not supported on 300 series */
201 SiS_Pr->SiS_CHTVSOPALData = SiS300_CHTVSOPALData;
202
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700203 SiS_Pr->SiS_LVDS848x480Data_1 = SiS300_LVDS848x480Data_1;
204 SiS_Pr->SiS_LVDS848x480Data_2 = SiS300_LVDS848x480Data_2;
205 SiS_Pr->SiS_LVDSBARCO1024Data_1 = SiS300_LVDSBARCO1024Data_1;
206 SiS_Pr->SiS_LVDSBARCO1366Data_1 = SiS300_LVDSBARCO1366Data_1;
207 SiS_Pr->SiS_LVDSBARCO1366Data_2 = SiS300_LVDSBARCO1366Data_2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700209 SiS_Pr->SiS_PanelType04_1a = SiS300_PanelType04_1a;
210 SiS_Pr->SiS_PanelType04_2a = SiS300_PanelType04_2a;
211 SiS_Pr->SiS_PanelType04_1b = SiS300_PanelType04_1b;
212 SiS_Pr->SiS_PanelType04_2b = SiS300_PanelType04_2b;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 SiS_Pr->SiS_CHTVCRT1UNTSC = SiS300_CHTVCRT1UNTSC;
215 SiS_Pr->SiS_CHTVCRT1ONTSC = SiS300_CHTVCRT1ONTSC;
216 SiS_Pr->SiS_CHTVCRT1UPAL = SiS300_CHTVCRT1UPAL;
217 SiS_Pr->SiS_CHTVCRT1OPAL = SiS300_CHTVCRT1OPAL;
218 SiS_Pr->SiS_CHTVCRT1SOPAL = SiS300_CHTVCRT1SOPAL;
219 SiS_Pr->SiS_CHTVReg_UNTSC = SiS300_CHTVReg_UNTSC;
220 SiS_Pr->SiS_CHTVReg_ONTSC = SiS300_CHTVReg_ONTSC;
221 SiS_Pr->SiS_CHTVReg_UPAL = SiS300_CHTVReg_UPAL;
222 SiS_Pr->SiS_CHTVReg_OPAL = SiS300_CHTVReg_OPAL;
223 SiS_Pr->SiS_CHTVReg_UPALM = SiS300_CHTVReg_UNTSC; /* not supported on 300 series */
224 SiS_Pr->SiS_CHTVReg_OPALM = SiS300_CHTVReg_ONTSC; /* not supported on 300 series */
225 SiS_Pr->SiS_CHTVReg_UPALN = SiS300_CHTVReg_UPAL; /* not supported on 300 series */
226 SiS_Pr->SiS_CHTVReg_OPALN = SiS300_CHTVReg_OPAL; /* not supported on 300 series */
227 SiS_Pr->SiS_CHTVReg_SOPAL = SiS300_CHTVReg_SOPAL;
228 SiS_Pr->SiS_CHTVVCLKUNTSC = SiS300_CHTVVCLKUNTSC;
229 SiS_Pr->SiS_CHTVVCLKONTSC = SiS300_CHTVVCLKONTSC;
230 SiS_Pr->SiS_CHTVVCLKUPAL = SiS300_CHTVVCLKUPAL;
231 SiS_Pr->SiS_CHTVVCLKOPAL = SiS300_CHTVVCLKOPAL;
232 SiS_Pr->SiS_CHTVVCLKUPALM = SiS300_CHTVVCLKUNTSC; /* not supported on 300 series */
233 SiS_Pr->SiS_CHTVVCLKOPALM = SiS300_CHTVVCLKONTSC; /* not supported on 300 series */
234 SiS_Pr->SiS_CHTVVCLKUPALN = SiS300_CHTVVCLKUPAL; /* not supported on 300 series */
235 SiS_Pr->SiS_CHTVVCLKOPALN = SiS300_CHTVVCLKOPAL; /* not supported on 300 series */
236 SiS_Pr->SiS_CHTVVCLKSOPAL = SiS300_CHTVVCLKSOPAL;
237}
238#endif
239
240#ifdef SIS315H
241static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700242InitTo310Pointer(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700244 InitCommonPointer(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 SiS_Pr->SiS_EModeIDTable = SiS310_EModeIDTable;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700247 SiS_Pr->SiS_RefIndex = SiS310_RefIndex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 SiS_Pr->SiS_CRT1Table = SiS310_CRT1Table;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700249 if(SiS_Pr->ChipType >= SIS_340) {
250 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_340; /* 340 + XGI */
251 } else if(SiS_Pr->ChipType >= SIS_761) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_761; /* 761 - preliminary */
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700253 } else if(SiS_Pr->ChipType >= SIS_760) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_760; /* 760 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700255 } else if(SiS_Pr->ChipType >= SIS_661) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_660; /* 661/741 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700257 } else if(SiS_Pr->ChipType == SIS_330) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_330; /* 330 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700259 } else if(SiS_Pr->ChipType > SIS_315PRO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_650; /* 550, 650, 740 */
261 } else {
262 SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_315; /* 315 */
263 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700264 if(SiS_Pr->ChipType >= SIS_340) {
265 SiS_Pr->SiS_MCLKData_1 = SiS310_MCLKData_1_340;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700267 SiS_Pr->SiS_MCLKData_1 = SiS310_MCLKData_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269 SiS_Pr->SiS_VCLKData = SiS310_VCLKData;
270 SiS_Pr->SiS_VBVCLKData = SiS310_VBVCLKData;
271
272 SiS_Pr->SiS_SR15 = SiS310_SR15;
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 SiS_Pr->SiS_PanelDelayTbl = SiS310_PanelDelayTbl;
275 SiS_Pr->SiS_PanelDelayTblLVDS = SiS310_PanelDelayTblLVDS;
276
277 SiS_Pr->SiS_St2LCD1024x768Data = SiS310_St2LCD1024x768Data;
278 SiS_Pr->SiS_ExtLCD1024x768Data = SiS310_ExtLCD1024x768Data;
279 SiS_Pr->SiS_St2LCD1280x1024Data = SiS310_St2LCD1280x1024Data;
280 SiS_Pr->SiS_ExtLCD1280x1024Data = SiS310_ExtLCD1280x1024Data;
281
282 SiS_Pr->SiS_CRT2Part2_1024x768_1 = SiS310_CRT2Part2_1024x768_1;
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 SiS_Pr->SiS_CHTVUPALData = SiS310_CHTVUPALData;
285 SiS_Pr->SiS_CHTVOPALData = SiS310_CHTVOPALData;
286 SiS_Pr->SiS_CHTVUPALMData = SiS310_CHTVUPALMData;
287 SiS_Pr->SiS_CHTVOPALMData = SiS310_CHTVOPALMData;
288 SiS_Pr->SiS_CHTVUPALNData = SiS310_CHTVUPALNData;
289 SiS_Pr->SiS_CHTVOPALNData = SiS310_CHTVOPALNData;
290 SiS_Pr->SiS_CHTVSOPALData = SiS310_CHTVSOPALData;
291
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700292 SiS_Pr->SiS_CHTVCRT1UNTSC = SiS310_CHTVCRT1UNTSC;
293 SiS_Pr->SiS_CHTVCRT1ONTSC = SiS310_CHTVCRT1ONTSC;
294 SiS_Pr->SiS_CHTVCRT1UPAL = SiS310_CHTVCRT1UPAL;
295 SiS_Pr->SiS_CHTVCRT1OPAL = SiS310_CHTVCRT1OPAL;
296 SiS_Pr->SiS_CHTVCRT1SOPAL = SiS310_CHTVCRT1OPAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 SiS_Pr->SiS_CHTVReg_UNTSC = SiS310_CHTVReg_UNTSC;
299 SiS_Pr->SiS_CHTVReg_ONTSC = SiS310_CHTVReg_ONTSC;
300 SiS_Pr->SiS_CHTVReg_UPAL = SiS310_CHTVReg_UPAL;
301 SiS_Pr->SiS_CHTVReg_OPAL = SiS310_CHTVReg_OPAL;
302 SiS_Pr->SiS_CHTVReg_UPALM = SiS310_CHTVReg_UPALM;
303 SiS_Pr->SiS_CHTVReg_OPALM = SiS310_CHTVReg_OPALM;
304 SiS_Pr->SiS_CHTVReg_UPALN = SiS310_CHTVReg_UPALN;
305 SiS_Pr->SiS_CHTVReg_OPALN = SiS310_CHTVReg_OPALN;
306 SiS_Pr->SiS_CHTVReg_SOPAL = SiS310_CHTVReg_OPAL;
307
308 SiS_Pr->SiS_CHTVVCLKUNTSC = SiS310_CHTVVCLKUNTSC;
309 SiS_Pr->SiS_CHTVVCLKONTSC = SiS310_CHTVVCLKONTSC;
310 SiS_Pr->SiS_CHTVVCLKUPAL = SiS310_CHTVVCLKUPAL;
311 SiS_Pr->SiS_CHTVVCLKOPAL = SiS310_CHTVVCLKOPAL;
312 SiS_Pr->SiS_CHTVVCLKUPALM = SiS310_CHTVVCLKUPALM;
313 SiS_Pr->SiS_CHTVVCLKOPALM = SiS310_CHTVVCLKOPALM;
314 SiS_Pr->SiS_CHTVVCLKUPALN = SiS310_CHTVVCLKUPALN;
315 SiS_Pr->SiS_CHTVVCLKOPALN = SiS310_CHTVVCLKOPALN;
316 SiS_Pr->SiS_CHTVVCLKSOPAL = SiS310_CHTVVCLKOPAL;
317}
318#endif
319
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800320bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700321SiSInitPtr(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700323 if(SiS_Pr->ChipType < SIS_315H) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324#ifdef SIS300
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700325 InitTo300Pointer(SiS_Pr);
326#else
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800327 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700329 } else {
330#ifdef SIS315H
331 InitTo310Pointer(SiS_Pr);
332#else
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800333 return false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700334#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 }
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800336 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
339/*********************************************/
340/* HELPER: Get ModeID */
341/*********************************************/
342
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700343#ifndef SIS_XORG_XF86
344static
345#endif
346unsigned short
347SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800348 int Depth, bool FSTN, int LCDwidth, int LCDheight)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700350 unsigned short ModeIndex = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 switch(HDisplay)
353 {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700354 case 320:
355 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
356 else if(VDisplay == 240) {
357 if((VBFlags & CRT2_LCD) && (FSTN))
358 ModeIndex = ModeIndex_320x240_FSTN[Depth];
359 else
360 ModeIndex = ModeIndex_320x240[Depth];
361 }
362 break;
363 case 400:
364 if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 800) && (LCDwidth >= 600))) {
365 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
366 }
367 break;
368 case 512:
369 if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 1024) && (LCDwidth >= 768))) {
370 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
371 }
372 break;
373 case 640:
374 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
375 else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
376 break;
377 case 720:
378 if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth];
379 else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
380 break;
381 case 768:
382 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
383 break;
384 case 800:
385 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
386 else if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
387 break;
388 case 848:
389 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
390 break;
391 case 856:
392 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
393 break;
394 case 960:
395 if(VGAEngine == SIS_315_VGA) {
396 if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth];
397 else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth];
398 }
399 break;
400 case 1024:
401 if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
402 else if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
403 else if(VGAEngine == SIS_300_VGA) {
404 if(VDisplay == 600) ModeIndex = ModeIndex_1024x600[Depth];
405 }
406 break;
407 case 1152:
408 if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth];
409 if(VGAEngine == SIS_300_VGA) {
410 if(VDisplay == 768) ModeIndex = ModeIndex_1152x768[Depth];
411 }
412 break;
413 case 1280:
414 switch(VDisplay) {
415 case 720:
416 ModeIndex = ModeIndex_1280x720[Depth];
417 break;
418 case 768:
419 if(VGAEngine == SIS_300_VGA) {
420 ModeIndex = ModeIndex_300_1280x768[Depth];
421 } else {
422 ModeIndex = ModeIndex_310_1280x768[Depth];
423 }
424 break;
425 case 800:
426 if(VGAEngine == SIS_315_VGA) {
427 ModeIndex = ModeIndex_1280x800[Depth];
428 }
429 break;
430 case 854:
431 if(VGAEngine == SIS_315_VGA) {
432 ModeIndex = ModeIndex_1280x854[Depth];
433 }
434 break;
435 case 960:
436 ModeIndex = ModeIndex_1280x960[Depth];
437 break;
438 case 1024:
439 ModeIndex = ModeIndex_1280x1024[Depth];
440 break;
441 }
442 break;
443 case 1360:
444 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
445 if(VGAEngine == SIS_300_VGA) {
446 if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
447 }
448 break;
449 case 1400:
450 if(VGAEngine == SIS_315_VGA) {
451 if(VDisplay == 1050) {
452 ModeIndex = ModeIndex_1400x1050[Depth];
453 }
454 }
455 break;
456 case 1600:
457 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
458 break;
459 case 1680:
460 if(VGAEngine == SIS_315_VGA) {
461 if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
462 }
463 break;
464 case 1920:
465 if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth];
466 else if(VGAEngine == SIS_315_VGA) {
467 if(VDisplay == 1080) ModeIndex = ModeIndex_1920x1080[Depth];
468 }
469 break;
470 case 2048:
471 if(VDisplay == 1536) {
472 if(VGAEngine == SIS_300_VGA) {
473 ModeIndex = ModeIndex_300_2048x1536[Depth];
474 } else {
475 ModeIndex = ModeIndex_310_2048x1536[Depth];
476 }
477 }
478 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 }
480
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700481 return ModeIndex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700484unsigned short
485SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800486 int Depth, bool FSTN, unsigned short CustomT, int LCDwidth, int LCDheight,
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700487 unsigned int VBFlags2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700489 unsigned short ModeIndex = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700491 if(VBFlags2 & (VB2_LVDS | VB2_30xBDH)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 switch(HDisplay)
494 {
495 case 320:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700496 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
497 if(VDisplay == 200) {
498 if(!FSTN) ModeIndex = ModeIndex_320x200[Depth];
499 } else if(VDisplay == 240) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 if(!FSTN) ModeIndex = ModeIndex_320x240[Depth];
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700501 else if(VGAEngine == SIS_315_VGA) {
502 ModeIndex = ModeIndex_320x240_FSTN[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
504 }
505 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700506 break;
507 case 400:
508 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
509 if(!((VGAEngine == SIS_300_VGA) && (VBFlags2 & VB2_TRUMPION))) {
510 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700513 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 case 512:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700515 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
516 if(!((VGAEngine == SIS_300_VGA) && (VBFlags2 & VB2_TRUMPION))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 if(LCDwidth >= 1024 && LCDwidth != 1152 && LCDheight >= 768) {
518 if(VDisplay == 384) {
519 ModeIndex = ModeIndex_512x384[Depth];
520 }
521 }
522 }
523 }
524 break;
525 case 640:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700526 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 else if(VDisplay == 400) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700528 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856))
529 ModeIndex = ModeIndex_640x400[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 }
531 break;
532 case 800:
533 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
534 break;
535 case 848:
536 if(CustomT == CUT_PANEL848) {
537 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
538 }
539 break;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700540 case 856:
541 if(CustomT == CUT_PANEL856) {
542 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
543 }
544 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 case 1024:
546 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
547 else if(VGAEngine == SIS_300_VGA) {
548 if((VDisplay == 600) && (LCDheight == 600)) {
549 ModeIndex = ModeIndex_1024x600[Depth];
550 }
551 }
552 break;
553 case 1152:
554 if(VGAEngine == SIS_300_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700555 if((VDisplay == 768) && (LCDheight == 768)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 ModeIndex = ModeIndex_1152x768[Depth];
557 }
558 }
559 break;
560 case 1280:
561 if(VDisplay == 1024) ModeIndex = ModeIndex_1280x1024[Depth];
562 else if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700563 if((VDisplay == 768) && (LCDheight == 768)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 ModeIndex = ModeIndex_310_1280x768[Depth];
565 }
566 }
567 break;
568 case 1360:
569 if(VGAEngine == SIS_300_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700570 if(CustomT == CUT_BARCO1366) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
572 }
573 }
574 if(CustomT == CUT_PANEL848) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700575 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
577 break;
578 case 1400:
579 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700580 if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 }
582 break;
583 case 1600:
584 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700585 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 }
587 break;
588 }
589
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700590 } else if(VBFlags2 & VB2_SISBRIDGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 switch(HDisplay)
593 {
594 case 320:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700595 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700597 break;
598 case 400:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 if(LCDwidth >= 800 && LCDheight >= 600) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700600 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700602 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 case 512:
604 if(LCDwidth >= 1024 && LCDheight >= 768 && LCDwidth != 1152) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700605 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 }
607 break;
608 case 640:
609 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
610 else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
611 break;
612 case 720:
613 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700614 if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
616 }
617 break;
618 case 768:
619 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700620 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 }
622 break;
623 case 800:
624 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
625 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700626 if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 }
628 break;
629 case 848:
630 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700631 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 }
633 break;
634 case 856:
635 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700636 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
638 break;
639 case 960:
640 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700641 if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth];
643 }
644 break;
645 case 1024:
646 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
647 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700648 if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650 break;
651 case 1152:
652 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700653 if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
655 break;
656 case 1280:
657 switch(VDisplay) {
658 case 720:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700659 ModeIndex = ModeIndex_1280x720[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 case 768:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700661 if(VGAEngine == SIS_300_VGA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 ModeIndex = ModeIndex_300_1280x768[Depth];
663 } else {
664 ModeIndex = ModeIndex_310_1280x768[Depth];
665 }
666 break;
667 case 800:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700668 if(VGAEngine == SIS_315_VGA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 ModeIndex = ModeIndex_1280x800[Depth];
670 }
671 break;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700672 case 854:
673 if(VGAEngine == SIS_315_VGA) {
674 ModeIndex = ModeIndex_1280x854[Depth];
675 }
676 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 case 960:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700678 ModeIndex = ModeIndex_1280x960[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 break;
680 case 1024:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700681 ModeIndex = ModeIndex_1280x1024[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 break;
683 }
684 break;
685 case 1360:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700686 if(VGAEngine == SIS_315_VGA) { /* OVER1280 only? */
687 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 }
689 break;
690 case 1400:
691 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700692 if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
694 }
695 }
696 break;
697 case 1600:
698 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700699 if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
700 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 }
702 }
703 break;
704#ifndef VB_FORBID_CRT2LCD_OVER_1600
705 case 1680:
706 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700707 if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
708 if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
709 }
710 }
711 break;
712 case 1920:
713 if(VGAEngine == SIS_315_VGA) {
714 if(VBFlags2 & VB2_LCDOVER1600BRIDGE) {
715 if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth];
716 }
717 }
718 break;
719 case 2048:
720 if(VGAEngine == SIS_315_VGA) {
721 if(VBFlags2 & VB2_LCDOVER1600BRIDGE) {
722 if(VDisplay == 1536) ModeIndex = ModeIndex_310_2048x1536[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
724 }
725 break;
726#endif
727 }
728 }
729
730 return ModeIndex;
731}
732
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700733unsigned short
734SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, int Depth,
735 unsigned int VBFlags2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700737 unsigned short ModeIndex = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700739 if(VBFlags2 & VB2_CHRONTEL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 switch(HDisplay)
742 {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700743 case 512:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 if(VGAEngine == SIS_315_VGA) {
745 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
746 }
747 break;
748 case 640:
749 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
750 else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
751 break;
752 case 800:
753 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
754 break;
755 case 1024:
756 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700757 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
759 break;
760 }
761
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700762 } else if(VBFlags2 & VB2_SISTVBRIDGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764 switch(HDisplay)
765 {
766 case 320:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700767 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700769 break;
770 case 400:
771 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
772 break;
773 case 512:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 if( ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR750P | TV_YPBPR1080I))) ||
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700775 (VBFlags & TV_HIVISION) ||
776 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) {
777 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 }
779 break;
780 case 640:
781 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
782 else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
783 break;
784 case 720:
785 if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700786 if(VDisplay == 480) {
787 ModeIndex = ModeIndex_720x480[Depth];
788 } else if(VDisplay == 576) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) ||
790 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) )
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700791 ModeIndex = ModeIndex_720x576[Depth];
792 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 }
794 break;
795 case 768:
796 if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700797 if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700799 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 }
801 }
802 break;
803 case 800:
804 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
805 else if(VDisplay == 480) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700806 if(!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 ModeIndex = ModeIndex_800x480[Depth];
808 }
809 }
810 break;
811 case 960:
812 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700813 if(VDisplay == 600) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 if((VBFlags & TV_HIVISION) || ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
815 ModeIndex = ModeIndex_960x600[Depth];
816 }
817 }
818 }
819 break;
820 case 1024:
821 if(VDisplay == 768) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700822 if(VBFlags2 & VB2_30xBLV) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 ModeIndex = ModeIndex_1024x768[Depth];
824 }
825 } else if(VDisplay == 576) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700826 if( (VBFlags & TV_HIVISION) ||
827 ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)) ||
828 ((VBFlags2 & VB2_30xBLV) &&
829 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL))) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 ModeIndex = ModeIndex_1024x576[Depth];
831 }
832 }
833 break;
834 case 1280:
835 if(VDisplay == 720) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700836 if((VBFlags & TV_HIVISION) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR1080I | TV_YPBPR750P)))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700838 ModeIndex = ModeIndex_1280x720[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 }
840 } else if(VDisplay == 1024) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700841 if((VBFlags & TV_HIVISION) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700843 ModeIndex = ModeIndex_1280x1024[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 }
845 }
846 break;
847 }
848 }
849 return ModeIndex;
850}
851
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700852unsigned short
853SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, int Depth,
854 unsigned int VBFlags2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700856 if(!(VBFlags2 & VB2_SISVGA2BRIDGE)) return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700858 if(HDisplay >= 1920) return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 switch(HDisplay)
861 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 case 1600:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700863 if(VDisplay == 1200) {
864 if(VGAEngine != SIS_315_VGA) return 0;
865 if(!(VBFlags2 & VB2_30xB)) return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
867 break;
868 case 1680:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700869 if(VDisplay == 1050) {
870 if(VGAEngine != SIS_315_VGA) return 0;
871 if(!(VBFlags2 & VB2_30xB)) return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 }
873 break;
874 }
875
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800876 return SiS_GetModeID(VGAEngine, 0, HDisplay, VDisplay, Depth, false, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877}
878
879
880/*********************************************/
881/* HELPER: SetReg, GetReg */
882/*********************************************/
883
884void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700885SiS_SetReg(SISIOADDRESS port, unsigned short index, unsigned short data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700887 OutPortByte(port, index);
888 OutPortByte(port + 1, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889}
890
891void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700892SiS_SetRegByte(SISIOADDRESS port, unsigned short data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700894 OutPortByte(port, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895}
896
897void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700898SiS_SetRegShort(SISIOADDRESS port, unsigned short data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700900 OutPortWord(port, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
902
903void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700904SiS_SetRegLong(SISIOADDRESS port, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700906 OutPortLong(port, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907}
908
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700909unsigned char
910SiS_GetReg(SISIOADDRESS port, unsigned short index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700912 OutPortByte(port, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 return(InPortByte(port + 1));
914}
915
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700916unsigned char
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917SiS_GetRegByte(SISIOADDRESS port)
918{
919 return(InPortByte(port));
920}
921
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700922unsigned short
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923SiS_GetRegShort(SISIOADDRESS port)
924{
925 return(InPortWord(port));
926}
927
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700928unsigned int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929SiS_GetRegLong(SISIOADDRESS port)
930{
931 return(InPortLong(port));
932}
933
934void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700935SiS_SetRegANDOR(SISIOADDRESS Port, unsigned short Index, unsigned short DataAND, unsigned short DataOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700937 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700939 temp = SiS_GetReg(Port, Index);
940 temp = (temp & (DataAND)) | DataOR;
941 SiS_SetReg(Port, Index, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
943
944void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700945SiS_SetRegAND(SISIOADDRESS Port, unsigned short Index, unsigned short DataAND)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700947 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700949 temp = SiS_GetReg(Port, Index);
950 temp &= DataAND;
951 SiS_SetReg(Port, Index, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952}
953
954void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700955SiS_SetRegOR(SISIOADDRESS Port, unsigned short Index, unsigned short DataOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700957 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700959 temp = SiS_GetReg(Port, Index);
960 temp |= DataOR;
961 SiS_SetReg(Port, Index, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962}
963
964/*********************************************/
965/* HELPER: DisplayOn, DisplayOff */
966/*********************************************/
967
968void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700969SiS_DisplayOn(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
971 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x01,0xDF);
972}
973
974void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700975SiS_DisplayOff(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
977 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x20);
978}
979
980
981/*********************************************/
982/* HELPER: Init Port Addresses */
983/*********************************************/
984
985void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700986SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987{
988 SiS_Pr->SiS_P3c4 = BaseAddr + 0x14;
989 SiS_Pr->SiS_P3d4 = BaseAddr + 0x24;
990 SiS_Pr->SiS_P3c0 = BaseAddr + 0x10;
991 SiS_Pr->SiS_P3ce = BaseAddr + 0x1e;
992 SiS_Pr->SiS_P3c2 = BaseAddr + 0x12;
993 SiS_Pr->SiS_P3ca = BaseAddr + 0x1a;
994 SiS_Pr->SiS_P3c6 = BaseAddr + 0x16;
995 SiS_Pr->SiS_P3c7 = BaseAddr + 0x17;
996 SiS_Pr->SiS_P3c8 = BaseAddr + 0x18;
997 SiS_Pr->SiS_P3c9 = BaseAddr + 0x19;
998 SiS_Pr->SiS_P3cb = BaseAddr + 0x1b;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700999 SiS_Pr->SiS_P3cc = BaseAddr + 0x1c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 SiS_Pr->SiS_P3cd = BaseAddr + 0x1d;
1001 SiS_Pr->SiS_P3da = BaseAddr + 0x2a;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001002 SiS_Pr->SiS_Part1Port = BaseAddr + SIS_CRT2_PORT_04;
1003 SiS_Pr->SiS_Part2Port = BaseAddr + SIS_CRT2_PORT_10;
1004 SiS_Pr->SiS_Part3Port = BaseAddr + SIS_CRT2_PORT_12;
1005 SiS_Pr->SiS_Part4Port = BaseAddr + SIS_CRT2_PORT_14;
1006 SiS_Pr->SiS_Part5Port = BaseAddr + SIS_CRT2_PORT_14 + 2;
1007 SiS_Pr->SiS_DDC_Port = BaseAddr + 0x14;
1008 SiS_Pr->SiS_VidCapt = BaseAddr + SIS_VIDEO_CAPTURE;
1009 SiS_Pr->SiS_VidPlay = BaseAddr + SIS_VIDEO_PLAYBACK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010}
1011
1012/*********************************************/
1013/* HELPER: GetSysFlags */
1014/*********************************************/
1015
1016static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001017SiS_GetSysFlags(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
1019 unsigned char cr5f, temp1, temp2;
1020
1021 /* 661 and newer: NEVER write non-zero to SR11[7:4] */
1022 /* (SR11 is used for DDC and in enable/disablebridge) */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001023 SiS_Pr->SiS_SensibleSR11 = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 SiS_Pr->SiS_MyCR63 = 0x63;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001025 if(SiS_Pr->ChipType >= SIS_330) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 SiS_Pr->SiS_MyCR63 = 0x53;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001027 if(SiS_Pr->ChipType >= SIS_661) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001028 SiS_Pr->SiS_SensibleSR11 = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 }
1030 }
1031
1032 /* You should use the macros, not these flags directly */
1033
1034 SiS_Pr->SiS_SysFlags = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001035 if(SiS_Pr->ChipType == SIS_650) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 cr5f = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
1037 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x5c,0x07);
1038 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
1039 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x5c,0xf8);
1040 temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
1041 if((!temp1) || (temp2)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001042 switch(cr5f) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 case 0x80:
1044 case 0x90:
1045 case 0xc0:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001046 SiS_Pr->SiS_SysFlags |= SF_IsM650;
1047 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 case 0xa0:
1049 case 0xb0:
1050 case 0xe0:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001051 SiS_Pr->SiS_SysFlags |= SF_Is651;
1052 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
1054 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001055 switch(cr5f) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 case 0x90:
1057 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
1058 switch(temp1) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001059 case 0x00: SiS_Pr->SiS_SysFlags |= SF_IsM652; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 case 0x40: SiS_Pr->SiS_SysFlags |= SF_IsM653; break;
1061 default: SiS_Pr->SiS_SysFlags |= SF_IsM650; break;
1062 }
1063 break;
1064 case 0xb0:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001065 SiS_Pr->SiS_SysFlags |= SF_Is652;
1066 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 default:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001068 SiS_Pr->SiS_SysFlags |= SF_IsM650;
1069 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 }
1071 }
1072 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001073
1074 if(SiS_Pr->ChipType >= SIS_760 && SiS_Pr->ChipType <= SIS_761) {
1075 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0x30) {
1076 SiS_Pr->SiS_SysFlags |= SF_760LFB;
1077 }
1078 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0xf0) {
1079 SiS_Pr->SiS_SysFlags |= SF_760UMA;
1080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 }
1082}
1083
1084/*********************************************/
1085/* HELPER: Init PCI & Engines */
1086/*********************************************/
1087
1088static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001089SiSInitPCIetc(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001091 switch(SiS_Pr->ChipType) {
1092#ifdef SIS300
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 case SIS_300:
1094 case SIS_540:
1095 case SIS_630:
1096 case SIS_730:
1097 /* Set - PCI LINEAR ADDRESSING ENABLE (0x80)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001098 * - RELOCATED VGA IO ENABLED (0x20)
1099 * - MMIO ENABLED (0x01)
1100 * Leave other bits untouched.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001102 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 /* - Enable 2D (0x40)
1104 * - Enable 3D (0x02)
1105 * - Enable 3D Vertex command fetch (0x10) ?
1106 * - Enable 3D command parser (0x08) ?
1107 */
1108 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x5A);
1109 break;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001110#endif
1111#ifdef SIS315H
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 case SIS_315H:
1113 case SIS_315:
1114 case SIS_315PRO:
1115 case SIS_650:
1116 case SIS_740:
1117 case SIS_330:
1118 case SIS_661:
1119 case SIS_741:
1120 case SIS_660:
1121 case SIS_760:
1122 case SIS_761:
1123 case SIS_340:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001124 case XGI_40:
1125 /* See above */
1126 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
1127 /* - Enable 3D G/L transformation engine (0x80)
1128 * - Enable 2D (0x40)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 * - Enable 3D vertex command fetch (0x10)
1130 * - Enable 3D command parser (0x08)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001131 * - Enable 3D (0x02)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 */
1133 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0xDA);
1134 break;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001135 case XGI_20:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 case SIS_550:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001137 /* See above */
1138 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 /* No 3D engine ! */
1140 /* - Enable 2D (0x40)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001141 * - disable 3D
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001143 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1E,0x60,0x40);
1144 break;
1145#endif
1146 default:
1147 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 }
1149}
1150
1151/*********************************************/
1152/* HELPER: SetLVDSetc */
1153/*********************************************/
1154
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001155#ifdef SIS_LINUX_KERNEL
1156static
1157#endif
1158void
1159SiSSetLVDSetc(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001161 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
1163 SiS_Pr->SiS_IF_DEF_LVDS = 0;
1164 SiS_Pr->SiS_IF_DEF_TRUMPION = 0;
1165 SiS_Pr->SiS_IF_DEF_CH70xx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 SiS_Pr->SiS_IF_DEF_CONEX = 0;
1167
1168 SiS_Pr->SiS_ChrontelInit = 0;
1169
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001170 if(SiS_Pr->ChipType == XGI_20) return;
1171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 /* Check for SiS30x first */
1173 temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
1174 if((temp == 1) || (temp == 2)) return;
1175
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001176 switch(SiS_Pr->ChipType) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177#ifdef SIS300
1178 case SIS_540:
1179 case SIS_630:
1180 case SIS_730:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001181 temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x37) & 0x0e) >> 1;
1182 if((temp >= 2) && (temp <= 5)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
1183 if(temp == 3) SiS_Pr->SiS_IF_DEF_TRUMPION = 1;
1184 if((temp == 4) || (temp == 5)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 /* Save power status (and error check) - UNUSED */
1186 SiS_Pr->SiS_Backup70xx = SiS_GetCH700x(SiS_Pr, 0x0e);
1187 SiS_Pr->SiS_IF_DEF_CH70xx = 1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 break;
1190#endif
1191#ifdef SIS315H
1192 case SIS_550:
1193 case SIS_650:
1194 case SIS_740:
1195 case SIS_330:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001196 temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x37) & 0x0e) >> 1;
1197 if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
1198 if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2;
1199 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 case SIS_661:
1201 case SIS_741:
1202 case SIS_660:
1203 case SIS_760:
1204 case SIS_761:
1205 case SIS_340:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001206 case XGI_20:
1207 case XGI_40:
1208 temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0xe0) >> 5;
1209 if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
1210 if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2;
1211 if(temp == 4) SiS_Pr->SiS_IF_DEF_CONEX = 1; /* Not yet supported */
1212 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213#endif
1214 default:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001215 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 }
1217}
1218
1219/*********************************************/
1220/* HELPER: Enable DSTN/FSTN */
1221/*********************************************/
1222
1223void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001224SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225{
1226 SiS_Pr->SiS_IF_DEF_DSTN = enable ? 1 : 0;
1227}
1228
1229void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001230SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231{
1232 SiS_Pr->SiS_IF_DEF_FSTN = enable ? 1 : 0;
1233}
1234
1235/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001236/* HELPER: Get modeflag */
1237/*********************************************/
1238
1239unsigned short
1240SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1241 unsigned short ModeIdIndex)
1242{
1243 if(SiS_Pr->UseCustomMode) {
1244 return SiS_Pr->CModeFlag;
1245 } else if(ModeNo <= 0x13) {
1246 return SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
1247 } else {
1248 return SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1249 }
1250}
1251
1252/*********************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253/* HELPER: Determine ROM usage */
1254/*********************************************/
1255
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001256bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001257SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001259 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1260 unsigned short romversoffs, romvmaj = 1, romvmin = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001262 if(SiS_Pr->ChipType >= XGI_20) {
1263 /* XGI ROMs don't qualify */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001264 return false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001265 } else if(SiS_Pr->ChipType >= SIS_761) {
1266 /* I very much assume 761, 340 and newer will use new layout */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001267 return true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001268 } else if(SiS_Pr->ChipType >= SIS_661) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 if((ROMAddr[0x1a] == 'N') &&
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001270 (ROMAddr[0x1b] == 'e') &&
1271 (ROMAddr[0x1c] == 'w') &&
1272 (ROMAddr[0x1d] == 'V')) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001273 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 }
1275 romversoffs = ROMAddr[0x16] | (ROMAddr[0x17] << 8);
1276 if(romversoffs) {
1277 if((ROMAddr[romversoffs+1] == '.') || (ROMAddr[romversoffs+4] == '.')) {
1278 romvmaj = ROMAddr[romversoffs] - '0';
1279 romvmin = ((ROMAddr[romversoffs+2] -'0') * 10) + (ROMAddr[romversoffs+3] - '0');
1280 }
1281 }
1282 if((romvmaj != 0) || (romvmin >= 92)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001283 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 }
1285 } else if(IS_SIS650740) {
1286 if((ROMAddr[0x1a] == 'N') &&
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001287 (ROMAddr[0x1b] == 'e') &&
1288 (ROMAddr[0x1c] == 'w') &&
1289 (ROMAddr[0x1d] == 'V')) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001290 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 }
1292 }
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001293 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294}
1295
1296static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001297SiSDetermineROMUsage(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001299 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1300 unsigned short romptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001302 SiS_Pr->SiS_UseROM = false;
1303 SiS_Pr->SiS_ROMNew = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001304 SiS_Pr->SiS_PWDOffset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001306 if(SiS_Pr->ChipType >= XGI_20) return;
1307
1308 if((ROMAddr) && (SiS_Pr->UseROM)) {
1309 if(SiS_Pr->ChipType == SIS_300) {
1310 /* 300: We check if the code starts below 0x220 by
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 * checking the jmp instruction at the beginning
1312 * of the BIOS image.
1313 */
1314 if((ROMAddr[3] == 0xe9) && ((ROMAddr[5] << 8) | ROMAddr[4]) > 0x21a)
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001315 SiS_Pr->SiS_UseROM = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001316 } else if(SiS_Pr->ChipType < SIS_315H) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 /* Sony's VAIO BIOS 1.09 follows the standard, so perhaps
1318 * the others do as well
1319 */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001320 SiS_Pr->SiS_UseROM = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001322 /* 315/330 series stick to the standard(s) */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001323 SiS_Pr->SiS_UseROM = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001324 if((SiS_Pr->SiS_ROMNew = SiSDetermineROMLayout661(SiS_Pr))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 SiS_Pr->SiS_EMIOffset = 14;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001326 SiS_Pr->SiS_PWDOffset = 17;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 SiS_Pr->SiS661LCD2TableSize = 36;
1328 /* Find out about LCD data table entry size */
1329 if((romptr = SISGETROMW(0x0102))) {
1330 if(ROMAddr[romptr + (32 * 16)] == 0xff)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001331 SiS_Pr->SiS661LCD2TableSize = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 else if(ROMAddr[romptr + (34 * 16)] == 0xff)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001333 SiS_Pr->SiS661LCD2TableSize = 34;
1334 else if(ROMAddr[romptr + (36 * 16)] == 0xff) /* 0.94, 2.05.00+ */
1335 SiS_Pr->SiS661LCD2TableSize = 36;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 else if( (ROMAddr[romptr + (38 * 16)] == 0xff) || /* 2.00.00 - 2.02.00 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001337 (ROMAddr[0x6F] & 0x01) ) { /* 2.03.00 - <2.05.00 */
1338 SiS_Pr->SiS661LCD2TableSize = 38; /* UMC data layout abandoned at 2.05.00 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 SiS_Pr->SiS_EMIOffset = 16;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001340 SiS_Pr->SiS_PWDOffset = 19;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 }
1342 }
1343 }
1344 }
1345 }
1346}
1347
1348/*********************************************/
1349/* HELPER: SET SEGMENT REGISTERS */
1350/*********************************************/
1351
1352static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001353SiS_SetSegRegLower(struct SiS_Private *SiS_Pr, unsigned short value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001355 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
1357 value &= 0x00ff;
1358 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0xf0;
1359 temp |= (value >> 4);
1360 SiS_SetRegByte(SiS_Pr->SiS_P3cb, temp);
1361 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cd) & 0xf0;
1362 temp |= (value & 0x0f);
1363 SiS_SetRegByte(SiS_Pr->SiS_P3cd, temp);
1364}
1365
1366static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001367SiS_SetSegRegUpper(struct SiS_Private *SiS_Pr, unsigned short value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001369 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
1371 value &= 0x00ff;
1372 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0x0f;
1373 temp |= (value & 0xf0);
1374 SiS_SetRegByte(SiS_Pr->SiS_P3cb, temp);
1375 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cd) & 0x0f;
1376 temp |= (value << 4);
1377 SiS_SetRegByte(SiS_Pr->SiS_P3cd, temp);
1378}
1379
1380static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001381SiS_SetSegmentReg(struct SiS_Private *SiS_Pr, unsigned short value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382{
1383 SiS_SetSegRegLower(SiS_Pr, value);
1384 SiS_SetSegRegUpper(SiS_Pr, value);
1385}
1386
1387static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001388SiS_ResetSegmentReg(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389{
1390 SiS_SetSegmentReg(SiS_Pr, 0);
1391}
1392
1393static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001394SiS_SetSegmentRegOver(struct SiS_Private *SiS_Pr, unsigned short value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001396 unsigned short temp = value >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398 temp &= 0x07;
1399 temp |= (temp << 4);
1400 SiS_SetReg(SiS_Pr->SiS_P3c4,0x1d,temp);
1401 SiS_SetSegmentReg(SiS_Pr, value);
1402}
1403
1404static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001405SiS_ResetSegmentRegOver(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406{
1407 SiS_SetSegmentRegOver(SiS_Pr, 0);
1408}
1409
1410static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001411SiS_ResetSegmentRegisters(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001413 if((IS_SIS65x) || (SiS_Pr->ChipType >= SIS_661)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 SiS_ResetSegmentReg(SiS_Pr);
1415 SiS_ResetSegmentRegOver(SiS_Pr);
1416 }
1417}
1418
1419/*********************************************/
1420/* HELPER: GetVBType */
1421/*********************************************/
1422
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001423#ifdef SIS_LINUX_KERNEL
1424static
1425#endif
1426void
1427SiS_GetVBType(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001429 unsigned short flag = 0, rev = 0, nolcd = 0;
1430 unsigned short p4_0f, p4_25, p4_27;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001432 SiS_Pr->SiS_VBType = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001434 if((SiS_Pr->SiS_IF_DEF_LVDS) || (SiS_Pr->SiS_IF_DEF_CONEX))
1435 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001437 if(SiS_Pr->ChipType == XGI_20)
1438 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001440 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001442 if(flag > 3)
1443 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001445 rev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01);
1446
1447 if(flag >= 2) {
1448 SiS_Pr->SiS_VBType = VB_SIS302B;
1449 } else if(flag == 1) {
1450 if(rev >= 0xC0) {
1451 SiS_Pr->SiS_VBType = VB_SIS301C;
1452 } else if(rev >= 0xB0) {
1453 SiS_Pr->SiS_VBType = VB_SIS301B;
1454 /* Check if 30xB DH version (no LCD support, use Panel Link instead) */
1455 nolcd = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x23);
1456 if(!(nolcd & 0x02)) SiS_Pr->SiS_VBType |= VB_NoLCD;
1457 } else {
1458 SiS_Pr->SiS_VBType = VB_SIS301;
1459 }
1460 }
1461 if(SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS301C | VB_SIS302B)) {
1462 if(rev >= 0xE0) {
1463 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x39);
1464 if(flag == 0xff) SiS_Pr->SiS_VBType = VB_SIS302LV;
1465 else SiS_Pr->SiS_VBType = VB_SIS301C; /* VB_SIS302ELV; */
1466 } else if(rev >= 0xD0) {
1467 SiS_Pr->SiS_VBType = VB_SIS301LV;
1468 }
1469 }
1470 if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) {
1471 p4_0f = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x0f);
1472 p4_25 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x25);
1473 p4_27 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x27);
1474 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0x7f);
1475 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x25,0x08);
1476 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,0xfd);
1477 if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x08) {
1478 SiS_Pr->SiS_VBType |= VB_UMC;
1479 }
1480 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x27,p4_27);
1481 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x25,p4_25);
1482 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0f,p4_0f);
1483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484}
1485
1486/*********************************************/
1487/* HELPER: Check RAM size */
1488/*********************************************/
1489
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001490#ifdef SIS_LINUX_KERNEL
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001491static bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001492SiS_CheckMemorySize(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1493 unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001495 unsigned short AdapterMemSize = SiS_Pr->VideoMemorySize / (1024*1024);
1496 unsigned short modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
1497 unsigned short memorysize = ((modeflag & MemoryInfoFlag) >> MemorySizeShift) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001499 if(!AdapterMemSize) return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001501 if(AdapterMemSize < memorysize) return false;
1502 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504#endif
1505
1506/*********************************************/
1507/* HELPER: Get DRAM type */
1508/*********************************************/
1509
1510#ifdef SIS315H
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001511static unsigned char
1512SiS_Get310DRAMType(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001514 unsigned char data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
1516 if((*SiS_Pr->pSiS_SoftSetting) & SoftDRAMType) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001517 data = (*SiS_Pr->pSiS_SoftSetting) & 0x03;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001519 if(SiS_Pr->ChipType >= XGI_20) {
1520 /* Do I need this? SR17 seems to be zero anyway... */
1521 data = 0;
1522 } else if(SiS_Pr->ChipType >= SIS_340) {
1523 /* TODO */
1524 data = 0;
1525 } if(SiS_Pr->ChipType >= SIS_661) {
1526 if(SiS_Pr->SiS_ROMNew) {
1527 data = ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0xc0) >> 6);
1528 } else {
1529 data = SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0x07;
1530 }
1531 } else if(IS_SIS550650740) {
1532 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x07;
1533 } else { /* 315, 330 */
1534 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x03;
1535 if(SiS_Pr->ChipType == SIS_330) {
1536 if(data > 1) {
1537 switch(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0x30) {
1538 case 0x00: data = 1; break;
1539 case 0x10: data = 3; break;
1540 case 0x20: data = 3; break;
1541 case 0x30: data = 2; break;
1542 }
1543 } else {
1544 data = 0;
1545 }
1546 }
1547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 }
1549
1550 return data;
1551}
1552
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001553static unsigned short
1554SiS_GetMCLK(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001556 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1557 unsigned short index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001559 index = SiS_Get310DRAMType(SiS_Pr);
1560 if(SiS_Pr->ChipType >= SIS_661) {
1561 if(SiS_Pr->SiS_ROMNew) {
1562 return((unsigned short)(SISGETROMW((0x90 + (index * 5) + 3))));
1563 }
1564 return(SiS_Pr->SiS_MCLKData_0[index].CLOCK);
1565 } else if(index >= 4) {
1566 return(SiS_Pr->SiS_MCLKData_1[index - 4].CLOCK);
1567 } else {
1568 return(SiS_Pr->SiS_MCLKData_0[index].CLOCK);
1569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570}
1571#endif
1572
1573/*********************************************/
1574/* HELPER: ClearBuffer */
1575/*********************************************/
1576
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001577#ifdef SIS_LINUX_KERNEL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001579SiS_ClearBuffer(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001581 unsigned char SISIOMEMTYPE *memaddr = SiS_Pr->VideoMemoryAddress;
1582 unsigned int memsize = SiS_Pr->VideoMemorySize;
1583 unsigned short SISIOMEMTYPE *pBuffer;
1584 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001586 if(!memaddr || !memsize) return;
1587
1588 if(SiS_Pr->SiS_ModeType >= ModeEGA) {
1589 if(ModeNo > 0x13) {
1590 SiS_SetMemory(memaddr, memsize, 0);
1591 } else {
1592 pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
1593 for(i = 0; i < 0x4000; i++) writew(0x0000, &pBuffer[i]);
1594 }
1595 } else if(SiS_Pr->SiS_ModeType < ModeCGA) {
1596 pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
1597 for(i = 0; i < 0x4000; i++) writew(0x0720, &pBuffer[i]);
1598 } else {
1599 SiS_SetMemory(memaddr, 0x8000, 0);
1600 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601}
1602#endif
1603
1604/*********************************************/
1605/* HELPER: SearchModeID */
1606/*********************************************/
1607
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001608bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001609SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
1610 unsigned short *ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001612 unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001614 if((*ModeNo) <= 0x13) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
1616 if((*ModeNo) <= 0x05) (*ModeNo) |= 0x01;
1617
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001618 for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
1619 if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == (*ModeNo)) break;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001620 if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == 0xFF) return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 }
1622
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001623 if((*ModeNo) == 0x07) {
1624 if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */
1625 /* else 350 lines */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001627 if((*ModeNo) <= 0x03) {
1628 if(!(VGAINFO & 0x80)) (*ModeIdIndex)++;
1629 if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */
1630 /* else 350 lines */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 }
1632 /* else 200 lines */
1633
1634 } else {
1635
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001636 for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
1637 if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == (*ModeNo)) break;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001638 if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == 0xFF) return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 }
1640
1641 }
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001642 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643}
1644
1645/*********************************************/
1646/* HELPER: GetModePtr */
1647/*********************************************/
1648
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001649unsigned short
1650SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001652 unsigned short index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
1654 if(ModeNo <= 0x13) {
1655 index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_StTableIndex;
1656 } else {
1657 if(SiS_Pr->SiS_ModeType <= ModeEGA) index = 0x1B;
1658 else index = 0x0F;
1659 }
1660 return index;
1661}
1662
1663/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001664/* HELPERS: Get some indices */
1665/*********************************************/
1666
1667unsigned short
1668SiS_GetRefCRTVCLK(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide)
1669{
1670 if(SiS_Pr->SiS_RefIndex[Index].Ext_InfoFlag & HaveWideTiming) {
1671 if(UseWide == 1) {
1672 return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK_WIDE;
1673 } else {
1674 return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK_NORM;
1675 }
1676 } else {
1677 return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK;
1678 }
1679}
1680
1681unsigned short
1682SiS_GetRefCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide)
1683{
1684 if(SiS_Pr->SiS_RefIndex[Index].Ext_InfoFlag & HaveWideTiming) {
1685 if(UseWide == 1) {
1686 return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC_WIDE;
1687 } else {
1688 return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC_NORM;
1689 }
1690 } else {
1691 return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC;
1692 }
1693}
1694
1695/*********************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696/* HELPER: LowModeTests */
1697/*********************************************/
1698
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001699static bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001700SiS_DoLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001702 unsigned short temp, temp1, temp2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001704 if((ModeNo != 0x03) && (ModeNo != 0x10) && (ModeNo != 0x12))
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001705 return true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001706 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x11);
1707 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x11,0x80);
1708 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00);
1709 SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,0x55);
1710 temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00);
1711 SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,temp1);
1712 SiS_SetReg(SiS_Pr->SiS_P3d4,0x11,temp);
1713 if((SiS_Pr->ChipType >= SIS_315H) ||
1714 (SiS_Pr->ChipType == SIS_300)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001715 if(temp2 == 0x55) return false;
1716 else return true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001717 } else {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001718 if(temp2 != 0x55) return true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001719 else {
1720 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001721 return false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001722 }
1723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724}
1725
1726static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001727SiS_SetLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001729 if(SiS_DoLowModeTest(SiS_Pr, ModeNo)) {
1730 SiS_Pr->SiS_SetFlag |= LowModeTests;
1731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
1734/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001735/* HELPER: OPEN/CLOSE CRT1 CRTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736/*********************************************/
1737
1738static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001739SiS_OpenCRTC(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001741 if(IS_SIS650) {
1742 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f);
1743 if(IS_SIS651) SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x20);
1744 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7);
1745 } else if(IS_SIS661741660760) {
1746 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x61,0xf7);
1747 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f);
1748 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7);
1749 if(!SiS_Pr->SiS_ROMNew) {
1750 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x3a,0xef);
1751 }
1752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753}
1754
1755static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001756SiS_CloseCRTC(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001758#if 0 /* This locks some CRTC registers. We don't want that. */
1759 unsigned short temp1 = 0, temp2 = 0;
1760
1761 if(IS_SIS661741660760) {
1762 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
1763 temp1 = 0xa0; temp2 = 0x08;
1764 }
1765 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x51,0x1f,temp1);
1766 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x56,0xe7,temp2);
1767 }
1768#endif
1769}
1770
1771static void
1772SiS_HandleCRT1(struct SiS_Private *SiS_Pr)
1773{
1774 /* Enable CRT1 gating */
1775 SiS_SetRegAND(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0xbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776#if 0
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001777 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x01)) {
1778 if((SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x0a) ||
1779 (SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x01)) {
1780 SiS_SetRegOR(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0x40);
1781 }
1782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783#endif
1784}
1785
1786/*********************************************/
1787/* HELPER: GetColorDepth */
1788/*********************************************/
1789
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001790unsigned short
1791SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1792 unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001794 static const unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
1795 unsigned short modeflag;
1796 short index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001798 /* Do NOT check UseCustomMode, will skrew up FIFO */
1799 if(ModeNo == 0xfe) {
1800 modeflag = SiS_Pr->CModeFlag;
1801 } else if(ModeNo <= 0x13) {
1802 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
1803 } else {
1804 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1805 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001807 index = (modeflag & ModeTypeMask) - ModeEGA;
1808 if(index < 0) index = 0;
1809 return ColorDepth[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810}
1811
1812/*********************************************/
1813/* HELPER: GetOffset */
1814/*********************************************/
1815
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001816unsigned short
1817SiS_GetOffset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1818 unsigned short ModeIdIndex, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001820 unsigned short xres, temp, colordepth, infoflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001822 if(SiS_Pr->UseCustomMode) {
1823 infoflag = SiS_Pr->CInfoFlag;
1824 xres = SiS_Pr->CHDisplay;
1825 } else {
1826 infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
1827 xres = SiS_Pr->SiS_RefIndex[RRTI].XRes;
1828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001830 colordepth = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001832 temp = xres / 16;
1833 if(infoflag & InterlaceMode) temp <<= 1;
1834 temp *= colordepth;
1835 if(xres % 16) temp += (colordepth >> 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001837 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838}
1839
1840/*********************************************/
1841/* SEQ */
1842/*********************************************/
1843
1844static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001845SiS_SetSeqRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001847 unsigned char SRdata;
1848 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001850 SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001852 /* or "display off" */
1853 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[0] | 0x20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001855 /* determine whether to force x8 dotclock */
1856 if((SiS_Pr->SiS_VBType & VB_SISVB) || (SiS_Pr->SiS_IF_DEF_LVDS)) {
1857
1858 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
1859 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) SRdata |= 0x01;
1860 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) SRdata |= 0x01;
1861
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 }
1863
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 SiS_SetReg(SiS_Pr->SiS_P3c4,0x01,SRdata);
1865
1866 for(i = 2; i <= 4; i++) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001867 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[i - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 SiS_SetReg(SiS_Pr->SiS_P3c4,i,SRdata);
1869 }
1870}
1871
1872/*********************************************/
1873/* MISC */
1874/*********************************************/
1875
1876static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001877SiS_SetMiscRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001879 unsigned char Miscdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
1881 Miscdata = SiS_Pr->SiS_StandTable[StandTableIndex].MISC;
1882
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001883 if(SiS_Pr->ChipType < SIS_661) {
1884 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
1885 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
1886 Miscdata |= 0x0C;
1887 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 }
1889 }
1890
1891 SiS_SetRegByte(SiS_Pr->SiS_P3c2,Miscdata);
1892}
1893
1894/*********************************************/
1895/* CRTC */
1896/*********************************************/
1897
1898static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001899SiS_SetCRTCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001901 unsigned char CRTCdata;
1902 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001904 /* Unlock CRTC */
1905 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001907 for(i = 0; i <= 0x18; i++) {
1908 CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
1909 SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata);
1910 }
1911
1912 if(SiS_Pr->ChipType >= SIS_661) {
1913 SiS_OpenCRTC(SiS_Pr);
1914 for(i = 0x13; i <= 0x14; i++) {
1915 CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
1916 SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata);
1917 }
1918 } else if( ( (SiS_Pr->ChipType == SIS_630) ||
1919 (SiS_Pr->ChipType == SIS_730) ) &&
1920 (SiS_Pr->ChipRevision >= 0x30) ) {
1921 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
1922 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
1923 SiS_SetReg(SiS_Pr->SiS_P3d4,0x18,0xFE);
1924 }
1925 }
1926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927}
1928
1929/*********************************************/
1930/* ATT */
1931/*********************************************/
1932
1933static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001934SiS_SetATTRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001936 unsigned char ARdata;
1937 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938
1939 for(i = 0; i <= 0x13; i++) {
1940 ARdata = SiS_Pr->SiS_StandTable[StandTableIndex].ATTR[i];
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001941
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 if(i == 0x13) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001943 /* Pixel shift. If screen on LCD or TV is shifted left or right,
1944 * this might be the cause.
1945 */
1946 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
1947 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) ARdata = 0;
1948 }
1949 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
1950 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
1951 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
1952 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
1953 }
1954 }
1955 }
1956 if(SiS_Pr->ChipType >= SIS_661) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001958 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 }
1960 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001961 if(SiS_Pr->ChipType >= SIS_315H) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 if(IS_SIS550650740660) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001963 /* 315, 330 don't do this */
1964 if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
1965 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
1966 } else {
1967 ARdata = 0;
1968 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 }
1970 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001971 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001975 SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */
1976 SiS_SetRegByte(SiS_Pr->SiS_P3c0,i); /* set index */
1977 SiS_SetRegByte(SiS_Pr->SiS_P3c0,ARdata); /* set data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001979
1980 SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */
1981 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x14); /* set index */
1982 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x00); /* set data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
1984 SiS_GetRegByte(SiS_Pr->SiS_P3da);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001985 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x20); /* Enable Attribute */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 SiS_GetRegByte(SiS_Pr->SiS_P3da);
1987}
1988
1989/*********************************************/
1990/* GRC */
1991/*********************************************/
1992
1993static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001994SiS_SetGRCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001996 unsigned char GRdata;
1997 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
1999 for(i = 0; i <= 0x08; i++) {
2000 GRdata = SiS_Pr->SiS_StandTable[StandTableIndex].GRC[i];
2001 SiS_SetReg(SiS_Pr->SiS_P3ce,i,GRdata);
2002 }
2003
2004 if(SiS_Pr->SiS_ModeType > ModeVGA) {
2005 /* 256 color disable */
2006 SiS_SetRegAND(SiS_Pr->SiS_P3ce,0x05,0xBF);
2007 }
2008}
2009
2010/*********************************************/
2011/* CLEAR EXTENDED REGISTERS */
2012/*********************************************/
2013
2014static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002015SiS_ClearExt1Regs(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002017 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002019 for(i = 0x0A; i <= 0x0E; i++) {
2020 SiS_SetReg(SiS_Pr->SiS_P3c4,i,0x00);
2021 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002023 if(SiS_Pr->ChipType >= SIS_315H) {
2024 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x37,0xFE);
2025 if(ModeNo <= 0x13) {
2026 if(ModeNo == 0x06 || ModeNo >= 0x0e) {
2027 SiS_SetReg(SiS_Pr->SiS_P3c4,0x0e,0x20);
2028 }
2029 }
2030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031}
2032
2033/*********************************************/
2034/* RESET VCLK */
2035/*********************************************/
2036
2037static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002038SiS_ResetCRT1VCLK(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002040 if(SiS_Pr->ChipType >= SIS_315H) {
2041 if(SiS_Pr->ChipType < SIS_661) {
2042 if(SiS_Pr->SiS_IF_DEF_LVDS == 0) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 }
2044 } else {
2045 if((SiS_Pr->SiS_IF_DEF_LVDS == 0) &&
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002046 (!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 return;
2048 }
2049 }
2050
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002051 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xcf,0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[1].SR2B);
2053 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[1].SR2C);
2054 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002055 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xcf,0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[0].SR2B);
2057 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[0].SR2C);
2058 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
2059}
2060
2061/*********************************************/
2062/* SYNC */
2063/*********************************************/
2064
2065static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002066SiS_SetCRT1Sync(struct SiS_Private *SiS_Pr, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002068 unsigned short sync;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002070 if(SiS_Pr->UseCustomMode) {
2071 sync = SiS_Pr->CInfoFlag >> 8;
2072 } else {
2073 sync = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag >> 8;
2074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002076 sync &= 0xC0;
2077 sync |= 0x2f;
2078 SiS_SetRegByte(SiS_Pr->SiS_P3c2,sync);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079}
2080
2081/*********************************************/
2082/* CRTC/2 */
2083/*********************************************/
2084
2085static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002086SiS_SetCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2087 unsigned short ModeIdIndex, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002089 unsigned short temp, i, j, modeflag;
2090 unsigned char *crt1data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002092 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002094 if(SiS_Pr->UseCustomMode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002096 crt1data = &SiS_Pr->CCRT1CRTC[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002098 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002100 temp = SiS_GetRefCRT1CRTC(SiS_Pr, RRTI, SiS_Pr->SiS_UseWide);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002102 /* Alternate for 1600x1200 LCDA */
2103 if((temp == 0x20) && (SiS_Pr->Alternate1600x1200)) temp = 0x57;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002105 crt1data = (unsigned char *)&SiS_Pr->SiS_CRT1Table[temp].CR[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002109 /* unlock cr0-7 */
2110 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002112 for(i = 0, j = 0; i <= 7; i++, j++) {
2113 SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
2114 }
2115 for(j = 0x10; i <= 10; i++, j++) {
2116 SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
2117 }
2118 for(j = 0x15; i <= 12; i++, j++) {
2119 SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
2120 }
2121 for(j = 0x0A; i <= 15; i++, j++) {
2122 SiS_SetReg(SiS_Pr->SiS_P3c4,j,crt1data[i]);
2123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002125 SiS_SetReg(SiS_Pr->SiS_P3c4,0x0E,crt1data[16] & 0xE0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002127 temp = (crt1data[16] & 0x01) << 5;
2128 if(modeflag & DoubleScanMode) temp |= 0x80;
2129 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002131 if(SiS_Pr->SiS_ModeType > ModeVGA) {
2132 SiS_SetReg(SiS_Pr->SiS_P3d4,0x14,0x4F);
2133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002135#ifdef SIS315H
2136 if(SiS_Pr->ChipType == XGI_20) {
2137 SiS_SetReg(SiS_Pr->SiS_P3d4,0x04,crt1data[4] - 1);
2138 if(!(temp = crt1data[5] & 0x1f)) {
2139 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x0c,0xfb);
2140 }
2141 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x05,0xe0,((temp - 1) & 0x1f));
2142 temp = (crt1data[16] >> 5) + 3;
2143 if(temp > 7) temp -= 7;
2144 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0e,0x1f,(temp << 5));
2145 }
2146#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147}
2148
2149/*********************************************/
2150/* OFFSET & PITCH */
2151/*********************************************/
2152/* (partly overruled by SetPitch() in XF86) */
2153/*********************************************/
2154
2155static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002156SiS_SetCRT1Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2157 unsigned short ModeIdIndex, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002159 unsigned short temp, DisplayUnit, infoflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
2161 if(SiS_Pr->UseCustomMode) {
2162 infoflag = SiS_Pr->CInfoFlag;
2163 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002164 infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 }
2166
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002167 DisplayUnit = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
2169 temp = (DisplayUnit >> 8) & 0x0f;
2170 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0xF0,temp);
2171
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002172 SiS_SetReg(SiS_Pr->SiS_P3d4,0x13,DisplayUnit & 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
2174 if(infoflag & InterlaceMode) DisplayUnit >>= 1;
2175
2176 DisplayUnit <<= 5;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002177 temp = (DisplayUnit >> 8) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 if(DisplayUnit & 0xff) temp++;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002179 if(SiS_Pr->ChipType == XGI_20) {
2180 if(ModeNo == 0x4a || ModeNo == 0x49) temp--;
2181 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 SiS_SetReg(SiS_Pr->SiS_P3c4,0x10,temp);
2183}
2184
2185/*********************************************/
2186/* VCLK */
2187/*********************************************/
2188
2189static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002190SiS_SetCRT1VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2191 unsigned short ModeIdIndex, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002193 unsigned short index = 0, clka, clkb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002195 if(SiS_Pr->UseCustomMode) {
2196 clka = SiS_Pr->CSR2B;
2197 clkb = SiS_Pr->CSR2C;
2198 } else {
2199 index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
2200 if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
2201 (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
2202 /* Alternate for 1600x1200 LCDA */
2203 if((index == 0x21) && (SiS_Pr->Alternate1600x1200)) index = 0x72;
2204 clka = SiS_Pr->SiS_VBVCLKData[index].Part4_A;
2205 clkb = SiS_Pr->SiS_VBVCLKData[index].Part4_B;
2206 } else {
2207 clka = SiS_Pr->SiS_VCLKData[index].SR2B;
2208 clkb = SiS_Pr->SiS_VCLKData[index].SR2C;
2209 }
2210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002212 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xCF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002214 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,clka);
2215 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002217 if(SiS_Pr->ChipType >= SIS_315H) {
2218#ifdef SIS315H
2219 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x01);
2220 if(SiS_Pr->ChipType == XGI_20) {
2221 unsigned short mf = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
2222 if(mf & HalfDCLK) {
2223 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,SiS_GetReg(SiS_Pr->SiS_P3c4,0x2b));
2224 clkb = SiS_GetReg(SiS_Pr->SiS_P3c4,0x2c);
2225 clkb = (((clkb & 0x1f) << 1) + 1) | (clkb & 0xe0);
2226 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb);
2227 }
2228 }
2229#endif
2230 } else {
2231 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
2232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233}
2234
2235/*********************************************/
2236/* FIFO */
2237/*********************************************/
2238
2239#ifdef SIS300
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002240void
2241SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *idx1,
2242 unsigned short *idx2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002244 unsigned short temp1, temp2;
2245 static const unsigned char ThTiming[8] = {
2246 1, 2, 2, 3, 0, 1, 1, 2
2247 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002249 temp1 = temp2 = (SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x62) >> 1;
2250 (*idx2) = (unsigned short)(ThTiming[((temp2 >> 3) | temp1) & 0x07]);
2251 (*idx1) = (unsigned short)(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) >> 6) & 0x03;
2252 (*idx1) |= (unsigned short)(((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 4) & 0x0c));
2253 (*idx1) <<= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254}
2255
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002256static unsigned short
2257SiS_GetFIFOThresholdA300(unsigned short idx1, unsigned short idx2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002259 static const unsigned char ThLowA[8 * 3] = {
2260 61, 3,52, 5,68, 7,100,11,
2261 43, 3,42, 5,54, 7, 78,11,
2262 34, 3,37, 5,47, 7, 67,11
2263 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002265 return (unsigned short)((ThLowA[idx1 + 1] * idx2) + ThLowA[idx1]);
2266}
2267
2268unsigned short
2269SiS_GetFIFOThresholdB300(unsigned short idx1, unsigned short idx2)
2270{
2271 static const unsigned char ThLowB[8 * 3] = {
2272 81, 4,72, 6,88, 8,120,12,
2273 55, 4,54, 6,66, 8, 90,12,
2274 42, 4,45, 6,55, 8, 75,12
2275 };
2276
2277 return (unsigned short)((ThLowB[idx1 + 1] * idx2) + ThLowB[idx1]);
2278}
2279
2280static unsigned short
2281SiS_DoCalcDelay(struct SiS_Private *SiS_Pr, unsigned short MCLK, unsigned short VCLK,
2282 unsigned short colordepth, unsigned short key)
2283{
2284 unsigned short idx1, idx2;
2285 unsigned int longtemp = VCLK * colordepth;
2286
2287 SiS_GetFIFOThresholdIndex300(SiS_Pr, &idx1, &idx2);
2288
2289 if(key == 0) {
2290 longtemp *= SiS_GetFIFOThresholdA300(idx1, idx2);
2291 } else {
2292 longtemp *= SiS_GetFIFOThresholdB300(idx1, idx2);
2293 }
2294 idx1 = longtemp % (MCLK * 16);
2295 longtemp /= (MCLK * 16);
2296 if(idx1) longtemp++;
2297 return (unsigned short)longtemp;
2298}
2299
2300static unsigned short
2301SiS_CalcDelay(struct SiS_Private *SiS_Pr, unsigned short VCLK,
2302 unsigned short colordepth, unsigned short MCLK)
2303{
2304 unsigned short temp1, temp2;
2305
2306 temp2 = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 0);
2307 temp1 = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 1);
2308 if(temp1 < 4) temp1 = 4;
2309 temp1 -= 4;
2310 if(temp2 < temp1) temp2 = temp1;
2311 return temp2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312}
2313
2314static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002315SiS_SetCRT1FIFO_300(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2316 unsigned short RefreshRateTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002318 unsigned short ThresholdLow = 0;
2319 unsigned short temp, index, VCLK, MCLK, colorth;
2320 static const unsigned short colortharray[6] = { 1, 1, 2, 2, 3, 4 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002322 if(ModeNo > 0x13) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002324 /* Get VCLK */
2325 if(SiS_Pr->UseCustomMode) {
2326 VCLK = SiS_Pr->CSRClock;
2327 } else {
2328 index = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWide);
2329 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
2330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002332 /* Get half colordepth */
2333 colorth = colortharray[(SiS_Pr->SiS_ModeType - ModeEGA)];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002335 /* Get MCLK */
2336 index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A) & 0x07;
2337 MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002339 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xc3;
2340 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3c,temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002342 do {
2343 ThresholdLow = SiS_CalcDelay(SiS_Pr, VCLK, colorth, MCLK) + 1;
2344 if(ThresholdLow < 0x13) break;
2345 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x16,0xfc);
2346 ThresholdLow = 0x13;
2347 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) >> 6;
2348 if(!temp) break;
2349 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3f,((temp - 1) << 6));
2350 } while(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002352 } else ThresholdLow = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002354 /* Write CRT/CPU threshold low, CRT/Engine threshold high */
2355 temp = (ThresholdLow << 4) | 0x0f;
2356 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002358 temp = (ThresholdLow & 0x10) << 1;
2359 if(ModeNo > 0x13) temp |= 0x40;
2360 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0f,0x9f,temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002362 /* What is this? */
2363 SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002365 /* Write CRT/CPU threshold high */
2366 temp = ThresholdLow + 3;
2367 if(temp > 0x0f) temp = 0x0f;
2368 SiS_SetReg(SiS_Pr->SiS_P3c4,0x09,temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369}
2370
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002371unsigned short
2372SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002374 static const unsigned char LatencyFactor[] = {
2375 97, 88, 86, 79, 77, 0, /* 64 bit BQ=2 */
2376 0, 87, 85, 78, 76, 54, /* 64 bit BQ=1 */
2377 97, 88, 86, 79, 77, 0, /* 128 bit BQ=2 */
2378 0, 79, 77, 70, 68, 48, /* 128 bit BQ=1 */
2379 80, 72, 69, 63, 61, 0, /* 64 bit BQ=2 */
2380 0, 70, 68, 61, 59, 37, /* 64 bit BQ=1 */
2381 86, 77, 75, 68, 66, 0, /* 128 bit BQ=2 */
2382 0, 68, 66, 59, 57, 37 /* 128 bit BQ=1 */
2383 };
2384 static const unsigned char LatencyFactor730[] = {
2385 69, 63, 61,
2386 86, 79, 77,
2387 103, 96, 94,
2388 120,113,111,
2389 137,130,128
2390 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002392 if(SiS_Pr->ChipType == SIS_730) {
2393 return (unsigned short)LatencyFactor730[index];
2394 } else {
2395 return (unsigned short)LatencyFactor[index];
2396 }
2397}
2398
2399static unsigned short
2400SiS_CalcDelay2(struct SiS_Private *SiS_Pr, unsigned char key)
2401{
2402 unsigned short index;
2403
2404 if(SiS_Pr->ChipType == SIS_730) {
2405 index = ((key & 0x0f) * 3) + ((key & 0xc0) >> 6);
2406 } else {
2407 index = (key & 0xe0) >> 5;
2408 if(key & 0x10) index += 6;
2409 if(!(key & 0x01)) index += 24;
2410 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
2411 }
2412 return SiS_GetLatencyFactor630(SiS_Pr, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413}
2414
2415static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002416SiS_SetCRT1FIFO_630(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2417 unsigned short RefreshRateTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002419 unsigned short ThresholdLow = 0;
2420 unsigned short i, data, VCLK, MCLK16, colorth = 0;
2421 unsigned int templ, datal;
2422 const unsigned char *queuedata = NULL;
2423 static const unsigned char FQBQData[21] = {
2424 0x01,0x21,0x41,0x61,0x81,
2425 0x31,0x51,0x71,0x91,0xb1,
2426 0x00,0x20,0x40,0x60,0x80,
2427 0x30,0x50,0x70,0x90,0xb0,
2428 0xff
2429 };
2430 static const unsigned char FQBQData730[16] = {
2431 0x34,0x74,0xb4,
2432 0x23,0x63,0xa3,
2433 0x12,0x52,0x92,
2434 0x01,0x41,0x81,
2435 0x00,0x40,0x80,
2436 0xff
2437 };
2438 static const unsigned short colortharray[6] = {
2439 1, 1, 2, 2, 3, 4
2440 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002442 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002444 if(ModeNo > 0x13) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002446 /* Get VCLK */
2447 if(SiS_Pr->UseCustomMode) {
2448 VCLK = SiS_Pr->CSRClock;
2449 } else {
2450 data = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWide);
2451 VCLK = SiS_Pr->SiS_VCLKData[data].CLOCK;
2452 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002454 /* Get MCLK * 16 */
2455 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A) & 0x07;
2456 MCLK16 = SiS_Pr->SiS_MCLKData_0[data].CLOCK * 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002458 /* Get half colordepth */
2459 colorth = colortharray[(SiS_Pr->SiS_ModeType - ModeEGA)];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002461 if(SiS_Pr->ChipType == SIS_730) {
2462 queuedata = &FQBQData730[0];
2463 } else {
2464 queuedata = &FQBQData[0];
2465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002467 do {
2468 templ = SiS_CalcDelay2(SiS_Pr, queuedata[i]) * VCLK * colorth;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002470 datal = templ % MCLK16;
2471 templ = (templ / MCLK16) + 1;
2472 if(datal) templ++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002474 if(templ > 0x13) {
2475 if(queuedata[i + 1] == 0xFF) {
2476 ThresholdLow = 0x13;
2477 break;
2478 }
2479 i++;
2480 } else {
2481 ThresholdLow = templ;
2482 break;
2483 }
2484 } while(queuedata[i] != 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002486 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002488 if(SiS_Pr->ChipType != SIS_730) i = 9;
2489 ThresholdLow = 0x02;
2490
2491 }
2492
2493 /* Write CRT/CPU threshold low, CRT/Engine threshold high */
2494 data = ((ThresholdLow & 0x0f) << 4) | 0x0f;
2495 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,data);
2496
2497 data = (ThresholdLow & 0x10) << 1;
2498 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xDF,data);
2499
2500 /* What is this? */
2501 SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
2502
2503 /* Write CRT/CPU threshold high (gap = 3) */
2504 data = ThresholdLow + 3;
2505 if(data > 0x0f) data = 0x0f;
2506 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x09,0x80,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507
2508 /* Write foreground and background queue */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002509#ifdef SIS_LINUX_KERNEL
2510 templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511#else
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002512 templ = pciReadLong(0x00000000, 0x50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513#endif
2514
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002515 if(SiS_Pr->ChipType == SIS_730) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002517 templ &= 0xfffff9ff;
2518 templ |= ((queuedata[i] & 0xc0) << 3);
2519
2520 } else {
2521
2522 templ &= 0xf0ffffff;
2523 if( (ModeNo <= 0x13) &&
2524 (SiS_Pr->ChipType == SIS_630) &&
2525 (SiS_Pr->ChipRevision >= 0x30) ) {
2526 templ |= 0x0b000000;
2527 } else {
2528 templ |= ((queuedata[i] & 0xf0) << 20);
2529 }
2530
2531 }
2532
2533#ifdef SIS_LINUX_KERNEL
2534 sisfb_write_nbridge_pci_dword(SiS_Pr, 0x50, templ);
2535 templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xA0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536#else
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002537 pciWriteLong(0x00000000, 0x50, templ);
2538 templ = pciReadLong(0x00000000, 0xA0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539#endif
2540
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002541 /* GUI grant timer (PCI config 0xA3) */
2542 if(SiS_Pr->ChipType == SIS_730) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002544 templ &= 0x00ffffff;
2545 datal = queuedata[i] << 8;
2546 templ |= (((datal & 0x0f00) | ((datal & 0x3000) >> 8)) << 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002548 } else {
2549
2550 templ &= 0xf0ffffff;
2551 templ |= ((queuedata[i] & 0x0f) << 24);
2552
2553 }
2554
2555#ifdef SIS_LINUX_KERNEL
2556 sisfb_write_nbridge_pci_dword(SiS_Pr, 0xA0, templ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557#else
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002558 pciWriteLong(0x00000000, 0xA0, templ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560}
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002561#endif /* SIS300 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562
2563#ifdef SIS315H
2564static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002565SiS_SetCRT1FIFO_310(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002567 unsigned short modeflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002569 /* disable auto-threshold */
2570 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x3D,0xFE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002572 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002574 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0xAE);
2575 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x09,0xF0);
2576 if(ModeNo > 0x13) {
2577 if(SiS_Pr->ChipType >= XGI_20) {
2578 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
2579 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
2580 } else if(SiS_Pr->ChipType >= SIS_661) {
2581 if(!(modeflag & HalfDCLK)) {
2582 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
2583 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
2584 }
2585 } else {
2586 if((!(modeflag & DoubleScanMode)) || (!(modeflag & HalfDCLK))) {
2587 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
2588 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
2589 }
2590 }
2591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592}
2593#endif
2594
2595/*********************************************/
2596/* MODE REGISTERS */
2597/*********************************************/
2598
2599static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002600SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2601 unsigned short RefreshRateTableIndex, unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002603 unsigned short data = 0, VCLK = 0, index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002605 if(ModeNo > 0x13) {
2606 if(SiS_Pr->UseCustomMode) {
2607 VCLK = SiS_Pr->CSRClock;
2608 } else {
2609 index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
2610 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
2611 }
2612 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002614 if(SiS_Pr->ChipType < SIS_315H) {
2615#ifdef SIS300
2616 if(VCLK > 150) data |= 0x80;
2617 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0x7B,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002619 data = 0x00;
2620 if(VCLK >= 150) data |= 0x08;
2621 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xF7,data);
2622#endif
2623 } else if(SiS_Pr->ChipType < XGI_20) {
2624#ifdef SIS315H
2625 if(VCLK >= 166) data |= 0x0c;
2626 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002628 if(VCLK >= 166) {
2629 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1f,0xe7);
2630 }
2631#endif
2632 } else {
2633#ifdef SIS315H
2634 if(VCLK >= 200) data |= 0x0c;
2635 if(SiS_Pr->ChipType == XGI_20) data &= ~0x04;
2636 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
2637 if(SiS_Pr->ChipType != XGI_20) {
2638 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xe7;
2639 if(VCLK < 200) data |= 0x10;
2640 SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,data);
2641 }
2642#endif
2643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002645 /* DAC speed */
2646 if(SiS_Pr->ChipType >= SIS_661) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002648 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xE8,0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002650 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002652 data = 0x03;
2653 if(VCLK >= 260) data = 0x00;
2654 else if(VCLK >= 160) data = 0x01;
2655 else if(VCLK >= 135) data = 0x02;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002657 if(SiS_Pr->ChipType == SIS_540) {
2658 if((VCLK == 203) || (VCLK < 234)) data = 0x02;
2659 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002661 if(SiS_Pr->ChipType < SIS_315H) {
2662 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xFC,data);
2663 } else {
2664 if(SiS_Pr->ChipType > SIS_315PRO) {
2665 if(ModeNo > 0x13) data &= 0xfc;
2666 }
2667 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xF8,data);
2668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671}
2672
2673static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002674SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2675 unsigned short ModeIdIndex, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002677 unsigned short data, infoflag = 0, modeflag, resindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678#ifdef SIS315H
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002679 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
2680 unsigned short data2, data3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681#endif
2682
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002683 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002685 if(SiS_Pr->UseCustomMode) {
2686 infoflag = SiS_Pr->CInfoFlag;
2687 } else {
2688 resindex = SiS_GetResInfo(SiS_Pr, ModeNo, ModeIdIndex);
2689 if(ModeNo > 0x13) {
2690 infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
2691 }
2692 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002694 /* Disable DPMS */
2695 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1F,0x3F);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002697 data = 0;
2698 if(ModeNo > 0x13) {
2699 if(SiS_Pr->SiS_ModeType > ModeEGA) {
2700 data |= 0x02;
2701 data |= ((SiS_Pr->SiS_ModeType - ModeVGA) << 2);
2702 }
2703 if(infoflag & InterlaceMode) data |= 0x20;
2704 }
2705 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x06,0xC0,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002707 if(SiS_Pr->ChipType != SIS_300) {
2708 data = 0;
2709 if(infoflag & InterlaceMode) {
2710 /* data = (Hsync / 8) - ((Htotal / 8) / 2) + 3 */
2711 int hrs = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x04) |
2712 ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2)) - 3;
2713 int hto = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x00) |
2714 ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0x03) << 8)) + 5;
2715 data = hrs - (hto >> 1) + 3;
2716 }
2717 SiS_SetReg(SiS_Pr->SiS_P3d4,0x19,data);
2718 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x1a,0xFC,((data >> 8) & 0x03));
2719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002721 if(modeflag & HalfDCLK) {
2722 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x08);
2723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002725 data = 0;
2726 if(modeflag & LineCompareOff) data = 0x08;
2727 if(SiS_Pr->ChipType == SIS_300) {
2728 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xF7,data);
2729 } else {
2730 if(SiS_Pr->ChipType >= XGI_20) data |= 0x20;
2731 if(SiS_Pr->SiS_ModeType == ModeEGA) {
2732 if(ModeNo > 0x13) {
2733 data |= 0x40;
2734 }
2735 }
2736 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xB7,data);
2737 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738
2739#ifdef SIS315H
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002740 if(SiS_Pr->ChipType >= SIS_315H) {
2741 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xfb);
2742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002744 if(SiS_Pr->ChipType == SIS_315PRO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002746 data = SiS_Pr->SiS_SR15[(2 * 4) + SiS_Get310DRAMType(SiS_Pr)];
2747 if(SiS_Pr->SiS_ModeType == ModeText) {
2748 data &= 0xc7;
2749 } else {
2750 data2 = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RRTI) >> 1;
2751 if(infoflag & InterlaceMode) data2 >>= 1;
2752 data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
2753 if(data3) data2 /= data3;
2754 if(data2 >= 0x50) {
2755 data &= 0x0f;
2756 data |= 0x50;
2757 }
2758 }
2759 SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002761 } else if((SiS_Pr->ChipType == SIS_330) || (SiS_Pr->SiS_SysFlags & SF_760LFB)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002763 data = SiS_Get310DRAMType(SiS_Pr);
2764 if(SiS_Pr->ChipType == SIS_330) {
2765 data = SiS_Pr->SiS_SR15[(2 * 4) + data];
2766 } else {
2767 if(SiS_Pr->SiS_ROMNew) data = ROMAddr[0xf6];
2768 else if(SiS_Pr->SiS_UseROM) data = ROMAddr[0x100 + data];
2769 else data = 0xba;
2770 }
2771 if(SiS_Pr->SiS_ModeType <= ModeEGA) {
2772 data &= 0xc7;
2773 } else {
2774 if(SiS_Pr->UseCustomMode) {
2775 data2 = SiS_Pr->CSRClock;
2776 } else {
2777 data2 = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
2778 data2 = SiS_Pr->SiS_VCLKData[data2].CLOCK;
2779 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002781 data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
2782 if(data3) data2 *= data3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002784 data2 = ((unsigned int)(SiS_GetMCLK(SiS_Pr) * 1024)) / data2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002786 if(SiS_Pr->ChipType == SIS_330) {
2787 if(SiS_Pr->SiS_ModeType != Mode16Bpp) {
2788 if (data2 >= 0x19c) data = 0xba;
2789 else if(data2 >= 0x140) data = 0x7a;
2790 else if(data2 >= 0x101) data = 0x3a;
2791 else if(data2 >= 0xf5) data = 0x32;
2792 else if(data2 >= 0xe2) data = 0x2a;
2793 else if(data2 >= 0xc4) data = 0x22;
2794 else if(data2 >= 0xac) data = 0x1a;
2795 else if(data2 >= 0x9e) data = 0x12;
2796 else if(data2 >= 0x8e) data = 0x0a;
2797 else data = 0x02;
2798 } else {
2799 if(data2 >= 0x127) data = 0xba;
2800 else data = 0x7a;
2801 }
2802 } else { /* 76x+LFB */
2803 if (data2 >= 0x190) data = 0xba;
2804 else if(data2 >= 0xff) data = 0x7a;
2805 else if(data2 >= 0xd3) data = 0x3a;
2806 else if(data2 >= 0xa9) data = 0x1a;
2807 else if(data2 >= 0x93) data = 0x0a;
2808 else data = 0x02;
2809 }
2810 }
2811 SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
2812
2813 }
2814 /* XGI: Nothing. */
2815 /* TODO: Check SiS340 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816#endif
2817
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002818 data = 0x60;
2819 if(SiS_Pr->SiS_ModeType != ModeText) {
2820 data ^= 0x60;
2821 if(SiS_Pr->SiS_ModeType != ModeEGA) {
2822 data ^= 0xA0;
2823 }
2824 }
2825 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x21,0x1F,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002827 SiS_SetVCLKState(SiS_Pr, ModeNo, RRTI, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828
2829#ifdef SIS315H
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002830 if(((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) ||
2831 (SiS_Pr->ChipType == XGI_40)) {
2832 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
2833 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x2c);
2834 } else {
2835 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x6c);
2836 }
2837 } else if(SiS_Pr->ChipType == XGI_20) {
2838 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
2839 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x33);
2840 } else {
2841 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x73);
2842 }
2843 SiS_SetReg(SiS_Pr->SiS_P3d4,0x51,0x02);
2844 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845#endif
2846}
2847
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002848#ifdef SIS315H
2849static void
2850SiS_SetupDualChip(struct SiS_Private *SiS_Pr)
2851{
2852#if 0
2853 /* TODO: Find out about IOAddress2 */
2854 SISIOADDRESS P2_3c2 = SiS_Pr->IOAddress2 + 0x12;
2855 SISIOADDRESS P2_3c4 = SiS_Pr->IOAddress2 + 0x14;
2856 SISIOADDRESS P2_3ce = SiS_Pr->IOAddress2 + 0x1e;
2857 int i;
2858
2859 if((SiS_Pr->ChipRevision != 0) ||
2860 (!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x04)))
2861 return;
2862
2863 for(i = 0; i <= 4; i++) { /* SR00 - SR04 */
2864 SiS_SetReg(P2_3c4,i,SiS_GetReg(SiS_Pr->SiS_P3c4,i));
2865 }
2866 for(i = 0; i <= 8; i++) { /* GR00 - GR08 */
2867 SiS_SetReg(P2_3ce,i,SiS_GetReg(SiS_Pr->SiS_P3ce,i));
2868 }
2869 SiS_SetReg(P2_3c4,0x05,0x86);
2870 SiS_SetReg(P2_3c4,0x06,SiS_GetReg(SiS_Pr->SiS_P3c4,0x06)); /* SR06 */
2871 SiS_SetReg(P2_3c4,0x21,SiS_GetReg(SiS_Pr->SiS_P3c4,0x21)); /* SR21 */
2872 SiS_SetRegByte(P2_3c2,SiS_GetRegByte(SiS_Pr->SiS_P3cc)); /* MISC */
2873 SiS_SetReg(P2_3c4,0x05,0x00);
2874#endif
2875}
2876#endif
2877
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878/*********************************************/
2879/* LOAD DAC */
2880/*********************************************/
2881
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002883SiS_WriteDAC(struct SiS_Private *SiS_Pr, SISIOADDRESS DACData, unsigned short shiftflag,
2884 unsigned short dl, unsigned short ah, unsigned short al, unsigned short dh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002886 unsigned short d1, d2, d3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002888 switch(dl) {
2889 case 0: d1 = dh; d2 = ah; d3 = al; break;
2890 case 1: d1 = ah; d2 = al; d3 = dh; break;
2891 default: d1 = al; d2 = dh; d3 = ah;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002893 SiS_SetRegByte(DACData, (d1 << shiftflag));
2894 SiS_SetRegByte(DACData, (d2 << shiftflag));
2895 SiS_SetRegByte(DACData, (d3 << shiftflag));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896}
2897
2898void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002899SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002901 unsigned short data, data2, time, i, j, k, m, n, o;
2902 unsigned short si, di, bx, sf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 SISIOADDRESS DACAddr, DACData;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002904 const unsigned char *table = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002906 data = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex) & DACInfoFlag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002908 j = time = 64;
2909 if(data == 0x00) table = SiS_MDA_DAC;
2910 else if(data == 0x08) table = SiS_CGA_DAC;
2911 else if(data == 0x10) table = SiS_EGA_DAC;
2912 else if(data == 0x18) {
2913 j = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 time = 256;
2915 table = SiS_VGA_DAC;
2916 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917
2918 if( ( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && /* 301B-DH LCD */
2919 (SiS_Pr->SiS_VBType & VB_NoLCD) ) ||
2920 (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) || /* LCDA */
2921 (!(SiS_Pr->SiS_SetFlag & ProgrammingCRT2)) ) { /* Programming CRT1 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002922 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 DACAddr = SiS_Pr->SiS_P3c8;
2924 DACData = SiS_Pr->SiS_P3c9;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002925 sf = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 DACAddr = SiS_Pr->SiS_Part5Port;
2928 DACData = SiS_Pr->SiS_Part5Port + 1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002929 sf = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 }
2931
2932 SiS_SetRegByte(DACAddr,0x00);
2933
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002934 for(i = 0; i < j; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 data = table[i];
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002936 for(k = 0; k < 3; k++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 data2 = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002938 if(data & 0x01) data2 += 0x2A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 if(data & 0x02) data2 += 0x15;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002940 SiS_SetRegByte(DACData, (data2 << sf));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 data >>= 2;
2942 }
2943 }
2944
2945 if(time == 256) {
2946 for(i = 16; i < 32; i++) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002947 data = table[i] << sf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 for(k = 0; k < 3; k++) SiS_SetRegByte(DACData, data);
2949 }
2950 si = 32;
2951 for(m = 0; m < 9; m++) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002952 di = si;
2953 bx = si + 4;
2954 for(n = 0; n < 3; n++) {
2955 for(o = 0; o < 5; o++) {
2956 SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[bx], table[si]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 si++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 }
2959 si -= 2;
2960 for(o = 0; o < 3; o++) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002961 SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[si], table[bx]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 si--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 } /* for n < 3 */
2965 si += 5;
2966 } /* for m < 9 */
2967 }
2968}
2969
2970/*********************************************/
2971/* SET CRT1 REGISTER GROUP */
2972/*********************************************/
2973
2974static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002975SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002977 unsigned short StandTableIndex, RefreshRateTableIndex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002979 SiS_Pr->SiS_CRT1Mode = ModeNo;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002981 StandTableIndex = SiS_GetModePtr(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002983 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
2984 if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2)) {
2985 SiS_DisableBridge(SiS_Pr);
2986 }
2987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002989 SiS_ResetSegmentRegisters(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002991 SiS_SetSeqRegs(SiS_Pr, StandTableIndex);
2992 SiS_SetMiscRegs(SiS_Pr, StandTableIndex);
2993 SiS_SetCRTCRegs(SiS_Pr, StandTableIndex);
2994 SiS_SetATTRegs(SiS_Pr, StandTableIndex);
2995 SiS_SetGRCRegs(SiS_Pr, StandTableIndex);
2996 SiS_ClearExt1Regs(SiS_Pr, ModeNo);
2997 SiS_ResetCRT1VCLK(SiS_Pr);
2998
2999 SiS_Pr->SiS_SelectCRT2Rate = 0;
3000 SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
3001
3002#ifdef SIS_XORG_XF86
3003 xf86DrvMsgVerb(0, X_PROBED, 4, "(init: VBType=0x%04x, VBInfo=0x%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 SiS_Pr->SiS_VBType, SiS_Pr->SiS_VBInfo);
3005#endif
3006
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003007 if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
3008 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
3009 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
3010 }
3011 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003013 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
3014 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
3015 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003017 RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003019 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
3020 SiS_Pr->SiS_SetFlag &= ~ProgrammingCRT2;
3021 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003023 if(RefreshRateTableIndex != 0xFFFF) {
3024 SiS_SetCRT1Sync(SiS_Pr, RefreshRateTableIndex);
3025 SiS_SetCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3026 SiS_SetCRT1Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3027 SiS_SetCRT1VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3028 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003030 switch(SiS_Pr->ChipType) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031#ifdef SIS300
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003032 case SIS_300:
3033 SiS_SetCRT1FIFO_300(SiS_Pr, ModeNo, RefreshRateTableIndex);
3034 break;
3035 case SIS_540:
3036 case SIS_630:
3037 case SIS_730:
3038 SiS_SetCRT1FIFO_630(SiS_Pr, ModeNo, RefreshRateTableIndex);
3039 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003041 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042#ifdef SIS315H
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003043 if(SiS_Pr->ChipType == XGI_20) {
3044 unsigned char sr2b = 0, sr2c = 0;
3045 switch(ModeNo) {
3046 case 0x00:
3047 case 0x01: sr2b = 0x4e; sr2c = 0xe9; break;
3048 case 0x04:
3049 case 0x05:
3050 case 0x0d: sr2b = 0x1b; sr2c = 0xe3; break;
3051 }
3052 if(sr2b) {
3053 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,sr2b);
3054 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,sr2c);
3055 SiS_SetRegByte(SiS_Pr->SiS_P3c2,(SiS_GetRegByte(SiS_Pr->SiS_P3cc) | 0x0c));
3056 }
3057 }
3058 SiS_SetCRT1FIFO_310(SiS_Pr, ModeNo, ModeIdIndex);
3059#endif
3060 break;
3061 }
3062
3063 SiS_SetCRT1ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3064
3065#ifdef SIS315H
3066 if(SiS_Pr->ChipType == XGI_40) {
3067 SiS_SetupDualChip(SiS_Pr);
3068 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069#endif
3070
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003071 SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003073#ifdef SIS_LINUX_KERNEL
3074 if(SiS_Pr->SiS_flag_clearbuffer) {
3075 SiS_ClearBuffer(SiS_Pr, ModeNo);
3076 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077#endif
3078
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003079 if(!(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA))) {
3080 SiS_WaitRetrace1(SiS_Pr);
3081 SiS_DisplayOn(SiS_Pr);
3082 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083}
3084
3085/*********************************************/
3086/* HELPER: VIDEO BRIDGE PROG CLK */
3087/*********************************************/
3088
3089static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003090SiS_InitVB(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003092 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003094 SiS_Pr->Init_P4_0E = 0;
3095 if(SiS_Pr->SiS_ROMNew) {
3096 SiS_Pr->Init_P4_0E = ROMAddr[0x82];
3097 } else if(SiS_Pr->ChipType >= XGI_40) {
3098 if(SiS_Pr->SiS_XGIROM) {
3099 SiS_Pr->Init_P4_0E = ROMAddr[0x80];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 }
3101 }
3102}
3103
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003104static void
3105SiS_ResetVB(struct SiS_Private *SiS_Pr)
3106{
3107#ifdef SIS315H
3108 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
3109 unsigned short temp;
3110
3111 /* VB programming clock */
3112 if(SiS_Pr->SiS_UseROM) {
3113 if(SiS_Pr->ChipType < SIS_330) {
3114 temp = ROMAddr[VB310Data_1_2_Offset] | 0x40;
3115 if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
3116 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
3117 } else if(SiS_Pr->ChipType >= SIS_661 && SiS_Pr->ChipType < XGI_20) {
3118 temp = ROMAddr[0x7e] | 0x40;
3119 if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
3120 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
3121 }
3122 } else if(SiS_Pr->ChipType >= XGI_40) {
3123 temp = 0x40;
3124 if(SiS_Pr->SiS_XGIROM) temp |= ROMAddr[0x7e];
3125 /* Can we do this on any chipset? */
3126 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
3127 }
3128#endif
3129}
3130
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003132/* HELPER: SET VIDEO/CAPTURE REGISTERS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133/*********************************************/
3134
3135static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003136SiS_StrangeStuff(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003138 /* SiS65x and XGI set up some sort of "lock mode" for text
3139 * which locks CRT2 in some way to CRT1 timing. Disable
3140 * this here.
3141 */
3142#ifdef SIS315H
3143 if((IS_SIS651) || (IS_SISM650) ||
3144 SiS_Pr->ChipType == SIS_340 ||
3145 SiS_Pr->ChipType == XGI_40) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x3f, 0x00); /* Fiddle with capture regs */
3147 SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x00, 0x00);
3148 SiS_SetReg(SiS_Pr->SiS_VidPlay, 0x00, 0x86); /* (BIOS does NOT unlock) */
3149 SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x30, 0xfe); /* Fiddle with video regs */
3150 SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x3f, 0xef);
3151 }
3152 /* !!! This does not support modes < 0x13 !!! */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003153#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154}
3155
3156/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003157/* HELPER: SET AGP TIMING FOR SiS760 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158/*********************************************/
3159
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003161SiS_Handle760(struct SiS_Private *SiS_Pr)
3162{
3163#ifdef SIS315H
3164 unsigned int somebase;
3165 unsigned char temp1, temp2, temp3;
3166
3167 if( (SiS_Pr->ChipType != SIS_760) ||
3168 ((SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5c) & 0xf8) != 0x80) ||
3169 (!(SiS_Pr->SiS_SysFlags & SF_760LFB)) ||
3170 (!(SiS_Pr->SiS_SysFlags & SF_760UMA)) )
3171 return;
3172
3173#ifdef SIS_LINUX_KERNEL
3174 somebase = sisfb_read_mio_pci_word(SiS_Pr, 0x74);
3175#else
3176 somebase = pciReadWord(0x00001000, 0x74);
3177#endif
3178 somebase &= 0xffff;
3179
3180 if(somebase == 0) return;
3181
3182 temp3 = SiS_GetRegByte((somebase + 0x85)) & 0xb7;
3183
3184 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
3185 temp1 = 0x21;
3186 temp2 = 0x03;
3187 temp3 |= 0x08;
3188 } else {
3189 temp1 = 0x25;
3190 temp2 = 0x0b;
3191 }
3192
3193#ifdef SIS_LINUX_KERNEL
3194 sisfb_write_nbridge_pci_byte(SiS_Pr, 0x7e, temp1);
3195 sisfb_write_nbridge_pci_byte(SiS_Pr, 0x8d, temp2);
3196#else
3197 pciWriteByte(0x00000000, 0x7e, temp1);
3198 pciWriteByte(0x00000000, 0x8d, temp2);
3199#endif
3200
3201 SiS_SetRegByte((somebase + 0x85), temp3);
3202#endif
3203}
3204
3205/*********************************************/
3206/* X.org/XFree86: SET SCREEN PITCH */
3207/*********************************************/
3208
3209#ifdef SIS_XORG_XF86
3210static void
3211SiS_SetPitchCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212{
3213 SISPtr pSiS = SISPTR(pScrn);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003214 unsigned short HDisplay = pSiS->scrnPitch >> 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215
3216 SiS_SetReg(SiS_Pr->SiS_P3d4,0x13,(HDisplay & 0xFF));
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003217 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0xF0,(HDisplay >> 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218}
3219
3220static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003221SiS_SetPitchCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222{
3223 SISPtr pSiS = SISPTR(pScrn);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003224 unsigned short HDisplay = pSiS->scrnPitch2 >> 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225
3226 /* Unlock CRT2 */
3227 if(pSiS->VGAEngine == SIS_315_VGA)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003228 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2F, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 else
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003230 SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
3232 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(HDisplay & 0xFF));
3233 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0xF0,(HDisplay >> 8));
3234}
3235
3236static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003237SiS_SetPitch(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238{
3239 SISPtr pSiS = SISPTR(pScrn);
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003240 bool isslavemode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003242 if( (pSiS->VBFlags2 & VB2_VIDEOBRIDGE) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 ( ((pSiS->VGAEngine == SIS_300_VGA) &&
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003244 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0xa0) == 0x20) ||
3245 ((pSiS->VGAEngine == SIS_315_VGA) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x50) == 0x10) ) ) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003247 isslavemode = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 }
3249
3250 /* We need to set pitch for CRT1 if bridge is in slave mode, too */
3251 if((pSiS->VBFlags & DISPTYPE_DISP1) || (isslavemode)) {
3252 SiS_SetPitchCRT1(SiS_Pr, pScrn);
3253 }
3254 /* We must not set the pitch for CRT2 if bridge is in slave mode */
3255 if((pSiS->VBFlags & DISPTYPE_DISP2) && (!isslavemode)) {
3256 SiS_SetPitchCRT2(SiS_Pr, pScrn);
3257 }
3258}
3259#endif
3260
3261/*********************************************/
3262/* SiSSetMode() */
3263/*********************************************/
3264
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003265#ifdef SIS_XORG_XF86
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266/* We need pScrn for setting the pitch correctly */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003267bool
3268SiSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, unsigned short ModeNo, bool dosetpitch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269#else
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003270bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003271SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272#endif
3273{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003274 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
3275 unsigned short RealModeNo, ModeIdIndex;
3276 unsigned char backupreg = 0;
3277#ifdef SIS_LINUX_KERNEL
3278 unsigned short KeepLockReg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003280 SiS_Pr->UseCustomMode = false;
3281 SiS_Pr->CRT1UsesCustomMode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282#endif
3283
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 SiS_Pr->SiS_flag_clearbuffer = 0;
3285
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003286 if(SiS_Pr->UseCustomMode) {
3287 ModeNo = 0xfe;
3288 } else {
3289#ifdef SIS_LINUX_KERNEL
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 if(!(ModeNo & 0x80)) SiS_Pr->SiS_flag_clearbuffer = 1;
3291#endif
3292 ModeNo &= 0x7f;
3293 }
3294
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003295 /* Don't use FSTN mode for CRT1 */
3296 RealModeNo = ModeNo;
3297 if(ModeNo == 0x5b) ModeNo = 0x56;
3298
3299 SiSInitPtr(SiS_Pr);
3300 SiSRegInit(SiS_Pr, BaseAddr);
3301 SiS_GetSysFlags(SiS_Pr);
3302
3303 SiS_Pr->SiS_VGAINFO = 0x11;
3304#if defined(SIS_XORG_XF86) && (defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__) || defined(__amd64__) || defined(__x86_64__))
3305 if(pScrn) SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff);
3306#endif
3307
3308#ifdef SIS_LINUX_KERNEL
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 KeepLockReg = SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
3310#endif
3311 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
3312
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003313 SiSInitPCIetc(SiS_Pr);
3314 SiSSetLVDSetc(SiS_Pr);
3315 SiSDetermineROMUsage(SiS_Pr);
3316
3317 SiS_UnLockCRT2(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
3319 if(!SiS_Pr->UseCustomMode) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003320 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 } else {
3322 ModeIdIndex = 0;
3323 }
3324
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003325 SiS_GetVBType(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
3327 /* Init/restore some VB registers */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003328 SiS_InitVB(SiS_Pr);
3329 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3330 if(SiS_Pr->ChipType >= SIS_315H) {
3331 SiS_ResetVB(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10);
3333 SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x00,0x0c);
3334 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3335 } else {
3336 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
3337 }
3338 }
3339
3340 /* Get VB information (connectors, connected devices) */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003341 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, (SiS_Pr->UseCustomMode) ? 0 : 1);
3342 SiS_SetYPbPr(SiS_Pr);
3343 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
3344 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
3345 SiS_SetLowModeTest(SiS_Pr, ModeNo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003347#ifdef SIS_LINUX_KERNEL
3348 /* Check memory size (kernel framebuffer driver only) */
3349 if(!SiS_CheckMemorySize(SiS_Pr, ModeNo, ModeIdIndex)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003350 return false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352#endif
3353
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003354 SiS_OpenCRTC(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
3356 if(SiS_Pr->UseCustomMode) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003357 SiS_Pr->CRT1UsesCustomMode = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 SiS_Pr->CSRClock_CRT1 = SiS_Pr->CSRClock;
3359 SiS_Pr->CModeFlag_CRT1 = SiS_Pr->CModeFlag;
3360 } else {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003361 SiS_Pr->CRT1UsesCustomMode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 }
3363
3364 /* Set mode on CRT1 */
3365 if( (SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) ||
3366 (!(SiS_Pr->SiS_VBInfo & SwitchCRT2)) ) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003367 SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 }
3369
3370 /* Set mode on CRT2 */
3371 if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA)) {
3372 if( (SiS_Pr->SiS_VBType & VB_SISVB) ||
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003373 (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
3374 (SiS_Pr->SiS_IF_DEF_CH70xx != 0) ||
3375 (SiS_Pr->SiS_IF_DEF_TRUMPION != 0) ) {
3376 SiS_SetCRT2Group(SiS_Pr, RealModeNo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 }
3378 }
3379
3380 SiS_HandleCRT1(SiS_Pr);
3381
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003382 SiS_StrangeStuff(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383
3384 SiS_DisplayOn(SiS_Pr);
3385 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3386
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003387#ifdef SIS315H
3388 if(SiS_Pr->ChipType >= SIS_315H) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003390 if(!(SiS_IsDualEdge(SiS_Pr))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
3392 }
3393 }
3394 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003395#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003397 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3398 if(SiS_Pr->ChipType >= SIS_315H) {
3399#ifdef SIS315H
3400 if(!SiS_Pr->SiS_ROMNew) {
3401 if(SiS_IsVAMode(SiS_Pr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
3403 } else {
3404 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0xFE);
3405 }
3406 }
3407
3408 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupreg);
3409
3410 if((IS_SIS650) && (SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0xfc)) {
3411 if((ModeNo == 0x03) || (ModeNo == 0x10)) {
3412 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x80);
3413 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x56,0x08);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 }
3416
3417 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) {
3418 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
3419 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003420#endif
3421 } else if((SiS_Pr->ChipType == SIS_630) ||
3422 (SiS_Pr->ChipType == SIS_730)) {
3423 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 }
3425 }
3426
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003427#ifdef SIS_XORG_XF86
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 if(pScrn) {
3429 /* SetPitch: Adapt to virtual size & position */
3430 if((ModeNo > 0x13) && (dosetpitch)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003431 SiS_SetPitch(SiS_Pr, pScrn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 }
3433
3434 /* Backup/Set ModeNo in BIOS scratch area */
3435 SiS_GetSetModeID(pScrn, ModeNo);
3436 }
3437#endif
3438
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003439 SiS_CloseCRTC(SiS_Pr);
3440
3441 SiS_Handle760(SiS_Pr);
3442
3443#ifdef SIS_LINUX_KERNEL
3444 /* We never lock registers in XF86 */
3445 if(KeepLockReg != 0xA1) SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446#endif
3447
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003448 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449}
3450
3451/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003452/* X.org/XFree86: SiSBIOSSetMode() */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453/* for non-Dual-Head mode */
3454/*********************************************/
3455
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003456#ifdef SIS_XORG_XF86
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003457bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003458SiSBIOSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003459 DisplayModePtr mode, bool IsCustom)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460{
3461 SISPtr pSiS = SISPTR(pScrn);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003462 unsigned short ModeNo = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003464 SiS_Pr->UseCustomMode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465
3466 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) {
3467
3468 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, "Setting custom mode %dx%d\n",
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003469 SiS_Pr->CHDisplay,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 (mode->Flags & V_INTERLACE ? SiS_Pr->CVDisplay * 2 :
3471 (mode->Flags & V_DBLSCAN ? SiS_Pr->CVDisplay / 2 :
3472 SiS_Pr->CVDisplay)));
3473
3474 } else {
3475
3476 /* Don't need vbflags here; checks done earlier */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003477 ModeNo = SiS_GetModeNumber(pScrn, mode, pSiS->VBFlags);
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003478 if(!ModeNo) return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479
3480 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, "Setting standard mode 0x%x\n", ModeNo);
3481
3482 }
3483
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003484 return(SiSSetMode(SiS_Pr, pScrn, ModeNo, true));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485}
3486
3487/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003488/* X.org/XFree86: SiSBIOSSetModeCRT2() */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489/* for Dual-Head modes */
3490/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003491
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003492bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003493SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003494 DisplayModePtr mode, bool IsCustom)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003496 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
3497 SISPtr pSiS = SISPTR(pScrn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498#ifdef SISDUALHEAD
3499 SISEntPtr pSiSEnt = pSiS->entityPrivate;
3500#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003501 unsigned short ModeIdIndex;
3502 unsigned short ModeNo = 0;
3503 unsigned char backupreg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003505 SiS_Pr->UseCustomMode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506
3507 /* Remember: Custom modes for CRT2 are ONLY supported
3508 * -) on the 30x/B/C, and
3509 * -) if CRT2 is LCD or VGA, or CRT1 is LCDA
3510 */
3511
3512 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) {
3513
3514 ModeNo = 0xfe;
3515
3516 } else {
3517
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003518 ModeNo = SiS_GetModeNumber(pScrn, mode, pSiS->VBFlags);
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003519 if(!ModeNo) return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520
3521 }
3522
3523 SiSRegInit(SiS_Pr, BaseAddr);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003524 SiSInitPtr(SiS_Pr);
3525 SiS_GetSysFlags(SiS_Pr);
3526#if defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__) || defined(__amd64__) || defined(__x86_64__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff);
3528#else
3529 SiS_Pr->SiS_VGAINFO = 0x11;
3530#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003531
3532 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
3533
3534 SiSInitPCIetc(SiS_Pr);
3535 SiSSetLVDSetc(SiS_Pr);
3536 SiSDetermineROMUsage(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537
3538 /* Save mode info so we can set it from within SetMode for CRT1 */
3539#ifdef SISDUALHEAD
3540 if(pSiS->DualHeadMode) {
3541 pSiSEnt->CRT2ModeNo = ModeNo;
3542 pSiSEnt->CRT2DMode = mode;
3543 pSiSEnt->CRT2IsCustom = IsCustom;
3544 pSiSEnt->CRT2CR30 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
3545 pSiSEnt->CRT2CR31 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
3546 pSiSEnt->CRT2CR35 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
3547 pSiSEnt->CRT2CR38 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3548#if 0
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003549 /* We can't set CRT2 mode before CRT1 mode is set - says who...? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 if(pSiSEnt->CRT1ModeNo == -1) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003551 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 "Setting CRT2 mode delayed until after setting CRT1 mode\n");
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003553 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 }
3555#endif
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003556 pSiSEnt->CRT2ModeSet = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 }
3558#endif
3559
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 if(SiS_Pr->UseCustomMode) {
3561
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003562 unsigned short temptemp = SiS_Pr->CVDisplay;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563
3564 if(SiS_Pr->CModeFlag & DoubleScanMode) temptemp >>= 1;
3565 else if(SiS_Pr->CInfoFlag & InterlaceMode) temptemp <<= 1;
3566
3567 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3568 "Setting custom mode %dx%d on CRT2\n",
3569 SiS_Pr->CHDisplay, temptemp);
3570
3571 } else {
3572
3573 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003574 "Setting standard mode 0x%x on CRT2\n", ModeNo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575
3576 }
3577
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003578 SiS_UnLockCRT2(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579
3580 if(!SiS_Pr->UseCustomMode) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003581 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582 } else {
3583 ModeIdIndex = 0;
3584 }
3585
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003586 SiS_GetVBType(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003588 SiS_InitVB(SiS_Pr);
3589 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3590 if(SiS_Pr->ChipType >= SIS_315H) {
3591 SiS_ResetVB(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10);
3593 SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x00,0x0c);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003594 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003596 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 }
3598 }
3599
3600 /* Get VB information (connectors, connected devices) */
3601 if(!SiS_Pr->UseCustomMode) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003602 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 } else {
3604 /* If this is a custom mode, we don't check the modeflag for CRT2Mode */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003605 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003607 SiS_SetYPbPr(SiS_Pr);
3608 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
3609 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
3610 SiS_SetLowModeTest(SiS_Pr, ModeNo);
3611
3612 SiS_ResetSegmentRegisters(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613
3614 /* Set mode on CRT2 */
3615 if( (SiS_Pr->SiS_VBType & VB_SISVB) ||
3616 (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
3617 (SiS_Pr->SiS_IF_DEF_CH70xx != 0) ||
3618 (SiS_Pr->SiS_IF_DEF_TRUMPION != 0) ) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003619 SiS_SetCRT2Group(SiS_Pr, ModeNo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620 }
3621
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003622 SiS_StrangeStuff(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623
3624 SiS_DisplayOn(SiS_Pr);
3625 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3626
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003627 if(SiS_Pr->ChipType >= SIS_315H) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003629 if(!(SiS_IsDualEdge(SiS_Pr))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
3631 }
3632 }
3633 }
3634
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003635 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3636 if(SiS_Pr->ChipType >= SIS_315H) {
3637 if(!SiS_Pr->SiS_ROMNew) {
3638 if(SiS_IsVAMode(SiS_Pr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
3640 } else {
3641 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0xFE);
3642 }
3643 }
3644
3645 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupreg);
3646
3647 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) {
3648 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
3649 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003650 } else if((SiS_Pr->ChipType == SIS_630) ||
3651 (SiS_Pr->ChipType == SIS_730)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
3653 }
3654 }
3655
3656 /* SetPitch: Adapt to virtual size & position */
3657 SiS_SetPitchCRT2(SiS_Pr, pScrn);
3658
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003659 SiS_Handle760(SiS_Pr);
3660
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003661 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662}
3663
3664/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003665/* X.org/XFree86: SiSBIOSSetModeCRT1() */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666/* for Dual-Head modes */
3667/*********************************************/
3668
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003669bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003670SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003671 DisplayModePtr mode, bool IsCustom)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003673 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 SISPtr pSiS = SISPTR(pScrn);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003675 unsigned short ModeIdIndex, ModeNo = 0;
3676 unsigned char backupreg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677#ifdef SISDUALHEAD
3678 SISEntPtr pSiSEnt = pSiS->entityPrivate;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003679 unsigned char backupcr30, backupcr31, backupcr38, backupcr35, backupp40d=0;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003680 bool backupcustom;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681#endif
3682
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003683 SiS_Pr->UseCustomMode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684
3685 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) {
3686
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003687 unsigned short temptemp = SiS_Pr->CVDisplay;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003689 if(SiS_Pr->CModeFlag & DoubleScanMode) temptemp >>= 1;
3690 else if(SiS_Pr->CInfoFlag & InterlaceMode) temptemp <<= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003692 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 "Setting custom mode %dx%d on CRT1\n",
3694 SiS_Pr->CHDisplay, temptemp);
3695 ModeNo = 0xfe;
3696
3697 } else {
3698
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003699 ModeNo = SiS_GetModeNumber(pScrn, mode, 0); /* don't give VBFlags */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003700 if(!ModeNo) return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003702 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 "Setting standard mode 0x%x on CRT1\n", ModeNo);
3704 }
3705
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003706 SiSInitPtr(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 SiSRegInit(SiS_Pr, BaseAddr);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003708 SiS_GetSysFlags(SiS_Pr);
3709#if defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__) || defined(__amd64__) || defined(__x86_64__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 SiS_Pr->SiS_VGAINFO = SiS_GetSetBIOSScratch(pScrn, 0x489, 0xff);
3711#else
3712 SiS_Pr->SiS_VGAINFO = 0x11;
3713#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714
3715 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
3716
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003717 SiSInitPCIetc(SiS_Pr);
3718 SiSSetLVDSetc(SiS_Pr);
3719 SiSDetermineROMUsage(SiS_Pr);
3720
3721 SiS_UnLockCRT2(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722
3723 if(!SiS_Pr->UseCustomMode) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003724 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 } else {
3726 ModeIdIndex = 0;
3727 }
3728
3729 /* Determine VBType */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003730 SiS_GetVBType(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003732 SiS_InitVB(SiS_Pr);
3733 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3734 if(SiS_Pr->ChipType >= SIS_315H) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3736 } else {
3737 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
3738 }
3739 }
3740
3741 /* Get VB information (connectors, connected devices) */
3742 /* (We don't care if the current mode is a CRT2 mode) */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003743 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, 0);
3744 SiS_SetYPbPr(SiS_Pr);
3745 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
3746 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
3747 SiS_SetLowModeTest(SiS_Pr, ModeNo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003749 SiS_OpenCRTC(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750
3751 /* Set mode on CRT1 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003752 SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003754 SiS_SetCRT2Group(SiS_Pr, ModeNo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 }
3756
3757 /* SetPitch: Adapt to virtual size & position */
3758 SiS_SetPitchCRT1(SiS_Pr, pScrn);
3759
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003760 SiS_HandleCRT1(SiS_Pr);
3761
3762 SiS_StrangeStuff(SiS_Pr);
3763
3764 SiS_CloseCRTC(SiS_Pr);
3765
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766#ifdef SISDUALHEAD
3767 if(pSiS->DualHeadMode) {
3768 pSiSEnt->CRT1ModeNo = ModeNo;
3769 pSiSEnt->CRT1DMode = mode;
3770 }
3771#endif
3772
3773 if(SiS_Pr->UseCustomMode) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003774 SiS_Pr->CRT1UsesCustomMode = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 SiS_Pr->CSRClock_CRT1 = SiS_Pr->CSRClock;
3776 SiS_Pr->CModeFlag_CRT1 = SiS_Pr->CModeFlag;
3777 } else {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003778 SiS_Pr->CRT1UsesCustomMode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 }
3780
3781 /* Reset CRT2 if changing mode on CRT1 */
3782#ifdef SISDUALHEAD
3783 if(pSiS->DualHeadMode) {
3784 if(pSiSEnt->CRT2ModeNo != -1) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003785 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 "(Re-)Setting mode for CRT2\n");
3787 backupcustom = SiS_Pr->UseCustomMode;
3788 backupcr30 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
3789 backupcr31 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
3790 backupcr35 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
3791 backupcr38 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3792 if(SiS_Pr->SiS_VBType & VB_SISVB) {
3793 /* Backup LUT-enable */
3794 if(pSiSEnt->CRT2ModeSet) {
3795 backupp40d = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x0d) & 0x08;
3796 }
3797 }
3798 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
3799 SiS_SetReg(SiS_Pr->SiS_P3d4,0x30,pSiSEnt->CRT2CR30);
3800 SiS_SetReg(SiS_Pr->SiS_P3d4,0x31,pSiSEnt->CRT2CR31);
3801 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,pSiSEnt->CRT2CR35);
3802 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,pSiSEnt->CRT2CR38);
3803 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003804
3805 SiSBIOSSetModeCRT2(SiS_Pr, pSiSEnt->pScrn_1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 pSiSEnt->CRT2DMode, pSiSEnt->CRT2IsCustom);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003807
3808 SiS_SetReg(SiS_Pr->SiS_P3d4,0x30,backupcr30);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 SiS_SetReg(SiS_Pr->SiS_P3d4,0x31,backupcr31);
3810 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupcr35);
3811 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupcr38);
3812 if(SiS_Pr->SiS_VBType & VB_SISVB) {
3813 SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d, ~0x08, backupp40d);
3814 }
3815 SiS_Pr->UseCustomMode = backupcustom;
3816 }
3817 }
3818#endif
3819
3820 /* Warning: From here, the custom mode entries in SiS_Pr are
3821 * possibly overwritten
3822 */
3823
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 SiS_DisplayOn(SiS_Pr);
3825 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3826
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003827 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3828 if(SiS_Pr->ChipType >= SIS_315H) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupreg);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003830 } else if((SiS_Pr->ChipType == SIS_630) ||
3831 (SiS_Pr->ChipType == SIS_730)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
3833 }
3834 }
3835
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003836 SiS_Handle760(SiS_Pr);
3837
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 /* Backup/Set ModeNo in BIOS scratch area */
3839 SiS_GetSetModeID(pScrn,ModeNo);
3840
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003841 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842}
3843#endif /* Linux_XF86 */
3844
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845#ifndef GETBITSTR
3846#define BITMASK(h,l) (((unsigned)(1U << ((h)-(l)+1))-1)<<(l))
3847#define GENMASK(mask) BITMASK(1?mask,0?mask)
3848#define GETBITS(var,mask) (((var) & GENMASK(mask)) >> (0?mask))
3849#define GETBITSTR(val,from,to) ((GETBITS(val,from)) << (0?to))
3850#endif
3851
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003852void
3853SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003855 int x = 1; /* Fix sync */
3856
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 SiS_Pr->CCRT1CRTC[0] = ((SiS_Pr->CHTotal >> 3) - 5) & 0xff; /* CR0 */
3858 SiS_Pr->CCRT1CRTC[1] = (SiS_Pr->CHDisplay >> 3) - 1; /* CR1 */
3859 SiS_Pr->CCRT1CRTC[2] = (SiS_Pr->CHBlankStart >> 3) - 1; /* CR2 */
3860 SiS_Pr->CCRT1CRTC[3] = (((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x1F) | 0x80; /* CR3 */
3861 SiS_Pr->CCRT1CRTC[4] = (SiS_Pr->CHSyncStart >> 3) + 3; /* CR4 */
3862 SiS_Pr->CCRT1CRTC[5] = ((((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x20) << 2) | /* CR5 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003863 (((SiS_Pr->CHSyncEnd >> 3) + 3) & 0x1F);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003865 SiS_Pr->CCRT1CRTC[6] = (SiS_Pr->CVTotal - 2) & 0xFF; /* CR6 */
3866 SiS_Pr->CCRT1CRTC[7] = (((SiS_Pr->CVTotal - 2) & 0x100) >> 8) /* CR7 */
3867 | (((SiS_Pr->CVDisplay - 1) & 0x100) >> 7)
3868 | (((SiS_Pr->CVSyncStart - x) & 0x100) >> 6)
3869 | (((SiS_Pr->CVBlankStart- 1) & 0x100) >> 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 | 0x10
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003871 | (((SiS_Pr->CVTotal - 2) & 0x200) >> 4)
3872 | (((SiS_Pr->CVDisplay - 1) & 0x200) >> 3)
3873 | (((SiS_Pr->CVSyncStart - x) & 0x200) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874
3875 SiS_Pr->CCRT1CRTC[16] = ((((SiS_Pr->CVBlankStart - 1) & 0x200) >> 4) >> 5); /* CR9 */
3876
3877 if(depth != 8) {
3878 if(SiS_Pr->CHDisplay >= 1600) SiS_Pr->CCRT1CRTC[16] |= 0x60; /* SRE */
3879 else if(SiS_Pr->CHDisplay >= 640) SiS_Pr->CCRT1CRTC[16] |= 0x40;
3880 }
3881
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003882 SiS_Pr->CCRT1CRTC[8] = (SiS_Pr->CVSyncStart - x) & 0xFF; /* CR10 */
3883 SiS_Pr->CCRT1CRTC[9] = ((SiS_Pr->CVSyncEnd - x) & 0x0F) | 0x80; /* CR11 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 SiS_Pr->CCRT1CRTC[10] = (SiS_Pr->CVDisplay - 1) & 0xFF; /* CR12 */
3885 SiS_Pr->CCRT1CRTC[11] = (SiS_Pr->CVBlankStart - 1) & 0xFF; /* CR15 */
3886 SiS_Pr->CCRT1CRTC[12] = (SiS_Pr->CVBlankEnd - 1) & 0xFF; /* CR16 */
3887
3888 SiS_Pr->CCRT1CRTC[13] = /* SRA */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003889 GETBITSTR((SiS_Pr->CVTotal -2), 10:10, 0:0) |
3890 GETBITSTR((SiS_Pr->CVDisplay -1), 10:10, 1:1) |
3891 GETBITSTR((SiS_Pr->CVBlankStart-1), 10:10, 2:2) |
3892 GETBITSTR((SiS_Pr->CVSyncStart -x), 10:10, 3:3) |
3893 GETBITSTR((SiS_Pr->CVBlankEnd -1), 8:8, 4:4) |
3894 GETBITSTR((SiS_Pr->CVSyncEnd ), 4:4, 5:5) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895
3896 SiS_Pr->CCRT1CRTC[14] = /* SRB */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003897 GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9:8, 1:0) |
3898 GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9:8, 3:2) |
3899 GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9:8, 5:4) |
3900 GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9:8, 7:6) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901
3902
3903 SiS_Pr->CCRT1CRTC[15] = /* SRC */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003904 GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7:6, 1:0) |
3905 GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5:5, 2:2) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906}
3907
3908void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003909SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
3910 unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003912 unsigned short modeflag, tempax, tempbx = 0, remaining = 0;
3913 unsigned short VGAHDE = SiS_Pr->SiS_VGAHDE;
3914 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915
3916 /* 1:1 data: use data set by setcrt1crtc() */
3917 if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
3918
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003919 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920
3921 if(modeflag & HalfDCLK) VGAHDE >>= 1;
3922
3923 SiS_Pr->CHDisplay = VGAHDE;
3924 SiS_Pr->CHBlankStart = VGAHDE;
3925
3926 SiS_Pr->CVDisplay = SiS_Pr->SiS_VGAVDE;
3927 SiS_Pr->CVBlankStart = SiS_Pr->SiS_VGAVDE;
3928
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003929 if(SiS_Pr->ChipType < SIS_315H) {
3930#ifdef SIS300
3931 tempbx = SiS_Pr->SiS_VGAHT;
3932 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3933 tempbx = SiS_Pr->PanelHT;
3934 }
3935 if(modeflag & HalfDCLK) tempbx >>= 1;
3936 remaining = tempbx % 8;
3937#endif
3938 } else {
3939#ifdef SIS315H
3940 /* OK for LCDA, LVDS */
3941 tempbx = SiS_Pr->PanelHT - SiS_Pr->PanelXRes;
3942 tempax = SiS_Pr->SiS_VGAHDE; /* not /2 ! */
3943 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3944 tempax = SiS_Pr->PanelXRes;
3945 }
3946 tempbx += tempax;
3947 if(modeflag & HalfDCLK) tempbx -= VGAHDE;
3948#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 SiS_Pr->CHTotal = SiS_Pr->CHBlankEnd = tempbx;
3951
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003952 if(SiS_Pr->ChipType < SIS_315H) {
3953#ifdef SIS300
3954 if(SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) {
3955 SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE + ((SiS_Pr->PanelHRS + 1) & ~1);
3956 SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + SiS_Pr->PanelHRE;
3957 if(modeflag & HalfDCLK) {
3958 SiS_Pr->CHSyncStart >>= 1;
3959 SiS_Pr->CHSyncEnd >>= 1;
3960 }
3961 } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3962 tempax = (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) >> 1;
3963 tempbx = (SiS_Pr->PanelHRS + 1) & ~1;
3964 if(modeflag & HalfDCLK) {
3965 tempax >>= 1;
3966 tempbx >>= 1;
3967 }
3968 SiS_Pr->CHSyncStart = (VGAHDE + tempax + tempbx + 7) & ~7;
3969 tempax = SiS_Pr->PanelHRE + 7;
3970 if(modeflag & HalfDCLK) tempax >>= 1;
3971 SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + tempax) & ~7;
3972 } else {
3973 SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE;
3974 if(modeflag & HalfDCLK) {
3975 SiS_Pr->CHSyncStart >>= 1;
3976 tempax = ((SiS_Pr->CHTotal - SiS_Pr->CHSyncStart) / 3) << 1;
3977 SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + tempax;
3978 } else {
3979 SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + (SiS_Pr->CHTotal / 10) + 7) & ~7;
3980 SiS_Pr->CHSyncStart += 8;
3981 }
3982 }
3983#endif
3984 } else {
3985#ifdef SIS315H
3986 tempax = VGAHDE;
3987 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3988 tempbx = SiS_Pr->PanelXRes;
3989 if(modeflag & HalfDCLK) tempbx >>= 1;
3990 tempax += ((tempbx - tempax) >> 1);
3991 }
3992 tempax += SiS_Pr->PanelHRS;
3993 SiS_Pr->CHSyncStart = tempax;
3994 tempax += SiS_Pr->PanelHRE;
3995 SiS_Pr->CHSyncEnd = tempax;
3996#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 }
3998
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 tempbx = SiS_Pr->PanelVT - SiS_Pr->PanelYRes;
4000 tempax = SiS_Pr->SiS_VGAVDE;
4001 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
4002 tempax = SiS_Pr->PanelYRes;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004003 } else if(SiS_Pr->ChipType < SIS_315H) {
4004#ifdef SIS300
4005 /* Stupid hack for 640x400/320x200 */
4006 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
4007 if((tempax + tempbx) == 438) tempbx += 16;
4008 } else if((SiS_Pr->SiS_LCDResInfo == Panel_800x600) ||
4009 (SiS_Pr->SiS_LCDResInfo == Panel_1024x600)) {
4010 tempax = 0;
4011 tempbx = SiS_Pr->SiS_VGAVT;
4012 }
4013#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 }
4015 SiS_Pr->CVTotal = SiS_Pr->CVBlankEnd = tempbx + tempax;
4016
4017 tempax = SiS_Pr->SiS_VGAVDE;
4018 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
4019 tempax += (SiS_Pr->PanelYRes - tempax) >> 1;
4020 }
4021 tempax += SiS_Pr->PanelVRS;
4022 SiS_Pr->CVSyncStart = tempax;
4023 tempax += SiS_Pr->PanelVRE;
4024 SiS_Pr->CVSyncEnd = tempax;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004025 if(SiS_Pr->ChipType < SIS_315H) {
4026 SiS_Pr->CVSyncStart--;
4027 SiS_Pr->CVSyncEnd--;
4028 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029
4030 SiS_CalcCRRegisters(SiS_Pr, 8);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004031 SiS_Pr->CCRT1CRTC[15] &= ~0xF8;
4032 SiS_Pr->CCRT1CRTC[15] |= (remaining << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
4034
4035 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
4036
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004037 for(i = 0, j = 0; i <= 7; i++, j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
4039 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004040 for(j = 0x10; i <= 10; i++, j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
4042 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004043 for(j = 0x15; i <= 12; i++, j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
4045 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004046 for(j = 0x0A; i <= 15; i++, j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 SiS_SetReg(SiS_Pr->SiS_P3c4,j,SiS_Pr->CCRT1CRTC[i]);
4048 }
4049
4050 tempax = SiS_Pr->CCRT1CRTC[16] & 0xE0;
4051 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1F,tempax);
4052
4053 tempax = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
4054 if(modeflag & DoubleScanMode) tempax |= 0x80;
4055 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,tempax);
4056
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004057#ifdef SIS_XORG_XF86
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058#ifdef TWDEBUG
4059 xf86DrvMsg(0, X_INFO, "%d %d %d %d %d %d %d %d (%d %d %d %d)\n",
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004060 SiS_Pr->CHDisplay, SiS_Pr->CHSyncStart, SiS_Pr->CHSyncEnd, SiS_Pr->CHTotal,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 SiS_Pr->CVDisplay, SiS_Pr->CVSyncStart, SiS_Pr->CVSyncEnd, SiS_Pr->CVTotal,
4062 SiS_Pr->CHBlankStart, SiS_Pr->CHBlankEnd, SiS_Pr->CVBlankStart, SiS_Pr->CVBlankEnd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 xf86DrvMsg(0, X_INFO, " {{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004064 SiS_Pr->CCRT1CRTC[0], SiS_Pr->CCRT1CRTC[1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065 SiS_Pr->CCRT1CRTC[2], SiS_Pr->CCRT1CRTC[3],
4066 SiS_Pr->CCRT1CRTC[4], SiS_Pr->CCRT1CRTC[5],
4067 SiS_Pr->CCRT1CRTC[6], SiS_Pr->CCRT1CRTC[7]);
4068 xf86DrvMsg(0, X_INFO, " 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004069 SiS_Pr->CCRT1CRTC[8], SiS_Pr->CCRT1CRTC[9],
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 SiS_Pr->CCRT1CRTC[10], SiS_Pr->CCRT1CRTC[11],
4071 SiS_Pr->CCRT1CRTC[12], SiS_Pr->CCRT1CRTC[13],
4072 SiS_Pr->CCRT1CRTC[14], SiS_Pr->CCRT1CRTC[15]);
4073 xf86DrvMsg(0, X_INFO, " 0x%02x}},\n", SiS_Pr->CCRT1CRTC[16]);
4074#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004075#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076}
4077
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004079SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
4080 int xres, int yres,
4081#ifdef SIS_XORG_XF86
4082 DisplayModePtr current
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004084#ifdef SIS_LINUX_KERNEL
Richard Knutssonc30660ea2007-02-12 00:55:06 -08004085 struct fb_var_screeninfo *var, bool writeres
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004087)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 unsigned short HRE, HBE, HRS, HBS, HDE, HT;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004090 unsigned short VRE, VBE, VRS, VBS, VDE, VT;
4091 unsigned char sr_data, cr_data, cr_data2;
4092 int A, B, C, D, E, F, temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004094 sr_data = crdata[14];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004096 /* Horizontal total */
4097 HT = crdata[0] | ((unsigned short)(sr_data & 0x03) << 8);
4098 A = HT + 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004100 /* Horizontal display enable end */
4101 HDE = crdata[1] | ((unsigned short)(sr_data & 0x0C) << 6);
4102 E = HDE + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004104 /* Horizontal retrace (=sync) start */
4105 HRS = crdata[4] | ((unsigned short)(sr_data & 0xC0) << 2);
4106 F = HRS - E - 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004108 /* Horizontal blank start */
4109 HBS = crdata[2] | ((unsigned short)(sr_data & 0x30) << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004111 sr_data = crdata[15];
4112 cr_data = crdata[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004114 /* Horizontal blank end */
4115 HBE = (crdata[3] & 0x1f) |
4116 ((unsigned short)(cr_data & 0x80) >> 2) |
4117 ((unsigned short)(sr_data & 0x03) << 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004119 /* Horizontal retrace (=sync) end */
4120 HRE = (cr_data & 0x1f) | ((sr_data & 0x04) << 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004122 temp = HBE - ((E - 1) & 255);
4123 B = (temp > 0) ? temp : (temp + 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004125 temp = HRE - ((E + F + 3) & 63);
4126 C = (temp > 0) ? temp : (temp + 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004128 D = B - F - C;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004130#ifdef SIS_XORG_XF86
4131 current->HDisplay = (E * 8);
4132 current->HSyncStart = (E * 8) + (F * 8);
4133 current->HSyncEnd = (E * 8) + (F * 8) + (C * 8);
4134 current->HTotal = (E * 8) + (F * 8) + (C * 8) + (D * 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135#ifdef TWDEBUG
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004136 xf86DrvMsg(0, X_INFO,
4137 "H: A %d B %d C %d D %d E %d F %d HT %d HDE %d HRS %d HBS %d HBE %d HRE %d\n",
4138 A, B, C, D, E, F, HT, HDE, HRS, HBS, HBE, HRE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139#else
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004140 (void)VBS; (void)HBS; (void)A;
4141#endif
4142#endif
4143#ifdef SIS_LINUX_KERNEL
4144 if(writeres) var->xres = xres = E * 8;
4145 var->left_margin = D * 8;
4146 var->right_margin = F * 8;
4147 var->hsync_len = C * 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148#endif
4149
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004150 /* Vertical */
4151 sr_data = crdata[13];
4152 cr_data = crdata[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004154 /* Vertical total */
4155 VT = crdata[6] |
4156 ((unsigned short)(cr_data & 0x01) << 8) |
4157 ((unsigned short)(cr_data & 0x20) << 4) |
4158 ((unsigned short)(sr_data & 0x01) << 10);
4159 A = VT + 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004161 /* Vertical display enable end */
4162 VDE = crdata[10] |
4163 ((unsigned short)(cr_data & 0x02) << 7) |
4164 ((unsigned short)(cr_data & 0x40) << 3) |
4165 ((unsigned short)(sr_data & 0x02) << 9);
4166 E = VDE + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004168 /* Vertical retrace (=sync) start */
4169 VRS = crdata[8] |
4170 ((unsigned short)(cr_data & 0x04) << 6) |
4171 ((unsigned short)(cr_data & 0x80) << 2) |
4172 ((unsigned short)(sr_data & 0x08) << 7);
4173 F = VRS + 1 - E;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004175 cr_data2 = (crdata[16] & 0x01) << 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004177 /* Vertical blank start */
4178 VBS = crdata[11] |
4179 ((unsigned short)(cr_data & 0x08) << 5) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 ((unsigned short)(cr_data2 & 0x20) << 4) |
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004181 ((unsigned short)(sr_data & 0x04) << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004183 /* Vertical blank end */
4184 VBE = crdata[12] | ((unsigned short)(sr_data & 0x10) << 4);
4185 temp = VBE - ((E - 1) & 511);
4186 B = (temp > 0) ? temp : (temp + 512);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004188 /* Vertical retrace (=sync) end */
4189 VRE = (crdata[9] & 0x0f) | ((sr_data & 0x20) >> 1);
4190 temp = VRE - ((E + F - 1) & 31);
4191 C = (temp > 0) ? temp : (temp + 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004193 D = B - F - C;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004195#ifdef SIS_XORG_XF86
4196 current->VDisplay = VDE + 1;
4197 current->VSyncStart = VRS + 1;
4198 current->VSyncEnd = ((VRS & ~0x1f) | VRE) + 1;
4199 if(VRE <= (VRS & 0x1f)) current->VSyncEnd += 32;
4200 current->VTotal = E + D + C + F;
4201#if 0
4202 current->VDisplay = E;
4203 current->VSyncStart = E + D;
4204 current->VSyncEnd = E + D + C;
4205 current->VTotal = E + D + C + F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004207#ifdef TWDEBUG
4208 xf86DrvMsg(0, X_INFO,
4209 "V: A %d B %d C %d D %d E %d F %d VT %d VDE %d VRS %d VBS %d VBE %d VRE %d\n",
4210 A, B, C, D, E, F, VT, VDE, VRS, VBS, VBE, VRE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004212#endif
4213#ifdef SIS_LINUX_KERNEL
4214 if(writeres) var->yres = yres = E;
4215 var->upper_margin = D;
4216 var->lower_margin = F;
4217 var->vsync_len = C;
4218#endif
4219
4220 if((xres == 320) && ((yres == 200) || (yres == 240))) {
4221 /* Terrible hack, but correct CRTC data for
4222 * these modes only produces a black screen...
4223 * (HRE is 0, leading into a too large C and
4224 * a negative D. The CRT controller does not
4225 * seem to like correcting HRE to 50)
4226 */
4227#ifdef SIS_XORG_XF86
4228 current->HDisplay = 320;
4229 current->HSyncStart = 328;
4230 current->HSyncEnd = 376;
4231 current->HTotal = 400;
4232#endif
4233#ifdef SIS_LINUX_KERNEL
4234 var->left_margin = (400 - 376);
4235 var->right_margin = (328 - 320);
4236 var->hsync_len = (376 - 328);
4237#endif
4238
4239 }
4240
4241}
4242
4243
4244
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245