blob: 4d0e204dd8ad311bd0f2bc6af06248b454bbec30 [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
Antonino A. Daplasff388ad2007-05-08 00:39:17 -0700186static int s3fb_get_tilemax(struct fb_info *info)
187{
188 return 256;
189}
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800190
191static struct fb_tile_ops s3fb_tile_ops = {
192 .fb_settile = svga_settile,
193 .fb_tilecopy = svga_tilecopy,
194 .fb_tilefill = svga_tilefill,
195 .fb_tileblit = svga_tileblit,
196 .fb_tilecursor = svga_tilecursor,
Antonino A. Daplasff388ad2007-05-08 00:39:17 -0700197 .fb_get_tilemax = s3fb_get_tilemax,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800198};
199
200static struct fb_tile_ops s3fb_fast_tile_ops = {
201 .fb_settile = s3fb_settile_fast,
202 .fb_tilecopy = svga_tilecopy,
203 .fb_tilefill = svga_tilefill,
204 .fb_tileblit = svga_tileblit,
205 .fb_tilecursor = svga_tilecursor,
Antonino A. Daplasff388ad2007-05-08 00:39:17 -0700206 .fb_get_tilemax = s3fb_get_tilemax,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800207};
208
209
210/* ------------------------------------------------------------------------- */
211
212/* image data is MSB-first, fb structure is MSB-first too */
213static inline u32 expand_color(u32 c)
214{
215 return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
216}
217
218/* s3fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
219static void s3fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
220{
221 u32 fg = expand_color(image->fg_color);
222 u32 bg = expand_color(image->bg_color);
223 const u8 *src1, *src;
224 u8 __iomem *dst1;
225 u32 __iomem *dst;
226 u32 val;
227 int x, y;
228
229 src1 = image->data;
230 dst1 = info->screen_base + (image->dy * info->fix.line_length)
231 + ((image->dx / 8) * 4);
232
233 for (y = 0; y < image->height; y++) {
234 src = src1;
235 dst = (u32 __iomem *) dst1;
236 for (x = 0; x < image->width; x += 8) {
237 val = *(src++) * 0x01010101;
238 val = (val & fg) | (~val & bg);
239 fb_writel(val, dst++);
240 }
241 src1 += image->width / 8;
242 dst1 += info->fix.line_length;
243 }
244
245}
246
247/* s3fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
248static void s3fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
249{
250 u32 fg = expand_color(rect->color);
251 u8 __iomem *dst1;
252 u32 __iomem *dst;
253 int x, y;
254
255 dst1 = info->screen_base + (rect->dy * info->fix.line_length)
256 + ((rect->dx / 8) * 4);
257
258 for (y = 0; y < rect->height; y++) {
259 dst = (u32 __iomem *) dst1;
260 for (x = 0; x < rect->width; x += 8) {
261 fb_writel(fg, dst++);
262 }
263 dst1 += info->fix.line_length;
264 }
265}
266
267
268/* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
269static inline u32 expand_pixel(u32 c)
270{
271 return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
272 ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
273}
274
275/* s3fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
276static void s3fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
277{
278 u32 fg = image->fg_color * 0x11111111;
279 u32 bg = image->bg_color * 0x11111111;
280 const u8 *src1, *src;
281 u8 __iomem *dst1;
282 u32 __iomem *dst;
283 u32 val;
284 int x, y;
285
286 src1 = image->data;
287 dst1 = info->screen_base + (image->dy * info->fix.line_length)
288 + ((image->dx / 8) * 4);
289
290 for (y = 0; y < image->height; y++) {
291 src = src1;
292 dst = (u32 __iomem *) dst1;
293 for (x = 0; x < image->width; x += 8) {
294 val = expand_pixel(*(src++));
295 val = (val & fg) | (~val & bg);
296 fb_writel(val, dst++);
297 }
298 src1 += image->width / 8;
299 dst1 += info->fix.line_length;
300 }
301}
302
303static void s3fb_imageblit(struct fb_info *info, const struct fb_image *image)
304{
305 if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
306 && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
307 if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
308 s3fb_iplan_imageblit(info, image);
309 else
310 s3fb_cfb4_imageblit(info, image);
311 } else
312 cfb_imageblit(info, image);
313}
314
315static void s3fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
316{
317 if ((info->var.bits_per_pixel == 4)
318 && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
319 && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
320 s3fb_iplan_fillrect(info, rect);
321 else
322 cfb_fillrect(info, rect);
323}
324
325
326
327/* ------------------------------------------------------------------------- */
328
329
330static void s3_set_pixclock(struct fb_info *info, u32 pixclock)
331{
332 u16 m, n, r;
333 u8 regval;
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700334 int rv;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800335
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700336 rv = svga_compute_pll(&s3_pll, 1000000000 / pixclock, &m, &n, &r, info->node);
337 if (rv < 0) {
338 printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node);
339 return;
340 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800341
342 /* Set VGA misc register */
343 regval = vga_r(NULL, VGA_MIS_R);
344 vga_w(NULL, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
345
346 /* Set S3 clock registers */
347 vga_wseq(NULL, 0x12, ((n - 2) | (r << 5)));
348 vga_wseq(NULL, 0x13, m - 2);
349
350 udelay(1000);
351
352 /* Activate clock - write 0, 1, 0 to seq/15 bit 5 */
353 regval = vga_rseq (NULL, 0x15); /* | 0x80; */
354 vga_wseq(NULL, 0x15, regval & ~(1<<5));
355 vga_wseq(NULL, 0x15, regval | (1<<5));
356 vga_wseq(NULL, 0x15, regval & ~(1<<5));
357}
358
359
360/* Open framebuffer */
361
362static int s3fb_open(struct fb_info *info, int user)
363{
364 struct s3fb_info *par = info->par;
365
366 mutex_lock(&(par->open_lock));
367 if (par->ref_count == 0) {
368 memset(&(par->state), 0, sizeof(struct vgastate));
369 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
370 par->state.num_crtc = 0x70;
371 par->state.num_seq = 0x20;
372 save_vga(&(par->state));
373 }
374
375 par->ref_count++;
376 mutex_unlock(&(par->open_lock));
377
378 return 0;
379}
380
381/* Close framebuffer */
382
383static int s3fb_release(struct fb_info *info, int user)
384{
385 struct s3fb_info *par = info->par;
386
387 mutex_lock(&(par->open_lock));
388 if (par->ref_count == 0) {
389 mutex_unlock(&(par->open_lock));
390 return -EINVAL;
391 }
392
393 if (par->ref_count == 1)
394 restore_vga(&(par->state));
395
396 par->ref_count--;
397 mutex_unlock(&(par->open_lock));
398
399 return 0;
400}
401
402/* Validate passed in var */
403
404static int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
405{
406 struct s3fb_info *par = info->par;
407 int rv, mem, step;
408
409 /* Find appropriate format */
410 rv = svga_match_format (s3fb_formats, var, NULL);
411 if ((rv < 0) || ((par->chip == CHIP_988_VIRGE_VX) ? (rv == 7) : (rv == 6)))
412 { /* 24bpp on VIRGE VX, 32bpp on others */
413 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
Antonino A. Daplas8db51662007-05-08 00:39:14 -0700462 /* supports blit rectangles of any dimension */
463 info->pixmap.blit_x = ~(u32)0;
464 info->pixmap.blit_y = ~(u32)0;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800465 offset_value = (info->var.xres_virtual * bpp) / 64;
466 screen_size = info->var.yres_virtual * info->fix.line_length;
467 } else {
468 info->fix.ypanstep = 16;
469 info->fix.line_length = 0;
470
471 info->flags |= FBINFO_MISC_TILEBLITTING;
472 info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops;
Antonino A. Daplas8db51662007-05-08 00:39:14 -0700473 /* supports 8x16 tiles only */
474 info->pixmap.blit_x = 1 << (8 - 1);
475 info->pixmap.blit_y = 1 << (16 - 1);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800476
477 offset_value = info->var.xres_virtual / 16;
478 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
479 }
480
481 info->var.xoffset = 0;
482 info->var.yoffset = 0;
483 info->var.activate = FB_ACTIVATE_NOW;
484
485 /* Unlock registers */
486 vga_wcrt(NULL, 0x38, 0x48);
487 vga_wcrt(NULL, 0x39, 0xA5);
488 vga_wseq(NULL, 0x08, 0x06);
489 svga_wcrt_mask(0x11, 0x00, 0x80);
490
491 /* Blank screen and turn off sync */
492 svga_wseq_mask(0x01, 0x20, 0x20);
493 svga_wcrt_mask(0x17, 0x00, 0x80);
494
495 /* Set default values */
496 svga_set_default_gfx_regs();
497 svga_set_default_atc_regs();
498 svga_set_default_seq_regs();
499 svga_set_default_crt_regs();
500 svga_wcrt_multi(s3_line_compare_regs, 0xFFFFFFFF);
501 svga_wcrt_multi(s3_start_address_regs, 0);
502
503 /* S3 specific initialization */
504 svga_wcrt_mask(0x58, 0x10, 0x10); /* enable linear framebuffer */
505 svga_wcrt_mask(0x31, 0x08, 0x08); /* enable sequencer access to framebuffer above 256 kB */
506
507/* svga_wcrt_mask(0x33, 0x08, 0x08); */ /* DDR ? */
508/* svga_wcrt_mask(0x43, 0x01, 0x01); */ /* DDR ? */
509 svga_wcrt_mask(0x33, 0x00, 0x08); /* no DDR ? */
510 svga_wcrt_mask(0x43, 0x00, 0x01); /* no DDR ? */
511
512 svga_wcrt_mask(0x5D, 0x00, 0x28); // Clear strange HSlen bits
513
514/* svga_wcrt_mask(0x58, 0x03, 0x03); */
515
516/* svga_wcrt_mask(0x53, 0x12, 0x13); */ /* enable MMIO */
517/* svga_wcrt_mask(0x40, 0x08, 0x08); */ /* enable write buffer */
518
519
520 /* Set the offset register */
521 pr_debug("fb%d: offset register : %d\n", info->node, offset_value);
522 svga_wcrt_multi(s3_offset_regs, offset_value);
523
524 vga_wcrt(NULL, 0x54, 0x18); /* M parameter */
525 vga_wcrt(NULL, 0x60, 0xff); /* N parameter */
526 vga_wcrt(NULL, 0x61, 0xff); /* L parameter */
527 vga_wcrt(NULL, 0x62, 0xff); /* L parameter */
528
529 vga_wcrt(NULL, 0x3A, 0x35);
530 svga_wattr(0x33, 0x00);
531
532 if (info->var.vmode & FB_VMODE_DOUBLE)
533 svga_wcrt_mask(0x09, 0x80, 0x80);
534 else
535 svga_wcrt_mask(0x09, 0x00, 0x80);
536
537 if (info->var.vmode & FB_VMODE_INTERLACED)
538 svga_wcrt_mask(0x42, 0x20, 0x20);
539 else
540 svga_wcrt_mask(0x42, 0x00, 0x20);
541
542 /* Disable hardware graphics cursor */
543 svga_wcrt_mask(0x45, 0x00, 0x01);
544 /* Disable Streams engine */
545 svga_wcrt_mask(0x67, 0x00, 0x0C);
546
547 mode = svga_match_format(s3fb_formats, &(info->var), &(info->fix));
548
549 /* S3 virge DX hack */
550 if (par->chip == CHIP_375_VIRGE_DX) {
551 vga_wcrt(NULL, 0x86, 0x80);
552 vga_wcrt(NULL, 0x90, 0x00);
553 }
554
555 /* S3 virge VX hack */
556 if (par->chip == CHIP_988_VIRGE_VX) {
557 vga_wcrt(NULL, 0x50, 0x00);
558 vga_wcrt(NULL, 0x67, 0x50);
559
560 vga_wcrt(NULL, 0x63, (mode <= 2) ? 0x90 : 0x09);
561 vga_wcrt(NULL, 0x66, 0x90);
562 }
563
564 svga_wcrt_mask(0x31, 0x00, 0x40);
565 multiplex = 0;
566 hmul = 1;
567
568 /* Set mode-specific register values */
569 switch (mode) {
570 case 0:
571 pr_debug("fb%d: text mode\n", info->node);
572 svga_set_textmode_vga_regs();
573
574 /* Set additional registers like in 8-bit mode */
575 svga_wcrt_mask(0x50, 0x00, 0x30);
576 svga_wcrt_mask(0x67, 0x00, 0xF0);
577
578 /* Disable enhanced mode */
579 svga_wcrt_mask(0x3A, 0x00, 0x30);
580
581 if (fasttext) {
582 pr_debug("fb%d: high speed text mode set\n", info->node);
583 svga_wcrt_mask(0x31, 0x40, 0x40);
584 }
585 break;
586 case 1:
587 pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
588 vga_wgfx(NULL, VGA_GFX_MODE, 0x40);
589
590 /* Set additional registers like in 8-bit mode */
591 svga_wcrt_mask(0x50, 0x00, 0x30);
592 svga_wcrt_mask(0x67, 0x00, 0xF0);
593
594 /* disable enhanced mode */
595 svga_wcrt_mask(0x3A, 0x00, 0x30);
596 break;
597 case 2:
598 pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
599
600 /* Set additional registers like in 8-bit mode */
601 svga_wcrt_mask(0x50, 0x00, 0x30);
602 svga_wcrt_mask(0x67, 0x00, 0xF0);
603
604 /* disable enhanced mode */
605 svga_wcrt_mask(0x3A, 0x00, 0x30);
606 break;
607 case 3:
608 pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
609 if (info->var.pixclock > 20000) {
610 svga_wcrt_mask(0x50, 0x00, 0x30);
611 svga_wcrt_mask(0x67, 0x00, 0xF0);
612 } else {
613 svga_wcrt_mask(0x50, 0x00, 0x30);
614 svga_wcrt_mask(0x67, 0x10, 0xF0);
615 multiplex = 1;
616 }
617 break;
618 case 4:
619 pr_debug("fb%d: 5/5/5 truecolor\n", info->node);
620 if (par->chip == CHIP_988_VIRGE_VX) {
621 if (info->var.pixclock > 20000)
622 svga_wcrt_mask(0x67, 0x20, 0xF0);
623 else
624 svga_wcrt_mask(0x67, 0x30, 0xF0);
625 } else {
626 svga_wcrt_mask(0x50, 0x10, 0x30);
627 svga_wcrt_mask(0x67, 0x30, 0xF0);
628 hmul = 2;
629 }
630 break;
631 case 5:
632 pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
633 if (par->chip == CHIP_988_VIRGE_VX) {
634 if (info->var.pixclock > 20000)
635 svga_wcrt_mask(0x67, 0x40, 0xF0);
636 else
637 svga_wcrt_mask(0x67, 0x50, 0xF0);
638 } else {
639 svga_wcrt_mask(0x50, 0x10, 0x30);
640 svga_wcrt_mask(0x67, 0x50, 0xF0);
641 hmul = 2;
642 }
643 break;
644 case 6:
645 /* VIRGE VX case */
646 pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
647 svga_wcrt_mask(0x67, 0xD0, 0xF0);
648 break;
649 case 7:
650 pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node);
651 svga_wcrt_mask(0x50, 0x30, 0x30);
652 svga_wcrt_mask(0x67, 0xD0, 0xF0);
653 break;
654 default:
655 printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node);
656 return -EINVAL;
657 }
658
659 if (par->chip != CHIP_988_VIRGE_VX) {
660 svga_wseq_mask(0x15, multiplex ? 0x10 : 0x00, 0x10);
661 svga_wseq_mask(0x18, multiplex ? 0x80 : 0x00, 0x80);
662 }
663
664 s3_set_pixclock(info, info->var.pixclock);
665 svga_set_timings(&s3_timing_regs, &(info->var), hmul, 1,
666 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
667 (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
668 hmul, info->node);
669
670 /* Set interlaced mode start/end register */
671 value = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
672 value = ((value * hmul) / 8) - 5;
673 vga_wcrt(NULL, 0x3C, (value + 1) / 2);
674
Antonino A. Daplas75814d82007-05-08 00:38:49 -0700675 memset_io(info->screen_base, 0x00, screen_size);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800676 /* Device and screen back on */
677 svga_wcrt_mask(0x17, 0x80, 0x80);
678 svga_wseq_mask(0x01, 0x00, 0x20);
679
680 return 0;
681}
682
683/* Set a colour register */
684
685static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
686 u_int transp, struct fb_info *fb)
687{
688 switch (fb->var.bits_per_pixel) {
689 case 0:
690 case 4:
691 if (regno >= 16)
692 return -EINVAL;
693
694 if ((fb->var.bits_per_pixel == 4) &&
695 (fb->var.nonstd == 0)) {
696 outb(0xF0, VGA_PEL_MSK);
697 outb(regno*16, VGA_PEL_IW);
698 } else {
699 outb(0x0F, VGA_PEL_MSK);
700 outb(regno, VGA_PEL_IW);
701 }
702 outb(red >> 10, VGA_PEL_D);
703 outb(green >> 10, VGA_PEL_D);
704 outb(blue >> 10, VGA_PEL_D);
705 break;
706 case 8:
707 if (regno >= 256)
708 return -EINVAL;
709
710 outb(0xFF, VGA_PEL_MSK);
711 outb(regno, VGA_PEL_IW);
712 outb(red >> 10, VGA_PEL_D);
713 outb(green >> 10, VGA_PEL_D);
714 outb(blue >> 10, VGA_PEL_D);
715 break;
716 case 16:
717 if (regno >= 16)
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700718 return 0;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800719
720 if (fb->var.green.length == 5)
721 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
722 ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
723 else if (fb->var.green.length == 6)
724 ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
725 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
726 else return -EINVAL;
727 break;
728 case 24:
729 case 32:
730 if (regno >= 16)
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700731 return 0;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800732
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700733 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800734 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
735 break;
736 default:
737 return -EINVAL;
738 }
739
740 return 0;
741}
742
743
744/* Set the display blanking state */
745
746static int s3fb_blank(int blank_mode, struct fb_info *info)
747{
748 switch (blank_mode) {
749 case FB_BLANK_UNBLANK:
750 pr_debug("fb%d: unblank\n", info->node);
751 svga_wcrt_mask(0x56, 0x00, 0x06);
752 svga_wseq_mask(0x01, 0x00, 0x20);
753 break;
754 case FB_BLANK_NORMAL:
755 pr_debug("fb%d: blank\n", info->node);
756 svga_wcrt_mask(0x56, 0x00, 0x06);
757 svga_wseq_mask(0x01, 0x20, 0x20);
758 break;
759 case FB_BLANK_HSYNC_SUSPEND:
760 pr_debug("fb%d: hsync\n", info->node);
761 svga_wcrt_mask(0x56, 0x02, 0x06);
762 svga_wseq_mask(0x01, 0x20, 0x20);
763 break;
764 case FB_BLANK_VSYNC_SUSPEND:
765 pr_debug("fb%d: vsync\n", info->node);
766 svga_wcrt_mask(0x56, 0x04, 0x06);
767 svga_wseq_mask(0x01, 0x20, 0x20);
768 break;
769 case FB_BLANK_POWERDOWN:
770 pr_debug("fb%d: sync down\n", info->node);
771 svga_wcrt_mask(0x56, 0x06, 0x06);
772 svga_wseq_mask(0x01, 0x20, 0x20);
773 break;
774 }
775
776 return 0;
777}
778
779
780/* Pan the display */
781
782static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) {
783
784 unsigned int offset;
785
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800786 /* Calculate the offset */
787 if (var->bits_per_pixel == 0) {
788 offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
789 offset = offset >> 2;
790 } else {
791 offset = (var->yoffset * info->fix.line_length) +
792 (var->xoffset * var->bits_per_pixel / 8);
793 offset = offset >> 2;
794 }
795
796 /* Set the offset */
797 svga_wcrt_multi(s3_start_address_regs, offset);
798
799 return 0;
800}
801
Antonino A. Daplas56c75542007-05-08 00:39:39 -0700802/* Get capabilities of accelerator based on the mode */
803
804static void s3fb_get_caps(struct fb_info *info, struct fb_blit_caps *caps,
805 struct fb_var_screeninfo *var)
806{
807 if (var->bits_per_pixel == 0) {
808 /* can only support 256 8x16 bitmap */
809 caps->x = 1 << (8 - 1);
810 caps->y = 1 << (16 - 1);
811 caps->len = 256;
812 } else {
813 caps->x = ~(u32)0;
814 caps->y = ~(u32)0;
815 caps->len = ~(u32)0;
816 }
817}
818
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800819/* ------------------------------------------------------------------------- */
820
821/* Frame buffer operations */
822
823static struct fb_ops s3fb_ops = {
824 .owner = THIS_MODULE,
825 .fb_open = s3fb_open,
826 .fb_release = s3fb_release,
827 .fb_check_var = s3fb_check_var,
828 .fb_set_par = s3fb_set_par,
829 .fb_setcolreg = s3fb_setcolreg,
830 .fb_blank = s3fb_blank,
831 .fb_pan_display = s3fb_pan_display,
832 .fb_fillrect = s3fb_fillrect,
833 .fb_copyarea = cfb_copyarea,
834 .fb_imageblit = s3fb_imageblit,
Antonino A. Daplas56c75542007-05-08 00:39:39 -0700835 .fb_get_caps = s3fb_get_caps,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800836};
837
838/* ------------------------------------------------------------------------- */
839
840static int __devinit s3_identification(int chip)
841{
842 if (chip == CHIP_XXX_TRIO) {
843 u8 cr30 = vga_rcrt(NULL, 0x30);
844 u8 cr2e = vga_rcrt(NULL, 0x2e);
845 u8 cr2f = vga_rcrt(NULL, 0x2f);
846
847 if ((cr30 == 0xE0) || (cr30 == 0xE1)) {
848 if (cr2e == 0x10)
849 return CHIP_732_TRIO32;
850 if (cr2e == 0x11) {
851 if (! (cr2f & 0x40))
852 return CHIP_764_TRIO64;
853 else
854 return CHIP_765_TRIO64VP;
855 }
856 }
857 }
858
859 if (chip == CHIP_XXX_TRIO64V2_DXGX) {
860 u8 cr6f = vga_rcrt(NULL, 0x6f);
861
862 if (! (cr6f & 0x01))
863 return CHIP_775_TRIO64V2_DX;
864 else
865 return CHIP_785_TRIO64V2_GX;
866 }
867
868 if (chip == CHIP_XXX_VIRGE_DXGX) {
869 u8 cr6f = vga_rcrt(NULL, 0x6f);
870
871 if (! (cr6f & 0x01))
872 return CHIP_375_VIRGE_DX;
873 else
874 return CHIP_385_VIRGE_GX;
875 }
876
877 return CHIP_UNKNOWN;
878}
879
880
881/* PCI probe */
882
883static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
884{
885 struct fb_info *info;
886 struct s3fb_info *par;
887 int rc;
888 u8 regval, cr38, cr39;
889
890 /* Ignore secondary VGA device because there is no VGA arbitration */
891 if (! svga_primary_device(dev)) {
892 dev_info(&(dev->dev), "ignoring secondary device\n");
893 return -ENODEV;
894 }
895
896 /* Allocate and fill driver data structure */
897 info = framebuffer_alloc(sizeof(struct s3fb_info), NULL);
898 if (!info) {
899 dev_err(&(dev->dev), "cannot allocate memory\n");
900 return -ENOMEM;
901 }
902
903 par = info->par;
904 mutex_init(&par->open_lock);
905
906 info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
907 info->fbops = &s3fb_ops;
908
909 /* Prepare PCI device */
910 rc = pci_enable_device(dev);
911 if (rc < 0) {
912 dev_err(&(dev->dev), "cannot enable PCI device\n");
913 goto err_enable_device;
914 }
915
916 rc = pci_request_regions(dev, "s3fb");
917 if (rc < 0) {
918 dev_err(&(dev->dev), "cannot reserve framebuffer region\n");
919 goto err_request_regions;
920 }
921
922
923 info->fix.smem_start = pci_resource_start(dev, 0);
924 info->fix.smem_len = pci_resource_len(dev, 0);
925
926 /* Map physical IO memory address into kernel space */
927 info->screen_base = pci_iomap(dev, 0, 0);
928 if (! info->screen_base) {
929 rc = -ENOMEM;
930 dev_err(&(dev->dev), "iomap for framebuffer failed\n");
931 goto err_iomap;
932 }
933
934 /* Unlock regs */
935 cr38 = vga_rcrt(NULL, 0x38);
936 cr39 = vga_rcrt(NULL, 0x39);
937 vga_wseq(NULL, 0x08, 0x06);
938 vga_wcrt(NULL, 0x38, 0x48);
939 vga_wcrt(NULL, 0x39, 0xA5);
940
941 /* Find how many physical memory there is on card */
942 /* 0x36 register is accessible even if other registers are locked */
943 regval = vga_rcrt(NULL, 0x36);
944 info->screen_size = s3_memsizes[regval >> 5] << 10;
945 info->fix.smem_len = info->screen_size;
946
947 par->chip = id->driver_data & CHIP_MASK;
948 par->rev = vga_rcrt(NULL, 0x2f);
949 if (par->chip & CHIP_UNDECIDED_FLAG)
950 par->chip = s3_identification(par->chip);
951
952 /* Find MCLK frequency */
953 regval = vga_rseq(NULL, 0x10);
954 par->mclk_freq = ((vga_rseq(NULL, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2);
955 par->mclk_freq = par->mclk_freq >> (regval >> 5);
956
957 /* Restore locks */
958 vga_wcrt(NULL, 0x38, cr38);
959 vga_wcrt(NULL, 0x39, cr39);
960
961 strcpy(info->fix.id, s3_names [par->chip]);
962 info->fix.mmio_start = 0;
963 info->fix.mmio_len = 0;
964 info->fix.type = FB_TYPE_PACKED_PIXELS;
965 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
966 info->fix.ypanstep = 0;
967 info->fix.accel = FB_ACCEL_NONE;
968 info->pseudo_palette = (void*) (par->pseudo_palette);
969
970 /* Prepare startup mode */
971 rc = fb_find_mode(&(info->var), info, mode, NULL, 0, NULL, 8);
972 if (! ((rc == 1) || (rc == 2))) {
973 rc = -EINVAL;
974 dev_err(&(dev->dev), "mode %s not found\n", mode);
975 goto err_find_mode;
976 }
977
978 rc = fb_alloc_cmap(&info->cmap, 256, 0);
979 if (rc < 0) {
980 dev_err(&(dev->dev), "cannot allocate colormap\n");
981 goto err_alloc_cmap;
982 }
983
984 rc = register_framebuffer(info);
985 if (rc < 0) {
986 dev_err(&(dev->dev), "cannot register framebuffer\n");
987 goto err_reg_fb;
988 }
989
990 printk(KERN_INFO "fb%d: %s on %s, %d MB RAM, %d MHz MCLK\n", info->node, info->fix.id,
991 pci_name(dev), info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000);
992
993 if (par->chip == CHIP_UNKNOWN)
994 printk(KERN_INFO "fb%d: unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n",
995 info->node, vga_rcrt(NULL, 0x2d), vga_rcrt(NULL, 0x2e),
996 vga_rcrt(NULL, 0x2f), vga_rcrt(NULL, 0x30));
997
998 /* Record a reference to the driver data */
999 pci_set_drvdata(dev, info);
1000
1001#ifdef CONFIG_MTRR
1002 if (mtrr) {
1003 par->mtrr_reg = -1;
1004 par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
1005 }
1006#endif
1007
1008 return 0;
1009
1010 /* Error handling */
1011err_reg_fb:
1012 fb_dealloc_cmap(&info->cmap);
1013err_alloc_cmap:
1014err_find_mode:
1015 pci_iounmap(dev, info->screen_base);
1016err_iomap:
1017 pci_release_regions(dev);
1018err_request_regions:
1019/* pci_disable_device(dev); */
1020err_enable_device:
1021 framebuffer_release(info);
1022 return rc;
1023}
1024
1025
1026/* PCI remove */
1027
1028static void __devexit s3_pci_remove(struct pci_dev *dev)
1029{
1030 struct fb_info *info = pci_get_drvdata(dev);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001031
1032 if (info) {
1033
1034#ifdef CONFIG_MTRR
Adrian Bunk47ebea82007-03-22 00:11:16 -08001035 struct s3fb_info *par = info->par;
1036
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001037 if (par->mtrr_reg >= 0) {
1038 mtrr_del(par->mtrr_reg, 0, 0);
1039 par->mtrr_reg = -1;
1040 }
1041#endif
1042
1043 unregister_framebuffer(info);
1044 fb_dealloc_cmap(&info->cmap);
1045
1046 pci_iounmap(dev, info->screen_base);
1047 pci_release_regions(dev);
1048/* pci_disable_device(dev); */
1049
1050 pci_set_drvdata(dev, NULL);
1051 framebuffer_release(info);
1052 }
1053}
1054
1055/* PCI suspend */
1056
1057static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state)
1058{
1059 struct fb_info *info = pci_get_drvdata(dev);
1060 struct s3fb_info *par = info->par;
1061
1062 dev_info(&(dev->dev), "suspend\n");
1063
1064 acquire_console_sem();
1065 mutex_lock(&(par->open_lock));
1066
1067 if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
1068 mutex_unlock(&(par->open_lock));
1069 release_console_sem();
1070 return 0;
1071 }
1072
1073 fb_set_suspend(info, 1);
1074
1075 pci_save_state(dev);
1076 pci_disable_device(dev);
1077 pci_set_power_state(dev, pci_choose_state(dev, state));
1078
1079 mutex_unlock(&(par->open_lock));
1080 release_console_sem();
1081
1082 return 0;
1083}
1084
1085
1086/* PCI resume */
1087
1088static int s3_pci_resume(struct pci_dev* dev)
1089{
1090 struct fb_info *info = pci_get_drvdata(dev);
1091 struct s3fb_info *par = info->par;
Randy Dunlap6314db42007-05-08 00:38:11 -07001092 int err;
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001093
1094 dev_info(&(dev->dev), "resume\n");
1095
1096 acquire_console_sem();
1097 mutex_lock(&(par->open_lock));
1098
1099 if (par->ref_count == 0) {
1100 mutex_unlock(&(par->open_lock));
1101 release_console_sem();
1102 return 0;
1103 }
1104
1105 pci_set_power_state(dev, PCI_D0);
1106 pci_restore_state(dev);
Randy Dunlap6314db42007-05-08 00:38:11 -07001107 err = pci_enable_device(dev);
1108 if (err) {
1109 mutex_unlock(&(par->open_lock));
1110 release_console_sem();
1111 dev_err(&(dev->dev), "error %d enabling device for resume\n", err);
1112 return err;
1113 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001114 pci_set_master(dev);
1115
1116 s3fb_set_par(info);
1117 fb_set_suspend(info, 0);
1118
1119 mutex_unlock(&(par->open_lock));
1120 release_console_sem();
1121
1122 return 0;
1123}
1124
1125
1126/* List of boards that we are trying to support */
1127
1128static struct pci_device_id s3_devices[] __devinitdata = {
1129 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO},
1130 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO},
1131 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP},
1132 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP},
1133 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX},
1134 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX},
1135
1136 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE},
1137 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX},
1138 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX},
1139 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_356_VIRGE_GX2},
1140 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_357_VIRGE_GX2P},
1141 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P},
1142
1143 {0, 0, 0, 0, 0, 0, 0}
1144};
1145
1146
1147MODULE_DEVICE_TABLE(pci, s3_devices);
1148
1149static struct pci_driver s3fb_pci_driver = {
1150 .name = "s3fb",
1151 .id_table = s3_devices,
1152 .probe = s3_pci_probe,
1153 .remove = __devexit_p(s3_pci_remove),
1154 .suspend = s3_pci_suspend,
1155 .resume = s3_pci_resume,
1156};
1157
1158/* Parse user speficied options */
1159
1160#ifndef MODULE
1161static int __init s3fb_setup(char *options)
1162{
1163 char *opt;
1164
1165 if (!options || !*options)
1166 return 0;
1167
1168 while ((opt = strsep(&options, ",")) != NULL) {
1169
1170 if (!*opt)
1171 continue;
1172#ifdef CONFIG_MTRR
Ondrej Zajicek62fa4dc2007-02-22 17:00:41 +01001173 else if (!strncmp(opt, "mtrr:", 5))
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001174 mtrr = simple_strtoul(opt + 5, NULL, 0);
1175#endif
Ondrej Zajicek62fa4dc2007-02-22 17:00:41 +01001176 else if (!strncmp(opt, "fasttext:", 9))
1177 fasttext = simple_strtoul(opt + 9, NULL, 0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001178 else
1179 mode = opt;
1180 }
1181
1182 return 0;
1183}
1184#endif
1185
1186/* Cleanup */
1187
1188static void __exit s3fb_cleanup(void)
1189{
1190 pr_debug("s3fb: cleaning up\n");
1191 pci_unregister_driver(&s3fb_pci_driver);
1192}
1193
1194/* Driver Initialisation */
1195
1196static int __init s3fb_init(void)
1197{
1198
1199#ifndef MODULE
1200 char *option = NULL;
1201
1202 if (fb_get_options("s3fb", &option))
1203 return -ENODEV;
1204 s3fb_setup(option);
1205#endif
1206
1207 pr_debug("s3fb: initializing\n");
1208 return pci_register_driver(&s3fb_pci_driver);
1209}
1210
1211/* ------------------------------------------------------------------------- */
1212
1213/* Modularization */
1214
1215module_init(s3fb_init);
1216module_exit(s3fb_cleanup);