blob: 7e3370f115b6cdba3259b9a5bfd516cc10b3709f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002 * SiS 300/540/630[S]/730[S],
3 * SiS 315[E|PRO]/550/[M]65x/[M]66x[F|M|G]X/[M]74x[GX]/330/[M]76x[GX],
4 * XGI V3XT/V5/V8, Z7
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
6 *
Thomas Winischhofer544393f2005-09-09 13:04:45 -07007 * Copyright (C) 2001-2005 Thomas Winischhofer, Vienna, Austria.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the named License,
12 * or any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
22 *
Thomas Winischhofer544393f2005-09-09 13:04:45 -070023 * Author: Thomas Winischhofer <thomas@winischhofer.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
25 * Author of (practically wiped) code base:
26 * SiS (www.sis.com)
Thomas Winischhofer544393f2005-09-09 13:04:45 -070027 * Copyright (C) 1999 Silicon Integrated Systems, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 *
29 * See http://www.winischhofer.net/ for more information and updates
30 *
31 * Originally based on the VBE 2.0 compliant graphic boards framebuffer driver,
32 * which is (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
33 *
34 */
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/spinlock.h>
40#include <linux/errno.h>
41#include <linux/string.h>
42#include <linux/mm.h>
Jon Smirla8f340e2006-07-10 04:44:12 -070043#include <linux/screen_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/fb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/selection.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/ioport.h>
48#include <linux/init.h>
49#include <linux/pci.h>
50#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/capability.h>
52#include <linux/fs.h>
53#include <linux/types.h>
Krzysztof Helt84902b72007-10-16 01:29:04 -070054#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <asm/io.h>
56#ifdef CONFIG_MTRR
57#include <asm/mtrr.h>
58#endif
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include "sis.h"
61#include "sis_main.h"
62
Aaro Koskinen1f8e6ee2010-11-19 21:58:50 +000063#if !defined(CONFIG_FB_SIS_300) && !defined(CONFIG_FB_SIS_315)
64#warning Neither CONFIG_FB_SIS_300 nor CONFIG_FB_SIS_315 is set
65#warning sisfb will not work!
66#endif
67
Thomas Winischhofer544393f2005-09-09 13:04:45 -070068static void sisfb_handle_command(struct sis_video_info *ivideo,
69 struct sisfb_cmd *sisfb_command);
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* ------------------ Internal helper routines ----------------- */
72
73static void __init
74sisfb_setdefaultparms(void)
75{
Thomas Winischhofer544393f2005-09-09 13:04:45 -070076 sisfb_off = 0;
77 sisfb_parm_mem = 0;
78 sisfb_accel = -1;
79 sisfb_ypan = -1;
80 sisfb_max = -1;
81 sisfb_userom = -1;
82 sisfb_useoem = -1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -070083 sisfb_mode_idx = -1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -070084 sisfb_parm_rate = -1;
85 sisfb_crt1off = 0;
86 sisfb_forcecrt1 = -1;
87 sisfb_crt2type = -1;
88 sisfb_crt2flags = 0;
89 sisfb_pdc = 0xff;
90 sisfb_pdca = 0xff;
91 sisfb_scalelcd = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 sisfb_specialtiming = CUT_NONE;
Thomas Winischhofer544393f2005-09-09 13:04:45 -070093 sisfb_lvdshl = -1;
94 sisfb_dstn = 0;
95 sisfb_fstn = 0;
96 sisfb_tvplug = -1;
97 sisfb_tvstd = -1;
98 sisfb_tvxposoffset = 0;
99 sisfb_tvyposoffset = 0;
100 sisfb_nocrt2rate = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#if !defined(__i386__) && !defined(__x86_64__)
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700102 sisfb_resetcard = 0;
103 sisfb_videoram = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#endif
105}
106
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700107/* ------------- Parameter parsing -------------- */
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static void __devinit
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800110sisfb_search_vesamode(unsigned int vesamode, bool quiet)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 int i = 0, j = 0;
113
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700114 /* We don't know the hardware specs yet and there is no ivideo */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 if(vesamode == 0) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700117 if(!quiet)
118 printk(KERN_ERR "sisfb: Invalid mode. Using default.\n");
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 sisfb_mode_idx = DEFAULT_MODE;
Michal Piotrowski43704092006-10-03 01:15:00 -0700121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return;
123 }
124
125 vesamode &= 0x1dff; /* Clean VESA mode number from other flags */
126
127 while(sisbios_mode[i++].mode_no[0] != 0) {
128 if( (sisbios_mode[i-1].vesa_mode_no_1 == vesamode) ||
129 (sisbios_mode[i-1].vesa_mode_no_2 == vesamode) ) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700130 if(sisfb_fstn) {
131 if(sisbios_mode[i-1].mode_no[1] == 0x50 ||
132 sisbios_mode[i-1].mode_no[1] == 0x56 ||
133 sisbios_mode[i-1].mode_no[1] == 0x53)
134 continue;
135 } else {
136 if(sisbios_mode[i-1].mode_no[1] == 0x5a ||
137 sisbios_mode[i-1].mode_no[1] == 0x5b)
138 continue;
139 }
140 sisfb_mode_idx = i - 1;
141 j = 1;
142 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
144 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700145 if((!j) && !quiet)
146 printk(KERN_ERR "sisfb: Invalid VESA mode 0x%x'\n", vesamode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700149static void __devinit
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800150sisfb_search_mode(char *name, bool quiet)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 unsigned int j = 0, xres = 0, yres = 0, depth = 0, rate = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700153 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 char strbuf[16], strbuf1[20];
155 char *nameptr = name;
156
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700157 /* We don't know the hardware specs yet and there is no ivideo */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 if(name == NULL) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700160 if(!quiet)
161 printk(KERN_ERR "sisfb: Internal error, using default mode.\n");
162
163 sisfb_mode_idx = DEFAULT_MODE;
164 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700167 if(!strnicmp(name, sisbios_mode[MODE_INDEX_NONE].name, strlen(name))) {
168 if(!quiet)
169 printk(KERN_ERR "sisfb: Mode 'none' not supported anymore. Using default.\n");
170
171 sisfb_mode_idx = DEFAULT_MODE;
172 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
Michal Piotrowski43704092006-10-03 01:15:00 -0700174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 if(strlen(name) <= 19) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700176 strcpy(strbuf1, name);
177 for(i = 0; i < strlen(strbuf1); i++) {
178 if(strbuf1[i] < '0' || strbuf1[i] > '9') strbuf1[i] = ' ';
179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700181 /* This does some fuzzy mode naming detection */
182 if(sscanf(strbuf1, "%u %u %u %u", &xres, &yres, &depth, &rate) == 4) {
183 if((rate <= 32) || (depth > 32)) {
184 j = rate; rate = depth; depth = j;
185 }
186 sprintf(strbuf, "%ux%ux%u", xres, yres, depth);
187 nameptr = strbuf;
188 sisfb_parm_rate = rate;
189 } else if(sscanf(strbuf1, "%u %u %u", &xres, &yres, &depth) == 3) {
190 sprintf(strbuf, "%ux%ux%u", xres, yres, depth);
191 nameptr = strbuf;
192 } else {
193 xres = 0;
194 if((sscanf(strbuf1, "%u %u", &xres, &yres) == 2) && (xres != 0)) {
195 sprintf(strbuf, "%ux%ux8", xres, yres);
196 nameptr = strbuf;
197 } else {
198 sisfb_search_vesamode(simple_strtoul(name, NULL, 0), quiet);
199 return;
200 }
201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
203
204 i = 0; j = 0;
205 while(sisbios_mode[i].mode_no[0] != 0) {
206 if(!strnicmp(nameptr, sisbios_mode[i++].name, strlen(nameptr))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700207 if(sisfb_fstn) {
208 if(sisbios_mode[i-1].mode_no[1] == 0x50 ||
209 sisbios_mode[i-1].mode_no[1] == 0x56 ||
210 sisbios_mode[i-1].mode_no[1] == 0x53)
211 continue;
212 } else {
213 if(sisbios_mode[i-1].mode_no[1] == 0x5a ||
214 sisbios_mode[i-1].mode_no[1] == 0x5b)
215 continue;
216 }
217 sisfb_mode_idx = i - 1;
218 j = 1;
219 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 }
221 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700222
223 if((!j) && !quiet)
224 printk(KERN_ERR "sisfb: Invalid mode '%s'\n", nameptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
227#ifndef MODULE
228static void __devinit
229sisfb_get_vga_mode_from_kernel(void)
230{
Adrian Bunk31c5cdb2006-06-26 00:26:28 -0700231#ifdef CONFIG_X86
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700232 char mymode[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 int mydepth = screen_info.lfb_depth;
234
235 if(screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) return;
236
237 if( (screen_info.lfb_width >= 320) && (screen_info.lfb_width <= 2048) &&
238 (screen_info.lfb_height >= 200) && (screen_info.lfb_height <= 1536) &&
239 (mydepth >= 8) && (mydepth <= 32) ) {
240
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700241 if(mydepth == 24) mydepth = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700243 sprintf(mymode, "%ux%ux%u", screen_info.lfb_width,
244 screen_info.lfb_height,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 mydepth);
246
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700247 printk(KERN_DEBUG
248 "sisfb: Using vga mode %s pre-set by kernel as default\n",
249 mymode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800251 sisfb_search_mode(mymode, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 }
253#endif
254 return;
255}
256#endif
257
258static void __init
259sisfb_search_crt2type(const char *name)
260{
261 int i = 0;
262
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700263 /* We don't know the hardware specs yet and there is no ivideo */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 if(name == NULL) return;
266
267 while(sis_crt2type[i].type_no != -1) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700268 if(!strnicmp(name, sis_crt2type[i].name, strlen(sis_crt2type[i].name))) {
269 sisfb_crt2type = sis_crt2type[i].type_no;
270 sisfb_tvplug = sis_crt2type[i].tvplug_no;
271 sisfb_crt2flags = sis_crt2type[i].flags;
272 break;
273 }
274 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276
277 sisfb_dstn = (sisfb_crt2flags & FL_550_DSTN) ? 1 : 0;
278 sisfb_fstn = (sisfb_crt2flags & FL_550_FSTN) ? 1 : 0;
279
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700280 if(sisfb_crt2type < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 printk(KERN_ERR "sisfb: Invalid CRT2 type: %s\n", name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
284static void __init
285sisfb_search_tvstd(const char *name)
286{
287 int i = 0;
288
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700289 /* We don't know the hardware specs yet and there is no ivideo */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700291 if(name == NULL)
292 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 while(sis_tvtype[i].type_no != -1) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700295 if(!strnicmp(name, sis_tvtype[i].name, strlen(sis_tvtype[i].name))) {
296 sisfb_tvstd = sis_tvtype[i].type_no;
297 break;
298 }
299 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
301}
302
303static void __init
304sisfb_search_specialtiming(const char *name)
305{
306 int i = 0;
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800307 bool found = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700309 /* We don't know the hardware specs yet and there is no ivideo */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700311 if(name == NULL)
312 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 if(!strnicmp(name, "none", 4)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700315 sisfb_specialtiming = CUT_FORCENONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 printk(KERN_DEBUG "sisfb: Special timing disabled\n");
317 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700318 while(mycustomttable[i].chipID != 0) {
319 if(!strnicmp(name,mycustomttable[i].optionName,
320 strlen(mycustomttable[i].optionName))) {
321 sisfb_specialtiming = mycustomttable[i].SpecialID;
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800322 found = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700323 printk(KERN_INFO "sisfb: Special timing for %s %s forced (\"%s\")\n",
324 mycustomttable[i].vendorName,
325 mycustomttable[i].cardName,
326 mycustomttable[i].optionName);
327 break;
328 }
329 i++;
330 }
331 if(!found) {
332 printk(KERN_WARNING "sisfb: Invalid SpecialTiming parameter, valid are:");
333 printk(KERN_WARNING "\t\"none\" (to disable special timings)\n");
334 i = 0;
335 while(mycustomttable[i].chipID != 0) {
336 printk(KERN_WARNING "\t\"%s\" (for %s %s)\n",
337 mycustomttable[i].optionName,
338 mycustomttable[i].vendorName,
339 mycustomttable[i].cardName);
340 i++;
341 }
342 }
343 }
344}
345
346/* ----------- Various detection routines ----------- */
347
348static void __devinit
349sisfb_detect_custom_timing(struct sis_video_info *ivideo)
350{
351 unsigned char *biosver = NULL;
352 unsigned char *biosdate = NULL;
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800353 bool footprint;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700354 u32 chksum = 0;
355 int i, j;
356
357 if(ivideo->SiS_Pr.UseROM) {
358 biosver = ivideo->SiS_Pr.VirtualRomBase + 0x06;
359 biosdate = ivideo->SiS_Pr.VirtualRomBase + 0x2c;
360 for(i = 0; i < 32768; i++)
361 chksum += ivideo->SiS_Pr.VirtualRomBase[i];
362 }
363
364 i = 0;
365 do {
366 if( (mycustomttable[i].chipID == ivideo->chip) &&
367 ((!strlen(mycustomttable[i].biosversion)) ||
368 (ivideo->SiS_Pr.UseROM &&
369 (!strncmp(mycustomttable[i].biosversion, biosver,
370 strlen(mycustomttable[i].biosversion))))) &&
371 ((!strlen(mycustomttable[i].biosdate)) ||
372 (ivideo->SiS_Pr.UseROM &&
373 (!strncmp(mycustomttable[i].biosdate, biosdate,
374 strlen(mycustomttable[i].biosdate))))) &&
375 ((!mycustomttable[i].bioschksum) ||
376 (ivideo->SiS_Pr.UseROM &&
377 (mycustomttable[i].bioschksum == chksum))) &&
378 (mycustomttable[i].pcisubsysvendor == ivideo->subsysvendor) &&
379 (mycustomttable[i].pcisubsyscard == ivideo->subsysdevice) ) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800380 footprint = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700381 for(j = 0; j < 5; j++) {
382 if(mycustomttable[i].biosFootprintAddr[j]) {
383 if(ivideo->SiS_Pr.UseROM) {
384 if(ivideo->SiS_Pr.VirtualRomBase[mycustomttable[i].biosFootprintAddr[j]] !=
385 mycustomttable[i].biosFootprintData[j]) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800386 footprint = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700387 }
388 } else
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800389 footprint = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700390 }
391 }
392 if(footprint) {
393 ivideo->SiS_Pr.SiS_CustomT = mycustomttable[i].SpecialID;
394 printk(KERN_DEBUG "sisfb: Identified [%s %s], special timing applies\n",
395 mycustomttable[i].vendorName,
396 mycustomttable[i].cardName);
397 printk(KERN_DEBUG "sisfb: [specialtiming parameter name: %s]\n",
398 mycustomttable[i].optionName);
399 break;
400 }
401 }
402 i++;
403 } while(mycustomttable[i].chipID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404}
405
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800406static bool __devinit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer)
408{
409 int i, j, xres, yres, refresh, index;
410 u32 emodes;
411
412 if(buffer[0] != 0x00 || buffer[1] != 0xff ||
413 buffer[2] != 0xff || buffer[3] != 0xff ||
414 buffer[4] != 0xff || buffer[5] != 0xff ||
415 buffer[6] != 0xff || buffer[7] != 0x00) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700416 printk(KERN_DEBUG "sisfb: Bad EDID header\n");
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800417 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
419
420 if(buffer[0x12] != 0x01) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700421 printk(KERN_INFO "sisfb: EDID version %d not supported\n",
422 buffer[0x12]);
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800423 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
425
426 monitor->feature = buffer[0x18];
427
Alexey Dobriyaneaa0ff12008-02-06 01:36:06 -0800428 if(!(buffer[0x14] & 0x80)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700429 if(!(buffer[0x14] & 0x08)) {
430 printk(KERN_INFO
431 "sisfb: WARNING: Monitor does not support separate syncs\n");
432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 }
434
435 if(buffer[0x13] >= 0x01) {
436 /* EDID V1 rev 1 and 2: Search for monitor descriptor
437 * to extract ranges
438 */
439 j = 0x36;
440 for(i=0; i<4; i++) {
441 if(buffer[j] == 0x00 && buffer[j + 1] == 0x00 &&
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700442 buffer[j + 2] == 0x00 && buffer[j + 3] == 0xfd &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 buffer[j + 4] == 0x00) {
444 monitor->hmin = buffer[j + 7];
445 monitor->hmax = buffer[j + 8];
446 monitor->vmin = buffer[j + 5];
447 monitor->vmax = buffer[j + 6];
448 monitor->dclockmax = buffer[j + 9] * 10 * 1000;
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800449 monitor->datavalid = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 break;
451 }
452 j += 18;
453 }
454 }
455
456 if(!monitor->datavalid) {
457 /* Otherwise: Get a range from the list of supported
458 * Estabished Timings. This is not entirely accurate,
459 * because fixed frequency monitors are not supported
460 * that way.
461 */
462 monitor->hmin = 65535; monitor->hmax = 0;
463 monitor->vmin = 65535; monitor->vmax = 0;
464 monitor->dclockmax = 0;
465 emodes = buffer[0x23] | (buffer[0x24] << 8) | (buffer[0x25] << 16);
466 for(i = 0; i < 13; i++) {
467 if(emodes & sisfb_ddcsmodes[i].mask) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700468 if(monitor->hmin > sisfb_ddcsmodes[i].h) monitor->hmin = sisfb_ddcsmodes[i].h;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 if(monitor->hmax < sisfb_ddcsmodes[i].h) monitor->hmax = sisfb_ddcsmodes[i].h + 1;
470 if(monitor->vmin > sisfb_ddcsmodes[i].v) monitor->vmin = sisfb_ddcsmodes[i].v;
471 if(monitor->vmax < sisfb_ddcsmodes[i].v) monitor->vmax = sisfb_ddcsmodes[i].v;
472 if(monitor->dclockmax < sisfb_ddcsmodes[i].d) monitor->dclockmax = sisfb_ddcsmodes[i].d;
473 }
474 }
475 index = 0x26;
476 for(i = 0; i < 8; i++) {
477 xres = (buffer[index] + 31) * 8;
478 switch(buffer[index + 1] & 0xc0) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700479 case 0xc0: yres = (xres * 9) / 16; break;
480 case 0x80: yres = (xres * 4) / 5; break;
481 case 0x40: yres = (xres * 3) / 4; break;
482 default: yres = xres; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 }
484 refresh = (buffer[index + 1] & 0x3f) + 60;
485 if((xres >= 640) && (yres >= 480)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700486 for(j = 0; j < 8; j++) {
487 if((xres == sisfb_ddcfmodes[j].x) &&
488 (yres == sisfb_ddcfmodes[j].y) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 (refresh == sisfb_ddcfmodes[j].v)) {
490 if(monitor->hmin > sisfb_ddcfmodes[j].h) monitor->hmin = sisfb_ddcfmodes[j].h;
491 if(monitor->hmax < sisfb_ddcfmodes[j].h) monitor->hmax = sisfb_ddcfmodes[j].h + 1;
492 if(monitor->vmin > sisfb_ddcsmodes[j].v) monitor->vmin = sisfb_ddcsmodes[j].v;
493 if(monitor->vmax < sisfb_ddcsmodes[j].v) monitor->vmax = sisfb_ddcsmodes[j].v;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700494 if(monitor->dclockmax < sisfb_ddcsmodes[j].d) monitor->dclockmax = sisfb_ddcsmodes[j].d;
495 }
496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498 index += 2;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 if((monitor->hmin <= monitor->hmax) && (monitor->vmin <= monitor->vmax)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800501 monitor->datavalid = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503 }
504
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700505 return monitor->datavalid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506}
507
508static void __devinit
509sisfb_handle_ddc(struct sis_video_info *ivideo, struct sisfb_monitor *monitor, int crtno)
510{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700511 unsigned short temp, i, realcrtno = crtno;
512 unsigned char buffer[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800514 monitor->datavalid = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 if(crtno) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700517 if(ivideo->vbflags & CRT2_LCD) realcrtno = 1;
518 else if(ivideo->vbflags & CRT2_VGA) realcrtno = 2;
519 else return;
520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700522 if((ivideo->sisfb_crt1off) && (!crtno))
523 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700525 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine,
526 realcrtno, 0, &buffer[0], ivideo->vbflags2);
527 if((!temp) || (temp == 0xffff)) {
528 printk(KERN_INFO "sisfb: CRT%d DDC probing failed\n", crtno + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 return;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700530 } else {
531 printk(KERN_INFO "sisfb: CRT%d DDC supported\n", crtno + 1);
532 printk(KERN_INFO "sisfb: CRT%d DDC level: %s%s%s%s\n",
533 crtno + 1,
534 (temp & 0x1a) ? "" : "[none of the supported]",
535 (temp & 0x02) ? "2 " : "",
536 (temp & 0x08) ? "D&P" : "",
537 (temp & 0x10) ? "FPDI-2" : "");
538 if(temp & 0x02) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 i = 3; /* Number of retrys */
540 do {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700541 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine,
542 realcrtno, 1, &buffer[0], ivideo->vbflags2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 } while((temp) && i--);
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700544 if(!temp) {
545 if(sisfb_interpret_edid(monitor, &buffer[0])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 printk(KERN_INFO "sisfb: Monitor range H %d-%dKHz, V %d-%dHz, Max. dotclock %dMHz\n",
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700547 monitor->hmin, monitor->hmax, monitor->vmin, monitor->vmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 monitor->dclockmax / 1000);
549 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700550 printk(KERN_INFO "sisfb: CRT%d DDC EDID corrupt\n", crtno + 1);
551 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700553 printk(KERN_INFO "sisfb: CRT%d DDC reading failed\n", crtno + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 }
555 } else {
556 printk(KERN_INFO "sisfb: VESA D&P and FPDI-2 not supported yet\n");
557 }
558 }
559}
560
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700561/* -------------- Mode validation --------------- */
562
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800563static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564sisfb_verify_rate(struct sis_video_info *ivideo, struct sisfb_monitor *monitor,
565 int mode_idx, int rate_idx, int rate)
566{
567 int htotal, vtotal;
568 unsigned int dclock, hsync;
569
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700570 if(!monitor->datavalid)
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800571 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700573 if(mode_idx < 0)
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800574 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 /* Skip for 320x200, 320x240, 640x400 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700577 switch(sisbios_mode[mode_idx].mode_no[ivideo->mni]) {
578 case 0x59:
579 case 0x41:
580 case 0x4f:
581 case 0x50:
582 case 0x56:
583 case 0x53:
584 case 0x2f:
585 case 0x5d:
586 case 0x5e:
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800587 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#ifdef CONFIG_FB_SIS_315
589 case 0x5a:
590 case 0x5b:
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800591 if(ivideo->sisvga_engine == SIS_315_VGA) return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700593 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700595 if(rate < (monitor->vmin - 1))
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800596 return false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700597 if(rate > (monitor->vmax + 1))
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800598 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700600 if(sisfb_gettotalfrommode(&ivideo->SiS_Pr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 sisbios_mode[mode_idx].mode_no[ivideo->mni],
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700602 &htotal, &vtotal, rate_idx)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 dclock = (htotal * vtotal * rate) / 1000;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700604 if(dclock > (monitor->dclockmax + 1000))
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800605 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 hsync = dclock / htotal;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700607 if(hsync < (monitor->hmin - 1))
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800608 return false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700609 if(hsync > (monitor->hmax + 1))
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800610 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 } else {
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800612 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800614 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615}
616
617static int
618sisfb_validate_mode(struct sis_video_info *ivideo, int myindex, u32 vbflags)
619{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700620 u16 xres=0, yres, myres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622#ifdef CONFIG_FB_SIS_300
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700623 if(ivideo->sisvga_engine == SIS_300_VGA) {
624 if(!(sisbios_mode[myindex].chipset & MD_SIS300))
625 return -1 ;
626 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627#endif
628#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700629 if(ivideo->sisvga_engine == SIS_315_VGA) {
630 if(!(sisbios_mode[myindex].chipset & MD_SIS315))
631 return -1;
632 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#endif
634
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700635 myres = sisbios_mode[myindex].yres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700637 switch(vbflags & VB_DISPTYPE_DISP2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700639 case CRT2_LCD:
640 xres = ivideo->lcdxres; yres = ivideo->lcdyres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700642 if((ivideo->SiS_Pr.SiS_CustomT != CUT_PANEL848) &&
643 (ivideo->SiS_Pr.SiS_CustomT != CUT_PANEL856)) {
644 if(sisbios_mode[myindex].xres > xres)
645 return -1;
646 if(myres > yres)
647 return -1;
648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700650 if(ivideo->sisfb_fstn) {
651 if(sisbios_mode[myindex].xres == 320) {
652 if(myres == 240) {
653 switch(sisbios_mode[myindex].mode_no[1]) {
654 case 0x50: myindex = MODE_FSTN_8; break;
655 case 0x56: myindex = MODE_FSTN_16; break;
656 case 0x53: return -1;
657 }
658 }
659 }
660 }
661
662 if(SiS_GetModeID_LCD(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres,
663 sisbios_mode[myindex].yres, 0, ivideo->sisfb_fstn,
664 ivideo->SiS_Pr.SiS_CustomT, xres, yres, ivideo->vbflags2) < 0x14) {
665 return -1;
666 }
667 break;
668
669 case CRT2_TV:
670 if(SiS_GetModeID_TV(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres,
671 sisbios_mode[myindex].yres, 0, ivideo->vbflags2) < 0x14) {
672 return -1;
673 }
674 break;
675
676 case CRT2_VGA:
677 if(SiS_GetModeID_VGA2(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres,
678 sisbios_mode[myindex].yres, 0, ivideo->vbflags2) < 0x14) {
679 return -1;
680 }
681 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 }
683
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700684 return myindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685}
686
687static u8
688sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate, int mode_idx)
689{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 int i = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700691 u16 xres = sisbios_mode[mode_idx].xres;
692 u16 yres = sisbios_mode[mode_idx].yres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694 ivideo->rate_idx = 0;
695 while((sisfb_vrate[i].idx != 0) && (sisfb_vrate[i].xres <= xres)) {
696 if((sisfb_vrate[i].xres == xres) && (sisfb_vrate[i].yres == yres)) {
697 if(sisfb_vrate[i].refresh == rate) {
698 ivideo->rate_idx = sisfb_vrate[i].idx;
699 break;
700 } else if(sisfb_vrate[i].refresh > rate) {
701 if((sisfb_vrate[i].refresh - rate) <= 3) {
702 DPRINTK("sisfb: Adjusting rate from %d up to %d\n",
703 rate, sisfb_vrate[i].refresh);
704 ivideo->rate_idx = sisfb_vrate[i].idx;
705 ivideo->refresh_rate = sisfb_vrate[i].refresh;
Roel Kluind63870d2009-09-22 16:47:07 -0700706 } else if((sisfb_vrate[i].idx != 1) &&
707 ((rate - sisfb_vrate[i-1].refresh) <= 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 DPRINTK("sisfb: Adjusting rate from %d down to %d\n",
709 rate, sisfb_vrate[i-1].refresh);
710 ivideo->rate_idx = sisfb_vrate[i-1].idx;
711 ivideo->refresh_rate = sisfb_vrate[i-1].refresh;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 break;
714 } else if((rate - sisfb_vrate[i].refresh) <= 2) {
715 DPRINTK("sisfb: Adjusting rate from %d down to %d\n",
716 rate, sisfb_vrate[i].refresh);
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700717 ivideo->rate_idx = sisfb_vrate[i].idx;
718 break;
719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
721 i++;
722 }
723 if(ivideo->rate_idx > 0) {
724 return ivideo->rate_idx;
725 } else {
726 printk(KERN_INFO "sisfb: Unsupported rate %d for %dx%d\n",
727 rate, xres, yres);
728 return 0;
729 }
730}
731
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800732static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733sisfb_bridgeisslave(struct sis_video_info *ivideo)
734{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700735 unsigned char P1_00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700737 if(!(ivideo->vbflags2 & VB2_VIDEOBRIDGE))
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800738 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700740 inSISIDXREG(SISPART1,0x00,P1_00);
741 if( ((ivideo->sisvga_engine == SIS_300_VGA) && (P1_00 & 0xa0) == 0x20) ||
742 ((ivideo->sisvga_engine == SIS_315_VGA) && (P1_00 & 0x50) == 0x10) ) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800743 return true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700744 } else {
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800745 return false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700746 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747}
748
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800749static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750sisfballowretracecrt1(struct sis_video_info *ivideo)
751{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700752 u8 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700754 inSISIDXREG(SISCR,0x17,temp);
755 if(!(temp & 0x80))
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800756 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700758 inSISIDXREG(SISSR,0x1f,temp);
759 if(temp & 0xc0)
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800760 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800762 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763}
764
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800765static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766sisfbcheckvretracecrt1(struct sis_video_info *ivideo)
767{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700768 if(!sisfballowretracecrt1(ivideo))
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800769 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700771 if(inSISREG(SISINPSTAT) & 0x08)
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800772 return true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700773 else
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800774 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
776
777static void
778sisfbwaitretracecrt1(struct sis_video_info *ivideo)
779{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700780 int watchdog;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700782 if(!sisfballowretracecrt1(ivideo))
783 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700785 watchdog = 65536;
786 while((!(inSISREG(SISINPSTAT) & 0x08)) && --watchdog);
787 watchdog = 65536;
788 while((inSISREG(SISINPSTAT) & 0x08) && --watchdog);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789}
790
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800791static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792sisfbcheckvretracecrt2(struct sis_video_info *ivideo)
793{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700794 unsigned char temp, reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700796 switch(ivideo->sisvga_engine) {
797 case SIS_300_VGA: reg = 0x25; break;
798 case SIS_315_VGA: reg = 0x30; break;
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800799 default: return false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700802 inSISIDXREG(SISPART1, reg, temp);
803 if(temp & 0x02)
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800804 return true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700805 else
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800806 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807}
808
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800809static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810sisfb_CheckVBRetrace(struct sis_video_info *ivideo)
811{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700812 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
813 if(!sisfb_bridgeisslave(ivideo)) {
814 return sisfbcheckvretracecrt2(ivideo);
815 }
816 }
817 return sisfbcheckvretracecrt1(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
820static u32
821sisfb_setupvbblankflags(struct sis_video_info *ivideo, u32 *vcount, u32 *hcount)
822{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700823 u8 idx, reg1, reg2, reg3, reg4;
824 u32 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700826 (*vcount) = (*hcount) = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700828 if((ivideo->currentvbflags & VB_DISPTYPE_DISP2) && (!(sisfb_bridgeisslave(ivideo)))) {
829
830 ret |= (FB_VBLANK_HAVE_VSYNC |
831 FB_VBLANK_HAVE_HBLANK |
832 FB_VBLANK_HAVE_VBLANK |
833 FB_VBLANK_HAVE_VCOUNT |
834 FB_VBLANK_HAVE_HCOUNT);
835 switch(ivideo->sisvga_engine) {
836 case SIS_300_VGA: idx = 0x25; break;
837 default:
838 case SIS_315_VGA: idx = 0x30; break;
839 }
840 inSISIDXREG(SISPART1,(idx+0),reg1); /* 30 */
841 inSISIDXREG(SISPART1,(idx+1),reg2); /* 31 */
842 inSISIDXREG(SISPART1,(idx+2),reg3); /* 32 */
843 inSISIDXREG(SISPART1,(idx+3),reg4); /* 33 */
844 if(reg1 & 0x01) ret |= FB_VBLANK_VBLANKING;
845 if(reg1 & 0x02) ret |= FB_VBLANK_VSYNCING;
846 if(reg4 & 0x80) ret |= FB_VBLANK_HBLANKING;
847 (*vcount) = reg3 | ((reg4 & 0x70) << 4);
848 (*hcount) = reg2 | ((reg4 & 0x0f) << 8);
849
850 } else if(sisfballowretracecrt1(ivideo)) {
851
852 ret |= (FB_VBLANK_HAVE_VSYNC |
853 FB_VBLANK_HAVE_VBLANK |
854 FB_VBLANK_HAVE_VCOUNT |
855 FB_VBLANK_HAVE_HCOUNT);
856 reg1 = inSISREG(SISINPSTAT);
857 if(reg1 & 0x08) ret |= FB_VBLANK_VSYNCING;
858 if(reg1 & 0x01) ret |= FB_VBLANK_VBLANKING;
859 inSISIDXREG(SISCR,0x20,reg1);
860 inSISIDXREG(SISCR,0x1b,reg1);
861 inSISIDXREG(SISCR,0x1c,reg2);
862 inSISIDXREG(SISCR,0x1d,reg3);
863 (*vcount) = reg2 | ((reg3 & 0x07) << 8);
864 (*hcount) = (reg1 | ((reg3 & 0x10) << 4)) << 3;
865 }
866
867 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868}
869
870static int
871sisfb_myblank(struct sis_video_info *ivideo, int blank)
872{
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700873 u8 sr01, sr11, sr1f, cr63=0, p2_0, p1_13;
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800874 bool backlight = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700876 switch(blank) {
877 case FB_BLANK_UNBLANK: /* on */
878 sr01 = 0x00;
879 sr11 = 0x00;
880 sr1f = 0x00;
881 cr63 = 0x00;
882 p2_0 = 0x20;
883 p1_13 = 0x00;
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800884 backlight = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700885 break;
886 case FB_BLANK_NORMAL: /* blank */
887 sr01 = 0x20;
888 sr11 = 0x00;
889 sr1f = 0x00;
890 cr63 = 0x00;
891 p2_0 = 0x20;
892 p1_13 = 0x00;
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800893 backlight = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700894 break;
895 case FB_BLANK_VSYNC_SUSPEND: /* no vsync */
896 sr01 = 0x20;
897 sr11 = 0x08;
898 sr1f = 0x80;
899 cr63 = 0x40;
900 p2_0 = 0x40;
901 p1_13 = 0x80;
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800902 backlight = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700903 break;
904 case FB_BLANK_HSYNC_SUSPEND: /* no hsync */
905 sr01 = 0x20;
906 sr11 = 0x08;
907 sr1f = 0x40;
908 cr63 = 0x40;
909 p2_0 = 0x80;
910 p1_13 = 0x40;
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800911 backlight = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700912 break;
913 case FB_BLANK_POWERDOWN: /* off */
914 sr01 = 0x20;
915 sr11 = 0x08;
916 sr1f = 0xc0;
917 cr63 = 0x40;
918 p2_0 = 0xc0;
919 p1_13 = 0xc0;
Richard Knutssonc30660ea2007-02-12 00:55:06 -0800920 backlight = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700921 break;
922 default:
923 return 1;
924 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700926 if(ivideo->currentvbflags & VB_DISPTYPE_CRT1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700928 if( (!ivideo->sisfb_thismonitor.datavalid) ||
929 ((ivideo->sisfb_thismonitor.datavalid) &&
930 (ivideo->sisfb_thismonitor.feature & 0xe0))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700932 if(ivideo->sisvga_engine == SIS_315_VGA) {
933 setSISIDXREG(SISCR, ivideo->SiS_Pr.SiS_MyCR63, 0xbf, cr63);
934 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700936 if(!(sisfb_bridgeisslave(ivideo))) {
937 setSISIDXREG(SISSR, 0x01, ~0x20, sr01);
938 setSISIDXREG(SISSR, 0x1f, 0x3f, sr1f);
939 }
940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700942 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700944 if(ivideo->currentvbflags & CRT2_LCD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700946 if(ivideo->vbflags2 & VB2_SISLVDSBRIDGE) {
947 if(backlight) {
948 SiS_SiS30xBLOn(&ivideo->SiS_Pr);
949 } else {
950 SiS_SiS30xBLOff(&ivideo->SiS_Pr);
951 }
952 } else if(ivideo->sisvga_engine == SIS_315_VGA) {
953#ifdef CONFIG_FB_SIS_315
954 if(ivideo->vbflags2 & VB2_CHRONTEL) {
955 if(backlight) {
956 SiS_Chrontel701xBLOn(&ivideo->SiS_Pr);
957 } else {
958 SiS_Chrontel701xBLOff(&ivideo->SiS_Pr);
959 }
960 }
961#endif
962 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700964 if(((ivideo->sisvga_engine == SIS_300_VGA) &&
965 (ivideo->vbflags2 & (VB2_301|VB2_30xBDH|VB2_LVDS))) ||
966 ((ivideo->sisvga_engine == SIS_315_VGA) &&
967 ((ivideo->vbflags2 & (VB2_LVDS | VB2_CHRONTEL)) == VB2_LVDS))) {
968 setSISIDXREG(SISSR, 0x11, ~0x0c, sr11);
969 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700971 if(ivideo->sisvga_engine == SIS_300_VGA) {
972 if((ivideo->vbflags2 & VB2_30xB) &&
973 (!(ivideo->vbflags2 & VB2_30xBDH))) {
974 setSISIDXREG(SISPART1, 0x13, 0x3f, p1_13);
975 }
976 } else if(ivideo->sisvga_engine == SIS_315_VGA) {
977 if((ivideo->vbflags2 & VB2_30xB) &&
978 (!(ivideo->vbflags2 & VB2_30xBDH))) {
979 setSISIDXREG(SISPART2, 0x00, 0x1f, p2_0);
980 }
981 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700983 } else if(ivideo->currentvbflags & CRT2_VGA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700985 if(ivideo->vbflags2 & VB2_30xB) {
986 setSISIDXREG(SISPART2, 0x00, 0x1f, p2_0);
987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700989 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700991 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992}
993
Thomas Winischhofer544393f2005-09-09 13:04:45 -0700994/* ------------- Callbacks from init.c/init301.c -------------- */
995
996#ifdef CONFIG_FB_SIS_300
997unsigned int
998sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg)
999{
1000 struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
1001 u32 val = 0;
1002
1003 pci_read_config_dword(ivideo->nbridge, reg, &val);
1004 return (unsigned int)val;
1005}
1006
1007void
1008sisfb_write_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg, unsigned int val)
1009{
1010 struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
1011
1012 pci_write_config_dword(ivideo->nbridge, reg, (u32)val);
1013}
1014
1015unsigned int
1016sisfb_read_lpc_pci_dword(struct SiS_Private *SiS_Pr, int reg)
1017{
1018 struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
1019 u32 val = 0;
1020
1021 if(!ivideo->lpcdev) return 0;
1022
1023 pci_read_config_dword(ivideo->lpcdev, reg, &val);
1024 return (unsigned int)val;
1025}
1026#endif
1027
1028#ifdef CONFIG_FB_SIS_315
1029void
1030sisfb_write_nbridge_pci_byte(struct SiS_Private *SiS_Pr, int reg, unsigned char val)
1031{
1032 struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
1033
1034 pci_write_config_byte(ivideo->nbridge, reg, (u8)val);
1035}
1036
1037unsigned int
1038sisfb_read_mio_pci_word(struct SiS_Private *SiS_Pr, int reg)
1039{
1040 struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
1041 u16 val = 0;
1042
1043 if(!ivideo->lpcdev) return 0;
1044
1045 pci_read_config_word(ivideo->lpcdev, reg, &val);
1046 return (unsigned int)val;
1047}
1048#endif
1049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050/* ----------- FBDev related routines for all series ----------- */
1051
1052static int
1053sisfb_get_cmap_len(const struct fb_var_screeninfo *var)
1054{
1055 return (var->bits_per_pixel == 8) ? 256 : 16;
1056}
1057
1058static void
1059sisfb_set_vparms(struct sis_video_info *ivideo)
1060{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001061 switch(ivideo->video_bpp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 case 8:
1063 ivideo->DstColor = 0x0000;
1064 ivideo->SiS310_AccelDepth = 0x00000000;
1065 ivideo->video_cmap_len = 256;
1066 break;
1067 case 16:
1068 ivideo->DstColor = 0x8000;
1069 ivideo->SiS310_AccelDepth = 0x00010000;
1070 ivideo->video_cmap_len = 16;
1071 break;
1072 case 32:
1073 ivideo->DstColor = 0xC000;
1074 ivideo->SiS310_AccelDepth = 0x00020000;
1075 ivideo->video_cmap_len = 16;
1076 break;
1077 default:
1078 ivideo->video_cmap_len = 16;
1079 printk(KERN_ERR "sisfb: Unsupported depth %d", ivideo->video_bpp);
1080 ivideo->accel = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001081 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082}
1083
1084static int
1085sisfb_calc_maxyres(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
1086{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001087 int maxyres = ivideo->sisfb_mem / (var->xres_virtual * (var->bits_per_pixel >> 3));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089 if(maxyres > 32767) maxyres = 32767;
1090
1091 return maxyres;
1092}
1093
1094static void
1095sisfb_calc_pitch(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
1096{
1097 ivideo->video_linelength = var->xres_virtual * (var->bits_per_pixel >> 3);
1098 ivideo->scrnpitchCRT1 = ivideo->video_linelength;
1099 if(!(ivideo->currentvbflags & CRT1_LCDA)) {
1100 if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
1101 ivideo->scrnpitchCRT1 <<= 1;
1102 }
1103 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104}
1105
1106static void
1107sisfb_set_pitch(struct sis_video_info *ivideo)
1108{
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001109 bool isslavemode = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 unsigned short HDisplay1 = ivideo->scrnpitchCRT1 >> 3;
1111 unsigned short HDisplay2 = ivideo->video_linelength >> 3;
1112
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001113 if(sisfb_bridgeisslave(ivideo)) isslavemode = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001115 /* We need to set pitch for CRT1 if bridge is in slave mode, too */
1116 if((ivideo->currentvbflags & VB_DISPTYPE_DISP1) || (isslavemode)) {
1117 outSISIDXREG(SISCR,0x13,(HDisplay1 & 0xFF));
1118 setSISIDXREG(SISSR,0x0E,0xF0,(HDisplay1 >> 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
1120
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001121 /* We must not set the pitch for CRT2 if bridge is in slave mode */
1122 if((ivideo->currentvbflags & VB_DISPTYPE_DISP2) && (!isslavemode)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 orSISIDXREG(SISPART1,ivideo->CRT2_write_enable,0x01);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001124 outSISIDXREG(SISPART1,0x07,(HDisplay2 & 0xFF));
1125 setSISIDXREG(SISPART1,0x09,0xF0,(HDisplay2 >> 8));
1126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
1129static void
1130sisfb_bpp_to_var(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
1131{
1132 ivideo->video_cmap_len = sisfb_get_cmap_len(var);
1133
1134 switch(var->bits_per_pixel) {
1135 case 8:
1136 var->red.offset = var->green.offset = var->blue.offset = 0;
Michal Januszewski811a2012009-04-13 14:39:52 -07001137 var->red.length = var->green.length = var->blue.length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 break;
1139 case 16:
1140 var->red.offset = 11;
1141 var->red.length = 5;
1142 var->green.offset = 5;
1143 var->green.length = 6;
1144 var->blue.offset = 0;
1145 var->blue.length = 5;
1146 var->transp.offset = 0;
1147 var->transp.length = 0;
1148 break;
1149 case 32:
1150 var->red.offset = 16;
1151 var->red.length = 8;
1152 var->green.offset = 8;
1153 var->green.length = 8;
1154 var->blue.offset = 0;
1155 var->blue.length = 8;
1156 var->transp.offset = 24;
1157 var->transp.length = 8;
1158 break;
1159 }
1160}
1161
1162static int
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001163sisfb_set_mode(struct sis_video_info *ivideo, int clrscrn)
1164{
1165 unsigned short modeno = ivideo->mode_no;
1166
1167 /* >=2.6.12's fbcon clears the screen anyway */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001168 modeno |= 0x80;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001169
1170 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
1171
1172 sisfb_pre_setmode(ivideo);
1173
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001174 if(!SiSSetMode(&ivideo->SiS_Pr, modeno)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001175 printk(KERN_ERR "sisfb: Setting mode[0x%x] failed\n", ivideo->mode_no);
1176 return -EINVAL;
1177 }
1178
1179 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
1180
1181 sisfb_post_setmode(ivideo);
1182
1183 return 0;
1184}
1185
1186
1187static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *info)
1189{
1190 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1191 unsigned int htotal = 0, vtotal = 0;
1192 unsigned int drate = 0, hrate = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001193 int found_mode = 0, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 int old_mode;
1195 u32 pixclock;
1196
1197 htotal = var->left_margin + var->xres + var->right_margin + var->hsync_len;
1198
1199 vtotal = var->upper_margin + var->lower_margin + var->vsync_len;
1200
1201 pixclock = var->pixclock;
1202
1203 if((var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED) {
1204 vtotal += var->yres;
1205 vtotal <<= 1;
1206 } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
1207 vtotal += var->yres;
1208 vtotal <<= 2;
1209 } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
1210 vtotal += var->yres;
1211 vtotal <<= 1;
1212 } else vtotal += var->yres;
1213
1214 if(!(htotal) || !(vtotal)) {
1215 DPRINTK("sisfb: Invalid 'var' information\n");
1216 return -EINVAL;
1217 }
1218
1219 if(pixclock && htotal && vtotal) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001220 drate = 1000000000 / pixclock;
1221 hrate = (drate * 1000) / htotal;
1222 ivideo->refresh_rate = (unsigned int) (hrate * 2 / vtotal);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001224 ivideo->refresh_rate = 60;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 }
1226
1227 old_mode = ivideo->sisfb_mode_idx;
1228 ivideo->sisfb_mode_idx = 0;
1229
1230 while( (sisbios_mode[ivideo->sisfb_mode_idx].mode_no[0] != 0) &&
1231 (sisbios_mode[ivideo->sisfb_mode_idx].xres <= var->xres) ) {
1232 if( (sisbios_mode[ivideo->sisfb_mode_idx].xres == var->xres) &&
1233 (sisbios_mode[ivideo->sisfb_mode_idx].yres == var->yres) &&
1234 (sisbios_mode[ivideo->sisfb_mode_idx].bpp == var->bits_per_pixel)) {
1235 ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni];
1236 found_mode = 1;
1237 break;
1238 }
1239 ivideo->sisfb_mode_idx++;
1240 }
1241
1242 if(found_mode) {
1243 ivideo->sisfb_mode_idx = sisfb_validate_mode(ivideo,
1244 ivideo->sisfb_mode_idx, ivideo->currentvbflags);
1245 } else {
1246 ivideo->sisfb_mode_idx = -1;
1247 }
1248
1249 if(ivideo->sisfb_mode_idx < 0) {
1250 printk(KERN_ERR "sisfb: Mode %dx%dx%d not supported\n", var->xres,
1251 var->yres, var->bits_per_pixel);
1252 ivideo->sisfb_mode_idx = old_mode;
1253 return -EINVAL;
1254 }
1255
Adrian Bunka9e60e52007-11-14 16:59:02 -08001256 ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni];
1257
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 if(sisfb_search_refresh_rate(ivideo, ivideo->refresh_rate, ivideo->sisfb_mode_idx) == 0) {
1259 ivideo->rate_idx = sisbios_mode[ivideo->sisfb_mode_idx].rate_idx;
1260 ivideo->refresh_rate = 60;
1261 }
1262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 if(isactive) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001264 /* If acceleration to be used? Need to know
1265 * before pre/post_set_mode()
1266 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 ivideo->accel = 0;
1268#if defined(FBINFO_HWACCEL_DISABLED) && defined(FBINFO_HWACCEL_XPAN)
1269#ifdef STUPID_ACCELF_TEXT_SHIT
1270 if(var->accel_flags & FB_ACCELF_TEXT) {
1271 info->flags &= ~FBINFO_HWACCEL_DISABLED;
1272 } else {
1273 info->flags |= FBINFO_HWACCEL_DISABLED;
1274 }
1275#endif
1276 if(!(info->flags & FBINFO_HWACCEL_DISABLED)) ivideo->accel = -1;
1277#else
1278 if(var->accel_flags & FB_ACCELF_TEXT) ivideo->accel = -1;
1279#endif
1280
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001281 if((ret = sisfb_set_mode(ivideo, 1))) {
1282 return ret;
1283 }
1284
1285 ivideo->video_bpp = sisbios_mode[ivideo->sisfb_mode_idx].bpp;
1286 ivideo->video_width = sisbios_mode[ivideo->sisfb_mode_idx].xres;
1287 ivideo->video_height = sisbios_mode[ivideo->sisfb_mode_idx].yres;
1288
1289 sisfb_calc_pitch(ivideo, var);
1290 sisfb_set_pitch(ivideo);
1291
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 sisfb_set_vparms(ivideo);
1293
1294 ivideo->current_width = ivideo->video_width;
1295 ivideo->current_height = ivideo->video_height;
1296 ivideo->current_bpp = ivideo->video_bpp;
1297 ivideo->current_htotal = htotal;
1298 ivideo->current_vtotal = vtotal;
1299 ivideo->current_linelength = ivideo->video_linelength;
1300 ivideo->current_pixclock = var->pixclock;
1301 ivideo->current_refresh_rate = ivideo->refresh_rate;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001302 ivideo->sisfb_lastrates[ivideo->mode_no] = ivideo->refresh_rate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 }
1304
1305 return 0;
1306}
1307
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001308static void
1309sisfb_set_base_CRT1(struct sis_video_info *ivideo, unsigned int base)
1310{
1311 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
1312
1313 outSISIDXREG(SISCR, 0x0D, base & 0xFF);
1314 outSISIDXREG(SISCR, 0x0C, (base >> 8) & 0xFF);
1315 outSISIDXREG(SISSR, 0x0D, (base >> 16) & 0xFF);
1316 if(ivideo->sisvga_engine == SIS_315_VGA) {
1317 setSISIDXREG(SISSR, 0x37, 0xFE, (base >> 24) & 0x01);
1318 }
1319}
1320
1321static void
1322sisfb_set_base_CRT2(struct sis_video_info *ivideo, unsigned int base)
1323{
1324 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
1325 orSISIDXREG(SISPART1, ivideo->CRT2_write_enable, 0x01);
1326 outSISIDXREG(SISPART1, 0x06, (base & 0xFF));
1327 outSISIDXREG(SISPART1, 0x05, ((base >> 8) & 0xFF));
1328 outSISIDXREG(SISPART1, 0x04, ((base >> 16) & 0xFF));
1329 if(ivideo->sisvga_engine == SIS_315_VGA) {
1330 setSISIDXREG(SISPART1, 0x02, 0x7F, ((base >> 24) & 0x01) << 7);
1331 }
1332 }
1333}
1334
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335static int
1336sisfb_pan_var(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
1337{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 if(var->xoffset > (var->xres_virtual - var->xres)) {
1339 return -EINVAL;
1340 }
1341 if(var->yoffset > (var->yres_virtual - var->yres)) {
1342 return -EINVAL;
1343 }
1344
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001345 ivideo->current_base = (var->yoffset * var->xres_virtual) + var->xoffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001347 /* calculate base bpp dep. */
1348 switch(var->bits_per_pixel) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 case 32:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001350 break;
1351 case 16:
1352 ivideo->current_base >>= 1;
1353 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 case 8:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001355 default:
1356 ivideo->current_base >>= 2;
1357 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001359
1360 ivideo->current_base += (ivideo->video_offset >> 2);
1361
1362 sisfb_set_base_CRT1(ivideo, ivideo->current_base);
1363 sisfb_set_base_CRT2(ivideo, ivideo->current_base);
1364
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 return 0;
1366}
1367
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368static int
1369sisfb_open(struct fb_info *info, int user)
1370{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001371 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372}
1373
1374static int
1375sisfb_release(struct fb_info *info, int user)
1376{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001377 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378}
1379
1380static int
1381sisfb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
1382 unsigned transp, struct fb_info *info)
1383{
1384 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1385
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001386 if(regno >= sisfb_get_cmap_len(&info->var))
1387 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 switch(info->var.bits_per_pixel) {
1390 case 8:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001391 outSISREG(SISDACA, regno);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 outSISREG(SISDACD, (red >> 10));
1393 outSISREG(SISDACD, (green >> 10));
1394 outSISREG(SISDACD, (blue >> 10));
1395 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001396 outSISREG(SISDAC2A, regno);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 outSISREG(SISDAC2D, (red >> 8));
1398 outSISREG(SISDAC2D, (green >> 8));
1399 outSISREG(SISDAC2D, (blue >> 8));
1400 }
1401 break;
1402 case 16:
Antonino A. Daplas000d5332007-07-17 04:05:44 -07001403 if (regno >= 16)
1404 break;
1405
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 ((u32 *)(info->pseudo_palette))[regno] =
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001407 (red & 0xf800) |
1408 ((green & 0xfc00) >> 5) |
1409 ((blue & 0xf800) >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 break;
1411 case 32:
Antonino A. Daplas000d5332007-07-17 04:05:44 -07001412 if (regno >= 16)
1413 break;
1414
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 red >>= 8;
1416 green >>= 8;
1417 blue >>= 8;
1418 ((u32 *)(info->pseudo_palette))[regno] =
1419 (red << 16) | (green << 8) | (blue);
1420 break;
1421 }
1422 return 0;
1423}
1424
1425static int
1426sisfb_set_par(struct fb_info *info)
1427{
1428 int err;
1429
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001430 if((err = sisfb_do_set_var(&info->var, 1, info)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 return err;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001432
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001433 sisfb_get_fix(&info->fix, -1, info);
Adrian Bunk14aefd12008-07-23 21:31:12 -07001434
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 return 0;
1436}
1437
1438static int
1439sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1440{
1441 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1442 unsigned int htotal = 0, vtotal = 0, myrateindex = 0;
1443 unsigned int drate = 0, hrate = 0, maxyres;
1444 int found_mode = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001445 int refresh_rate, search_idx, tidx;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001446 bool recalc_clock = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 u32 pixclock;
1448
1449 htotal = var->left_margin + var->xres + var->right_margin + var->hsync_len;
1450
1451 vtotal = var->upper_margin + var->lower_margin + var->vsync_len;
1452
1453 pixclock = var->pixclock;
1454
1455 if((var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED) {
1456 vtotal += var->yres;
1457 vtotal <<= 1;
1458 } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
1459 vtotal += var->yres;
1460 vtotal <<= 2;
1461 } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
1462 vtotal += var->yres;
1463 vtotal <<= 1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001464 } else
1465 vtotal += var->yres;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
1467 if(!(htotal) || !(vtotal)) {
1468 SISFAIL("sisfb: no valid timing data");
1469 }
1470
1471 search_idx = 0;
1472 while( (sisbios_mode[search_idx].mode_no[0] != 0) &&
1473 (sisbios_mode[search_idx].xres <= var->xres) ) {
1474 if( (sisbios_mode[search_idx].xres == var->xres) &&
1475 (sisbios_mode[search_idx].yres == var->yres) &&
1476 (sisbios_mode[search_idx].bpp == var->bits_per_pixel)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001477 if((tidx = sisfb_validate_mode(ivideo, search_idx,
1478 ivideo->currentvbflags)) > 0) {
1479 found_mode = 1;
1480 search_idx = tidx;
1481 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 }
1483 }
1484 search_idx++;
1485 }
1486
1487 if(!found_mode) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001488 search_idx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 while(sisbios_mode[search_idx].mode_no[0] != 0) {
1490 if( (var->xres <= sisbios_mode[search_idx].xres) &&
1491 (var->yres <= sisbios_mode[search_idx].yres) &&
1492 (var->bits_per_pixel == sisbios_mode[search_idx].bpp) ) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001493 if((tidx = sisfb_validate_mode(ivideo,search_idx,
1494 ivideo->currentvbflags)) > 0) {
1495 found_mode = 1;
1496 search_idx = tidx;
1497 break;
1498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 }
1500 search_idx++;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 if(found_mode) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001503 printk(KERN_DEBUG
1504 "sisfb: Adapted from %dx%dx%d to %dx%dx%d\n",
1505 var->xres, var->yres, var->bits_per_pixel,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 sisbios_mode[search_idx].xres,
1507 sisbios_mode[search_idx].yres,
1508 var->bits_per_pixel);
1509 var->xres = sisbios_mode[search_idx].xres;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001510 var->yres = sisbios_mode[search_idx].yres;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001512 printk(KERN_ERR
1513 "sisfb: Failed to find supported mode near %dx%dx%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 var->xres, var->yres, var->bits_per_pixel);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001515 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 }
1517 }
1518
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001519 if( ((ivideo->vbflags2 & VB2_LVDS) ||
1520 ((ivideo->vbflags2 & VB2_30xBDH) && (ivideo->currentvbflags & CRT2_LCD))) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 (var->bits_per_pixel == 8) ) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001522 /* Slave modes on LVDS and 301B-DH */
1523 refresh_rate = 60;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001524 recalc_clock = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001525 } else if( (ivideo->current_htotal == htotal) &&
1526 (ivideo->current_vtotal == vtotal) &&
1527 (ivideo->current_pixclock == pixclock) ) {
1528 /* x=x & y=y & c=c -> assume depth change */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 drate = 1000000000 / pixclock;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001530 hrate = (drate * 1000) / htotal;
1531 refresh_rate = (unsigned int) (hrate * 2 / vtotal);
1532 } else if( ( (ivideo->current_htotal != htotal) ||
1533 (ivideo->current_vtotal != vtotal) ) &&
1534 (ivideo->current_pixclock == var->pixclock) ) {
1535 /* x!=x | y!=y & c=c -> invalid pixclock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 if(ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]]) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001537 refresh_rate =
1538 ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 } else if(ivideo->sisfb_parm_rate != -1) {
1540 /* Sic, sisfb_parm_rate - want to know originally desired rate here */
1541 refresh_rate = ivideo->sisfb_parm_rate;
1542 } else {
1543 refresh_rate = 60;
1544 }
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001545 recalc_clock = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 } else if((pixclock) && (htotal) && (vtotal)) {
1547 drate = 1000000000 / pixclock;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001548 hrate = (drate * 1000) / htotal;
1549 refresh_rate = (unsigned int) (hrate * 2 / vtotal);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 } else if(ivideo->current_refresh_rate) {
1551 refresh_rate = ivideo->current_refresh_rate;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001552 recalc_clock = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 } else {
1554 refresh_rate = 60;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08001555 recalc_clock = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 }
1557
1558 myrateindex = sisfb_search_refresh_rate(ivideo, refresh_rate, search_idx);
1559
1560 /* Eventually recalculate timing and clock */
1561 if(recalc_clock) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001562 if(!myrateindex) myrateindex = sisbios_mode[search_idx].rate_idx;
1563 var->pixclock = (u32) (1000000000 / sisfb_mode_rate_to_dclock(&ivideo->SiS_Pr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 sisbios_mode[search_idx].mode_no[ivideo->mni],
1565 myrateindex));
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001566 sisfb_mode_rate_to_ddata(&ivideo->SiS_Pr,
1567 sisbios_mode[search_idx].mode_no[ivideo->mni],
1568 myrateindex, var);
1569 if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
1570 var->pixclock <<= 1;
1571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 }
1573
1574 if(ivideo->sisfb_thismonitor.datavalid) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001575 if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor, search_idx,
1576 myrateindex, refresh_rate)) {
1577 printk(KERN_INFO
1578 "sisfb: WARNING: Refresh rate exceeds monitor specs!\n");
1579 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 }
1581
1582 /* Adapt RGB settings */
1583 sisfb_bpp_to_var(ivideo, var);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001584
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 /* Sanity check for offsets */
1586 if(var->xoffset < 0) var->xoffset = 0;
1587 if(var->yoffset < 0) var->yoffset = 0;
1588
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001589 if(var->xres > var->xres_virtual)
1590 var->xres_virtual = var->xres;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
1592 if(ivideo->sisfb_ypan) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001593 maxyres = sisfb_calc_maxyres(ivideo, var);
1594 if(ivideo->sisfb_max) {
1595 var->yres_virtual = maxyres;
1596 } else {
1597 if(var->yres_virtual > maxyres) {
1598 var->yres_virtual = maxyres;
1599 }
1600 }
1601 if(var->yres_virtual <= var->yres) {
1602 var->yres_virtual = var->yres;
1603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001605 if(var->yres != var->yres_virtual) {
1606 var->yres_virtual = var->yres;
1607 }
1608 var->xoffset = 0;
1609 var->yoffset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001611
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 /* Truncate offsets to maximum if too high */
1613 if(var->xoffset > var->xres_virtual - var->xres) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001614 var->xoffset = var->xres_virtual - var->xres - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 }
1616
1617 if(var->yoffset > var->yres_virtual - var->yres) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001618 var->yoffset = var->yres_virtual - var->yres - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 /* Set everything else to 0 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001622 var->red.msb_right =
1623 var->green.msb_right =
1624 var->blue.msb_right =
1625 var->transp.offset =
1626 var->transp.length =
1627 var->transp.msb_right = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
1629 return 0;
1630}
1631
1632static int
1633sisfb_pan_display(struct fb_var_screeninfo *var, struct fb_info* info)
1634{
1635 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1636 int err;
1637
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001638 if(var->xoffset > (var->xres_virtual - var->xres))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001641 if(var->yoffset > (var->yres_virtual - var->yres))
1642 return -EINVAL;
1643
1644 if(var->vmode & FB_VMODE_YWRAP)
1645 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
1647 if(var->xoffset + info->var.xres > info->var.xres_virtual ||
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001648 var->yoffset + info->var.yres > info->var.yres_virtual)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001651 if((err = sisfb_pan_var(ivideo, var)) < 0)
1652 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
1654 info->var.xoffset = var->xoffset;
1655 info->var.yoffset = var->yoffset;
1656
1657 return 0;
1658}
1659
1660static int
1661sisfb_blank(int blank, struct fb_info *info)
1662{
1663 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1664
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001665 return sisfb_myblank(ivideo, blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666}
1667
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668/* ----------- FBDev related routines for all series ---------- */
1669
Christoph Hellwig67a66802006-01-14 13:21:25 -08001670static int sisfb_ioctl(struct fb_info *info, unsigned int cmd,
1671 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672{
1673 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001674 struct sis_memreq sismemreq;
1675 struct fb_vblank sisvbblank;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 u32 gpu32 = 0;
1677#ifndef __user
1678#define __user
1679#endif
1680 u32 __user *argp = (u32 __user *)arg;
1681
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001682 switch(cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 case FBIO_ALLOC:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001684 if(!capable(CAP_SYS_RAWIO))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 return -EPERM;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001686
1687 if(copy_from_user(&sismemreq, (void __user *)arg, sizeof(sismemreq)))
1688 return -EFAULT;
1689
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 sis_malloc(&sismemreq);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001691
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 if(copy_to_user((void __user *)arg, &sismemreq, sizeof(sismemreq))) {
1693 sis_free((u32)sismemreq.offset);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001694 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 }
1696 break;
1697
1698 case FBIO_FREE:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001699 if(!capable(CAP_SYS_RAWIO))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 return -EPERM;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001701
1702 if(get_user(gpu32, argp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 return -EFAULT;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001704
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 sis_free(gpu32);
1706 break;
1707
1708 case FBIOGET_VBLANK:
Dan Rosenbergfd02db92010-09-22 13:05:09 -07001709
1710 memset(&sisvbblank, 0, sizeof(struct fb_vblank));
1711
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 sisvbblank.count = 0;
1713 sisvbblank.flags = sisfb_setupvbblankflags(ivideo, &sisvbblank.vcount, &sisvbblank.hcount);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001714
1715 if(copy_to_user((void __user *)arg, &sisvbblank, sizeof(sisvbblank)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 return -EFAULT;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 break;
1719
1720 case SISFB_GET_INFO_SIZE:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001721 return put_user(sizeof(struct sisfb_info), argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
1723 case SISFB_GET_INFO_OLD:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001724 if(ivideo->warncount++ < 10)
1725 printk(KERN_INFO
1726 "sisfb: Deprecated ioctl call received - update your application!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 case SISFB_GET_INFO: /* For communication with X driver */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001728 ivideo->sisfb_infoblock.sisfb_id = SISFB_ID;
1729 ivideo->sisfb_infoblock.sisfb_version = VER_MAJOR;
1730 ivideo->sisfb_infoblock.sisfb_revision = VER_MINOR;
1731 ivideo->sisfb_infoblock.sisfb_patchlevel = VER_LEVEL;
1732 ivideo->sisfb_infoblock.chip_id = ivideo->chip_id;
1733 ivideo->sisfb_infoblock.sisfb_pci_vendor = ivideo->chip_vendor;
1734 ivideo->sisfb_infoblock.memory = ivideo->video_size / 1024;
1735 ivideo->sisfb_infoblock.heapstart = ivideo->heapstart / 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 if(ivideo->modechanged) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001737 ivideo->sisfb_infoblock.fbvidmode = ivideo->mode_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001739 ivideo->sisfb_infoblock.fbvidmode = ivideo->modeprechange;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001741 ivideo->sisfb_infoblock.sisfb_caps = ivideo->caps;
1742 ivideo->sisfb_infoblock.sisfb_tqlen = ivideo->cmdQueueSize / 1024;
1743 ivideo->sisfb_infoblock.sisfb_pcibus = ivideo->pcibus;
1744 ivideo->sisfb_infoblock.sisfb_pcislot = ivideo->pcislot;
1745 ivideo->sisfb_infoblock.sisfb_pcifunc = ivideo->pcifunc;
1746 ivideo->sisfb_infoblock.sisfb_lcdpdc = ivideo->detectedpdc;
1747 ivideo->sisfb_infoblock.sisfb_lcdpdca = ivideo->detectedpdca;
1748 ivideo->sisfb_infoblock.sisfb_lcda = ivideo->detectedlcda;
1749 ivideo->sisfb_infoblock.sisfb_vbflags = ivideo->vbflags;
1750 ivideo->sisfb_infoblock.sisfb_currentvbflags = ivideo->currentvbflags;
1751 ivideo->sisfb_infoblock.sisfb_scalelcd = ivideo->SiS_Pr.UsePanelScaler;
1752 ivideo->sisfb_infoblock.sisfb_specialtiming = ivideo->SiS_Pr.SiS_CustomT;
1753 ivideo->sisfb_infoblock.sisfb_haveemi = ivideo->SiS_Pr.HaveEMI ? 1 : 0;
1754 ivideo->sisfb_infoblock.sisfb_haveemilcd = ivideo->SiS_Pr.HaveEMILCD ? 1 : 0;
1755 ivideo->sisfb_infoblock.sisfb_emi30 = ivideo->SiS_Pr.EMI_30;
1756 ivideo->sisfb_infoblock.sisfb_emi31 = ivideo->SiS_Pr.EMI_31;
1757 ivideo->sisfb_infoblock.sisfb_emi32 = ivideo->SiS_Pr.EMI_32;
1758 ivideo->sisfb_infoblock.sisfb_emi33 = ivideo->SiS_Pr.EMI_33;
1759 ivideo->sisfb_infoblock.sisfb_tvxpos = (u16)(ivideo->tvxpos + 32);
1760 ivideo->sisfb_infoblock.sisfb_tvypos = (u16)(ivideo->tvypos + 32);
1761 ivideo->sisfb_infoblock.sisfb_heapsize = ivideo->sisfb_heap_size / 1024;
1762 ivideo->sisfb_infoblock.sisfb_videooffset = ivideo->video_offset;
1763 ivideo->sisfb_infoblock.sisfb_curfstn = ivideo->curFSTN;
1764 ivideo->sisfb_infoblock.sisfb_curdstn = ivideo->curDSTN;
1765 ivideo->sisfb_infoblock.sisfb_vbflags2 = ivideo->vbflags2;
1766 ivideo->sisfb_infoblock.sisfb_can_post = ivideo->sisfb_can_post ? 1 : 0;
1767 ivideo->sisfb_infoblock.sisfb_card_posted = ivideo->sisfb_card_posted ? 1 : 0;
1768 ivideo->sisfb_infoblock.sisfb_was_boot_device = ivideo->sisfb_was_boot_device ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001770 if(copy_to_user((void __user *)arg, &ivideo->sisfb_infoblock,
1771 sizeof(ivideo->sisfb_infoblock)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 return -EFAULT;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001773
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 break;
1775
1776 case SISFB_GET_VBRSTATUS_OLD:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001777 if(ivideo->warncount++ < 10)
1778 printk(KERN_INFO
1779 "sisfb: Deprecated ioctl call received - update your application!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 case SISFB_GET_VBRSTATUS:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001781 if(sisfb_CheckVBRetrace(ivideo))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 return put_user((u32)1, argp);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001783 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 return put_user((u32)0, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
1786 case SISFB_GET_AUTOMAXIMIZE_OLD:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001787 if(ivideo->warncount++ < 10)
1788 printk(KERN_INFO
1789 "sisfb: Deprecated ioctl call received - update your application!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 case SISFB_GET_AUTOMAXIMIZE:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001791 if(ivideo->sisfb_max)
1792 return put_user((u32)1, argp);
1793 else
1794 return put_user((u32)0, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
1796 case SISFB_SET_AUTOMAXIMIZE_OLD:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001797 if(ivideo->warncount++ < 10)
1798 printk(KERN_INFO
1799 "sisfb: Deprecated ioctl call received - update your application!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 case SISFB_SET_AUTOMAXIMIZE:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001801 if(get_user(gpu32, argp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 return -EFAULT;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001803
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 ivideo->sisfb_max = (gpu32) ? 1 : 0;
1805 break;
1806
1807 case SISFB_SET_TVPOSOFFSET:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001808 if(get_user(gpu32, argp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 return -EFAULT;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001810
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 sisfb_set_TVxposoffset(ivideo, ((int)(gpu32 >> 16)) - 32);
1812 sisfb_set_TVyposoffset(ivideo, ((int)(gpu32 & 0xffff)) - 32);
1813 break;
1814
1815 case SISFB_GET_TVPOSOFFSET:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001816 return put_user((u32)(((ivideo->tvxpos+32)<<16)|((ivideo->tvypos+32)&0xffff)),
1817 argp);
1818
1819 case SISFB_COMMAND:
1820 if(copy_from_user(&ivideo->sisfb_command, (void __user *)arg,
1821 sizeof(struct sisfb_cmd)))
1822 return -EFAULT;
1823
1824 sisfb_handle_command(ivideo, &ivideo->sisfb_command);
1825
1826 if(copy_to_user((void __user *)arg, &ivideo->sisfb_command,
1827 sizeof(struct sisfb_cmd)))
1828 return -EFAULT;
1829
1830 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
1832 case SISFB_SET_LOCK:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001833 if(get_user(gpu32, argp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 return -EFAULT;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 ivideo->sisfblocked = (gpu32) ? 1 : 0;
1837 break;
1838
1839 default:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001840#ifdef SIS_NEW_CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 return -ENOIOCTLCMD;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001842#else
1843 return -EINVAL;
1844#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 }
1846 return 0;
1847}
1848
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849static int
1850sisfb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
1851{
1852 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1853
1854 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
1855
Dan Carpenterdbd536b2010-05-24 14:33:53 -07001856 strlcpy(fix->id, ivideo->myid, sizeof(fix->id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
Krzysztof Helt537a1bf2009-06-30 11:41:29 -07001858 mutex_lock(&info->mm_lock);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001859 fix->smem_start = ivideo->video_base + ivideo->video_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 fix->smem_len = ivideo->sisfb_mem;
Krzysztof Helt537a1bf2009-06-30 11:41:29 -07001861 mutex_unlock(&info->mm_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 fix->type = FB_TYPE_PACKED_PIXELS;
1863 fix->type_aux = 0;
1864 fix->visual = (ivideo->video_bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
1865 fix->xpanstep = 1;
1866 fix->ypanstep = (ivideo->sisfb_ypan) ? 1 : 0;
1867 fix->ywrapstep = 0;
1868 fix->line_length = ivideo->video_linelength;
1869 fix->mmio_start = ivideo->mmio_base;
1870 fix->mmio_len = ivideo->mmio_size;
1871 if(ivideo->sisvga_engine == SIS_300_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001872 fix->accel = FB_ACCEL_SIS_GLAMOUR;
1873 } else if((ivideo->chip == SIS_330) ||
1874 (ivideo->chip == SIS_760) ||
1875 (ivideo->chip == SIS_761)) {
1876 fix->accel = FB_ACCEL_SIS_XABRE;
1877 } else if(ivideo->chip == XGI_20) {
1878 fix->accel = FB_ACCEL_XGI_VOLARI_Z;
1879 } else if(ivideo->chip >= XGI_40) {
1880 fix->accel = FB_ACCEL_XGI_VOLARI_V;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001882 fix->accel = FB_ACCEL_SIS_GLAMOUR_2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 }
1884
1885 return 0;
1886}
1887
1888/* ---------------- fb_ops structures ----------------- */
1889
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890static struct fb_ops sisfb_ops = {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001891 .owner = THIS_MODULE,
1892 .fb_open = sisfb_open,
1893 .fb_release = sisfb_release,
1894 .fb_check_var = sisfb_check_var,
1895 .fb_set_par = sisfb_set_par,
1896 .fb_setcolreg = sisfb_setcolreg,
1897 .fb_pan_display = sisfb_pan_display,
1898 .fb_blank = sisfb_blank,
1899 .fb_fillrect = fbcon_sis_fillrect,
1900 .fb_copyarea = fbcon_sis_copyarea,
1901 .fb_imageblit = cfb_imageblit,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001902 .fb_sync = fbcon_sis_sync,
1903#ifdef SIS_NEW_CONFIG_COMPAT
Christoph Hellwig67a66802006-01-14 13:21:25 -08001904 .fb_compat_ioctl= sisfb_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001906 .fb_ioctl = sisfb_ioctl
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
1909/* ---------------- Chip generation dependent routines ---------------- */
1910
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001911static struct pci_dev * __devinit
1912sisfb_get_northbridge(int basechipid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913{
1914 struct pci_dev *pdev = NULL;
1915 int nbridgenum, nbridgeidx, i;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001916 static const unsigned short nbridgeids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 PCI_DEVICE_ID_SI_540, /* for SiS 540 VGA */
1918 PCI_DEVICE_ID_SI_630, /* for SiS 630/730 VGA */
1919 PCI_DEVICE_ID_SI_730,
1920 PCI_DEVICE_ID_SI_550, /* for SiS 550 VGA */
1921 PCI_DEVICE_ID_SI_650, /* for SiS 650/651/740 VGA */
1922 PCI_DEVICE_ID_SI_651,
1923 PCI_DEVICE_ID_SI_740,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001924 PCI_DEVICE_ID_SI_661, /* for SiS 661/741/660/760/761 VGA */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 PCI_DEVICE_ID_SI_741,
1926 PCI_DEVICE_ID_SI_660,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001927 PCI_DEVICE_ID_SI_760,
1928 PCI_DEVICE_ID_SI_761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 };
1930
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001931 switch(basechipid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932#ifdef CONFIG_FB_SIS_300
1933 case SIS_540: nbridgeidx = 0; nbridgenum = 1; break;
1934 case SIS_630: nbridgeidx = 1; nbridgenum = 2; break;
1935#endif
1936#ifdef CONFIG_FB_SIS_315
1937 case SIS_550: nbridgeidx = 3; nbridgenum = 1; break;
1938 case SIS_650: nbridgeidx = 4; nbridgenum = 3; break;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001939 case SIS_660: nbridgeidx = 7; nbridgenum = 5; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940#endif
1941 default: return NULL;
1942 }
1943 for(i = 0; i < nbridgenum; i++) {
Adrian Bunk0959f0c2007-05-08 00:39:50 -07001944 if((pdev = pci_get_device(PCI_VENDOR_ID_SI,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001945 nbridgeids[nbridgeidx+i], NULL)))
1946 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 }
1948 return pdev;
1949}
1950
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001951static int __devinit
1952sisfb_get_dram_size(struct sis_video_info *ivideo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953{
1954#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
1955 u8 reg;
1956#endif
1957
1958 ivideo->video_size = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001959 ivideo->UMAsize = ivideo->LFBsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
1961 switch(ivideo->chip) {
1962#ifdef CONFIG_FB_SIS_300
1963 case SIS_300:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001964 inSISIDXREG(SISSR, 0x14, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 ivideo->video_size = ((reg & 0x3F) + 1) << 20;
1966 break;
1967 case SIS_540:
1968 case SIS_630:
1969 case SIS_730:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001970 if(!ivideo->nbridge)
1971 return -1;
1972 pci_read_config_byte(ivideo->nbridge, 0x63, &reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 ivideo->video_size = 1 << (((reg & 0x70) >> 4) + 21);
1974 break;
1975#endif
1976#ifdef CONFIG_FB_SIS_315
1977 case SIS_315H:
1978 case SIS_315PRO:
1979 case SIS_315:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001980 inSISIDXREG(SISSR, 0x14, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
1982 switch((reg >> 2) & 0x03) {
1983 case 0x01:
1984 case 0x03:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001985 ivideo->video_size <<= 1;
1986 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 case 0x02:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001988 ivideo->video_size += (ivideo->video_size/2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001990 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 case SIS_330:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001992 inSISIDXREG(SISSR, 0x14, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
1994 if(reg & 0x0c) ivideo->video_size <<= 1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001995 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 case SIS_550:
1997 case SIS_650:
1998 case SIS_740:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07001999 inSISIDXREG(SISSR, 0x14, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 ivideo->video_size = (((reg & 0x3f) + 1) << 2) << 20;
2001 break;
2002 case SIS_661:
2003 case SIS_741:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002004 inSISIDXREG(SISCR, 0x79, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002006 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 case SIS_660:
2008 case SIS_760:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002009 case SIS_761:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 inSISIDXREG(SISCR, 0x79, reg);
2011 reg = (reg & 0xf0) >> 4;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002012 if(reg) {
2013 ivideo->video_size = (1 << reg) << 20;
2014 ivideo->UMAsize = ivideo->video_size;
2015 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 inSISIDXREG(SISCR, 0x78, reg);
2017 reg &= 0x30;
2018 if(reg) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002019 if(reg == 0x10) {
2020 ivideo->LFBsize = (32 << 20);
2021 } else {
2022 ivideo->LFBsize = (64 << 20);
2023 }
2024 ivideo->video_size += ivideo->LFBsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002026 break;
2027 case SIS_340:
2028 case XGI_20:
2029 case XGI_40:
2030 inSISIDXREG(SISSR, 0x14, reg);
2031 ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
2032 if(ivideo->chip != XGI_20) {
2033 reg = (reg & 0x0c) >> 2;
2034 if(ivideo->revision_id == 2) {
2035 if(reg & 0x01) reg = 0x02;
2036 else reg = 0x00;
2037 }
2038 if(reg == 0x02) ivideo->video_size <<= 1;
2039 else if(reg == 0x03) ivideo->video_size <<= 2;
2040 }
2041 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042#endif
2043 default:
2044 return -1;
2045 }
2046 return 0;
2047}
2048
2049/* -------------- video bridge device detection --------------- */
2050
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002051static void __devinit
2052sisfb_detect_VB_connect(struct sis_video_info *ivideo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053{
2054 u8 cr32, temp;
2055
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002056 /* No CRT2 on XGI Z7 */
2057 if(ivideo->chip == XGI_20) {
2058 ivideo->sisfb_crt1off = 0;
2059 return;
2060 }
2061
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062#ifdef CONFIG_FB_SIS_300
2063 if(ivideo->sisvga_engine == SIS_300_VGA) {
2064 inSISIDXREG(SISSR, 0x17, temp);
2065 if((temp & 0x0F) && (ivideo->chip != SIS_300)) {
2066 /* PAL/NTSC is stored on SR16 on such machines */
2067 if(!(ivideo->vbflags & (TV_PAL | TV_NTSC | TV_PALM | TV_PALN))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002068 inSISIDXREG(SISSR, 0x16, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 if(temp & 0x20)
2070 ivideo->vbflags |= TV_PAL;
2071 else
2072 ivideo->vbflags |= TV_NTSC;
2073 }
2074 }
2075 }
2076#endif
2077
2078 inSISIDXREG(SISCR, 0x32, cr32);
2079
2080 if(cr32 & SIS_CRT1) {
2081 ivideo->sisfb_crt1off = 0;
2082 } else {
2083 ivideo->sisfb_crt1off = (cr32 & 0xDF) ? 1 : 0;
2084 }
2085
2086 ivideo->vbflags &= ~(CRT2_TV | CRT2_LCD | CRT2_VGA);
2087
2088 if(cr32 & SIS_VB_TV) ivideo->vbflags |= CRT2_TV;
2089 if(cr32 & SIS_VB_LCD) ivideo->vbflags |= CRT2_LCD;
2090 if(cr32 & SIS_VB_CRT2) ivideo->vbflags |= CRT2_VGA;
2091
2092 /* Check given parms for hardware compatibility.
2093 * (Cannot do this in the search_xx routines since we don't
2094 * know what hardware we are running on then)
2095 */
2096
2097 if(ivideo->chip != SIS_550) {
2098 ivideo->sisfb_dstn = ivideo->sisfb_fstn = 0;
2099 }
2100
2101 if(ivideo->sisfb_tvplug != -1) {
2102 if( (ivideo->sisvga_engine != SIS_315_VGA) ||
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002103 (!(ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 if(ivideo->sisfb_tvplug & TV_YPBPR) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002105 ivideo->sisfb_tvplug = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 printk(KERN_ERR "sisfb: YPbPr not supported\n");
2107 }
2108 }
2109 }
2110 if(ivideo->sisfb_tvplug != -1) {
2111 if( (ivideo->sisvga_engine != SIS_315_VGA) ||
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002112 (!(ivideo->vbflags2 & VB2_SISHIVISIONBRIDGE)) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 if(ivideo->sisfb_tvplug & TV_HIVISION) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002114 ivideo->sisfb_tvplug = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 printk(KERN_ERR "sisfb: HiVision not supported\n");
2116 }
2117 }
2118 }
2119 if(ivideo->sisfb_tvstd != -1) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002120 if( (!(ivideo->vbflags2 & VB2_SISBRIDGE)) &&
2121 (!((ivideo->sisvga_engine == SIS_315_VGA) &&
2122 (ivideo->vbflags2 & VB2_CHRONTEL))) ) {
Roel Kluin5ab94812009-12-15 16:46:23 -08002123 if(ivideo->sisfb_tvstd & (TV_PALM | TV_PALN | TV_NTSCJ)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002124 ivideo->sisfb_tvstd = -1;
2125 printk(KERN_ERR "sisfb: PALM/PALN/NTSCJ not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 }
2127 }
2128 }
2129
2130 /* Detect/set TV plug & type */
2131 if(ivideo->sisfb_tvplug != -1) {
2132 ivideo->vbflags |= ivideo->sisfb_tvplug;
2133 } else {
2134 if(cr32 & SIS_VB_YPBPR) ivideo->vbflags |= (TV_YPBPR|TV_YPBPR525I); /* default: 480i */
2135 else if(cr32 & SIS_VB_HIVISION) ivideo->vbflags |= TV_HIVISION;
2136 else if(cr32 & SIS_VB_SCART) ivideo->vbflags |= TV_SCART;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002137 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 if(cr32 & SIS_VB_SVIDEO) ivideo->vbflags |= TV_SVIDEO;
2139 if(cr32 & SIS_VB_COMPOSITE) ivideo->vbflags |= TV_AVIDEO;
2140 }
2141 }
2142
2143 if(!(ivideo->vbflags & (TV_YPBPR | TV_HIVISION))) {
2144 if(ivideo->sisfb_tvstd != -1) {
2145 ivideo->vbflags &= ~(TV_NTSC | TV_PAL | TV_PALM | TV_PALN | TV_NTSCJ);
2146 ivideo->vbflags |= ivideo->sisfb_tvstd;
2147 }
2148 if(ivideo->vbflags & TV_SCART) {
2149 ivideo->vbflags &= ~(TV_NTSC | TV_PALM | TV_PALN | TV_NTSCJ);
2150 ivideo->vbflags |= TV_PAL;
2151 }
2152 if(!(ivideo->vbflags & (TV_PAL | TV_NTSC | TV_PALM | TV_PALN | TV_NTSCJ))) {
2153 if(ivideo->sisvga_engine == SIS_300_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002154 inSISIDXREG(SISSR, 0x38, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 if(temp & 0x01) ivideo->vbflags |= TV_PAL;
2156 else ivideo->vbflags |= TV_NTSC;
2157 } else if((ivideo->chip <= SIS_315PRO) || (ivideo->chip >= SIS_330)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002158 inSISIDXREG(SISSR, 0x38, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 if(temp & 0x01) ivideo->vbflags |= TV_PAL;
2160 else ivideo->vbflags |= TV_NTSC;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002161 } else {
2162 inSISIDXREG(SISCR, 0x79, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 if(temp & 0x20) ivideo->vbflags |= TV_PAL;
2164 else ivideo->vbflags |= TV_NTSC;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 }
2167 }
2168
2169 /* Copy forceCRT1 option to CRT1off if option is given */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002170 if(ivideo->sisfb_forcecrt1 != -1) {
2171 ivideo->sisfb_crt1off = (ivideo->sisfb_forcecrt1) ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 }
2173}
2174
2175/* ------------------ Sensing routines ------------------ */
2176
Richard Knutssonc30660ea2007-02-12 00:55:06 -08002177static bool __devinit
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002178sisfb_test_DDC1(struct sis_video_info *ivideo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179{
2180 unsigned short old;
2181 int count = 48;
2182
2183 old = SiS_ReadDDC1Bit(&ivideo->SiS_Pr);
2184 do {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002185 if(old != SiS_ReadDDC1Bit(&ivideo->SiS_Pr)) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 } while(count--);
Richard Knutssonc30660ea2007-02-12 00:55:06 -08002187 return (count != -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188}
2189
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002190static void __devinit
2191sisfb_sense_crt1(struct sis_video_info *ivideo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192{
Richard Knutssonc30660ea2007-02-12 00:55:06 -08002193 bool mustwait = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 u8 sr1F, cr17;
2195#ifdef CONFIG_FB_SIS_315
2196 u8 cr63=0;
2197#endif
2198 u16 temp = 0xffff;
2199 int i;
2200
2201 inSISIDXREG(SISSR,0x1F,sr1F);
2202 orSISIDXREG(SISSR,0x1F,0x04);
2203 andSISIDXREG(SISSR,0x1F,0x3F);
Richard Knutssonc30660ea2007-02-12 00:55:06 -08002204 if(sr1F & 0xc0) mustwait = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
2206#ifdef CONFIG_FB_SIS_315
2207 if(ivideo->sisvga_engine == SIS_315_VGA) {
2208 inSISIDXREG(SISCR,ivideo->SiS_Pr.SiS_MyCR63,cr63);
2209 cr63 &= 0x40;
2210 andSISIDXREG(SISCR,ivideo->SiS_Pr.SiS_MyCR63,0xBF);
2211 }
2212#endif
2213
2214 inSISIDXREG(SISCR,0x17,cr17);
2215 cr17 &= 0x80;
2216 if(!cr17) {
2217 orSISIDXREG(SISCR,0x17,0x80);
Richard Knutssonc30660ea2007-02-12 00:55:06 -08002218 mustwait = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 outSISIDXREG(SISSR, 0x00, 0x01);
2220 outSISIDXREG(SISSR, 0x00, 0x03);
2221 }
2222
2223 if(mustwait) {
2224 for(i=0; i < 10; i++) sisfbwaitretracecrt1(ivideo);
2225 }
2226
2227#ifdef CONFIG_FB_SIS_315
2228 if(ivideo->chip >= SIS_330) {
2229 andSISIDXREG(SISCR,0x32,~0x20);
2230 if(ivideo->chip >= SIS_340) {
2231 outSISIDXREG(SISCR, 0x57, 0x4a);
2232 } else {
2233 outSISIDXREG(SISCR, 0x57, 0x5f);
2234 }
2235 orSISIDXREG(SISCR, 0x53, 0x02);
2236 while((inSISREG(SISINPSTAT)) & 0x01) break;
2237 while(!((inSISREG(SISINPSTAT)) & 0x01)) break;
2238 if((inSISREG(SISMISCW)) & 0x10) temp = 1;
2239 andSISIDXREG(SISCR, 0x53, 0xfd);
2240 andSISIDXREG(SISCR, 0x57, 0x00);
2241 }
2242#endif
2243
2244 if(temp == 0xffff) {
2245 i = 3;
2246 do {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002247 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags,
2248 ivideo->sisvga_engine, 0, 0, NULL, ivideo->vbflags2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 } while(((temp == 0) || (temp == 0xffff)) && i--);
2250
2251 if((temp == 0) || (temp == 0xffff)) {
2252 if(sisfb_test_DDC1(ivideo)) temp = 1;
2253 }
2254 }
2255
2256 if((temp) && (temp != 0xffff)) {
2257 orSISIDXREG(SISCR,0x32,0x20);
2258 }
2259
2260#ifdef CONFIG_FB_SIS_315
2261 if(ivideo->sisvga_engine == SIS_315_VGA) {
2262 setSISIDXREG(SISCR,ivideo->SiS_Pr.SiS_MyCR63,0xBF,cr63);
2263 }
2264#endif
2265
2266 setSISIDXREG(SISCR,0x17,0x7F,cr17);
2267
2268 outSISIDXREG(SISSR,0x1F,sr1F);
2269}
2270
2271/* Determine and detect attached devices on SiS30x */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002272static void __devinit
2273SiS_SenseLCD(struct sis_video_info *ivideo)
2274{
2275 unsigned char buffer[256];
2276 unsigned short temp, realcrtno, i;
2277 u8 reg, cr37 = 0, paneltype = 0;
2278 u16 xres, yres;
2279
Richard Knutssonc30660ea2007-02-12 00:55:06 -08002280 ivideo->SiS_Pr.PanelSelfDetected = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002281
2282 /* LCD detection only for TMDS bridges */
2283 if(!(ivideo->vbflags2 & VB2_SISTMDSBRIDGE))
2284 return;
2285 if(ivideo->vbflags2 & VB2_30xBDH)
2286 return;
2287
2288 /* If LCD already set up by BIOS, skip it */
2289 inSISIDXREG(SISCR, 0x32, reg);
2290 if(reg & 0x08)
2291 return;
2292
2293 realcrtno = 1;
2294 if(ivideo->SiS_Pr.DDCPortMixup)
2295 realcrtno = 0;
2296
2297 /* Check DDC capabilities */
2298 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine,
2299 realcrtno, 0, &buffer[0], ivideo->vbflags2);
2300
2301 if((!temp) || (temp == 0xffff) || (!(temp & 0x02)))
2302 return;
2303
2304 /* Read DDC data */
2305 i = 3; /* Number of retrys */
2306 do {
2307 temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags,
2308 ivideo->sisvga_engine, realcrtno, 1,
2309 &buffer[0], ivideo->vbflags2);
2310 } while((temp) && i--);
2311
2312 if(temp)
2313 return;
2314
2315 /* No digital device */
2316 if(!(buffer[0x14] & 0x80))
2317 return;
2318
2319 /* First detailed timing preferred timing? */
2320 if(!(buffer[0x18] & 0x02))
2321 return;
2322
2323 xres = buffer[0x38] | ((buffer[0x3a] & 0xf0) << 4);
2324 yres = buffer[0x3b] | ((buffer[0x3d] & 0xf0) << 4);
2325
2326 switch(xres) {
2327 case 1024:
2328 if(yres == 768)
2329 paneltype = 0x02;
2330 break;
2331 case 1280:
2332 if(yres == 1024)
2333 paneltype = 0x03;
2334 break;
2335 case 1600:
2336 if((yres == 1200) && (ivideo->vbflags2 & VB2_30xC))
2337 paneltype = 0x0b;
2338 break;
2339 }
2340
2341 if(!paneltype)
2342 return;
2343
2344 if(buffer[0x23])
2345 cr37 |= 0x10;
2346
2347 if((buffer[0x47] & 0x18) == 0x18)
2348 cr37 |= ((((buffer[0x47] & 0x06) ^ 0x06) << 5) | 0x20);
2349 else
2350 cr37 |= 0xc0;
2351
2352 outSISIDXREG(SISCR, 0x36, paneltype);
2353 cr37 &= 0xf1;
2354 setSISIDXREG(SISCR, 0x37, 0x0c, cr37);
2355 orSISIDXREG(SISCR, 0x32, 0x08);
2356
Richard Knutssonc30660ea2007-02-12 00:55:06 -08002357 ivideo->SiS_Pr.PanelSelfDetected = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002358}
2359
2360static int __devinit
2361SISDoSense(struct sis_video_info *ivideo, u16 type, u16 test)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362{
2363 int temp, mytest, result, i, j;
2364
2365 for(j = 0; j < 10; j++) {
2366 result = 0;
2367 for(i = 0; i < 3; i++) {
2368 mytest = test;
2369 outSISIDXREG(SISPART4,0x11,(type & 0x00ff));
2370 temp = (type >> 8) | (mytest & 0x00ff);
2371 setSISIDXREG(SISPART4,0x10,0xe0,temp);
2372 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x1500);
2373 mytest >>= 8;
2374 mytest &= 0x7f;
2375 inSISIDXREG(SISPART4,0x03,temp);
2376 temp ^= 0x0e;
2377 temp &= mytest;
2378 if(temp == mytest) result++;
2379#if 1
2380 outSISIDXREG(SISPART4,0x11,0x00);
2381 andSISIDXREG(SISPART4,0x10,0xe0);
2382 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x1000);
2383#endif
2384 }
2385 if((result == 0) || (result >= 2)) break;
2386 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002387 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388}
2389
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002390static void __devinit
2391SiS_Sense30x(struct sis_video_info *ivideo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392{
2393 u8 backupP4_0d,backupP2_00,backupP2_4d,backupSR_1e,biosflag=0;
2394 u16 svhs=0, svhs_c=0;
2395 u16 cvbs=0, cvbs_c=0;
2396 u16 vga2=0, vga2_c=0;
2397 int myflag, result;
2398 char stdstr[] = "sisfb: Detected";
2399 char tvstr[] = "TV connected to";
2400
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002401 if(ivideo->vbflags2 & VB2_301) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 svhs = 0x00b9; cvbs = 0x00b3; vga2 = 0x00d1;
2403 inSISIDXREG(SISPART4,0x01,myflag);
2404 if(myflag & 0x04) {
2405 svhs = 0x00dd; cvbs = 0x00ee; vga2 = 0x00fd;
2406 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002407 } else if(ivideo->vbflags2 & (VB2_301B | VB2_302B)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 svhs = 0x016b; cvbs = 0x0174; vga2 = 0x0190;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002409 } else if(ivideo->vbflags2 & (VB2_301LV | VB2_302LV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 svhs = 0x0200; cvbs = 0x0100;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002411 } else if(ivideo->vbflags2 & (VB2_301C | VB2_302ELV | VB2_307T | VB2_307LV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 svhs = 0x016b; cvbs = 0x0110; vga2 = 0x0190;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002413 } else
2414 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
2416 vga2_c = 0x0e08; svhs_c = 0x0404; cvbs_c = 0x0804;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002417 if(ivideo->vbflags & (VB2_301LV|VB2_302LV|VB2_302ELV|VB2_307LV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 svhs_c = 0x0408; cvbs_c = 0x0808;
2419 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002420
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 biosflag = 2;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002422 if(ivideo->haveXGIROM) {
2423 biosflag = ivideo->bios_abase[0x58] & 0x03;
2424 } else if(ivideo->newrom) {
2425 if(ivideo->bios_abase[0x5d] & 0x04) biosflag |= 0x01;
2426 } else if(ivideo->sisvga_engine == SIS_300_VGA) {
2427 if(ivideo->bios_abase) {
2428 biosflag = ivideo->bios_abase[0xfe] & 0x03;
2429 }
2430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
2432 if(ivideo->chip == SIS_300) {
2433 inSISIDXREG(SISSR,0x3b,myflag);
2434 if(!(myflag & 0x01)) vga2 = vga2_c = 0;
2435 }
2436
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002437 if(!(ivideo->vbflags2 & VB2_SISVGA2BRIDGE)) {
2438 vga2 = vga2_c = 0;
2439 }
2440
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 inSISIDXREG(SISSR,0x1e,backupSR_1e);
2442 orSISIDXREG(SISSR,0x1e,0x20);
2443
2444 inSISIDXREG(SISPART4,0x0d,backupP4_0d);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002445 if(ivideo->vbflags2 & VB2_30xC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 setSISIDXREG(SISPART4,0x0d,~0x07,0x01);
2447 } else {
2448 orSISIDXREG(SISPART4,0x0d,0x04);
2449 }
2450 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x2000);
2451
2452 inSISIDXREG(SISPART2,0x00,backupP2_00);
2453 outSISIDXREG(SISPART2,0x00,((backupP2_00 | 0x1c) & 0xfc));
2454
2455 inSISIDXREG(SISPART2,0x4d,backupP2_4d);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002456 if(ivideo->vbflags2 & VB2_SISYPBPRBRIDGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 outSISIDXREG(SISPART2,0x4d,(backupP2_4d & ~0x10));
2458 }
2459
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002460 if(!(ivideo->vbflags2 & VB2_30xCLV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 SISDoSense(ivideo, 0, 0);
2462 }
2463
2464 andSISIDXREG(SISCR, 0x32, ~0x14);
2465
2466 if(vga2_c || vga2) {
2467 if(SISDoSense(ivideo, vga2, vga2_c)) {
2468 if(biosflag & 0x01) {
2469 printk(KERN_INFO "%s %s SCART output\n", stdstr, tvstr);
2470 orSISIDXREG(SISCR, 0x32, 0x04);
2471 } else {
2472 printk(KERN_INFO "%s secondary VGA connection\n", stdstr);
2473 orSISIDXREG(SISCR, 0x32, 0x10);
2474 }
2475 }
2476 }
2477
2478 andSISIDXREG(SISCR, 0x32, 0x3f);
2479
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002480 if(ivideo->vbflags2 & VB2_30xCLV) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 orSISIDXREG(SISPART4,0x0d,0x04);
2482 }
2483
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002484 if((ivideo->sisvga_engine == SIS_315_VGA) && (ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 outSISIDXREG(SISPART2,0x4d,(backupP2_4d | 0x10));
2486 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x2000);
2487 if((result = SISDoSense(ivideo, svhs, 0x0604))) {
2488 if((result = SISDoSense(ivideo, cvbs, 0x0804))) {
2489 printk(KERN_INFO "%s %s YPbPr component output\n", stdstr, tvstr);
2490 orSISIDXREG(SISCR,0x32,0x80);
2491 }
2492 }
2493 outSISIDXREG(SISPART2,0x4d,backupP2_4d);
2494 }
2495
2496 andSISIDXREG(SISCR, 0x32, ~0x03);
2497
2498 if(!(ivideo->vbflags & TV_YPBPR)) {
2499 if((result = SISDoSense(ivideo, svhs, svhs_c))) {
2500 printk(KERN_INFO "%s %s SVIDEO output\n", stdstr, tvstr);
2501 orSISIDXREG(SISCR, 0x32, 0x02);
2502 }
2503 if((biosflag & 0x02) || (!result)) {
2504 if(SISDoSense(ivideo, cvbs, cvbs_c)) {
2505 printk(KERN_INFO "%s %s COMPOSITE output\n", stdstr, tvstr);
2506 orSISIDXREG(SISCR, 0x32, 0x01);
2507 }
2508 }
2509 }
2510
2511 SISDoSense(ivideo, 0, 0);
2512
2513 outSISIDXREG(SISPART2,0x00,backupP2_00);
2514 outSISIDXREG(SISPART4,0x0d,backupP4_0d);
2515 outSISIDXREG(SISSR,0x1e,backupSR_1e);
2516
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002517 if(ivideo->vbflags2 & VB2_30xCLV) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 inSISIDXREG(SISPART2,0x00,biosflag);
2519 if(biosflag & 0x20) {
2520 for(myflag = 2; myflag > 0; myflag--) {
2521 biosflag ^= 0x20;
2522 outSISIDXREG(SISPART2,0x00,biosflag);
2523 }
2524 }
2525 }
2526
2527 outSISIDXREG(SISPART2,0x00,backupP2_00);
2528}
2529
2530/* Determine and detect attached TV's on Chrontel */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002531static void __devinit
2532SiS_SenseCh(struct sis_video_info *ivideo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533{
2534#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
2535 u8 temp1, temp2;
2536 char stdstr[] = "sisfb: Chrontel: Detected TV connected to";
2537#endif
2538#ifdef CONFIG_FB_SIS_300
2539 unsigned char test[3];
2540 int i;
2541#endif
2542
2543 if(ivideo->chip < SIS_315H) {
2544
2545#ifdef CONFIG_FB_SIS_300
2546 ivideo->SiS_Pr.SiS_IF_DEF_CH70xx = 1; /* Chrontel 700x */
2547 SiS_SetChrontelGPIO(&ivideo->SiS_Pr, 0x9c); /* Set general purpose IO for Chrontel communication */
2548 SiS_DDC2Delay(&ivideo->SiS_Pr, 1000);
2549 temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x25);
2550 /* See Chrontel TB31 for explanation */
2551 temp2 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0e);
2552 if(((temp2 & 0x07) == 0x01) || (temp2 & 0x04)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002553 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0e, 0x0b);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 SiS_DDC2Delay(&ivideo->SiS_Pr, 300);
2555 }
2556 temp2 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x25);
2557 if(temp2 != temp1) temp1 = temp2;
2558
2559 if((temp1 >= 0x22) && (temp1 <= 0x50)) {
2560 /* Read power status */
2561 temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0e);
2562 if((temp1 & 0x03) != 0x03) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002563 /* Power all outputs */
2564 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0e,0x0b);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 SiS_DDC2Delay(&ivideo->SiS_Pr, 300);
2566 }
2567 /* Sense connected TV devices */
2568 for(i = 0; i < 3; i++) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002569 SiS_SetCH700x(&ivideo->SiS_Pr, 0x10, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002571 SiS_SetCH700x(&ivideo->SiS_Pr, 0x10, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
2573 temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x10);
2574 if(!(temp1 & 0x08)) test[i] = 0x02;
2575 else if(!(temp1 & 0x02)) test[i] = 0x01;
2576 else test[i] = 0;
2577 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
2578 }
2579
2580 if(test[0] == test[1]) temp1 = test[0];
2581 else if(test[0] == test[2]) temp1 = test[0];
2582 else if(test[1] == test[2]) temp1 = test[1];
2583 else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002584 printk(KERN_INFO
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 "sisfb: TV detection unreliable - test results varied\n");
2586 temp1 = test[2];
2587 }
2588 if(temp1 == 0x02) {
2589 printk(KERN_INFO "%s SVIDEO output\n", stdstr);
2590 ivideo->vbflags |= TV_SVIDEO;
2591 orSISIDXREG(SISCR, 0x32, 0x02);
2592 andSISIDXREG(SISCR, 0x32, ~0x05);
2593 } else if (temp1 == 0x01) {
2594 printk(KERN_INFO "%s CVBS output\n", stdstr);
2595 ivideo->vbflags |= TV_AVIDEO;
2596 orSISIDXREG(SISCR, 0x32, 0x01);
2597 andSISIDXREG(SISCR, 0x32, ~0x06);
2598 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002599 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x0e, 0x01, 0xF8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 andSISIDXREG(SISCR, 0x32, ~0x07);
2601 }
2602 } else if(temp1 == 0) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002603 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x0e, 0x01, 0xF8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 andSISIDXREG(SISCR, 0x32, ~0x07);
2605 }
2606 /* Set general purpose IO for Chrontel communication */
2607 SiS_SetChrontelGPIO(&ivideo->SiS_Pr, 0x00);
2608#endif
2609
2610 } else {
2611
2612#ifdef CONFIG_FB_SIS_315
2613 ivideo->SiS_Pr.SiS_IF_DEF_CH70xx = 2; /* Chrontel 7019 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002614 temp1 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x49);
2615 SiS_SetCH701x(&ivideo->SiS_Pr, 0x49, 0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
2617 temp2 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x20);
2618 temp2 |= 0x01;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002619 SiS_SetCH701x(&ivideo->SiS_Pr, 0x20, temp2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
2621 temp2 ^= 0x01;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002622 SiS_SetCH701x(&ivideo->SiS_Pr, 0x20, temp2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
2624 temp2 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x20);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002625 SiS_SetCH701x(&ivideo->SiS_Pr, 0x49, temp1);
2626 temp1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 if(temp2 & 0x02) temp1 |= 0x01;
2628 if(temp2 & 0x10) temp1 |= 0x01;
2629 if(temp2 & 0x04) temp1 |= 0x02;
2630 if( (temp1 & 0x01) && (temp1 & 0x02) ) temp1 = 0x04;
2631 switch(temp1) {
2632 case 0x01:
2633 printk(KERN_INFO "%s CVBS output\n", stdstr);
2634 ivideo->vbflags |= TV_AVIDEO;
2635 orSISIDXREG(SISCR, 0x32, 0x01);
2636 andSISIDXREG(SISCR, 0x32, ~0x06);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002637 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 case 0x02:
2639 printk(KERN_INFO "%s SVIDEO output\n", stdstr);
2640 ivideo->vbflags |= TV_SVIDEO;
2641 orSISIDXREG(SISCR, 0x32, 0x02);
2642 andSISIDXREG(SISCR, 0x32, ~0x05);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002643 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 case 0x04:
2645 printk(KERN_INFO "%s SCART output\n", stdstr);
2646 orSISIDXREG(SISCR, 0x32, 0x04);
2647 andSISIDXREG(SISCR, 0x32, ~0x03);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002648 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 default:
2650 andSISIDXREG(SISCR, 0x32, ~0x07);
2651 }
2652#endif
2653 }
2654}
2655
Thomas Winischhofer544393f2005-09-09 13:04:45 -07002656static void __devinit
2657sisfb_get_VB_type(struct sis_video_info *ivideo)
2658{
2659 char stdstr[] = "sisfb: Detected";
2660 char bridgestr[] = "video bridge";
2661 u8 vb_chipid;
2662 u8 reg;
2663
2664 /* No CRT2 on XGI Z7 */
2665 if(ivideo->chip == XGI_20)
2666 return;
2667
2668 inSISIDXREG(SISPART4, 0x00, vb_chipid);
2669 switch(vb_chipid) {
2670 case 0x01:
2671 inSISIDXREG(SISPART4, 0x01, reg);
2672 if(reg < 0xb0) {
2673 ivideo->vbflags |= VB_301; /* Deprecated */
2674 ivideo->vbflags2 |= VB2_301;
2675 printk(KERN_INFO "%s SiS301 %s\n", stdstr, bridgestr);
2676 } else if(reg < 0xc0) {
2677 ivideo->vbflags |= VB_301B; /* Deprecated */
2678 ivideo->vbflags2 |= VB2_301B;
2679 inSISIDXREG(SISPART4,0x23,reg);
2680 if(!(reg & 0x02)) {
2681 ivideo->vbflags |= VB_30xBDH; /* Deprecated */
2682 ivideo->vbflags2 |= VB2_30xBDH;
2683 printk(KERN_INFO "%s SiS301B-DH %s\n", stdstr, bridgestr);
2684 } else {
2685 printk(KERN_INFO "%s SiS301B %s\n", stdstr, bridgestr);
2686 }
2687 } else if(reg < 0xd0) {
2688 ivideo->vbflags |= VB_301C; /* Deprecated */
2689 ivideo->vbflags2 |= VB2_301C;
2690 printk(KERN_INFO "%s SiS301C %s\n", stdstr, bridgestr);
2691 } else if(reg < 0xe0) {
2692 ivideo->vbflags |= VB_301LV; /* Deprecated */
2693 ivideo->vbflags2 |= VB2_301LV;
2694 printk(KERN_INFO "%s SiS301LV %s\n", stdstr, bridgestr);
2695 } else if(reg <= 0xe1) {
2696 inSISIDXREG(SISPART4,0x39,reg);
2697 if(reg == 0xff) {
2698 ivideo->vbflags |= VB_302LV; /* Deprecated */
2699 ivideo->vbflags2 |= VB2_302LV;
2700 printk(KERN_INFO "%s SiS302LV %s\n", stdstr, bridgestr);
2701 } else {
2702 ivideo->vbflags |= VB_301C; /* Deprecated */
2703 ivideo->vbflags2 |= VB2_301C;
2704 printk(KERN_INFO "%s SiS301C(P4) %s\n", stdstr, bridgestr);
2705#if 0
2706 ivideo->vbflags |= VB_302ELV; /* Deprecated */
2707 ivideo->vbflags2 |= VB2_302ELV;
2708 printk(KERN_INFO "%s SiS302ELV %s\n", stdstr, bridgestr);
2709#endif
2710 }
2711 }
2712 break;
2713 case 0x02:
2714 ivideo->vbflags |= VB_302B; /* Deprecated */
2715 ivideo->vbflags2 |= VB2_302B;
2716 printk(KERN_INFO "%s SiS302B %s\n", stdstr, bridgestr);
2717 break;
2718 }
2719
2720 if((!(ivideo->vbflags2 & VB2_VIDEOBRIDGE)) && (ivideo->chip != SIS_300)) {
2721 inSISIDXREG(SISCR, 0x37, reg);
2722 reg &= SIS_EXTERNAL_CHIP_MASK;
2723 reg >>= 1;
2724 if(ivideo->sisvga_engine == SIS_300_VGA) {
2725#ifdef CONFIG_FB_SIS_300
2726 switch(reg) {
2727 case SIS_EXTERNAL_CHIP_LVDS:
2728 ivideo->vbflags |= VB_LVDS; /* Deprecated */
2729 ivideo->vbflags2 |= VB2_LVDS;
2730 break;
2731 case SIS_EXTERNAL_CHIP_TRUMPION:
2732 ivideo->vbflags |= (VB_LVDS | VB_TRUMPION); /* Deprecated */
2733 ivideo->vbflags2 |= (VB2_LVDS | VB2_TRUMPION);
2734 break;
2735 case SIS_EXTERNAL_CHIP_CHRONTEL:
2736 ivideo->vbflags |= VB_CHRONTEL; /* Deprecated */
2737 ivideo->vbflags2 |= VB2_CHRONTEL;
2738 break;
2739 case SIS_EXTERNAL_CHIP_LVDS_CHRONTEL:
2740 ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */
2741 ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL);
2742 break;
2743 }
2744 if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 1;
2745#endif
2746 } else if(ivideo->chip < SIS_661) {
2747#ifdef CONFIG_FB_SIS_315
2748 switch (reg) {
2749 case SIS310_EXTERNAL_CHIP_LVDS:
2750 ivideo->vbflags |= VB_LVDS; /* Deprecated */
2751 ivideo->vbflags2 |= VB2_LVDS;
2752 break;
2753 case SIS310_EXTERNAL_CHIP_LVDS_CHRONTEL:
2754 ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */
2755 ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL);
2756 break;
2757 }
2758 if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 2;
2759#endif
2760 } else if(ivideo->chip >= SIS_661) {
2761#ifdef CONFIG_FB_SIS_315
2762 inSISIDXREG(SISCR, 0x38, reg);
2763 reg >>= 5;
2764 switch(reg) {
2765 case 0x02:
2766 ivideo->vbflags |= VB_LVDS; /* Deprecated */
2767 ivideo->vbflags2 |= VB2_LVDS;
2768 break;
2769 case 0x03:
2770 ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */
2771 ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL);
2772 break;
2773 case 0x04:
2774 ivideo->vbflags |= (VB_LVDS | VB_CONEXANT); /* Deprecated */
2775 ivideo->vbflags2 |= (VB2_LVDS | VB2_CONEXANT);
2776 break;
2777 }
2778 if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 2;
2779#endif
2780 }
2781 if(ivideo->vbflags2 & VB2_LVDS) {
2782 printk(KERN_INFO "%s LVDS transmitter\n", stdstr);
2783 }
2784 if((ivideo->sisvga_engine == SIS_300_VGA) && (ivideo->vbflags2 & VB2_TRUMPION)) {
2785 printk(KERN_INFO "%s Trumpion Zurac LCD scaler\n", stdstr);
2786 }
2787 if(ivideo->vbflags2 & VB2_CHRONTEL) {
2788 printk(KERN_INFO "%s Chrontel TV encoder\n", stdstr);
2789 }
2790 if((ivideo->chip >= SIS_661) && (ivideo->vbflags2 & VB2_CONEXANT)) {
2791 printk(KERN_INFO "%s Conexant external device\n", stdstr);
2792 }
2793 }
2794
2795 if(ivideo->vbflags2 & VB2_SISBRIDGE) {
2796 SiS_SenseLCD(ivideo);
2797 SiS_Sense30x(ivideo);
2798 } else if(ivideo->vbflags2 & VB2_CHRONTEL) {
2799 SiS_SenseCh(ivideo);
2800 }
2801}
2802
2803/* ---------- Engine initialization routines ------------ */
2804
2805static void
2806sisfb_engine_init(struct sis_video_info *ivideo)
2807{
2808
2809 /* Initialize command queue (we use MMIO only) */
2810
2811 /* BEFORE THIS IS CALLED, THE ENGINES *MUST* BE SYNC'ED */
2812
2813 ivideo->caps &= ~(TURBO_QUEUE_CAP |
2814 MMIO_CMD_QUEUE_CAP |
2815 VM_CMD_QUEUE_CAP |
2816 AGP_CMD_QUEUE_CAP);
2817
2818#ifdef CONFIG_FB_SIS_300
2819 if(ivideo->sisvga_engine == SIS_300_VGA) {
2820 u32 tqueue_pos;
2821 u8 tq_state;
2822
2823 tqueue_pos = (ivideo->video_size - ivideo->cmdQueueSize) / (64 * 1024);
2824
2825 inSISIDXREG(SISSR, IND_SIS_TURBOQUEUE_SET, tq_state);
2826 tq_state |= 0xf0;
2827 tq_state &= 0xfc;
2828 tq_state |= (u8)(tqueue_pos >> 8);
2829 outSISIDXREG(SISSR, IND_SIS_TURBOQUEUE_SET, tq_state);
2830
2831 outSISIDXREG(SISSR, IND_SIS_TURBOQUEUE_ADR, (u8)(tqueue_pos & 0xff));
2832
2833 ivideo->caps |= TURBO_QUEUE_CAP;
2834 }
2835#endif
2836
2837#ifdef CONFIG_FB_SIS_315
2838 if(ivideo->sisvga_engine == SIS_315_VGA) {
2839 u32 tempq = 0, templ;
2840 u8 temp;
2841
2842 if(ivideo->chip == XGI_20) {
2843 switch(ivideo->cmdQueueSize) {
2844 case (64 * 1024):
2845 temp = SIS_CMD_QUEUE_SIZE_Z7_64k;
2846 break;
2847 case (128 * 1024):
2848 default:
2849 temp = SIS_CMD_QUEUE_SIZE_Z7_128k;
2850 }
2851 } else {
2852 switch(ivideo->cmdQueueSize) {
2853 case (4 * 1024 * 1024):
2854 temp = SIS_CMD_QUEUE_SIZE_4M;
2855 break;
2856 case (2 * 1024 * 1024):
2857 temp = SIS_CMD_QUEUE_SIZE_2M;
2858 break;
2859 case (1 * 1024 * 1024):
2860 temp = SIS_CMD_QUEUE_SIZE_1M;
2861 break;
2862 default:
2863 case (512 * 1024):
2864 temp = SIS_CMD_QUEUE_SIZE_512k;
2865 }
2866 }
2867
2868 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_THRESHOLD, COMMAND_QUEUE_THRESHOLD);
2869 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_SET, SIS_CMD_QUEUE_RESET);
2870
2871 if((ivideo->chip >= XGI_40) && ivideo->modechanged) {
2872 /* Must disable dual pipe on XGI_40. Can't do
2873 * this in MMIO mode, because it requires
2874 * setting/clearing a bit in the MMIO fire trigger
2875 * register.
2876 */
2877 if(!((templ = MMIO_IN32(ivideo->mmio_vbase, 0x8240)) & (1 << 10))) {
2878
2879 MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, 0);
2880
2881 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_SET, (temp | SIS_VRAM_CMDQUEUE_ENABLE));
2882
2883 tempq = MMIO_IN32(ivideo->mmio_vbase, Q_READ_PTR);
2884 MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, tempq);
2885
2886 tempq = (u32)(ivideo->video_size - ivideo->cmdQueueSize);
2887 MMIO_OUT32(ivideo->mmio_vbase, Q_BASE_ADDR, tempq);
2888
2889 writel(0x16800000 + 0x8240, ivideo->video_vbase + tempq);
2890 writel(templ | (1 << 10), ivideo->video_vbase + tempq + 4);
2891 writel(0x168F0000, ivideo->video_vbase + tempq + 8);
2892 writel(0x168F0000, ivideo->video_vbase + tempq + 12);
2893
2894 MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, (tempq + 16));
2895
2896 sisfb_syncaccel(ivideo);
2897
2898 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_SET, SIS_CMD_QUEUE_RESET);
2899
2900 }
2901 }
2902
2903 tempq = MMIO_IN32(ivideo->mmio_vbase, MMIO_QUEUE_READPORT);
2904 MMIO_OUT32(ivideo->mmio_vbase, MMIO_QUEUE_WRITEPORT, tempq);
2905
2906 temp |= (SIS_MMIO_CMD_ENABLE | SIS_CMD_AUTO_CORR);
2907 outSISIDXREG(SISSR, IND_SIS_CMDQUEUE_SET, temp);
2908
2909 tempq = (u32)(ivideo->video_size - ivideo->cmdQueueSize);
2910 MMIO_OUT32(ivideo->mmio_vbase, MMIO_QUEUE_PHYBASE, tempq);
2911
2912 ivideo->caps |= MMIO_CMD_QUEUE_CAP;
2913 }
2914#endif
2915
2916 ivideo->engineok = 1;
2917}
2918
2919static void __devinit
2920sisfb_detect_lcd_type(struct sis_video_info *ivideo)
2921{
2922 u8 reg;
2923 int i;
2924
2925 inSISIDXREG(SISCR, 0x36, reg);
2926 reg &= 0x0f;
2927 if(ivideo->sisvga_engine == SIS_300_VGA) {
2928 ivideo->CRT2LCDType = sis300paneltype[reg];
2929 } else if(ivideo->chip >= SIS_661) {
2930 ivideo->CRT2LCDType = sis661paneltype[reg];
2931 } else {
2932 ivideo->CRT2LCDType = sis310paneltype[reg];
2933 if((ivideo->chip == SIS_550) && (sisfb_fstn)) {
2934 if((ivideo->CRT2LCDType != LCD_320x240_2) &&
2935 (ivideo->CRT2LCDType != LCD_320x240_3)) {
2936 ivideo->CRT2LCDType = LCD_320x240;
2937 }
2938 }
2939 }
2940
2941 if(ivideo->CRT2LCDType == LCD_UNKNOWN) {
2942 /* For broken BIOSes: Assume 1024x768, RGB18 */
2943 ivideo->CRT2LCDType = LCD_1024x768;
2944 setSISIDXREG(SISCR,0x36,0xf0,0x02);
2945 setSISIDXREG(SISCR,0x37,0xee,0x01);
2946 printk(KERN_DEBUG "sisfb: Invalid panel ID (%02x), assuming 1024x768, RGB18\n", reg);
2947 }
2948
2949 for(i = 0; i < SIS_LCD_NUMBER; i++) {
2950 if(ivideo->CRT2LCDType == sis_lcd_data[i].lcdtype) {
2951 ivideo->lcdxres = sis_lcd_data[i].xres;
2952 ivideo->lcdyres = sis_lcd_data[i].yres;
2953 ivideo->lcddefmodeidx = sis_lcd_data[i].default_mode_idx;
2954 break;
2955 }
2956 }
2957
2958#ifdef CONFIG_FB_SIS_300
2959 if(ivideo->SiS_Pr.SiS_CustomT == CUT_BARCO1366) {
2960 ivideo->lcdxres = 1360; ivideo->lcdyres = 1024;
2961 ivideo->lcddefmodeidx = DEFAULT_MODE_1360;
2962 } else if(ivideo->SiS_Pr.SiS_CustomT == CUT_PANEL848) {
2963 ivideo->lcdxres = 848; ivideo->lcdyres = 480;
2964 ivideo->lcddefmodeidx = DEFAULT_MODE_848;
2965 } else if(ivideo->SiS_Pr.SiS_CustomT == CUT_PANEL856) {
2966 ivideo->lcdxres = 856; ivideo->lcdyres = 480;
2967 ivideo->lcddefmodeidx = DEFAULT_MODE_856;
2968 }
2969#endif
2970
2971 printk(KERN_DEBUG "sisfb: Detected %dx%d flat panel\n",
2972 ivideo->lcdxres, ivideo->lcdyres);
2973}
2974
2975static void __devinit
2976sisfb_save_pdc_emi(struct sis_video_info *ivideo)
2977{
2978#ifdef CONFIG_FB_SIS_300
2979 /* Save the current PanelDelayCompensation if the LCD is currently used */
2980 if(ivideo->sisvga_engine == SIS_300_VGA) {
2981 if(ivideo->vbflags2 & (VB2_LVDS | VB2_30xBDH)) {
2982 int tmp;
2983 inSISIDXREG(SISCR,0x30,tmp);
2984 if(tmp & 0x20) {
2985 /* Currently on LCD? If yes, read current pdc */
2986 inSISIDXREG(SISPART1,0x13,ivideo->detectedpdc);
2987 ivideo->detectedpdc &= 0x3c;
2988 if(ivideo->SiS_Pr.PDC == -1) {
2989 /* Let option override detection */
2990 ivideo->SiS_Pr.PDC = ivideo->detectedpdc;
2991 }
2992 printk(KERN_INFO "sisfb: Detected LCD PDC 0x%02x\n",
2993 ivideo->detectedpdc);
2994 }
2995 if((ivideo->SiS_Pr.PDC != -1) &&
2996 (ivideo->SiS_Pr.PDC != ivideo->detectedpdc)) {
2997 printk(KERN_INFO "sisfb: Using LCD PDC 0x%02x\n",
2998 ivideo->SiS_Pr.PDC);
2999 }
3000 }
3001 }
3002#endif
3003
3004#ifdef CONFIG_FB_SIS_315
3005 if(ivideo->sisvga_engine == SIS_315_VGA) {
3006
3007 /* Try to find about LCDA */
3008 if(ivideo->vbflags2 & VB2_SISLCDABRIDGE) {
3009 int tmp;
3010 inSISIDXREG(SISPART1,0x13,tmp);
3011 if(tmp & 0x04) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003012 ivideo->SiS_Pr.SiS_UseLCDA = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003013 ivideo->detectedlcda = 0x03;
3014 }
3015 }
3016
3017 /* Save PDC */
3018 if(ivideo->vbflags2 & VB2_SISLVDSBRIDGE) {
3019 int tmp;
3020 inSISIDXREG(SISCR,0x30,tmp);
3021 if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) {
3022 /* Currently on LCD? If yes, read current pdc */
3023 u8 pdc;
3024 inSISIDXREG(SISPART1,0x2D,pdc);
3025 ivideo->detectedpdc = (pdc & 0x0f) << 1;
3026 ivideo->detectedpdca = (pdc & 0xf0) >> 3;
3027 inSISIDXREG(SISPART1,0x35,pdc);
3028 ivideo->detectedpdc |= ((pdc >> 7) & 0x01);
3029 inSISIDXREG(SISPART1,0x20,pdc);
3030 ivideo->detectedpdca |= ((pdc >> 6) & 0x01);
3031 if(ivideo->newrom) {
3032 /* New ROM invalidates other PDC resp. */
3033 if(ivideo->detectedlcda != 0xff) {
3034 ivideo->detectedpdc = 0xff;
3035 } else {
3036 ivideo->detectedpdca = 0xff;
3037 }
3038 }
3039 if(ivideo->SiS_Pr.PDC == -1) {
3040 if(ivideo->detectedpdc != 0xff) {
3041 ivideo->SiS_Pr.PDC = ivideo->detectedpdc;
3042 }
3043 }
3044 if(ivideo->SiS_Pr.PDCA == -1) {
3045 if(ivideo->detectedpdca != 0xff) {
3046 ivideo->SiS_Pr.PDCA = ivideo->detectedpdca;
3047 }
3048 }
3049 if(ivideo->detectedpdc != 0xff) {
3050 printk(KERN_INFO
3051 "sisfb: Detected LCD PDC 0x%02x (for LCD=CRT2)\n",
3052 ivideo->detectedpdc);
3053 }
3054 if(ivideo->detectedpdca != 0xff) {
3055 printk(KERN_INFO
3056 "sisfb: Detected LCD PDC1 0x%02x (for LCD=CRT1)\n",
3057 ivideo->detectedpdca);
3058 }
3059 }
3060
3061 /* Save EMI */
3062 if(ivideo->vbflags2 & VB2_SISEMIBRIDGE) {
3063 inSISIDXREG(SISPART4,0x30,ivideo->SiS_Pr.EMI_30);
3064 inSISIDXREG(SISPART4,0x31,ivideo->SiS_Pr.EMI_31);
3065 inSISIDXREG(SISPART4,0x32,ivideo->SiS_Pr.EMI_32);
3066 inSISIDXREG(SISPART4,0x33,ivideo->SiS_Pr.EMI_33);
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003067 ivideo->SiS_Pr.HaveEMI = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003068 if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003069 ivideo->SiS_Pr.HaveEMILCD = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003070 }
3071 }
3072 }
3073
3074 /* Let user override detected PDCs (all bridges) */
3075 if(ivideo->vbflags2 & VB2_30xBLV) {
3076 if((ivideo->SiS_Pr.PDC != -1) &&
3077 (ivideo->SiS_Pr.PDC != ivideo->detectedpdc)) {
3078 printk(KERN_INFO "sisfb: Using LCD PDC 0x%02x (for LCD=CRT2)\n",
3079 ivideo->SiS_Pr.PDC);
3080 }
3081 if((ivideo->SiS_Pr.PDCA != -1) &&
3082 (ivideo->SiS_Pr.PDCA != ivideo->detectedpdca)) {
3083 printk(KERN_INFO "sisfb: Using LCD PDC1 0x%02x (for LCD=CRT1)\n",
3084 ivideo->SiS_Pr.PDCA);
3085 }
3086 }
3087
3088 }
3089#endif
3090}
3091
3092/* -------------------- Memory manager routines ---------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093
3094static u32 __devinit
3095sisfb_getheapstart(struct sis_video_info *ivideo)
3096{
3097 u32 ret = ivideo->sisfb_parm_mem * 1024;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003098 u32 maxoffs = ivideo->video_size - ivideo->hwcursor_size - ivideo->cmdQueueSize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 u32 def;
3100
3101 /* Calculate heap start = end of memory for console
3102 *
3103 * CCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDHHHHQQQQQQQQQQ
3104 * C = console, D = heap, H = HWCursor, Q = cmd-queue
3105 *
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003106 * On 76x in UMA+LFB mode, the layout is as follows:
3107 * DDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCHHHHQQQQQQQQQQQ
3108 * where the heap is the entire UMA area, eventually
3109 * into the LFB area if the given mem parameter is
3110 * higher than the size of the UMA memory.
3111 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 * Basically given by "mem" parameter
3113 *
3114 * maximum = videosize - cmd_queue - hwcursor
3115 * (results in a heap of size 0)
3116 * default = SiS 300: depends on videosize
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003117 * SiS 315/330/340/XGI: 32k below max
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 */
3119
3120 if(ivideo->sisvga_engine == SIS_300_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003121 if(ivideo->video_size > 0x1000000) {
3122 def = 0xc00000;
3123 } else if(ivideo->video_size > 0x800000) {
3124 def = 0x800000;
3125 } else {
3126 def = 0x400000;
3127 }
3128 } else if(ivideo->UMAsize && ivideo->LFBsize) {
3129 ret = def = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003131 def = maxoffs - 0x8000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 }
3133
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003134 /* Use default for secondary card for now (FIXME) */
3135 if((!ret) || (ret > maxoffs) || (ivideo->cardnumber != 0))
3136 ret = def;
3137
3138 return ret;
3139}
3140
3141static u32 __devinit
3142sisfb_getheapsize(struct sis_video_info *ivideo)
3143{
3144 u32 max = ivideo->video_size - ivideo->hwcursor_size - ivideo->cmdQueueSize;
3145 u32 ret = 0;
3146
3147 if(ivideo->UMAsize && ivideo->LFBsize) {
3148 if( (!ivideo->sisfb_parm_mem) ||
3149 ((ivideo->sisfb_parm_mem * 1024) > max) ||
3150 ((max - (ivideo->sisfb_parm_mem * 1024)) < ivideo->UMAsize) ) {
3151 ret = ivideo->UMAsize;
3152 max -= ivideo->UMAsize;
3153 } else {
3154 ret = max - (ivideo->sisfb_parm_mem * 1024);
3155 max = ivideo->sisfb_parm_mem * 1024;
3156 }
3157 ivideo->video_offset = ret;
3158 ivideo->sisfb_mem = max;
3159 } else {
3160 ret = max - ivideo->heapstart;
3161 ivideo->sisfb_mem = ivideo->heapstart;
3162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163
3164 return ret;
3165}
3166
3167static int __devinit
3168sisfb_heap_init(struct sis_video_info *ivideo)
3169{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003170 struct SIS_OH *poh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003172 ivideo->video_offset = 0;
3173 if(ivideo->sisfb_parm_mem) {
3174 if( (ivideo->sisfb_parm_mem < (2 * 1024 * 1024)) ||
3175 (ivideo->sisfb_parm_mem > ivideo->video_size) ) {
3176 ivideo->sisfb_parm_mem = 0;
3177 }
3178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003180 ivideo->heapstart = sisfb_getheapstart(ivideo);
3181 ivideo->sisfb_heap_size = sisfb_getheapsize(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003183 ivideo->sisfb_heap_start = ivideo->video_vbase + ivideo->heapstart;
3184 ivideo->sisfb_heap_end = ivideo->sisfb_heap_start + ivideo->sisfb_heap_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003186 printk(KERN_INFO "sisfb: Memory heap starting at %dK, size %dK\n",
3187 (int)(ivideo->heapstart / 1024), (int)(ivideo->sisfb_heap_size / 1024));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003189 ivideo->sisfb_heap.vinfo = ivideo;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003191 ivideo->sisfb_heap.poha_chain = NULL;
3192 ivideo->sisfb_heap.poh_freelist = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003194 poh = sisfb_poh_new_node(&ivideo->sisfb_heap);
3195 if(poh == NULL)
3196 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003198 poh->poh_next = &ivideo->sisfb_heap.oh_free;
3199 poh->poh_prev = &ivideo->sisfb_heap.oh_free;
3200 poh->size = ivideo->sisfb_heap_size;
3201 poh->offset = ivideo->heapstart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003203 ivideo->sisfb_heap.oh_free.poh_next = poh;
3204 ivideo->sisfb_heap.oh_free.poh_prev = poh;
3205 ivideo->sisfb_heap.oh_free.size = 0;
3206 ivideo->sisfb_heap.max_freesize = poh->size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003208 ivideo->sisfb_heap.oh_used.poh_next = &ivideo->sisfb_heap.oh_used;
3209 ivideo->sisfb_heap.oh_used.poh_prev = &ivideo->sisfb_heap.oh_used;
3210 ivideo->sisfb_heap.oh_used.size = SENTINEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003212 if(ivideo->cardnumber == 0) {
3213 /* For the first card, make this heap the "global" one
3214 * for old DRM (which could handle only one card)
3215 */
3216 sisfb_heap = &ivideo->sisfb_heap;
3217 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003219 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220}
3221
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003222static struct SIS_OH *
3223sisfb_poh_new_node(struct SIS_HEAP *memheap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003225 struct SIS_OHALLOC *poha;
3226 struct SIS_OH *poh;
3227 unsigned long cOhs;
3228 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003230 if(memheap->poh_freelist == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 poha = kmalloc(SIS_OH_ALLOC_SIZE, GFP_KERNEL);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003232 if(!poha)
3233 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003235 poha->poha_next = memheap->poha_chain;
3236 memheap->poha_chain = poha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003238 cOhs = (SIS_OH_ALLOC_SIZE - sizeof(struct SIS_OHALLOC)) / sizeof(struct SIS_OH) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239
3240 poh = &poha->aoh[0];
3241 for(i = cOhs - 1; i != 0; i--) {
3242 poh->poh_next = poh + 1;
3243 poh = poh + 1;
3244 }
3245
3246 poh->poh_next = NULL;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003247 memheap->poh_freelist = &poha->aoh[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 }
3249
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003250 poh = memheap->poh_freelist;
3251 memheap->poh_freelist = poh->poh_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003253 return poh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254}
3255
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003256static struct SIS_OH *
3257sisfb_poh_allocate(struct SIS_HEAP *memheap, u32 size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003259 struct SIS_OH *pohThis;
3260 struct SIS_OH *pohRoot;
3261 int bAllocated = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003263 if(size > memheap->max_freesize) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 DPRINTK("sisfb: Can't allocate %dk video memory\n",
3265 (unsigned int) size / 1024);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003266 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 }
3268
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003269 pohThis = memheap->oh_free.poh_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003271 while(pohThis != &memheap->oh_free) {
3272 if(size <= pohThis->size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 bAllocated = 1;
3274 break;
3275 }
3276 pohThis = pohThis->poh_next;
3277 }
3278
3279 if(!bAllocated) {
3280 DPRINTK("sisfb: Can't allocate %dk video memory\n",
3281 (unsigned int) size / 1024);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003282 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 }
3284
3285 if(size == pohThis->size) {
3286 pohRoot = pohThis;
3287 sisfb_delete_node(pohThis);
3288 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003289 pohRoot = sisfb_poh_new_node(memheap);
3290 if(pohRoot == NULL)
3291 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292
3293 pohRoot->offset = pohThis->offset;
3294 pohRoot->size = size;
3295
3296 pohThis->offset += size;
3297 pohThis->size -= size;
3298 }
3299
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003300 memheap->max_freesize -= size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003302 pohThis = &memheap->oh_used;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 sisfb_insert_node(pohThis, pohRoot);
3304
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003305 return pohRoot;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306}
3307
3308static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003309sisfb_delete_node(struct SIS_OH *poh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003311 poh->poh_prev->poh_next = poh->poh_next;
3312 poh->poh_next->poh_prev = poh->poh_prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313}
3314
3315static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003316sisfb_insert_node(struct SIS_OH *pohList, struct SIS_OH *poh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003318 struct SIS_OH *pohTemp = pohList->poh_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319
3320 pohList->poh_next = poh;
3321 pohTemp->poh_prev = poh;
3322
3323 poh->poh_prev = pohList;
3324 poh->poh_next = pohTemp;
3325}
3326
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003327static struct SIS_OH *
3328sisfb_poh_free(struct SIS_HEAP *memheap, u32 base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003330 struct SIS_OH *pohThis;
3331 struct SIS_OH *poh_freed;
3332 struct SIS_OH *poh_prev;
3333 struct SIS_OH *poh_next;
3334 u32 ulUpper;
3335 u32 ulLower;
3336 int foundNode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003338 poh_freed = memheap->oh_used.poh_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003340 while(poh_freed != &memheap->oh_used) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 if(poh_freed->offset == base) {
3342 foundNode = 1;
3343 break;
3344 }
3345
3346 poh_freed = poh_freed->poh_next;
3347 }
3348
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003349 if(!foundNode)
3350 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003352 memheap->max_freesize += poh_freed->size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
3354 poh_prev = poh_next = NULL;
3355 ulUpper = poh_freed->offset + poh_freed->size;
3356 ulLower = poh_freed->offset;
3357
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003358 pohThis = memheap->oh_free.poh_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003360 while(pohThis != &memheap->oh_free) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 if(pohThis->offset == ulUpper) {
3362 poh_next = pohThis;
3363 } else if((pohThis->offset + pohThis->size) == ulLower) {
3364 poh_prev = pohThis;
3365 }
3366 pohThis = pohThis->poh_next;
3367 }
3368
3369 sisfb_delete_node(poh_freed);
3370
3371 if(poh_prev && poh_next) {
3372 poh_prev->size += (poh_freed->size + poh_next->size);
3373 sisfb_delete_node(poh_next);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003374 sisfb_free_node(memheap, poh_freed);
3375 sisfb_free_node(memheap, poh_next);
3376 return poh_prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 }
3378
3379 if(poh_prev) {
3380 poh_prev->size += poh_freed->size;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003381 sisfb_free_node(memheap, poh_freed);
3382 return poh_prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 }
3384
3385 if(poh_next) {
3386 poh_next->size += poh_freed->size;
3387 poh_next->offset = poh_freed->offset;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003388 sisfb_free_node(memheap, poh_freed);
3389 return poh_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 }
3391
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003392 sisfb_insert_node(&memheap->oh_free, poh_freed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003394 return poh_freed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395}
3396
3397static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003398sisfb_free_node(struct SIS_HEAP *memheap, struct SIS_OH *poh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003400 if(poh == NULL)
3401 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003403 poh->poh_next = memheap->poh_freelist;
3404 memheap->poh_freelist = poh;
3405}
3406
3407static void
3408sis_int_malloc(struct sis_video_info *ivideo, struct sis_memreq *req)
3409{
3410 struct SIS_OH *poh = NULL;
3411
3412 if((ivideo) && (ivideo->sisfb_id == SISFB_ID) && (!ivideo->havenoheap))
3413 poh = sisfb_poh_allocate(&ivideo->sisfb_heap, (u32)req->size);
3414
3415 if(poh == NULL) {
3416 req->offset = req->size = 0;
3417 DPRINTK("sisfb: Video RAM allocation failed\n");
3418 } else {
3419 req->offset = poh->offset;
3420 req->size = poh->size;
3421 DPRINTK("sisfb: Video RAM allocation succeeded: 0x%lx\n",
3422 (poh->offset + ivideo->video_vbase));
3423 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424}
3425
3426void
3427sis_malloc(struct sis_memreq *req)
3428{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003429 struct sis_video_info *ivideo = sisfb_heap->vinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003431 if(&ivideo->sisfb_heap == sisfb_heap)
3432 sis_int_malloc(ivideo, req);
3433 else
3434 req->offset = req->size = 0;
3435}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003437void
3438sis_malloc_new(struct pci_dev *pdev, struct sis_memreq *req)
3439{
3440 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
3441
3442 sis_int_malloc(ivideo, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443}
3444
3445/* sis_free: u32 because "base" is offset inside video ram, can never be >4GB */
3446
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003447static void
3448sis_int_free(struct sis_video_info *ivideo, u32 base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003450 struct SIS_OH *poh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003452 if((!ivideo) || (ivideo->sisfb_id != SISFB_ID) || (ivideo->havenoheap))
3453 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003455 poh = sisfb_poh_free(&ivideo->sisfb_heap, base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456
3457 if(poh == NULL) {
3458 DPRINTK("sisfb: sisfb_poh_free() failed at base 0x%x\n",
3459 (unsigned int) base);
3460 }
3461}
3462
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003463void
3464sis_free(u32 base)
3465{
3466 struct sis_video_info *ivideo = sisfb_heap->vinfo;
3467
3468 sis_int_free(ivideo, base);
3469}
3470
3471void
3472sis_free_new(struct pci_dev *pdev, u32 base)
3473{
3474 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
3475
3476 sis_int_free(ivideo, base);
3477}
3478
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479/* --------------------- SetMode routines ------------------------- */
3480
3481static void
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003482sisfb_check_engine_and_sync(struct sis_video_info *ivideo)
3483{
3484 u8 cr30, cr31;
3485
3486 /* Check if MMIO and engines are enabled,
3487 * and sync in case they are. Can't use
3488 * ivideo->accel here, as this might have
3489 * been changed before this is called.
3490 */
3491 inSISIDXREG(SISSR, IND_SIS_PCI_ADDRESS_SET, cr30);
3492 inSISIDXREG(SISSR, IND_SIS_MODULE_ENABLE, cr31);
3493 /* MMIO and 2D/3D engine enabled? */
3494 if((cr30 & SIS_MEM_MAP_IO_ENABLE) && (cr31 & 0x42)) {
3495#ifdef CONFIG_FB_SIS_300
3496 if(ivideo->sisvga_engine == SIS_300_VGA) {
3497 /* Don't care about TurboQueue. It's
3498 * enough to know that the engines
3499 * are enabled
3500 */
3501 sisfb_syncaccel(ivideo);
3502 }
3503#endif
3504#ifdef CONFIG_FB_SIS_315
3505 if(ivideo->sisvga_engine == SIS_315_VGA) {
3506 /* Check that any queue mode is
3507 * enabled, and that the queue
3508 * is not in the state of "reset"
3509 */
3510 inSISIDXREG(SISSR, 0x26, cr30);
3511 if((cr30 & 0xe0) && (!(cr30 & 0x01))) {
3512 sisfb_syncaccel(ivideo);
3513 }
3514 }
3515#endif
3516 }
3517}
3518
3519static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520sisfb_pre_setmode(struct sis_video_info *ivideo)
3521{
3522 u8 cr30 = 0, cr31 = 0, cr33 = 0, cr35 = 0, cr38 = 0;
3523 int tvregnum = 0;
3524
3525 ivideo->currentvbflags &= (VB_VIDEOBRIDGE | VB_DISPTYPE_DISP2);
3526
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003527 outSISIDXREG(SISSR, 0x05, 0x86);
3528
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 inSISIDXREG(SISCR, 0x31, cr31);
3530 cr31 &= ~0x60;
3531 cr31 |= 0x04;
3532
3533 cr33 = ivideo->rate_idx & 0x0F;
3534
3535#ifdef CONFIG_FB_SIS_315
3536 if(ivideo->sisvga_engine == SIS_315_VGA) {
3537 if(ivideo->chip >= SIS_661) {
3538 inSISIDXREG(SISCR, 0x38, cr38);
3539 cr38 &= ~0x07; /* Clear LCDA/DualEdge and YPbPr bits */
3540 } else {
3541 tvregnum = 0x38;
3542 inSISIDXREG(SISCR, tvregnum, cr38);
3543 cr38 &= ~0x3b; /* Clear LCDA/DualEdge and YPbPr bits */
3544 }
3545 }
3546#endif
3547#ifdef CONFIG_FB_SIS_300
3548 if(ivideo->sisvga_engine == SIS_300_VGA) {
3549 tvregnum = 0x35;
3550 inSISIDXREG(SISCR, tvregnum, cr38);
3551 }
3552#endif
3553
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003554 SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
3555 SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003556 ivideo->curFSTN = ivideo->curDSTN = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557
3558 switch(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
3559
3560 case CRT2_TV:
3561 cr38 &= ~0xc0; /* Clear PAL-M / PAL-N bits */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003562 if((ivideo->vbflags & TV_YPBPR) && (ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003564 if(ivideo->chip >= SIS_661) {
3565 cr38 |= 0x04;
3566 if(ivideo->vbflags & TV_YPBPR525P) cr35 |= 0x20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 else if(ivideo->vbflags & TV_YPBPR750P) cr35 |= 0x40;
3568 else if(ivideo->vbflags & TV_YPBPR1080I) cr35 |= 0x60;
3569 cr30 |= SIS_SIMULTANEOUS_VIEW_ENABLE;
3570 cr35 &= ~0x01;
3571 ivideo->currentvbflags |= (TV_YPBPR | (ivideo->vbflags & TV_YPBPRALL));
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003572 } else if(ivideo->sisvga_engine == SIS_315_VGA) {
3573 cr30 |= (0x80 | SIS_SIMULTANEOUS_VIEW_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 cr38 |= 0x08;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003575 if(ivideo->vbflags & TV_YPBPR525P) cr38 |= 0x10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 else if(ivideo->vbflags & TV_YPBPR750P) cr38 |= 0x20;
3577 else if(ivideo->vbflags & TV_YPBPR1080I) cr38 |= 0x30;
3578 cr31 &= ~0x01;
3579 ivideo->currentvbflags |= (TV_YPBPR | (ivideo->vbflags & TV_YPBPRALL));
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003582 } else if((ivideo->vbflags & TV_HIVISION) &&
3583 (ivideo->vbflags2 & VB2_SISHIVISIONBRIDGE)) {
3584 if(ivideo->chip >= SIS_661) {
3585 cr38 |= 0x04;
3586 cr35 |= 0x60;
3587 } else {
3588 cr30 |= 0x80;
3589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 cr30 |= SIS_SIMULTANEOUS_VIEW_ENABLE;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003591 cr31 |= 0x01;
3592 cr35 |= 0x01;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 ivideo->currentvbflags |= TV_HIVISION;
3594 } else if(ivideo->vbflags & TV_SCART) {
3595 cr30 = (SIS_VB_OUTPUT_SCART | SIS_SIMULTANEOUS_VIEW_ENABLE);
3596 cr31 |= 0x01;
3597 cr35 |= 0x01;
3598 ivideo->currentvbflags |= TV_SCART;
3599 } else {
3600 if(ivideo->vbflags & TV_SVIDEO) {
3601 cr30 = (SIS_VB_OUTPUT_SVIDEO | SIS_SIMULTANEOUS_VIEW_ENABLE);
3602 ivideo->currentvbflags |= TV_SVIDEO;
3603 }
3604 if(ivideo->vbflags & TV_AVIDEO) {
3605 cr30 = (SIS_VB_OUTPUT_COMPOSITE | SIS_SIMULTANEOUS_VIEW_ENABLE);
3606 ivideo->currentvbflags |= TV_AVIDEO;
3607 }
3608 }
3609 cr31 |= SIS_DRIVER_MODE;
3610
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003611 if(ivideo->vbflags & (TV_AVIDEO | TV_SVIDEO)) {
3612 if(ivideo->vbflags & TV_PAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 cr31 |= 0x01; cr35 |= 0x01;
3614 ivideo->currentvbflags |= TV_PAL;
3615 if(ivideo->vbflags & TV_PALM) {
3616 cr38 |= 0x40; cr35 |= 0x04;
3617 ivideo->currentvbflags |= TV_PALM;
3618 } else if(ivideo->vbflags & TV_PALN) {
3619 cr38 |= 0x80; cr35 |= 0x08;
3620 ivideo->currentvbflags |= TV_PALN;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003621 }
3622 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 cr31 &= ~0x01; cr35 &= ~0x01;
3624 ivideo->currentvbflags |= TV_NTSC;
3625 if(ivideo->vbflags & TV_NTSCJ) {
3626 cr38 |= 0x40; cr35 |= 0x02;
3627 ivideo->currentvbflags |= TV_NTSCJ;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003628 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 }
3630 }
3631 break;
3632
3633 case CRT2_LCD:
3634 cr30 = (SIS_VB_OUTPUT_LCD | SIS_SIMULTANEOUS_VIEW_ENABLE);
3635 cr31 |= SIS_DRIVER_MODE;
3636 SiS_SetEnableDstn(&ivideo->SiS_Pr, ivideo->sisfb_dstn);
3637 SiS_SetEnableFstn(&ivideo->SiS_Pr, ivideo->sisfb_fstn);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003638 ivideo->curFSTN = ivideo->sisfb_fstn;
3639 ivideo->curDSTN = ivideo->sisfb_dstn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 break;
3641
3642 case CRT2_VGA:
3643 cr30 = (SIS_VB_OUTPUT_CRT2 | SIS_SIMULTANEOUS_VIEW_ENABLE);
3644 cr31 |= SIS_DRIVER_MODE;
3645 if(ivideo->sisfb_nocrt2rate) {
3646 cr33 |= (sisbios_mode[ivideo->sisfb_mode_idx].rate_idx << 4);
3647 } else {
3648 cr33 |= ((ivideo->rate_idx & 0x0F) << 4);
3649 }
3650 break;
3651
3652 default: /* disable CRT2 */
3653 cr30 = 0x00;
3654 cr31 |= (SIS_DRIVER_MODE | SIS_VB_OUTPUT_DISABLE);
3655 }
3656
3657 outSISIDXREG(SISCR, 0x30, cr30);
3658 outSISIDXREG(SISCR, 0x33, cr33);
3659
3660 if(ivideo->chip >= SIS_661) {
3661#ifdef CONFIG_FB_SIS_315
3662 cr31 &= ~0x01; /* Clear PAL flag (now in CR35) */
3663 setSISIDXREG(SISCR, 0x35, ~0x10, cr35); /* Leave overscan bit alone */
3664 cr38 &= 0x07; /* Use only LCDA and HiVision/YPbPr bits */
3665 setSISIDXREG(SISCR, 0x38, 0xf8, cr38);
3666#endif
3667 } else if(ivideo->chip != SIS_300) {
3668 outSISIDXREG(SISCR, tvregnum, cr38);
3669 }
3670 outSISIDXREG(SISCR, 0x31, cr31);
3671
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 ivideo->SiS_Pr.SiS_UseOEM = ivideo->sisfb_useoem;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003673
3674 sisfb_check_engine_and_sync(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675}
3676
3677/* Fix SR11 for 661 and later */
3678#ifdef CONFIG_FB_SIS_315
3679static void
3680sisfb_fixup_SR11(struct sis_video_info *ivideo)
3681{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003682 u8 tmpreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003684 if(ivideo->chip >= SIS_661) {
3685 inSISIDXREG(SISSR,0x11,tmpreg);
3686 if(tmpreg & 0x20) {
3687 inSISIDXREG(SISSR,0x3e,tmpreg);
3688 tmpreg = (tmpreg + 1) & 0xff;
3689 outSISIDXREG(SISSR,0x3e,tmpreg);
3690 inSISIDXREG(SISSR,0x11,tmpreg);
3691 }
3692 if(tmpreg & 0xf0) {
3693 andSISIDXREG(SISSR,0x11,0x0f);
3694 }
3695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696}
3697#endif
3698
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003699static void
3700sisfb_set_TVxposoffset(struct sis_video_info *ivideo, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003702 if(val > 32) val = 32;
3703 if(val < -32) val = -32;
3704 ivideo->tvxpos = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003706 if(ivideo->sisfblocked) return;
3707 if(!ivideo->modechanged) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003709 if(ivideo->currentvbflags & CRT2_TV) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003711 if(ivideo->vbflags2 & VB2_CHRONTEL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003713 int x = ivideo->tvx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003715 switch(ivideo->chronteltype) {
3716 case 1:
3717 x += val;
3718 if(x < 0) x = 0;
3719 outSISIDXREG(SISSR,0x05,0x86);
3720 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0a, (x & 0xff));
3721 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x08, ((x & 0x0100) >> 7), 0xFD);
3722 break;
3723 case 2:
3724 /* Not supported by hardware */
3725 break;
3726 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003728 } else if(ivideo->vbflags2 & VB2_SISBRIDGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003730 u8 p2_1f,p2_20,p2_2b,p2_42,p2_43;
3731 unsigned short temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003733 p2_1f = ivideo->p2_1f;
3734 p2_20 = ivideo->p2_20;
3735 p2_2b = ivideo->p2_2b;
3736 p2_42 = ivideo->p2_42;
3737 p2_43 = ivideo->p2_43;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003739 temp = p2_1f | ((p2_20 & 0xf0) << 4);
3740 temp += (val * 2);
3741 p2_1f = temp & 0xff;
3742 p2_20 = (temp & 0xf00) >> 4;
3743 p2_2b = ((p2_2b & 0x0f) + (val * 2)) & 0x0f;
3744 temp = p2_43 | ((p2_42 & 0xf0) << 4);
3745 temp += (val * 2);
3746 p2_43 = temp & 0xff;
3747 p2_42 = (temp & 0xf00) >> 4;
3748 outSISIDXREG(SISPART2,0x1f,p2_1f);
3749 setSISIDXREG(SISPART2,0x20,0x0F,p2_20);
3750 setSISIDXREG(SISPART2,0x2b,0xF0,p2_2b);
3751 setSISIDXREG(SISPART2,0x42,0x0F,p2_42);
3752 outSISIDXREG(SISPART2,0x43,p2_43);
3753 }
3754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755}
3756
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003757static void
3758sisfb_set_TVyposoffset(struct sis_video_info *ivideo, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003760 if(val > 32) val = 32;
3761 if(val < -32) val = -32;
3762 ivideo->tvypos = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003764 if(ivideo->sisfblocked) return;
3765 if(!ivideo->modechanged) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003767 if(ivideo->currentvbflags & CRT2_TV) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003769 if(ivideo->vbflags2 & VB2_CHRONTEL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003771 int y = ivideo->tvy;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003773 switch(ivideo->chronteltype) {
3774 case 1:
3775 y -= val;
3776 if(y < 0) y = 0;
3777 outSISIDXREG(SISSR,0x05,0x86);
3778 SiS_SetCH700x(&ivideo->SiS_Pr, 0x0b, (y & 0xff));
3779 SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x08, ((y & 0x0100) >> 8), 0xFE);
3780 break;
3781 case 2:
3782 /* Not supported by hardware */
3783 break;
3784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003786 } else if(ivideo->vbflags2 & VB2_SISBRIDGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003788 char p2_01, p2_02;
3789 val /= 2;
3790 p2_01 = ivideo->p2_01;
3791 p2_02 = ivideo->p2_02;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003793 p2_01 += val;
3794 p2_02 += val;
3795 if(!(ivideo->currentvbflags & (TV_HIVISION | TV_YPBPR))) {
3796 while((p2_01 <= 0) || (p2_02 <= 0)) {
3797 p2_01 += 2;
3798 p2_02 += 2;
3799 }
3800 }
3801 outSISIDXREG(SISPART2,0x01,p2_01);
3802 outSISIDXREG(SISPART2,0x02,p2_02);
3803 }
3804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805}
3806
3807static void
3808sisfb_post_setmode(struct sis_video_info *ivideo)
3809{
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003810 bool crt1isoff = false;
3811 bool doit = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
3813 u8 reg;
3814#endif
3815#ifdef CONFIG_FB_SIS_315
3816 u8 reg1;
3817#endif
3818
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003819 outSISIDXREG(SISSR, 0x05, 0x86);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820
3821#ifdef CONFIG_FB_SIS_315
3822 sisfb_fixup_SR11(ivideo);
3823#endif
3824
3825 /* Now we actually HAVE changed the display mode */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003826 ivideo->modechanged = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827
3828 /* We can't switch off CRT1 if bridge is in slave mode */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003829 if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003830 if(sisfb_bridgeisslave(ivideo)) doit = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003831 } else
3832 ivideo->sisfb_crt1off = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833
3834#ifdef CONFIG_FB_SIS_300
3835 if(ivideo->sisvga_engine == SIS_300_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003836 if((ivideo->sisfb_crt1off) && (doit)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003837 crt1isoff = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003838 reg = 0x00;
3839 } else {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003840 crt1isoff = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003841 reg = 0x80;
3842 }
3843 setSISIDXREG(SISCR, 0x17, 0x7f, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 }
3845#endif
3846#ifdef CONFIG_FB_SIS_315
3847 if(ivideo->sisvga_engine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003848 if((ivideo->sisfb_crt1off) && (doit)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003849 crt1isoff = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003850 reg = 0x40;
3851 reg1 = 0xc0;
3852 } else {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003853 crt1isoff = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003854 reg = 0x00;
3855 reg1 = 0x00;
3856 }
3857 setSISIDXREG(SISCR, ivideo->SiS_Pr.SiS_MyCR63, ~0x40, reg);
3858 setSISIDXREG(SISSR, 0x1f, ~0xc0, reg1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 }
3860#endif
3861
3862 if(crt1isoff) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003863 ivideo->currentvbflags &= ~VB_DISPTYPE_CRT1;
3864 ivideo->currentvbflags |= VB_SINGLE_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003866 ivideo->currentvbflags |= VB_DISPTYPE_CRT1;
3867 if(ivideo->currentvbflags & VB_DISPTYPE_CRT2) {
3868 ivideo->currentvbflags |= VB_MIRROR_MODE;
3869 } else {
3870 ivideo->currentvbflags |= VB_SINGLE_MODE;
3871 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 }
3873
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003874 andSISIDXREG(SISSR, IND_SIS_RAMDAC_CONTROL, ~0x04);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875
3876 if(ivideo->currentvbflags & CRT2_TV) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003877 if(ivideo->vbflags2 & VB2_SISBRIDGE) {
3878 inSISIDXREG(SISPART2,0x1f,ivideo->p2_1f);
3879 inSISIDXREG(SISPART2,0x20,ivideo->p2_20);
3880 inSISIDXREG(SISPART2,0x2b,ivideo->p2_2b);
3881 inSISIDXREG(SISPART2,0x42,ivideo->p2_42);
3882 inSISIDXREG(SISPART2,0x43,ivideo->p2_43);
3883 inSISIDXREG(SISPART2,0x01,ivideo->p2_01);
3884 inSISIDXREG(SISPART2,0x02,ivideo->p2_02);
3885 } else if(ivideo->vbflags2 & VB2_CHRONTEL) {
3886 if(ivideo->chronteltype == 1) {
3887 ivideo->tvx = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0a);
3888 ivideo->tvx |= (((SiS_GetCH700x(&ivideo->SiS_Pr, 0x08) & 0x02) >> 1) << 8);
3889 ivideo->tvy = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0b);
3890 ivideo->tvy |= ((SiS_GetCH700x(&ivideo->SiS_Pr, 0x08) & 0x01) << 8);
3891 }
3892 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 }
3894
3895 if(ivideo->tvxpos) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003896 sisfb_set_TVxposoffset(ivideo, ivideo->tvxpos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 }
3898 if(ivideo->tvypos) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003899 sisfb_set_TVyposoffset(ivideo, ivideo->tvypos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 }
3901
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003902 /* Eventually sync engines */
3903 sisfb_check_engine_and_sync(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003905 /* (Re-)Initialize chip engines */
3906 if(ivideo->accel) {
3907 sisfb_engine_init(ivideo);
3908 } else {
3909 ivideo->engineok = 0;
3910 }
3911}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003913static int
3914sisfb_reset_mode(struct sis_video_info *ivideo)
3915{
3916 if(sisfb_set_mode(ivideo, 0))
3917 return 1;
3918
3919 sisfb_set_pitch(ivideo);
3920 sisfb_set_base_CRT1(ivideo, ivideo->current_base);
3921 sisfb_set_base_CRT2(ivideo, ivideo->current_base);
3922
3923 return 0;
3924}
3925
3926static void
3927sisfb_handle_command(struct sis_video_info *ivideo, struct sisfb_cmd *sisfb_command)
3928{
3929 int mycrt1off;
3930
3931 switch(sisfb_command->sisfb_cmd) {
3932 case SISFB_CMD_GETVBFLAGS:
3933 if(!ivideo->modechanged) {
3934 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_EARLY;
3935 } else {
3936 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK;
3937 sisfb_command->sisfb_result[1] = ivideo->currentvbflags;
3938 sisfb_command->sisfb_result[2] = ivideo->vbflags2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003940 break;
3941 case SISFB_CMD_SWITCHCRT1:
3942 /* arg[0]: 0 = off, 1 = on, 99 = query */
3943 if(!ivideo->modechanged) {
3944 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_EARLY;
3945 } else if(sisfb_command->sisfb_arg[0] == 99) {
3946 /* Query */
3947 sisfb_command->sisfb_result[1] = ivideo->sisfb_crt1off ? 0 : 1;
3948 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK;
3949 } else if(ivideo->sisfblocked) {
3950 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_LOCKED;
3951 } else if((!(ivideo->currentvbflags & CRT2_ENABLE)) &&
3952 (sisfb_command->sisfb_arg[0] == 0)) {
3953 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_NOCRT2;
3954 } else {
3955 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK;
3956 mycrt1off = sisfb_command->sisfb_arg[0] ? 0 : 1;
3957 if( ((ivideo->currentvbflags & VB_DISPTYPE_CRT1) && mycrt1off) ||
3958 ((!(ivideo->currentvbflags & VB_DISPTYPE_CRT1)) && !mycrt1off) ) {
3959 ivideo->sisfb_crt1off = mycrt1off;
3960 if(sisfb_reset_mode(ivideo)) {
3961 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OTHER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 }
3963 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003964 sisfb_command->sisfb_result[1] = ivideo->sisfb_crt1off ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003966 break;
3967 /* more to come */
3968 default:
3969 sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_UNKNOWN;
3970 printk(KERN_ERR "sisfb: Unknown command 0x%x\n",
3971 sisfb_command->sisfb_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 }
3973}
3974
3975#ifndef MODULE
Adrian Bunk14aefd12008-07-23 21:31:12 -07003976static int __init sisfb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977{
3978 char *this_opt;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003979
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 sisfb_setdefaultparms();
3981
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003982 if(!options || !(*options))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984
3985 while((this_opt = strsep(&options, ",")) != NULL) {
3986
3987 if(!(*this_opt)) continue;
3988
3989 if(!strnicmp(this_opt, "off", 3)) {
3990 sisfb_off = 1;
3991 } else if(!strnicmp(this_opt, "forcecrt2type:", 14)) {
3992 /* Need to check crt2 type first for fstn/dstn */
3993 sisfb_search_crt2type(this_opt + 14);
3994 } else if(!strnicmp(this_opt, "tvmode:",7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 sisfb_search_tvstd(this_opt + 7);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07003996 } else if(!strnicmp(this_opt, "tvstandard:",11)) {
3997 sisfb_search_tvstd(this_opt + 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 } else if(!strnicmp(this_opt, "mode:", 5)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08003999 sisfb_search_mode(this_opt + 5, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 } else if(!strnicmp(this_opt, "vesa:", 5)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08004001 sisfb_search_vesamode(simple_strtoul(this_opt + 5, NULL, 0), false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 } else if(!strnicmp(this_opt, "rate:", 5)) {
4003 sisfb_parm_rate = simple_strtoul(this_opt + 5, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 } else if(!strnicmp(this_opt, "forcecrt1:", 10)) {
4005 sisfb_forcecrt1 = (int)simple_strtoul(this_opt + 10, NULL, 0);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004006 } else if(!strnicmp(this_opt, "mem:",4)) {
4007 sisfb_parm_mem = simple_strtoul(this_opt + 4, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 } else if(!strnicmp(this_opt, "pdc:", 4)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004009 sisfb_pdc = simple_strtoul(this_opt + 4, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 } else if(!strnicmp(this_opt, "pdc1:", 5)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004011 sisfb_pdca = simple_strtoul(this_opt + 5, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 } else if(!strnicmp(this_opt, "noaccel", 7)) {
4013 sisfb_accel = 0;
4014 } else if(!strnicmp(this_opt, "accel", 5)) {
4015 sisfb_accel = -1;
4016 } else if(!strnicmp(this_opt, "noypan", 6)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004017 sisfb_ypan = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 } else if(!strnicmp(this_opt, "ypan", 4)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004019 sisfb_ypan = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 } else if(!strnicmp(this_opt, "nomax", 5)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004021 sisfb_max = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 } else if(!strnicmp(this_opt, "max", 3)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004023 sisfb_max = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 } else if(!strnicmp(this_opt, "userom:", 7)) {
4025 sisfb_userom = (int)simple_strtoul(this_opt + 7, NULL, 0);
4026 } else if(!strnicmp(this_opt, "useoem:", 7)) {
4027 sisfb_useoem = (int)simple_strtoul(this_opt + 7, NULL, 0);
4028 } else if(!strnicmp(this_opt, "nocrt2rate", 10)) {
4029 sisfb_nocrt2rate = 1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004030 } else if(!strnicmp(this_opt, "scalelcd:", 9)) {
4031 unsigned long temp = 2;
4032 temp = simple_strtoul(this_opt + 9, NULL, 0);
4033 if((temp == 0) || (temp == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 sisfb_scalelcd = temp ^ 1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004035 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 } else if(!strnicmp(this_opt, "tvxposoffset:", 13)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004037 int temp = 0;
4038 temp = (int)simple_strtol(this_opt + 13, NULL, 0);
4039 if((temp >= -32) && (temp <= 32)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 sisfb_tvxposoffset = temp;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004041 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 } else if(!strnicmp(this_opt, "tvyposoffset:", 13)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004043 int temp = 0;
4044 temp = (int)simple_strtol(this_opt + 13, NULL, 0);
4045 if((temp >= -32) && (temp <= 32)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 sisfb_tvyposoffset = temp;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004047 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 } else if(!strnicmp(this_opt, "specialtiming:", 14)) {
4049 sisfb_search_specialtiming(this_opt + 14);
4050 } else if(!strnicmp(this_opt, "lvdshl:", 7)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004051 int temp = 4;
4052 temp = simple_strtoul(this_opt + 7, NULL, 0);
4053 if((temp >= 0) && (temp <= 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054 sisfb_lvdshl = temp;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004055 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 } else if(this_opt[0] >= '0' && this_opt[0] <= '9') {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08004057 sisfb_search_mode(this_opt, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058#if !defined(__i386__) && !defined(__x86_64__)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004059 } else if(!strnicmp(this_opt, "resetcard", 9)) {
4060 sisfb_resetcard = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 } else if(!strnicmp(this_opt, "videoram:", 9)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004062 sisfb_videoram = simple_strtoul(this_opt + 9, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063#endif
4064 } else {
4065 printk(KERN_INFO "sisfb: Invalid option %s\n", this_opt);
4066 }
4067
4068 }
4069
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 return 0;
4071}
4072#endif
4073
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004074static int __devinit
Adrian Bunk14aefd12008-07-23 21:31:12 -07004075sisfb_check_rom(void __iomem *rom_base, struct sis_video_info *ivideo)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004076{
Adrian Bunk14aefd12008-07-23 21:31:12 -07004077 void __iomem *rom;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004078 int romptr;
4079
4080 if((readb(rom_base) != 0x55) || (readb(rom_base + 1) != 0xaa))
4081 return 0;
4082
4083 romptr = (readb(rom_base + 0x18) | (readb(rom_base + 0x19) << 8));
4084 if(romptr > (0x10000 - 8))
4085 return 0;
4086
4087 rom = rom_base + romptr;
4088
4089 if((readb(rom) != 'P') || (readb(rom + 1) != 'C') ||
4090 (readb(rom + 2) != 'I') || (readb(rom + 3) != 'R'))
4091 return 0;
4092
4093 if((readb(rom + 4) | (readb(rom + 5) << 8)) != ivideo->chip_vendor)
4094 return 0;
4095
4096 if((readb(rom + 6) | (readb(rom + 7) << 8)) != ivideo->chip_id)
4097 return 0;
4098
4099 return 1;
4100}
4101
4102static unsigned char * __devinit
4103sisfb_find_rom(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104{
4105 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
Adrian Bunk14aefd12008-07-23 21:31:12 -07004106 void __iomem *rom_base;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004107 unsigned char *myrombase = NULL;
4108 u32 temp;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004109 size_t romsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004111 /* First, try the official pci ROM functions (except
4112 * on integrated chipsets which have no ROM).
4113 */
4114
4115 if(!ivideo->nbridge) {
4116
4117 if((rom_base = pci_map_rom(pdev, &romsize))) {
4118
4119 if(sisfb_check_rom(rom_base, ivideo)) {
4120
4121 if((myrombase = vmalloc(65536))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004122 memcpy_fromio(myrombase, rom_base,
4123 (romsize > 65536) ? 65536 : romsize);
4124 }
4125 }
4126 pci_unmap_rom(pdev, rom_base);
4127 }
4128 }
4129
4130 if(myrombase) return myrombase;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004131
4132 /* Otherwise do it the conventional way. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133
4134#if defined(__i386__) || defined(__x86_64__)
4135
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004136 for(temp = 0x000c0000; temp < 0x000f0000; temp += 0x00001000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004138 rom_base = ioremap(temp, 65536);
4139 if(!rom_base)
4140 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004142 if(!sisfb_check_rom(rom_base, ivideo)) {
4143 iounmap(rom_base);
4144 continue;
4145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004147 if((myrombase = vmalloc(65536)))
4148 memcpy_fromio(myrombase, rom_base, 65536);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004150 iounmap(rom_base);
4151 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 }
4154
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155#endif
4156
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004157 return myrombase;
4158}
4159
4160static void __devinit
4161sisfb_post_map_vram(struct sis_video_info *ivideo, unsigned int *mapsize,
4162 unsigned int min)
4163{
Aaro Koskinen32ed3032010-11-10 13:04:19 +02004164 if (*mapsize < (min << 20))
4165 return;
4166
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004167 ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize));
4168
4169 if(!ivideo->video_vbase) {
4170 printk(KERN_ERR
4171 "sisfb: Unable to map maximum video RAM for size detection\n");
4172 (*mapsize) >>= 1;
4173 while((!(ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize))))) {
4174 (*mapsize) >>= 1;
4175 if((*mapsize) < (min << 20))
4176 break;
4177 }
4178 if(ivideo->video_vbase) {
4179 printk(KERN_ERR
4180 "sisfb: Video RAM size detection limited to %dMB\n",
4181 (int)((*mapsize) >> 20));
4182 }
4183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184}
4185
4186#ifdef CONFIG_FB_SIS_300
4187static int __devinit
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004188sisfb_post_300_buswidth(struct sis_video_info *ivideo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189{
Adrian Bunk14aefd12008-07-23 21:31:12 -07004190 void __iomem *FBAddress = ivideo->video_vbase;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004191 unsigned short temp;
4192 unsigned char reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004195 andSISIDXREG(SISSR, 0x15, 0xFB);
4196 orSISIDXREG(SISSR, 0x15, 0x04);
4197 outSISIDXREG(SISSR, 0x13, 0x00);
4198 outSISIDXREG(SISSR, 0x14, 0xBF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004200 for(i = 0; i < 2; i++) {
4201 temp = 0x1234;
4202 for(j = 0; j < 4; j++) {
4203 writew(temp, FBAddress);
4204 if(readw(FBAddress) == temp)
4205 break;
4206 orSISIDXREG(SISSR, 0x3c, 0x01);
4207 inSISIDXREG(SISSR, 0x05, reg);
4208 inSISIDXREG(SISSR, 0x05, reg);
4209 andSISIDXREG(SISSR, 0x3c, 0xfe);
4210 inSISIDXREG(SISSR, 0x05, reg);
4211 inSISIDXREG(SISSR, 0x05, reg);
4212 temp++;
4213 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 }
4215
4216 writel(0x01234567L, FBAddress);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004217 writel(0x456789ABL, (FBAddress + 4));
4218 writel(0x89ABCDEFL, (FBAddress + 8));
4219 writel(0xCDEF0123L, (FBAddress + 12));
4220
4221 inSISIDXREG(SISSR, 0x3b, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 if(reg & 0x01) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004223 if(readl((FBAddress + 12)) == 0xCDEF0123L)
4224 return 4; /* Channel A 128bit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004226
4227 if(readl((FBAddress + 4)) == 0x456789ABL)
4228 return 2; /* Channel B 64bit */
4229
4230 return 1; /* 32bit */
4231}
4232
4233static int __devinit
4234sisfb_post_300_rwtest(struct sis_video_info *ivideo, int iteration, int buswidth,
4235 int PseudoRankCapacity, int PseudoAdrPinCount,
4236 unsigned int mapsize)
4237{
Adrian Bunk14aefd12008-07-23 21:31:12 -07004238 void __iomem *FBAddr = ivideo->video_vbase;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004239 unsigned short sr14;
4240 unsigned int k, RankCapacity, PageCapacity, BankNumHigh, BankNumMid;
4241 unsigned int PhysicalAdrOtherPage, PhysicalAdrHigh, PhysicalAdrHalfPage;
4242 static const unsigned short SiS_DRAMType[17][5] = {
4243 {0x0C,0x0A,0x02,0x40,0x39},
4244 {0x0D,0x0A,0x01,0x40,0x48},
4245 {0x0C,0x09,0x02,0x20,0x35},
4246 {0x0D,0x09,0x01,0x20,0x44},
4247 {0x0C,0x08,0x02,0x10,0x31},
4248 {0x0D,0x08,0x01,0x10,0x40},
4249 {0x0C,0x0A,0x01,0x20,0x34},
4250 {0x0C,0x09,0x01,0x08,0x32},
4251 {0x0B,0x08,0x02,0x08,0x21},
4252 {0x0C,0x08,0x01,0x08,0x30},
4253 {0x0A,0x08,0x02,0x04,0x11},
4254 {0x0B,0x0A,0x01,0x10,0x28},
4255 {0x09,0x08,0x02,0x02,0x01},
4256 {0x0B,0x09,0x01,0x08,0x24},
4257 {0x0B,0x08,0x01,0x04,0x20},
4258 {0x0A,0x08,0x01,0x02,0x10},
4259 {0x09,0x08,0x01,0x01,0x00}
4260 };
4261
4262 for(k = 0; k <= 16; k++) {
4263
4264 RankCapacity = buswidth * SiS_DRAMType[k][3];
4265
4266 if(RankCapacity != PseudoRankCapacity)
4267 continue;
4268
4269 if((SiS_DRAMType[k][2] + SiS_DRAMType[k][0]) > PseudoAdrPinCount)
4270 continue;
4271
4272 BankNumHigh = RankCapacity * 16 * iteration - 1;
4273 if(iteration == 3) { /* Rank No */
4274 BankNumMid = RankCapacity * 16 - 1;
4275 } else {
4276 BankNumMid = RankCapacity * 16 * iteration / 2 - 1;
4277 }
4278
4279 PageCapacity = (1 << SiS_DRAMType[k][1]) * buswidth * 4;
4280 PhysicalAdrHigh = BankNumHigh;
4281 PhysicalAdrHalfPage = (PageCapacity / 2 + PhysicalAdrHigh) % PageCapacity;
4282 PhysicalAdrOtherPage = PageCapacity * SiS_DRAMType[k][2] + PhysicalAdrHigh;
4283
4284 andSISIDXREG(SISSR, 0x15, 0xFB); /* Test */
4285 orSISIDXREG(SISSR, 0x15, 0x04); /* Test */
4286 sr14 = (SiS_DRAMType[k][3] * buswidth) - 1;
4287 if(buswidth == 4) sr14 |= 0x80;
4288 else if(buswidth == 2) sr14 |= 0x40;
4289 outSISIDXREG(SISSR, 0x13, SiS_DRAMType[k][4]);
4290 outSISIDXREG(SISSR, 0x14, sr14);
4291
4292 BankNumHigh <<= 16;
4293 BankNumMid <<= 16;
4294
4295 if((BankNumHigh + PhysicalAdrHigh >= mapsize) ||
4296 (BankNumMid + PhysicalAdrHigh >= mapsize) ||
4297 (BankNumHigh + PhysicalAdrHalfPage >= mapsize) ||
4298 (BankNumHigh + PhysicalAdrOtherPage >= mapsize))
4299 continue;
4300
4301 /* Write data */
4302 writew(((unsigned short)PhysicalAdrHigh),
4303 (FBAddr + BankNumHigh + PhysicalAdrHigh));
4304 writew(((unsigned short)BankNumMid),
4305 (FBAddr + BankNumMid + PhysicalAdrHigh));
4306 writew(((unsigned short)PhysicalAdrHalfPage),
4307 (FBAddr + BankNumHigh + PhysicalAdrHalfPage));
4308 writew(((unsigned short)PhysicalAdrOtherPage),
4309 (FBAddr + BankNumHigh + PhysicalAdrOtherPage));
4310
4311 /* Read data */
4312 if(readw(FBAddr + BankNumHigh + PhysicalAdrHigh) == PhysicalAdrHigh)
4313 return 1;
4314 }
4315
4316 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317}
4318
4319static void __devinit
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004320sisfb_post_300_ramsize(struct pci_dev *pdev, unsigned int mapsize)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004322 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
4323 int i, j, buswidth;
4324 int PseudoRankCapacity, PseudoAdrPinCount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004326 buswidth = sisfb_post_300_buswidth(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004328 for(i = 6; i >= 0; i--) {
4329 PseudoRankCapacity = 1 << i;
4330 for(j = 4; j >= 1; j--) {
4331 PseudoAdrPinCount = 15 - j;
4332 if((PseudoRankCapacity * j) <= 64) {
4333 if(sisfb_post_300_rwtest(ivideo,
4334 j,
4335 buswidth,
4336 PseudoRankCapacity,
4337 PseudoAdrPinCount,
4338 mapsize))
4339 return;
4340 }
4341 }
4342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343}
4344
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004345static void __devinit
4346sisfb_post_sis300(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347{
4348 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004349 unsigned char *bios = ivideo->SiS_Pr.VirtualRomBase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 u8 reg, v1, v2, v3, v4, v5, v6, v7, v8;
4351 u16 index, rindex, memtype = 0;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004352 unsigned int mapsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004354 if(!ivideo->SiS_Pr.UseROM)
4355 bios = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004357 outSISIDXREG(SISSR, 0x05, 0x86);
4358
4359 if(bios) {
4360 if(bios[0x52] & 0x80) {
4361 memtype = bios[0x52];
4362 } else {
4363 inSISIDXREG(SISSR, 0x3a, memtype);
4364 }
4365 memtype &= 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366 }
4367
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004368 v3 = 0x80; v6 = 0x80;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369 if(ivideo->revision_id <= 0x13) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004370 v1 = 0x44; v2 = 0x42;
4371 v4 = 0x44; v5 = 0x42;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004373 v1 = 0x68; v2 = 0x43; /* Assume 125Mhz MCLK */
4374 v4 = 0x68; v5 = 0x43; /* Assume 125Mhz ECLK */
4375 if(bios) {
4376 index = memtype * 5;
4377 rindex = index + 0x54;
4378 v1 = bios[rindex++];
4379 v2 = bios[rindex++];
4380 v3 = bios[rindex++];
4381 rindex = index + 0x7c;
4382 v4 = bios[rindex++];
4383 v5 = bios[rindex++];
4384 v6 = bios[rindex++];
4385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004387 outSISIDXREG(SISSR, 0x28, v1);
4388 outSISIDXREG(SISSR, 0x29, v2);
4389 outSISIDXREG(SISSR, 0x2a, v3);
4390 outSISIDXREG(SISSR, 0x2e, v4);
4391 outSISIDXREG(SISSR, 0x2f, v5);
4392 outSISIDXREG(SISSR, 0x30, v6);
4393
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 v1 = 0x10;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004395 if(bios)
4396 v1 = bios[0xa4];
4397 outSISIDXREG(SISSR, 0x07, v1); /* DAC speed */
4398
4399 outSISIDXREG(SISSR, 0x11, 0x0f); /* DDC, power save */
4400
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 v1 = 0x01; v2 = 0x43; v3 = 0x1e; v4 = 0x2a;
4402 v5 = 0x06; v6 = 0x00; v7 = 0x00; v8 = 0x00;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004403 if(bios) {
4404 memtype += 0xa5;
4405 v1 = bios[memtype];
4406 v2 = bios[memtype + 8];
4407 v3 = bios[memtype + 16];
4408 v4 = bios[memtype + 24];
4409 v5 = bios[memtype + 32];
4410 v6 = bios[memtype + 40];
4411 v7 = bios[memtype + 48];
4412 v8 = bios[memtype + 56];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004414 if(ivideo->revision_id >= 0x80)
4415 v3 &= 0xfd;
4416 outSISIDXREG(SISSR, 0x15, v1); /* Ram type (assuming 0, BIOS 0xa5 step 8) */
4417 outSISIDXREG(SISSR, 0x16, v2);
4418 outSISIDXREG(SISSR, 0x17, v3);
4419 outSISIDXREG(SISSR, 0x18, v4);
4420 outSISIDXREG(SISSR, 0x19, v5);
4421 outSISIDXREG(SISSR, 0x1a, v6);
4422 outSISIDXREG(SISSR, 0x1b, v7);
4423 outSISIDXREG(SISSR, 0x1c, v8); /* ---- */
4424 andSISIDXREG(SISSR, 0x15 ,0xfb);
4425 orSISIDXREG(SISSR, 0x15, 0x04);
4426 if(bios) {
4427 if(bios[0x53] & 0x02) {
4428 orSISIDXREG(SISSR, 0x19, 0x20);
4429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 }
4431 v1 = 0x04; /* DAC pedestal (BIOS 0xe5) */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004432 if(ivideo->revision_id >= 0x80)
4433 v1 |= 0x01;
4434 outSISIDXREG(SISSR, 0x1f, v1);
4435 outSISIDXREG(SISSR, 0x20, 0xa4); /* linear & relocated io & disable a0000 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 v1 = 0xf6; v2 = 0x0d; v3 = 0x00;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004437 if(bios) {
4438 v1 = bios[0xe8];
4439 v2 = bios[0xe9];
4440 v3 = bios[0xea];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004442 outSISIDXREG(SISSR, 0x23, v1);
4443 outSISIDXREG(SISSR, 0x24, v2);
4444 outSISIDXREG(SISSR, 0x25, v3);
4445 outSISIDXREG(SISSR, 0x21, 0x84);
4446 outSISIDXREG(SISSR, 0x22, 0x00);
4447 outSISIDXREG(SISCR, 0x37, 0x00);
4448 orSISIDXREG(SISPART1, 0x24, 0x01); /* unlock crt2 */
4449 outSISIDXREG(SISPART1, 0x00, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 v1 = 0x40; v2 = 0x11;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004451 if(bios) {
4452 v1 = bios[0xec];
4453 v2 = bios[0xeb];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004455 outSISIDXREG(SISPART1, 0x02, v1);
4456
4457 if(ivideo->revision_id >= 0x80)
4458 v2 &= ~0x01;
4459
4460 inSISIDXREG(SISPART4, 0x00, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 if((reg == 1) || (reg == 2)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004462 outSISIDXREG(SISCR, 0x37, 0x02);
4463 outSISIDXREG(SISPART2, 0x00, 0x1c);
4464 v4 = 0x00; v5 = 0x00; v6 = 0x10;
4465 if(ivideo->SiS_Pr.UseROM) {
4466 v4 = bios[0xf5];
4467 v5 = bios[0xf6];
4468 v6 = bios[0xf7];
4469 }
4470 outSISIDXREG(SISPART4, 0x0d, v4);
4471 outSISIDXREG(SISPART4, 0x0e, v5);
4472 outSISIDXREG(SISPART4, 0x10, v6);
4473 outSISIDXREG(SISPART4, 0x0f, 0x3f);
4474 inSISIDXREG(SISPART4, 0x01, reg);
4475 if(reg >= 0xb0) {
4476 inSISIDXREG(SISPART4, 0x23, reg);
4477 reg &= 0x20;
4478 reg <<= 1;
4479 outSISIDXREG(SISPART4, 0x23, reg);
4480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004482 v2 &= ~0x10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004484 outSISIDXREG(SISSR, 0x32, v2);
4485
4486 andSISIDXREG(SISPART1, 0x24, 0xfe); /* Lock CRT2 */
4487
4488 inSISIDXREG(SISSR, 0x16, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 reg &= 0xc3;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004490 outSISIDXREG(SISCR, 0x35, reg);
4491 outSISIDXREG(SISCR, 0x83, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492#if !defined(__i386__) && !defined(__x86_64__)
4493 if(sisfb_videoram) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004494 outSISIDXREG(SISSR, 0x13, 0x28); /* ? */
4495 reg = ((sisfb_videoram >> 10) - 1) | 0x40;
4496 outSISIDXREG(SISSR, 0x14, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 } else {
4498#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004499 /* Need to map max FB size for finding out about RAM size */
Aaro Koskinen32ed3032010-11-10 13:04:19 +02004500 mapsize = ivideo->video_size;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004501 sisfb_post_map_vram(ivideo, &mapsize, 4);
4502
4503 if(ivideo->video_vbase) {
4504 sisfb_post_300_ramsize(pdev, mapsize);
4505 iounmap(ivideo->video_vbase);
4506 } else {
4507 printk(KERN_DEBUG
4508 "sisfb: Failed to map memory for size detection, assuming 8MB\n");
4509 outSISIDXREG(SISSR, 0x13, 0x28); /* ? */
4510 outSISIDXREG(SISSR, 0x14, 0x47); /* 8MB, 64bit default */
4511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512#if !defined(__i386__) && !defined(__x86_64__)
4513 }
4514#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004515 if(bios) {
4516 v1 = bios[0xe6];
4517 v2 = bios[0xe7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004519 inSISIDXREG(SISSR, 0x3a, reg);
4520 if((reg & 0x30) == 0x30) {
4521 v1 = 0x04; /* PCI */
4522 v2 = 0x92;
4523 } else {
4524 v1 = 0x14; /* AGP */
4525 v2 = 0xb2;
4526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004528 outSISIDXREG(SISSR, 0x21, v1);
4529 outSISIDXREG(SISSR, 0x22, v2);
4530
4531 /* Sense CRT1 */
4532 sisfb_sense_crt1(ivideo);
4533
4534 /* Set default mode, don't clear screen */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08004535 ivideo->SiS_Pr.SiS_UseOEM = false;
4536 SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
4537 SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004538 ivideo->curFSTN = ivideo->curDSTN = 0;
4539 ivideo->SiS_Pr.VideoMemorySize = 8 << 20;
4540 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
4541
4542 outSISIDXREG(SISSR, 0x05, 0x86);
4543
4544 /* Display off */
4545 orSISIDXREG(SISSR, 0x01, 0x20);
4546
4547 /* Save mode number in CR34 */
4548 outSISIDXREG(SISCR, 0x34, 0x2e);
4549
4550 /* Let everyone know what the current mode is */
4551 ivideo->modeprechange = 0x2e;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552}
4553#endif
4554
4555#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004556#if 0
4557static void __devinit
4558sisfb_post_sis315330(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004560 /* TODO */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561}
4562#endif
4563
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004564static void __devinit
4565sisfb_post_xgi_delay(struct sis_video_info *ivideo, int delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004567 unsigned int i;
4568 u8 reg;
4569
4570 for(i = 0; i <= (delay * 10 * 36); i++) {
4571 inSISIDXREG(SISSR, 0x05, reg);
4572 reg++;
4573 }
4574}
4575
4576static int __devinit
4577sisfb_find_host_bridge(struct sis_video_info *ivideo, struct pci_dev *mypdev,
4578 unsigned short pcivendor)
4579{
4580 struct pci_dev *pdev = NULL;
4581 unsigned short temp;
4582 int ret = 0;
4583
Adrian Bunk0959f0c2007-05-08 00:39:50 -07004584 while((pdev = pci_get_class(PCI_CLASS_BRIDGE_HOST, pdev))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004585 temp = pdev->vendor;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004586 if(temp == pcivendor) {
4587 ret = 1;
Julia Lawallea237a62008-02-06 01:39:07 -08004588 pci_dev_put(pdev);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004589 break;
4590 }
4591 }
4592
4593 return ret;
4594}
4595
4596static int __devinit
4597sisfb_post_xgi_rwtest(struct sis_video_info *ivideo, int starta,
4598 unsigned int enda, unsigned int mapsize)
4599{
4600 unsigned int pos;
4601 int i;
4602
4603 writel(0, ivideo->video_vbase);
4604
4605 for(i = starta; i <= enda; i++) {
4606 pos = 1 << i;
4607 if(pos < mapsize)
4608 writel(pos, ivideo->video_vbase + pos);
4609 }
4610
4611 sisfb_post_xgi_delay(ivideo, 150);
4612
4613 if(readl(ivideo->video_vbase) != 0)
4614 return 0;
4615
4616 for(i = starta; i <= enda; i++) {
4617 pos = 1 << i;
4618 if(pos < mapsize) {
4619 if(readl(ivideo->video_vbase + pos) != pos)
4620 return 0;
4621 } else
4622 return 0;
4623 }
4624
4625 return 1;
4626}
4627
4628static void __devinit
4629sisfb_post_xgi_ramsize(struct sis_video_info *ivideo)
4630{
4631 unsigned int buswidth, ranksize, channelab, mapsize;
4632 int i, j, k, l;
4633 u8 reg, sr14;
4634 static const u8 dramsr13[12 * 5] = {
4635 0x02, 0x0e, 0x0b, 0x80, 0x5d,
4636 0x02, 0x0e, 0x0a, 0x40, 0x59,
4637 0x02, 0x0d, 0x0b, 0x40, 0x4d,
4638 0x02, 0x0e, 0x09, 0x20, 0x55,
4639 0x02, 0x0d, 0x0a, 0x20, 0x49,
4640 0x02, 0x0c, 0x0b, 0x20, 0x3d,
4641 0x02, 0x0e, 0x08, 0x10, 0x51,
4642 0x02, 0x0d, 0x09, 0x10, 0x45,
4643 0x02, 0x0c, 0x0a, 0x10, 0x39,
4644 0x02, 0x0d, 0x08, 0x08, 0x41,
4645 0x02, 0x0c, 0x09, 0x08, 0x35,
4646 0x02, 0x0c, 0x08, 0x04, 0x31
4647 };
4648 static const u8 dramsr13_4[4 * 5] = {
4649 0x02, 0x0d, 0x09, 0x40, 0x45,
4650 0x02, 0x0c, 0x09, 0x20, 0x35,
4651 0x02, 0x0c, 0x08, 0x10, 0x31,
4652 0x02, 0x0b, 0x08, 0x08, 0x21
4653 };
4654
4655 /* Enable linear mode, disable 0xa0000 address decoding */
4656 /* We disable a0000 address decoding, because
4657 * - if running on x86, if the card is disabled, it means
4658 * that another card is in the system. We don't want
4659 * to interphere with that primary card's textmode.
4660 * - if running on non-x86, there usually is no VGA window
4661 * at a0000.
4662 */
4663 orSISIDXREG(SISSR, 0x20, (0x80 | 0x04));
4664
4665 /* Need to map max FB size for finding out about RAM size */
Aaro Koskinen32ed3032010-11-10 13:04:19 +02004666 mapsize = ivideo->video_size;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07004667 sisfb_post_map_vram(ivideo, &mapsize, 32);
4668
4669 if(!ivideo->video_vbase) {
4670 printk(KERN_ERR "sisfb: Unable to detect RAM size. Setting default.\n");
4671 outSISIDXREG(SISSR, 0x13, 0x35);
4672 outSISIDXREG(SISSR, 0x14, 0x41);
4673 /* TODO */
4674 return;
4675 }
4676
4677 /* Non-interleaving */
4678 outSISIDXREG(SISSR, 0x15, 0x00);
4679 /* No tiling */
4680 outSISIDXREG(SISSR, 0x1c, 0x00);
4681
4682 if(ivideo->chip == XGI_20) {
4683
4684 channelab = 1;
4685 inSISIDXREG(SISCR, 0x97, reg);
4686 if(!(reg & 0x01)) { /* Single 32/16 */
4687 buswidth = 32;
4688 outSISIDXREG(SISSR, 0x13, 0xb1);
4689 outSISIDXREG(SISSR, 0x14, 0x52);
4690 sisfb_post_xgi_delay(ivideo, 1);
4691 sr14 = 0x02;
4692 if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
4693 goto bail_out;
4694
4695 outSISIDXREG(SISSR, 0x13, 0x31);
4696 outSISIDXREG(SISSR, 0x14, 0x42);
4697 sisfb_post_xgi_delay(ivideo, 1);
4698 if(sisfb_post_xgi_rwtest(ivideo, 23, 23, mapsize))
4699 goto bail_out;
4700
4701 buswidth = 16;
4702 outSISIDXREG(SISSR, 0x13, 0xb1);
4703 outSISIDXREG(SISSR, 0x14, 0x41);
4704 sisfb_post_xgi_delay(ivideo, 1);
4705 sr14 = 0x01;
4706 if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
4707 goto bail_out;
4708 else
4709 outSISIDXREG(SISSR, 0x13, 0x31);
4710 } else { /* Dual 16/8 */
4711 buswidth = 16;
4712 outSISIDXREG(SISSR, 0x13, 0xb1);
4713 outSISIDXREG(SISSR, 0x14, 0x41);
4714 sisfb_post_xgi_delay(ivideo, 1);
4715 sr14 = 0x01;
4716 if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
4717 goto bail_out;
4718
4719 outSISIDXREG(SISSR, 0x13, 0x31);
4720 outSISIDXREG(SISSR, 0x14, 0x31);
4721 sisfb_post_xgi_delay(ivideo, 1);
4722 if(sisfb_post_xgi_rwtest(ivideo, 22, 22, mapsize))
4723 goto bail_out;
4724
4725 buswidth = 8;
4726 outSISIDXREG(SISSR, 0x13, 0xb1);
4727 outSISIDXREG(SISSR, 0x14, 0x30);
4728 sisfb_post_xgi_delay(ivideo, 1);
4729 sr14 = 0x00;
4730 if(sisfb_post_xgi_rwtest(ivideo, 21, 22, mapsize))
4731 goto bail_out;
4732 else
4733 outSISIDXREG(SISSR, 0x13, 0x31);
4734 }
4735
4736 } else { /* XGI_40 */
4737
4738 inSISIDXREG(SISCR, 0x97, reg);
4739 if(!(reg & 0x10)) {
4740 inSISIDXREG(SISSR, 0x39, reg);
4741 reg >>= 1;
4742 }
4743
4744 if(reg & 0x01) { /* DDRII */
4745 buswidth = 32;
4746 if(ivideo->revision_id == 2) {
4747 channelab = 2;
4748 outSISIDXREG(SISSR, 0x13, 0xa1);
4749 outSISIDXREG(SISSR, 0x14, 0x44);
4750 sr14 = 0x04;
4751 sisfb_post_xgi_delay(ivideo, 1);
4752 if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
4753 goto bail_out;
4754
4755 outSISIDXREG(SISSR, 0x13, 0x21);
4756 outSISIDXREG(SISSR, 0x14, 0x34);
4757 if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
4758 goto bail_out;
4759
4760 channelab = 1;
4761 outSISIDXREG(SISSR, 0x13, 0xa1);
4762 outSISIDXREG(SISSR, 0x14, 0x40);
4763 sr14 = 0x00;
4764 if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
4765 goto bail_out;
4766
4767 outSISIDXREG(SISSR, 0x13, 0x21);
4768 outSISIDXREG(SISSR, 0x14, 0x30);
4769 } else {
4770 channelab = 3;
4771 outSISIDXREG(SISSR, 0x13, 0xa1);
4772 outSISIDXREG(SISSR, 0x14, 0x4c);
4773 sr14 = 0x0c;
4774 sisfb_post_xgi_delay(ivideo, 1);
4775 if(sisfb_post_xgi_rwtest(ivideo, 23, 25, mapsize))
4776 goto bail_out;
4777
4778 channelab = 2;
4779 outSISIDXREG(SISSR, 0x14, 0x48);
4780 sisfb_post_xgi_delay(ivideo, 1);
4781 sr14 = 0x08;
4782 if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
4783 goto bail_out;
4784
4785 outSISIDXREG(SISSR, 0x13, 0x21);
4786 outSISIDXREG(SISSR, 0x14, 0x3c);
4787 sr14 = 0x0c;
4788
4789 if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize)) {
4790 channelab = 3;
4791 } else {
4792 channelab = 2;
4793 outSISIDXREG(SISSR, 0x14, 0x38);
4794 sr14 = 0x08;
4795 }
4796 }
4797 sisfb_post_xgi_delay(ivideo, 1);
4798
4799 } else { /* DDR */
4800
4801 buswidth = 64;
4802 if(ivideo->revision_id == 2) {
4803 channelab = 1;
4804 outSISIDXREG(SISSR, 0x13, 0xa1);
4805 outSISIDXREG(SISSR, 0x14, 0x52);
4806 sisfb_post_xgi_delay(ivideo, 1);
4807 sr14 = 0x02;
4808 if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
4809 goto bail_out;
4810
4811 outSISIDXREG(SISSR, 0x13, 0x21);
4812 outSISIDXREG(SISSR, 0x14, 0x42);
4813 } else {
4814 channelab = 2;
4815 outSISIDXREG(SISSR, 0x13, 0xa1);
4816 outSISIDXREG(SISSR, 0x14, 0x5a);
4817 sisfb_post_xgi_delay(ivideo, 1);
4818 sr14 = 0x0a;
4819 if(sisfb_post_xgi_rwtest(ivideo, 24, 25, mapsize))
4820 goto bail_out;
4821
4822 outSISIDXREG(SISSR, 0x13, 0x21);
4823 outSISIDXREG(SISSR, 0x14, 0x4a);
4824 }
4825 sisfb_post_xgi_delay(ivideo, 1);
4826
4827 }
4828 }
4829
4830bail_out:
4831 setSISIDXREG(SISSR, 0x14, 0xf0, sr14);
4832 sisfb_post_xgi_delay(ivideo, 1);
4833
4834 j = (ivideo->chip == XGI_20) ? 5 : 9;
4835 k = (ivideo->chip == XGI_20) ? 12 : 4;
4836
4837 for(i = 0; i < k; i++) {
4838
4839 reg = (ivideo->chip == XGI_20) ?
4840 dramsr13[(i * 5) + 4] : dramsr13_4[(i * 5) + 4];
4841 setSISIDXREG(SISSR, 0x13, 0x80, reg);
4842 sisfb_post_xgi_delay(ivideo, 50);
4843
4844 ranksize = (ivideo->chip == XGI_20) ?
4845 dramsr13[(i * 5) + 3] : dramsr13_4[(i * 5) + 3];
4846
4847 inSISIDXREG(SISSR, 0x13, reg);
4848 if(reg & 0x80) ranksize <<= 1;
4849
4850 if(ivideo->chip == XGI_20) {
4851 if(buswidth == 16) ranksize <<= 1;
4852 else if(buswidth == 32) ranksize <<= 2;
4853 } else {
4854 if(buswidth == 64) ranksize <<= 1;
4855 }
4856
4857 reg = 0;
4858 l = channelab;
4859 if(l == 3) l = 4;
4860 if((ranksize * l) <= 256) {
4861 while((ranksize >>= 1)) reg += 0x10;
4862 }
4863
4864 if(!reg) continue;
4865
4866 setSISIDXREG(SISSR, 0x14, 0x0f, (reg & 0xf0));
4867 sisfb_post_xgi_delay(ivideo, 1);
4868
4869 if(sisfb_post_xgi_rwtest(ivideo, j, ((reg >> 4) + channelab - 2 + 20), mapsize))
4870 break;
4871 }
4872
4873 iounmap(ivideo->video_vbase);
4874}
4875
4876static void __devinit
4877sisfb_post_xgi_setclocks(struct sis_video_info *ivideo, u8 regb)
4878{
4879 u8 v1, v2, v3;
4880 int index;
4881 static const u8 cs90[8 * 3] = {
4882 0x16, 0x01, 0x01,
4883 0x3e, 0x03, 0x01,
4884 0x7c, 0x08, 0x01,
4885 0x79, 0x06, 0x01,
4886 0x29, 0x01, 0x81,
4887 0x5c, 0x23, 0x01,
4888 0x5c, 0x23, 0x01,
4889 0x5c, 0x23, 0x01
4890 };
4891 static const u8 csb8[8 * 3] = {
4892 0x5c, 0x23, 0x01,
4893 0x29, 0x01, 0x01,
4894 0x7c, 0x08, 0x01,
4895 0x79, 0x06, 0x01,
4896 0x29, 0x01, 0x81,
4897 0x5c, 0x23, 0x01,
4898 0x5c, 0x23, 0x01,
4899 0x5c, 0x23, 0x01
4900 };
4901
4902 regb = 0; /* ! */
4903
4904 index = regb * 3;
4905 v1 = cs90[index]; v2 = cs90[index + 1]; v3 = cs90[index + 2];
4906 if(ivideo->haveXGIROM) {
4907 v1 = ivideo->bios_abase[0x90 + index];
4908 v2 = ivideo->bios_abase[0x90 + index + 1];
4909 v3 = ivideo->bios_abase[0x90 + index + 2];
4910 }
4911 outSISIDXREG(SISSR, 0x28, v1);
4912 outSISIDXREG(SISSR, 0x29, v2);
4913 outSISIDXREG(SISSR, 0x2a, v3);
4914 sisfb_post_xgi_delay(ivideo, 0x43);
4915 sisfb_post_xgi_delay(ivideo, 0x43);
4916 sisfb_post_xgi_delay(ivideo, 0x43);
4917 index = regb * 3;
4918 v1 = csb8[index]; v2 = csb8[index + 1]; v3 = csb8[index + 2];
4919 if(ivideo->haveXGIROM) {
4920 v1 = ivideo->bios_abase[0xb8 + index];
4921 v2 = ivideo->bios_abase[0xb8 + index + 1];
4922 v3 = ivideo->bios_abase[0xb8 + index + 2];
4923 }
4924 outSISIDXREG(SISSR, 0x2e, v1);
4925 outSISIDXREG(SISSR, 0x2f, v2);
4926 outSISIDXREG(SISSR, 0x30, v3);
4927 sisfb_post_xgi_delay(ivideo, 0x43);
4928 sisfb_post_xgi_delay(ivideo, 0x43);
4929 sisfb_post_xgi_delay(ivideo, 0x43);
4930}
4931
4932static int __devinit
4933sisfb_post_xgi(struct pci_dev *pdev)
4934{
4935 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
4936 unsigned char *bios = ivideo->bios_abase;
4937 struct pci_dev *mypdev = NULL;
4938 const u8 *ptr, *ptr2;
4939 u8 v1, v2, v3, v4, v5, reg, ramtype;
4940 u32 rega, regb, regd;
4941 int i, j, k, index;
4942 static const u8 cs78[3] = { 0xf6, 0x0d, 0x00 };
4943 static const u8 cs76[2] = { 0xa3, 0xfb };
4944 static const u8 cs7b[3] = { 0xc0, 0x11, 0x00 };
4945 static const u8 cs158[8] = {
4946 0x88, 0xaa, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00
4947 };
4948 static const u8 cs160[8] = {
4949 0x44, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00
4950 };
4951 static const u8 cs168[8] = {
4952 0x48, 0x78, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00
4953 };
4954 static const u8 cs128[3 * 8] = {
4955 0x90, 0x28, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
4956 0x77, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
4957 0x77, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00
4958 };
4959 static const u8 cs148[2 * 8] = {
4960 0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00,
4961 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4962 };
4963 static const u8 cs31a[8 * 4] = {
4964 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
4965 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
4966 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4967 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4968 };
4969 static const u8 cs33a[8 * 4] = {
4970 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4971 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4972 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4973 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4974 };
4975 static const u8 cs45a[8 * 2] = {
4976 0x00, 0x00, 0xa0, 0x00, 0xa0, 0x00, 0x00, 0x00,
4977 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4978 };
4979 static const u8 cs170[7 * 8] = {
4980 0x54, 0x32, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
4981 0x54, 0x43, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
4982 0x0a, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
4983 0x44, 0x34, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
4984 0x10, 0x0a, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
4985 0x11, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
4986 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00
4987 };
4988 static const u8 cs1a8[3 * 8] = {
4989 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
4990 0x05, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
4991 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4992 };
4993 static const u8 cs100[2 * 8] = {
4994 0xc4, 0x04, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00,
4995 0xc4, 0x04, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
4996 };
4997
4998 /* VGA enable */
4999 reg = inSISREG(SISVGAENABLE) | 0x01;
5000 outSISREG(SISVGAENABLE, reg);
5001
5002 /* Misc */
5003 reg = inSISREG(SISMISCR) | 0x01;
5004 outSISREG(SISMISCW, reg);
5005
5006 /* Unlock SR */
5007 outSISIDXREG(SISSR, 0x05, 0x86);
5008 inSISIDXREG(SISSR, 0x05, reg);
5009 if(reg != 0xa1)
5010 return 0;
5011
5012 /* Clear some regs */
5013 for(i = 0; i < 0x22; i++) {
5014 if(0x06 + i == 0x20) continue;
5015 outSISIDXREG(SISSR, 0x06 + i, 0x00);
5016 }
5017 for(i = 0; i < 0x0b; i++) {
5018 outSISIDXREG(SISSR, 0x31 + i, 0x00);
5019 }
5020 for(i = 0; i < 0x10; i++) {
5021 outSISIDXREG(SISCR, 0x30 + i, 0x00);
5022 }
5023
5024 ptr = cs78;
5025 if(ivideo->haveXGIROM) {
5026 ptr = (const u8 *)&bios[0x78];
5027 }
5028 for(i = 0; i < 3; i++) {
5029 outSISIDXREG(SISSR, 0x23 + i, ptr[i]);
5030 }
5031
5032 ptr = cs76;
5033 if(ivideo->haveXGIROM) {
5034 ptr = (const u8 *)&bios[0x76];
5035 }
5036 for(i = 0; i < 2; i++) {
5037 outSISIDXREG(SISSR, 0x21 + i, ptr[i]);
5038 }
5039
5040 v1 = 0x18; v2 = 0x00;
5041 if(ivideo->haveXGIROM) {
5042 v1 = bios[0x74];
5043 v2 = bios[0x75];
5044 }
5045 outSISIDXREG(SISSR, 0x07, v1);
5046 outSISIDXREG(SISSR, 0x11, 0x0f);
5047 outSISIDXREG(SISSR, 0x1f, v2);
5048 /* PCI linear mode, RelIO enabled, A0000 decoding disabled */
5049 outSISIDXREG(SISSR, 0x20, 0x80 | 0x20 | 0x04);
5050 outSISIDXREG(SISSR, 0x27, 0x74);
5051
5052 ptr = cs7b;
5053 if(ivideo->haveXGIROM) {
5054 ptr = (const u8 *)&bios[0x7b];
5055 }
5056 for(i = 0; i < 3; i++) {
5057 outSISIDXREG(SISSR, 0x31 + i, ptr[i]);
5058 }
5059
5060 if(ivideo->chip == XGI_40) {
5061 if(ivideo->revision_id == 2) {
5062 setSISIDXREG(SISSR, 0x3b, 0x3f, 0xc0);
5063 }
5064 outSISIDXREG(SISCR, 0x7d, 0xfe);
5065 outSISIDXREG(SISCR, 0x7e, 0x0f);
5066 }
5067 if(ivideo->revision_id == 0) { /* 40 *and* 20? */
5068 andSISIDXREG(SISCR, 0x58, 0xd7);
5069 inSISIDXREG(SISCR, 0xcb, reg);
5070 if(reg & 0x20) {
5071 setSISIDXREG(SISCR, 0x58, 0xd7, (reg & 0x10) ? 0x08 : 0x20); /* =0x28 Z7 ? */
5072 }
5073 }
5074
5075 reg = (ivideo->chip == XGI_40) ? 0x20 : 0x00;
5076 setSISIDXREG(SISCR, 0x38, 0x1f, reg);
5077
5078 if(ivideo->chip == XGI_20) {
5079 outSISIDXREG(SISSR, 0x36, 0x70);
5080 } else {
5081 outSISIDXREG(SISVID, 0x00, 0x86);
5082 outSISIDXREG(SISVID, 0x32, 0x00);
5083 outSISIDXREG(SISVID, 0x30, 0x00);
5084 outSISIDXREG(SISVID, 0x32, 0x01);
5085 outSISIDXREG(SISVID, 0x30, 0x00);
5086 andSISIDXREG(SISVID, 0x2f, 0xdf);
5087 andSISIDXREG(SISCAP, 0x00, 0x3f);
5088
5089 outSISIDXREG(SISPART1, 0x2f, 0x01);
5090 outSISIDXREG(SISPART1, 0x00, 0x00);
5091 outSISIDXREG(SISPART1, 0x02, bios[0x7e]);
5092 outSISIDXREG(SISPART1, 0x2e, 0x08);
5093 andSISIDXREG(SISPART1, 0x35, 0x7f);
5094 andSISIDXREG(SISPART1, 0x50, 0xfe);
5095
5096 inSISIDXREG(SISPART4, 0x00, reg);
5097 if(reg == 1 || reg == 2) {
5098 outSISIDXREG(SISPART2, 0x00, 0x1c);
5099 outSISIDXREG(SISPART4, 0x0d, bios[0x7f]);
5100 outSISIDXREG(SISPART4, 0x0e, bios[0x80]);
5101 outSISIDXREG(SISPART4, 0x10, bios[0x81]);
5102 andSISIDXREG(SISPART4, 0x0f, 0x3f);
5103
5104 inSISIDXREG(SISPART4, 0x01, reg);
5105 if((reg & 0xf0) >= 0xb0) {
5106 inSISIDXREG(SISPART4, 0x23, reg);
5107 if(reg & 0x20) reg |= 0x40;
5108 outSISIDXREG(SISPART4, 0x23, reg);
5109 reg = (reg & 0x20) ? 0x02 : 0x00;
5110 setSISIDXREG(SISPART1, 0x1e, 0xfd, reg);
5111 }
5112 }
5113
5114 v1 = bios[0x77];
5115
5116 inSISIDXREG(SISSR, 0x3b, reg);
5117 if(reg & 0x02) {
5118 inSISIDXREG(SISSR, 0x3a, reg);
5119 v2 = (reg & 0x30) >> 3;
5120 if(!(v2 & 0x04)) v2 ^= 0x02;
5121 inSISIDXREG(SISSR, 0x39, reg);
5122 if(reg & 0x80) v2 |= 0x80;
5123 v2 |= 0x01;
5124
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005125 if((mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0730, NULL))) {
5126 pci_dev_put(mypdev);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005127 if(((v2 & 0x06) == 2) || ((v2 & 0x06) == 4))
5128 v2 &= 0xf9;
5129 v2 |= 0x08;
5130 v1 &= 0xfe;
5131 } else {
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005132 mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0735, NULL);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005133 if(!mypdev)
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005134 mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0645, NULL);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005135 if(!mypdev)
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005136 mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0650, NULL);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005137 if(mypdev) {
5138 pci_read_config_dword(mypdev, 0x94, &regd);
5139 regd &= 0xfffffeff;
5140 pci_write_config_dword(mypdev, 0x94, regd);
5141 v1 &= 0xfe;
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005142 pci_dev_put(mypdev);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005143 } else if(sisfb_find_host_bridge(ivideo, pdev, PCI_VENDOR_ID_SI)) {
5144 v1 &= 0xfe;
5145 } else if(sisfb_find_host_bridge(ivideo, pdev, 0x1106) ||
5146 sisfb_find_host_bridge(ivideo, pdev, 0x1022) ||
5147 sisfb_find_host_bridge(ivideo, pdev, 0x700e) ||
5148 sisfb_find_host_bridge(ivideo, pdev, 0x10de)) {
5149 if((v2 & 0x06) == 4)
5150 v2 ^= 0x06;
5151 v2 |= 0x08;
5152 }
5153 }
5154 setSISIDXREG(SISCR, 0x5f, 0xf0, v2);
5155 }
5156 outSISIDXREG(SISSR, 0x22, v1);
5157
5158 if(ivideo->revision_id == 2) {
5159 inSISIDXREG(SISSR, 0x3b, v1);
5160 inSISIDXREG(SISSR, 0x3a, v2);
5161 regd = bios[0x90 + 3] | (bios[0x90 + 4] << 8);
5162 if( (!(v1 & 0x02)) && (v2 & 0x30) && (regd < 0xcf) )
5163 setSISIDXREG(SISCR, 0x5f, 0xf1, 0x01);
5164
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005165 if((mypdev = pci_get_device(0x10de, 0x01e0, NULL))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005166 /* TODO: set CR5f &0xf1 | 0x01 for version 6570
5167 * of nforce 2 ROM
5168 */
5169 if(0)
5170 setSISIDXREG(SISCR, 0x5f, 0xf1, 0x01);
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005171 pci_dev_put(mypdev);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005172 }
5173 }
5174
5175 v1 = 0x30;
5176 inSISIDXREG(SISSR, 0x3b, reg);
5177 inSISIDXREG(SISCR, 0x5f, v2);
5178 if((!(reg & 0x02)) && (v2 & 0x0e))
5179 v1 |= 0x08;
5180 outSISIDXREG(SISSR, 0x27, v1);
5181
5182 if(bios[0x64] & 0x01) {
5183 setSISIDXREG(SISCR, 0x5f, 0xf0, bios[0x64]);
5184 }
5185
5186 v1 = bios[0x4f7];
5187 pci_read_config_dword(pdev, 0x50, &regd);
5188 regd = (regd >> 20) & 0x0f;
5189 if(regd == 1) {
5190 v1 &= 0xfc;
5191 orSISIDXREG(SISCR, 0x5f, 0x08);
5192 }
5193 outSISIDXREG(SISCR, 0x48, v1);
5194
5195 setSISIDXREG(SISCR, 0x47, 0x04, bios[0x4f6] & 0xfb);
5196 setSISIDXREG(SISCR, 0x49, 0xf0, bios[0x4f8] & 0x0f);
5197 setSISIDXREG(SISCR, 0x4a, 0x60, bios[0x4f9] & 0x9f);
5198 setSISIDXREG(SISCR, 0x4b, 0x08, bios[0x4fa] & 0xf7);
5199 setSISIDXREG(SISCR, 0x4c, 0x80, bios[0x4fb] & 0x7f);
5200 outSISIDXREG(SISCR, 0x70, bios[0x4fc]);
5201 setSISIDXREG(SISCR, 0x71, 0xf0, bios[0x4fd] & 0x0f);
5202 outSISIDXREG(SISCR, 0x74, 0xd0);
5203 setSISIDXREG(SISCR, 0x74, 0xcf, bios[0x4fe] & 0x30);
5204 setSISIDXREG(SISCR, 0x75, 0xe0, bios[0x4ff] & 0x1f);
5205 setSISIDXREG(SISCR, 0x76, 0xe0, bios[0x500] & 0x1f);
5206 v1 = bios[0x501];
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005207 if((mypdev = pci_get_device(0x8086, 0x2530, NULL))) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005208 v1 = 0xf0;
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005209 pci_dev_put(mypdev);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005210 }
5211 outSISIDXREG(SISCR, 0x77, v1);
5212 }
5213
5214 /* RAM type */
5215
5216 regb = 0; /* ! */
5217
5218 v1 = 0xff;
5219 if(ivideo->haveXGIROM) {
5220 v1 = bios[0x140 + regb];
5221 }
5222 outSISIDXREG(SISCR, 0x6d, v1);
5223
5224 ptr = cs128;
5225 if(ivideo->haveXGIROM) {
5226 ptr = (const u8 *)&bios[0x128];
5227 }
5228 for(i = 0, j = 0; i < 3; i++, j += 8) {
5229 outSISIDXREG(SISCR, 0x68 + i, ptr[j + regb]);
5230 }
5231
5232 ptr = cs31a;
5233 ptr2 = cs33a;
5234 if(ivideo->haveXGIROM) {
5235 index = (ivideo->chip == XGI_20) ? 0x31a : 0x3a6;
5236 ptr = (const u8 *)&bios[index];
5237 ptr2 = (const u8 *)&bios[index + 0x20];
5238 }
5239 for(i = 0; i < 2; i++) {
5240 if(i == 0) {
5241 regd = le32_to_cpu(((u32 *)ptr)[regb]);
5242 rega = 0x6b;
5243 } else {
5244 regd = le32_to_cpu(((u32 *)ptr2)[regb]);
5245 rega = 0x6e;
5246 }
5247 reg = 0x00;
5248 for(j = 0; j < 16; j++) {
5249 reg &= 0xf3;
5250 if(regd & 0x01) reg |= 0x04;
5251 if(regd & 0x02) reg |= 0x08;
5252 regd >>= 2;
5253 outSISIDXREG(SISCR, rega, reg);
5254 inSISIDXREG(SISCR, rega, reg);
5255 inSISIDXREG(SISCR, rega, reg);
5256 reg += 0x10;
5257 }
5258 }
5259
5260 andSISIDXREG(SISCR, 0x6e, 0xfc);
5261
5262 ptr = NULL;
5263 if(ivideo->haveXGIROM) {
5264 index = (ivideo->chip == XGI_20) ? 0x35a : 0x3e6;
5265 ptr = (const u8 *)&bios[index];
5266 }
5267 for(i = 0; i < 4; i++) {
5268 setSISIDXREG(SISCR, 0x6e, 0xfc, i);
5269 reg = 0x00;
5270 for(j = 0; j < 2; j++) {
5271 regd = 0;
5272 if(ptr) {
5273 regd = le32_to_cpu(((u32 *)ptr)[regb * 8]);
5274 ptr += 4;
5275 }
5276 /* reg = 0x00; */
5277 for(k = 0; k < 16; k++) {
5278 reg &= 0xfc;
5279 if(regd & 0x01) reg |= 0x01;
5280 if(regd & 0x02) reg |= 0x02;
5281 regd >>= 2;
5282 outSISIDXREG(SISCR, 0x6f, reg);
5283 inSISIDXREG(SISCR, 0x6f, reg);
5284 inSISIDXREG(SISCR, 0x6f, reg);
5285 reg += 0x08;
5286 }
5287 }
5288 }
5289
5290 ptr = cs148;
5291 if(ivideo->haveXGIROM) {
5292 ptr = (const u8 *)&bios[0x148];
5293 }
5294 for(i = 0, j = 0; i < 2; i++, j += 8) {
5295 outSISIDXREG(SISCR, 0x80 + i, ptr[j + regb]);
5296 }
5297
5298 andSISIDXREG(SISCR, 0x89, 0x8f);
5299
5300 ptr = cs45a;
5301 if(ivideo->haveXGIROM) {
5302 index = (ivideo->chip == XGI_20) ? 0x45a : 0x4e6;
5303 ptr = (const u8 *)&bios[index];
5304 }
5305 regd = le16_to_cpu(((const u16 *)ptr)[regb]);
5306 reg = 0x80;
5307 for(i = 0; i < 5; i++) {
5308 reg &= 0xfc;
5309 if(regd & 0x01) reg |= 0x01;
5310 if(regd & 0x02) reg |= 0x02;
5311 regd >>= 2;
5312 outSISIDXREG(SISCR, 0x89, reg);
5313 inSISIDXREG(SISCR, 0x89, reg);
5314 inSISIDXREG(SISCR, 0x89, reg);
5315 reg += 0x10;
5316 }
5317
5318 v1 = 0xb5; v2 = 0x20; v3 = 0xf0; v4 = 0x13;
5319 if(ivideo->haveXGIROM) {
5320 v1 = bios[0x118 + regb];
5321 v2 = bios[0xf8 + regb];
5322 v3 = bios[0x120 + regb];
5323 v4 = bios[0x1ca];
5324 }
5325 outSISIDXREG(SISCR, 0x45, v1 & 0x0f);
5326 outSISIDXREG(SISCR, 0x99, (v1 >> 4) & 0x07);
5327 orSISIDXREG(SISCR, 0x40, v1 & 0x80);
5328 outSISIDXREG(SISCR, 0x41, v2);
5329
5330 ptr = cs170;
5331 if(ivideo->haveXGIROM) {
5332 ptr = (const u8 *)&bios[0x170];
5333 }
5334 for(i = 0, j = 0; i < 7; i++, j += 8) {
5335 outSISIDXREG(SISCR, 0x90 + i, ptr[j + regb]);
5336 }
5337
5338 outSISIDXREG(SISCR, 0x59, v3);
5339
5340 ptr = cs1a8;
5341 if(ivideo->haveXGIROM) {
5342 ptr = (const u8 *)&bios[0x1a8];
5343 }
5344 for(i = 0, j = 0; i < 3; i++, j += 8) {
5345 outSISIDXREG(SISCR, 0xc3 + i, ptr[j + regb]);
5346 }
5347
5348 ptr = cs100;
5349 if(ivideo->haveXGIROM) {
5350 ptr = (const u8 *)&bios[0x100];
5351 }
5352 for(i = 0, j = 0; i < 2; i++, j += 8) {
5353 outSISIDXREG(SISCR, 0x8a + i, ptr[j + regb]);
5354 }
5355
5356 outSISIDXREG(SISCR, 0xcf, v4);
5357
5358 outSISIDXREG(SISCR, 0x83, 0x09);
5359 outSISIDXREG(SISCR, 0x87, 0x00);
5360
5361 if(ivideo->chip == XGI_40) {
5362 if( (ivideo->revision_id == 1) ||
5363 (ivideo->revision_id == 2) ) {
5364 outSISIDXREG(SISCR, 0x8c, 0x87);
5365 }
5366 }
5367
5368 outSISIDXREG(SISSR, 0x17, 0x00);
5369 outSISIDXREG(SISSR, 0x1a, 0x87);
5370
5371 if(ivideo->chip == XGI_20) {
5372 outSISIDXREG(SISSR, 0x15, 0x00);
5373 outSISIDXREG(SISSR, 0x1c, 0x00);
5374 }
5375
5376 ramtype = 0x00; v1 = 0x10;
5377 if(ivideo->haveXGIROM) {
5378 ramtype = bios[0x62];
5379 v1 = bios[0x1d2];
5380 }
5381 if(!(ramtype & 0x80)) {
5382 if(ivideo->chip == XGI_20) {
5383 outSISIDXREG(SISCR, 0x97, v1);
5384 inSISIDXREG(SISCR, 0x97, reg);
5385 if(reg & 0x10) {
5386 ramtype = (reg & 0x01) << 1;
5387 }
5388 } else {
5389 inSISIDXREG(SISSR, 0x39, reg);
5390 ramtype = reg & 0x02;
5391 if(!(ramtype)) {
5392 inSISIDXREG(SISSR, 0x3a, reg);
5393 ramtype = (reg >> 1) & 0x01;
5394 }
5395 }
5396 }
5397 ramtype &= 0x07;
5398
5399 regb = 0; /* ! */
5400
5401 switch(ramtype) {
5402 case 0:
5403 sisfb_post_xgi_setclocks(ivideo, regb);
5404 if((ivideo->chip == XGI_20) ||
5405 (ivideo->revision_id == 1) ||
5406 (ivideo->revision_id == 2)) {
5407 v1 = cs158[regb]; v2 = cs160[regb]; v3 = cs168[regb];
5408 if(ivideo->haveXGIROM) {
5409 v1 = bios[regb + 0x158];
5410 v2 = bios[regb + 0x160];
5411 v3 = bios[regb + 0x168];
5412 }
5413 outSISIDXREG(SISCR, 0x82, v1);
5414 outSISIDXREG(SISCR, 0x85, v2);
5415 outSISIDXREG(SISCR, 0x86, v3);
5416 } else {
5417 outSISIDXREG(SISCR, 0x82, 0x88);
5418 outSISIDXREG(SISCR, 0x86, 0x00);
5419 inSISIDXREG(SISCR, 0x86, reg);
5420 outSISIDXREG(SISCR, 0x86, 0x88);
5421 inSISIDXREG(SISCR, 0x86, reg);
5422 outSISIDXREG(SISCR, 0x86, bios[regb + 0x168]);
5423 outSISIDXREG(SISCR, 0x82, 0x77);
5424 outSISIDXREG(SISCR, 0x85, 0x00);
5425 inSISIDXREG(SISCR, 0x85, reg);
5426 outSISIDXREG(SISCR, 0x85, 0x88);
5427 inSISIDXREG(SISCR, 0x85, reg);
5428 outSISIDXREG(SISCR, 0x85, bios[regb + 0x160]);
5429 outSISIDXREG(SISCR, 0x82, bios[regb + 0x158]);
5430 }
5431 if(ivideo->chip == XGI_40) {
5432 outSISIDXREG(SISCR, 0x97, 0x00);
5433 }
5434 outSISIDXREG(SISCR, 0x98, 0x01);
5435 outSISIDXREG(SISCR, 0x9a, 0x02);
5436
5437 outSISIDXREG(SISSR, 0x18, 0x01);
5438 if((ivideo->chip == XGI_20) ||
5439 (ivideo->revision_id == 2)) {
5440 outSISIDXREG(SISSR, 0x19, 0x40);
5441 } else {
5442 outSISIDXREG(SISSR, 0x19, 0x20);
5443 }
5444 outSISIDXREG(SISSR, 0x16, 0x00);
5445 outSISIDXREG(SISSR, 0x16, 0x80);
5446 if((ivideo->chip == XGI_20) || (bios[0x1cb] != 0x0c)) {
5447 sisfb_post_xgi_delay(ivideo, 0x43);
5448 sisfb_post_xgi_delay(ivideo, 0x43);
5449 sisfb_post_xgi_delay(ivideo, 0x43);
5450 outSISIDXREG(SISSR, 0x18, 0x00);
5451 if((ivideo->chip == XGI_20) ||
5452 (ivideo->revision_id == 2)) {
5453 outSISIDXREG(SISSR, 0x19, 0x40);
5454 } else {
5455 outSISIDXREG(SISSR, 0x19, 0x20);
5456 }
5457 } else if((ivideo->chip == XGI_40) && (bios[0x1cb] == 0x0c)) {
5458 /* outSISIDXREG(SISSR, 0x16, 0x0c); */ /* ? */
5459 }
5460 outSISIDXREG(SISSR, 0x16, 0x00);
5461 outSISIDXREG(SISSR, 0x16, 0x80);
5462 sisfb_post_xgi_delay(ivideo, 4);
5463 v1 = 0x31; v2 = 0x03; v3 = 0x83; v4 = 0x03; v5 = 0x83;
5464 if(ivideo->haveXGIROM) {
5465 v1 = bios[0xf0];
5466 index = (ivideo->chip == XGI_20) ? 0x4b2 : 0x53e;
5467 v2 = bios[index];
5468 v3 = bios[index + 1];
5469 v4 = bios[index + 2];
5470 v5 = bios[index + 3];
5471 }
5472 outSISIDXREG(SISSR, 0x18, v1);
5473 outSISIDXREG(SISSR, 0x19, ((ivideo->chip == XGI_20) ? 0x02 : 0x01));
5474 outSISIDXREG(SISSR, 0x16, v2);
5475 outSISIDXREG(SISSR, 0x16, v3);
5476 sisfb_post_xgi_delay(ivideo, 0x43);
5477 outSISIDXREG(SISSR, 0x1b, 0x03);
5478 sisfb_post_xgi_delay(ivideo, 0x22);
5479 outSISIDXREG(SISSR, 0x18, v1);
5480 outSISIDXREG(SISSR, 0x19, 0x00);
5481 outSISIDXREG(SISSR, 0x16, v4);
5482 outSISIDXREG(SISSR, 0x16, v5);
5483 outSISIDXREG(SISSR, 0x1b, 0x00);
5484 break;
5485 case 1:
5486 outSISIDXREG(SISCR, 0x82, 0x77);
5487 outSISIDXREG(SISCR, 0x86, 0x00);
5488 inSISIDXREG(SISCR, 0x86, reg);
5489 outSISIDXREG(SISCR, 0x86, 0x88);
5490 inSISIDXREG(SISCR, 0x86, reg);
5491 v1 = cs168[regb]; v2 = cs160[regb]; v3 = cs158[regb];
5492 if(ivideo->haveXGIROM) {
5493 v1 = bios[regb + 0x168];
5494 v2 = bios[regb + 0x160];
5495 v3 = bios[regb + 0x158];
5496 }
5497 outSISIDXREG(SISCR, 0x86, v1);
5498 outSISIDXREG(SISCR, 0x82, 0x77);
5499 outSISIDXREG(SISCR, 0x85, 0x00);
5500 inSISIDXREG(SISCR, 0x85, reg);
5501 outSISIDXREG(SISCR, 0x85, 0x88);
5502 inSISIDXREG(SISCR, 0x85, reg);
5503 outSISIDXREG(SISCR, 0x85, v2);
5504 outSISIDXREG(SISCR, 0x82, v3);
5505 outSISIDXREG(SISCR, 0x98, 0x01);
5506 outSISIDXREG(SISCR, 0x9a, 0x02);
5507
5508 outSISIDXREG(SISSR, 0x28, 0x64);
5509 outSISIDXREG(SISSR, 0x29, 0x63);
5510 sisfb_post_xgi_delay(ivideo, 15);
5511 outSISIDXREG(SISSR, 0x18, 0x00);
5512 outSISIDXREG(SISSR, 0x19, 0x20);
5513 outSISIDXREG(SISSR, 0x16, 0x00);
5514 outSISIDXREG(SISSR, 0x16, 0x80);
5515 outSISIDXREG(SISSR, 0x18, 0xc5);
5516 outSISIDXREG(SISSR, 0x19, 0x23);
5517 outSISIDXREG(SISSR, 0x16, 0x00);
5518 outSISIDXREG(SISSR, 0x16, 0x80);
5519 sisfb_post_xgi_delay(ivideo, 1);
5520 outSISIDXREG(SISCR, 0x97,0x11);
5521 sisfb_post_xgi_setclocks(ivideo, regb);
5522 sisfb_post_xgi_delay(ivideo, 0x46);
5523 outSISIDXREG(SISSR, 0x18, 0xc5);
5524 outSISIDXREG(SISSR, 0x19, 0x23);
5525 outSISIDXREG(SISSR, 0x16, 0x00);
5526 outSISIDXREG(SISSR, 0x16, 0x80);
5527 sisfb_post_xgi_delay(ivideo, 1);
5528 outSISIDXREG(SISSR, 0x1b, 0x04);
5529 sisfb_post_xgi_delay(ivideo, 1);
5530 outSISIDXREG(SISSR, 0x1b, 0x00);
5531 sisfb_post_xgi_delay(ivideo, 1);
5532 v1 = 0x31;
5533 if(ivideo->haveXGIROM) {
5534 v1 = bios[0xf0];
5535 }
5536 outSISIDXREG(SISSR, 0x18, v1);
5537 outSISIDXREG(SISSR, 0x19, 0x06);
5538 outSISIDXREG(SISSR, 0x16, 0x04);
5539 outSISIDXREG(SISSR, 0x16, 0x84);
5540 sisfb_post_xgi_delay(ivideo, 1);
5541 break;
5542 default:
5543 sisfb_post_xgi_setclocks(ivideo, regb);
5544 if((ivideo->chip == XGI_40) &&
5545 ((ivideo->revision_id == 1) ||
5546 (ivideo->revision_id == 2))) {
5547 outSISIDXREG(SISCR, 0x82, bios[regb + 0x158]);
5548 outSISIDXREG(SISCR, 0x85, bios[regb + 0x160]);
5549 outSISIDXREG(SISCR, 0x86, bios[regb + 0x168]);
5550 } else {
5551 outSISIDXREG(SISCR, 0x82, 0x88);
5552 outSISIDXREG(SISCR, 0x86, 0x00);
5553 inSISIDXREG(SISCR, 0x86, reg);
5554 outSISIDXREG(SISCR, 0x86, 0x88);
5555 outSISIDXREG(SISCR, 0x82, 0x77);
5556 outSISIDXREG(SISCR, 0x85, 0x00);
5557 inSISIDXREG(SISCR, 0x85, reg);
5558 outSISIDXREG(SISCR, 0x85, 0x88);
5559 inSISIDXREG(SISCR, 0x85, reg);
5560 v1 = cs160[regb]; v2 = cs158[regb];
5561 if(ivideo->haveXGIROM) {
5562 v1 = bios[regb + 0x160];
5563 v2 = bios[regb + 0x158];
5564 }
5565 outSISIDXREG(SISCR, 0x85, v1);
5566 outSISIDXREG(SISCR, 0x82, v2);
5567 }
5568 if(ivideo->chip == XGI_40) {
5569 outSISIDXREG(SISCR, 0x97, 0x11);
5570 }
5571 if((ivideo->chip == XGI_40) && (ivideo->revision_id == 2)) {
5572 outSISIDXREG(SISCR, 0x98, 0x01);
5573 } else {
5574 outSISIDXREG(SISCR, 0x98, 0x03);
5575 }
5576 outSISIDXREG(SISCR, 0x9a, 0x02);
5577
5578 if(ivideo->chip == XGI_40) {
5579 outSISIDXREG(SISSR, 0x18, 0x01);
5580 } else {
5581 outSISIDXREG(SISSR, 0x18, 0x00);
5582 }
5583 outSISIDXREG(SISSR, 0x19, 0x40);
5584 outSISIDXREG(SISSR, 0x16, 0x00);
5585 outSISIDXREG(SISSR, 0x16, 0x80);
5586 if((ivideo->chip == XGI_40) && (bios[0x1cb] != 0x0c)) {
5587 sisfb_post_xgi_delay(ivideo, 0x43);
5588 sisfb_post_xgi_delay(ivideo, 0x43);
5589 sisfb_post_xgi_delay(ivideo, 0x43);
5590 outSISIDXREG(SISSR, 0x18, 0x00);
5591 outSISIDXREG(SISSR, 0x19, 0x40);
5592 outSISIDXREG(SISSR, 0x16, 0x00);
5593 outSISIDXREG(SISSR, 0x16, 0x80);
5594 }
5595 sisfb_post_xgi_delay(ivideo, 4);
5596 v1 = 0x31;
5597 if(ivideo->haveXGIROM) {
5598 v1 = bios[0xf0];
5599 }
5600 outSISIDXREG(SISSR, 0x18, v1);
5601 outSISIDXREG(SISSR, 0x19, 0x01);
5602 if(ivideo->chip == XGI_40) {
5603 outSISIDXREG(SISSR, 0x16, bios[0x53e]);
5604 outSISIDXREG(SISSR, 0x16, bios[0x53f]);
5605 } else {
5606 outSISIDXREG(SISSR, 0x16, 0x05);
5607 outSISIDXREG(SISSR, 0x16, 0x85);
5608 }
5609 sisfb_post_xgi_delay(ivideo, 0x43);
5610 if(ivideo->chip == XGI_40) {
5611 outSISIDXREG(SISSR, 0x1b, 0x01);
5612 } else {
5613 outSISIDXREG(SISSR, 0x1b, 0x03);
5614 }
5615 sisfb_post_xgi_delay(ivideo, 0x22);
5616 outSISIDXREG(SISSR, 0x18, v1);
5617 outSISIDXREG(SISSR, 0x19, 0x00);
5618 if(ivideo->chip == XGI_40) {
5619 outSISIDXREG(SISSR, 0x16, bios[0x540]);
5620 outSISIDXREG(SISSR, 0x16, bios[0x541]);
5621 } else {
5622 outSISIDXREG(SISSR, 0x16, 0x05);
5623 outSISIDXREG(SISSR, 0x16, 0x85);
5624 }
5625 outSISIDXREG(SISSR, 0x1b, 0x00);
5626 }
5627
5628 regb = 0; /* ! */
5629 v1 = 0x03;
5630 if(ivideo->haveXGIROM) {
5631 v1 = bios[0x110 + regb];
5632 }
5633 outSISIDXREG(SISSR, 0x1b, v1);
5634
5635 /* RAM size */
5636 v1 = 0x00; v2 = 0x00;
5637 if(ivideo->haveXGIROM) {
5638 v1 = bios[0x62];
5639 v2 = bios[0x63];
5640 }
5641 regb = 0; /* ! */
5642 regd = 1 << regb;
5643 if((v1 & 0x40) && (v2 & regd) && ivideo->haveXGIROM) {
5644
5645 outSISIDXREG(SISSR, 0x13, bios[regb + 0xe0]);
5646 outSISIDXREG(SISSR, 0x14, bios[regb + 0xe0 + 8]);
5647
5648 } else {
5649
5650 /* Set default mode, don't clear screen */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08005651 ivideo->SiS_Pr.SiS_UseOEM = false;
5652 SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
5653 SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005654 ivideo->curFSTN = ivideo->curDSTN = 0;
5655 ivideo->SiS_Pr.VideoMemorySize = 8 << 20;
5656 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
5657
5658 outSISIDXREG(SISSR, 0x05, 0x86);
5659
5660 /* Disable read-cache */
5661 andSISIDXREG(SISSR, 0x21, 0xdf);
5662 sisfb_post_xgi_ramsize(ivideo);
5663 /* Enable read-cache */
5664 orSISIDXREG(SISSR, 0x21, 0x20);
5665
5666 }
5667
5668#if 0
5669 printk(KERN_DEBUG "-----------------\n");
5670 for(i = 0; i < 0xff; i++) {
5671 inSISIDXREG(SISCR, i, reg);
5672 printk(KERN_DEBUG "CR%02x(%x) = 0x%02x\n", i, SISCR, reg);
5673 }
5674 for(i = 0; i < 0x40; i++) {
5675 inSISIDXREG(SISSR, i, reg);
5676 printk(KERN_DEBUG "SR%02x(%x) = 0x%02x\n", i, SISSR, reg);
5677 }
5678 printk(KERN_DEBUG "-----------------\n");
5679#endif
5680
5681 /* Sense CRT1 */
5682 if(ivideo->chip == XGI_20) {
5683 orSISIDXREG(SISCR, 0x32, 0x20);
5684 } else {
5685 inSISIDXREG(SISPART4, 0x00, reg);
5686 if((reg == 1) || (reg == 2)) {
5687 sisfb_sense_crt1(ivideo);
5688 } else {
5689 orSISIDXREG(SISCR, 0x32, 0x20);
5690 }
5691 }
5692
5693 /* Set default mode, don't clear screen */
Richard Knutssonc30660ea2007-02-12 00:55:06 -08005694 ivideo->SiS_Pr.SiS_UseOEM = false;
5695 SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
5696 SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005697 ivideo->curFSTN = ivideo->curDSTN = 0;
5698 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
5699
5700 outSISIDXREG(SISSR, 0x05, 0x86);
5701
5702 /* Display off */
5703 orSISIDXREG(SISSR, 0x01, 0x20);
5704
5705 /* Save mode number in CR34 */
5706 outSISIDXREG(SISCR, 0x34, 0x2e);
5707
5708 /* Let everyone know what the current mode is */
5709 ivideo->modeprechange = 0x2e;
5710
5711 if(ivideo->chip == XGI_40) {
5712 inSISIDXREG(SISCR, 0xca, reg);
5713 inSISIDXREG(SISCR, 0xcc, v1);
5714 if((reg & 0x10) && (!(v1 & 0x04))) {
5715 printk(KERN_ERR
5716 "sisfb: Please connect power to the card.\n");
5717 return 0;
5718 }
5719 }
5720
5721 return 1;
5722}
5723#endif
5724
5725static int __devinit
5726sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5727{
5728 struct sisfb_chip_info *chipinfo = &sisfb_chip_info[ent->driver_data];
5729 struct sis_video_info *ivideo = NULL;
5730 struct fb_info *sis_fb_info = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005731 u16 reg16;
5732 u8 reg;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005733 int i, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005735 if(sisfb_off)
5736 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005737
Linus Torvalds1da177e2005-04-16 15:20:36 -07005738 sis_fb_info = framebuffer_alloc(sizeof(*ivideo), &pdev->dev);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005739 if(!sis_fb_info)
5740 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005741
5742 ivideo = (struct sis_video_info *)sis_fb_info->par;
5743 ivideo->memyselfandi = sis_fb_info;
5744
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005745 ivideo->sisfb_id = SISFB_ID;
5746
Linus Torvalds1da177e2005-04-16 15:20:36 -07005747 if(card_list == NULL) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005748 ivideo->cardnumber = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005749 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005750 struct sis_video_info *countvideo = card_list;
5751 ivideo->cardnumber = 1;
Harvey Harrison5e2daeb2008-05-22 15:45:08 -07005752 while((countvideo = countvideo->next) != NULL)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005753 ivideo->cardnumber++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005754 }
5755
5756 strncpy(ivideo->myid, chipinfo->chip_name, 30);
5757
5758 ivideo->warncount = 0;
5759 ivideo->chip_id = pdev->device;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005760 ivideo->chip_vendor = pdev->vendor;
Auke Kok44c10132007-06-08 15:46:36 -07005761 ivideo->revision_id = pdev->revision;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005762 ivideo->SiS_Pr.ChipRevision = ivideo->revision_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763 pci_read_config_word(pdev, PCI_COMMAND, &reg16);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005764 ivideo->sisvga_enabled = reg16 & 0x01;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005765 ivideo->pcibus = pdev->bus->number;
5766 ivideo->pcislot = PCI_SLOT(pdev->devfn);
5767 ivideo->pcifunc = PCI_FUNC(pdev->devfn);
5768 ivideo->subsysvendor = pdev->subsystem_vendor;
5769 ivideo->subsysdevice = pdev->subsystem_device;
5770
5771#ifndef MODULE
5772 if(sisfb_mode_idx == -1) {
5773 sisfb_get_vga_mode_from_kernel();
5774 }
5775#endif
5776
5777 ivideo->chip = chipinfo->chip;
5778 ivideo->sisvga_engine = chipinfo->vgaengine;
5779 ivideo->hwcursor_size = chipinfo->hwcursor_size;
5780 ivideo->CRT2_write_enable = chipinfo->CRT2_write_enable;
5781 ivideo->mni = chipinfo->mni;
5782
5783 ivideo->detectedpdc = 0xff;
5784 ivideo->detectedpdca = 0xff;
5785 ivideo->detectedlcda = 0xff;
5786
Richard Knutssonc30660ea2007-02-12 00:55:06 -08005787 ivideo->sisfb_thismonitor.datavalid = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005789 ivideo->current_base = 0;
5790
5791 ivideo->engineok = 0;
5792
5793 ivideo->sisfb_was_boot_device = 0;
Adrian Bunk14aefd12008-07-23 21:31:12 -07005794
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005795 if(pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW) {
5796 if(ivideo->sisvga_enabled)
5797 ivideo->sisfb_was_boot_device = 1;
5798 else {
5799 printk(KERN_DEBUG "sisfb: PCI device is disabled, "
5800 "but marked as boot video device ???\n");
5801 printk(KERN_DEBUG "sisfb: I will not accept this "
5802 "as the primary VGA device\n");
5803 }
5804 }
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005805
Linus Torvalds1da177e2005-04-16 15:20:36 -07005806 ivideo->sisfb_parm_mem = sisfb_parm_mem;
5807 ivideo->sisfb_accel = sisfb_accel;
5808 ivideo->sisfb_ypan = sisfb_ypan;
5809 ivideo->sisfb_max = sisfb_max;
5810 ivideo->sisfb_userom = sisfb_userom;
5811 ivideo->sisfb_useoem = sisfb_useoem;
5812 ivideo->sisfb_mode_idx = sisfb_mode_idx;
5813 ivideo->sisfb_parm_rate = sisfb_parm_rate;
5814 ivideo->sisfb_crt1off = sisfb_crt1off;
5815 ivideo->sisfb_forcecrt1 = sisfb_forcecrt1;
5816 ivideo->sisfb_crt2type = sisfb_crt2type;
5817 ivideo->sisfb_crt2flags = sisfb_crt2flags;
5818 /* pdc(a), scalelcd, special timing, lvdshl handled below */
5819 ivideo->sisfb_dstn = sisfb_dstn;
5820 ivideo->sisfb_fstn = sisfb_fstn;
5821 ivideo->sisfb_tvplug = sisfb_tvplug;
5822 ivideo->sisfb_tvstd = sisfb_tvstd;
5823 ivideo->tvxpos = sisfb_tvxposoffset;
5824 ivideo->tvypos = sisfb_tvyposoffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825 ivideo->sisfb_nocrt2rate = sisfb_nocrt2rate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005826 ivideo->refresh_rate = 0;
5827 if(ivideo->sisfb_parm_rate != -1) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005828 ivideo->refresh_rate = ivideo->sisfb_parm_rate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829 }
5830
5831 ivideo->SiS_Pr.UsePanelScaler = sisfb_scalelcd;
5832 ivideo->SiS_Pr.CenterScreen = -1;
5833 ivideo->SiS_Pr.SiS_CustomT = sisfb_specialtiming;
5834 ivideo->SiS_Pr.LVDSHL = sisfb_lvdshl;
5835
5836 ivideo->SiS_Pr.SiS_Backup70xx = 0xff;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005837 ivideo->SiS_Pr.SiS_CHOverScan = -1;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08005838 ivideo->SiS_Pr.SiS_ChSW = false;
5839 ivideo->SiS_Pr.SiS_UseLCDA = false;
5840 ivideo->SiS_Pr.HaveEMI = false;
5841 ivideo->SiS_Pr.HaveEMILCD = false;
5842 ivideo->SiS_Pr.OverruleEMI = false;
5843 ivideo->SiS_Pr.SiS_SensibleSR11 = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844 ivideo->SiS_Pr.SiS_MyCR63 = 0x63;
5845 ivideo->SiS_Pr.PDC = -1;
5846 ivideo->SiS_Pr.PDCA = -1;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08005847 ivideo->SiS_Pr.DDCPortMixup = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848#ifdef CONFIG_FB_SIS_315
5849 if(ivideo->chip >= SIS_330) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005850 ivideo->SiS_Pr.SiS_MyCR63 = 0x53;
5851 if(ivideo->chip >= SIS_661) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08005852 ivideo->SiS_Pr.SiS_SensibleSR11 = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005853 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854 }
5855#endif
5856
5857 memcpy(&ivideo->default_var, &my_default_var, sizeof(my_default_var));
5858
5859 pci_set_drvdata(pdev, ivideo);
5860
5861 /* Patch special cases */
5862 if((ivideo->nbridge = sisfb_get_northbridge(ivideo->chip))) {
5863 switch(ivideo->nbridge->device) {
5864#ifdef CONFIG_FB_SIS_300
5865 case PCI_DEVICE_ID_SI_730:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005866 ivideo->chip = SIS_730;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867 strcpy(ivideo->myid, "SiS 730");
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005868 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005869#endif
5870#ifdef CONFIG_FB_SIS_315
5871 case PCI_DEVICE_ID_SI_651:
5872 /* ivideo->chip is ok */
5873 strcpy(ivideo->myid, "SiS 651");
5874 break;
5875 case PCI_DEVICE_ID_SI_740:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005876 ivideo->chip = SIS_740;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 strcpy(ivideo->myid, "SiS 740");
5878 break;
5879 case PCI_DEVICE_ID_SI_661:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005880 ivideo->chip = SIS_661;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881 strcpy(ivideo->myid, "SiS 661");
5882 break;
5883 case PCI_DEVICE_ID_SI_741:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005884 ivideo->chip = SIS_741;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885 strcpy(ivideo->myid, "SiS 741");
5886 break;
5887 case PCI_DEVICE_ID_SI_760:
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005888 ivideo->chip = SIS_760;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889 strcpy(ivideo->myid, "SiS 760");
5890 break;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005891 case PCI_DEVICE_ID_SI_761:
5892 ivideo->chip = SIS_761;
5893 strcpy(ivideo->myid, "SiS 761");
5894 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005895#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005896 default:
5897 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898 }
5899 }
5900
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005901 ivideo->SiS_Pr.ChipType = ivideo->chip;
5902
5903 ivideo->SiS_Pr.ivideo = (void *)ivideo;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005904
5905#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005906 if((ivideo->SiS_Pr.ChipType == SIS_315PRO) ||
5907 (ivideo->SiS_Pr.ChipType == SIS_315)) {
5908 ivideo->SiS_Pr.ChipType = SIS_315H;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909 }
5910#endif
5911
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005912 if(!ivideo->sisvga_enabled) {
5913 if(pci_enable_device(pdev)) {
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005914 if(ivideo->nbridge) pci_dev_put(ivideo->nbridge);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005915 pci_set_drvdata(pdev, NULL);
Krzysztof Helt491bcc92009-06-16 15:34:36 -07005916 framebuffer_release(sis_fb_info);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005917 return -EIO;
5918 }
5919 }
5920
Linus Torvalds1da177e2005-04-16 15:20:36 -07005921 ivideo->video_base = pci_resource_start(pdev, 0);
Aaro Koskinen32ed3032010-11-10 13:04:19 +02005922 ivideo->video_size = pci_resource_len(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005923 ivideo->mmio_base = pci_resource_start(pdev, 1);
5924 ivideo->mmio_size = pci_resource_len(pdev, 1);
5925 ivideo->SiS_Pr.RelIO = pci_resource_start(pdev, 2) + 0x30;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005926 ivideo->SiS_Pr.IOAddress = ivideo->vga_base = ivideo->SiS_Pr.RelIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005928 SiSRegInit(&ivideo->SiS_Pr, ivideo->SiS_Pr.IOAddress);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929
5930#ifdef CONFIG_FB_SIS_300
5931 /* Find PCI systems for Chrontel/GPIO communication setup */
5932 if(ivideo->chip == SIS_630) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005933 i = 0;
5934 do {
5935 if(mychswtable[i].subsysVendor == ivideo->subsysvendor &&
5936 mychswtable[i].subsysCard == ivideo->subsysdevice) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08005937 ivideo->SiS_Pr.SiS_ChSW = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005938 printk(KERN_DEBUG "sisfb: Identified [%s %s] "
5939 "requiring Chrontel/GPIO setup\n",
5940 mychswtable[i].vendorName,
5941 mychswtable[i].cardName);
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005942 ivideo->lpcdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0008, NULL);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005943 break;
5944 }
5945 i++;
5946 } while(mychswtable[i].subsysVendor != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947 }
5948#endif
5949
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005950#ifdef CONFIG_FB_SIS_315
5951 if((ivideo->chip == SIS_760) && (ivideo->nbridge)) {
Adrian Bunk0959f0c2007-05-08 00:39:50 -07005952 ivideo->lpcdev = pci_get_slot(ivideo->nbridge->bus, (2 << 3));
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005953 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005955
5956 outSISIDXREG(SISSR, 0x05, 0x86);
5957
5958 if( (!ivideo->sisvga_enabled)
5959#if !defined(__i386__) && !defined(__x86_64__)
5960 || (sisfb_resetcard)
5961#endif
5962 ) {
5963 for(i = 0x30; i <= 0x3f; i++) {
5964 outSISIDXREG(SISCR, i, 0x00);
5965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 }
5967
5968 /* Find out about current video mode */
5969 ivideo->modeprechange = 0x03;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005970 inSISIDXREG(SISCR, 0x34, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971 if(reg & 0x7f) {
5972 ivideo->modeprechange = reg & 0x7f;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005973 } else if(ivideo->sisvga_enabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974#if defined(__i386__) || defined(__x86_64__)
Adrian Bunk14aefd12008-07-23 21:31:12 -07005975 unsigned char __iomem *tt = ioremap(0x400, 0x100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976 if(tt) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005977 ivideo->modeprechange = readb(tt + 0x49);
5978 iounmap(tt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979 }
5980#endif
5981 }
5982
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005983 /* Search and copy ROM image */
5984 ivideo->bios_abase = NULL;
5985 ivideo->SiS_Pr.VirtualRomBase = NULL;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08005986 ivideo->SiS_Pr.UseROM = false;
5987 ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = false;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005988 if(ivideo->sisfb_userom) {
5989 ivideo->SiS_Pr.VirtualRomBase = sisfb_find_rom(pdev);
5990 ivideo->bios_abase = ivideo->SiS_Pr.VirtualRomBase;
Richard Knutssonc30660ea2007-02-12 00:55:06 -08005991 ivideo->SiS_Pr.UseROM = (bool)(ivideo->SiS_Pr.VirtualRomBase);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005992 printk(KERN_INFO "sisfb: Video ROM %sfound\n",
5993 ivideo->SiS_Pr.UseROM ? "" : "not ");
5994 if((ivideo->SiS_Pr.UseROM) && (ivideo->chip >= XGI_20)) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08005995 ivideo->SiS_Pr.UseROM = false;
5996 ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07005997 if( (ivideo->revision_id == 2) &&
5998 (!(ivideo->bios_abase[0x1d1] & 0x01)) ) {
Richard Knutssonc30660ea2007-02-12 00:55:06 -08005999 ivideo->SiS_Pr.DDCPortMixup = true;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006000 }
6001 }
6002 } else {
6003 printk(KERN_INFO "sisfb: Video ROM usage disabled\n");
6004 }
6005
6006 /* Find systems for special custom timing */
6007 if(ivideo->SiS_Pr.SiS_CustomT == CUT_NONE) {
6008 sisfb_detect_custom_timing(ivideo);
6009 }
6010
6011 /* POST card in case this has not been done by the BIOS */
6012 if( (!ivideo->sisvga_enabled)
6013#if !defined(__i386__) && !defined(__x86_64__)
6014 || (sisfb_resetcard)
6015#endif
6016 ) {
6017#ifdef CONFIG_FB_SIS_300
6018 if(ivideo->sisvga_engine == SIS_300_VGA) {
6019 if(ivideo->chip == SIS_300) {
6020 sisfb_post_sis300(pdev);
6021 ivideo->sisfb_can_post = 1;
6022 }
6023 }
6024#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07006025
6026#ifdef CONFIG_FB_SIS_315
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006027 if(ivideo->sisvga_engine == SIS_315_VGA) {
6028 int result = 1;
6029 /* if((ivideo->chip == SIS_315H) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 (ivideo->chip == SIS_315) ||
6031 (ivideo->chip == SIS_315PRO) ||
6032 (ivideo->chip == SIS_330)) {
6033 sisfb_post_sis315330(pdev);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006034 } else */ if(ivideo->chip == XGI_20) {
6035 result = sisfb_post_xgi(pdev);
6036 ivideo->sisfb_can_post = 1;
6037 } else if((ivideo->chip == XGI_40) && ivideo->haveXGIROM) {
6038 result = sisfb_post_xgi(pdev);
6039 ivideo->sisfb_can_post = 1;
6040 } else {
6041 printk(KERN_INFO "sisfb: Card is not "
6042 "POSTed and sisfb can't do this either.\n");
6043 }
6044 if(!result) {
6045 printk(KERN_ERR "sisfb: Failed to POST card\n");
6046 ret = -ENODEV;
6047 goto error_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006048 }
6049 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051 }
6052
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006053 ivideo->sisfb_card_posted = 1;
6054
6055 /* Find out about RAM size */
6056 if(sisfb_get_dram_size(ivideo)) {
6057 printk(KERN_INFO "sisfb: Fatal error: Unable to determine VRAM size.\n");
6058 ret = -ENODEV;
6059 goto error_3;
6060 }
6061
6062
6063 /* Enable PCI addressing and MMIO */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064 if((ivideo->sisfb_mode_idx < 0) ||
6065 ((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]) != 0xFF)) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006066 /* Enable PCI_LINEAR_ADDRESSING and MMIO_ENABLE */
6067 orSISIDXREG(SISSR, IND_SIS_PCI_ADDRESS_SET, (SIS_PCI_ADDR_ENABLE | SIS_MEM_MAP_IO_ENABLE));
6068 /* Enable 2D accelerator engine */
6069 orSISIDXREG(SISSR, IND_SIS_MODULE_ENABLE, SIS_ENABLE_2D);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 }
6071
6072 if(sisfb_pdc != 0xff) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006073 if(ivideo->sisvga_engine == SIS_300_VGA)
6074 sisfb_pdc &= 0x3c;
6075 else
6076 sisfb_pdc &= 0x1f;
6077 ivideo->SiS_Pr.PDC = sisfb_pdc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078 }
6079#ifdef CONFIG_FB_SIS_315
6080 if(ivideo->sisvga_engine == SIS_315_VGA) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006081 if(sisfb_pdca != 0xff)
6082 ivideo->SiS_Pr.PDCA = sisfb_pdca & 0x1f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083 }
6084#endif
6085
6086 if(!request_mem_region(ivideo->video_base, ivideo->video_size, "sisfb FB")) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006087 printk(KERN_ERR "sisfb: Fatal error: Unable to reserve %dMB framebuffer memory\n",
6088 (int)(ivideo->video_size >> 20));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 printk(KERN_ERR "sisfb: Is there another framebuffer driver active?\n");
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006090 ret = -ENODEV;
6091 goto error_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092 }
6093
6094 if(!request_mem_region(ivideo->mmio_base, ivideo->mmio_size, "sisfb MMIO")) {
6095 printk(KERN_ERR "sisfb: Fatal error: Unable to reserve MMIO region\n");
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006096 ret = -ENODEV;
6097 goto error_2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098 }
6099
6100 ivideo->video_vbase = ioremap(ivideo->video_base, ivideo->video_size);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006101 ivideo->SiS_Pr.VideoMemoryAddress = ivideo->video_vbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102 if(!ivideo->video_vbase) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006103 printk(KERN_ERR "sisfb: Fatal error: Unable to map framebuffer memory\n");
6104 ret = -ENODEV;
6105 goto error_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106 }
6107
6108 ivideo->mmio_vbase = ioremap(ivideo->mmio_base, ivideo->mmio_size);
6109 if(!ivideo->mmio_vbase) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006110 printk(KERN_ERR "sisfb: Fatal error: Unable to map MMIO region\n");
6111 ret = -ENODEV;
6112error_0: iounmap(ivideo->video_vbase);
6113error_1: release_mem_region(ivideo->video_base, ivideo->video_size);
6114error_2: release_mem_region(ivideo->mmio_base, ivideo->mmio_size);
6115error_3: vfree(ivideo->bios_abase);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006116 if(ivideo->lpcdev)
Adrian Bunk0959f0c2007-05-08 00:39:50 -07006117 pci_dev_put(ivideo->lpcdev);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006118 if(ivideo->nbridge)
Adrian Bunk0959f0c2007-05-08 00:39:50 -07006119 pci_dev_put(ivideo->nbridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006120 pci_set_drvdata(pdev, NULL);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006121 if(!ivideo->sisvga_enabled)
6122 pci_disable_device(pdev);
Krzysztof Helt491bcc92009-06-16 15:34:36 -07006123 framebuffer_release(sis_fb_info);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006124 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 }
6126
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006127 printk(KERN_INFO "sisfb: Video RAM at 0x%lx, mapped to 0x%lx, size %ldk\n",
6128 ivideo->video_base, (unsigned long)ivideo->video_vbase, ivideo->video_size / 1024);
6129
6130 if(ivideo->video_offset) {
6131 printk(KERN_INFO "sisfb: Viewport offset %ldk\n",
6132 ivideo->video_offset / 1024);
6133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134
6135 printk(KERN_INFO "sisfb: MMIO at 0x%lx, mapped to 0x%lx, size %ldk\n",
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006136 ivideo->mmio_base, (unsigned long)ivideo->mmio_vbase, ivideo->mmio_size / 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006138
6139 /* Determine the size of the command queue */
6140 if(ivideo->sisvga_engine == SIS_300_VGA) {
6141 ivideo->cmdQueueSize = TURBO_QUEUE_AREA_SIZE;
6142 } else {
6143 if(ivideo->chip == XGI_20) {
6144 ivideo->cmdQueueSize = COMMAND_QUEUE_AREA_SIZE_Z7;
6145 } else {
6146 ivideo->cmdQueueSize = COMMAND_QUEUE_AREA_SIZE;
6147 }
6148 }
6149
6150 /* Engines are no longer initialized here; this is
6151 * now done after the first mode-switch (if the
6152 * submitted var has its acceleration flags set).
6153 */
6154
6155 /* Calculate the base of the (unused) hw cursor */
6156 ivideo->hwcursor_vbase = ivideo->video_vbase
6157 + ivideo->video_size
6158 - ivideo->cmdQueueSize
6159 - ivideo->hwcursor_size;
6160 ivideo->caps |= HW_CURSOR_CAP;
6161
6162 /* Initialize offscreen memory manager */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163 if((ivideo->havenoheap = sisfb_heap_init(ivideo))) {
6164 printk(KERN_WARNING "sisfb: Failed to initialize offscreen memory heap\n");
6165 }
6166
6167 /* Used for clearing the screen only, therefore respect our mem limit */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006168 ivideo->SiS_Pr.VideoMemoryAddress += ivideo->video_offset;
6169 ivideo->SiS_Pr.VideoMemorySize = ivideo->sisfb_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006171 ivideo->mtrr = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172
6173 ivideo->vbflags = 0;
6174 ivideo->lcddefmodeidx = DEFAULT_LCDMODE;
6175 ivideo->tvdefmodeidx = DEFAULT_TVMODE;
6176 ivideo->defmodeidx = DEFAULT_MODE;
6177
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006178 ivideo->newrom = 0;
6179 if(ivideo->chip < XGI_20) {
6180 if(ivideo->bios_abase) {
6181 ivideo->newrom = SiSDetermineROMLayout661(&ivideo->SiS_Pr);
6182 }
6183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184
6185 if((ivideo->sisfb_mode_idx < 0) ||
6186 ((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]) != 0xFF)) {
6187
6188 sisfb_sense_crt1(ivideo);
6189
6190 sisfb_get_VB_type(ivideo);
6191
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006192 if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193 sisfb_detect_VB_connect(ivideo);
6194 }
6195
6196 ivideo->currentvbflags = ivideo->vbflags & (VB_VIDEOBRIDGE | TV_STANDARD);
6197
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006198 /* Decide on which CRT2 device to use */
6199 if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) {
6200 if(ivideo->sisfb_crt2type != -1) {
6201 if((ivideo->sisfb_crt2type == CRT2_LCD) &&
6202 (ivideo->vbflags & CRT2_LCD)) {
6203 ivideo->currentvbflags |= CRT2_LCD;
6204 } else if(ivideo->sisfb_crt2type != CRT2_LCD) {
6205 ivideo->currentvbflags |= ivideo->sisfb_crt2type;
6206 }
6207 } else {
6208 /* Chrontel 700x TV detection often unreliable, therefore
6209 * use a different default order on such machines
6210 */
6211 if((ivideo->sisvga_engine == SIS_300_VGA) &&
6212 (ivideo->vbflags2 & VB2_CHRONTEL)) {
6213 if(ivideo->vbflags & CRT2_LCD)
6214 ivideo->currentvbflags |= CRT2_LCD;
6215 else if(ivideo->vbflags & CRT2_TV)
6216 ivideo->currentvbflags |= CRT2_TV;
6217 else if(ivideo->vbflags & CRT2_VGA)
6218 ivideo->currentvbflags |= CRT2_VGA;
6219 } else {
6220 if(ivideo->vbflags & CRT2_TV)
6221 ivideo->currentvbflags |= CRT2_TV;
6222 else if(ivideo->vbflags & CRT2_LCD)
6223 ivideo->currentvbflags |= CRT2_LCD;
6224 else if(ivideo->vbflags & CRT2_VGA)
6225 ivideo->currentvbflags |= CRT2_VGA;
6226 }
6227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228 }
6229
6230 if(ivideo->vbflags & CRT2_LCD) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006231 sisfb_detect_lcd_type(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232 }
6233
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006234 sisfb_save_pdc_emi(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235
6236 if(!ivideo->sisfb_crt1off) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006237 sisfb_handle_ddc(ivideo, &ivideo->sisfb_thismonitor, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238 } else {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006239 if((ivideo->vbflags2 & VB2_SISTMDSBRIDGE) &&
6240 (ivideo->vbflags & (CRT2_VGA | CRT2_LCD))) {
6241 sisfb_handle_ddc(ivideo, &ivideo->sisfb_thismonitor, 1);
6242 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 }
6244
6245 if(ivideo->sisfb_mode_idx >= 0) {
6246 int bu = ivideo->sisfb_mode_idx;
6247 ivideo->sisfb_mode_idx = sisfb_validate_mode(ivideo,
6248 ivideo->sisfb_mode_idx, ivideo->currentvbflags);
6249 if(bu != ivideo->sisfb_mode_idx) {
6250 printk(KERN_ERR "Mode %dx%dx%d failed validation\n",
6251 sisbios_mode[bu].xres,
6252 sisbios_mode[bu].yres,
6253 sisbios_mode[bu].bpp);
6254 }
6255 }
6256
6257 if(ivideo->sisfb_mode_idx < 0) {
6258 switch(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
6259 case CRT2_LCD:
6260 ivideo->sisfb_mode_idx = ivideo->lcddefmodeidx;
6261 break;
6262 case CRT2_TV:
6263 ivideo->sisfb_mode_idx = ivideo->tvdefmodeidx;
6264 break;
6265 default:
6266 ivideo->sisfb_mode_idx = ivideo->defmodeidx;
6267 break;
6268 }
6269 }
6270
6271 ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni];
6272
6273 if(ivideo->refresh_rate != 0) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006274 sisfb_search_refresh_rate(ivideo, ivideo->refresh_rate,
6275 ivideo->sisfb_mode_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276 }
6277
6278 if(ivideo->rate_idx == 0) {
6279 ivideo->rate_idx = sisbios_mode[ivideo->sisfb_mode_idx].rate_idx;
6280 ivideo->refresh_rate = 60;
6281 }
6282
6283 if(ivideo->sisfb_thismonitor.datavalid) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006284 if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor,
6285 ivideo->sisfb_mode_idx,
6286 ivideo->rate_idx,
6287 ivideo->refresh_rate)) {
6288 printk(KERN_INFO "sisfb: WARNING: Refresh rate "
6289 "exceeds monitor specs!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290 }
6291 }
6292
6293 ivideo->video_bpp = sisbios_mode[ivideo->sisfb_mode_idx].bpp;
6294 ivideo->video_width = sisbios_mode[ivideo->sisfb_mode_idx].xres;
6295 ivideo->video_height = sisbios_mode[ivideo->sisfb_mode_idx].yres;
6296
6297 sisfb_set_vparms(ivideo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299 printk(KERN_INFO "sisfb: Default mode is %dx%dx%d (%dHz)\n",
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006300 ivideo->video_width, ivideo->video_height, ivideo->video_bpp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006301 ivideo->refresh_rate);
6302
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006303 /* Set up the default var according to chosen default display mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304 ivideo->default_var.xres = ivideo->default_var.xres_virtual = ivideo->video_width;
6305 ivideo->default_var.yres = ivideo->default_var.yres_virtual = ivideo->video_height;
6306 ivideo->default_var.bits_per_pixel = ivideo->video_bpp;
6307
6308 sisfb_bpp_to_var(ivideo, &ivideo->default_var);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006309
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310 ivideo->default_var.pixclock = (u32) (1000000000 /
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006311 sisfb_mode_rate_to_dclock(&ivideo->SiS_Pr, ivideo->mode_no, ivideo->rate_idx));
6312
6313 if(sisfb_mode_rate_to_ddata(&ivideo->SiS_Pr, ivideo->mode_no,
6314 ivideo->rate_idx, &ivideo->default_var)) {
6315 if((ivideo->default_var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
6316 ivideo->default_var.pixclock <<= 1;
6317 }
6318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319
6320 if(ivideo->sisfb_ypan) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006321 /* Maximize regardless of sisfb_max at startup */
6322 ivideo->default_var.yres_virtual =
6323 sisfb_calc_maxyres(ivideo, &ivideo->default_var);
6324 if(ivideo->default_var.yres_virtual < ivideo->default_var.yres) {
6325 ivideo->default_var.yres_virtual = ivideo->default_var.yres;
6326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327 }
6328
6329 sisfb_calc_pitch(ivideo, &ivideo->default_var);
6330
6331 ivideo->accel = 0;
6332 if(ivideo->sisfb_accel) {
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006333 ivideo->accel = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334#ifdef STUPID_ACCELF_TEXT_SHIT
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006335 ivideo->default_var.accel_flags |= FB_ACCELF_TEXT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006336#endif
6337 }
6338 sisfb_initaccel(ivideo);
6339
6340#if defined(FBINFO_HWACCEL_DISABLED) && defined(FBINFO_HWACCEL_XPAN)
6341 sis_fb_info->flags = FBINFO_DEFAULT |
6342 FBINFO_HWACCEL_YPAN |
6343 FBINFO_HWACCEL_XPAN |
6344 FBINFO_HWACCEL_COPYAREA |
6345 FBINFO_HWACCEL_FILLRECT |
6346 ((ivideo->accel) ? 0 : FBINFO_HWACCEL_DISABLED);
6347#else
6348 sis_fb_info->flags = FBINFO_FLAG_DEFAULT;
6349#endif
6350 sis_fb_info->var = ivideo->default_var;
6351 sis_fb_info->fix = ivideo->sisfb_fix;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006352 sis_fb_info->screen_base = ivideo->video_vbase + ivideo->video_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353 sis_fb_info->fbops = &sisfb_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354 sis_fb_info->pseudo_palette = ivideo->pseudo_palette;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006355
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356 fb_alloc_cmap(&sis_fb_info->cmap, 256 , 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006358 printk(KERN_DEBUG "sisfb: Initial vbflags 0x%x\n", (int)ivideo->vbflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359
6360#ifdef CONFIG_MTRR
6361 ivideo->mtrr = mtrr_add(ivideo->video_base, ivideo->video_size,
6362 MTRR_TYPE_WRCOMB, 1);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006363 if(ivideo->mtrr < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364 printk(KERN_DEBUG "sisfb: Failed to add MTRRs\n");
6365 }
6366#endif
6367
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368 if(register_framebuffer(sis_fb_info) < 0) {
6369 printk(KERN_ERR "sisfb: Fatal error: Failed to register framebuffer\n");
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006370 ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371 iounmap(ivideo->mmio_vbase);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006372 goto error_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373 }
6374
6375 ivideo->registered = 1;
6376
6377 /* Enlist us */
6378 ivideo->next = card_list;
6379 card_list = ivideo;
6380
6381 printk(KERN_INFO "sisfb: 2D acceleration is %s, y-panning %s\n",
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006382 ivideo->sisfb_accel ? "enabled" : "disabled",
6383 ivideo->sisfb_ypan ?
6384 (ivideo->sisfb_max ? "enabled (auto-max)" :
6385 "enabled (no auto-max)") :
6386 "disabled");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387
6388
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006389 printk(KERN_INFO "fb%d: %s frame buffer device version %d.%d.%d\n",
Michal Piotrowski43704092006-10-03 01:15:00 -07006390 sis_fb_info->node, ivideo->myid, VER_MAJOR, VER_MINOR, VER_LEVEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006392 printk(KERN_INFO "sisfb: Copyright (C) 2001-2005 Thomas Winischhofer\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393
6394 } /* if mode = "none" */
6395
6396 return 0;
6397}
6398
6399/*****************************************************/
6400/* PCI DEVICE HANDLING */
6401/*****************************************************/
6402
6403static void __devexit sisfb_remove(struct pci_dev *pdev)
6404{
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006405 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
6406 struct fb_info *sis_fb_info = ivideo->memyselfandi;
6407 int registered = ivideo->registered;
6408 int modechanged = ivideo->modechanged;
6409
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410 /* Unmap */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411 iounmap(ivideo->mmio_vbase);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006412 iounmap(ivideo->video_vbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006413
6414 /* Release mem regions */
6415 release_mem_region(ivideo->video_base, ivideo->video_size);
6416 release_mem_region(ivideo->mmio_base, ivideo->mmio_size);
6417
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006418 vfree(ivideo->bios_abase);
6419
6420 if(ivideo->lpcdev)
Adrian Bunk0959f0c2007-05-08 00:39:50 -07006421 pci_dev_put(ivideo->lpcdev);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006422
6423 if(ivideo->nbridge)
Adrian Bunk0959f0c2007-05-08 00:39:50 -07006424 pci_dev_put(ivideo->nbridge);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006425
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426#ifdef CONFIG_MTRR
6427 /* Release MTRR region */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006428 if(ivideo->mtrr >= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429 mtrr_del(ivideo->mtrr, ivideo->video_base, ivideo->video_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430#endif
6431
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006432 pci_set_drvdata(pdev, NULL);
6433
6434 /* If device was disabled when starting, disable
6435 * it when quitting.
6436 */
6437 if(!ivideo->sisvga_enabled)
6438 pci_disable_device(pdev);
6439
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440 /* Unregister the framebuffer */
6441 if(ivideo->registered) {
6442 unregister_framebuffer(sis_fb_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 framebuffer_release(sis_fb_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 }
6445
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006446 /* OK, our ivideo is gone for good from here. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006447
6448 /* TODO: Restore the initial mode
6449 * This sounds easy but is as good as impossible
6450 * on many machines with SiS chip and video bridge
6451 * since text modes are always set up differently
6452 * from machine to machine. Depends on the type
6453 * of integration between chipset and bridge.
6454 */
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006455 if(registered && modechanged)
6456 printk(KERN_INFO
6457 "sisfb: Restoring of text mode not supported yet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458};
6459
6460static struct pci_driver sisfb_driver = {
6461 .name = "sisfb",
6462 .id_table = sisfb_pci_table,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006463 .probe = sisfb_probe,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 .remove = __devexit_p(sisfb_remove)
6465};
6466
Adrian Bunk14aefd12008-07-23 21:31:12 -07006467static int __init sisfb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469#ifndef MODULE
6470 char *options = NULL;
6471
6472 if(fb_get_options("sisfb", &options))
6473 return -ENODEV;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006474
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475 sisfb_setup(options);
6476#endif
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006477 return pci_register_driver(&sisfb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006478}
6479
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480#ifndef MODULE
6481module_init(sisfb_init);
6482#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483
6484/*****************************************************/
6485/* MODULE */
6486/*****************************************************/
6487
6488#ifdef MODULE
6489
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006490static char *mode = NULL;
6491static int vesa = -1;
6492static unsigned int rate = 0;
6493static unsigned int crt1off = 1;
6494static unsigned int mem = 0;
6495static char *forcecrt2type = NULL;
6496static int forcecrt1 = -1;
6497static int pdc = -1;
6498static int pdc1 = -1;
6499static int noaccel = -1;
6500static int noypan = -1;
6501static int nomax = -1;
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006502static int userom = -1;
6503static int useoem = -1;
6504static char *tvstandard = NULL;
6505static int nocrt2rate = 0;
6506static int scalelcd = -1;
6507static char *specialtiming = NULL;
6508static int lvdshl = -1;
6509static int tvxposoffset = 0, tvyposoffset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510#if !defined(__i386__) && !defined(__x86_64__)
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006511static int resetcard = 0;
6512static int videoram = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513#endif
6514
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006515static int __init sisfb_init_module(void)
6516{
6517 sisfb_setdefaultparms();
6518
6519 if(rate)
6520 sisfb_parm_rate = rate;
6521
6522 if((scalelcd == 0) || (scalelcd == 1))
6523 sisfb_scalelcd = scalelcd ^ 1;
6524
6525 /* Need to check crt2 type first for fstn/dstn */
6526
6527 if(forcecrt2type)
6528 sisfb_search_crt2type(forcecrt2type);
6529
6530 if(tvstandard)
6531 sisfb_search_tvstd(tvstandard);
6532
6533 if(mode)
Richard Knutssonc30660ea2007-02-12 00:55:06 -08006534 sisfb_search_mode(mode, false);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006535 else if(vesa != -1)
Richard Knutssonc30660ea2007-02-12 00:55:06 -08006536 sisfb_search_vesamode(vesa, false);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006537
6538 sisfb_crt1off = (crt1off == 0) ? 1 : 0;
6539
6540 sisfb_forcecrt1 = forcecrt1;
6541 if(forcecrt1 == 1)
6542 sisfb_crt1off = 0;
6543 else if(forcecrt1 == 0)
6544 sisfb_crt1off = 1;
6545
6546 if(noaccel == 1)
6547 sisfb_accel = 0;
6548 else if(noaccel == 0)
6549 sisfb_accel = 1;
6550
6551 if(noypan == 1)
6552 sisfb_ypan = 0;
6553 else if(noypan == 0)
6554 sisfb_ypan = 1;
6555
6556 if(nomax == 1)
6557 sisfb_max = 0;
6558 else if(nomax == 0)
6559 sisfb_max = 1;
6560
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006561 if(mem)
6562 sisfb_parm_mem = mem;
6563
6564 if(userom != -1)
6565 sisfb_userom = userom;
6566
6567 if(useoem != -1)
6568 sisfb_useoem = useoem;
6569
6570 if(pdc != -1)
6571 sisfb_pdc = (pdc & 0x7f);
6572
6573 if(pdc1 != -1)
6574 sisfb_pdca = (pdc1 & 0x1f);
6575
6576 sisfb_nocrt2rate = nocrt2rate;
6577
6578 if(specialtiming)
6579 sisfb_search_specialtiming(specialtiming);
6580
6581 if((lvdshl >= 0) && (lvdshl <= 3))
6582 sisfb_lvdshl = lvdshl;
6583
6584 sisfb_tvxposoffset = tvxposoffset;
6585 sisfb_tvyposoffset = tvyposoffset;
6586
6587#if !defined(__i386__) && !defined(__x86_64__)
6588 sisfb_resetcard = (resetcard) ? 1 : 0;
6589 if(videoram)
6590 sisfb_videoram = videoram;
6591#endif
6592
6593 return sisfb_init();
6594}
6595
6596static void __exit sisfb_remove_module(void)
6597{
6598 pci_unregister_driver(&sisfb_driver);
6599 printk(KERN_DEBUG "sisfb: Module unloaded\n");
6600}
6601
6602module_init(sisfb_init_module);
6603module_exit(sisfb_remove_module);
6604
6605MODULE_DESCRIPTION("SiS 300/540/630/730/315/55x/65x/661/74x/330/76x/34x, XGI V3XT/V5/V8/Z7 framebuffer device driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606MODULE_LICENSE("GPL");
6607MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>, Others");
6608
Linus Torvalds1da177e2005-04-16 15:20:36 -07006609module_param(mem, int, 0);
6610module_param(noaccel, int, 0);
6611module_param(noypan, int, 0);
6612module_param(nomax, int, 0);
6613module_param(userom, int, 0);
6614module_param(useoem, int, 0);
6615module_param(mode, charp, 0);
6616module_param(vesa, int, 0);
6617module_param(rate, int, 0);
6618module_param(forcecrt1, int, 0);
6619module_param(forcecrt2type, charp, 0);
6620module_param(scalelcd, int, 0);
6621module_param(pdc, int, 0);
6622module_param(pdc1, int, 0);
6623module_param(specialtiming, charp, 0);
6624module_param(lvdshl, int, 0);
6625module_param(tvstandard, charp, 0);
6626module_param(tvxposoffset, int, 0);
6627module_param(tvyposoffset, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006628module_param(nocrt2rate, int, 0);
6629#if !defined(__i386__) && !defined(__x86_64__)
6630module_param(resetcard, int, 0);
6631module_param(videoram, int, 0);
6632#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006634MODULE_PARM_DESC(mem,
6635 "\nDetermines the beginning of the video memory heap in KB. This heap is used\n"
6636 "for video RAM management for eg. DRM/DRI. On 300 series, the default depends\n"
6637 "on the amount of video RAM available. If 8MB of video RAM or less is available,\n"
6638 "the heap starts at 4096KB, if between 8 and 16MB are available at 8192KB,\n"
6639 "otherwise at 12288KB. On 315/330/340 series, the heap size is 32KB by default.\n"
6640 "The value is to be specified without 'KB'.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641
6642MODULE_PARM_DESC(noaccel,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006643 "\nIf set to anything other than 0, 2D acceleration will be disabled.\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644 "(default: 0)\n");
6645
6646MODULE_PARM_DESC(noypan,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006647 "\nIf set to anything other than 0, y-panning will be disabled and scrolling\n"
6648 "will be performed by redrawing the screen. (default: 0)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649
6650MODULE_PARM_DESC(nomax,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006651 "\nIf y-panning is enabled, sisfb will by default use the entire available video\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07006652 "memory for the virtual screen in order to optimize scrolling performance. If\n"
6653 "this is set to anything other than 0, sisfb will not do this and thereby \n"
6654 "enable the user to positively specify a virtual Y size of the screen using\n"
6655 "fbset. (default: 0)\n");
6656
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657MODULE_PARM_DESC(mode,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006658 "\nSelects the desired default display mode in the format XxYxDepth,\n"
6659 "eg. 1024x768x16. Other formats supported include XxY-Depth and\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660 "XxY-Depth@Rate. If the parameter is only one (decimal or hexadecimal)\n"
6661 "number, it will be interpreted as a VESA mode number. (default: 800x600x8)\n");
6662
6663MODULE_PARM_DESC(vesa,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006664 "\nSelects the desired default display mode by VESA defined mode number, eg.\n"
6665 "0x117 (default: 0x0103)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666
6667MODULE_PARM_DESC(rate,
6668 "\nSelects the desired vertical refresh rate for CRT1 (external VGA) in Hz.\n"
6669 "If the mode is specified in the format XxY-Depth@Rate, this parameter\n"
6670 "will be ignored (default: 60)\n");
6671
6672MODULE_PARM_DESC(forcecrt1,
6673 "\nNormally, the driver autodetects whether or not CRT1 (external VGA) is \n"
6674 "connected. With this option, the detection can be overridden (1=CRT1 ON,\n"
6675 "0=CRT1 OFF) (default: [autodetected])\n");
6676
6677MODULE_PARM_DESC(forcecrt2type,
6678 "\nIf this option is omitted, the driver autodetects CRT2 output devices, such as\n"
6679 "LCD, TV or secondary VGA. With this option, this autodetection can be\n"
6680 "overridden. Possible parameters are LCD, TV, VGA or NONE. NONE disables CRT2.\n"
6681 "On systems with a SiS video bridge, parameters SVIDEO, COMPOSITE or SCART can\n"
6682 "be used instead of TV to override the TV detection. Furthermore, on systems\n"
6683 "with a SiS video bridge, SVIDEO+COMPOSITE, HIVISION, YPBPR480I, YPBPR480P,\n"
6684 "YPBPR720P and YPBPR1080I are understood. However, whether or not these work\n"
6685 "depends on the very hardware in use. (default: [autodetected])\n");
6686
6687MODULE_PARM_DESC(scalelcd,
6688 "\nSetting this to 1 will force the driver to scale the LCD image to the panel's\n"
6689 "native resolution. Setting it to 0 will disable scaling; LVDS panels will\n"
6690 "show black bars around the image, TMDS panels will probably do the scaling\n"
6691 "themselves. Default: 1 on LVDS panels, 0 on TMDS panels\n");
6692
6693MODULE_PARM_DESC(pdc,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006694 "\nThis is for manually selecting the LCD panel delay compensation. The driver\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07006695 "should detect this correctly in most cases; however, sometimes this is not\n"
6696 "possible. If you see 'small waves' on the LCD, try setting this to 4, 32 or 24\n"
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006697 "on a 300 series chipset; 6 on other chipsets. If the problem persists, try\n"
6698 "other values (on 300 series: between 4 and 60 in steps of 4; otherwise: any\n"
6699 "value from 0 to 31). (default: autodetected, if LCD is active during start)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006700
6701#ifdef CONFIG_FB_SIS_315
6702MODULE_PARM_DESC(pdc1,
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006703 "\nThis is same as pdc, but for LCD-via CRT1. Hence, this is for the 315/330/340\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07006704 "series only. (default: autodetected if LCD is in LCD-via-CRT1 mode during\n"
6705 "startup) - Note: currently, this has no effect because LCD-via-CRT1 is not\n"
6706 "implemented yet.\n");
6707#endif
6708
6709MODULE_PARM_DESC(specialtiming,
6710 "\nPlease refer to documentation for more information on this option.\n");
6711
6712MODULE_PARM_DESC(lvdshl,
6713 "\nPlease refer to documentation for more information on this option.\n");
6714
6715MODULE_PARM_DESC(tvstandard,
6716 "\nThis allows overriding the BIOS default for the TV standard. Valid choices are\n"
6717 "pal, ntsc, palm and paln. (default: [auto; pal or ntsc only])\n");
6718
6719MODULE_PARM_DESC(tvxposoffset,
6720 "\nRelocate TV output horizontally. Possible parameters: -32 through 32.\n"
6721 "Default: 0\n");
6722
6723MODULE_PARM_DESC(tvyposoffset,
6724 "\nRelocate TV output vertically. Possible parameters: -32 through 32.\n"
6725 "Default: 0\n");
6726
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727MODULE_PARM_DESC(nocrt2rate,
6728 "\nSetting this to 1 will force the driver to use the default refresh rate for\n"
6729 "CRT2 if CRT2 type is VGA. (default: 0, use same rate as CRT1)\n");
6730
Linus Torvalds1da177e2005-04-16 15:20:36 -07006731#if !defined(__i386__) && !defined(__x86_64__)
6732#ifdef CONFIG_FB_SIS_300
6733MODULE_PARM_DESC(resetcard,
6734 "\nSet this to 1 in order to reset (POST) the card on non-x86 machines where\n"
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006735 "the BIOS did not POST the card (only supported for SiS 300/305 and XGI cards\n"
6736 "currently). Default: 0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006737
6738MODULE_PARM_DESC(videoram,
6739 "\nSet this to the amount of video RAM (in kilobyte) the card has. Required on\n"
6740 "some non-x86 architectures where the memory auto detection fails. Only\n"
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006741 "relevant if resetcard is set, too. SiS300/305 only. Default: [auto-detect]\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742#endif
6743#endif
6744
Linus Torvalds1da177e2005-04-16 15:20:36 -07006745#endif /* /MODULE */
6746
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006747/* _GPL only for new symbols. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748EXPORT_SYMBOL(sis_malloc);
6749EXPORT_SYMBOL(sis_free);
Thomas Winischhofer544393f2005-09-09 13:04:45 -07006750EXPORT_SYMBOL_GPL(sis_malloc_new);
6751EXPORT_SYMBOL_GPL(sis_free_new);
6752
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753
6754