1 #ifndef _XGIFB_MAIN
2 #define _XGIFB_MAIN
3 
4 
5 /* ------------------- Constant Definitions ------------------------- */
6 
7 
8 #include "XGIfb.h"
9 #include "vb_struct.h"
10 #include "vb_def.h"
11 
12 #define XGIFAIL(x) do { printk(x "\n"); return -EINVAL; } while(0)
13 
14 #define VER_MAJOR                 0
15 #define VER_MINOR                 8
16 #define VER_LEVEL                 1
17 
18 #define DRIVER_DESC  "XGI Volari Frame Buffer Module Version 0.8.1"
19 
20 #ifndef PCI_VENDOR_ID_XG
21 #define PCI_VENDOR_ID_XG          0x18CA
22 #endif
23 
24 #ifndef PCI_DEVICE_ID_XG_40
25 #define PCI_DEVICE_ID_XG_40      0x040
26 #endif
27 #ifndef PCI_DEVICE_ID_XG_41
28 #define PCI_DEVICE_ID_XG_41      0x041
29 #endif
30 #ifndef PCI_DEVICE_ID_XG_42
31 #define PCI_DEVICE_ID_XG_42      0x042
32 #endif
33 #ifndef PCI_DEVICE_ID_XG_20
34 #define PCI_DEVICE_ID_XG_20      0x020
35 #endif
36 #ifndef PCI_DEVICE_ID_XG_27
37 #define PCI_DEVICE_ID_XG_27      0x027
38 #endif
39 
40 
41 
42 #define XGI_IOTYPE1 void __iomem
43 #define XGI_IOTYPE2 __iomem
44 #define XGIINITSTATIC static
45 
46 static DEFINE_PCI_DEVICE_TABLE(xgifb_pci_table) = {
47 	{ PCI_VENDOR_ID_XG, PCI_DEVICE_ID_XG_20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
48 	{ PCI_VENDOR_ID_XG, PCI_DEVICE_ID_XG_27, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
49 	{ PCI_VENDOR_ID_XG, PCI_DEVICE_ID_XG_40, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
50 	{ PCI_VENDOR_ID_XG, PCI_DEVICE_ID_XG_42, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
51 	{ 0 }
52 };
53 
54 MODULE_DEVICE_TABLE(pci, xgifb_pci_table);
55 
56 /* To be included in fb.h */
57 #ifndef FB_ACCEL_XGI_GLAMOUR_2
58 #define FB_ACCEL_XGI_GLAMOUR_2  40	/* XGI 315, 650, 740		*/
59 #endif
60 #ifndef FB_ACCEL_XGI_XABRE
61 #define FB_ACCEL_XGI_XABRE      41	/* XGI 330 ("Xabre")		*/
62 #endif
63 
64 #define MAX_ROM_SCAN              0x10000
65 
66 #define SEQ_ADR                   0x14
67 #define SEQ_DATA                  0x15
68 #define DAC_ADR                   0x18
69 #define DAC_DATA                  0x19
70 #define CRTC_ADR                  0x24
71 #define CRTC_DATA                 0x25
72 #define DAC2_ADR                  (0x16-0x30)
73 #define DAC2_DATA                 (0x17-0x30)
74 #define VB_PART1_ADR              (0x04-0x30)
75 #define VB_PART1_DATA             (0x05-0x30)
76 #define VB_PART2_ADR              (0x10-0x30)
77 #define VB_PART2_DATA             (0x11-0x30)
78 #define VB_PART3_ADR              (0x12-0x30)
79 #define VB_PART3_DATA             (0x13-0x30)
80 #define VB_PART4_ADR              (0x14-0x30)
81 #define VB_PART4_DATA             (0x15-0x30)
82 
83 #define XGISR			  XGI_Pr.P3c4
84 #define XGICR                     XGI_Pr.P3d4
85 #define XGIDACA                   XGI_Pr.P3c8
86 #define XGIDACD                   XGI_Pr.P3c9
87 #define XGIPART1                  XGI_Pr.Part1Port
88 #define XGIPART2                  XGI_Pr.Part2Port
89 #define XGIPART3                  XGI_Pr.Part3Port
90 #define XGIPART4                  XGI_Pr.Part4Port
91 #define XGIPART5                  XGI_Pr.Part5Port
92 #define XGIDAC2A                  XGIPART5
93 #define XGIDAC2D                  (XGIPART5 + 1)
94 #define XGIMISCR                  (XGI_Pr.RelIO + 0x1c)
95 #define XGIINPSTAT		  (XGI_Pr.RelIO + 0x2a)
96 
97 #define IND_XGI_PASSWORD          0x05  /* SRs */
98 #define IND_XGI_COLOR_MODE        0x06
99 #define IND_XGI_RAMDAC_CONTROL    0x07
100 #define IND_XGI_DRAM_SIZE         0x14
101 #define IND_XGI_SCRATCH_REG_16    0x16
102 #define IND_XGI_SCRATCH_REG_17    0x17
103 #define IND_XGI_SCRATCH_REG_1A    0x1A
104 #define IND_XGI_MODULE_ENABLE     0x1E
105 #define IND_XGI_PCI_ADDRESS_SET   0x20
106 #define IND_XGI_TURBOQUEUE_ADR    0x26
107 #define IND_XGI_TURBOQUEUE_SET    0x27
108 #define IND_XGI_POWER_ON_TRAP     0x38
109 #define IND_XGI_POWER_ON_TRAP2    0x39
110 #define IND_XGI_CMDQUEUE_SET      0x26
111 #define IND_XGI_CMDQUEUE_THRESHOLD  0x27
112 
113 #define IND_XGI_SCRATCH_REG_CR30  0x30  /* CRs */
114 #define IND_XGI_SCRATCH_REG_CR31  0x31
115 #define IND_XGI_SCRATCH_REG_CR32  0x32
116 #define IND_XGI_SCRATCH_REG_CR33  0x33
117 #define IND_XGI_LCD_PANEL         0x36
118 #define IND_XGI_SCRATCH_REG_CR37  0x37
119 #define IND_XGI_AGP_IO_PAD        0x48
120 
121 #define IND_BRI_DRAM_STATUS       0x63 /* PCI config memory size offset */
122 
123 #define MMIO_QUEUE_PHYBASE        0x85C0
124 #define MMIO_QUEUE_WRITEPORT      0x85C4
125 #define MMIO_QUEUE_READPORT       0x85C8
126 
127 #define IND_XGI_CRT2_WRITE_ENABLE_300 0x24
128 #define IND_XGI_CRT2_WRITE_ENABLE_315 0x2F
129 
130 #define XGI_PASSWORD              0x86  /* SR05 */
131 #define XGI_INTERLACED_MODE       0x20  /* SR06 */
132 #define XGI_8BPP_COLOR_MODE       0x0
133 #define XGI_15BPP_COLOR_MODE      0x1
134 #define XGI_16BPP_COLOR_MODE      0x2
135 #define XGI_32BPP_COLOR_MODE      0x4
136 
137 #define XGI_DRAM_SIZE_MASK     0xF0  /*SR14 */
138 #define XGI_DRAM_SIZE_1MB      0x00
139 #define XGI_DRAM_SIZE_2MB      0x01
140 #define XGI_DRAM_SIZE_4MB      0x02
141 #define XGI_DRAM_SIZE_8MB      0x03
142 #define XGI_DRAM_SIZE_16MB     0x04
143 #define XGI_DRAM_SIZE_32MB     0x05
144 #define XGI_DRAM_SIZE_64MB     0x06
145 #define XGI_DRAM_SIZE_128MB    0x07
146 #define XGI_DRAM_SIZE_256MB    0x08
147 #define XGI_DATA_BUS_MASK      0x02
148 #define XGI_DATA_BUS_64        0x00
149 #define XGI_DATA_BUS_128       0x01
150 #define XGI_DUAL_CHANNEL_MASK  0x0C
151 #define XGI_SINGLE_CHANNEL_1_RANK  	0x0
152 #define XGI_SINGLE_CHANNEL_2_RANK  	0x1
153 #define XGI_ASYM_DDR		  	0x02
154 #define XGI_DUAL_CHANNEL_1_RANK    	0x3
155 
156 #define XGI550_DRAM_SIZE_MASK     0x3F  /* 550/650/740 SR14 */
157 #define XGI550_DRAM_SIZE_4MB      0x00
158 #define XGI550_DRAM_SIZE_8MB      0x01
159 #define XGI550_DRAM_SIZE_16MB     0x03
160 #define XGI550_DRAM_SIZE_24MB     0x05
161 #define XGI550_DRAM_SIZE_32MB     0x07
162 #define XGI550_DRAM_SIZE_64MB     0x0F
163 #define XGI550_DRAM_SIZE_96MB     0x17
164 #define XGI550_DRAM_SIZE_128MB    0x1F
165 #define XGI550_DRAM_SIZE_256MB    0x3F
166 
167 #define XGI_SCRATCH_REG_1A_MASK   0x10
168 
169 #define XGI_ENABLE_2D             0x40  /* SR1E */
170 
171 #define XGI_MEM_MAP_IO_ENABLE     0x01  /* SR20 */
172 #define XGI_PCI_ADDR_ENABLE       0x80
173 
174 #define XGI_SIMULTANEOUS_VIEW_ENABLE  0x01  /* CR30 */
175 #define XGI_MODE_SELECT_CRT2      0x02
176 #define XGI_VB_OUTPUT_COMPOSITE   0x04
177 #define XGI_VB_OUTPUT_SVIDEO      0x08
178 #define XGI_VB_OUTPUT_SCART       0x10
179 #define XGI_VB_OUTPUT_LCD         0x20
180 #define XGI_VB_OUTPUT_CRT2        0x40
181 #define XGI_VB_OUTPUT_HIVISION    0x80
182 
183 #define XGI_VB_OUTPUT_DISABLE     0x20  /* CR31 */
184 #define XGI_DRIVER_MODE           0x40
185 
186 #define XGI_VB_COMPOSITE          0x01  /* CR32 */
187 #define XGI_VB_SVIDEO             0x02
188 #define XGI_VB_SCART              0x04
189 #define XGI_VB_LCD                0x08
190 #define XGI_VB_CRT2               0x10
191 #define XGI_CRT1                  0x20
192 #define XGI_VB_HIVISION           0x40
193 #define XGI_VB_YPBPR                0x80
194 #define XGI_VB_TV                 (XGI_VB_COMPOSITE | XGI_VB_SVIDEO | \
195                                    XGI_VB_SCART | XGI_VB_HIVISION|XGI_VB_YPBPR)
196 
197 #define XGI_EXTERNAL_CHIP_MASK    	   0x0E  /* CR37 */
198 #define XGI_EXTERNAL_CHIP_XGI301           0x01  /* in CR37 << 1 ! */
199 #define XGI_EXTERNAL_CHIP_LVDS             0x02  /* in CR37 << 1 ! */
200 #define XGI_EXTERNAL_CHIP_TRUMPION         0x03  /* in CR37 << 1 ! */
201 #define XGI_EXTERNAL_CHIP_LVDS_CHRONTEL    0x04  /* in CR37 << 1 ! */
202 #define XGI_EXTERNAL_CHIP_CHRONTEL         0x05  /* in CR37 << 1 ! */
203 #define XGI310_EXTERNAL_CHIP_LVDS          0x02  /* in CR37 << 1 ! */
204 #define XGI310_EXTERNAL_CHIP_LVDS_CHRONTEL 0x03  /* in CR37 << 1 ! */
205 
206 #define XGI_AGP_2X                0x20  /* CR48 */
207 
208 #define BRI_DRAM_SIZE_MASK        0x70  /* PCI bridge config data */
209 #define BRI_DRAM_SIZE_2MB         0x00
210 #define BRI_DRAM_SIZE_4MB         0x01
211 #define BRI_DRAM_SIZE_8MB         0x02
212 #define BRI_DRAM_SIZE_16MB        0x03
213 #define BRI_DRAM_SIZE_32MB        0x04
214 #define BRI_DRAM_SIZE_64MB        0x05
215 
216 #define SR_BUFFER_SIZE            5
217 #define CR_BUFFER_SIZE            5
218 
219 /* Useful macros */
220 #define inXGIREG(base)          inb(base)
221 #define outXGIREG(base,val)     outb(val,base)
222 #define orXGIREG(base,val)      do { \
223                                   unsigned char __Temp = inb(base); \
224                                   outXGIREG(base, __Temp | (val)); \
225                                 } while (0)
226 #define andXGIREG(base,val)     do { \
227                                   unsigned char __Temp = inb(base); \
228                                   outXGIREG(base, __Temp & (val)); \
229                                 } while (0)
230 #define inXGIIDXREG(base,idx,var)   do { \
231                                       outb(idx,base); var=inb((base)+1); \
232                                     } while (0)
233 #define outXGIIDXREG(base,idx,val)  do { \
234                                       outb(idx,base); outb((val),(base)+1); \
235                                     } while (0)
236 #define orXGIIDXREG(base,idx,val)   do { \
237                                       unsigned char __Temp; \
238                                       outb(idx,base);   \
239                                       __Temp = inb((base)+1)|(val); \
240                                       outXGIIDXREG(base,idx,__Temp); \
241                                     } while (0)
242 #define andXGIIDXREG(base,idx,and)  do { \
243                                       unsigned char __Temp; \
244                                       outb(idx,base);   \
245                                       __Temp = inb((base)+1)&(and); \
246                                       outXGIIDXREG(base,idx,__Temp); \
247                                     } while (0)
248 #define setXGIIDXREG(base,idx,and,or)   do { \
249                                           unsigned char __Temp; \
250                                           outb(idx,base);   \
251                                           __Temp = (inb((base)+1)&(and))|(or); \
252                                           outXGIIDXREG(base,idx,__Temp); \
253                                         } while (0)
254 
255 /* ------------------- Global Variables ----------------------------- */
256 
257 /* Fbcon variables */
258 static struct fb_info* fb_info;
259 
260 
261 static int    video_type = FB_TYPE_PACKED_PIXELS;
262 
263 static struct fb_var_screeninfo default_var = {
264 	.xres		= 0,
265 	.yres		= 0,
266 	.xres_virtual	= 0,
267 	.yres_virtual	= 0,
268 	.xoffset	= 0,
269 	.yoffset	= 0,
270 	.bits_per_pixel	= 0,
271 	.grayscale	= 0,
272 	.red		= {0, 8, 0},
273 	.green		= {0, 8, 0},
274 	.blue		= {0, 8, 0},
275 	.transp		= {0, 0, 0},
276 	.nonstd		= 0,
277 	.activate	= FB_ACTIVATE_NOW,
278 	.height		= -1,
279 	.width		= -1,
280 	.accel_flags	= 0,
281 	.pixclock	= 0,
282 	.left_margin	= 0,
283 	.right_margin	= 0,
284 	.upper_margin	= 0,
285 	.lower_margin	= 0,
286 	.hsync_len	= 0,
287 	.vsync_len	= 0,
288 	.sync		= 0,
289 	.vmode		= FB_VMODE_NONINTERLACED,
290 };
291 
292 static struct fb_fix_screeninfo XGIfb_fix = {
293 	.id		= "XGI",
294 	.type		= FB_TYPE_PACKED_PIXELS,
295 	.xpanstep	= 1,
296 	.ypanstep	= 1,
297 };
298 static char myid[20];
299 static u32 pseudo_palette[17];
300 
301 
302 /* display status */
303 static int XGIfb_off = 0;
304 static int XGIfb_crt1off = 0;
305 static int XGIfb_forcecrt1 = -1;
306 static int XGIfb_userom = 0;
307 //static int XGIfb_useoem = -1;
308 
309 /* global flags */
310 static int XGIfb_registered;
311 static int XGIfb_tvmode = 0;
312 static int XGIfb_pdc = 0;
313 static int enable_dstn = 0;
314 static int XGIfb_ypan = -1;
315 
316 
317 static int XGIfb_CRT2_write_enable = 0;
318 
319 static int XGIfb_crt2type = -1; /* TW: CRT2 type (for overriding autodetection) */
320 static int XGIfb_tvplug = -1; /* PR: Tv plug type (for overriding autodetection) */
321 
322 static unsigned char XGIfb_detectedpdc = 0;
323 
324 static unsigned char XGIfb_detectedlcda = 0xff;
325 
326 
327 
328 
329 /* TW: For ioctl XGIFB_GET_INFO */
330 /* XGIfb_info XGIfbinfo; */
331 
332 /* TW: Hardware extension; contains data on hardware */
333 static struct xgi_hw_device_info XGIhw_ext;
334 
335 /* TW: XGI private structure */
336 static struct vb_device_info  XGI_Pr;
337 
338 #define MD_XGI300 1
339 #define MD_XGI315 2
340 
341 /* mode table */
342 /* NOT const - will be patched for 1280x960 mode number chaos reasons */
343 static struct _XGIbios_mode {
344 	char name[15];
345 	u8 mode_no;
346 	u16 vesa_mode_no_1;  /* "XGI defined" VESA mode number */
347 	u16 vesa_mode_no_2;  /* Real VESA mode numbers */
348 	u16 xres;
349 	u16 yres;
350 	u16 bpp;
351 	u16 rate_idx;
352 	u16 cols;
353 	u16 rows;
354 	u8  chipset;
355 } XGIbios_mode[] = {
356 #define MODE_INDEX_NONE           0  /* TW: index for mode=none */
357 	{"none",         0xFF, 0x0000, 0x0000,    0,    0,  0, 0,   0,  0, MD_XGI300|MD_XGI315},  /* TW: for mode "none" */
358 	{"320x240x16",   0x56, 0x0000, 0x0000,  320,  240, 16, 1,  40, 15,           MD_XGI315},
359 	{"320x480x8",    0x5A, 0x0000, 0x0000,  320,  480,  8, 1,  40, 30,           MD_XGI315},  /* TW: FSTN */
360 	{"320x480x16",   0x5B, 0x0000, 0x0000,  320,  480, 16, 1,  40, 30,           MD_XGI315},  /* TW: FSTN */
361 	{"640x480x8",    0x2E, 0x0101, 0x0101,  640,  480,  8, 1,  80, 30, MD_XGI300|MD_XGI315},
362 	{"640x480x16",   0x44, 0x0111, 0x0111,  640,  480, 16, 1,  80, 30, MD_XGI300|MD_XGI315},
363 	{"640x480x24",   0x62, 0x013a, 0x0112,  640,  480, 32, 1,  80, 30, MD_XGI300|MD_XGI315},  /* TW: That's for people who mix up color- and fb depth */
364 	{"640x480x32",   0x62, 0x013a, 0x0112,  640,  480, 32, 1,  80, 30, MD_XGI300|MD_XGI315},
365 	{"720x480x8",    0x31, 0x0000, 0x0000,  720,  480,  8, 1,  90, 30, MD_XGI300|MD_XGI315},
366 	{"720x480x16",   0x33, 0x0000, 0x0000,  720,  480, 16, 1,  90, 30, MD_XGI300|MD_XGI315},
367 	{"720x480x24",   0x35, 0x0000, 0x0000,  720,  480, 32, 1,  90, 30, MD_XGI300|MD_XGI315},
368 	{"720x480x32",   0x35, 0x0000, 0x0000,  720,  480, 32, 1,  90, 30, MD_XGI300|MD_XGI315},
369 	{"720x576x8",    0x32, 0x0000, 0x0000,  720,  576,  8, 1,  90, 36, MD_XGI300|MD_XGI315},
370 	{"720x576x16",   0x34, 0x0000, 0x0000,  720,  576, 16, 1,  90, 36, MD_XGI300|MD_XGI315},
371 	{"720x576x24",   0x36, 0x0000, 0x0000,  720,  576, 32, 1,  90, 36, MD_XGI300|MD_XGI315},
372 	{"720x576x32",   0x36, 0x0000, 0x0000,  720,  576, 32, 1,  90, 36, MD_XGI300|MD_XGI315},
373 	{"800x480x8",    0x70, 0x0000, 0x0000,  800,  480,  8, 1, 100, 30, MD_XGI300|MD_XGI315},
374 	{"800x480x16",   0x7a, 0x0000, 0x0000,  800,  480, 16, 1, 100, 30, MD_XGI300|MD_XGI315},
375 	{"800x480x24",   0x76, 0x0000, 0x0000,  800,  480, 32, 1, 100, 30, MD_XGI300|MD_XGI315},
376 	{"800x480x32",   0x76, 0x0000, 0x0000,  800,  480, 32, 1, 100, 30, MD_XGI300|MD_XGI315},
377 #define DEFAULT_MODE              21 /* TW: index for 800x600x8 */
378 #define DEFAULT_LCDMODE           21 /* TW: index for 800x600x8 */
379 #define DEFAULT_TVMODE            21 /* TW: index for 800x600x8 */
380 	{"800x600x8",    0x30, 0x0103, 0x0103,  800,  600,  8, 1, 100, 37, MD_XGI300|MD_XGI315},
381 	{"800x600x16",   0x47, 0x0114, 0x0114,  800,  600, 16, 1, 100, 37, MD_XGI300|MD_XGI315},
382 	{"800x600x24",   0x63, 0x013b, 0x0115,  800,  600, 32, 1, 100, 37, MD_XGI300|MD_XGI315},
383 	{"800x600x32",   0x63, 0x013b, 0x0115,  800,  600, 32, 1, 100, 37, MD_XGI300|MD_XGI315},
384 	{"1024x576x8",   0x71, 0x0000, 0x0000, 1024,  576,  8, 1, 128, 36, MD_XGI300|MD_XGI315},
385 	{"1024x576x16",  0x74, 0x0000, 0x0000, 1024,  576, 16, 1, 128, 36, MD_XGI300|MD_XGI315},
386 	{"1024x576x24",  0x77, 0x0000, 0x0000, 1024,  576, 32, 1, 128, 36, MD_XGI300|MD_XGI315},
387 	{"1024x576x32",  0x77, 0x0000, 0x0000, 1024,  576, 32, 1, 128, 36, MD_XGI300|MD_XGI315},
388 	{"1024x600x8",   0x20, 0x0000, 0x0000, 1024,  600,  8, 1, 128, 37, MD_XGI300          },  /* TW: 300 series only */
389 	{"1024x600x16",  0x21, 0x0000, 0x0000, 1024,  600, 16, 1, 128, 37, MD_XGI300          },
390 	{"1024x600x24",  0x22, 0x0000, 0x0000, 1024,  600, 32, 1, 128, 37, MD_XGI300          },
391 	{"1024x600x32",  0x22, 0x0000, 0x0000, 1024,  600, 32, 1, 128, 37, MD_XGI300          },
392 	{"1024x768x8",   0x38, 0x0105, 0x0105, 1024,  768,  8, 1, 128, 48, MD_XGI300|MD_XGI315},
393 	{"1024x768x16",  0x4A, 0x0117, 0x0117, 1024,  768, 16, 1, 128, 48, MD_XGI300|MD_XGI315},
394 	{"1024x768x24",  0x64, 0x013c, 0x0118, 1024,  768, 32, 1, 128, 48, MD_XGI300|MD_XGI315},
395 	{"1024x768x32",  0x64, 0x013c, 0x0118, 1024,  768, 32, 1, 128, 48, MD_XGI300|MD_XGI315},
396 	{"1152x768x8",   0x23, 0x0000, 0x0000, 1152,  768,  8, 1, 144, 48, MD_XGI300          },  /* TW: 300 series only */
397 	{"1152x768x16",  0x24, 0x0000, 0x0000, 1152,  768, 16, 1, 144, 48, MD_XGI300          },
398 	{"1152x768x24",  0x25, 0x0000, 0x0000, 1152,  768, 32, 1, 144, 48, MD_XGI300          },
399 	{"1152x768x32",  0x25, 0x0000, 0x0000, 1152,  768, 32, 1, 144, 48, MD_XGI300          },
400 	{"1280x720x8",   0x79, 0x0000, 0x0000, 1280,  720,  8, 1, 160, 45, MD_XGI300|MD_XGI315},
401 	{"1280x720x16",  0x75, 0x0000, 0x0000, 1280,  720, 16, 1, 160, 45, MD_XGI300|MD_XGI315},
402 	{"1280x720x24",  0x78, 0x0000, 0x0000, 1280,  720, 32, 1, 160, 45, MD_XGI300|MD_XGI315},
403 	{"1280x720x32",  0x78, 0x0000, 0x0000, 1280,  720, 32, 1, 160, 45, MD_XGI300|MD_XGI315},
404 	{"1280x768x8",   0x23, 0x0000, 0x0000, 1280,  768,  8, 1, 160, 48,           MD_XGI315},  /* TW: 310/325 series only */
405 	{"1280x768x16",  0x24, 0x0000, 0x0000, 1280,  768, 16, 1, 160, 48,           MD_XGI315},
406 	{"1280x768x24",  0x25, 0x0000, 0x0000, 1280,  768, 32, 1, 160, 48,           MD_XGI315},
407 	{"1280x768x32",  0x25, 0x0000, 0x0000, 1280,  768, 32, 1, 160, 48,           MD_XGI315},
408 #define MODEINDEX_1280x960 48
409 	{"1280x960x8",   0x7C, 0x0000, 0x0000, 1280,  960,  8, 1, 160, 60, MD_XGI300|MD_XGI315},  /* TW: Modenumbers being patched */
410 	{"1280x960x16",  0x7D, 0x0000, 0x0000, 1280,  960, 16, 1, 160, 60, MD_XGI300|MD_XGI315},
411 	{"1280x960x24",  0x7E, 0x0000, 0x0000, 1280,  960, 32, 1, 160, 60, MD_XGI300|MD_XGI315},
412 	{"1280x960x32",  0x7E, 0x0000, 0x0000, 1280,  960, 32, 1, 160, 60, MD_XGI300|MD_XGI315},
413 	{"1280x1024x8",  0x3A, 0x0107, 0x0107, 1280, 1024,  8, 1, 160, 64, MD_XGI300|MD_XGI315},
414 	{"1280x1024x16", 0x4D, 0x011a, 0x011a, 1280, 1024, 16, 1, 160, 64, MD_XGI300|MD_XGI315},
415 	{"1280x1024x24", 0x65, 0x013d, 0x011b, 1280, 1024, 32, 1, 160, 64, MD_XGI300|MD_XGI315},
416 	{"1280x1024x32", 0x65, 0x013d, 0x011b, 1280, 1024, 32, 1, 160, 64, MD_XGI300|MD_XGI315},
417 	{"1400x1050x8",  0x26, 0x0000, 0x0000, 1400, 1050,  8, 1, 175, 65,           MD_XGI315},  /* TW: 310/325 series only */
418 	{"1400x1050x16", 0x27, 0x0000, 0x0000, 1400, 1050, 16, 1, 175, 65,           MD_XGI315},
419 	{"1400x1050x24", 0x28, 0x0000, 0x0000, 1400, 1050, 32, 1, 175, 65,           MD_XGI315},
420 	{"1400x1050x32", 0x28, 0x0000, 0x0000, 1400, 1050, 32, 1, 175, 65,           MD_XGI315},
421 	{"1600x1200x8",  0x3C, 0x0130, 0x011c, 1600, 1200,  8, 1, 200, 75, MD_XGI300|MD_XGI315},
422 	{"1600x1200x16", 0x3D, 0x0131, 0x011e, 1600, 1200, 16, 1, 200, 75, MD_XGI300|MD_XGI315},
423 	{"1600x1200x24", 0x66, 0x013e, 0x011f, 1600, 1200, 32, 1, 200, 75, MD_XGI300|MD_XGI315},
424 	{"1600x1200x32", 0x66, 0x013e, 0x011f, 1600, 1200, 32, 1, 200, 75, MD_XGI300|MD_XGI315},
425 	{"1920x1440x8",  0x68, 0x013f, 0x0000, 1920, 1440,  8, 1, 240, 75, MD_XGI300|MD_XGI315},
426 	{"1920x1440x16", 0x69, 0x0140, 0x0000, 1920, 1440, 16, 1, 240, 75, MD_XGI300|MD_XGI315},
427 	{"1920x1440x24", 0x6B, 0x0141, 0x0000, 1920, 1440, 32, 1, 240, 75, MD_XGI300|MD_XGI315},
428 	{"1920x1440x32", 0x6B, 0x0141, 0x0000, 1920, 1440, 32, 1, 240, 75, MD_XGI300|MD_XGI315},
429 	{"2048x1536x8",  0x6c, 0x0000, 0x0000, 2048, 1536,  8, 1, 256, 96,           MD_XGI315},  /* TW: 310/325 series only */
430 	{"2048x1536x16", 0x6d, 0x0000, 0x0000, 2048, 1536, 16, 1, 256, 96,           MD_XGI315},
431 	{"2048x1536x24", 0x6e, 0x0000, 0x0000, 2048, 1536, 32, 1, 256, 96,           MD_XGI315},
432 	{"2048x1536x32", 0x6e, 0x0000, 0x0000, 2048, 1536, 32, 1, 256, 96,           MD_XGI315},
433 	{"\0", 0x00, 0, 0, 0, 0, 0, 0, 0}
434 };
435 
436 /* mode-related variables */
437 #ifdef MODULE
438 static int xgifb_mode_idx = 1;
439 #else
440 static int xgifb_mode_idx = -1;               /* Use a default mode if we are inside the kernel */
441 #endif
442 static u8  XGIfb_mode_no  = 0;
443 static u8  XGIfb_rate_idx = 0;
444 
445 /* TW: CR36 evaluation */
446 static const unsigned short XGI300paneltype[] =
447     { LCD_UNKNOWN,   LCD_800x600,  LCD_1024x768,  LCD_1280x1024,
448       LCD_1280x960,  LCD_640x480,  LCD_1024x600,  LCD_1152x768,
449        LCD_1024x768, LCD_1024x768,  LCD_1024x768,
450       LCD_1024x768,  LCD_1024x768, LCD_1024x768,  LCD_1024x768 };
451 
452 static const unsigned short XGI310paneltype[] =
453     { LCD_UNKNOWN,   LCD_800x600,  LCD_1024x768,  LCD_1280x1024,
454       LCD_640x480,   LCD_1024x600, LCD_1152x864,  LCD_1280x960,
455       LCD_1152x768,  LCD_1400x1050,LCD_1280x768,  LCD_1600x1200,
456       LCD_1024x768, LCD_1024x768,  LCD_1024x768 };
457 
458 static const struct _XGI_crt2type {
459 	char name[10];
460 	int type_no;
461 	int tvplug_no;
462 } XGI_crt2type[] = {
463 	{"NONE", 	0, 		-1},
464 	{"LCD",  	DISPTYPE_LCD, 	-1},
465 	{"TV",   	DISPTYPE_TV, 	-1},
466 	{"VGA",  	DISPTYPE_CRT2, 	-1},
467 	{"SVIDEO", 	DISPTYPE_TV, 	TVPLUG_SVIDEO},
468 	{"COMPOSITE", 	DISPTYPE_TV, 	TVPLUG_COMPOSITE},
469 	{"SCART", 	DISPTYPE_TV, 	TVPLUG_SCART},
470 	{"none", 	0, 		-1},
471 	{"lcd",  	DISPTYPE_LCD, 	-1},
472 	{"tv",   	DISPTYPE_TV, 	-1},
473 	{"vga",  	DISPTYPE_CRT2, 	-1},
474 	{"svideo", 	DISPTYPE_TV, 	TVPLUG_SVIDEO},
475 	{"composite", 	DISPTYPE_TV, 	TVPLUG_COMPOSITE},
476 	{"scart", 	DISPTYPE_TV, 	TVPLUG_SCART},
477 	{"\0",  	-1, 		-1}
478 };
479 
480 /* TV standard */
481 static const struct _XGI_tvtype {
482 	char name[6];
483 	int type_no;
484 } XGI_tvtype[] = {
485 	{"PAL",  	1},
486 	{"NTSC", 	2},
487 	{"pal", 	1},
488 	{"ntsc",  	2},
489 	{"\0",   	-1}
490 };
491 
492 static const struct _XGI_vrate {
493 	u16 idx;
494 	u16 xres;
495 	u16 yres;
496 	u16 refresh;
497 } XGIfb_vrate[] = {
498 	{1,  640,  480, 60}, {2,  640,  480,  72}, {3, 640,   480,  75}, {4,  640, 480,  85},
499 	{5,  640,  480,100}, {6,  640,  480, 120}, {7, 640,   480, 160}, {8,  640, 480, 200},
500 	{1,  720,  480, 60},
501 	{1,  720,  576, 58},
502 	{1,  800,  480, 60}, {2,  800,  480,  75}, {3, 800,   480,  85},
503         {1,  800,  600,  60}, {2, 800,   600,  72}, {3,  800, 600,  75},
504 	{4,  800,  600, 85}, {5,  800,  600, 100}, {6, 800,   600, 120}, {7,  800, 600, 160},
505 	{1, 1024,  768,  60}, {2, 1024,  768,  70}, {3, 1024, 768,  75},
506 	{4, 1024,  768, 85}, {5, 1024,  768, 100}, {6, 1024,  768, 120},
507 	{1, 1024,  576, 60}, {2, 1024,  576,  75}, {3, 1024,  576,  85},
508 	{1, 1024,  600, 60},
509 	{1, 1152,  768, 60},
510 	{1, 1280,  720, 60}, {2, 1280,  720,  75}, {3, 1280,  720,  85},
511 	{1, 1280,  768, 60},
512         {1, 1280, 1024,  60}, {2, 1280, 1024,  75}, {3, 1280, 1024,  85},
513 	{1, 1280,  960, 70},
514 	{1, 1400, 1050, 60},
515 	{1, 1600, 1200, 60}, {2, 1600, 1200,  65}, {3, 1600, 1200,  70}, {4, 1600, 1200,  75},
516 	{5, 1600, 1200, 85}, {6, 1600, 1200, 100}, {7, 1600, 1200, 120},
517 	{1, 1920, 1440, 60}, {2, 1920, 1440,  65}, {3, 1920, 1440,  70}, {4, 1920, 1440,  75},
518 	{5, 1920, 1440, 85}, {6, 1920, 1440, 100},
519 	{1, 2048, 1536, 60}, {2, 2048, 1536,  65}, {3, 2048, 1536,  70}, {4, 2048, 1536,  75},
520 	{5, 2048, 1536, 85},
521 	{0, 0, 0, 0}
522 };
523 
524 static const struct _chswtable {
525     int subsysVendor;
526     int subsysCard;
527     char *vendorName;
528     char *cardName;
529 } mychswtable[] = {
530         { 0x1631, 0x1002, "Mitachi", "0x1002" },
531 	{ 0,      0,      ""       , ""       }
532 };
533 
534 // Eden Chen
535 static const struct _XGI_TV_filter {
536 	u8 filter[9][4];
537 } XGI_TV_filter[] = {
538 	{ {{0x00,0x00,0x00,0x40},  /* NTSCFilter_0 */
539 	   {0x00,0xE0,0x10,0x60},
540 	   {0x00,0xEE,0x10,0x44},
541 	   {0x00,0xF4,0x10,0x38},
542 	   {0xF8,0xF4,0x18,0x38},
543 	   {0xFC,0xFB,0x14,0x2A},
544 	   {0x00,0x00,0x10,0x20},
545 	   {0x00,0x04,0x10,0x18},
546 	   {0xFF,0xFF,0xFF,0xFF} }},
547 	{ {{0x00,0x00,0x00,0x40},  /* NTSCFilter_1 */
548 	   {0x00,0xE0,0x10,0x60},
549 	   {0x00,0xEE,0x10,0x44},
550 	   {0x00,0xF4,0x10,0x38},
551 	   {0xF8,0xF4,0x18,0x38},
552 	   {0xFC,0xFB,0x14,0x2A},
553 	   {0x00,0x00,0x10,0x20},
554 	   {0x00,0x04,0x10,0x18},
555 	   {0xFF,0xFF,0xFF,0xFF} }},
556 	{ {{0x00,0x00,0x00,0x40},  /* NTSCFilter_2 */
557 	   {0xF5,0xEE,0x1B,0x44},
558 	   {0xF8,0xF4,0x18,0x38},
559 	   {0xEB,0x04,0x25,0x18},
560 	   {0xF1,0x05,0x1F,0x16},
561 	   {0xF6,0x06,0x1A,0x14},
562 	   {0xFA,0x06,0x16,0x14},
563 	   {0x00,0x04,0x10,0x18},
564 	   {0xFF,0xFF,0xFF,0xFF} }},
565 	{ {{0x00,0x00,0x00,0x40},  /* NTSCFilter_3 */
566 	   {0xF1,0x04,0x1F,0x18},
567 	   {0xEE,0x0D,0x22,0x06},
568 	   {0xF7,0x06,0x19,0x14},
569 	   {0xF4,0x0B,0x1C,0x0A},
570 	   {0xFA,0x07,0x16,0x12},
571 	   {0xF9,0x0A,0x17,0x0C},
572 	   {0x00,0x07,0x10,0x12},
573 	   {0xFF,0xFF,0xFF,0xFF} }},
574 	{ {{0x00,0x00,0x00,0x40},  /* NTSCFilter_4 */
575 	   {0x00,0xE0,0x10,0x60},
576 	   {0x00,0xEE,0x10,0x44},
577 	   {0x00,0xF4,0x10,0x38},
578 	   {0xF8,0xF4,0x18,0x38},
579 	   {0xFC,0xFB,0x14,0x2A},
580 	   {0x00,0x00,0x10,0x20},
581 	   {0x00,0x04,0x10,0x18},
582 	   {0xFF,0xFF,0xFF,0xFF} }},
583 	{ {{0x00,0x00,0x00,0x40},  /* NTSCFilter_5 */
584 	   {0xF5,0xEE,0x1B,0x44},
585 	   {0xF8,0xF4,0x18,0x38},
586 	   {0xEB,0x04,0x25,0x18},
587 	   {0xF1,0x05,0x1F,0x16},
588 	   {0xF6,0x06,0x1A,0x14},
589 	   {0xFA,0x06,0x16,0x14},
590 	   {0x00,0x04,0x10,0x18},
591 	   {0xFF,0xFF,0xFF,0xFF} }},
592 	{ {{0x00,0x00,0x00,0x40},  /* NTSCFilter_6 */
593 	   {0xEB,0x04,0x25,0x18},
594 	   {0xE7,0x0E,0x29,0x04},
595 	   {0xEE,0x0C,0x22,0x08},
596 	   {0xF6,0x0B,0x1A,0x0A},
597 	   {0xF9,0x0A,0x17,0x0C},
598 	   {0xFC,0x0A,0x14,0x0C},
599 	   {0x00,0x08,0x10,0x10},
600 	   {0xFF,0xFF,0xFF,0xFF} }},
601 	{ {{0x00,0x00,0x00,0x40},  /* NTSCFilter_7 */
602 	   {0xEC,0x02,0x24,0x1C},
603 	   {0xF2,0x04,0x1E,0x18},
604 	   {0xEB,0x15,0x25,0xF6},
605 	   {0xF4,0x10,0x1C,0x00},
606 	   {0xF8,0x0F,0x18,0x02},
607 	   {0x00,0x04,0x10,0x18},
608 	   {0x01,0x06,0x0F,0x14},
609 	   {0xFF,0xFF,0xFF,0xFF} }},
610 	{ {{0x00,0x00,0x00,0x40},  /* PALFilter_0 */
611 	   {0x00,0xE0,0x10,0x60},
612 	   {0x00,0xEE,0x10,0x44},
613 	   {0x00,0xF4,0x10,0x38},
614 	   {0xF8,0xF4,0x18,0x38},
615 	   {0xFC,0xFB,0x14,0x2A},
616 	   {0x00,0x00,0x10,0x20},
617 	   {0x00,0x04,0x10,0x18},
618 	   {0xFF,0xFF,0xFF,0xFF} }},
619 	{ {{0x00,0x00,0x00,0x40},  /* PALFilter_1 */
620 	   {0x00,0xE0,0x10,0x60},
621 	   {0x00,0xEE,0x10,0x44},
622 	   {0x00,0xF4,0x10,0x38},
623 	   {0xF8,0xF4,0x18,0x38},
624 	   {0xFC,0xFB,0x14,0x2A},
625 	   {0x00,0x00,0x10,0x20},
626 	   {0x00,0x04,0x10,0x18},
627 	   {0xFF,0xFF,0xFF,0xFF} }},
628 	{ {{0x00,0x00,0x00,0x40},  /* PALFilter_2 */
629 	   {0xF5,0xEE,0x1B,0x44},
630 	   {0xF8,0xF4,0x18,0x38},
631 	   {0xF1,0xF7,0x01,0x32},
632 	   {0xF5,0xFB,0x1B,0x2A},
633 	   {0xF9,0xFF,0x17,0x22},
634 	   {0xFB,0x01,0x15,0x1E},
635 	   {0x00,0x04,0x10,0x18},
636 	   {0xFF,0xFF,0xFF,0xFF} }},
637 	{ {{0x00,0x00,0x00,0x40},  /* PALFilter_3 */
638 	   {0xF5,0xFB,0x1B,0x2A},
639 	   {0xEE,0xFE,0x22,0x24},
640 	   {0xF3,0x00,0x1D,0x20},
641 	   {0xF9,0x03,0x17,0x1A},
642 	   {0xFB,0x02,0x14,0x1E},
643 	   {0xFB,0x04,0x15,0x18},
644 	   {0x00,0x06,0x10,0x14},
645 	   {0xFF,0xFF,0xFF,0xFF} }},
646 	{ {{0x00,0x00,0x00,0x40},  /* PALFilter_4 */
647 	   {0x00,0xE0,0x10,0x60},
648 	   {0x00,0xEE,0x10,0x44},
649 	   {0x00,0xF4,0x10,0x38},
650 	   {0xF8,0xF4,0x18,0x38},
651 	   {0xFC,0xFB,0x14,0x2A},
652 	   {0x00,0x00,0x10,0x20},
653 	   {0x00,0x04,0x10,0x18},
654 	   {0xFF,0xFF,0xFF,0xFF} }},
655 	{ {{0x00,0x00,0x00,0x40},  /* PALFilter_5 */
656 	   {0xF5,0xEE,0x1B,0x44},
657 	   {0xF8,0xF4,0x18,0x38},
658 	   {0xF1,0xF7,0x1F,0x32},
659 	   {0xF5,0xFB,0x1B,0x2A},
660 	   {0xF9,0xFF,0x17,0x22},
661 	   {0xFB,0x01,0x15,0x1E},
662 	   {0x00,0x04,0x10,0x18},
663 	   {0xFF,0xFF,0xFF,0xFF} }},
664 	{ {{0x00,0x00,0x00,0x40},  /* PALFilter_6 */
665 	   {0xF5,0xEE,0x1B,0x2A},
666 	   {0xEE,0xFE,0x22,0x24},
667 	   {0xF3,0x00,0x1D,0x20},
668 	   {0xF9,0x03,0x17,0x1A},
669 	   {0xFB,0x02,0x14,0x1E},
670 	   {0xFB,0x04,0x15,0x18},
671 	   {0x00,0x06,0x10,0x14},
672 	   {0xFF,0xFF,0xFF,0xFF} }},
673 	{ {{0x00,0x00,0x00,0x40},  /* PALFilter_7 */
674 	   {0xF5,0xEE,0x1B,0x44},
675 	   {0xF8,0xF4,0x18,0x38},
676 	   {0xFC,0xFB,0x14,0x2A},
677 	   {0xEB,0x05,0x25,0x16},
678 	   {0xF1,0x05,0x1F,0x16},
679 	   {0xFA,0x07,0x16,0x12},
680 	   {0x00,0x07,0x10,0x12},
681 	   {0xFF,0xFF,0xFF,0xFF} }}
682 };
683 
684 static int           filter = -1;
685 static unsigned char filter_tb;
686 
687 
688 /* ---------------------- Routine prototypes ------------------------- */
689 
690 /* Interface used by the world */
691 #ifndef MODULE
692 XGIINITSTATIC int __init XGIfb_setup(char *options);
693 #endif
694 
695 /* Interface to the low level console driver */
696 
697 
698 
699 /* fbdev routines */
700 XGIINITSTATIC int __init xgifb_init(void);
701 static int      XGIfb_set_par(struct fb_info *info);
702 static int      XGIfb_blank(int blank,
703                             struct fb_info *info);
704 /*static int 	XGIfb_mmap(struct fb_info *info, struct file *file,
705 		           struct vm_area_struct *vma);
706 */
707 
708 /*
709 extern int	XGIfb_mode_rate_to_dclock(VB_DEVICE_INFO *XGI_Pr,
710 			      struct xgi_hw_device_info *HwDeviceExtension,
711 			      unsigned char modeno, unsigned char rateindex);
712 extern int      XGIfb_mode_rate_to_ddata(VB_DEVICE_INFO *XGI_Pr, struct xgi_hw_device_info *HwDeviceExtension,
713 			 unsigned char modeno, unsigned char rateindex,
714 			 unsigned int *left_margin, unsigned int *right_margin,
715 			 unsigned int *upper_margin, unsigned int *lower_margin,
716 			 unsigned int *hsync_len, unsigned int *vsync_len,
717 			 unsigned int *sync, unsigned int *vmode);
718 */
719 extern unsigned char XGI_SearchModeID(unsigned short ModeNo,
720 				unsigned short *ModeIdIndex,
721 				struct vb_device_info *);
722 static int      XGIfb_get_fix(struct fb_fix_screeninfo *fix, int con,
723 			      struct fb_info *info);
724 
725 /* Internal general routines */
726 static void     XGIfb_search_mode(const char *name);
727 static int      XGIfb_validate_mode(int modeindex);
728 static u8       XGIfb_search_refresh_rate(unsigned int rate);
729 static int      XGIfb_setcolreg(unsigned regno, unsigned red, unsigned green,
730 			unsigned blue, unsigned transp,
731 			struct fb_info *fb_info);
732 static int      XGIfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
733 		      	struct fb_info *info);
734 static void     XGIfb_pre_setmode(void);
735 static void     XGIfb_post_setmode(void);
736 
737 /* Internal hardware access routines */
738 void            XGIfb_set_reg4(u16 port, unsigned long data);
739 u32             XGIfb_get_reg3(u16 port);
740 
741 /* Chipset-dependent internal routines */
742 
743 
744 static int      XGIfb_get_dram_size(void);
745 static void     XGIfb_detect_VB(void);
746 static void     XGIfb_get_VB_type(void);
747 static int      XGIfb_has_VB(void);
748 
749 
750 /* Internal routines to access PCI configuration space */
751 unsigned char XGIfb_query_VGA_config_space(struct xgi_hw_device_info *pXGIhw_ext,
752 					   unsigned long offset,
753 					   unsigned long set,
754 					   unsigned long *value);
755 //BOOLEAN         XGIfb_query_north_bridge_space(PXGI_HW_DEVICE_INFO pXGIhw_ext,
756 //	         	unsigned long offset, unsigned long set, unsigned long *value);
757 
758 
759 /* Routines from init.c/init301.c */
760 extern void     InitTo330Pointer(unsigned char, struct vb_device_info *pVBInfo);
761 extern unsigned char  XGIInitNew(struct xgi_hw_device_info *HwDeviceExtension);
762 extern unsigned char XGISetModeNew(struct xgi_hw_device_info *HwDeviceExtension,
763 				   unsigned short ModeNo);
764 //extern void     XGI_SetEnableDstn(VB_DEVICE_INFO *XGI_Pr);
765 extern void     XGI_LongWait(struct vb_device_info *XGI_Pr);
766 extern unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
767 					 unsigned short ModeNo,
768 					 unsigned short ModeIdIndex,
769 					 struct vb_device_info *pVBInfo);
770 /* TW: Chrontel TV functions */
771 extern unsigned short XGI_GetCH700x(struct vb_device_info *XGI_Pr,
772 				    unsigned short tempbx);
773 extern void XGI_SetCH700x(struct vb_device_info *XGI_Pr, unsigned short tempbx);
774 extern unsigned short XGI_GetCH701x(struct vb_device_info *XGI_Pr,
775 				    unsigned short tempbx);
776 extern void XGI_SetCH701x(struct vb_device_info *XGI_Pr, unsigned short tempbx);
777 extern void XGI_SetCH70xxANDOR(struct vb_device_info *XGI_Pr,
778 			       unsigned short tempax,
779 			       unsigned short tempbh);
780 extern void XGI_DDC2Delay(struct vb_device_info *XGI_Pr, unsigned short delaytime);
781 
782 /* TW: Sensing routines */
783 void            XGI_Sense30x(void);
784 int             XGIDoSense(int tempbl, int tempbh, int tempcl, int tempch);
785 
786 extern struct XGI21_LVDSCapStruct XGI21_LCDCapList[13];
787 #endif
788