blob: 31137adc8fba5245596d378bf785345957cc6597 [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
Aaro Koskinenf7854e52010-11-19 21:58:47 +000065#ifdef CONFIG_FB_SIS_300
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#include "300vtbl.h"
67#endif
68
Aaro Koskinenf7854e52010-11-19 21:58:47 +000069#ifdef CONFIG_FB_SIS_315
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#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
Aaro Koskinenf7854e52010-11-19 21:58:47 +000081#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static 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
Aaro Koskinenf7854e52010-11-19 21:58:47 +0000163#ifdef CONFIG_FB_SIS_300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164static 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
Aaro Koskinenf7854e52010-11-19 21:58:47 +0000240#ifdef CONFIG_FB_SIS_315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241static 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) {
Aaro Koskinenf7854e52010-11-19 21:58:47 +0000324#ifdef CONFIG_FB_SIS_300
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 {
Aaro Koskinenf7854e52010-11-19 21:58:47 +0000330#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700331 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 -0700343static
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700344unsigned short
345SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800346 int Depth, bool FSTN, int LCDwidth, int LCDheight)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700348 unsigned short ModeIndex = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350 switch(HDisplay)
351 {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700352 case 320:
353 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
354 else if(VDisplay == 240) {
355 if((VBFlags & CRT2_LCD) && (FSTN))
356 ModeIndex = ModeIndex_320x240_FSTN[Depth];
357 else
358 ModeIndex = ModeIndex_320x240[Depth];
359 }
360 break;
361 case 400:
362 if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 800) && (LCDwidth >= 600))) {
363 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
364 }
365 break;
366 case 512:
367 if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 1024) && (LCDwidth >= 768))) {
368 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
369 }
370 break;
371 case 640:
372 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
373 else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
374 break;
375 case 720:
376 if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth];
377 else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
378 break;
379 case 768:
380 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
381 break;
382 case 800:
383 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
384 else if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
385 break;
386 case 848:
387 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
388 break;
389 case 856:
390 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
391 break;
392 case 960:
393 if(VGAEngine == SIS_315_VGA) {
394 if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth];
395 else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth];
396 }
397 break;
398 case 1024:
399 if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
400 else if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
401 else if(VGAEngine == SIS_300_VGA) {
402 if(VDisplay == 600) ModeIndex = ModeIndex_1024x600[Depth];
403 }
404 break;
405 case 1152:
406 if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth];
407 if(VGAEngine == SIS_300_VGA) {
408 if(VDisplay == 768) ModeIndex = ModeIndex_1152x768[Depth];
409 }
410 break;
411 case 1280:
412 switch(VDisplay) {
413 case 720:
414 ModeIndex = ModeIndex_1280x720[Depth];
415 break;
416 case 768:
417 if(VGAEngine == SIS_300_VGA) {
418 ModeIndex = ModeIndex_300_1280x768[Depth];
419 } else {
420 ModeIndex = ModeIndex_310_1280x768[Depth];
421 }
422 break;
423 case 800:
424 if(VGAEngine == SIS_315_VGA) {
425 ModeIndex = ModeIndex_1280x800[Depth];
426 }
427 break;
428 case 854:
429 if(VGAEngine == SIS_315_VGA) {
430 ModeIndex = ModeIndex_1280x854[Depth];
431 }
432 break;
433 case 960:
434 ModeIndex = ModeIndex_1280x960[Depth];
435 break;
436 case 1024:
437 ModeIndex = ModeIndex_1280x1024[Depth];
438 break;
439 }
440 break;
441 case 1360:
442 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
443 if(VGAEngine == SIS_300_VGA) {
444 if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
445 }
446 break;
447 case 1400:
448 if(VGAEngine == SIS_315_VGA) {
449 if(VDisplay == 1050) {
450 ModeIndex = ModeIndex_1400x1050[Depth];
451 }
452 }
453 break;
454 case 1600:
455 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
456 break;
457 case 1680:
458 if(VGAEngine == SIS_315_VGA) {
459 if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
460 }
461 break;
462 case 1920:
463 if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth];
464 else if(VGAEngine == SIS_315_VGA) {
465 if(VDisplay == 1080) ModeIndex = ModeIndex_1920x1080[Depth];
466 }
467 break;
468 case 2048:
469 if(VDisplay == 1536) {
470 if(VGAEngine == SIS_300_VGA) {
471 ModeIndex = ModeIndex_300_2048x1536[Depth];
472 } else {
473 ModeIndex = ModeIndex_310_2048x1536[Depth];
474 }
475 }
476 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 }
478
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700479 return ModeIndex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700482unsigned short
483SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800484 int Depth, bool FSTN, unsigned short CustomT, int LCDwidth, int LCDheight,
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700485 unsigned int VBFlags2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700487 unsigned short ModeIndex = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700489 if(VBFlags2 & (VB2_LVDS | VB2_30xBDH)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491 switch(HDisplay)
492 {
493 case 320:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700494 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
495 if(VDisplay == 200) {
496 if(!FSTN) ModeIndex = ModeIndex_320x200[Depth];
497 } else if(VDisplay == 240) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 if(!FSTN) ModeIndex = ModeIndex_320x240[Depth];
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700499 else if(VGAEngine == SIS_315_VGA) {
500 ModeIndex = ModeIndex_320x240_FSTN[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502 }
503 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700504 break;
505 case 400:
506 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
507 if(!((VGAEngine == SIS_300_VGA) && (VBFlags2 & VB2_TRUMPION))) {
508 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
510 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700511 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 case 512:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700513 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
514 if(!((VGAEngine == SIS_300_VGA) && (VBFlags2 & VB2_TRUMPION))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if(LCDwidth >= 1024 && LCDwidth != 1152 && LCDheight >= 768) {
516 if(VDisplay == 384) {
517 ModeIndex = ModeIndex_512x384[Depth];
518 }
519 }
520 }
521 }
522 break;
523 case 640:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700524 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 else if(VDisplay == 400) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700526 if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856))
527 ModeIndex = ModeIndex_640x400[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 }
529 break;
530 case 800:
531 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
532 break;
533 case 848:
534 if(CustomT == CUT_PANEL848) {
535 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
536 }
537 break;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700538 case 856:
539 if(CustomT == CUT_PANEL856) {
540 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
541 }
542 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 case 1024:
544 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
545 else if(VGAEngine == SIS_300_VGA) {
546 if((VDisplay == 600) && (LCDheight == 600)) {
547 ModeIndex = ModeIndex_1024x600[Depth];
548 }
549 }
550 break;
551 case 1152:
552 if(VGAEngine == SIS_300_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700553 if((VDisplay == 768) && (LCDheight == 768)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 ModeIndex = ModeIndex_1152x768[Depth];
555 }
556 }
557 break;
558 case 1280:
559 if(VDisplay == 1024) ModeIndex = ModeIndex_1280x1024[Depth];
560 else if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700561 if((VDisplay == 768) && (LCDheight == 768)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 ModeIndex = ModeIndex_310_1280x768[Depth];
563 }
564 }
565 break;
566 case 1360:
567 if(VGAEngine == SIS_300_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700568 if(CustomT == CUT_BARCO1366) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
570 }
571 }
572 if(CustomT == CUT_PANEL848) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700573 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 }
575 break;
576 case 1400:
577 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700578 if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580 break;
581 case 1600:
582 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700583 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
585 break;
586 }
587
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700588 } else if(VBFlags2 & VB2_SISBRIDGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 switch(HDisplay)
591 {
592 case 320:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700593 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700595 break;
596 case 400:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 if(LCDwidth >= 800 && LCDheight >= 600) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700598 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700600 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 case 512:
602 if(LCDwidth >= 1024 && LCDheight >= 768 && LCDwidth != 1152) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700603 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 }
605 break;
606 case 640:
607 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
608 else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
609 break;
610 case 720:
611 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700612 if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
614 }
615 break;
616 case 768:
617 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700618 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
620 break;
621 case 800:
622 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
623 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700624 if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
626 break;
627 case 848:
628 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700629 if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631 break;
632 case 856:
633 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700634 if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 }
636 break;
637 case 960:
638 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700639 if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth];
641 }
642 break;
643 case 1024:
644 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
645 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700646 if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648 break;
649 case 1152:
650 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700651 if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653 break;
654 case 1280:
655 switch(VDisplay) {
656 case 720:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700657 ModeIndex = ModeIndex_1280x720[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 case 768:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700659 if(VGAEngine == SIS_300_VGA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 ModeIndex = ModeIndex_300_1280x768[Depth];
661 } else {
662 ModeIndex = ModeIndex_310_1280x768[Depth];
663 }
664 break;
665 case 800:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700666 if(VGAEngine == SIS_315_VGA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 ModeIndex = ModeIndex_1280x800[Depth];
668 }
669 break;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700670 case 854:
671 if(VGAEngine == SIS_315_VGA) {
672 ModeIndex = ModeIndex_1280x854[Depth];
673 }
674 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 case 960:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700676 ModeIndex = ModeIndex_1280x960[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 break;
678 case 1024:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700679 ModeIndex = ModeIndex_1280x1024[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 break;
681 }
682 break;
683 case 1360:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700684 if(VGAEngine == SIS_315_VGA) { /* OVER1280 only? */
685 if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
687 break;
688 case 1400:
689 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700690 if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
692 }
693 }
694 break;
695 case 1600:
696 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700697 if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
698 if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700 }
701 break;
702#ifndef VB_FORBID_CRT2LCD_OVER_1600
703 case 1680:
704 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700705 if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
706 if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
707 }
708 }
709 break;
710 case 1920:
711 if(VGAEngine == SIS_315_VGA) {
712 if(VBFlags2 & VB2_LCDOVER1600BRIDGE) {
713 if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth];
714 }
715 }
716 break;
717 case 2048:
718 if(VGAEngine == SIS_315_VGA) {
719 if(VBFlags2 & VB2_LCDOVER1600BRIDGE) {
720 if(VDisplay == 1536) ModeIndex = ModeIndex_310_2048x1536[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722 }
723 break;
724#endif
725 }
726 }
727
728 return ModeIndex;
729}
730
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700731unsigned short
732SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, int Depth,
733 unsigned int VBFlags2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700735 unsigned short ModeIndex = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700737 if(VBFlags2 & VB2_CHRONTEL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 switch(HDisplay)
740 {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700741 case 512:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 if(VGAEngine == SIS_315_VGA) {
743 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
744 }
745 break;
746 case 640:
747 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
748 else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
749 break;
750 case 800:
751 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
752 break;
753 case 1024:
754 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700755 if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
757 break;
758 }
759
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700760 } else if(VBFlags2 & VB2_SISTVBRIDGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 switch(HDisplay)
763 {
764 case 320:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700765 if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700767 break;
768 case 400:
769 if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
770 break;
771 case 512:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 if( ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR750P | TV_YPBPR1080I))) ||
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700773 (VBFlags & TV_HIVISION) ||
774 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) {
775 if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 }
777 break;
778 case 640:
779 if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
780 else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
781 break;
782 case 720:
783 if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700784 if(VDisplay == 480) {
785 ModeIndex = ModeIndex_720x480[Depth];
786 } else if(VDisplay == 576) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) ||
788 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) )
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700789 ModeIndex = ModeIndex_720x576[Depth];
790 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 }
792 break;
793 case 768:
794 if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700795 if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700797 if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 }
799 }
800 break;
801 case 800:
802 if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
803 else if(VDisplay == 480) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700804 if(!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 ModeIndex = ModeIndex_800x480[Depth];
806 }
807 }
808 break;
809 case 960:
810 if(VGAEngine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700811 if(VDisplay == 600) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 if((VBFlags & TV_HIVISION) || ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
813 ModeIndex = ModeIndex_960x600[Depth];
814 }
815 }
816 }
817 break;
818 case 1024:
819 if(VDisplay == 768) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700820 if(VBFlags2 & VB2_30xBLV) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 ModeIndex = ModeIndex_1024x768[Depth];
822 }
823 } else if(VDisplay == 576) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700824 if( (VBFlags & TV_HIVISION) ||
825 ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)) ||
826 ((VBFlags2 & VB2_30xBLV) &&
827 ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL))) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 ModeIndex = ModeIndex_1024x576[Depth];
829 }
830 }
831 break;
832 case 1280:
833 if(VDisplay == 720) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700834 if((VBFlags & TV_HIVISION) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR1080I | TV_YPBPR750P)))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700836 ModeIndex = ModeIndex_1280x720[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 }
838 } else if(VDisplay == 1024) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700839 if((VBFlags & TV_HIVISION) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700841 ModeIndex = ModeIndex_1280x1024[Depth];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 }
843 }
844 break;
845 }
846 }
847 return ModeIndex;
848}
849
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700850unsigned short
851SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, int Depth,
852 unsigned int VBFlags2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700854 if(!(VBFlags2 & VB2_SISVGA2BRIDGE)) return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700856 if(HDisplay >= 1920) return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 switch(HDisplay)
859 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 case 1600:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700861 if(VDisplay == 1200) {
862 if(VGAEngine != SIS_315_VGA) return 0;
863 if(!(VBFlags2 & VB2_30xB)) return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 }
865 break;
866 case 1680:
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700867 if(VDisplay == 1050) {
868 if(VGAEngine != SIS_315_VGA) return 0;
869 if(!(VBFlags2 & VB2_30xB)) return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 }
871 break;
872 }
873
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800874 return SiS_GetModeID(VGAEngine, 0, HDisplay, VDisplay, Depth, false, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
876
877
878/*********************************************/
879/* HELPER: SetReg, GetReg */
880/*********************************************/
881
882void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700883SiS_SetReg(SISIOADDRESS port, unsigned short index, unsigned short data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884{
Aaro Koskinen2ad28472010-11-19 21:58:48 +0000885 outb((u8)index, port);
886 outb((u8)data, port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887}
888
889void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700890SiS_SetRegByte(SISIOADDRESS port, unsigned short data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
Aaro Koskinen2ad28472010-11-19 21:58:48 +0000892 outb((u8)data, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893}
894
895void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700896SiS_SetRegShort(SISIOADDRESS port, unsigned short data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
Aaro Koskinen2ad28472010-11-19 21:58:48 +0000898 outw((u16)data, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899}
900
901void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700902SiS_SetRegLong(SISIOADDRESS port, unsigned int data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903{
Aaro Koskinen2ad28472010-11-19 21:58:48 +0000904 outl((u32)data, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905}
906
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700907unsigned char
908SiS_GetReg(SISIOADDRESS port, unsigned short index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909{
Aaro Koskinen2ad28472010-11-19 21:58:48 +0000910 outb((u8)index, port);
911 return inb(port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912}
913
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700914unsigned char
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915SiS_GetRegByte(SISIOADDRESS port)
916{
Aaro Koskinen2ad28472010-11-19 21:58:48 +0000917 return inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918}
919
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700920unsigned short
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921SiS_GetRegShort(SISIOADDRESS port)
922{
Aaro Koskinen2ad28472010-11-19 21:58:48 +0000923 return inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924}
925
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700926unsigned int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927SiS_GetRegLong(SISIOADDRESS port)
928{
Aaro Koskinen2ad28472010-11-19 21:58:48 +0000929 return inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930}
931
932void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700933SiS_SetRegANDOR(SISIOADDRESS Port, unsigned short Index, unsigned short DataAND, unsigned short DataOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700935 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700937 temp = SiS_GetReg(Port, Index);
938 temp = (temp & (DataAND)) | DataOR;
939 SiS_SetReg(Port, Index, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940}
941
942void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700943SiS_SetRegAND(SISIOADDRESS Port, unsigned short Index, unsigned short DataAND)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700945 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700947 temp = SiS_GetReg(Port, Index);
948 temp &= DataAND;
949 SiS_SetReg(Port, Index, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
952void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700953SiS_SetRegOR(SISIOADDRESS Port, unsigned short Index, unsigned short DataOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700955 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700957 temp = SiS_GetReg(Port, Index);
958 temp |= DataOR;
959 SiS_SetReg(Port, Index, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960}
961
962/*********************************************/
963/* HELPER: DisplayOn, DisplayOff */
964/*********************************************/
965
966void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700967SiS_DisplayOn(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968{
969 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x01,0xDF);
970}
971
972void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700973SiS_DisplayOff(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974{
975 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x20);
976}
977
978
979/*********************************************/
980/* HELPER: Init Port Addresses */
981/*********************************************/
982
983void
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700984SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985{
986 SiS_Pr->SiS_P3c4 = BaseAddr + 0x14;
987 SiS_Pr->SiS_P3d4 = BaseAddr + 0x24;
988 SiS_Pr->SiS_P3c0 = BaseAddr + 0x10;
989 SiS_Pr->SiS_P3ce = BaseAddr + 0x1e;
990 SiS_Pr->SiS_P3c2 = BaseAddr + 0x12;
991 SiS_Pr->SiS_P3ca = BaseAddr + 0x1a;
992 SiS_Pr->SiS_P3c6 = BaseAddr + 0x16;
993 SiS_Pr->SiS_P3c7 = BaseAddr + 0x17;
994 SiS_Pr->SiS_P3c8 = BaseAddr + 0x18;
995 SiS_Pr->SiS_P3c9 = BaseAddr + 0x19;
996 SiS_Pr->SiS_P3cb = BaseAddr + 0x1b;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700997 SiS_Pr->SiS_P3cc = BaseAddr + 0x1c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 SiS_Pr->SiS_P3cd = BaseAddr + 0x1d;
999 SiS_Pr->SiS_P3da = BaseAddr + 0x2a;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001000 SiS_Pr->SiS_Part1Port = BaseAddr + SIS_CRT2_PORT_04;
1001 SiS_Pr->SiS_Part2Port = BaseAddr + SIS_CRT2_PORT_10;
1002 SiS_Pr->SiS_Part3Port = BaseAddr + SIS_CRT2_PORT_12;
1003 SiS_Pr->SiS_Part4Port = BaseAddr + SIS_CRT2_PORT_14;
1004 SiS_Pr->SiS_Part5Port = BaseAddr + SIS_CRT2_PORT_14 + 2;
1005 SiS_Pr->SiS_DDC_Port = BaseAddr + 0x14;
1006 SiS_Pr->SiS_VidCapt = BaseAddr + SIS_VIDEO_CAPTURE;
1007 SiS_Pr->SiS_VidPlay = BaseAddr + SIS_VIDEO_PLAYBACK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008}
1009
1010/*********************************************/
1011/* HELPER: GetSysFlags */
1012/*********************************************/
1013
1014static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001015SiS_GetSysFlags(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
1017 unsigned char cr5f, temp1, temp2;
1018
1019 /* 661 and newer: NEVER write non-zero to SR11[7:4] */
1020 /* (SR11 is used for DDC and in enable/disablebridge) */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001021 SiS_Pr->SiS_SensibleSR11 = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 SiS_Pr->SiS_MyCR63 = 0x63;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001023 if(SiS_Pr->ChipType >= SIS_330) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 SiS_Pr->SiS_MyCR63 = 0x53;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001025 if(SiS_Pr->ChipType >= SIS_661) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001026 SiS_Pr->SiS_SensibleSR11 = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 }
1028 }
1029
1030 /* You should use the macros, not these flags directly */
1031
1032 SiS_Pr->SiS_SysFlags = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001033 if(SiS_Pr->ChipType == SIS_650) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 cr5f = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
1035 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x5c,0x07);
1036 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
1037 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x5c,0xf8);
1038 temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
1039 if((!temp1) || (temp2)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001040 switch(cr5f) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 case 0x80:
1042 case 0x90:
1043 case 0xc0:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001044 SiS_Pr->SiS_SysFlags |= SF_IsM650;
1045 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 case 0xa0:
1047 case 0xb0:
1048 case 0xe0:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001049 SiS_Pr->SiS_SysFlags |= SF_Is651;
1050 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 }
1052 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001053 switch(cr5f) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 case 0x90:
1055 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
1056 switch(temp1) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001057 case 0x00: SiS_Pr->SiS_SysFlags |= SF_IsM652; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 case 0x40: SiS_Pr->SiS_SysFlags |= SF_IsM653; break;
1059 default: SiS_Pr->SiS_SysFlags |= SF_IsM650; break;
1060 }
1061 break;
1062 case 0xb0:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001063 SiS_Pr->SiS_SysFlags |= SF_Is652;
1064 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 default:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001066 SiS_Pr->SiS_SysFlags |= SF_IsM650;
1067 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
1069 }
1070 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001071
1072 if(SiS_Pr->ChipType >= SIS_760 && SiS_Pr->ChipType <= SIS_761) {
1073 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0x30) {
1074 SiS_Pr->SiS_SysFlags |= SF_760LFB;
1075 }
1076 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0xf0) {
1077 SiS_Pr->SiS_SysFlags |= SF_760UMA;
1078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 }
1080}
1081
1082/*********************************************/
1083/* HELPER: Init PCI & Engines */
1084/*********************************************/
1085
1086static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001087SiSInitPCIetc(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001089 switch(SiS_Pr->ChipType) {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00001090#ifdef CONFIG_FB_SIS_300
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 case SIS_300:
1092 case SIS_540:
1093 case SIS_630:
1094 case SIS_730:
1095 /* Set - PCI LINEAR ADDRESSING ENABLE (0x80)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001096 * - RELOCATED VGA IO ENABLED (0x20)
1097 * - MMIO ENABLED (0x01)
1098 * Leave other bits untouched.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001100 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 /* - Enable 2D (0x40)
1102 * - Enable 3D (0x02)
1103 * - Enable 3D Vertex command fetch (0x10) ?
1104 * - Enable 3D command parser (0x08) ?
1105 */
1106 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x5A);
1107 break;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001108#endif
Aaro Koskinenf7854e52010-11-19 21:58:47 +00001109#ifdef CONFIG_FB_SIS_315
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 case SIS_315H:
1111 case SIS_315:
1112 case SIS_315PRO:
1113 case SIS_650:
1114 case SIS_740:
1115 case SIS_330:
1116 case SIS_661:
1117 case SIS_741:
1118 case SIS_660:
1119 case SIS_760:
1120 case SIS_761:
1121 case SIS_340:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001122 case XGI_40:
1123 /* See above */
1124 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
1125 /* - Enable 3D G/L transformation engine (0x80)
1126 * - Enable 2D (0x40)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 * - Enable 3D vertex command fetch (0x10)
1128 * - Enable 3D command parser (0x08)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001129 * - Enable 3D (0x02)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 */
1131 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0xDA);
1132 break;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001133 case XGI_20:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 case SIS_550:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001135 /* See above */
1136 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 /* No 3D engine ! */
1138 /* - Enable 2D (0x40)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001139 * - disable 3D
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001141 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1E,0x60,0x40);
1142 break;
1143#endif
1144 default:
1145 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 }
1147}
1148
1149/*********************************************/
1150/* HELPER: SetLVDSetc */
1151/*********************************************/
1152
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001153static
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001154void
1155SiSSetLVDSetc(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001157 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
1159 SiS_Pr->SiS_IF_DEF_LVDS = 0;
1160 SiS_Pr->SiS_IF_DEF_TRUMPION = 0;
1161 SiS_Pr->SiS_IF_DEF_CH70xx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 SiS_Pr->SiS_IF_DEF_CONEX = 0;
1163
1164 SiS_Pr->SiS_ChrontelInit = 0;
1165
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001166 if(SiS_Pr->ChipType == XGI_20) return;
1167
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 /* Check for SiS30x first */
1169 temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
1170 if((temp == 1) || (temp == 2)) return;
1171
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001172 switch(SiS_Pr->ChipType) {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00001173#ifdef CONFIG_FB_SIS_300
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 case SIS_540:
1175 case SIS_630:
1176 case SIS_730:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001177 temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x37) & 0x0e) >> 1;
1178 if((temp >= 2) && (temp <= 5)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
1179 if(temp == 3) SiS_Pr->SiS_IF_DEF_TRUMPION = 1;
1180 if((temp == 4) || (temp == 5)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 /* Save power status (and error check) - UNUSED */
1182 SiS_Pr->SiS_Backup70xx = SiS_GetCH700x(SiS_Pr, 0x0e);
1183 SiS_Pr->SiS_IF_DEF_CH70xx = 1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001184 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 break;
1186#endif
Aaro Koskinenf7854e52010-11-19 21:58:47 +00001187#ifdef CONFIG_FB_SIS_315
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 case SIS_550:
1189 case SIS_650:
1190 case SIS_740:
1191 case SIS_330:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001192 temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x37) & 0x0e) >> 1;
1193 if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
1194 if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2;
1195 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 case SIS_661:
1197 case SIS_741:
1198 case SIS_660:
1199 case SIS_760:
1200 case SIS_761:
1201 case SIS_340:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001202 case XGI_20:
1203 case XGI_40:
1204 temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0xe0) >> 5;
1205 if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
1206 if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2;
1207 if(temp == 4) SiS_Pr->SiS_IF_DEF_CONEX = 1; /* Not yet supported */
1208 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209#endif
1210 default:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001211 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 }
1213}
1214
1215/*********************************************/
1216/* HELPER: Enable DSTN/FSTN */
1217/*********************************************/
1218
1219void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001220SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221{
1222 SiS_Pr->SiS_IF_DEF_DSTN = enable ? 1 : 0;
1223}
1224
1225void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001226SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227{
1228 SiS_Pr->SiS_IF_DEF_FSTN = enable ? 1 : 0;
1229}
1230
1231/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001232/* HELPER: Get modeflag */
1233/*********************************************/
1234
1235unsigned short
1236SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1237 unsigned short ModeIdIndex)
1238{
1239 if(SiS_Pr->UseCustomMode) {
1240 return SiS_Pr->CModeFlag;
1241 } else if(ModeNo <= 0x13) {
1242 return SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
1243 } else {
1244 return SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1245 }
1246}
1247
1248/*********************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249/* HELPER: Determine ROM usage */
1250/*********************************************/
1251
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001252bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001253SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001255 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1256 unsigned short romversoffs, romvmaj = 1, romvmin = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001258 if(SiS_Pr->ChipType >= XGI_20) {
1259 /* XGI ROMs don't qualify */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001260 return false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001261 } else if(SiS_Pr->ChipType >= SIS_761) {
1262 /* I very much assume 761, 340 and newer will use new layout */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001263 return true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001264 } else if(SiS_Pr->ChipType >= SIS_661) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 if((ROMAddr[0x1a] == 'N') &&
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001266 (ROMAddr[0x1b] == 'e') &&
1267 (ROMAddr[0x1c] == 'w') &&
1268 (ROMAddr[0x1d] == 'V')) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001269 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 }
1271 romversoffs = ROMAddr[0x16] | (ROMAddr[0x17] << 8);
1272 if(romversoffs) {
1273 if((ROMAddr[romversoffs+1] == '.') || (ROMAddr[romversoffs+4] == '.')) {
1274 romvmaj = ROMAddr[romversoffs] - '0';
1275 romvmin = ((ROMAddr[romversoffs+2] -'0') * 10) + (ROMAddr[romversoffs+3] - '0');
1276 }
1277 }
1278 if((romvmaj != 0) || (romvmin >= 92)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001279 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 }
1281 } else if(IS_SIS650740) {
1282 if((ROMAddr[0x1a] == 'N') &&
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001283 (ROMAddr[0x1b] == 'e') &&
1284 (ROMAddr[0x1c] == 'w') &&
1285 (ROMAddr[0x1d] == 'V')) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001286 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 }
1288 }
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001289 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290}
1291
1292static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001293SiSDetermineROMUsage(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001295 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1296 unsigned short romptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001298 SiS_Pr->SiS_UseROM = false;
1299 SiS_Pr->SiS_ROMNew = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001300 SiS_Pr->SiS_PWDOffset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001302 if(SiS_Pr->ChipType >= XGI_20) return;
1303
1304 if((ROMAddr) && (SiS_Pr->UseROM)) {
1305 if(SiS_Pr->ChipType == SIS_300) {
1306 /* 300: We check if the code starts below 0x220 by
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 * checking the jmp instruction at the beginning
1308 * of the BIOS image.
1309 */
1310 if((ROMAddr[3] == 0xe9) && ((ROMAddr[5] << 8) | ROMAddr[4]) > 0x21a)
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001311 SiS_Pr->SiS_UseROM = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001312 } else if(SiS_Pr->ChipType < SIS_315H) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 /* Sony's VAIO BIOS 1.09 follows the standard, so perhaps
1314 * the others do as well
1315 */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001316 SiS_Pr->SiS_UseROM = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001318 /* 315/330 series stick to the standard(s) */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001319 SiS_Pr->SiS_UseROM = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001320 if((SiS_Pr->SiS_ROMNew = SiSDetermineROMLayout661(SiS_Pr))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 SiS_Pr->SiS_EMIOffset = 14;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001322 SiS_Pr->SiS_PWDOffset = 17;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 SiS_Pr->SiS661LCD2TableSize = 36;
1324 /* Find out about LCD data table entry size */
1325 if((romptr = SISGETROMW(0x0102))) {
1326 if(ROMAddr[romptr + (32 * 16)] == 0xff)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001327 SiS_Pr->SiS661LCD2TableSize = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 else if(ROMAddr[romptr + (34 * 16)] == 0xff)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001329 SiS_Pr->SiS661LCD2TableSize = 34;
1330 else if(ROMAddr[romptr + (36 * 16)] == 0xff) /* 0.94, 2.05.00+ */
1331 SiS_Pr->SiS661LCD2TableSize = 36;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 else if( (ROMAddr[romptr + (38 * 16)] == 0xff) || /* 2.00.00 - 2.02.00 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001333 (ROMAddr[0x6F] & 0x01) ) { /* 2.03.00 - <2.05.00 */
1334 SiS_Pr->SiS661LCD2TableSize = 38; /* UMC data layout abandoned at 2.05.00 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 SiS_Pr->SiS_EMIOffset = 16;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001336 SiS_Pr->SiS_PWDOffset = 19;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 }
1338 }
1339 }
1340 }
1341 }
1342}
1343
1344/*********************************************/
1345/* HELPER: SET SEGMENT REGISTERS */
1346/*********************************************/
1347
1348static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001349SiS_SetSegRegLower(struct SiS_Private *SiS_Pr, unsigned short value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001351 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
1353 value &= 0x00ff;
1354 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0xf0;
1355 temp |= (value >> 4);
1356 SiS_SetRegByte(SiS_Pr->SiS_P3cb, temp);
1357 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cd) & 0xf0;
1358 temp |= (value & 0x0f);
1359 SiS_SetRegByte(SiS_Pr->SiS_P3cd, temp);
1360}
1361
1362static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001363SiS_SetSegRegUpper(struct SiS_Private *SiS_Pr, unsigned short value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001365 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367 value &= 0x00ff;
1368 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0x0f;
1369 temp |= (value & 0xf0);
1370 SiS_SetRegByte(SiS_Pr->SiS_P3cb, temp);
1371 temp = SiS_GetRegByte(SiS_Pr->SiS_P3cd) & 0x0f;
1372 temp |= (value << 4);
1373 SiS_SetRegByte(SiS_Pr->SiS_P3cd, temp);
1374}
1375
1376static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001377SiS_SetSegmentReg(struct SiS_Private *SiS_Pr, unsigned short value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
1379 SiS_SetSegRegLower(SiS_Pr, value);
1380 SiS_SetSegRegUpper(SiS_Pr, value);
1381}
1382
1383static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001384SiS_ResetSegmentReg(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385{
1386 SiS_SetSegmentReg(SiS_Pr, 0);
1387}
1388
1389static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001390SiS_SetSegmentRegOver(struct SiS_Private *SiS_Pr, unsigned short value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001392 unsigned short temp = value >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
1394 temp &= 0x07;
1395 temp |= (temp << 4);
1396 SiS_SetReg(SiS_Pr->SiS_P3c4,0x1d,temp);
1397 SiS_SetSegmentReg(SiS_Pr, value);
1398}
1399
1400static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001401SiS_ResetSegmentRegOver(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402{
1403 SiS_SetSegmentRegOver(SiS_Pr, 0);
1404}
1405
1406static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001407SiS_ResetSegmentRegisters(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001409 if((IS_SIS65x) || (SiS_Pr->ChipType >= SIS_661)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 SiS_ResetSegmentReg(SiS_Pr);
1411 SiS_ResetSegmentRegOver(SiS_Pr);
1412 }
1413}
1414
1415/*********************************************/
1416/* HELPER: GetVBType */
1417/*********************************************/
1418
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001419static
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001420void
1421SiS_GetVBType(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001423 unsigned short flag = 0, rev = 0, nolcd = 0;
1424 unsigned short p4_0f, p4_25, p4_27;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001426 SiS_Pr->SiS_VBType = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001428 if((SiS_Pr->SiS_IF_DEF_LVDS) || (SiS_Pr->SiS_IF_DEF_CONEX))
1429 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001431 if(SiS_Pr->ChipType == XGI_20)
1432 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001434 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001436 if(flag > 3)
1437 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001439 rev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01);
1440
1441 if(flag >= 2) {
1442 SiS_Pr->SiS_VBType = VB_SIS302B;
1443 } else if(flag == 1) {
1444 if(rev >= 0xC0) {
1445 SiS_Pr->SiS_VBType = VB_SIS301C;
1446 } else if(rev >= 0xB0) {
1447 SiS_Pr->SiS_VBType = VB_SIS301B;
1448 /* Check if 30xB DH version (no LCD support, use Panel Link instead) */
1449 nolcd = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x23);
1450 if(!(nolcd & 0x02)) SiS_Pr->SiS_VBType |= VB_NoLCD;
1451 } else {
1452 SiS_Pr->SiS_VBType = VB_SIS301;
1453 }
1454 }
1455 if(SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS301C | VB_SIS302B)) {
1456 if(rev >= 0xE0) {
1457 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x39);
1458 if(flag == 0xff) SiS_Pr->SiS_VBType = VB_SIS302LV;
1459 else SiS_Pr->SiS_VBType = VB_SIS301C; /* VB_SIS302ELV; */
1460 } else if(rev >= 0xD0) {
1461 SiS_Pr->SiS_VBType = VB_SIS301LV;
1462 }
1463 }
1464 if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) {
1465 p4_0f = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x0f);
1466 p4_25 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x25);
1467 p4_27 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x27);
1468 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0x7f);
1469 SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x25,0x08);
1470 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,0xfd);
1471 if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x08) {
1472 SiS_Pr->SiS_VBType |= VB_UMC;
1473 }
1474 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x27,p4_27);
1475 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x25,p4_25);
1476 SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0f,p4_0f);
1477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478}
1479
1480/*********************************************/
1481/* HELPER: Check RAM size */
1482/*********************************************/
1483
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001484static bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001485SiS_CheckMemorySize(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1486 unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001488 unsigned short AdapterMemSize = SiS_Pr->VideoMemorySize / (1024*1024);
1489 unsigned short modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
1490 unsigned short memorysize = ((modeflag & MemoryInfoFlag) >> MemorySizeShift) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001492 if(!AdapterMemSize) return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001494 if(AdapterMemSize < memorysize) return false;
1495 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498/*********************************************/
1499/* HELPER: Get DRAM type */
1500/*********************************************/
1501
Aaro Koskinenf7854e52010-11-19 21:58:47 +00001502#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001503static unsigned char
1504SiS_Get310DRAMType(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001506 unsigned char data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
1508 if((*SiS_Pr->pSiS_SoftSetting) & SoftDRAMType) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001509 data = (*SiS_Pr->pSiS_SoftSetting) & 0x03;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001511 if(SiS_Pr->ChipType >= XGI_20) {
1512 /* Do I need this? SR17 seems to be zero anyway... */
1513 data = 0;
1514 } else if(SiS_Pr->ChipType >= SIS_340) {
1515 /* TODO */
1516 data = 0;
1517 } if(SiS_Pr->ChipType >= SIS_661) {
1518 if(SiS_Pr->SiS_ROMNew) {
1519 data = ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0xc0) >> 6);
1520 } else {
1521 data = SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0x07;
1522 }
1523 } else if(IS_SIS550650740) {
1524 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x07;
1525 } else { /* 315, 330 */
1526 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x03;
1527 if(SiS_Pr->ChipType == SIS_330) {
1528 if(data > 1) {
1529 switch(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0x30) {
1530 case 0x00: data = 1; break;
1531 case 0x10: data = 3; break;
1532 case 0x20: data = 3; break;
1533 case 0x30: data = 2; break;
1534 }
1535 } else {
1536 data = 0;
1537 }
1538 }
1539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 }
1541
1542 return data;
1543}
1544
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001545static unsigned short
1546SiS_GetMCLK(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001548 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1549 unsigned short index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001551 index = SiS_Get310DRAMType(SiS_Pr);
1552 if(SiS_Pr->ChipType >= SIS_661) {
1553 if(SiS_Pr->SiS_ROMNew) {
1554 return((unsigned short)(SISGETROMW((0x90 + (index * 5) + 3))));
1555 }
1556 return(SiS_Pr->SiS_MCLKData_0[index].CLOCK);
1557 } else if(index >= 4) {
1558 return(SiS_Pr->SiS_MCLKData_1[index - 4].CLOCK);
1559 } else {
1560 return(SiS_Pr->SiS_MCLKData_0[index].CLOCK);
1561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562}
1563#endif
1564
1565/*********************************************/
1566/* HELPER: ClearBuffer */
1567/*********************************************/
1568
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001570SiS_ClearBuffer(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001572 unsigned char SISIOMEMTYPE *memaddr = SiS_Pr->VideoMemoryAddress;
1573 unsigned int memsize = SiS_Pr->VideoMemorySize;
1574 unsigned short SISIOMEMTYPE *pBuffer;
1575 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001577 if(!memaddr || !memsize) return;
1578
1579 if(SiS_Pr->SiS_ModeType >= ModeEGA) {
1580 if(ModeNo > 0x13) {
Aaro Koskinenec49ec32010-11-19 21:58:49 +00001581 memset_io(memaddr, 0, memsize);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001582 } else {
1583 pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
1584 for(i = 0; i < 0x4000; i++) writew(0x0000, &pBuffer[i]);
1585 }
1586 } else if(SiS_Pr->SiS_ModeType < ModeCGA) {
1587 pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
1588 for(i = 0; i < 0x4000; i++) writew(0x0720, &pBuffer[i]);
1589 } else {
Aaro Koskinenec49ec32010-11-19 21:58:49 +00001590 memset_io(memaddr, 0, 0x8000);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
1594/*********************************************/
1595/* HELPER: SearchModeID */
1596/*********************************************/
1597
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001598bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001599SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
1600 unsigned short *ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001602 unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001604 if((*ModeNo) <= 0x13) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
1606 if((*ModeNo) <= 0x05) (*ModeNo) |= 0x01;
1607
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001608 for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
1609 if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == (*ModeNo)) break;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001610 if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == 0xFF) return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 }
1612
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001613 if((*ModeNo) == 0x07) {
1614 if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */
1615 /* else 350 lines */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001617 if((*ModeNo) <= 0x03) {
1618 if(!(VGAINFO & 0x80)) (*ModeIdIndex)++;
1619 if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */
1620 /* else 350 lines */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 }
1622 /* else 200 lines */
1623
1624 } else {
1625
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001626 for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
1627 if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == (*ModeNo)) break;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001628 if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == 0xFF) return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 }
1630
1631 }
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001632 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633}
1634
1635/*********************************************/
1636/* HELPER: GetModePtr */
1637/*********************************************/
1638
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001639unsigned short
1640SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001642 unsigned short index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
1644 if(ModeNo <= 0x13) {
1645 index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_StTableIndex;
1646 } else {
1647 if(SiS_Pr->SiS_ModeType <= ModeEGA) index = 0x1B;
1648 else index = 0x0F;
1649 }
1650 return index;
1651}
1652
1653/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001654/* HELPERS: Get some indices */
1655/*********************************************/
1656
1657unsigned short
1658SiS_GetRefCRTVCLK(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide)
1659{
1660 if(SiS_Pr->SiS_RefIndex[Index].Ext_InfoFlag & HaveWideTiming) {
1661 if(UseWide == 1) {
1662 return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK_WIDE;
1663 } else {
1664 return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK_NORM;
1665 }
1666 } else {
1667 return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK;
1668 }
1669}
1670
1671unsigned short
1672SiS_GetRefCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide)
1673{
1674 if(SiS_Pr->SiS_RefIndex[Index].Ext_InfoFlag & HaveWideTiming) {
1675 if(UseWide == 1) {
1676 return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC_WIDE;
1677 } else {
1678 return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC_NORM;
1679 }
1680 } else {
1681 return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC;
1682 }
1683}
1684
1685/*********************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686/* HELPER: LowModeTests */
1687/*********************************************/
1688
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001689static bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001690SiS_DoLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001692 unsigned short temp, temp1, temp2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001694 if((ModeNo != 0x03) && (ModeNo != 0x10) && (ModeNo != 0x12))
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001695 return true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001696 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x11);
1697 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x11,0x80);
1698 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00);
1699 SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,0x55);
1700 temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00);
1701 SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,temp1);
1702 SiS_SetReg(SiS_Pr->SiS_P3d4,0x11,temp);
1703 if((SiS_Pr->ChipType >= SIS_315H) ||
1704 (SiS_Pr->ChipType == SIS_300)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001705 if(temp2 == 0x55) return false;
1706 else return true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001707 } else {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001708 if(temp2 != 0x55) return true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001709 else {
1710 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001711 return false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001712 }
1713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714}
1715
1716static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001717SiS_SetLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001719 if(SiS_DoLowModeTest(SiS_Pr, ModeNo)) {
1720 SiS_Pr->SiS_SetFlag |= LowModeTests;
1721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
1723
1724/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001725/* HELPER: OPEN/CLOSE CRT1 CRTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726/*********************************************/
1727
1728static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001729SiS_OpenCRTC(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001731 if(IS_SIS650) {
1732 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f);
1733 if(IS_SIS651) SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x20);
1734 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7);
1735 } else if(IS_SIS661741660760) {
1736 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x61,0xf7);
1737 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f);
1738 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7);
1739 if(!SiS_Pr->SiS_ROMNew) {
1740 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x3a,0xef);
1741 }
1742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743}
1744
1745static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001746SiS_CloseCRTC(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001748#if 0 /* This locks some CRTC registers. We don't want that. */
1749 unsigned short temp1 = 0, temp2 = 0;
1750
1751 if(IS_SIS661741660760) {
1752 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
1753 temp1 = 0xa0; temp2 = 0x08;
1754 }
1755 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x51,0x1f,temp1);
1756 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x56,0xe7,temp2);
1757 }
1758#endif
1759}
1760
1761static void
1762SiS_HandleCRT1(struct SiS_Private *SiS_Pr)
1763{
1764 /* Enable CRT1 gating */
1765 SiS_SetRegAND(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0xbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766#if 0
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001767 if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x01)) {
1768 if((SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x0a) ||
1769 (SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x01)) {
1770 SiS_SetRegOR(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0x40);
1771 }
1772 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773#endif
1774}
1775
1776/*********************************************/
1777/* HELPER: GetColorDepth */
1778/*********************************************/
1779
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001780unsigned short
1781SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1782 unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001784 static const unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
1785 unsigned short modeflag;
1786 short index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001788 /* Do NOT check UseCustomMode, will skrew up FIFO */
1789 if(ModeNo == 0xfe) {
1790 modeflag = SiS_Pr->CModeFlag;
1791 } else if(ModeNo <= 0x13) {
1792 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
1793 } else {
1794 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1795 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001797 index = (modeflag & ModeTypeMask) - ModeEGA;
1798 if(index < 0) index = 0;
1799 return ColorDepth[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800}
1801
1802/*********************************************/
1803/* HELPER: GetOffset */
1804/*********************************************/
1805
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001806unsigned short
1807SiS_GetOffset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1808 unsigned short ModeIdIndex, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001810 unsigned short xres, temp, colordepth, infoflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001812 if(SiS_Pr->UseCustomMode) {
1813 infoflag = SiS_Pr->CInfoFlag;
1814 xres = SiS_Pr->CHDisplay;
1815 } else {
1816 infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
1817 xres = SiS_Pr->SiS_RefIndex[RRTI].XRes;
1818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001820 colordepth = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001822 temp = xres / 16;
1823 if(infoflag & InterlaceMode) temp <<= 1;
1824 temp *= colordepth;
1825 if(xres % 16) temp += (colordepth >> 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001827 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828}
1829
1830/*********************************************/
1831/* SEQ */
1832/*********************************************/
1833
1834static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001835SiS_SetSeqRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001837 unsigned char SRdata;
1838 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001840 SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001842 /* or "display off" */
1843 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[0] | 0x20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001845 /* determine whether to force x8 dotclock */
1846 if((SiS_Pr->SiS_VBType & VB_SISVB) || (SiS_Pr->SiS_IF_DEF_LVDS)) {
1847
1848 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
1849 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) SRdata |= 0x01;
1850 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) SRdata |= 0x01;
1851
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 }
1853
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 SiS_SetReg(SiS_Pr->SiS_P3c4,0x01,SRdata);
1855
1856 for(i = 2; i <= 4; i++) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001857 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[i - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 SiS_SetReg(SiS_Pr->SiS_P3c4,i,SRdata);
1859 }
1860}
1861
1862/*********************************************/
1863/* MISC */
1864/*********************************************/
1865
1866static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001867SiS_SetMiscRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001869 unsigned char Miscdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
1871 Miscdata = SiS_Pr->SiS_StandTable[StandTableIndex].MISC;
1872
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001873 if(SiS_Pr->ChipType < SIS_661) {
1874 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
1875 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
1876 Miscdata |= 0x0C;
1877 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 }
1879 }
1880
1881 SiS_SetRegByte(SiS_Pr->SiS_P3c2,Miscdata);
1882}
1883
1884/*********************************************/
1885/* CRTC */
1886/*********************************************/
1887
1888static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001889SiS_SetCRTCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001891 unsigned char CRTCdata;
1892 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001894 /* Unlock CRTC */
1895 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001897 for(i = 0; i <= 0x18; i++) {
1898 CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
1899 SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata);
1900 }
1901
1902 if(SiS_Pr->ChipType >= SIS_661) {
1903 SiS_OpenCRTC(SiS_Pr);
1904 for(i = 0x13; i <= 0x14; i++) {
1905 CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
1906 SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata);
1907 }
1908 } else if( ( (SiS_Pr->ChipType == SIS_630) ||
1909 (SiS_Pr->ChipType == SIS_730) ) &&
1910 (SiS_Pr->ChipRevision >= 0x30) ) {
1911 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
1912 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
1913 SiS_SetReg(SiS_Pr->SiS_P3d4,0x18,0xFE);
1914 }
1915 }
1916 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917}
1918
1919/*********************************************/
1920/* ATT */
1921/*********************************************/
1922
1923static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001924SiS_SetATTRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001926 unsigned char ARdata;
1927 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
1929 for(i = 0; i <= 0x13; i++) {
1930 ARdata = SiS_Pr->SiS_StandTable[StandTableIndex].ATTR[i];
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001931
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 if(i == 0x13) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001933 /* Pixel shift. If screen on LCD or TV is shifted left or right,
1934 * this might be the cause.
1935 */
1936 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
1937 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) ARdata = 0;
1938 }
1939 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
1940 if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
1941 if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
1942 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
1943 }
1944 }
1945 }
1946 if(SiS_Pr->ChipType >= SIS_661) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 if(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001948 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 }
1950 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001951 if(SiS_Pr->ChipType >= SIS_315H) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 if(IS_SIS550650740660) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001953 /* 315, 330 don't do this */
1954 if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
1955 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
1956 } else {
1957 ARdata = 0;
1958 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 }
1960 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001961 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001963 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001965 SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */
1966 SiS_SetRegByte(SiS_Pr->SiS_P3c0,i); /* set index */
1967 SiS_SetRegByte(SiS_Pr->SiS_P3c0,ARdata); /* set data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001969
1970 SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */
1971 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x14); /* set index */
1972 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x00); /* set data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
1974 SiS_GetRegByte(SiS_Pr->SiS_P3da);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001975 SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x20); /* Enable Attribute */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 SiS_GetRegByte(SiS_Pr->SiS_P3da);
1977}
1978
1979/*********************************************/
1980/* GRC */
1981/*********************************************/
1982
1983static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001984SiS_SetGRCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001986 unsigned char GRdata;
1987 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
1989 for(i = 0; i <= 0x08; i++) {
1990 GRdata = SiS_Pr->SiS_StandTable[StandTableIndex].GRC[i];
1991 SiS_SetReg(SiS_Pr->SiS_P3ce,i,GRdata);
1992 }
1993
1994 if(SiS_Pr->SiS_ModeType > ModeVGA) {
1995 /* 256 color disable */
1996 SiS_SetRegAND(SiS_Pr->SiS_P3ce,0x05,0xBF);
1997 }
1998}
1999
2000/*********************************************/
2001/* CLEAR EXTENDED REGISTERS */
2002/*********************************************/
2003
2004static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002005SiS_ClearExt1Regs(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002007 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002009 for(i = 0x0A; i <= 0x0E; i++) {
2010 SiS_SetReg(SiS_Pr->SiS_P3c4,i,0x00);
2011 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002013 if(SiS_Pr->ChipType >= SIS_315H) {
2014 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x37,0xFE);
2015 if(ModeNo <= 0x13) {
2016 if(ModeNo == 0x06 || ModeNo >= 0x0e) {
2017 SiS_SetReg(SiS_Pr->SiS_P3c4,0x0e,0x20);
2018 }
2019 }
2020 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021}
2022
2023/*********************************************/
2024/* RESET VCLK */
2025/*********************************************/
2026
2027static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002028SiS_ResetCRT1VCLK(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002030 if(SiS_Pr->ChipType >= SIS_315H) {
2031 if(SiS_Pr->ChipType < SIS_661) {
2032 if(SiS_Pr->SiS_IF_DEF_LVDS == 0) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 }
2034 } else {
2035 if((SiS_Pr->SiS_IF_DEF_LVDS == 0) &&
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002036 (!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 return;
2038 }
2039 }
2040
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002041 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xcf,0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[1].SR2B);
2043 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[1].SR2C);
2044 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002045 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xcf,0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[0].SR2B);
2047 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[0].SR2C);
2048 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
2049}
2050
2051/*********************************************/
2052/* SYNC */
2053/*********************************************/
2054
2055static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002056SiS_SetCRT1Sync(struct SiS_Private *SiS_Pr, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002058 unsigned short sync;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002060 if(SiS_Pr->UseCustomMode) {
2061 sync = SiS_Pr->CInfoFlag >> 8;
2062 } else {
2063 sync = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag >> 8;
2064 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002066 sync &= 0xC0;
2067 sync |= 0x2f;
2068 SiS_SetRegByte(SiS_Pr->SiS_P3c2,sync);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069}
2070
2071/*********************************************/
2072/* CRTC/2 */
2073/*********************************************/
2074
2075static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002076SiS_SetCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2077 unsigned short ModeIdIndex, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002079 unsigned short temp, i, j, modeflag;
2080 unsigned char *crt1data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002082 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002084 if(SiS_Pr->UseCustomMode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002086 crt1data = &SiS_Pr->CCRT1CRTC[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002088 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002090 temp = SiS_GetRefCRT1CRTC(SiS_Pr, RRTI, SiS_Pr->SiS_UseWide);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002092 /* Alternate for 1600x1200 LCDA */
2093 if((temp == 0x20) && (SiS_Pr->Alternate1600x1200)) temp = 0x57;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002095 crt1data = (unsigned char *)&SiS_Pr->SiS_CRT1Table[temp].CR[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002099 /* unlock cr0-7 */
2100 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002102 for(i = 0, j = 0; i <= 7; i++, j++) {
2103 SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
2104 }
2105 for(j = 0x10; i <= 10; i++, j++) {
2106 SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
2107 }
2108 for(j = 0x15; i <= 12; i++, j++) {
2109 SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
2110 }
2111 for(j = 0x0A; i <= 15; i++, j++) {
2112 SiS_SetReg(SiS_Pr->SiS_P3c4,j,crt1data[i]);
2113 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002115 SiS_SetReg(SiS_Pr->SiS_P3c4,0x0E,crt1data[16] & 0xE0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002117 temp = (crt1data[16] & 0x01) << 5;
2118 if(modeflag & DoubleScanMode) temp |= 0x80;
2119 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002121 if(SiS_Pr->SiS_ModeType > ModeVGA) {
2122 SiS_SetReg(SiS_Pr->SiS_P3d4,0x14,0x4F);
2123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002125#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002126 if(SiS_Pr->ChipType == XGI_20) {
2127 SiS_SetReg(SiS_Pr->SiS_P3d4,0x04,crt1data[4] - 1);
2128 if(!(temp = crt1data[5] & 0x1f)) {
2129 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x0c,0xfb);
2130 }
2131 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x05,0xe0,((temp - 1) & 0x1f));
2132 temp = (crt1data[16] >> 5) + 3;
2133 if(temp > 7) temp -= 7;
2134 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0e,0x1f,(temp << 5));
2135 }
2136#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137}
2138
2139/*********************************************/
2140/* OFFSET & PITCH */
2141/*********************************************/
2142/* (partly overruled by SetPitch() in XF86) */
2143/*********************************************/
2144
2145static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002146SiS_SetCRT1Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2147 unsigned short ModeIdIndex, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002149 unsigned short temp, DisplayUnit, infoflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
2151 if(SiS_Pr->UseCustomMode) {
2152 infoflag = SiS_Pr->CInfoFlag;
2153 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002154 infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 }
2156
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002157 DisplayUnit = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
2159 temp = (DisplayUnit >> 8) & 0x0f;
2160 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0xF0,temp);
2161
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002162 SiS_SetReg(SiS_Pr->SiS_P3d4,0x13,DisplayUnit & 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164 if(infoflag & InterlaceMode) DisplayUnit >>= 1;
2165
2166 DisplayUnit <<= 5;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002167 temp = (DisplayUnit >> 8) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 if(DisplayUnit & 0xff) temp++;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002169 if(SiS_Pr->ChipType == XGI_20) {
2170 if(ModeNo == 0x4a || ModeNo == 0x49) temp--;
2171 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 SiS_SetReg(SiS_Pr->SiS_P3c4,0x10,temp);
2173}
2174
2175/*********************************************/
2176/* VCLK */
2177/*********************************************/
2178
2179static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002180SiS_SetCRT1VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2181 unsigned short ModeIdIndex, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002183 unsigned short index = 0, clka, clkb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002185 if(SiS_Pr->UseCustomMode) {
2186 clka = SiS_Pr->CSR2B;
2187 clkb = SiS_Pr->CSR2C;
2188 } else {
2189 index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
2190 if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
2191 (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
2192 /* Alternate for 1600x1200 LCDA */
2193 if((index == 0x21) && (SiS_Pr->Alternate1600x1200)) index = 0x72;
2194 clka = SiS_Pr->SiS_VBVCLKData[index].Part4_A;
2195 clkb = SiS_Pr->SiS_VBVCLKData[index].Part4_B;
2196 } else {
2197 clka = SiS_Pr->SiS_VCLKData[index].SR2B;
2198 clkb = SiS_Pr->SiS_VCLKData[index].SR2C;
2199 }
2200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002202 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xCF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002204 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,clka);
2205 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002207 if(SiS_Pr->ChipType >= SIS_315H) {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002208#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002209 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x01);
2210 if(SiS_Pr->ChipType == XGI_20) {
2211 unsigned short mf = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
2212 if(mf & HalfDCLK) {
2213 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,SiS_GetReg(SiS_Pr->SiS_P3c4,0x2b));
2214 clkb = SiS_GetReg(SiS_Pr->SiS_P3c4,0x2c);
2215 clkb = (((clkb & 0x1f) << 1) + 1) | (clkb & 0xe0);
2216 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb);
2217 }
2218 }
2219#endif
2220 } else {
2221 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
2222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223}
2224
2225/*********************************************/
2226/* FIFO */
2227/*********************************************/
2228
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002229#ifdef CONFIG_FB_SIS_300
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002230void
2231SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *idx1,
2232 unsigned short *idx2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002234 unsigned short temp1, temp2;
2235 static const unsigned char ThTiming[8] = {
2236 1, 2, 2, 3, 0, 1, 1, 2
2237 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002239 temp1 = temp2 = (SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x62) >> 1;
2240 (*idx2) = (unsigned short)(ThTiming[((temp2 >> 3) | temp1) & 0x07]);
2241 (*idx1) = (unsigned short)(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) >> 6) & 0x03;
2242 (*idx1) |= (unsigned short)(((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 4) & 0x0c));
2243 (*idx1) <<= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244}
2245
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002246static unsigned short
2247SiS_GetFIFOThresholdA300(unsigned short idx1, unsigned short idx2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002249 static const unsigned char ThLowA[8 * 3] = {
2250 61, 3,52, 5,68, 7,100,11,
2251 43, 3,42, 5,54, 7, 78,11,
2252 34, 3,37, 5,47, 7, 67,11
2253 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002255 return (unsigned short)((ThLowA[idx1 + 1] * idx2) + ThLowA[idx1]);
2256}
2257
2258unsigned short
2259SiS_GetFIFOThresholdB300(unsigned short idx1, unsigned short idx2)
2260{
2261 static const unsigned char ThLowB[8 * 3] = {
2262 81, 4,72, 6,88, 8,120,12,
2263 55, 4,54, 6,66, 8, 90,12,
2264 42, 4,45, 6,55, 8, 75,12
2265 };
2266
2267 return (unsigned short)((ThLowB[idx1 + 1] * idx2) + ThLowB[idx1]);
2268}
2269
2270static unsigned short
2271SiS_DoCalcDelay(struct SiS_Private *SiS_Pr, unsigned short MCLK, unsigned short VCLK,
2272 unsigned short colordepth, unsigned short key)
2273{
2274 unsigned short idx1, idx2;
2275 unsigned int longtemp = VCLK * colordepth;
2276
2277 SiS_GetFIFOThresholdIndex300(SiS_Pr, &idx1, &idx2);
2278
2279 if(key == 0) {
2280 longtemp *= SiS_GetFIFOThresholdA300(idx1, idx2);
2281 } else {
2282 longtemp *= SiS_GetFIFOThresholdB300(idx1, idx2);
2283 }
2284 idx1 = longtemp % (MCLK * 16);
2285 longtemp /= (MCLK * 16);
2286 if(idx1) longtemp++;
2287 return (unsigned short)longtemp;
2288}
2289
2290static unsigned short
2291SiS_CalcDelay(struct SiS_Private *SiS_Pr, unsigned short VCLK,
2292 unsigned short colordepth, unsigned short MCLK)
2293{
2294 unsigned short temp1, temp2;
2295
2296 temp2 = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 0);
2297 temp1 = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 1);
2298 if(temp1 < 4) temp1 = 4;
2299 temp1 -= 4;
2300 if(temp2 < temp1) temp2 = temp1;
2301 return temp2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302}
2303
2304static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002305SiS_SetCRT1FIFO_300(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2306 unsigned short RefreshRateTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002308 unsigned short ThresholdLow = 0;
2309 unsigned short temp, index, VCLK, MCLK, colorth;
2310 static const unsigned short colortharray[6] = { 1, 1, 2, 2, 3, 4 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002312 if(ModeNo > 0x13) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002314 /* Get VCLK */
2315 if(SiS_Pr->UseCustomMode) {
2316 VCLK = SiS_Pr->CSRClock;
2317 } else {
2318 index = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWide);
2319 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
2320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002322 /* Get half colordepth */
2323 colorth = colortharray[(SiS_Pr->SiS_ModeType - ModeEGA)];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002325 /* Get MCLK */
2326 index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A) & 0x07;
2327 MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002329 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xc3;
2330 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3c,temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002332 do {
2333 ThresholdLow = SiS_CalcDelay(SiS_Pr, VCLK, colorth, MCLK) + 1;
2334 if(ThresholdLow < 0x13) break;
2335 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x16,0xfc);
2336 ThresholdLow = 0x13;
2337 temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) >> 6;
2338 if(!temp) break;
2339 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3f,((temp - 1) << 6));
2340 } while(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002342 } else ThresholdLow = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002344 /* Write CRT/CPU threshold low, CRT/Engine threshold high */
2345 temp = (ThresholdLow << 4) | 0x0f;
2346 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002348 temp = (ThresholdLow & 0x10) << 1;
2349 if(ModeNo > 0x13) temp |= 0x40;
2350 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0f,0x9f,temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002352 /* What is this? */
2353 SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002355 /* Write CRT/CPU threshold high */
2356 temp = ThresholdLow + 3;
2357 if(temp > 0x0f) temp = 0x0f;
2358 SiS_SetReg(SiS_Pr->SiS_P3c4,0x09,temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359}
2360
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002361unsigned short
2362SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002364 static const unsigned char LatencyFactor[] = {
2365 97, 88, 86, 79, 77, 0, /* 64 bit BQ=2 */
2366 0, 87, 85, 78, 76, 54, /* 64 bit BQ=1 */
2367 97, 88, 86, 79, 77, 0, /* 128 bit BQ=2 */
2368 0, 79, 77, 70, 68, 48, /* 128 bit BQ=1 */
2369 80, 72, 69, 63, 61, 0, /* 64 bit BQ=2 */
2370 0, 70, 68, 61, 59, 37, /* 64 bit BQ=1 */
2371 86, 77, 75, 68, 66, 0, /* 128 bit BQ=2 */
2372 0, 68, 66, 59, 57, 37 /* 128 bit BQ=1 */
2373 };
2374 static const unsigned char LatencyFactor730[] = {
2375 69, 63, 61,
2376 86, 79, 77,
2377 103, 96, 94,
2378 120,113,111,
2379 137,130,128
2380 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002382 if(SiS_Pr->ChipType == SIS_730) {
2383 return (unsigned short)LatencyFactor730[index];
2384 } else {
2385 return (unsigned short)LatencyFactor[index];
2386 }
2387}
2388
2389static unsigned short
2390SiS_CalcDelay2(struct SiS_Private *SiS_Pr, unsigned char key)
2391{
2392 unsigned short index;
2393
2394 if(SiS_Pr->ChipType == SIS_730) {
2395 index = ((key & 0x0f) * 3) + ((key & 0xc0) >> 6);
2396 } else {
2397 index = (key & 0xe0) >> 5;
2398 if(key & 0x10) index += 6;
2399 if(!(key & 0x01)) index += 24;
2400 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
2401 }
2402 return SiS_GetLatencyFactor630(SiS_Pr, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403}
2404
2405static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002406SiS_SetCRT1FIFO_630(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2407 unsigned short RefreshRateTableIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002409 unsigned short ThresholdLow = 0;
2410 unsigned short i, data, VCLK, MCLK16, colorth = 0;
2411 unsigned int templ, datal;
2412 const unsigned char *queuedata = NULL;
2413 static const unsigned char FQBQData[21] = {
2414 0x01,0x21,0x41,0x61,0x81,
2415 0x31,0x51,0x71,0x91,0xb1,
2416 0x00,0x20,0x40,0x60,0x80,
2417 0x30,0x50,0x70,0x90,0xb0,
2418 0xff
2419 };
2420 static const unsigned char FQBQData730[16] = {
2421 0x34,0x74,0xb4,
2422 0x23,0x63,0xa3,
2423 0x12,0x52,0x92,
2424 0x01,0x41,0x81,
2425 0x00,0x40,0x80,
2426 0xff
2427 };
2428 static const unsigned short colortharray[6] = {
2429 1, 1, 2, 2, 3, 4
2430 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002432 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002434 if(ModeNo > 0x13) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002436 /* Get VCLK */
2437 if(SiS_Pr->UseCustomMode) {
2438 VCLK = SiS_Pr->CSRClock;
2439 } else {
2440 data = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWide);
2441 VCLK = SiS_Pr->SiS_VCLKData[data].CLOCK;
2442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002444 /* Get MCLK * 16 */
2445 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A) & 0x07;
2446 MCLK16 = SiS_Pr->SiS_MCLKData_0[data].CLOCK * 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002448 /* Get half colordepth */
2449 colorth = colortharray[(SiS_Pr->SiS_ModeType - ModeEGA)];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002451 if(SiS_Pr->ChipType == SIS_730) {
2452 queuedata = &FQBQData730[0];
2453 } else {
2454 queuedata = &FQBQData[0];
2455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002457 do {
2458 templ = SiS_CalcDelay2(SiS_Pr, queuedata[i]) * VCLK * colorth;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002460 datal = templ % MCLK16;
2461 templ = (templ / MCLK16) + 1;
2462 if(datal) templ++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002464 if(templ > 0x13) {
2465 if(queuedata[i + 1] == 0xFF) {
2466 ThresholdLow = 0x13;
2467 break;
2468 }
2469 i++;
2470 } else {
2471 ThresholdLow = templ;
2472 break;
2473 }
2474 } while(queuedata[i] != 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002476 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002478 if(SiS_Pr->ChipType != SIS_730) i = 9;
2479 ThresholdLow = 0x02;
2480
2481 }
2482
2483 /* Write CRT/CPU threshold low, CRT/Engine threshold high */
2484 data = ((ThresholdLow & 0x0f) << 4) | 0x0f;
2485 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,data);
2486
2487 data = (ThresholdLow & 0x10) << 1;
2488 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xDF,data);
2489
2490 /* What is this? */
2491 SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
2492
2493 /* Write CRT/CPU threshold high (gap = 3) */
2494 data = ThresholdLow + 3;
2495 if(data > 0x0f) data = 0x0f;
2496 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x09,0x80,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
2498 /* Write foreground and background queue */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002499 templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002501 if(SiS_Pr->ChipType == SIS_730) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002503 templ &= 0xfffff9ff;
2504 templ |= ((queuedata[i] & 0xc0) << 3);
2505
2506 } else {
2507
2508 templ &= 0xf0ffffff;
2509 if( (ModeNo <= 0x13) &&
2510 (SiS_Pr->ChipType == SIS_630) &&
2511 (SiS_Pr->ChipRevision >= 0x30) ) {
2512 templ |= 0x0b000000;
2513 } else {
2514 templ |= ((queuedata[i] & 0xf0) << 20);
2515 }
2516
2517 }
2518
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002519 sisfb_write_nbridge_pci_dword(SiS_Pr, 0x50, templ);
2520 templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xA0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002522 /* GUI grant timer (PCI config 0xA3) */
2523 if(SiS_Pr->ChipType == SIS_730) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002525 templ &= 0x00ffffff;
2526 datal = queuedata[i] << 8;
2527 templ |= (((datal & 0x0f00) | ((datal & 0x3000) >> 8)) << 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002529 } else {
2530
2531 templ &= 0xf0ffffff;
2532 templ |= ((queuedata[i] & 0x0f) << 24);
2533
2534 }
2535
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002536 sisfb_write_nbridge_pci_dword(SiS_Pr, 0xA0, templ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537}
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002538#endif /* CONFIG_FB_SIS_300 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002540#ifdef CONFIG_FB_SIS_315
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002542SiS_SetCRT1FIFO_310(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002544 unsigned short modeflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002546 /* disable auto-threshold */
2547 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x3D,0xFE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002549 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002551 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0xAE);
2552 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x09,0xF0);
2553 if(ModeNo > 0x13) {
2554 if(SiS_Pr->ChipType >= XGI_20) {
2555 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
2556 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
2557 } else if(SiS_Pr->ChipType >= SIS_661) {
2558 if(!(modeflag & HalfDCLK)) {
2559 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
2560 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
2561 }
2562 } else {
2563 if((!(modeflag & DoubleScanMode)) || (!(modeflag & HalfDCLK))) {
2564 SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
2565 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
2566 }
2567 }
2568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569}
2570#endif
2571
2572/*********************************************/
2573/* MODE REGISTERS */
2574/*********************************************/
2575
2576static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002577SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2578 unsigned short RefreshRateTableIndex, unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002580 unsigned short data = 0, VCLK = 0, index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002582 if(ModeNo > 0x13) {
2583 if(SiS_Pr->UseCustomMode) {
2584 VCLK = SiS_Pr->CSRClock;
2585 } else {
2586 index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
2587 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
2588 }
2589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002591 if(SiS_Pr->ChipType < SIS_315H) {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002592#ifdef CONFIG_FB_SIS_300
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002593 if(VCLK > 150) data |= 0x80;
2594 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0x7B,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002596 data = 0x00;
2597 if(VCLK >= 150) data |= 0x08;
2598 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xF7,data);
2599#endif
2600 } else if(SiS_Pr->ChipType < XGI_20) {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002601#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002602 if(VCLK >= 166) data |= 0x0c;
2603 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002605 if(VCLK >= 166) {
2606 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1f,0xe7);
2607 }
2608#endif
2609 } else {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002610#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002611 if(VCLK >= 200) data |= 0x0c;
2612 if(SiS_Pr->ChipType == XGI_20) data &= ~0x04;
2613 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
2614 if(SiS_Pr->ChipType != XGI_20) {
2615 data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xe7;
2616 if(VCLK < 200) data |= 0x10;
2617 SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,data);
2618 }
2619#endif
2620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002622 /* DAC speed */
2623 if(SiS_Pr->ChipType >= SIS_661) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002625 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xE8,0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002627 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002629 data = 0x03;
2630 if(VCLK >= 260) data = 0x00;
2631 else if(VCLK >= 160) data = 0x01;
2632 else if(VCLK >= 135) data = 0x02;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002634 if(SiS_Pr->ChipType == SIS_540) {
2635 if((VCLK == 203) || (VCLK < 234)) data = 0x02;
2636 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002638 if(SiS_Pr->ChipType < SIS_315H) {
2639 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xFC,data);
2640 } else {
2641 if(SiS_Pr->ChipType > SIS_315PRO) {
2642 if(ModeNo > 0x13) data &= 0xfc;
2643 }
2644 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xF8,data);
2645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648}
2649
2650static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002651SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
2652 unsigned short ModeIdIndex, unsigned short RRTI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002654 unsigned short data, infoflag = 0, modeflag, resindex;
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002655#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002656 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
2657 unsigned short data2, data3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658#endif
2659
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002660 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002662 if(SiS_Pr->UseCustomMode) {
2663 infoflag = SiS_Pr->CInfoFlag;
2664 } else {
2665 resindex = SiS_GetResInfo(SiS_Pr, ModeNo, ModeIdIndex);
2666 if(ModeNo > 0x13) {
2667 infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
2668 }
2669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002671 /* Disable DPMS */
2672 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1F,0x3F);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002674 data = 0;
2675 if(ModeNo > 0x13) {
2676 if(SiS_Pr->SiS_ModeType > ModeEGA) {
2677 data |= 0x02;
2678 data |= ((SiS_Pr->SiS_ModeType - ModeVGA) << 2);
2679 }
2680 if(infoflag & InterlaceMode) data |= 0x20;
2681 }
2682 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x06,0xC0,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002684 if(SiS_Pr->ChipType != SIS_300) {
2685 data = 0;
2686 if(infoflag & InterlaceMode) {
2687 /* data = (Hsync / 8) - ((Htotal / 8) / 2) + 3 */
2688 int hrs = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x04) |
2689 ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2)) - 3;
2690 int hto = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x00) |
2691 ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0x03) << 8)) + 5;
2692 data = hrs - (hto >> 1) + 3;
2693 }
2694 SiS_SetReg(SiS_Pr->SiS_P3d4,0x19,data);
2695 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x1a,0xFC,((data >> 8) & 0x03));
2696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002698 if(modeflag & HalfDCLK) {
2699 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x08);
2700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002702 data = 0;
2703 if(modeflag & LineCompareOff) data = 0x08;
2704 if(SiS_Pr->ChipType == SIS_300) {
2705 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xF7,data);
2706 } else {
2707 if(SiS_Pr->ChipType >= XGI_20) data |= 0x20;
2708 if(SiS_Pr->SiS_ModeType == ModeEGA) {
2709 if(ModeNo > 0x13) {
2710 data |= 0x40;
2711 }
2712 }
2713 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xB7,data);
2714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002716#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002717 if(SiS_Pr->ChipType >= SIS_315H) {
2718 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xfb);
2719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002721 if(SiS_Pr->ChipType == SIS_315PRO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002723 data = SiS_Pr->SiS_SR15[(2 * 4) + SiS_Get310DRAMType(SiS_Pr)];
2724 if(SiS_Pr->SiS_ModeType == ModeText) {
2725 data &= 0xc7;
2726 } else {
2727 data2 = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RRTI) >> 1;
2728 if(infoflag & InterlaceMode) data2 >>= 1;
2729 data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
2730 if(data3) data2 /= data3;
2731 if(data2 >= 0x50) {
2732 data &= 0x0f;
2733 data |= 0x50;
2734 }
2735 }
2736 SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002738 } else if((SiS_Pr->ChipType == SIS_330) || (SiS_Pr->SiS_SysFlags & SF_760LFB)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002740 data = SiS_Get310DRAMType(SiS_Pr);
2741 if(SiS_Pr->ChipType == SIS_330) {
2742 data = SiS_Pr->SiS_SR15[(2 * 4) + data];
2743 } else {
2744 if(SiS_Pr->SiS_ROMNew) data = ROMAddr[0xf6];
2745 else if(SiS_Pr->SiS_UseROM) data = ROMAddr[0x100 + data];
2746 else data = 0xba;
2747 }
2748 if(SiS_Pr->SiS_ModeType <= ModeEGA) {
2749 data &= 0xc7;
2750 } else {
2751 if(SiS_Pr->UseCustomMode) {
2752 data2 = SiS_Pr->CSRClock;
2753 } else {
2754 data2 = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
2755 data2 = SiS_Pr->SiS_VCLKData[data2].CLOCK;
2756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002758 data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
2759 if(data3) data2 *= data3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002761 data2 = ((unsigned int)(SiS_GetMCLK(SiS_Pr) * 1024)) / data2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002763 if(SiS_Pr->ChipType == SIS_330) {
2764 if(SiS_Pr->SiS_ModeType != Mode16Bpp) {
2765 if (data2 >= 0x19c) data = 0xba;
2766 else if(data2 >= 0x140) data = 0x7a;
2767 else if(data2 >= 0x101) data = 0x3a;
2768 else if(data2 >= 0xf5) data = 0x32;
2769 else if(data2 >= 0xe2) data = 0x2a;
2770 else if(data2 >= 0xc4) data = 0x22;
2771 else if(data2 >= 0xac) data = 0x1a;
2772 else if(data2 >= 0x9e) data = 0x12;
2773 else if(data2 >= 0x8e) data = 0x0a;
2774 else data = 0x02;
2775 } else {
2776 if(data2 >= 0x127) data = 0xba;
2777 else data = 0x7a;
2778 }
2779 } else { /* 76x+LFB */
2780 if (data2 >= 0x190) data = 0xba;
2781 else if(data2 >= 0xff) data = 0x7a;
2782 else if(data2 >= 0xd3) data = 0x3a;
2783 else if(data2 >= 0xa9) data = 0x1a;
2784 else if(data2 >= 0x93) data = 0x0a;
2785 else data = 0x02;
2786 }
2787 }
2788 SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
2789
2790 }
2791 /* XGI: Nothing. */
2792 /* TODO: Check SiS340 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793#endif
2794
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002795 data = 0x60;
2796 if(SiS_Pr->SiS_ModeType != ModeText) {
2797 data ^= 0x60;
2798 if(SiS_Pr->SiS_ModeType != ModeEGA) {
2799 data ^= 0xA0;
2800 }
2801 }
2802 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x21,0x1F,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002804 SiS_SetVCLKState(SiS_Pr, ModeNo, RRTI, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002806#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002807 if(((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) ||
2808 (SiS_Pr->ChipType == XGI_40)) {
2809 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
2810 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x2c);
2811 } else {
2812 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x6c);
2813 }
2814 } else if(SiS_Pr->ChipType == XGI_20) {
2815 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
2816 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x33);
2817 } else {
2818 SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x73);
2819 }
2820 SiS_SetReg(SiS_Pr->SiS_P3d4,0x51,0x02);
2821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822#endif
2823}
2824
Aaro Koskinenf7854e52010-11-19 21:58:47 +00002825#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002826static void
2827SiS_SetupDualChip(struct SiS_Private *SiS_Pr)
2828{
2829#if 0
2830 /* TODO: Find out about IOAddress2 */
2831 SISIOADDRESS P2_3c2 = SiS_Pr->IOAddress2 + 0x12;
2832 SISIOADDRESS P2_3c4 = SiS_Pr->IOAddress2 + 0x14;
2833 SISIOADDRESS P2_3ce = SiS_Pr->IOAddress2 + 0x1e;
2834 int i;
2835
2836 if((SiS_Pr->ChipRevision != 0) ||
2837 (!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x04)))
2838 return;
2839
2840 for(i = 0; i <= 4; i++) { /* SR00 - SR04 */
2841 SiS_SetReg(P2_3c4,i,SiS_GetReg(SiS_Pr->SiS_P3c4,i));
2842 }
2843 for(i = 0; i <= 8; i++) { /* GR00 - GR08 */
2844 SiS_SetReg(P2_3ce,i,SiS_GetReg(SiS_Pr->SiS_P3ce,i));
2845 }
2846 SiS_SetReg(P2_3c4,0x05,0x86);
2847 SiS_SetReg(P2_3c4,0x06,SiS_GetReg(SiS_Pr->SiS_P3c4,0x06)); /* SR06 */
2848 SiS_SetReg(P2_3c4,0x21,SiS_GetReg(SiS_Pr->SiS_P3c4,0x21)); /* SR21 */
2849 SiS_SetRegByte(P2_3c2,SiS_GetRegByte(SiS_Pr->SiS_P3cc)); /* MISC */
2850 SiS_SetReg(P2_3c4,0x05,0x00);
2851#endif
2852}
2853#endif
2854
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855/*********************************************/
2856/* LOAD DAC */
2857/*********************************************/
2858
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002860SiS_WriteDAC(struct SiS_Private *SiS_Pr, SISIOADDRESS DACData, unsigned short shiftflag,
2861 unsigned short dl, unsigned short ah, unsigned short al, unsigned short dh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002863 unsigned short d1, d2, d3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002865 switch(dl) {
2866 case 0: d1 = dh; d2 = ah; d3 = al; break;
2867 case 1: d1 = ah; d2 = al; d3 = dh; break;
2868 default: d1 = al; d2 = dh; d3 = ah;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002870 SiS_SetRegByte(DACData, (d1 << shiftflag));
2871 SiS_SetRegByte(DACData, (d2 << shiftflag));
2872 SiS_SetRegByte(DACData, (d3 << shiftflag));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873}
2874
2875void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002876SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002878 unsigned short data, data2, time, i, j, k, m, n, o;
2879 unsigned short si, di, bx, sf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 SISIOADDRESS DACAddr, DACData;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002881 const unsigned char *table = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002883 data = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex) & DACInfoFlag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002885 j = time = 64;
2886 if(data == 0x00) table = SiS_MDA_DAC;
2887 else if(data == 0x08) table = SiS_CGA_DAC;
2888 else if(data == 0x10) table = SiS_EGA_DAC;
2889 else if(data == 0x18) {
2890 j = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 time = 256;
2892 table = SiS_VGA_DAC;
2893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894
2895 if( ( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && /* 301B-DH LCD */
2896 (SiS_Pr->SiS_VBType & VB_NoLCD) ) ||
2897 (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) || /* LCDA */
2898 (!(SiS_Pr->SiS_SetFlag & ProgrammingCRT2)) ) { /* Programming CRT1 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002899 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 DACAddr = SiS_Pr->SiS_P3c8;
2901 DACData = SiS_Pr->SiS_P3c9;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002902 sf = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 DACAddr = SiS_Pr->SiS_Part5Port;
2905 DACData = SiS_Pr->SiS_Part5Port + 1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002906 sf = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 }
2908
2909 SiS_SetRegByte(DACAddr,0x00);
2910
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002911 for(i = 0; i < j; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 data = table[i];
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002913 for(k = 0; k < 3; k++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 data2 = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002915 if(data & 0x01) data2 += 0x2A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 if(data & 0x02) data2 += 0x15;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002917 SiS_SetRegByte(DACData, (data2 << sf));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 data >>= 2;
2919 }
2920 }
2921
2922 if(time == 256) {
2923 for(i = 16; i < 32; i++) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002924 data = table[i] << sf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 for(k = 0; k < 3; k++) SiS_SetRegByte(DACData, data);
2926 }
2927 si = 32;
2928 for(m = 0; m < 9; m++) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002929 di = si;
2930 bx = si + 4;
2931 for(n = 0; n < 3; n++) {
2932 for(o = 0; o < 5; o++) {
2933 SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[bx], table[si]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 si++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 }
2936 si -= 2;
2937 for(o = 0; o < 3; o++) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002938 SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[si], table[bx]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 si--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 } /* for n < 3 */
2942 si += 5;
2943 } /* for m < 9 */
2944 }
2945}
2946
2947/*********************************************/
2948/* SET CRT1 REGISTER GROUP */
2949/*********************************************/
2950
2951static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002952SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002954 unsigned short StandTableIndex, RefreshRateTableIndex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002956 SiS_Pr->SiS_CRT1Mode = ModeNo;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002958 StandTableIndex = SiS_GetModePtr(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002960 if(SiS_Pr->SiS_SetFlag & LowModeTests) {
2961 if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2)) {
2962 SiS_DisableBridge(SiS_Pr);
2963 }
2964 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002966 SiS_ResetSegmentRegisters(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002968 SiS_SetSeqRegs(SiS_Pr, StandTableIndex);
2969 SiS_SetMiscRegs(SiS_Pr, StandTableIndex);
2970 SiS_SetCRTCRegs(SiS_Pr, StandTableIndex);
2971 SiS_SetATTRegs(SiS_Pr, StandTableIndex);
2972 SiS_SetGRCRegs(SiS_Pr, StandTableIndex);
2973 SiS_ClearExt1Regs(SiS_Pr, ModeNo);
2974 SiS_ResetCRT1VCLK(SiS_Pr);
2975
2976 SiS_Pr->SiS_SelectCRT2Rate = 0;
2977 SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
2978
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002979 if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
2980 if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
2981 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
2982 }
2983 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002985 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
2986 SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
2987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002989 RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002991 if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
2992 SiS_Pr->SiS_SetFlag &= ~ProgrammingCRT2;
2993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002995 if(RefreshRateTableIndex != 0xFFFF) {
2996 SiS_SetCRT1Sync(SiS_Pr, RefreshRateTableIndex);
2997 SiS_SetCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
2998 SiS_SetCRT1Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
2999 SiS_SetCRT1VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3000 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003002 switch(SiS_Pr->ChipType) {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003003#ifdef CONFIG_FB_SIS_300
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003004 case SIS_300:
3005 SiS_SetCRT1FIFO_300(SiS_Pr, ModeNo, RefreshRateTableIndex);
3006 break;
3007 case SIS_540:
3008 case SIS_630:
3009 case SIS_730:
3010 SiS_SetCRT1FIFO_630(SiS_Pr, ModeNo, RefreshRateTableIndex);
3011 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003013 default:
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003014#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003015 if(SiS_Pr->ChipType == XGI_20) {
3016 unsigned char sr2b = 0, sr2c = 0;
3017 switch(ModeNo) {
3018 case 0x00:
3019 case 0x01: sr2b = 0x4e; sr2c = 0xe9; break;
3020 case 0x04:
3021 case 0x05:
3022 case 0x0d: sr2b = 0x1b; sr2c = 0xe3; break;
3023 }
3024 if(sr2b) {
3025 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,sr2b);
3026 SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,sr2c);
3027 SiS_SetRegByte(SiS_Pr->SiS_P3c2,(SiS_GetRegByte(SiS_Pr->SiS_P3cc) | 0x0c));
3028 }
3029 }
3030 SiS_SetCRT1FIFO_310(SiS_Pr, ModeNo, ModeIdIndex);
3031#endif
3032 break;
3033 }
3034
3035 SiS_SetCRT1ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
3036
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003037#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003038 if(SiS_Pr->ChipType == XGI_40) {
3039 SiS_SetupDualChip(SiS_Pr);
3040 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041#endif
3042
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003043 SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003045 if(SiS_Pr->SiS_flag_clearbuffer) {
3046 SiS_ClearBuffer(SiS_Pr, ModeNo);
3047 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003049 if(!(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA))) {
3050 SiS_WaitRetrace1(SiS_Pr);
3051 SiS_DisplayOn(SiS_Pr);
3052 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053}
3054
3055/*********************************************/
3056/* HELPER: VIDEO BRIDGE PROG CLK */
3057/*********************************************/
3058
3059static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003060SiS_InitVB(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003062 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003064 SiS_Pr->Init_P4_0E = 0;
3065 if(SiS_Pr->SiS_ROMNew) {
3066 SiS_Pr->Init_P4_0E = ROMAddr[0x82];
3067 } else if(SiS_Pr->ChipType >= XGI_40) {
3068 if(SiS_Pr->SiS_XGIROM) {
3069 SiS_Pr->Init_P4_0E = ROMAddr[0x80];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 }
3071 }
3072}
3073
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003074static void
3075SiS_ResetVB(struct SiS_Private *SiS_Pr)
3076{
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003077#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003078 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
3079 unsigned short temp;
3080
3081 /* VB programming clock */
3082 if(SiS_Pr->SiS_UseROM) {
3083 if(SiS_Pr->ChipType < SIS_330) {
3084 temp = ROMAddr[VB310Data_1_2_Offset] | 0x40;
3085 if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
3086 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
3087 } else if(SiS_Pr->ChipType >= SIS_661 && SiS_Pr->ChipType < XGI_20) {
3088 temp = ROMAddr[0x7e] | 0x40;
3089 if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
3090 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
3091 }
3092 } else if(SiS_Pr->ChipType >= XGI_40) {
3093 temp = 0x40;
3094 if(SiS_Pr->SiS_XGIROM) temp |= ROMAddr[0x7e];
3095 /* Can we do this on any chipset? */
3096 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
3097 }
3098#endif
3099}
3100
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003102/* HELPER: SET VIDEO/CAPTURE REGISTERS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103/*********************************************/
3104
3105static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003106SiS_StrangeStuff(struct SiS_Private *SiS_Pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003108 /* SiS65x and XGI set up some sort of "lock mode" for text
3109 * which locks CRT2 in some way to CRT1 timing. Disable
3110 * this here.
3111 */
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003112#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003113 if((IS_SIS651) || (IS_SISM650) ||
3114 SiS_Pr->ChipType == SIS_340 ||
3115 SiS_Pr->ChipType == XGI_40) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x3f, 0x00); /* Fiddle with capture regs */
3117 SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x00, 0x00);
3118 SiS_SetReg(SiS_Pr->SiS_VidPlay, 0x00, 0x86); /* (BIOS does NOT unlock) */
3119 SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x30, 0xfe); /* Fiddle with video regs */
3120 SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x3f, 0xef);
3121 }
3122 /* !!! This does not support modes < 0x13 !!! */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003123#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124}
3125
3126/*********************************************/
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003127/* HELPER: SET AGP TIMING FOR SiS760 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128/*********************************************/
3129
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003131SiS_Handle760(struct SiS_Private *SiS_Pr)
3132{
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003133#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003134 unsigned int somebase;
3135 unsigned char temp1, temp2, temp3;
3136
3137 if( (SiS_Pr->ChipType != SIS_760) ||
3138 ((SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5c) & 0xf8) != 0x80) ||
3139 (!(SiS_Pr->SiS_SysFlags & SF_760LFB)) ||
3140 (!(SiS_Pr->SiS_SysFlags & SF_760UMA)) )
3141 return;
3142
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003143 somebase = sisfb_read_mio_pci_word(SiS_Pr, 0x74);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003144 somebase &= 0xffff;
3145
3146 if(somebase == 0) return;
3147
3148 temp3 = SiS_GetRegByte((somebase + 0x85)) & 0xb7;
3149
3150 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
3151 temp1 = 0x21;
3152 temp2 = 0x03;
3153 temp3 |= 0x08;
3154 } else {
3155 temp1 = 0x25;
3156 temp2 = 0x0b;
3157 }
3158
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003159 sisfb_write_nbridge_pci_byte(SiS_Pr, 0x7e, temp1);
3160 sisfb_write_nbridge_pci_byte(SiS_Pr, 0x8d, temp2);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003161
3162 SiS_SetRegByte((somebase + 0x85), temp3);
3163#endif
3164}
3165
3166/*********************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167/* SiSSetMode() */
3168/*********************************************/
3169
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003170bool
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003171SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003173 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
3174 unsigned short RealModeNo, ModeIdIndex;
3175 unsigned char backupreg = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003176 unsigned short KeepLockReg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003178 SiS_Pr->UseCustomMode = false;
3179 SiS_Pr->CRT1UsesCustomMode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 SiS_Pr->SiS_flag_clearbuffer = 0;
3182
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003183 if(SiS_Pr->UseCustomMode) {
3184 ModeNo = 0xfe;
3185 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 if(!(ModeNo & 0x80)) SiS_Pr->SiS_flag_clearbuffer = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 ModeNo &= 0x7f;
3188 }
3189
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003190 /* Don't use FSTN mode for CRT1 */
3191 RealModeNo = ModeNo;
3192 if(ModeNo == 0x5b) ModeNo = 0x56;
3193
3194 SiSInitPtr(SiS_Pr);
3195 SiSRegInit(SiS_Pr, BaseAddr);
3196 SiS_GetSysFlags(SiS_Pr);
3197
3198 SiS_Pr->SiS_VGAINFO = 0x11;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003199
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 KeepLockReg = SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
3202
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003203 SiSInitPCIetc(SiS_Pr);
3204 SiSSetLVDSetc(SiS_Pr);
3205 SiSDetermineROMUsage(SiS_Pr);
3206
3207 SiS_UnLockCRT2(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208
3209 if(!SiS_Pr->UseCustomMode) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003210 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 } else {
3212 ModeIdIndex = 0;
3213 }
3214
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003215 SiS_GetVBType(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216
3217 /* Init/restore some VB registers */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003218 SiS_InitVB(SiS_Pr);
3219 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3220 if(SiS_Pr->ChipType >= SIS_315H) {
3221 SiS_ResetVB(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10);
3223 SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x00,0x0c);
3224 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
3225 } else {
3226 backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
3227 }
3228 }
3229
3230 /* Get VB information (connectors, connected devices) */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003231 SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, (SiS_Pr->UseCustomMode) ? 0 : 1);
3232 SiS_SetYPbPr(SiS_Pr);
3233 SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
3234 SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
3235 SiS_SetLowModeTest(SiS_Pr, ModeNo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003237 /* Check memory size (kernel framebuffer driver only) */
3238 if(!SiS_CheckMemorySize(SiS_Pr, ModeNo, ModeIdIndex)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003239 return false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003242 SiS_OpenCRTC(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
3244 if(SiS_Pr->UseCustomMode) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003245 SiS_Pr->CRT1UsesCustomMode = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 SiS_Pr->CSRClock_CRT1 = SiS_Pr->CSRClock;
3247 SiS_Pr->CModeFlag_CRT1 = SiS_Pr->CModeFlag;
3248 } else {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003249 SiS_Pr->CRT1UsesCustomMode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 }
3251
3252 /* Set mode on CRT1 */
3253 if( (SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) ||
3254 (!(SiS_Pr->SiS_VBInfo & SwitchCRT2)) ) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003255 SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 }
3257
3258 /* Set mode on CRT2 */
3259 if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA)) {
3260 if( (SiS_Pr->SiS_VBType & VB_SISVB) ||
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003261 (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
3262 (SiS_Pr->SiS_IF_DEF_CH70xx != 0) ||
3263 (SiS_Pr->SiS_IF_DEF_TRUMPION != 0) ) {
3264 SiS_SetCRT2Group(SiS_Pr, RealModeNo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 }
3266 }
3267
3268 SiS_HandleCRT1(SiS_Pr);
3269
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003270 SiS_StrangeStuff(SiS_Pr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271
3272 SiS_DisplayOn(SiS_Pr);
3273 SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
3274
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003275#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003276 if(SiS_Pr->ChipType >= SIS_315H) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003278 if(!(SiS_IsDualEdge(SiS_Pr))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
3280 }
3281 }
3282 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003283#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003285 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
3286 if(SiS_Pr->ChipType >= SIS_315H) {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003287#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003288 if(!SiS_Pr->SiS_ROMNew) {
3289 if(SiS_IsVAMode(SiS_Pr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
3291 } else {
3292 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0xFE);
3293 }
3294 }
3295
3296 SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupreg);
3297
3298 if((IS_SIS650) && (SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0xfc)) {
3299 if((ModeNo == 0x03) || (ModeNo == 0x10)) {
3300 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x80);
3301 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x56,0x08);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 }
3304
3305 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) {
3306 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
3307 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003308#endif
3309 } else if((SiS_Pr->ChipType == SIS_630) ||
3310 (SiS_Pr->ChipType == SIS_730)) {
3311 SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 }
3313 }
3314
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003315 SiS_CloseCRTC(SiS_Pr);
3316
3317 SiS_Handle760(SiS_Pr);
3318
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003319 /* We never lock registers in XF86 */
3320 if(KeepLockReg != 0xA1) SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003322 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323}
3324
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325#ifndef GETBITSTR
3326#define BITMASK(h,l) (((unsigned)(1U << ((h)-(l)+1))-1)<<(l))
3327#define GENMASK(mask) BITMASK(1?mask,0?mask)
3328#define GETBITS(var,mask) (((var) & GENMASK(mask)) >> (0?mask))
3329#define GETBITSTR(val,from,to) ((GETBITS(val,from)) << (0?to))
3330#endif
3331
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003332void
3333SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003335 int x = 1; /* Fix sync */
3336
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 SiS_Pr->CCRT1CRTC[0] = ((SiS_Pr->CHTotal >> 3) - 5) & 0xff; /* CR0 */
3338 SiS_Pr->CCRT1CRTC[1] = (SiS_Pr->CHDisplay >> 3) - 1; /* CR1 */
3339 SiS_Pr->CCRT1CRTC[2] = (SiS_Pr->CHBlankStart >> 3) - 1; /* CR2 */
3340 SiS_Pr->CCRT1CRTC[3] = (((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x1F) | 0x80; /* CR3 */
3341 SiS_Pr->CCRT1CRTC[4] = (SiS_Pr->CHSyncStart >> 3) + 3; /* CR4 */
3342 SiS_Pr->CCRT1CRTC[5] = ((((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x20) << 2) | /* CR5 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003343 (((SiS_Pr->CHSyncEnd >> 3) + 3) & 0x1F);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003345 SiS_Pr->CCRT1CRTC[6] = (SiS_Pr->CVTotal - 2) & 0xFF; /* CR6 */
3346 SiS_Pr->CCRT1CRTC[7] = (((SiS_Pr->CVTotal - 2) & 0x100) >> 8) /* CR7 */
3347 | (((SiS_Pr->CVDisplay - 1) & 0x100) >> 7)
3348 | (((SiS_Pr->CVSyncStart - x) & 0x100) >> 6)
3349 | (((SiS_Pr->CVBlankStart- 1) & 0x100) >> 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 | 0x10
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003351 | (((SiS_Pr->CVTotal - 2) & 0x200) >> 4)
3352 | (((SiS_Pr->CVDisplay - 1) & 0x200) >> 3)
3353 | (((SiS_Pr->CVSyncStart - x) & 0x200) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354
3355 SiS_Pr->CCRT1CRTC[16] = ((((SiS_Pr->CVBlankStart - 1) & 0x200) >> 4) >> 5); /* CR9 */
3356
3357 if(depth != 8) {
3358 if(SiS_Pr->CHDisplay >= 1600) SiS_Pr->CCRT1CRTC[16] |= 0x60; /* SRE */
3359 else if(SiS_Pr->CHDisplay >= 640) SiS_Pr->CCRT1CRTC[16] |= 0x40;
3360 }
3361
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003362 SiS_Pr->CCRT1CRTC[8] = (SiS_Pr->CVSyncStart - x) & 0xFF; /* CR10 */
3363 SiS_Pr->CCRT1CRTC[9] = ((SiS_Pr->CVSyncEnd - x) & 0x0F) | 0x80; /* CR11 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 SiS_Pr->CCRT1CRTC[10] = (SiS_Pr->CVDisplay - 1) & 0xFF; /* CR12 */
3365 SiS_Pr->CCRT1CRTC[11] = (SiS_Pr->CVBlankStart - 1) & 0xFF; /* CR15 */
3366 SiS_Pr->CCRT1CRTC[12] = (SiS_Pr->CVBlankEnd - 1) & 0xFF; /* CR16 */
3367
3368 SiS_Pr->CCRT1CRTC[13] = /* SRA */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003369 GETBITSTR((SiS_Pr->CVTotal -2), 10:10, 0:0) |
3370 GETBITSTR((SiS_Pr->CVDisplay -1), 10:10, 1:1) |
3371 GETBITSTR((SiS_Pr->CVBlankStart-1), 10:10, 2:2) |
3372 GETBITSTR((SiS_Pr->CVSyncStart -x), 10:10, 3:3) |
3373 GETBITSTR((SiS_Pr->CVBlankEnd -1), 8:8, 4:4) |
3374 GETBITSTR((SiS_Pr->CVSyncEnd ), 4:4, 5:5) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375
3376 SiS_Pr->CCRT1CRTC[14] = /* SRB */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003377 GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9:8, 1:0) |
3378 GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9:8, 3:2) |
3379 GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9:8, 5:4) |
3380 GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9:8, 7:6) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381
3382
3383 SiS_Pr->CCRT1CRTC[15] = /* SRC */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003384 GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7:6, 1:0) |
3385 GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5:5, 2:2) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386}
3387
3388void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003389SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
3390 unsigned short ModeIdIndex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003392 unsigned short modeflag, tempax, tempbx = 0, remaining = 0;
3393 unsigned short VGAHDE = SiS_Pr->SiS_VGAHDE;
3394 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
3396 /* 1:1 data: use data set by setcrt1crtc() */
3397 if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
3398
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003399 modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400
3401 if(modeflag & HalfDCLK) VGAHDE >>= 1;
3402
3403 SiS_Pr->CHDisplay = VGAHDE;
3404 SiS_Pr->CHBlankStart = VGAHDE;
3405
3406 SiS_Pr->CVDisplay = SiS_Pr->SiS_VGAVDE;
3407 SiS_Pr->CVBlankStart = SiS_Pr->SiS_VGAVDE;
3408
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003409 if(SiS_Pr->ChipType < SIS_315H) {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003410#ifdef CONFIG_FB_SIS_300
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003411 tempbx = SiS_Pr->SiS_VGAHT;
3412 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3413 tempbx = SiS_Pr->PanelHT;
3414 }
3415 if(modeflag & HalfDCLK) tempbx >>= 1;
3416 remaining = tempbx % 8;
3417#endif
3418 } else {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003419#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003420 /* OK for LCDA, LVDS */
3421 tempbx = SiS_Pr->PanelHT - SiS_Pr->PanelXRes;
3422 tempax = SiS_Pr->SiS_VGAHDE; /* not /2 ! */
3423 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3424 tempax = SiS_Pr->PanelXRes;
3425 }
3426 tempbx += tempax;
3427 if(modeflag & HalfDCLK) tempbx -= VGAHDE;
3428#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 SiS_Pr->CHTotal = SiS_Pr->CHBlankEnd = tempbx;
3431
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003432 if(SiS_Pr->ChipType < SIS_315H) {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003433#ifdef CONFIG_FB_SIS_300
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003434 if(SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) {
3435 SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE + ((SiS_Pr->PanelHRS + 1) & ~1);
3436 SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + SiS_Pr->PanelHRE;
3437 if(modeflag & HalfDCLK) {
3438 SiS_Pr->CHSyncStart >>= 1;
3439 SiS_Pr->CHSyncEnd >>= 1;
3440 }
3441 } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3442 tempax = (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) >> 1;
3443 tempbx = (SiS_Pr->PanelHRS + 1) & ~1;
3444 if(modeflag & HalfDCLK) {
3445 tempax >>= 1;
3446 tempbx >>= 1;
3447 }
3448 SiS_Pr->CHSyncStart = (VGAHDE + tempax + tempbx + 7) & ~7;
3449 tempax = SiS_Pr->PanelHRE + 7;
3450 if(modeflag & HalfDCLK) tempax >>= 1;
3451 SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + tempax) & ~7;
3452 } else {
3453 SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE;
3454 if(modeflag & HalfDCLK) {
3455 SiS_Pr->CHSyncStart >>= 1;
3456 tempax = ((SiS_Pr->CHTotal - SiS_Pr->CHSyncStart) / 3) << 1;
3457 SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + tempax;
3458 } else {
3459 SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + (SiS_Pr->CHTotal / 10) + 7) & ~7;
3460 SiS_Pr->CHSyncStart += 8;
3461 }
3462 }
3463#endif
3464 } else {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003465#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003466 tempax = VGAHDE;
3467 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3468 tempbx = SiS_Pr->PanelXRes;
3469 if(modeflag & HalfDCLK) tempbx >>= 1;
3470 tempax += ((tempbx - tempax) >> 1);
3471 }
3472 tempax += SiS_Pr->PanelHRS;
3473 SiS_Pr->CHSyncStart = tempax;
3474 tempax += SiS_Pr->PanelHRE;
3475 SiS_Pr->CHSyncEnd = tempax;
3476#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 }
3478
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 tempbx = SiS_Pr->PanelVT - SiS_Pr->PanelYRes;
3480 tempax = SiS_Pr->SiS_VGAVDE;
3481 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3482 tempax = SiS_Pr->PanelYRes;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003483 } else if(SiS_Pr->ChipType < SIS_315H) {
Aaro Koskinenf7854e52010-11-19 21:58:47 +00003484#ifdef CONFIG_FB_SIS_300
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003485 /* Stupid hack for 640x400/320x200 */
3486 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
3487 if((tempax + tempbx) == 438) tempbx += 16;
3488 } else if((SiS_Pr->SiS_LCDResInfo == Panel_800x600) ||
3489 (SiS_Pr->SiS_LCDResInfo == Panel_1024x600)) {
3490 tempax = 0;
3491 tempbx = SiS_Pr->SiS_VGAVT;
3492 }
3493#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 }
3495 SiS_Pr->CVTotal = SiS_Pr->CVBlankEnd = tempbx + tempax;
3496
3497 tempax = SiS_Pr->SiS_VGAVDE;
3498 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
3499 tempax += (SiS_Pr->PanelYRes - tempax) >> 1;
3500 }
3501 tempax += SiS_Pr->PanelVRS;
3502 SiS_Pr->CVSyncStart = tempax;
3503 tempax += SiS_Pr->PanelVRE;
3504 SiS_Pr->CVSyncEnd = tempax;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003505 if(SiS_Pr->ChipType < SIS_315H) {
3506 SiS_Pr->CVSyncStart--;
3507 SiS_Pr->CVSyncEnd--;
3508 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509
3510 SiS_CalcCRRegisters(SiS_Pr, 8);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003511 SiS_Pr->CCRT1CRTC[15] &= ~0xF8;
3512 SiS_Pr->CCRT1CRTC[15] |= (remaining << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
3514
3515 SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
3516
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003517 for(i = 0, j = 0; i <= 7; i++, j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
3519 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003520 for(j = 0x10; i <= 10; i++, j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
3522 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003523 for(j = 0x15; i <= 12; i++, j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
3525 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003526 for(j = 0x0A; i <= 15; i++, j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 SiS_SetReg(SiS_Pr->SiS_P3c4,j,SiS_Pr->CCRT1CRTC[i]);
3528 }
3529
3530 tempax = SiS_Pr->CCRT1CRTC[16] & 0xE0;
3531 SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1F,tempax);
3532
3533 tempax = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
3534 if(modeflag & DoubleScanMode) tempax |= 0x80;
3535 SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,tempax);
3536
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537}
3538
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003540SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
3541 int xres, int yres,
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003542 struct fb_var_screeninfo *var, bool writeres
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 unsigned short HRE, HBE, HRS, HBS, HDE, HT;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003546 unsigned short VRE, VBE, VRS, VBS, VDE, VT;
3547 unsigned char sr_data, cr_data, cr_data2;
3548 int A, B, C, D, E, F, temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003550 sr_data = crdata[14];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003552 /* Horizontal total */
3553 HT = crdata[0] | ((unsigned short)(sr_data & 0x03) << 8);
3554 A = HT + 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003556 /* Horizontal display enable end */
3557 HDE = crdata[1] | ((unsigned short)(sr_data & 0x0C) << 6);
3558 E = HDE + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003560 /* Horizontal retrace (=sync) start */
3561 HRS = crdata[4] | ((unsigned short)(sr_data & 0xC0) << 2);
3562 F = HRS - E - 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003564 /* Horizontal blank start */
3565 HBS = crdata[2] | ((unsigned short)(sr_data & 0x30) << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003567 sr_data = crdata[15];
3568 cr_data = crdata[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003570 /* Horizontal blank end */
3571 HBE = (crdata[3] & 0x1f) |
3572 ((unsigned short)(cr_data & 0x80) >> 2) |
3573 ((unsigned short)(sr_data & 0x03) << 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003575 /* Horizontal retrace (=sync) end */
3576 HRE = (cr_data & 0x1f) | ((sr_data & 0x04) << 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003578 temp = HBE - ((E - 1) & 255);
3579 B = (temp > 0) ? temp : (temp + 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003581 temp = HRE - ((E + F + 3) & 63);
3582 C = (temp > 0) ? temp : (temp + 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003584 D = B - F - C;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003586 if(writeres) var->xres = xres = E * 8;
3587 var->left_margin = D * 8;
3588 var->right_margin = F * 8;
3589 var->hsync_len = C * 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003591 /* Vertical */
3592 sr_data = crdata[13];
3593 cr_data = crdata[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003595 /* Vertical total */
3596 VT = crdata[6] |
3597 ((unsigned short)(cr_data & 0x01) << 8) |
3598 ((unsigned short)(cr_data & 0x20) << 4) |
3599 ((unsigned short)(sr_data & 0x01) << 10);
3600 A = VT + 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003602 /* Vertical display enable end */
3603 VDE = crdata[10] |
3604 ((unsigned short)(cr_data & 0x02) << 7) |
3605 ((unsigned short)(cr_data & 0x40) << 3) |
3606 ((unsigned short)(sr_data & 0x02) << 9);
3607 E = VDE + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003609 /* Vertical retrace (=sync) start */
3610 VRS = crdata[8] |
3611 ((unsigned short)(cr_data & 0x04) << 6) |
3612 ((unsigned short)(cr_data & 0x80) << 2) |
3613 ((unsigned short)(sr_data & 0x08) << 7);
3614 F = VRS + 1 - E;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003616 cr_data2 = (crdata[16] & 0x01) << 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003618 /* Vertical blank start */
3619 VBS = crdata[11] |
3620 ((unsigned short)(cr_data & 0x08) << 5) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 ((unsigned short)(cr_data2 & 0x20) << 4) |
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003622 ((unsigned short)(sr_data & 0x04) << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003624 /* Vertical blank end */
3625 VBE = crdata[12] | ((unsigned short)(sr_data & 0x10) << 4);
3626 temp = VBE - ((E - 1) & 511);
3627 B = (temp > 0) ? temp : (temp + 512);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003629 /* Vertical retrace (=sync) end */
3630 VRE = (crdata[9] & 0x0f) | ((sr_data & 0x20) >> 1);
3631 temp = VRE - ((E + F - 1) & 31);
3632 C = (temp > 0) ? temp : (temp + 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003634 D = B - F - C;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003636 if(writeres) var->yres = yres = E;
3637 var->upper_margin = D;
3638 var->lower_margin = F;
3639 var->vsync_len = C;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003640
3641 if((xres == 320) && ((yres == 200) || (yres == 240))) {
3642 /* Terrible hack, but correct CRTC data for
3643 * these modes only produces a black screen...
3644 * (HRE is 0, leading into a too large C and
3645 * a negative D. The CRT controller does not
3646 * seem to like correcting HRE to 50)
3647 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003648 var->left_margin = (400 - 376);
3649 var->right_margin = (328 - 320);
3650 var->hsync_len = (376 - 328);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003651
3652 }
3653
3654}
3655
3656
3657
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658