ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / video / sis / sis_main.h
1 /*
2  * SiS 300/630/730/540/315/550/650/651/M650/661FX/M661FX/740/741/330/760
3  * frame buffer driver for Linux kernels 2.4.x and 2.5.x
4  *
5  * Copyright (C) 2001-2004 Thomas Winischhofer, Vienna, Austria.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the named License,
10  * or any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20  */
21
22 #ifndef _SISFB_MAIN
23 #define _SISFB_MAIN
24
25 #include "vstruct.h"
26
27 /* ------------------- Constant Definitions ------------------------- */
28
29 #define AGPOFF     /* default is turn off AGP */
30
31 #define SISFAIL(x) do { printk(x "\n"); return -EINVAL; } while(0)
32
33 #define VER_MAJOR                 1
34 #define VER_MINOR                 6
35 #define VER_LEVEL                 25
36
37 #include "sis.h"
38
39 /* To be included in pci_ids.h */
40 #ifndef PCI_DEVICE_ID_SI_650_VGA
41 #define PCI_DEVICE_ID_SI_650_VGA  0x6325
42 #endif
43 #ifndef PCI_DEVICE_ID_SI_650
44 #define PCI_DEVICE_ID_SI_650      0x0650
45 #endif
46 #ifndef PCI_DEVICE_ID_SI_740
47 #define PCI_DEVICE_ID_SI_740      0x0740
48 #endif
49 #ifndef PCI_DEVICE_ID_SI_330
50 #define PCI_DEVICE_ID_SI_330      0x0330
51 #endif
52 #ifndef PCI_DEVICE_ID_SI_660_VGA
53 #define PCI_DEVICE_ID_SI_660_VGA  0x6330
54 #endif
55 #ifndef PCI_DEVICE_ID_SI_660
56 #define PCI_DEVICE_ID_SI_660      0x0661
57 #endif
58 #ifndef PCI_DEVICE_ID_SI_741
59 #define PCI_DEVICE_ID_SI_741      0x0741
60 #endif
61 #ifndef PCI_DEVICE_ID_SI_660
62 #define PCI_DEVICE_ID_SI_660      0x0660
63 #endif
64 #ifndef PCI_DEVICE_ID_SI_760
65 #define PCI_DEVICE_ID_SI_760      0x0760
66 #endif
67
68 /* To be included in fb.h */
69 #ifndef FB_ACCEL_SIS_GLAMOUR_2
70 #define FB_ACCEL_SIS_GLAMOUR_2  40      /* SiS 315, 65x, 740, 661, 741  */
71 #endif
72 #ifndef FB_ACCEL_SIS_XABRE
73 #define FB_ACCEL_SIS_XABRE      41      /* SiS 330 ("Xabre"), 760       */
74 #endif
75
76 #define MAX_ROM_SCAN              0x10000
77
78 #define HW_CURSOR_CAP             0x80
79 #define TURBO_QUEUE_CAP           0x40
80 #define AGP_CMD_QUEUE_CAP         0x20
81 #define VM_CMD_QUEUE_CAP          0x10
82 #define MMIO_CMD_QUEUE_CAP        0x08
83
84 /* For 300 series */
85 #ifdef CONFIG_FB_SIS_300
86 #define TURBO_QUEUE_AREA_SIZE     0x80000 /* 512K */
87 #endif
88
89 /* For 315/Xabre series */
90 #ifdef CONFIG_FB_SIS_315
91 #define COMMAND_QUEUE_AREA_SIZE   0x80000 /* 512K */
92 #define COMMAND_QUEUE_THRESHOLD   0x1F
93 #endif
94
95 #define HW_CURSOR_AREA_SIZE_315   0x4000  /* 16K */
96 #define HW_CURSOR_AREA_SIZE_300   0x1000  /* 4K */
97
98 #define OH_ALLOC_SIZE             4000
99 #define SENTINEL                  0x7fffffff
100
101 #define SEQ_ADR                   0x14
102 #define SEQ_DATA                  0x15
103 #define DAC_ADR                   0x18
104 #define DAC_DATA                  0x19
105 #define CRTC_ADR                  0x24
106 #define CRTC_DATA                 0x25
107 #define DAC2_ADR                  (0x16-0x30)
108 #define DAC2_DATA                 (0x17-0x30)
109 #define VB_PART1_ADR              (0x04-0x30)
110 #define VB_PART1_DATA             (0x05-0x30)
111 #define VB_PART2_ADR              (0x10-0x30)
112 #define VB_PART2_DATA             (0x11-0x30)
113 #define VB_PART3_ADR              (0x12-0x30)
114 #define VB_PART3_DATA             (0x13-0x30)
115 #define VB_PART4_ADR              (0x14-0x30)
116 #define VB_PART4_DATA             (0x15-0x30)
117
118 #define SISSR                     SiS_Pr.SiS_P3c4
119 #define SISCR                     SiS_Pr.SiS_P3d4
120 #define SISDACA                   SiS_Pr.SiS_P3c8
121 #define SISDACD                   SiS_Pr.SiS_P3c9
122 #define SISPART1                  SiS_Pr.SiS_Part1Port
123 #define SISPART2                  SiS_Pr.SiS_Part2Port
124 #define SISPART3                  SiS_Pr.SiS_Part3Port
125 #define SISPART4                  SiS_Pr.SiS_Part4Port
126 #define SISPART5                  SiS_Pr.SiS_Part5Port
127 #define SISDAC2A                  SISPART5
128 #define SISDAC2D                  (SISPART5 + 1)
129 #define SISMISCR                  (SiS_Pr.RelIO + 0x1c)
130 #define SISMISCW                  SiS_Pr.SiS_P3c2
131 #define SISINPSTAT                (SiS_Pr.RelIO + 0x2a)
132 #define SISPEL                    SiS_Pr.SiS_P3c6
133
134 #define IND_SIS_PASSWORD          0x05  /* SRs */
135 #define IND_SIS_COLOR_MODE        0x06
136 #define IND_SIS_RAMDAC_CONTROL    0x07
137 #define IND_SIS_DRAM_SIZE         0x14
138 #define IND_SIS_SCRATCH_REG_16    0x16
139 #define IND_SIS_SCRATCH_REG_17    0x17
140 #define IND_SIS_SCRATCH_REG_1A    0x1A
141 #define IND_SIS_MODULE_ENABLE     0x1E
142 #define IND_SIS_PCI_ADDRESS_SET   0x20
143 #define IND_SIS_TURBOQUEUE_ADR    0x26
144 #define IND_SIS_TURBOQUEUE_SET    0x27
145 #define IND_SIS_POWER_ON_TRAP     0x38
146 #define IND_SIS_POWER_ON_TRAP2    0x39
147 #define IND_SIS_CMDQUEUE_SET      0x26
148 #define IND_SIS_CMDQUEUE_THRESHOLD  0x27
149
150 #define IND_SIS_SCRATCH_REG_CR30  0x30  /* CRs */
151 #define IND_SIS_SCRATCH_REG_CR31  0x31
152 #define IND_SIS_SCRATCH_REG_CR32  0x32
153 #define IND_SIS_SCRATCH_REG_CR33  0x33
154 #define IND_SIS_LCD_PANEL         0x36
155 #define IND_SIS_SCRATCH_REG_CR37  0x37
156 #define IND_SIS_AGP_IO_PAD        0x48
157
158 #define IND_BRI_DRAM_STATUS       0x63 /* PCI config memory size offset */
159
160 #define MMIO_QUEUE_PHYBASE        0x85C0
161 #define MMIO_QUEUE_WRITEPORT      0x85C4
162 #define MMIO_QUEUE_READPORT       0x85C8
163
164 #define IND_SIS_CRT2_WRITE_ENABLE_300 0x24
165 #define IND_SIS_CRT2_WRITE_ENABLE_315 0x2F
166
167 #define SIS_PASSWORD              0x86  /* SR05 */
168 #define SIS_INTERLACED_MODE       0x20  /* SR06 */
169 #define SIS_8BPP_COLOR_MODE       0x0 
170 #define SIS_15BPP_COLOR_MODE      0x1 
171 #define SIS_16BPP_COLOR_MODE      0x2 
172 #define SIS_32BPP_COLOR_MODE      0x4 
173 #define SIS_DRAM_SIZE_MASK        0x3F  /* 300/630/730 SR14 */
174 #define SIS_DRAM_SIZE_1MB         0x00
175 #define SIS_DRAM_SIZE_2MB         0x01
176 #define SIS_DRAM_SIZE_4MB         0x03
177 #define SIS_DRAM_SIZE_8MB         0x07
178 #define SIS_DRAM_SIZE_16MB        0x0F
179 #define SIS_DRAM_SIZE_32MB        0x1F
180 #define SIS_DRAM_SIZE_64MB        0x3F
181 #define SIS_DATA_BUS_MASK         0xC0
182 #define SIS_DATA_BUS_32           0x00
183 #define SIS_DATA_BUS_64           0x01
184 #define SIS_DATA_BUS_128          0x02
185
186 #define SIS315_DATA_BUS_MASK      0x02
187 #define SIS315_DATA_BUS_64        0x00
188 #define SIS315_DATA_BUS_128       0x01
189 #define SIS315_DUAL_CHANNEL_MASK  0x0C
190 #define SIS315_SINGLE_CHANNEL_1_RANK    0x0
191 #define SIS315_SINGLE_CHANNEL_2_RANK    0x1
192 #define SIS315_ASYM_DDR                 0x02
193 #define SIS315_DUAL_CHANNEL_1_RANK      0x3
194
195 #define SIS_SCRATCH_REG_1A_MASK   0x10
196
197 #define SIS_ENABLE_2D             0x40  /* SR1E */
198
199 #define SIS_MEM_MAP_IO_ENABLE     0x01  /* SR20 */
200 #define SIS_PCI_ADDR_ENABLE       0x80
201
202 #define SIS_AGP_CMDQUEUE_ENABLE   0x80  /* 315/650/740 SR26 */
203 #define SIS_VRAM_CMDQUEUE_ENABLE  0x40
204 #define SIS_MMIO_CMD_ENABLE       0x20
205 #define SIS_CMD_QUEUE_SIZE_512k   0x00
206 #define SIS_CMD_QUEUE_SIZE_1M     0x04
207 #define SIS_CMD_QUEUE_SIZE_2M     0x08
208 #define SIS_CMD_QUEUE_SIZE_4M     0x0C
209 #define SIS_CMD_QUEUE_RESET       0x01
210 #define SIS_CMD_AUTO_CORR         0x02
211
212 #define SIS_SIMULTANEOUS_VIEW_ENABLE  0x01  /* CR30 */
213 #define SIS_MODE_SELECT_CRT2      0x02
214 #define SIS_VB_OUTPUT_COMPOSITE   0x04
215 #define SIS_VB_OUTPUT_SVIDEO      0x08
216 #define SIS_VB_OUTPUT_SCART       0x10
217 #define SIS_VB_OUTPUT_LCD         0x20
218 #define SIS_VB_OUTPUT_CRT2        0x40
219 #define SIS_VB_OUTPUT_HIVISION    0x80
220
221 #define SIS_VB_OUTPUT_DISABLE     0x20  /* CR31 */
222 #define SIS_DRIVER_MODE           0x40
223
224 #define SIS_VB_COMPOSITE          0x01  /* CR32 */
225 #define SIS_VB_SVIDEO             0x02
226 #define SIS_VB_SCART              0x04
227 #define SIS_VB_LCD                0x08
228 #define SIS_VB_CRT2               0x10
229 #define SIS_CRT1                  0x20
230 #define SIS_VB_HIVISION           0x40
231 #define SIS_VB_DVI                0x80
232 #define SIS_VB_TV                 (SIS_VB_COMPOSITE | SIS_VB_SVIDEO | \
233                                    SIS_VB_SCART | SIS_VB_HIVISION)
234
235 #define SIS_EXTERNAL_CHIP_MASK             0x0E  /* CR37 (< SiS 660) */
236 #define SIS_EXTERNAL_CHIP_SIS301           0x01  /* in CR37 << 1 ! */
237 #define SIS_EXTERNAL_CHIP_LVDS             0x02  /* in CR37 << 1 ! */
238 #define SIS_EXTERNAL_CHIP_TRUMPION         0x03  /* in CR37 << 1 ! */
239 #define SIS_EXTERNAL_CHIP_LVDS_CHRONTEL    0x04  /* in CR37 << 1 ! */
240 #define SIS_EXTERNAL_CHIP_CHRONTEL         0x05  /* in CR37 << 1 ! */
241 #define SIS310_EXTERNAL_CHIP_LVDS          0x02  /* in CR37 << 1 ! */
242 #define SIS310_EXTERNAL_CHIP_LVDS_CHRONTEL 0x03  /* in CR37 << 1 ! */
243
244 #define SIS_AGP_2X                0x20  /* CR48 */
245
246 #define BRI_DRAM_SIZE_MASK        0x70  /* PCI bridge config data */
247 #define BRI_DRAM_SIZE_2MB         0x00
248 #define BRI_DRAM_SIZE_4MB         0x01
249 #define BRI_DRAM_SIZE_8MB         0x02
250 #define BRI_DRAM_SIZE_16MB        0x03
251 #define BRI_DRAM_SIZE_32MB        0x04
252 #define BRI_DRAM_SIZE_64MB        0x05
253
254 #define HW_DEVICE_EXTENSION       SIS_HW_INFO
255 #define PHW_DEVICE_EXTENSION      PSIS_HW_INFO
256
257 #define SR_BUFFER_SIZE            5
258 #define CR_BUFFER_SIZE            5
259
260 /* entries for disp_state - deprecated as of 1.6.02 */
261 #define DISPTYPE_CRT1       0x00000008L
262 #define DISPTYPE_CRT2       0x00000004L
263 #define DISPTYPE_LCD        0x00000002L
264 #define DISPTYPE_TV         0x00000001L
265 #define DISPTYPE_DISP1      DISPTYPE_CRT1
266 #define DISPTYPE_DISP2      (DISPTYPE_CRT2 | DISPTYPE_LCD | DISPTYPE_TV)
267 #define DISPMODE_SINGLE     0x00000020L
268 #define DISPMODE_MIRROR     0x00000010L
269 #define DISPMODE_DUALVIEW   0x00000040L
270
271 /* Deprecated as of 1.6.02 - use vbflags instead */
272 #define HASVB_NONE              0x00
273 #define HASVB_301               0x01
274 #define HASVB_LVDS              0x02
275 #define HASVB_TRUMPION          0x04
276 #define HASVB_LVDS_CHRONTEL     0x10
277 #define HASVB_302               0x20
278 #define HASVB_303               0x40
279 #define HASVB_CHRONTEL          0x80
280
281 /* Useful macros */
282 #define inSISREG(base)          inb(base)
283 #define outSISREG(base,val)     outb(val,base)
284 #define orSISREG(base,val)      do { \
285                                   unsigned char __Temp = inb(base); \
286                                   outSISREG(base, __Temp | (val)); \
287                                 } while (0)
288 #define andSISREG(base,val)     do { \
289                                   unsigned char __Temp = inb(base); \
290                                   outSISREG(base, __Temp & (val)); \
291                                 } while (0)
292 #define inSISIDXREG(base,idx,var)   do { \
293                                       outb(idx,base); var=inb((base)+1); \
294                                     } while (0)
295 #define outSISIDXREG(base,idx,val)  do { \
296                                       outb(idx,base); outb((val),(base)+1); \
297                                     } while (0)
298 #define orSISIDXREG(base,idx,val)   do { \
299                                       unsigned char __Temp; \
300                                       outb(idx,base);   \
301                                       __Temp = inb((base)+1)|(val); \
302                                       outSISIDXREG(base,idx,__Temp); \
303                                     } while (0)
304 #define andSISIDXREG(base,idx,and)  do { \
305                                       unsigned char __Temp; \
306                                       outb(idx,base);   \
307                                       __Temp = inb((base)+1)&(and); \
308                                       outSISIDXREG(base,idx,__Temp); \
309                                     } while (0)
310 #define setSISIDXREG(base,idx,and,or)   do { \
311                                           unsigned char __Temp; \
312                                           outb(idx,base);   \
313                                           __Temp = (inb((base)+1)&(and))|(or); \
314                                           outSISIDXREG(base,idx,__Temp); \
315                                         } while (0)
316
317 /* ------------------- Global Variables ----------------------------- */
318
319 /* Fbcon variables */
320 static struct fb_info *sis_fb_info;
321
322 static struct fb_var_screeninfo default_var = {
323         .xres            = 0,
324         .yres            = 0,
325         .xres_virtual    = 0,
326         .yres_virtual    = 0,
327         .xoffset         = 0,
328         .yoffset         = 0,
329         .bits_per_pixel  = 0,
330         .grayscale       = 0,
331         .red             = {0, 8, 0},
332         .green           = {0, 8, 0},
333         .blue            = {0, 8, 0},
334         .transp          = {0, 0, 0},
335         .nonstd          = 0,
336         .activate        = FB_ACTIVATE_NOW,
337         .height          = -1,
338         .width           = -1,
339         .accel_flags     = 0,
340         .pixclock        = 0,
341         .left_margin     = 0,
342         .right_margin    = 0,
343         .upper_margin    = 0,
344         .lower_margin    = 0,
345         .hsync_len       = 0,
346         .vsync_len       = 0,
347         .sync            = 0,
348         .vmode           = FB_VMODE_NONINTERLACED,
349 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
350         .reserved        = {0, 0, 0, 0, 0, 0}
351 #endif
352 };
353
354 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
355 static struct fb_fix_screeninfo sisfb_fix = {
356         .id             = "SiS",
357         .type           = FB_TYPE_PACKED_PIXELS,
358         .xpanstep       = 0,
359         .ypanstep       = 1,
360 };
361 static char myid[40];
362 static u32 pseudo_palette[17];
363 #endif
364
365 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
366 static struct display sis_disp;
367
368 static struct display_switch sisfb_sw;  
369
370 static struct {
371         u16 blue, green, red, pad;
372 } sis_palette[256];
373
374 static union {
375 #ifdef FBCON_HAS_CFB16
376         u16 cfb16[16];
377 #endif
378 #ifdef FBCON_HAS_CFB32
379         u32 cfb32[16];
380 #endif
381 } sis_fbcon_cmap;
382
383 static int sisfb_inverse = 0;
384 static int currcon = 0;
385 #endif
386
387 /* global flags */
388 static int sisfb_off = 0;
389 static int sisfb_crt1off = 0;
390 static int sisfb_forcecrt1 = -1;
391 static int sisvga_enabled = 0;
392 static int sisfb_userom = 1;
393 static int sisfb_useoem = -1;
394 static int sisfb_parm_rate = -1;
395 static int sisfb_registered = 0;
396 static int sisfb_mem = 0;
397 static int sisfb_pdc = 0;
398 static int sisfb_ypan = -1;
399 static int sisfb_max = -1;
400 static int sisfb_nocrt2rate = 0;
401 static int sisfb_dstn = 0;
402 static int sisfb_fstn = 0;
403
404 VGA_ENGINE sisvga_engine = UNKNOWN_VGA;
405 int        sisfb_accel = -1;
406
407 /* These are to adapted according to VGA_ENGINE type */
408 static int sisfb_hwcursor_size = 0;
409 static int sisfb_CRT2_write_enable = 0;
410
411 int sisfb_crt2type  = -1;       /* CRT2 type (for overriding autodetection) */
412 int sisfb_tvplug    = -1;       /* Tv plug type (for overriding autodetection) */
413
414 int sisfb_queuemode = -1;       /* Use MMIO queue mode by default (315 series only) */
415
416 unsigned char sisfb_detectedpdc = 0;
417
418 unsigned char sisfb_detectedlcda = 0xff;
419
420 /* data for sis hardware ("par") */
421 struct video_info ivideo;
422
423 /* For ioctl SISFB_GET_INFO */
424 sisfb_info sisfbinfo;
425
426 /* Hardware info; contains data on hardware */
427 SIS_HW_INFO sishw_ext;
428
429 /* SiS private structure */
430 SiS_Private  SiS_Pr;
431
432 /* Card parameters */
433 static unsigned long sisfb_mmio_size = 0;
434 static u8            sisfb_caps = 0;
435
436 typedef enum _SIS_CMDTYPE {
437         MMIO_CMD = 0,
438         AGP_CMD_QUEUE,
439         VM_CMD_QUEUE,
440 } SIS_CMDTYPE;
441
442 /* List of supported chips */
443 static struct board {
444         u16 vendor, device;
445         const char *name;
446 } sisdev_list[] = {
447         {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_300,     "SIS 300"},
448         {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_540_VGA, "SIS 540 VGA"},
449         {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_630_VGA, "SIS 630/730 VGA"},
450         {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_315H,    "SIS 315H"},
451         {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_315,     "SIS 315"},
452         {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_315PRO,  "SIS 315PRO"},
453         {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_550_VGA, "SIS 550 VGA"},
454         {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_650_VGA, "SIS 65x/M65x/740 VGA"},
455         {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_330,     "SIS 330"},
456         {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_660_VGA, "SIS 661FX/M661FX/741/760 VGA"},
457         {0, 0, NULL}
458 };
459
460 #define MD_SIS300 1
461 #define MD_SIS315 2
462
463 /* Mode table */
464 /* NOT const - will be patched for 1280x768 mode number chaos reasons */
465 struct _sisbios_mode {
466         char name[15];
467         u8 mode_no;
468         u16 vesa_mode_no_1;  /* "SiS defined" VESA mode number */
469         u16 vesa_mode_no_2;  /* Real VESA mode numbers */
470         u16 xres;
471         u16 yres;
472         u16 bpp;
473         u16 rate_idx;
474         u16 cols;
475         u16 rows;
476         u8  chipset;
477 } sisbios_mode[] = {
478 #define MODE_INDEX_NONE           0  /* index for mode=none */
479         {"none",         0xff, 0x0000, 0x0000,    0,    0,  0, 0,   0,  0, MD_SIS300|MD_SIS315},
480         {"320x200x8",    0x59, 0x0138, 0x0000,  320,  200,  8, 1,  40, 12, MD_SIS300|MD_SIS315},
481         {"320x200x16",   0x41, 0x010e, 0x0000,  320,  200, 16, 1,  40, 12, MD_SIS300|MD_SIS315},
482         {"320x200x24",   0x4f, 0x0000, 0x0000,  320,  200, 32, 1,  40, 12, MD_SIS300|MD_SIS315},  /* TW: That's for people who mix up color- and fb depth */
483         {"320x200x32",   0x4f, 0x0000, 0x0000,  320,  200, 32, 1,  40, 12, MD_SIS300|MD_SIS315},
484         {"320x240x8",    0x50, 0x0132, 0x0000,  320,  240,  8, 1,  40, 15, MD_SIS300|MD_SIS315},
485         {"320x240x16",   0x56, 0x0135, 0x0000,  320,  240, 16, 1,  40, 15, MD_SIS300|MD_SIS315},
486         {"320x240x24",   0x53, 0x0000, 0x0000,  320,  240, 32, 1,  40, 15, MD_SIS300|MD_SIS315},
487         {"320x240x32",   0x53, 0x0000, 0x0000,  320,  240, 32, 1,  40, 15, MD_SIS300|MD_SIS315},
488         {"320x240x8",    0x5a, 0x0132, 0x0000,  320,  480,  8, 1,  40, 30,           MD_SIS315},  /* TW: FSTN */
489         {"320x240x16",   0x5b, 0x0135, 0x0000,  320,  480, 16, 1,  40, 30,           MD_SIS315},  /* TW: FSTN */
490         {"400x300x8",    0x51, 0x0133, 0x0000,  400,  300,  8, 1,  50, 18, MD_SIS300|MD_SIS315},
491         {"400x300x16",   0x57, 0x0136, 0x0000,  400,  300, 16, 1,  50, 18, MD_SIS300|MD_SIS315},
492         {"400x300x24",   0x54, 0x0000, 0x0000,  400,  300, 32, 1,  50, 18, MD_SIS300|MD_SIS315},
493         {"400x300x32",   0x54, 0x0000, 0x0000,  400,  300, 32, 1,  50, 18, MD_SIS300|MD_SIS315},
494         {"512x384x8",    0x52, 0x0000, 0x0000,  512,  384,  8, 1,  64, 24, MD_SIS300|MD_SIS315},
495         {"512x384x16",   0x58, 0x0000, 0x0000,  512,  384, 16, 1,  64, 24, MD_SIS300|MD_SIS315},
496         {"512x384x24",   0x5c, 0x0000, 0x0000,  512,  384, 32, 1,  64, 24, MD_SIS300|MD_SIS315},
497         {"512x384x32",   0x5c, 0x0000, 0x0000,  512,  384, 32, 1,  64, 24, MD_SIS300|MD_SIS315},
498         {"640x400x8",    0x2f, 0x0000, 0x0000,  640,  400,  8, 1,  80, 25, MD_SIS300|MD_SIS315},
499         {"640x400x16",   0x5d, 0x0000, 0x0000,  640,  400, 16, 1,  80, 25, MD_SIS300|MD_SIS315},
500         {"640x400x24",   0x5e, 0x0000, 0x0000,  640,  400, 32, 1,  80, 25, MD_SIS300|MD_SIS315},
501         {"640x400x32",   0x5e, 0x0000, 0x0000,  640,  400, 32, 1,  80, 25, MD_SIS300|MD_SIS315},
502         {"640x480x8",    0x2e, 0x0101, 0x0101,  640,  480,  8, 1,  80, 30, MD_SIS300|MD_SIS315},
503         {"640x480x16",   0x44, 0x0111, 0x0111,  640,  480, 16, 1,  80, 30, MD_SIS300|MD_SIS315},
504         {"640x480x24",   0x62, 0x013a, 0x0112,  640,  480, 32, 1,  80, 30, MD_SIS300|MD_SIS315},
505         {"640x480x32",   0x62, 0x013a, 0x0112,  640,  480, 32, 1,  80, 30, MD_SIS300|MD_SIS315},
506         {"720x480x8",    0x31, 0x0000, 0x0000,  720,  480,  8, 1,  90, 30, MD_SIS300|MD_SIS315},
507         {"720x480x16",   0x33, 0x0000, 0x0000,  720,  480, 16, 1,  90, 30, MD_SIS300|MD_SIS315},
508         {"720x480x24",   0x35, 0x0000, 0x0000,  720,  480, 32, 1,  90, 30, MD_SIS300|MD_SIS315},
509         {"720x480x32",   0x35, 0x0000, 0x0000,  720,  480, 32, 1,  90, 30, MD_SIS300|MD_SIS315},
510         {"720x576x8",    0x32, 0x0000, 0x0000,  720,  576,  8, 1,  90, 36, MD_SIS300|MD_SIS315},
511         {"720x576x16",   0x34, 0x0000, 0x0000,  720,  576, 16, 1,  90, 36, MD_SIS300|MD_SIS315},
512         {"720x576x24",   0x36, 0x0000, 0x0000,  720,  576, 32, 1,  90, 36, MD_SIS300|MD_SIS315},
513         {"720x576x32",   0x36, 0x0000, 0x0000,  720,  576, 32, 1,  90, 36, MD_SIS300|MD_SIS315},
514         {"768x576x8",    0x5f, 0x0000, 0x0000,  768,  576,  8, 1,  96, 36, MD_SIS300|MD_SIS315},
515         {"768x576x16",   0x60, 0x0000, 0x0000,  768,  576, 16, 1,  96, 36, MD_SIS300|MD_SIS315},
516         {"768x576x24",   0x61, 0x0000, 0x0000,  768,  576, 32, 1,  96, 36, MD_SIS300|MD_SIS315},
517         {"768x576x32",   0x61, 0x0000, 0x0000,  768,  576, 32, 1,  96, 36, MD_SIS300|MD_SIS315},
518         {"800x480x8",    0x70, 0x0000, 0x0000,  800,  480,  8, 1, 100, 30, MD_SIS300|MD_SIS315},
519         {"800x480x16",   0x7a, 0x0000, 0x0000,  800,  480, 16, 1, 100, 30, MD_SIS300|MD_SIS315},
520         {"800x480x24",   0x76, 0x0000, 0x0000,  800,  480, 32, 1, 100, 30, MD_SIS300|MD_SIS315},
521         {"800x480x32",   0x76, 0x0000, 0x0000,  800,  480, 32, 1, 100, 30, MD_SIS300|MD_SIS315},
522 #define DEFAULT_MODE              43 /* index for 800x600x8 */
523 #define DEFAULT_LCDMODE           43 /* index for 800x600x8 */
524 #define DEFAULT_TVMODE            43 /* index for 800x600x8 */
525         {"800x600x8",    0x30, 0x0103, 0x0103,  800,  600,  8, 2, 100, 37, MD_SIS300|MD_SIS315},
526         {"800x600x16",   0x47, 0x0114, 0x0114,  800,  600, 16, 2, 100, 37, MD_SIS300|MD_SIS315},
527         {"800x600x24",   0x63, 0x013b, 0x0115,  800,  600, 32, 2, 100, 37, MD_SIS300|MD_SIS315},
528         {"800x600x32",   0x63, 0x013b, 0x0115,  800,  600, 32, 2, 100, 37, MD_SIS300|MD_SIS315},
529         {"848x480x8",    0x39, 0x0000, 0x0000,  848,  480,  8, 2, 106, 30, MD_SIS300|MD_SIS315},
530         {"848x480x16",   0x3b, 0x0000, 0x0000,  848,  480, 16, 2, 106, 30, MD_SIS300|MD_SIS315},
531         {"848x480x24",   0x3e, 0x0000, 0x0000,  848,  480, 32, 2, 106, 30, MD_SIS300|MD_SIS315},
532         {"848x480x32",   0x3e, 0x0000, 0x0000,  848,  480, 32, 2, 106, 30, MD_SIS300|MD_SIS315},
533         {"856x480x8",    0x3f, 0x0000, 0x0000,  856,  480,  8, 2, 107, 30, MD_SIS300|MD_SIS315},
534         {"856x480x16",   0x42, 0x0000, 0x0000,  856,  480, 16, 2, 107, 30, MD_SIS300|MD_SIS315},
535         {"856x480x24",   0x45, 0x0000, 0x0000,  856,  480, 32, 2, 107, 30, MD_SIS300|MD_SIS315},
536         {"856x480x32",   0x45, 0x0000, 0x0000,  856,  480, 32, 2, 107, 30, MD_SIS300|MD_SIS315},
537         {"1024x576x8",   0x71, 0x0000, 0x0000, 1024,  576,  8, 1, 128, 36, MD_SIS300|MD_SIS315},
538         {"1024x576x16",  0x74, 0x0000, 0x0000, 1024,  576, 16, 1, 128, 36, MD_SIS300|MD_SIS315},
539         {"1024x576x24",  0x77, 0x0000, 0x0000, 1024,  576, 32, 1, 128, 36, MD_SIS300|MD_SIS315},
540         {"1024x576x32",  0x77, 0x0000, 0x0000, 1024,  576, 32, 1, 128, 36, MD_SIS300|MD_SIS315},
541         {"1024x600x8",   0x20, 0x0000, 0x0000, 1024,  600,  8, 1, 128, 37, MD_SIS300          },
542         {"1024x600x16",  0x21, 0x0000, 0x0000, 1024,  600, 16, 1, 128, 37, MD_SIS300          },
543         {"1024x600x24",  0x22, 0x0000, 0x0000, 1024,  600, 32, 1, 128, 37, MD_SIS300          },
544         {"1024x600x32",  0x22, 0x0000, 0x0000, 1024,  600, 32, 1, 128, 37, MD_SIS300          },
545         {"1024x768x8",   0x38, 0x0105, 0x0105, 1024,  768,  8, 2, 128, 48, MD_SIS300|MD_SIS315},
546         {"1024x768x16",  0x4a, 0x0117, 0x0117, 1024,  768, 16, 2, 128, 48, MD_SIS300|MD_SIS315},
547         {"1024x768x24",  0x64, 0x013c, 0x0118, 1024,  768, 32, 2, 128, 48, MD_SIS300|MD_SIS315},
548         {"1024x768x32",  0x64, 0x013c, 0x0118, 1024,  768, 32, 2, 128, 48, MD_SIS300|MD_SIS315},
549         {"1152x768x8",   0x23, 0x0000, 0x0000, 1152,  768,  8, 1, 144, 48, MD_SIS300          },
550         {"1152x768x16",  0x24, 0x0000, 0x0000, 1152,  768, 16, 1, 144, 48, MD_SIS300          },
551         {"1152x768x24",  0x25, 0x0000, 0x0000, 1152,  768, 32, 1, 144, 48, MD_SIS300          },
552         {"1152x768x32",  0x25, 0x0000, 0x0000, 1152,  768, 32, 1, 144, 48, MD_SIS300          },
553         {"1152x864x8",   0x29, 0x0000, 0x0000, 1152,  864,  8, 1, 144, 54, MD_SIS300|MD_SIS315},
554         {"1152x864x16",  0x2a, 0x0000, 0x0000, 1152,  864, 16, 1, 144, 54, MD_SIS300|MD_SIS315},
555         {"1152x864x24",  0x2b, 0x0000, 0x0000, 1152,  864, 32, 1, 144, 54, MD_SIS300|MD_SIS315},
556         {"1152x864x32",  0x2b, 0x0000, 0x0000, 1152,  864, 32, 1, 144, 54, MD_SIS300|MD_SIS315},
557         {"1280x720x8",   0x79, 0x0000, 0x0000, 1280,  720,  8, 1, 160, 45, MD_SIS300|MD_SIS315},
558         {"1280x720x16",  0x75, 0x0000, 0x0000, 1280,  720, 16, 1, 160, 45, MD_SIS300|MD_SIS315},
559         {"1280x720x24",  0x78, 0x0000, 0x0000, 1280,  720, 32, 1, 160, 45, MD_SIS300|MD_SIS315},
560         {"1280x720x32",  0x78, 0x0000, 0x0000, 1280,  720, 32, 1, 160, 45, MD_SIS300|MD_SIS315},
561 #define MODEINDEX_1280x768 79
562         {"1280x768x8",   0x23, 0x0000, 0x0000, 1280,  768,  8, 1, 160, 48, MD_SIS300|MD_SIS315},
563         {"1280x768x16",  0x24, 0x0000, 0x0000, 1280,  768, 16, 1, 160, 48, MD_SIS300|MD_SIS315},
564         {"1280x768x24",  0x25, 0x0000, 0x0000, 1280,  768, 32, 1, 160, 48, MD_SIS300|MD_SIS315},
565         {"1280x768x32",  0x25, 0x0000, 0x0000, 1280,  768, 32, 1, 160, 48, MD_SIS300|MD_SIS315},
566         {"1280x960x8",   0x7c, 0x0000, 0x0000, 1280,  960,  8, 1, 160, 60, MD_SIS300|MD_SIS315},
567         {"1280x960x16",  0x7d, 0x0000, 0x0000, 1280,  960, 16, 1, 160, 60, MD_SIS300|MD_SIS315},
568         {"1280x960x24",  0x7e, 0x0000, 0x0000, 1280,  960, 32, 1, 160, 60, MD_SIS300|MD_SIS315},
569         {"1280x960x32",  0x7e, 0x0000, 0x0000, 1280,  960, 32, 1, 160, 60, MD_SIS300|MD_SIS315},
570         {"1280x1024x8",  0x3a, 0x0107, 0x0107, 1280, 1024,  8, 2, 160, 64, MD_SIS300|MD_SIS315},
571         {"1280x1024x16", 0x4d, 0x011a, 0x011a, 1280, 1024, 16, 2, 160, 64, MD_SIS300|MD_SIS315},
572         {"1280x1024x24", 0x65, 0x013d, 0x011b, 1280, 1024, 32, 2, 160, 64, MD_SIS300|MD_SIS315},
573         {"1280x1024x32", 0x65, 0x013d, 0x011b, 1280, 1024, 32, 2, 160, 64, MD_SIS300|MD_SIS315},
574         {"1360x768x8",   0x48, 0x0000, 0x0000, 1360,  768,  8, 1, 170, 48, MD_SIS300|MD_SIS315},
575         {"1360x768x16",  0x4b, 0x0000, 0x0000, 1360,  768, 16, 1, 170, 48, MD_SIS300|MD_SIS315},
576         {"1360x768x24",  0x4e, 0x0000, 0x0000, 1360,  768, 32, 1, 170, 48, MD_SIS300|MD_SIS315},
577         {"1360x768x32",  0x4e, 0x0000, 0x0000, 1360,  768, 32, 1, 170, 48, MD_SIS300|MD_SIS315},
578         {"1360x1024x8",  0x67, 0x0000, 0x0000, 1360, 1024,  8, 1, 170, 64, MD_SIS300          },
579         {"1360x1024x16", 0x6f, 0x0000, 0x0000, 1360, 1024, 16, 1, 170, 64, MD_SIS300          },
580         {"1360x1024x24", 0x72, 0x0000, 0x0000, 1360, 1024, 32, 1, 170, 64, MD_SIS300          },
581         {"1360x1024x32", 0x72, 0x0000, 0x0000, 1360, 1024, 32, 1, 170, 64, MD_SIS300          },
582         {"1400x1050x8",  0x26, 0x0000, 0x0000, 1400, 1050,  8, 1, 175, 65,           MD_SIS315},
583         {"1400x1050x16", 0x27, 0x0000, 0x0000, 1400, 1050, 16, 1, 175, 65,           MD_SIS315},
584         {"1400x1050x24", 0x28, 0x0000, 0x0000, 1400, 1050, 32, 1, 175, 65,           MD_SIS315},
585         {"1400x1050x32", 0x28, 0x0000, 0x0000, 1400, 1050, 32, 1, 175, 65,           MD_SIS315},
586         {"1600x1200x8",  0x3c, 0x0130, 0x011c, 1600, 1200,  8, 1, 200, 75, MD_SIS300|MD_SIS315},
587         {"1600x1200x16", 0x3d, 0x0131, 0x011e, 1600, 1200, 16, 1, 200, 75, MD_SIS300|MD_SIS315},
588         {"1600x1200x24", 0x66, 0x013e, 0x011f, 1600, 1200, 32, 1, 200, 75, MD_SIS300|MD_SIS315},
589         {"1600x1200x32", 0x66, 0x013e, 0x011f, 1600, 1200, 32, 1, 200, 75, MD_SIS300|MD_SIS315},
590         {"1920x1440x8",  0x68, 0x013f, 0x0000, 1920, 1440,  8, 1, 240, 75, MD_SIS300|MD_SIS315},
591         {"1920x1440x16", 0x69, 0x0140, 0x0000, 1920, 1440, 16, 1, 240, 75, MD_SIS300|MD_SIS315},
592         {"1920x1440x24", 0x6b, 0x0141, 0x0000, 1920, 1440, 32, 1, 240, 75, MD_SIS300|MD_SIS315},
593         {"1920x1440x32", 0x6b, 0x0141, 0x0000, 1920, 1440, 32, 1, 240, 75, MD_SIS300|MD_SIS315},
594         {"2048x1536x8",  0x6c, 0x0000, 0x0000, 2048, 1536,  8, 1, 256, 96,           MD_SIS315},
595         {"2048x1536x16", 0x6d, 0x0000, 0x0000, 2048, 1536, 16, 1, 256, 96,           MD_SIS315},
596         {"2048x1536x24", 0x6e, 0x0000, 0x0000, 2048, 1536, 32, 1, 256, 96,           MD_SIS315},
597         {"2048x1536x32", 0x6e, 0x0000, 0x0000, 2048, 1536, 32, 1, 256, 96,           MD_SIS315},
598         {"\0", 0x00, 0, 0, 0, 0, 0, 0, 0}
599 };
600
601 /* mode-related variables */
602 #ifdef MODULE
603 int sisfb_mode_idx = MODE_INDEX_NONE;  /* Don't use a mode by default if we are a module */
604 #else
605 int sisfb_mode_idx = -1;               /* Use a default mode if we are inside the kernel */
606 #endif
607 u8  sisfb_mode_no  = 0;
608 u8  sisfb_rate_idx = 0;
609
610 /* CR36 evaluation */
611 const USHORT sis300paneltype[] =
612     { LCD_UNKNOWN,   LCD_800x600,   LCD_1024x768,  LCD_1280x1024,
613       LCD_1280x960,  LCD_640x480,   LCD_1024x600,  LCD_1152x768,
614       LCD_1024x768,  LCD_1024x768,  LCD_1024x768,  LCD_1024x768,
615       LCD_1024x768,  LCD_1024x768,  LCD_320x480,   LCD_1024x768 };
616
617 const USHORT sis310paneltype[] =
618     { LCD_UNKNOWN,   LCD_800x600,   LCD_1024x768,  LCD_1280x1024,
619       LCD_640x480,   LCD_1024x600,  LCD_1152x864,  LCD_1280x960,
620       LCD_1152x768,  LCD_1400x1050, LCD_1280x768,  LCD_1600x1200,
621       LCD_640x480_2, LCD_640x480_3, LCD_320x480,   LCD_1024x768 };
622
623 #define FL_550_DSTN 0x01
624 #define FL_550_FSTN 0x02
625
626 static const struct _sis_crt2type {
627         char name[10];
628         int type_no;
629         int tvplug_no;
630         unsigned short flags;
631 } sis_crt2type[] = {
632         {"NONE",        0,              -1,        0},
633         {"LCD",         CRT2_LCD,       -1,        0},
634         {"TV",          CRT2_TV,        -1,        0},
635         {"VGA",         CRT2_VGA,       -1,        0},
636         {"SVIDEO",      CRT2_TV,        TV_SVIDEO, 0},
637         {"COMPOSITE",   CRT2_TV,        TV_AVIDEO, 0},
638         {"SCART",       CRT2_TV,        TV_SCART,  0},
639         {"DSTN",        CRT2_LCD,       -1,        FL_550_DSTN},
640         {"FSTN",        CRT2_LCD,       -1,        FL_550_FSTN},
641         {"\0",          -1,             -1,        0}
642 };
643
644 /* Queue mode selection for 310 series */
645 static const struct _sis_queuemode {
646         char name[6];
647         int type_no;
648 } sis_queuemode[] = {
649         {"AGP",         AGP_CMD_QUEUE},
650         {"VRAM",        VM_CMD_QUEUE},
651         {"MMIO",        MMIO_CMD},
652         {"\0",          -1}
653 };
654
655 /* TV standard */
656 static const struct _sis_tvtype {
657         char name[6];
658         int type_no;
659 } sis_tvtype[] = {
660         {"PAL",         TV_PAL},
661         {"NTSC",        TV_NTSC},
662         {"\0",          -1}
663 };
664
665 static const struct _sis_vrate {
666         u16 idx;
667         u16 xres;
668         u16 yres;
669         u16 refresh;
670         BOOLEAN SiS730valid32bpp;
671 } sisfb_vrate[] = {
672         {1,  320,  200,  70,  TRUE},
673         {1,  320,  240,  60,  TRUE},
674         {1,  320,  480,  60,  TRUE},
675         {1,  400,  300,  60,  TRUE},
676         {1,  512,  384,  60,  TRUE},
677         {1,  640,  400,  72,  TRUE},
678         {1,  640,  480,  60,  TRUE}, {2,  640,  480,  72,  TRUE}, {3,  640,  480,  75,  TRUE},
679         {4,  640,  480,  85,  TRUE}, {5,  640,  480, 100,  TRUE}, {6,  640,  480, 120,  TRUE},
680         {7,  640,  480, 160,  TRUE}, {8,  640,  480, 200,  TRUE},
681         {1,  720,  480,  60,  TRUE},
682         {1,  720,  576,  58,  TRUE},
683         {1,  768,  576,  58,  TRUE},
684         {1,  800,  480,  60,  TRUE}, {2,  800,  480,  75,  TRUE}, {3,  800,  480,  85,  TRUE},
685         {1,  800,  600,  56,  TRUE}, {2,  800,  600,  60,  TRUE}, {3,  800,  600,  72,  TRUE},
686         {4,  800,  600,  75,  TRUE}, {5,  800,  600,  85,  TRUE}, {6,  800,  600, 105,  TRUE},
687         {7,  800,  600, 120,  TRUE}, {8,  800,  600, 160,  TRUE},
688         {1,  848,  480,  39,  TRUE}, {2,  848,  480,  60,  TRUE},
689         {1,  856,  480,  39,  TRUE}, {2,  856,  480,  60,  TRUE},
690         {1, 1024,  576,  60,  TRUE}, {2, 1024,  576,  75,  TRUE}, {3, 1024,  576,  85,  TRUE},
691         {1, 1024,  600,  60,  TRUE},
692         {1, 1024,  768,  43,  TRUE}, {2, 1024,  768,  60,  TRUE}, {3, 1024,  768,  70, FALSE},
693         {4, 1024,  768,  75, FALSE}, {5, 1024,  768,  85,  TRUE}, {6, 1024,  768, 100,  TRUE},
694         {7, 1024,  768, 120,  TRUE},
695         {1, 1152,  768,  60,  TRUE},
696         {1, 1152,  864,  75,  TRUE}, {2, 1152,  864,  84,  TRUE},
697         {1, 1280,  720,  60,  TRUE}, {2, 1280,  720,  75,  TRUE}, {3, 1280,  720,  85,  TRUE},
698         {1, 1280,  768,  60,  TRUE},
699         {1, 1280,  960,  60,  TRUE}, {2, 1280,  960,  85,  TRUE},
700         {1, 1280, 1024,  43,  TRUE}, {2, 1280, 1024,  60,  TRUE}, {3, 1280, 1024,  75,  TRUE},
701         {4, 1280, 1024,  85,  TRUE},
702         {1, 1360,  768,  60,  TRUE},
703         {1, 1360, 1024,  59,  TRUE},
704         {1, 1400, 1050,  60,  TRUE}, {2, 1400, 1050,  75,  TRUE},
705         {1, 1600, 1200,  60,  TRUE}, {2, 1600, 1200,  65,  TRUE}, {3, 1600, 1200,  70,  TRUE},
706         {4, 1600, 1200,  75,  TRUE}, {5, 1600, 1200,  85,  TRUE}, {6, 1600, 1200, 100,  TRUE},
707         {7, 1600, 1200, 120,  TRUE},
708         {1, 1920, 1440,  60,  TRUE}, {2, 1920, 1440,  65,  TRUE}, {3, 1920, 1440,  70,  TRUE},
709         {4, 1920, 1440,  75,  TRUE}, {5, 1920, 1440,  85,  TRUE}, {6, 1920, 1440, 100,  TRUE},
710         {1, 2048, 1536,  60,  TRUE}, {2, 2048, 1536,  65,  TRUE}, {3, 2048, 1536,  70,  TRUE},
711         {4, 2048, 1536,  75,  TRUE}, {5, 2048, 1536,  85,  TRUE},
712         {0,    0,    0,   0, FALSE}
713 };
714
715 static struct sisfb_monitor {
716         u16 hmin;
717         u16 hmax;
718         u16 vmin;
719         u16 vmax;
720         u32 dclockmax;
721         u8  feature;
722         BOOLEAN datavalid;
723 } sisfb_thismonitor;
724
725 static const struct _sisfbddcsmodes {
726         u32 mask;
727         u16 h;
728         u16 v;
729         u32 d;
730 } sisfb_ddcsmodes[] = {
731         { 0x10000, 67, 75, 108000},
732         { 0x08000, 48, 72,  50000},
733         { 0x04000, 46, 75,  49500},
734         { 0x01000, 35, 43,  44900},
735         { 0x00800, 48, 60,  65000},
736         { 0x00400, 56, 70,  75000},
737         { 0x00200, 60, 75,  78800},
738         { 0x00100, 80, 75, 135000},
739         { 0x00020, 31, 60,  25200},
740         { 0x00008, 38, 72,  31500},
741         { 0x00004, 37, 75,  31500},
742         { 0x00002, 35, 56,  36000},
743         { 0x00001, 38, 60,  40000}
744 };
745
746 static const struct _sisfbddcfmodes {
747         u16 x;
748         u16 y;
749         u16 v;
750         u16 h;
751         u32 d;
752 } sisfb_ddcfmodes[] = {
753        { 1280, 1024, 85, 92, 157500},
754        { 1600, 1200, 60, 75, 162000},
755        { 1600, 1200, 65, 82, 175500},
756        { 1600, 1200, 70, 88, 189000},
757        { 1600, 1200, 75, 94, 202500},
758        { 1600, 1200, 85, 107,229500},
759        { 1920, 1440, 60, 90, 234000},
760        { 1920, 1440, 75, 113,297000}
761 };
762
763 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
764 static u8 sisfb_lastrates[128];
765 #endif
766
767 static const struct _chswtable {
768     int subsysVendor;
769     int subsysCard;
770     char *vendorName;
771     char *cardName;
772 } mychswtable[] = {
773         { 0x1631, 0x1002, "Mitachi", "0x1002" },
774         { 0x1071, 0x7521, "Mitac"  , "7521P"  },
775         { 0,      0,      ""       , ""       }
776 };
777
778 static const struct _customttable {
779     unsigned short chipID;
780     char *biosversion;
781     char *biosdate;
782     unsigned long bioschksum;
783     unsigned short biosFootprintAddr[5];
784     unsigned char biosFootprintData[5];
785     unsigned short pcisubsysvendor;
786     unsigned short pcisubsyscard;
787     char *vendorName;
788     char *cardName;
789     unsigned long SpecialID;
790     char *optionName;
791 } mycustomttable[] = {
792         { SIS_630, "2.00.07", "09/27/2002-13:38:25",
793           0x3240A8,
794           { 0x220, 0x227, 0x228, 0x229, 0x0ee },
795           {  0x01,  0xe3,  0x9a,  0x6a,  0xef },
796           0x1039, 0x6300,
797           "Barco", "iQ R200L/300/400", CUT_BARCO1366, "BARCO_1366"
798         },
799         { SIS_630, "2.00.07", "09/27/2002-13:38:25",
800           0x323FBD,
801           { 0x220, 0x227, 0x228, 0x229, 0x0ee },
802           {  0x00,  0x5a,  0x64,  0x41,  0xef },
803           0x1039, 0x6300,
804           "Barco", "iQ G200L/300/400/500", CUT_BARCO1024, "BARCO_1024"
805         },
806         { SIS_650, "", "",
807           0,
808           { 0, 0, 0, 0, 0 },
809           { 0, 0, 0, 0, 0 },
810           0x0e11, 0x083c,
811           "Inventec (Compaq)", "3017cl/3045US", CUT_COMPAQ12802, "COMPAQ_1280"
812         },
813         { SIS_650, "", "",
814           0,
815           { 0x00c, 0, 0, 0, 0 },
816           { 'e'  , 0, 0, 0, 0 },
817           0x1558, 0x0287,
818           "Clevo", "L285/L287 (Version 1)", CUT_CLEVO1024, "CLEVO_L28X_1"
819         },
820         { SIS_650, "", "",
821           0,
822           { 0x00c, 0, 0, 0, 0 },
823           { 'y'  , 0, 0, 0, 0 },
824           0x1558, 0x0287,
825           "Clevo", "L285/L287 (Version 2)", CUT_CLEVO10242, "CLEVO_L28X_2"
826         },
827         { SIS_650, "", "",
828           0,
829           { 0, 0, 0, 0, 0 },
830           { 0, 0, 0, 0, 0 },
831           0x1558, 0x0400,  /* possibly 401 and 402 as well; not panelsize specific (?) */
832           "Clevo", "D400S/D410S/D400H/D410H", CUT_CLEVO1400, "CLEVO_D4X0"
833         },
834         { SIS_650, "", "",
835           0,    /* Shift LCD in LCD-via-CRT1 mode */
836           { 0, 0, 0, 0, 0 },
837           { 0, 0, 0, 0, 0 },
838           0x1558, 0x2263,
839           "Clevo", "D22ES/D27ES", CUT_UNIWILL1024, "CLEVO_D2X0ES"
840         },
841         { SIS_650, "", "",
842           0,    /* Shift LCD in LCD-via-CRT1 mode */
843           { 0, 0, 0, 0, 0 },
844           { 0, 0, 0, 0, 0 },
845           0x1734, 0x101f,
846           "Uniwill", "N243S9", CUT_UNIWILL1024, "UNIWILL_N243S9"
847         },
848         { SIS_650, "", "",
849           0,    /* Shift LCD in LCD-via-CRT1 mode */
850           { 0, 0, 0, 0, 0 },
851           { 0, 0, 0, 0, 0 },
852           0x1584, 0x5103,
853           "Uniwill", "N35BS1", CUT_UNIWILL10242, "UNIWILL_N35BS1"
854         },
855         { SIS_650, "1.09.2c", "",  /* Other versions, too? */
856           0,    /* Shift LCD in LCD-via-CRT1 mode */
857           { 0, 0, 0, 0, 0 },
858           { 0, 0, 0, 0, 0 },
859           0x1019, 0x0f05,
860           "ECS", "A928", CUT_UNIWILL1024, "ECS_A928"
861         },
862         { SIS_740, "1.11.27a", "",
863           0,
864           { 0, 0, 0, 0, 0 },
865           { 0, 0, 0, 0, 0 },
866           0x1043, 0x1612,
867           "Asus", "L3000D/L3500D", CUT_ASUSL3000D, "ASUS_L3X00"
868         },
869         { SIS_650, "1.10.9k", "",
870           0,
871           { 0, 0, 0, 0, 0 },
872           { 0, 0, 0, 0, 0 },
873           0x1025, 0x0028,
874           "Acer", "Aspire 1700", CUT_ACER1280, "ACER_ASPIRE1700"
875         },
876         { SIS_650, "1.10.7w", "",
877           0,
878           { 0, 0, 0, 0, 0 },
879           { 0, 0, 0, 0, 0 },
880           0x14c0, 0x0012,
881           "Compal", "??? (V1)", CUT_COMPAL1400_1, "COMPAL_1400_1"
882         },
883         { SIS_650, "1.10.7x", "",
884           0,
885           { 0, 0, 0, 0, 0 },
886           { 0, 0, 0, 0, 0 },
887           0x14c0, 0x0012,
888           "Compal", "??? (V2)", CUT_COMPAL1400_2, "COMPAL_1400_2"
889         },
890         { SIS_650, "1.10.8o", "",
891           0,    /* For EMI (unknown) */
892           { 0, 0, 0, 0, 0 },
893           { 0, 0, 0, 0, 0 },
894           0x1043, 0x1612,
895           "Asus", "A2H (V1)", CUT_ASUSA2H_1, "ASUS_A2H_1"
896         },
897         { SIS_650, "1.10.8q", "",
898           0,    /* For EMI */
899           { 0, 0, 0, 0, 0 },
900           { 0, 0, 0, 0, 0 },
901           0x1043, 0x1612,
902           "Asus", "A2H (V2)", CUT_ASUSA2H_2, "ASUS_A2H_2"
903         },
904         { 4321, "", "",                 /* never autodetected */
905           0,
906           { 0, 0, 0, 0, 0 },
907           { 0, 0, 0, 0, 0 },
908           0, 0,
909           "Generic", "LVDS/Parallel 848x480", CUT_PANEL848, "PANEL848x480"
910         },
911         { 0, "", "",
912           0,
913           { 0, 0, 0, 0 },
914           { 0, 0, 0, 0 },
915           0, 0,
916           "", "", CUT_NONE, ""
917         }
918 };
919
920 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
921 /* Offscreen layout */
922 typedef struct _SIS_GLYINFO {
923         unsigned char ch;
924         int fontwidth;
925         int fontheight;
926         u8 gmask[72];
927         int ngmask;
928 } SIS_GLYINFO;
929
930 static char sisfb_fontname[40];
931 #endif
932
933 typedef struct _SIS_OH {
934         struct _SIS_OH *poh_next;
935         struct _SIS_OH *poh_prev;
936         unsigned long offset;
937         unsigned long size;
938 } SIS_OH;
939
940 typedef struct _SIS_OHALLOC {
941         struct _SIS_OHALLOC *poha_next;
942         SIS_OH aoh[1];
943 } SIS_OHALLOC;
944
945 typedef struct _SIS_HEAP {
946         SIS_OH oh_free;
947         SIS_OH oh_used;
948         SIS_OH *poh_freelist;
949         SIS_OHALLOC *poha_chain;
950         unsigned long max_freesize;
951 } SIS_HEAP;
952
953 static unsigned long sisfb_hwcursor_vbase;
954
955 static unsigned long sisfb_heap_start;
956 static unsigned long sisfb_heap_end;
957 static unsigned long sisfb_heap_size;
958 static SIS_HEAP      sisfb_heap;
959
960 static const struct _sis_TV_filter {
961         u8 filter[9][4];
962 } sis_TV_filter[] = {
963         { {{0x00,0x00,0x00,0x40},  /* NTSCFilter_0 */
964            {0x00,0xE0,0x10,0x60},
965            {0x00,0xEE,0x10,0x44},
966            {0x00,0xF4,0x10,0x38},
967            {0xF8,0xF4,0x18,0x38},
968            {0xFC,0xFB,0x14,0x2A},
969            {0x00,0x00,0x10,0x20},
970            {0x00,0x04,0x10,0x18}, 
971            {0xFF,0xFF,0xFF,0xFF} }},
972         { {{0x00,0x00,0x00,0x40},  /* NTSCFilter_1 */
973            {0x00,0xE0,0x10,0x60},
974            {0x00,0xEE,0x10,0x44},
975            {0x00,0xF4,0x10,0x38},
976            {0xF8,0xF4,0x18,0x38},
977            {0xFC,0xFB,0x14,0x2A},
978            {0x00,0x00,0x10,0x20},
979            {0x00,0x04,0x10,0x18},
980            {0xFF,0xFF,0xFF,0xFF} }},
981         { {{0x00,0x00,0x00,0x40},  /* NTSCFilter_2 */
982            {0xF5,0xEE,0x1B,0x44},
983            {0xF8,0xF4,0x18,0x38},
984            {0xEB,0x04,0x25,0x18},
985            {0xF1,0x05,0x1F,0x16},
986            {0xF6,0x06,0x1A,0x14},
987            {0xFA,0x06,0x16,0x14},
988            {0x00,0x04,0x10,0x18}, 
989            {0xFF,0xFF,0xFF,0xFF} }},
990         { {{0x00,0x00,0x00,0x40},  /* NTSCFilter_3 */
991            {0xF1,0x04,0x1F,0x18},
992            {0xEE,0x0D,0x22,0x06},
993            {0xF7,0x06,0x19,0x14},
994            {0xF4,0x0B,0x1C,0x0A},
995            {0xFA,0x07,0x16,0x12},
996            {0xF9,0x0A,0x17,0x0C},
997            {0x00,0x07,0x10,0x12}, 
998            {0xFF,0xFF,0xFF,0xFF} }},
999         { {{0x00,0x00,0x00,0x40},  /* NTSCFilter_4 - 320 */
1000            {0x00,0xE0,0x10,0x60},
1001            {0x00,0xEE,0x10,0x44},
1002            {0x00,0xF4,0x10,0x38},
1003            {0xF8,0xF4,0x18,0x38},
1004            {0xFC,0xFB,0x14,0x2A},
1005            {0x00,0x00,0x10,0x20},
1006            {0x00,0x04,0x10,0x18}, 
1007            {0xFF,0xFF,0xFF,0xFF} }},
1008         { {{0x00,0x00,0x00,0x40},  /* NTSCFilter_5 - 640 */
1009            {0xF5,0xEE,0x1B,0x44},
1010            {0xF8,0xF4,0x18,0x38},
1011            {0xEB,0x04,0x25,0x18},
1012            {0xF1,0x05,0x1F,0x16},
1013            {0xF6,0x06,0x1A,0x14},
1014            {0xFA,0x06,0x16,0x14},
1015            {0x00,0x04,0x10,0x18}, 
1016            {0xFF,0xFF,0xFF,0xFF} }},
1017         { {{0x00,0x00,0x00,0x40},  /* NTSCFilter_6 - 720 */
1018            {0xEB,0x04,0x25,0x18},
1019            {0xE7,0x0E,0x29,0x04},
1020            {0xEE,0x0C,0x22,0x08},
1021            {0xF6,0x0B,0x1A,0x0A},
1022            {0xF9,0x0A,0x17,0x0C},
1023            {0xFC,0x0A,0x14,0x0C},
1024            {0x00,0x08,0x10,0x10}, 
1025            {0xFF,0xFF,0xFF,0xFF} }},
1026         { {{0x00,0x00,0x00,0x40},  /* NTSCFilter_7 - 800 */
1027            {0xEC,0x02,0x24,0x1C},
1028            {0xF2,0x04,0x1E,0x18},
1029            {0xEB,0x15,0x25,0xF6},
1030            {0xF4,0x10,0x1C,0x00},
1031            {0xF8,0x0F,0x18,0x02},
1032            {0x00,0x04,0x10,0x18},
1033            {0x01,0x06,0x0F,0x14}, 
1034            {0xFF,0xFF,0xFF,0xFF} }},
1035         { {{0x00,0x00,0x00,0x40},  /* PALFilter_0 */
1036            {0x00,0xE0,0x10,0x60},
1037            {0x00,0xEE,0x10,0x44},
1038            {0x00,0xF4,0x10,0x38},
1039            {0xF8,0xF4,0x18,0x38},
1040            {0xFC,0xFB,0x14,0x2A},
1041            {0x00,0x00,0x10,0x20},
1042            {0x00,0x04,0x10,0x18}, 
1043            {0xFF,0xFF,0xFF,0xFF} }},
1044         { {{0x00,0x00,0x00,0x40},  /* PALFilter_1 */
1045            {0x00,0xE0,0x10,0x60},
1046            {0x00,0xEE,0x10,0x44},
1047            {0x00,0xF4,0x10,0x38},
1048            {0xF8,0xF4,0x18,0x38},
1049            {0xFC,0xFB,0x14,0x2A},
1050            {0x00,0x00,0x10,0x20},
1051            {0x00,0x04,0x10,0x18}, 
1052            {0xFF,0xFF,0xFF,0xFF} }},
1053         { {{0x00,0x00,0x00,0x40},  /* PALFilter_2 */
1054            {0xF5,0xEE,0x1B,0x44},
1055            {0xF8,0xF4,0x18,0x38},
1056            {0xF1,0xF7,0x01,0x32},
1057            {0xF5,0xFB,0x1B,0x2A},
1058            {0xF9,0xFF,0x17,0x22},
1059            {0xFB,0x01,0x15,0x1E},
1060            {0x00,0x04,0x10,0x18}, 
1061            {0xFF,0xFF,0xFF,0xFF} }},
1062         { {{0x00,0x00,0x00,0x40},  /* PALFilter_3 */
1063            {0xF5,0xFB,0x1B,0x2A},
1064            {0xEE,0xFE,0x22,0x24},
1065            {0xF3,0x00,0x1D,0x20},
1066            {0xF9,0x03,0x17,0x1A},
1067            {0xFB,0x02,0x14,0x1E},
1068            {0xFB,0x04,0x15,0x18},
1069            {0x00,0x06,0x10,0x14}, 
1070            {0xFF,0xFF,0xFF,0xFF} }},
1071         { {{0x00,0x00,0x00,0x40},  /* PALFilter_4 - 320 */
1072            {0x00,0xE0,0x10,0x60},
1073            {0x00,0xEE,0x10,0x44},
1074            {0x00,0xF4,0x10,0x38},
1075            {0xF8,0xF4,0x18,0x38},
1076            {0xFC,0xFB,0x14,0x2A},
1077            {0x00,0x00,0x10,0x20},
1078            {0x00,0x04,0x10,0x18}, 
1079            {0xFF,0xFF,0xFF,0xFF} }},
1080         { {{0x00,0x00,0x00,0x40},  /* PALFilter_5 - 640 */
1081            {0xF5,0xEE,0x1B,0x44},
1082            {0xF8,0xF4,0x18,0x38},
1083            {0xF1,0xF7,0x1F,0x32},
1084            {0xF5,0xFB,0x1B,0x2A},
1085            {0xF9,0xFF,0x17,0x22},
1086            {0xFB,0x01,0x15,0x1E},
1087            {0x00,0x04,0x10,0x18}, 
1088            {0xFF,0xFF,0xFF,0xFF} }},
1089         { {{0x00,0x00,0x00,0x40},  /* PALFilter_6 - 720 */
1090            {0xF5,0xEE,0x1B,0x2A},
1091            {0xEE,0xFE,0x22,0x24},
1092            {0xF3,0x00,0x1D,0x20},
1093            {0xF9,0x03,0x17,0x1A},
1094            {0xFB,0x02,0x14,0x1E},
1095            {0xFB,0x04,0x15,0x18},
1096            {0x00,0x06,0x10,0x14}, 
1097            {0xFF,0xFF,0xFF,0xFF} }},
1098         { {{0x00,0x00,0x00,0x40},  /* PALFilter_7 - 800 */
1099            {0xF5,0xEE,0x1B,0x44},
1100            {0xF8,0xF4,0x18,0x38},
1101            {0xFC,0xFB,0x14,0x2A},
1102            {0xEB,0x05,0x25,0x16},
1103            {0xF1,0x05,0x1F,0x16},
1104            {0xFA,0x07,0x16,0x12},
1105            {0x00,0x07,0x10,0x12}, 
1106            {0xFF,0xFF,0xFF,0xFF} }}
1107 };
1108
1109 static int           filter = -1;
1110 static unsigned char filter_tb;
1111
1112 /* ---------------------- Prototypes ------------------------- */
1113
1114 /* Interface used by the world */
1115 #ifndef MODULE
1116 int             sisfb_setup(char *options);
1117 #endif
1118
1119 /* Interface to the low level console driver */
1120 int             sisfb_init(void);
1121
1122 /* fbdev routines */
1123 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1124 static int      sisfb_get_fix(struct fb_fix_screeninfo *fix, 
1125                               int con,
1126                               struct fb_info *info);
1127 static int      sisfb_get_var(struct fb_var_screeninfo *var, 
1128                               int con,
1129                               struct fb_info *info);
1130 static int      sisfb_set_var(struct fb_var_screeninfo *var, 
1131                               int con,
1132                               struct fb_info *info);
1133 static void     sisfb_crtc_to_var(struct fb_var_screeninfo *var);                             
1134 static int      sisfb_get_cmap(struct fb_cmap *cmap, 
1135                                int kspc, 
1136                                int con,
1137                                struct fb_info *info);
1138 static int      sisfb_set_cmap(struct fb_cmap *cmap, 
1139                                int kspc, 
1140                                int con,
1141                                struct fb_info *info);                   
1142 static int      sisfb_update_var(int con, 
1143                                  struct fb_info *info);
1144 static int      sisfb_switch(int con, 
1145                              struct fb_info *info);
1146 static void     sisfb_blank(int blank, 
1147                             struct fb_info *info);
1148 static void     sisfb_set_disp(int con, 
1149                                struct fb_var_screeninfo *var, 
1150                                struct fb_info *info);
1151 static int      sis_getcolreg(unsigned regno, unsigned *red, unsigned *green,
1152                               unsigned *blue, unsigned *transp,
1153                               struct fb_info *fb_info);
1154 static void     sisfb_do_install_cmap(int con, 
1155                                       struct fb_info *info);
1156 static void     sis_get_glyph(struct fb_info *info, 
1157                               SIS_GLYINFO *gly);
1158 static int      sisfb_mmap(struct fb_info *info, struct file *file,
1159                            struct vm_area_struct *vma); 
1160 static int      sisfb_ioctl(struct inode *inode, struct file *file,
1161                             unsigned int cmd, unsigned long arg, int con,
1162                             struct fb_info *info);                    
1163 #endif                  
1164
1165 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1166 static int      sisfb_set_par(struct fb_info *info);
1167 static int      sisfb_blank(int blank, 
1168                             struct fb_info *info);                      
1169 static int      sisfb_mmap(struct fb_info *info, struct file *file,
1170                            struct vm_area_struct *vma);                     
1171 extern void     fbcon_sis_fillrect(struct fb_info *info, 
1172                                    const struct fb_fillrect *rect);
1173 extern void     fbcon_sis_copyarea(struct fb_info *info, 
1174                                    const struct fb_copyarea *area);
1175 extern int      fbcon_sis_sync(struct fb_info *info);
1176 static int      sisfb_ioctl(struct inode *inode, 
1177                             struct file *file,
1178                             unsigned int cmd, 
1179                             unsigned long arg, 
1180                             struct fb_info *info);
1181 extern int      sisfb_mode_rate_to_dclock(SiS_Private *SiS_Pr, 
1182                               PSIS_HW_INFO HwDeviceExtension,
1183                               unsigned char modeno, unsigned char rateindex);   
1184 extern int      sisfb_mode_rate_to_ddata(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceExtension,
1185                          unsigned char modeno, unsigned char rateindex,
1186                          unsigned int *left_margin, unsigned int *right_margin, 
1187                          unsigned int *upper_margin, unsigned int *lower_margin,
1188                          unsigned int *hsync_len, unsigned int *vsync_len,
1189                          unsigned int *sync, unsigned int *vmode);
1190 #endif
1191                         
1192 static int      sisfb_get_fix(struct fb_fix_screeninfo *fix, int con,
1193                               struct fb_info *info);
1194
1195 /* Internal 2D accelerator functions */
1196 extern int      sisfb_initaccel(void);
1197 extern void     sisfb_syncaccel(void);
1198
1199 /* Internal general routines */
1200 static void     sisfb_search_mode(char *name, BOOLEAN quiet);
1201 static int      sisfb_validate_mode(int modeindex, unsigned long vbflags);
1202 static u8       sisfb_search_refresh_rate(unsigned int rate, int index);
1203 static int      sisfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1204                         unsigned blue, unsigned transp,
1205                         struct fb_info *fb_info);
1206 static int      sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
1207                         struct fb_info *info);
1208 static void     sisfb_pre_setmode(void);
1209 static void     sisfb_post_setmode(void);
1210
1211 static char *   sis_find_rom(void);
1212 static BOOLEAN  sisfb_CheckVBRetrace(void);
1213 static BOOLEAN  sisfbcheckvretracecrt2(void);
1214 static BOOLEAN  sisfbcheckvretracecrt1(void);
1215 static BOOLEAN  sisfb_bridgeisslave(void);
1216 static void     sisfb_detect_VB_connect(void);
1217 static void     sisfb_get_VB_type(void);
1218
1219 static void     sisfb_handle_ddc(struct sisfb_monitor *monitor, int crtno);
1220 static BOOLEAN  sisfb_interpret_edid(struct sisfb_monitor *monitor, unsigned char *buffer);
1221
1222 /* SiS-specific Export functions */
1223 void            sis_dispinfo(struct ap_data *rec);
1224 void            sis_malloc(struct sis_memreq *req);
1225 void            sis_free(unsigned long base);
1226
1227 /* Internal hardware access routines */
1228 void            sisfb_set_reg4(u16 port, unsigned long data);
1229 u32             sisfb_get_reg3(u16 port);
1230
1231 /* Chipset-dependent internal routines */
1232 #ifdef CONFIG_FB_SIS_300
1233 static int      sisfb_get_dram_size_300(void);
1234 #endif
1235 #ifdef CONFIG_FB_SIS_315
1236 static int      sisfb_get_dram_size_315(void);
1237 #endif
1238
1239 /* Internal heap routines */
1240 static int      sisfb_heap_init(void);
1241 static SIS_OH   *sisfb_poh_new_node(void);
1242 static SIS_OH   *sisfb_poh_allocate(unsigned long size);
1243 static void     sisfb_delete_node(SIS_OH *poh);
1244 static void     sisfb_insert_node(SIS_OH *pohList, SIS_OH *poh);
1245 static SIS_OH   *sisfb_poh_free(unsigned long base);
1246 static void     sisfb_free_node(SIS_OH *poh);
1247
1248 /* Internal routines to access PCI configuration space */
1249 BOOLEAN         sisfb_query_VGA_config_space(PSIS_HW_INFO psishw_ext,
1250                         unsigned long offset, unsigned long set, unsigned long *value);
1251 BOOLEAN         sisfb_query_north_bridge_space(PSIS_HW_INFO psishw_ext,
1252                         unsigned long offset, unsigned long set, unsigned long *value);
1253
1254 /* Sensing routines */
1255 static void     SiS_Sense30x(void);
1256 static int      SISDoSense(int tempbl, int tempbh, int tempcl, int tempch);
1257 static void     SiS_SenseCh(void);
1258
1259 /* Routines from init.c/init301.c */
1260 extern USHORT   SiS_GetModeID(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth, BOOLEAN FSTN);
1261 extern USHORT   SiS_GetModeID_LCD(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth,
1262                                   BOOLEAN FSTN, USHORT CustomT, int LCDwith, int LCDheight);
1263 extern USHORT   SiS_GetModeID_TV(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth);
1264 extern USHORT   SiS_GetModeID_VGA2(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth);
1265
1266 extern void     SiSRegInit(SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr);
1267 extern BOOLEAN  SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceInfo, USHORT ModeNo);
1268 extern void     SiS_SetEnableDstn(SiS_Private *SiS_Pr, int enable);
1269 extern void     SiS_SetEnableFstn(SiS_Private *SiS_Pr, int enable);
1270
1271 extern BOOLEAN  sisfb_gettotalfrommode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceExtension,
1272                        unsigned char modeno, int *htotal, int *vtotal, unsigned char rateindex);
1273
1274 /* Chrontel TV functions */
1275 extern USHORT   SiS_GetCH700x(SiS_Private *SiS_Pr, USHORT tempbx);
1276 extern void     SiS_SetCH700x(SiS_Private *SiS_Pr, USHORT tempbx);
1277 extern USHORT   SiS_GetCH701x(SiS_Private *SiS_Pr, USHORT tempbx);
1278 extern void     SiS_SetCH701x(SiS_Private *SiS_Pr, USHORT tempbx);
1279 extern void     SiS_SetCH70xxANDOR(SiS_Private *SiS_Pr, USHORT tempax,USHORT tempbh);
1280 extern void     SiS_DDC2Delay(SiS_Private *SiS_Pr, USHORT delaytime);
1281 extern void     SiS_SetChrontelGPIO(SiS_Private *SiS_Pr, USHORT myvbinfo);
1282 extern USHORT   SiS_HandleDDC(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
1283                               USHORT adaptnum, USHORT DDCdatatype, unsigned char *buffer);
1284 extern USHORT   SiS_ReadDDC1Bit(SiS_Private *SiS_Pr);
1285 extern void     SiS_Chrontel701xBLOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceInfo);
1286 extern void     SiS_Chrontel701xBLOff(SiS_Private *SiS_Pr);
1287 extern void     SiS_SiS30xBLOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceInfo);
1288 extern void     SiS_SiS30xBLOff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwDeviceInfo);
1289
1290                         
1291 #endif