blob: a96ac43921732c37c1ff1bb62e1c04955b7b70e1 [file] [log] [blame]
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001/*
2 * linux/drivers/video/s3fb.c -- Frame buffer device driver for S3 Trio/Virge
3 *
4 * Copyright (c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive for
8 * more details.
9 *
10 * Code is based on David Boucher's viafb (http://davesdomain.org.uk/viafb/)
11 * which is based on the code of neofb.
12 */
13
14#include <linux/version.h>
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/errno.h>
18#include <linux/string.h>
19#include <linux/mm.h>
20#include <linux/tty.h>
21#include <linux/slab.h>
22#include <linux/delay.h>
23#include <linux/fb.h>
24#include <linux/svga.h>
25#include <linux/init.h>
26#include <linux/pci.h>
27#include <linux/console.h> /* Why should fb driver call console functions? because acquire_console_sem() */
28#include <video/vga.h>
29
30#ifdef CONFIG_MTRR
31#include <asm/mtrr.h>
32#endif
33
34struct s3fb_info {
35 int chip, rev, mclk_freq;
36 int mtrr_reg;
37 struct vgastate state;
38 struct mutex open_lock;
39 unsigned int ref_count;
40 u32 pseudo_palette[16];
41};
42
43
44/* ------------------------------------------------------------------------- */
45
46static const struct svga_fb_format s3fb_formats[] = {
47 { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
48 FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 16},
49 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
50 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16},
51 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1,
52 FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16},
53 { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
54 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 4, 8},
55 {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
56 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
57 {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
58 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
59 {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
60 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2},
61 {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
62 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2},
63 SVGA_FORMAT_END
64};
65
66
67static const struct svga_pll s3_pll = {3, 129, 3, 33, 0, 3,
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -070068 35000, 240000, 14318};
Ondrej Zajiceka2684222007-02-12 00:54:49 -080069
70static const int s3_memsizes[] = {4096, 0, 3072, 8192, 2048, 6144, 1024, 512};
71
72static const char * const s3_names[] = {"S3 Unknown", "S3 Trio32", "S3 Trio64", "S3 Trio64V+",
73 "S3 Trio64UV+", "S3 Trio64V2/DX", "S3 Trio64V2/GX",
74 "S3 Plato/PX", "S3 Aurora64VP", "S3 Virge",
75 "S3 Virge/VX", "S3 Virge/DX", "S3 Virge/GX",
76 "S3 Virge/GX2", "S3 Virge/GX2P", "S3 Virge/GX2P"};
77
78#define CHIP_UNKNOWN 0x00
79#define CHIP_732_TRIO32 0x01
80#define CHIP_764_TRIO64 0x02
81#define CHIP_765_TRIO64VP 0x03
82#define CHIP_767_TRIO64UVP 0x04
83#define CHIP_775_TRIO64V2_DX 0x05
84#define CHIP_785_TRIO64V2_GX 0x06
85#define CHIP_551_PLATO_PX 0x07
86#define CHIP_M65_AURORA64VP 0x08
87#define CHIP_325_VIRGE 0x09
88#define CHIP_988_VIRGE_VX 0x0A
89#define CHIP_375_VIRGE_DX 0x0B
90#define CHIP_385_VIRGE_GX 0x0C
91#define CHIP_356_VIRGE_GX2 0x0D
92#define CHIP_357_VIRGE_GX2P 0x0E
93#define CHIP_359_VIRGE_GX2P 0x0F
94
95#define CHIP_XXX_TRIO 0x80
96#define CHIP_XXX_TRIO64V2_DXGX 0x81
97#define CHIP_XXX_VIRGE_DXGX 0x82
98
99#define CHIP_UNDECIDED_FLAG 0x80
100#define CHIP_MASK 0xFF
101
102/* CRT timing register sets */
103
104static const struct vga_regset s3_h_total_regs[] = {{0x00, 0, 7}, {0x5D, 0, 0}, VGA_REGSET_END};
105static const struct vga_regset s3_h_display_regs[] = {{0x01, 0, 7}, {0x5D, 1, 1}, VGA_REGSET_END};
106static const struct vga_regset s3_h_blank_start_regs[] = {{0x02, 0, 7}, {0x5D, 2, 2}, VGA_REGSET_END};
107static const struct vga_regset s3_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7}, VGA_REGSET_END};
108static const struct vga_regset s3_h_sync_start_regs[] = {{0x04, 0, 7}, {0x5D, 4, 4}, VGA_REGSET_END};
109static const struct vga_regset s3_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
110
111static const struct vga_regset s3_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x5E, 0, 0}, VGA_REGSET_END};
112static const struct vga_regset s3_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x5E, 1, 1}, VGA_REGSET_END};
113static const struct vga_regset s3_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x5E, 2, 2}, VGA_REGSET_END};
114static const struct vga_regset s3_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
115static const struct vga_regset s3_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x5E, 4, 4}, VGA_REGSET_END};
116static const struct vga_regset s3_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
117
118static const struct vga_regset s3_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, {0x5E, 6, 6}, VGA_REGSET_END};
119static const struct vga_regset s3_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x31, 4, 5}, {0x51, 0, 1}, VGA_REGSET_END};
120static const struct vga_regset s3_offset_regs[] = {{0x13, 0, 7}, {0x51, 4, 5}, VGA_REGSET_END}; /* set 0x43 bit 2 to 0 */
121
122static const struct svga_timing_regs s3_timing_regs = {
123 s3_h_total_regs, s3_h_display_regs, s3_h_blank_start_regs,
124 s3_h_blank_end_regs, s3_h_sync_start_regs, s3_h_sync_end_regs,
125 s3_v_total_regs, s3_v_display_regs, s3_v_blank_start_regs,
126 s3_v_blank_end_regs, s3_v_sync_start_regs, s3_v_sync_end_regs,
127};
128
129
130/* ------------------------------------------------------------------------- */
131
132/* Module parameters */
133
134
135static char *mode = "640x480-8@60";
136
137#ifdef CONFIG_MTRR
138static int mtrr = 1;
139#endif
140
141static int fasttext = 1;
142
143
144MODULE_AUTHOR("(c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>");
145MODULE_LICENSE("GPL");
146MODULE_DESCRIPTION("fbdev driver for S3 Trio/Virge");
147
148module_param(mode, charp, 0444);
149MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc)");
150
151#ifdef CONFIG_MTRR
152module_param(mtrr, int, 0444);
153MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
154#endif
155
156module_param(fasttext, int, 0644);
157MODULE_PARM_DESC(fasttext, "Enable S3 fast text mode (1=enable, 0=disable, default=1)");
158
159
160/* ------------------------------------------------------------------------- */
161
162/* Set font in S3 fast text mode */
163
164static void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map)
165{
166 const u8 *font = map->data;
Antonino A. Daplas75814d82007-05-08 00:38:49 -0700167 u8 __iomem *fb = (u8 __iomem *) info->screen_base;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800168 int i, c;
169
170 if ((map->width != 8) || (map->height != 16) ||
171 (map->depth != 1) || (map->length != 256)) {
172 printk(KERN_ERR "fb%d: unsupported font parameters: width %d, height %d, depth %d, length %d\n",
173 info->node, map->width, map->height, map->depth, map->length);
174 return;
175 }
176
177 fb += 2;
178 for (i = 0; i < map->height; i++) {
179 for (c = 0; c < map->length; c++) {
Antonino A. Daplas75814d82007-05-08 00:38:49 -0700180 fb_writeb(font[c * map->height + i], fb + c * 4);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800181 }
182 fb += 1024;
183 }
184}
185
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800186static struct fb_tile_ops s3fb_tile_ops = {
187 .fb_settile = svga_settile,
188 .fb_tilecopy = svga_tilecopy,
189 .fb_tilefill = svga_tilefill,
190 .fb_tileblit = svga_tileblit,
191 .fb_tilecursor = svga_tilecursor,
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700192 .fb_get_tilemax = svga_get_tilemax,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800193};
194
195static struct fb_tile_ops s3fb_fast_tile_ops = {
196 .fb_settile = s3fb_settile_fast,
197 .fb_tilecopy = svga_tilecopy,
198 .fb_tilefill = svga_tilefill,
199 .fb_tileblit = svga_tileblit,
200 .fb_tilecursor = svga_tilecursor,
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700201 .fb_get_tilemax = svga_get_tilemax,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800202};
203
204
205/* ------------------------------------------------------------------------- */
206
207/* image data is MSB-first, fb structure is MSB-first too */
208static inline u32 expand_color(u32 c)
209{
210 return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
211}
212
213/* s3fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
214static void s3fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
215{
216 u32 fg = expand_color(image->fg_color);
217 u32 bg = expand_color(image->bg_color);
218 const u8 *src1, *src;
219 u8 __iomem *dst1;
220 u32 __iomem *dst;
221 u32 val;
222 int x, y;
223
224 src1 = image->data;
225 dst1 = info->screen_base + (image->dy * info->fix.line_length)
226 + ((image->dx / 8) * 4);
227
228 for (y = 0; y < image->height; y++) {
229 src = src1;
230 dst = (u32 __iomem *) dst1;
231 for (x = 0; x < image->width; x += 8) {
232 val = *(src++) * 0x01010101;
233 val = (val & fg) | (~val & bg);
234 fb_writel(val, dst++);
235 }
236 src1 += image->width / 8;
237 dst1 += info->fix.line_length;
238 }
239
240}
241
242/* s3fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
243static void s3fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
244{
245 u32 fg = expand_color(rect->color);
246 u8 __iomem *dst1;
247 u32 __iomem *dst;
248 int x, y;
249
250 dst1 = info->screen_base + (rect->dy * info->fix.line_length)
251 + ((rect->dx / 8) * 4);
252
253 for (y = 0; y < rect->height; y++) {
254 dst = (u32 __iomem *) dst1;
255 for (x = 0; x < rect->width; x += 8) {
256 fb_writel(fg, dst++);
257 }
258 dst1 += info->fix.line_length;
259 }
260}
261
262
263/* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
264static inline u32 expand_pixel(u32 c)
265{
266 return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
267 ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
268}
269
270/* s3fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
271static void s3fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
272{
273 u32 fg = image->fg_color * 0x11111111;
274 u32 bg = image->bg_color * 0x11111111;
275 const u8 *src1, *src;
276 u8 __iomem *dst1;
277 u32 __iomem *dst;
278 u32 val;
279 int x, y;
280
281 src1 = image->data;
282 dst1 = info->screen_base + (image->dy * info->fix.line_length)
283 + ((image->dx / 8) * 4);
284
285 for (y = 0; y < image->height; y++) {
286 src = src1;
287 dst = (u32 __iomem *) dst1;
288 for (x = 0; x < image->width; x += 8) {
289 val = expand_pixel(*(src++));
290 val = (val & fg) | (~val & bg);
291 fb_writel(val, dst++);
292 }
293 src1 += image->width / 8;
294 dst1 += info->fix.line_length;
295 }
296}
297
298static void s3fb_imageblit(struct fb_info *info, const struct fb_image *image)
299{
300 if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
301 && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
302 if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
303 s3fb_iplan_imageblit(info, image);
304 else
305 s3fb_cfb4_imageblit(info, image);
306 } else
307 cfb_imageblit(info, image);
308}
309
310static void s3fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
311{
312 if ((info->var.bits_per_pixel == 4)
313 && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
314 && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
315 s3fb_iplan_fillrect(info, rect);
316 else
317 cfb_fillrect(info, rect);
318}
319
320
321
322/* ------------------------------------------------------------------------- */
323
324
325static void s3_set_pixclock(struct fb_info *info, u32 pixclock)
326{
327 u16 m, n, r;
328 u8 regval;
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700329 int rv;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800330
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700331 rv = svga_compute_pll(&s3_pll, 1000000000 / pixclock, &m, &n, &r, info->node);
332 if (rv < 0) {
333 printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node);
334 return;
335 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800336
337 /* Set VGA misc register */
338 regval = vga_r(NULL, VGA_MIS_R);
339 vga_w(NULL, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
340
341 /* Set S3 clock registers */
342 vga_wseq(NULL, 0x12, ((n - 2) | (r << 5)));
343 vga_wseq(NULL, 0x13, m - 2);
344
345 udelay(1000);
346
347 /* Activate clock - write 0, 1, 0 to seq/15 bit 5 */
348 regval = vga_rseq (NULL, 0x15); /* | 0x80; */
349 vga_wseq(NULL, 0x15, regval & ~(1<<5));
350 vga_wseq(NULL, 0x15, regval | (1<<5));
351 vga_wseq(NULL, 0x15, regval & ~(1<<5));
352}
353
354
355/* Open framebuffer */
356
357static int s3fb_open(struct fb_info *info, int user)
358{
359 struct s3fb_info *par = info->par;
360
361 mutex_lock(&(par->open_lock));
362 if (par->ref_count == 0) {
363 memset(&(par->state), 0, sizeof(struct vgastate));
364 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
365 par->state.num_crtc = 0x70;
366 par->state.num_seq = 0x20;
367 save_vga(&(par->state));
368 }
369
370 par->ref_count++;
371 mutex_unlock(&(par->open_lock));
372
373 return 0;
374}
375
376/* Close framebuffer */
377
378static int s3fb_release(struct fb_info *info, int user)
379{
380 struct s3fb_info *par = info->par;
381
382 mutex_lock(&(par->open_lock));
383 if (par->ref_count == 0) {
384 mutex_unlock(&(par->open_lock));
385 return -EINVAL;
386 }
387
388 if (par->ref_count == 1)
389 restore_vga(&(par->state));
390
391 par->ref_count--;
392 mutex_unlock(&(par->open_lock));
393
394 return 0;
395}
396
397/* Validate passed in var */
398
399static int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
400{
401 struct s3fb_info *par = info->par;
402 int rv, mem, step;
403
404 /* Find appropriate format */
405 rv = svga_match_format (s3fb_formats, var, NULL);
Ondrej Zajicekd4b766a2007-10-16 01:29:52 -0700406
407 /* 32bpp mode is not supported on VIRGE VX,
408 24bpp is not supported on others */
409 if ((par->chip == CHIP_988_VIRGE_VX) ? (rv == 7) : (rv == 6))
410 rv = -EINVAL;
411
412 if (rv < 0) {
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800413 printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node);
414 return rv;
415 }
416
417 /* Do not allow to have real resoulution larger than virtual */
418 if (var->xres > var->xres_virtual)
419 var->xres_virtual = var->xres;
420
421 if (var->yres > var->yres_virtual)
422 var->yres_virtual = var->yres;
423
424 /* Round up xres_virtual to have proper alignment of lines */
425 step = s3fb_formats[rv].xresstep - 1;
426 var->xres_virtual = (var->xres_virtual+step) & ~step;
427
428 /* Check whether have enough memory */
429 mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
430 if (mem > info->screen_size)
431 {
432 printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n",
433 info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
434 return -EINVAL;
435 }
436
437 rv = svga_check_timings (&s3_timing_regs, var, info->node);
438 if (rv < 0)
439 {
440 printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
441 return rv;
442 }
443
444 return 0;
445}
446
447/* Set video mode from par */
448
449static int s3fb_set_par(struct fb_info *info)
450{
451 struct s3fb_info *par = info->par;
452 u32 value, mode, hmul, offset_value, screen_size, multiplex;
453 u32 bpp = info->var.bits_per_pixel;
454
455 if (bpp != 0) {
456 info->fix.ypanstep = 1;
457 info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
458
459 info->flags &= ~FBINFO_MISC_TILEBLITTING;
460 info->tileops = NULL;
461
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700462 /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
463 info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
Antonino A. Daplas8db51662007-05-08 00:39:14 -0700464 info->pixmap.blit_y = ~(u32)0;
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700465
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800466 offset_value = (info->var.xres_virtual * bpp) / 64;
467 screen_size = info->var.yres_virtual * info->fix.line_length;
468 } else {
469 info->fix.ypanstep = 16;
470 info->fix.line_length = 0;
471
472 info->flags |= FBINFO_MISC_TILEBLITTING;
473 info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops;
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700474
Antonino A. Daplas8db51662007-05-08 00:39:14 -0700475 /* supports 8x16 tiles only */
476 info->pixmap.blit_x = 1 << (8 - 1);
477 info->pixmap.blit_y = 1 << (16 - 1);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800478
479 offset_value = info->var.xres_virtual / 16;
480 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
481 }
482
483 info->var.xoffset = 0;
484 info->var.yoffset = 0;
485 info->var.activate = FB_ACTIVATE_NOW;
486
487 /* Unlock registers */
488 vga_wcrt(NULL, 0x38, 0x48);
489 vga_wcrt(NULL, 0x39, 0xA5);
490 vga_wseq(NULL, 0x08, 0x06);
491 svga_wcrt_mask(0x11, 0x00, 0x80);
492
493 /* Blank screen and turn off sync */
494 svga_wseq_mask(0x01, 0x20, 0x20);
495 svga_wcrt_mask(0x17, 0x00, 0x80);
496
497 /* Set default values */
498 svga_set_default_gfx_regs();
499 svga_set_default_atc_regs();
500 svga_set_default_seq_regs();
501 svga_set_default_crt_regs();
502 svga_wcrt_multi(s3_line_compare_regs, 0xFFFFFFFF);
503 svga_wcrt_multi(s3_start_address_regs, 0);
504
505 /* S3 specific initialization */
506 svga_wcrt_mask(0x58, 0x10, 0x10); /* enable linear framebuffer */
507 svga_wcrt_mask(0x31, 0x08, 0x08); /* enable sequencer access to framebuffer above 256 kB */
508
509/* svga_wcrt_mask(0x33, 0x08, 0x08); */ /* DDR ? */
510/* svga_wcrt_mask(0x43, 0x01, 0x01); */ /* DDR ? */
511 svga_wcrt_mask(0x33, 0x00, 0x08); /* no DDR ? */
512 svga_wcrt_mask(0x43, 0x00, 0x01); /* no DDR ? */
513
514 svga_wcrt_mask(0x5D, 0x00, 0x28); // Clear strange HSlen bits
515
516/* svga_wcrt_mask(0x58, 0x03, 0x03); */
517
518/* svga_wcrt_mask(0x53, 0x12, 0x13); */ /* enable MMIO */
519/* svga_wcrt_mask(0x40, 0x08, 0x08); */ /* enable write buffer */
520
521
522 /* Set the offset register */
523 pr_debug("fb%d: offset register : %d\n", info->node, offset_value);
524 svga_wcrt_multi(s3_offset_regs, offset_value);
525
526 vga_wcrt(NULL, 0x54, 0x18); /* M parameter */
527 vga_wcrt(NULL, 0x60, 0xff); /* N parameter */
528 vga_wcrt(NULL, 0x61, 0xff); /* L parameter */
529 vga_wcrt(NULL, 0x62, 0xff); /* L parameter */
530
531 vga_wcrt(NULL, 0x3A, 0x35);
532 svga_wattr(0x33, 0x00);
533
534 if (info->var.vmode & FB_VMODE_DOUBLE)
535 svga_wcrt_mask(0x09, 0x80, 0x80);
536 else
537 svga_wcrt_mask(0x09, 0x00, 0x80);
538
539 if (info->var.vmode & FB_VMODE_INTERLACED)
540 svga_wcrt_mask(0x42, 0x20, 0x20);
541 else
542 svga_wcrt_mask(0x42, 0x00, 0x20);
543
544 /* Disable hardware graphics cursor */
545 svga_wcrt_mask(0x45, 0x00, 0x01);
546 /* Disable Streams engine */
547 svga_wcrt_mask(0x67, 0x00, 0x0C);
548
549 mode = svga_match_format(s3fb_formats, &(info->var), &(info->fix));
550
551 /* S3 virge DX hack */
552 if (par->chip == CHIP_375_VIRGE_DX) {
553 vga_wcrt(NULL, 0x86, 0x80);
554 vga_wcrt(NULL, 0x90, 0x00);
555 }
556
557 /* S3 virge VX hack */
558 if (par->chip == CHIP_988_VIRGE_VX) {
559 vga_wcrt(NULL, 0x50, 0x00);
560 vga_wcrt(NULL, 0x67, 0x50);
561
562 vga_wcrt(NULL, 0x63, (mode <= 2) ? 0x90 : 0x09);
563 vga_wcrt(NULL, 0x66, 0x90);
564 }
565
566 svga_wcrt_mask(0x31, 0x00, 0x40);
567 multiplex = 0;
568 hmul = 1;
569
570 /* Set mode-specific register values */
571 switch (mode) {
572 case 0:
573 pr_debug("fb%d: text mode\n", info->node);
574 svga_set_textmode_vga_regs();
575
576 /* Set additional registers like in 8-bit mode */
577 svga_wcrt_mask(0x50, 0x00, 0x30);
578 svga_wcrt_mask(0x67, 0x00, 0xF0);
579
580 /* Disable enhanced mode */
581 svga_wcrt_mask(0x3A, 0x00, 0x30);
582
583 if (fasttext) {
584 pr_debug("fb%d: high speed text mode set\n", info->node);
585 svga_wcrt_mask(0x31, 0x40, 0x40);
586 }
587 break;
588 case 1:
589 pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
590 vga_wgfx(NULL, VGA_GFX_MODE, 0x40);
591
592 /* Set additional registers like in 8-bit mode */
593 svga_wcrt_mask(0x50, 0x00, 0x30);
594 svga_wcrt_mask(0x67, 0x00, 0xF0);
595
596 /* disable enhanced mode */
597 svga_wcrt_mask(0x3A, 0x00, 0x30);
598 break;
599 case 2:
600 pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
601
602 /* Set additional registers like in 8-bit mode */
603 svga_wcrt_mask(0x50, 0x00, 0x30);
604 svga_wcrt_mask(0x67, 0x00, 0xF0);
605
606 /* disable enhanced mode */
607 svga_wcrt_mask(0x3A, 0x00, 0x30);
608 break;
609 case 3:
610 pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
611 if (info->var.pixclock > 20000) {
612 svga_wcrt_mask(0x50, 0x00, 0x30);
613 svga_wcrt_mask(0x67, 0x00, 0xF0);
614 } else {
615 svga_wcrt_mask(0x50, 0x00, 0x30);
616 svga_wcrt_mask(0x67, 0x10, 0xF0);
617 multiplex = 1;
618 }
619 break;
620 case 4:
621 pr_debug("fb%d: 5/5/5 truecolor\n", info->node);
622 if (par->chip == CHIP_988_VIRGE_VX) {
623 if (info->var.pixclock > 20000)
624 svga_wcrt_mask(0x67, 0x20, 0xF0);
625 else
626 svga_wcrt_mask(0x67, 0x30, 0xF0);
627 } else {
628 svga_wcrt_mask(0x50, 0x10, 0x30);
629 svga_wcrt_mask(0x67, 0x30, 0xF0);
630 hmul = 2;
631 }
632 break;
633 case 5:
634 pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
635 if (par->chip == CHIP_988_VIRGE_VX) {
636 if (info->var.pixclock > 20000)
637 svga_wcrt_mask(0x67, 0x40, 0xF0);
638 else
639 svga_wcrt_mask(0x67, 0x50, 0xF0);
640 } else {
641 svga_wcrt_mask(0x50, 0x10, 0x30);
642 svga_wcrt_mask(0x67, 0x50, 0xF0);
643 hmul = 2;
644 }
645 break;
646 case 6:
647 /* VIRGE VX case */
648 pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
649 svga_wcrt_mask(0x67, 0xD0, 0xF0);
650 break;
651 case 7:
652 pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node);
653 svga_wcrt_mask(0x50, 0x30, 0x30);
654 svga_wcrt_mask(0x67, 0xD0, 0xF0);
655 break;
656 default:
657 printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node);
658 return -EINVAL;
659 }
660
661 if (par->chip != CHIP_988_VIRGE_VX) {
662 svga_wseq_mask(0x15, multiplex ? 0x10 : 0x00, 0x10);
663 svga_wseq_mask(0x18, multiplex ? 0x80 : 0x00, 0x80);
664 }
665
666 s3_set_pixclock(info, info->var.pixclock);
667 svga_set_timings(&s3_timing_regs, &(info->var), hmul, 1,
668 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
669 (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
670 hmul, info->node);
671
672 /* Set interlaced mode start/end register */
673 value = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
674 value = ((value * hmul) / 8) - 5;
675 vga_wcrt(NULL, 0x3C, (value + 1) / 2);
676
Antonino A. Daplas75814d82007-05-08 00:38:49 -0700677 memset_io(info->screen_base, 0x00, screen_size);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800678 /* Device and screen back on */
679 svga_wcrt_mask(0x17, 0x80, 0x80);
680 svga_wseq_mask(0x01, 0x00, 0x20);
681
682 return 0;
683}
684
685/* Set a colour register */
686
687static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
688 u_int transp, struct fb_info *fb)
689{
690 switch (fb->var.bits_per_pixel) {
691 case 0:
692 case 4:
693 if (regno >= 16)
694 return -EINVAL;
695
696 if ((fb->var.bits_per_pixel == 4) &&
697 (fb->var.nonstd == 0)) {
698 outb(0xF0, VGA_PEL_MSK);
699 outb(regno*16, VGA_PEL_IW);
700 } else {
701 outb(0x0F, VGA_PEL_MSK);
702 outb(regno, VGA_PEL_IW);
703 }
704 outb(red >> 10, VGA_PEL_D);
705 outb(green >> 10, VGA_PEL_D);
706 outb(blue >> 10, VGA_PEL_D);
707 break;
708 case 8:
709 if (regno >= 256)
710 return -EINVAL;
711
712 outb(0xFF, VGA_PEL_MSK);
713 outb(regno, VGA_PEL_IW);
714 outb(red >> 10, VGA_PEL_D);
715 outb(green >> 10, VGA_PEL_D);
716 outb(blue >> 10, VGA_PEL_D);
717 break;
718 case 16:
719 if (regno >= 16)
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700720 return 0;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800721
722 if (fb->var.green.length == 5)
723 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
724 ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
725 else if (fb->var.green.length == 6)
726 ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
727 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
728 else return -EINVAL;
729 break;
730 case 24:
731 case 32:
732 if (regno >= 16)
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700733 return 0;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800734
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700735 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800736 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
737 break;
738 default:
739 return -EINVAL;
740 }
741
742 return 0;
743}
744
745
746/* Set the display blanking state */
747
748static int s3fb_blank(int blank_mode, struct fb_info *info)
749{
750 switch (blank_mode) {
751 case FB_BLANK_UNBLANK:
752 pr_debug("fb%d: unblank\n", info->node);
753 svga_wcrt_mask(0x56, 0x00, 0x06);
754 svga_wseq_mask(0x01, 0x00, 0x20);
755 break;
756 case FB_BLANK_NORMAL:
757 pr_debug("fb%d: blank\n", info->node);
758 svga_wcrt_mask(0x56, 0x00, 0x06);
759 svga_wseq_mask(0x01, 0x20, 0x20);
760 break;
761 case FB_BLANK_HSYNC_SUSPEND:
762 pr_debug("fb%d: hsync\n", info->node);
763 svga_wcrt_mask(0x56, 0x02, 0x06);
764 svga_wseq_mask(0x01, 0x20, 0x20);
765 break;
766 case FB_BLANK_VSYNC_SUSPEND:
767 pr_debug("fb%d: vsync\n", info->node);
768 svga_wcrt_mask(0x56, 0x04, 0x06);
769 svga_wseq_mask(0x01, 0x20, 0x20);
770 break;
771 case FB_BLANK_POWERDOWN:
772 pr_debug("fb%d: sync down\n", info->node);
773 svga_wcrt_mask(0x56, 0x06, 0x06);
774 svga_wseq_mask(0x01, 0x20, 0x20);
775 break;
776 }
777
778 return 0;
779}
780
781
782/* Pan the display */
783
784static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) {
785
786 unsigned int offset;
787
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800788 /* Calculate the offset */
789 if (var->bits_per_pixel == 0) {
790 offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
791 offset = offset >> 2;
792 } else {
793 offset = (var->yoffset * info->fix.line_length) +
794 (var->xoffset * var->bits_per_pixel / 8);
795 offset = offset >> 2;
796 }
797
798 /* Set the offset */
799 svga_wcrt_multi(s3_start_address_regs, offset);
800
801 return 0;
802}
803
804/* ------------------------------------------------------------------------- */
805
806/* Frame buffer operations */
807
808static struct fb_ops s3fb_ops = {
809 .owner = THIS_MODULE,
810 .fb_open = s3fb_open,
811 .fb_release = s3fb_release,
812 .fb_check_var = s3fb_check_var,
813 .fb_set_par = s3fb_set_par,
814 .fb_setcolreg = s3fb_setcolreg,
815 .fb_blank = s3fb_blank,
816 .fb_pan_display = s3fb_pan_display,
817 .fb_fillrect = s3fb_fillrect,
818 .fb_copyarea = cfb_copyarea,
819 .fb_imageblit = s3fb_imageblit,
Antonino A. Daplas5a87ede2007-05-09 02:35:32 -0700820 .fb_get_caps = svga_get_caps,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800821};
822
823/* ------------------------------------------------------------------------- */
824
825static int __devinit s3_identification(int chip)
826{
827 if (chip == CHIP_XXX_TRIO) {
828 u8 cr30 = vga_rcrt(NULL, 0x30);
829 u8 cr2e = vga_rcrt(NULL, 0x2e);
830 u8 cr2f = vga_rcrt(NULL, 0x2f);
831
832 if ((cr30 == 0xE0) || (cr30 == 0xE1)) {
833 if (cr2e == 0x10)
834 return CHIP_732_TRIO32;
835 if (cr2e == 0x11) {
836 if (! (cr2f & 0x40))
837 return CHIP_764_TRIO64;
838 else
839 return CHIP_765_TRIO64VP;
840 }
841 }
842 }
843
844 if (chip == CHIP_XXX_TRIO64V2_DXGX) {
845 u8 cr6f = vga_rcrt(NULL, 0x6f);
846
847 if (! (cr6f & 0x01))
848 return CHIP_775_TRIO64V2_DX;
849 else
850 return CHIP_785_TRIO64V2_GX;
851 }
852
853 if (chip == CHIP_XXX_VIRGE_DXGX) {
854 u8 cr6f = vga_rcrt(NULL, 0x6f);
855
856 if (! (cr6f & 0x01))
857 return CHIP_375_VIRGE_DX;
858 else
859 return CHIP_385_VIRGE_GX;
860 }
861
862 return CHIP_UNKNOWN;
863}
864
865
866/* PCI probe */
867
868static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
869{
870 struct fb_info *info;
871 struct s3fb_info *par;
872 int rc;
873 u8 regval, cr38, cr39;
874
875 /* Ignore secondary VGA device because there is no VGA arbitration */
876 if (! svga_primary_device(dev)) {
877 dev_info(&(dev->dev), "ignoring secondary device\n");
878 return -ENODEV;
879 }
880
881 /* Allocate and fill driver data structure */
882 info = framebuffer_alloc(sizeof(struct s3fb_info), NULL);
883 if (!info) {
884 dev_err(&(dev->dev), "cannot allocate memory\n");
885 return -ENOMEM;
886 }
887
888 par = info->par;
889 mutex_init(&par->open_lock);
890
891 info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
892 info->fbops = &s3fb_ops;
893
894 /* Prepare PCI device */
895 rc = pci_enable_device(dev);
896 if (rc < 0) {
897 dev_err(&(dev->dev), "cannot enable PCI device\n");
898 goto err_enable_device;
899 }
900
901 rc = pci_request_regions(dev, "s3fb");
902 if (rc < 0) {
903 dev_err(&(dev->dev), "cannot reserve framebuffer region\n");
904 goto err_request_regions;
905 }
906
907
908 info->fix.smem_start = pci_resource_start(dev, 0);
909 info->fix.smem_len = pci_resource_len(dev, 0);
910
911 /* Map physical IO memory address into kernel space */
912 info->screen_base = pci_iomap(dev, 0, 0);
913 if (! info->screen_base) {
914 rc = -ENOMEM;
915 dev_err(&(dev->dev), "iomap for framebuffer failed\n");
916 goto err_iomap;
917 }
918
919 /* Unlock regs */
920 cr38 = vga_rcrt(NULL, 0x38);
921 cr39 = vga_rcrt(NULL, 0x39);
922 vga_wseq(NULL, 0x08, 0x06);
923 vga_wcrt(NULL, 0x38, 0x48);
924 vga_wcrt(NULL, 0x39, 0xA5);
925
926 /* Find how many physical memory there is on card */
927 /* 0x36 register is accessible even if other registers are locked */
928 regval = vga_rcrt(NULL, 0x36);
929 info->screen_size = s3_memsizes[regval >> 5] << 10;
930 info->fix.smem_len = info->screen_size;
931
932 par->chip = id->driver_data & CHIP_MASK;
933 par->rev = vga_rcrt(NULL, 0x2f);
934 if (par->chip & CHIP_UNDECIDED_FLAG)
935 par->chip = s3_identification(par->chip);
936
937 /* Find MCLK frequency */
938 regval = vga_rseq(NULL, 0x10);
939 par->mclk_freq = ((vga_rseq(NULL, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2);
940 par->mclk_freq = par->mclk_freq >> (regval >> 5);
941
942 /* Restore locks */
943 vga_wcrt(NULL, 0x38, cr38);
944 vga_wcrt(NULL, 0x39, cr39);
945
946 strcpy(info->fix.id, s3_names [par->chip]);
947 info->fix.mmio_start = 0;
948 info->fix.mmio_len = 0;
949 info->fix.type = FB_TYPE_PACKED_PIXELS;
950 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
951 info->fix.ypanstep = 0;
952 info->fix.accel = FB_ACCEL_NONE;
953 info->pseudo_palette = (void*) (par->pseudo_palette);
954
955 /* Prepare startup mode */
956 rc = fb_find_mode(&(info->var), info, mode, NULL, 0, NULL, 8);
957 if (! ((rc == 1) || (rc == 2))) {
958 rc = -EINVAL;
959 dev_err(&(dev->dev), "mode %s not found\n", mode);
960 goto err_find_mode;
961 }
962
963 rc = fb_alloc_cmap(&info->cmap, 256, 0);
964 if (rc < 0) {
965 dev_err(&(dev->dev), "cannot allocate colormap\n");
966 goto err_alloc_cmap;
967 }
968
969 rc = register_framebuffer(info);
970 if (rc < 0) {
971 dev_err(&(dev->dev), "cannot register framebuffer\n");
972 goto err_reg_fb;
973 }
974
975 printk(KERN_INFO "fb%d: %s on %s, %d MB RAM, %d MHz MCLK\n", info->node, info->fix.id,
976 pci_name(dev), info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000);
977
978 if (par->chip == CHIP_UNKNOWN)
979 printk(KERN_INFO "fb%d: unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n",
980 info->node, vga_rcrt(NULL, 0x2d), vga_rcrt(NULL, 0x2e),
981 vga_rcrt(NULL, 0x2f), vga_rcrt(NULL, 0x30));
982
983 /* Record a reference to the driver data */
984 pci_set_drvdata(dev, info);
985
986#ifdef CONFIG_MTRR
987 if (mtrr) {
988 par->mtrr_reg = -1;
989 par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
990 }
991#endif
992
993 return 0;
994
995 /* Error handling */
996err_reg_fb:
997 fb_dealloc_cmap(&info->cmap);
998err_alloc_cmap:
999err_find_mode:
1000 pci_iounmap(dev, info->screen_base);
1001err_iomap:
1002 pci_release_regions(dev);
1003err_request_regions:
1004/* pci_disable_device(dev); */
1005err_enable_device:
1006 framebuffer_release(info);
1007 return rc;
1008}
1009
1010
1011/* PCI remove */
1012
1013static void __devexit s3_pci_remove(struct pci_dev *dev)
1014{
1015 struct fb_info *info = pci_get_drvdata(dev);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001016
1017 if (info) {
1018
1019#ifdef CONFIG_MTRR
Adrian Bunk47ebea82007-03-22 00:11:16 -08001020 struct s3fb_info *par = info->par;
1021
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001022 if (par->mtrr_reg >= 0) {
1023 mtrr_del(par->mtrr_reg, 0, 0);
1024 par->mtrr_reg = -1;
1025 }
1026#endif
1027
1028 unregister_framebuffer(info);
1029 fb_dealloc_cmap(&info->cmap);
1030
1031 pci_iounmap(dev, info->screen_base);
1032 pci_release_regions(dev);
1033/* pci_disable_device(dev); */
1034
1035 pci_set_drvdata(dev, NULL);
1036 framebuffer_release(info);
1037 }
1038}
1039
1040/* PCI suspend */
1041
1042static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state)
1043{
1044 struct fb_info *info = pci_get_drvdata(dev);
1045 struct s3fb_info *par = info->par;
1046
1047 dev_info(&(dev->dev), "suspend\n");
1048
1049 acquire_console_sem();
1050 mutex_lock(&(par->open_lock));
1051
1052 if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
1053 mutex_unlock(&(par->open_lock));
1054 release_console_sem();
1055 return 0;
1056 }
1057
1058 fb_set_suspend(info, 1);
1059
1060 pci_save_state(dev);
1061 pci_disable_device(dev);
1062 pci_set_power_state(dev, pci_choose_state(dev, state));
1063
1064 mutex_unlock(&(par->open_lock));
1065 release_console_sem();
1066
1067 return 0;
1068}
1069
1070
1071/* PCI resume */
1072
1073static int s3_pci_resume(struct pci_dev* dev)
1074{
1075 struct fb_info *info = pci_get_drvdata(dev);
1076 struct s3fb_info *par = info->par;
Randy Dunlap6314db42007-05-08 00:38:11 -07001077 int err;
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001078
1079 dev_info(&(dev->dev), "resume\n");
1080
1081 acquire_console_sem();
1082 mutex_lock(&(par->open_lock));
1083
1084 if (par->ref_count == 0) {
1085 mutex_unlock(&(par->open_lock));
1086 release_console_sem();
1087 return 0;
1088 }
1089
1090 pci_set_power_state(dev, PCI_D0);
1091 pci_restore_state(dev);
Randy Dunlap6314db42007-05-08 00:38:11 -07001092 err = pci_enable_device(dev);
1093 if (err) {
1094 mutex_unlock(&(par->open_lock));
1095 release_console_sem();
1096 dev_err(&(dev->dev), "error %d enabling device for resume\n", err);
1097 return err;
1098 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001099 pci_set_master(dev);
1100
1101 s3fb_set_par(info);
1102 fb_set_suspend(info, 0);
1103
1104 mutex_unlock(&(par->open_lock));
1105 release_console_sem();
1106
1107 return 0;
1108}
1109
1110
1111/* List of boards that we are trying to support */
1112
1113static struct pci_device_id s3_devices[] __devinitdata = {
1114 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO},
1115 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO},
1116 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP},
1117 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP},
1118 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX},
1119 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX},
1120
1121 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE},
1122 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX},
1123 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX},
1124 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_356_VIRGE_GX2},
1125 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_357_VIRGE_GX2P},
1126 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P},
1127
1128 {0, 0, 0, 0, 0, 0, 0}
1129};
1130
1131
1132MODULE_DEVICE_TABLE(pci, s3_devices);
1133
1134static struct pci_driver s3fb_pci_driver = {
1135 .name = "s3fb",
1136 .id_table = s3_devices,
1137 .probe = s3_pci_probe,
1138 .remove = __devexit_p(s3_pci_remove),
1139 .suspend = s3_pci_suspend,
1140 .resume = s3_pci_resume,
1141};
1142
1143/* Parse user speficied options */
1144
1145#ifndef MODULE
1146static int __init s3fb_setup(char *options)
1147{
1148 char *opt;
1149
1150 if (!options || !*options)
1151 return 0;
1152
1153 while ((opt = strsep(&options, ",")) != NULL) {
1154
1155 if (!*opt)
1156 continue;
1157#ifdef CONFIG_MTRR
Ondrej Zajicek62fa4dc2007-02-22 17:00:41 +01001158 else if (!strncmp(opt, "mtrr:", 5))
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001159 mtrr = simple_strtoul(opt + 5, NULL, 0);
1160#endif
Ondrej Zajicek62fa4dc2007-02-22 17:00:41 +01001161 else if (!strncmp(opt, "fasttext:", 9))
1162 fasttext = simple_strtoul(opt + 9, NULL, 0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001163 else
1164 mode = opt;
1165 }
1166
1167 return 0;
1168}
1169#endif
1170
1171/* Cleanup */
1172
1173static void __exit s3fb_cleanup(void)
1174{
1175 pr_debug("s3fb: cleaning up\n");
1176 pci_unregister_driver(&s3fb_pci_driver);
1177}
1178
1179/* Driver Initialisation */
1180
1181static int __init s3fb_init(void)
1182{
1183
1184#ifndef MODULE
1185 char *option = NULL;
1186
1187 if (fb_get_options("s3fb", &option))
1188 return -ENODEV;
1189 s3fb_setup(option);
1190#endif
1191
1192 pr_debug("s3fb: initializing\n");
1193 return pci_register_driver(&s3fb_pci_driver);
1194}
1195
1196/* ------------------------------------------------------------------------- */
1197
1198/* Modularization */
1199
1200module_init(s3fb_init);
1201module_exit(s3fb_cleanup);