blob: 7b8fdc6d9d55a3a8a35752153b4301cdef32d2d1 [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
Ondrej Zajiceka2684222007-02-12 00:54:49 -080014#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/string.h>
18#include <linux/mm.h>
19#include <linux/tty.h>
Ondrej Zajiceka2684222007-02-12 00:54:49 -080020#include <linux/delay.h>
21#include <linux/fb.h>
22#include <linux/svga.h>
23#include <linux/init.h>
24#include <linux/pci.h>
Torben Hohnac751ef2011-01-25 15:07:35 -080025#include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */
Ondrej Zajiceka2684222007-02-12 00:54:49 -080026#include <video/vga.h>
27
28#ifdef CONFIG_MTRR
29#include <asm/mtrr.h>
30#endif
31
32struct s3fb_info {
33 int chip, rev, mclk_freq;
34 int mtrr_reg;
35 struct vgastate state;
36 struct mutex open_lock;
37 unsigned int ref_count;
38 u32 pseudo_palette[16];
39};
40
41
42/* ------------------------------------------------------------------------- */
43
44static const struct svga_fb_format s3fb_formats[] = {
45 { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
46 FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 16},
Michal Januszewskic26d7b22009-04-13 14:39:49 -070047 { 4, {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0}, 0,
Ondrej Zajiceka2684222007-02-12 00:54:49 -080048 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16},
Michal Januszewskic26d7b22009-04-13 14:39:49 -070049 { 4, {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0}, 1,
Ondrej Zajiceka2684222007-02-12 00:54:49 -080050 FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16},
Michal Januszewskic26d7b22009-04-13 14:39:49 -070051 { 8, {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
Ondrej Zajiceka2684222007-02-12 00:54:49 -080052 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 4, 8},
53 {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
54 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
55 {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
56 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
57 {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
58 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2},
59 {32, {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 SVGA_FORMAT_END
62};
63
64
65static const struct svga_pll s3_pll = {3, 129, 3, 33, 0, 3,
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -070066 35000, 240000, 14318};
Ondrej Zary5694f9c2011-03-01 19:18:17 +000067static const struct svga_pll s3_trio3d_pll = {3, 129, 3, 31, 0, 4,
68 230000, 460000, 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",
Ondrej Zary9966c4f2010-05-26 14:42:27 -070076 "S3 Virge/GX2", "S3 Virge/GX2P", "S3 Virge/GX2P",
Ondrej Zary5694f9c2011-03-01 19:18:17 +000077 "S3 Trio3D/1X", "S3 Trio3D/2X", "S3 Trio3D/2X",
78 "S3 Trio3D"};
Ondrej Zajiceka2684222007-02-12 00:54:49 -080079
80#define CHIP_UNKNOWN 0x00
81#define CHIP_732_TRIO32 0x01
82#define CHIP_764_TRIO64 0x02
83#define CHIP_765_TRIO64VP 0x03
84#define CHIP_767_TRIO64UVP 0x04
85#define CHIP_775_TRIO64V2_DX 0x05
86#define CHIP_785_TRIO64V2_GX 0x06
87#define CHIP_551_PLATO_PX 0x07
88#define CHIP_M65_AURORA64VP 0x08
89#define CHIP_325_VIRGE 0x09
90#define CHIP_988_VIRGE_VX 0x0A
91#define CHIP_375_VIRGE_DX 0x0B
92#define CHIP_385_VIRGE_GX 0x0C
93#define CHIP_356_VIRGE_GX2 0x0D
94#define CHIP_357_VIRGE_GX2P 0x0E
95#define CHIP_359_VIRGE_GX2P 0x0F
Ondrej Zary9966c4f2010-05-26 14:42:27 -070096#define CHIP_360_TRIO3D_1X 0x10
97#define CHIP_362_TRIO3D_2X 0x11
98#define CHIP_368_TRIO3D_2X 0x12
Ondrej Zary5694f9c2011-03-01 19:18:17 +000099#define CHIP_365_TRIO3D 0x13
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800100
101#define CHIP_XXX_TRIO 0x80
102#define CHIP_XXX_TRIO64V2_DXGX 0x81
103#define CHIP_XXX_VIRGE_DXGX 0x82
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700104#define CHIP_36X_TRIO3D_1X_2X 0x83
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800105
106#define CHIP_UNDECIDED_FLAG 0x80
107#define CHIP_MASK 0xFF
108
109/* CRT timing register sets */
110
111static const struct vga_regset s3_h_total_regs[] = {{0x00, 0, 7}, {0x5D, 0, 0}, VGA_REGSET_END};
112static const struct vga_regset s3_h_display_regs[] = {{0x01, 0, 7}, {0x5D, 1, 1}, VGA_REGSET_END};
113static const struct vga_regset s3_h_blank_start_regs[] = {{0x02, 0, 7}, {0x5D, 2, 2}, VGA_REGSET_END};
114static const struct vga_regset s3_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7}, VGA_REGSET_END};
115static const struct vga_regset s3_h_sync_start_regs[] = {{0x04, 0, 7}, {0x5D, 4, 4}, VGA_REGSET_END};
116static const struct vga_regset s3_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
117
118static const struct vga_regset s3_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x5E, 0, 0}, VGA_REGSET_END};
119static const struct vga_regset s3_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x5E, 1, 1}, VGA_REGSET_END};
120static const struct vga_regset s3_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x5E, 2, 2}, VGA_REGSET_END};
121static const struct vga_regset s3_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
122static const struct vga_regset s3_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x5E, 4, 4}, VGA_REGSET_END};
123static const struct vga_regset s3_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
124
125static const struct vga_regset s3_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, {0x5E, 6, 6}, VGA_REGSET_END};
126static const struct vga_regset s3_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x31, 4, 5}, {0x51, 0, 1}, VGA_REGSET_END};
127static const struct vga_regset s3_offset_regs[] = {{0x13, 0, 7}, {0x51, 4, 5}, VGA_REGSET_END}; /* set 0x43 bit 2 to 0 */
128
129static const struct svga_timing_regs s3_timing_regs = {
130 s3_h_total_regs, s3_h_display_regs, s3_h_blank_start_regs,
131 s3_h_blank_end_regs, s3_h_sync_start_regs, s3_h_sync_end_regs,
132 s3_v_total_regs, s3_v_display_regs, s3_v_blank_start_regs,
133 s3_v_blank_end_regs, s3_v_sync_start_regs, s3_v_sync_end_regs,
134};
135
136
137/* ------------------------------------------------------------------------- */
138
139/* Module parameters */
140
141
Krzysztof Helta8140542008-04-28 02:15:09 -0700142static char *mode_option __devinitdata = "640x480-8@60";
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800143
144#ifdef CONFIG_MTRR
Krzysztof Helta8140542008-04-28 02:15:09 -0700145static int mtrr __devinitdata = 1;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800146#endif
147
148static int fasttext = 1;
149
150
151MODULE_AUTHOR("(c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>");
152MODULE_LICENSE("GPL");
153MODULE_DESCRIPTION("fbdev driver for S3 Trio/Virge");
154
Krzysztof Helta8140542008-04-28 02:15:09 -0700155module_param(mode_option, charp, 0444);
156MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)");
157module_param_named(mode, mode_option, charp, 0444);
158MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc) (deprecated)");
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800159
160#ifdef CONFIG_MTRR
161module_param(mtrr, int, 0444);
162MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
163#endif
164
165module_param(fasttext, int, 0644);
166MODULE_PARM_DESC(fasttext, "Enable S3 fast text mode (1=enable, 0=disable, default=1)");
167
168
169/* ------------------------------------------------------------------------- */
170
171/* Set font in S3 fast text mode */
172
173static void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map)
174{
175 const u8 *font = map->data;
Antonino A. Daplas75814d82007-05-08 00:38:49 -0700176 u8 __iomem *fb = (u8 __iomem *) info->screen_base;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800177 int i, c;
178
179 if ((map->width != 8) || (map->height != 16) ||
180 (map->depth != 1) || (map->length != 256)) {
181 printk(KERN_ERR "fb%d: unsupported font parameters: width %d, height %d, depth %d, length %d\n",
182 info->node, map->width, map->height, map->depth, map->length);
183 return;
184 }
185
186 fb += 2;
187 for (i = 0; i < map->height; i++) {
188 for (c = 0; c < map->length; c++) {
Antonino A. Daplas75814d82007-05-08 00:38:49 -0700189 fb_writeb(font[c * map->height + i], fb + c * 4);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800190 }
191 fb += 1024;
192 }
193}
194
David Miller55db0922011-01-11 23:52:11 +0000195static void s3fb_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor)
196{
197 struct s3fb_info *par = info->par;
198
199 svga_tilecursor(par->state.vgabase, info, cursor);
200}
201
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800202static struct fb_tile_ops s3fb_tile_ops = {
203 .fb_settile = svga_settile,
204 .fb_tilecopy = svga_tilecopy,
205 .fb_tilefill = svga_tilefill,
206 .fb_tileblit = svga_tileblit,
David Miller55db0922011-01-11 23:52:11 +0000207 .fb_tilecursor = s3fb_tilecursor,
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700208 .fb_get_tilemax = svga_get_tilemax,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800209};
210
211static struct fb_tile_ops s3fb_fast_tile_ops = {
212 .fb_settile = s3fb_settile_fast,
213 .fb_tilecopy = svga_tilecopy,
214 .fb_tilefill = svga_tilefill,
215 .fb_tileblit = svga_tileblit,
David Miller55db0922011-01-11 23:52:11 +0000216 .fb_tilecursor = s3fb_tilecursor,
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700217 .fb_get_tilemax = svga_get_tilemax,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800218};
219
220
221/* ------------------------------------------------------------------------- */
222
223/* image data is MSB-first, fb structure is MSB-first too */
224static inline u32 expand_color(u32 c)
225{
226 return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
227}
228
229/* s3fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
230static void s3fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
231{
232 u32 fg = expand_color(image->fg_color);
233 u32 bg = expand_color(image->bg_color);
234 const u8 *src1, *src;
235 u8 __iomem *dst1;
236 u32 __iomem *dst;
237 u32 val;
238 int x, y;
239
240 src1 = image->data;
241 dst1 = info->screen_base + (image->dy * info->fix.line_length)
242 + ((image->dx / 8) * 4);
243
244 for (y = 0; y < image->height; y++) {
245 src = src1;
246 dst = (u32 __iomem *) dst1;
247 for (x = 0; x < image->width; x += 8) {
248 val = *(src++) * 0x01010101;
249 val = (val & fg) | (~val & bg);
250 fb_writel(val, dst++);
251 }
252 src1 += image->width / 8;
253 dst1 += info->fix.line_length;
254 }
255
256}
257
258/* s3fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
259static void s3fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
260{
261 u32 fg = expand_color(rect->color);
262 u8 __iomem *dst1;
263 u32 __iomem *dst;
264 int x, y;
265
266 dst1 = info->screen_base + (rect->dy * info->fix.line_length)
267 + ((rect->dx / 8) * 4);
268
269 for (y = 0; y < rect->height; y++) {
270 dst = (u32 __iomem *) dst1;
271 for (x = 0; x < rect->width; x += 8) {
272 fb_writel(fg, dst++);
273 }
274 dst1 += info->fix.line_length;
275 }
276}
277
278
279/* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
280static inline u32 expand_pixel(u32 c)
281{
282 return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
283 ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
284}
285
286/* s3fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
287static void s3fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
288{
289 u32 fg = image->fg_color * 0x11111111;
290 u32 bg = image->bg_color * 0x11111111;
291 const u8 *src1, *src;
292 u8 __iomem *dst1;
293 u32 __iomem *dst;
294 u32 val;
295 int x, y;
296
297 src1 = image->data;
298 dst1 = info->screen_base + (image->dy * info->fix.line_length)
299 + ((image->dx / 8) * 4);
300
301 for (y = 0; y < image->height; y++) {
302 src = src1;
303 dst = (u32 __iomem *) dst1;
304 for (x = 0; x < image->width; x += 8) {
305 val = expand_pixel(*(src++));
306 val = (val & fg) | (~val & bg);
307 fb_writel(val, dst++);
308 }
309 src1 += image->width / 8;
310 dst1 += info->fix.line_length;
311 }
312}
313
314static void s3fb_imageblit(struct fb_info *info, const struct fb_image *image)
315{
316 if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
317 && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
318 if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
319 s3fb_iplan_imageblit(info, image);
320 else
321 s3fb_cfb4_imageblit(info, image);
322 } else
323 cfb_imageblit(info, image);
324}
325
326static void s3fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
327{
328 if ((info->var.bits_per_pixel == 4)
329 && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
330 && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
331 s3fb_iplan_fillrect(info, rect);
332 else
333 cfb_fillrect(info, rect);
334}
335
336
337
338/* ------------------------------------------------------------------------- */
339
340
341static void s3_set_pixclock(struct fb_info *info, u32 pixclock)
342{
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700343 struct s3fb_info *par = info->par;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800344 u16 m, n, r;
345 u8 regval;
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700346 int rv;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800347
Ondrej Zary5694f9c2011-03-01 19:18:17 +0000348 rv = svga_compute_pll((par->chip == CHIP_365_TRIO3D) ? &s3_trio3d_pll : &s3_pll,
349 1000000000 / pixclock, &m, &n, &r, info->node);
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700350 if (rv < 0) {
351 printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node);
352 return;
353 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800354
355 /* Set VGA misc register */
David Millerf8645932011-01-11 23:52:57 +0000356 regval = vga_r(par->state.vgabase, VGA_MIS_R);
357 vga_w(par->state.vgabase, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800358
359 /* Set S3 clock registers */
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700360 if (par->chip == CHIP_360_TRIO3D_1X ||
361 par->chip == CHIP_362_TRIO3D_2X ||
362 par->chip == CHIP_368_TRIO3D_2X) {
David Millerf8645932011-01-11 23:52:57 +0000363 vga_wseq(par->state.vgabase, 0x12, (n - 2) | ((r & 3) << 6)); /* n and two bits of r */
364 vga_wseq(par->state.vgabase, 0x29, r >> 2); /* remaining highest bit of r */
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700365 } else
David Millerf8645932011-01-11 23:52:57 +0000366 vga_wseq(par->state.vgabase, 0x12, (n - 2) | (r << 5));
367 vga_wseq(par->state.vgabase, 0x13, m - 2);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800368
369 udelay(1000);
370
371 /* Activate clock - write 0, 1, 0 to seq/15 bit 5 */
David Millerf8645932011-01-11 23:52:57 +0000372 regval = vga_rseq (par->state.vgabase, 0x15); /* | 0x80; */
373 vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5));
374 vga_wseq(par->state.vgabase, 0x15, regval | (1<<5));
375 vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5));
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800376}
377
378
379/* Open framebuffer */
380
381static int s3fb_open(struct fb_info *info, int user)
382{
383 struct s3fb_info *par = info->par;
384
385 mutex_lock(&(par->open_lock));
386 if (par->ref_count == 0) {
David Miller3ff259f2011-01-11 23:53:53 +0000387 void __iomem *vgabase = par->state.vgabase;
388
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800389 memset(&(par->state), 0, sizeof(struct vgastate));
David Miller3ff259f2011-01-11 23:53:53 +0000390 par->state.vgabase = vgabase;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800391 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
392 par->state.num_crtc = 0x70;
393 par->state.num_seq = 0x20;
394 save_vga(&(par->state));
395 }
396
397 par->ref_count++;
398 mutex_unlock(&(par->open_lock));
399
400 return 0;
401}
402
403/* Close framebuffer */
404
405static int s3fb_release(struct fb_info *info, int user)
406{
407 struct s3fb_info *par = info->par;
408
409 mutex_lock(&(par->open_lock));
410 if (par->ref_count == 0) {
411 mutex_unlock(&(par->open_lock));
412 return -EINVAL;
413 }
414
415 if (par->ref_count == 1)
416 restore_vga(&(par->state));
417
418 par->ref_count--;
419 mutex_unlock(&(par->open_lock));
420
421 return 0;
422}
423
424/* Validate passed in var */
425
426static int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
427{
428 struct s3fb_info *par = info->par;
429 int rv, mem, step;
Krzysztof Heltc3ca34f2007-10-16 01:29:54 -0700430 u16 m, n, r;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800431
432 /* Find appropriate format */
433 rv = svga_match_format (s3fb_formats, var, NULL);
Ondrej Zajicekd4b766a02007-10-16 01:29:52 -0700434
435 /* 32bpp mode is not supported on VIRGE VX,
436 24bpp is not supported on others */
437 if ((par->chip == CHIP_988_VIRGE_VX) ? (rv == 7) : (rv == 6))
438 rv = -EINVAL;
439
440 if (rv < 0) {
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800441 printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node);
442 return rv;
443 }
444
445 /* Do not allow to have real resoulution larger than virtual */
446 if (var->xres > var->xres_virtual)
447 var->xres_virtual = var->xres;
448
449 if (var->yres > var->yres_virtual)
450 var->yres_virtual = var->yres;
451
452 /* Round up xres_virtual to have proper alignment of lines */
453 step = s3fb_formats[rv].xresstep - 1;
454 var->xres_virtual = (var->xres_virtual+step) & ~step;
455
456 /* Check whether have enough memory */
457 mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
Krzysztof Heltc3ca34f2007-10-16 01:29:54 -0700458 if (mem > info->screen_size) {
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800459 printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n",
460 info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
461 return -EINVAL;
462 }
463
464 rv = svga_check_timings (&s3_timing_regs, var, info->node);
Krzysztof Heltc3ca34f2007-10-16 01:29:54 -0700465 if (rv < 0) {
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800466 printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
467 return rv;
468 }
469
Krzysztof Heltc3ca34f2007-10-16 01:29:54 -0700470 rv = svga_compute_pll(&s3_pll, PICOS2KHZ(var->pixclock), &m, &n, &r,
471 info->node);
472 if (rv < 0) {
473 printk(KERN_ERR "fb%d: invalid pixclock value requested\n",
474 info->node);
475 return rv;
476 }
477
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800478 return 0;
479}
480
481/* Set video mode from par */
482
483static int s3fb_set_par(struct fb_info *info)
484{
485 struct s3fb_info *par = info->par;
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700486 u32 value, mode, hmul, offset_value, screen_size, multiplex, dbytes;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800487 u32 bpp = info->var.bits_per_pixel;
488
489 if (bpp != 0) {
490 info->fix.ypanstep = 1;
491 info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
492
493 info->flags &= ~FBINFO_MISC_TILEBLITTING;
494 info->tileops = NULL;
495
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700496 /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
497 info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
Antonino A. Daplas8db51662007-05-08 00:39:14 -0700498 info->pixmap.blit_y = ~(u32)0;
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700499
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800500 offset_value = (info->var.xres_virtual * bpp) / 64;
501 screen_size = info->var.yres_virtual * info->fix.line_length;
502 } else {
503 info->fix.ypanstep = 16;
504 info->fix.line_length = 0;
505
506 info->flags |= FBINFO_MISC_TILEBLITTING;
507 info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops;
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700508
Antonino A. Daplas8db51662007-05-08 00:39:14 -0700509 /* supports 8x16 tiles only */
510 info->pixmap.blit_x = 1 << (8 - 1);
511 info->pixmap.blit_y = 1 << (16 - 1);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800512
513 offset_value = info->var.xres_virtual / 16;
514 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
515 }
516
517 info->var.xoffset = 0;
518 info->var.yoffset = 0;
519 info->var.activate = FB_ACTIVATE_NOW;
520
521 /* Unlock registers */
David Millerf8645932011-01-11 23:52:57 +0000522 vga_wcrt(par->state.vgabase, 0x38, 0x48);
523 vga_wcrt(par->state.vgabase, 0x39, 0xA5);
524 vga_wseq(par->state.vgabase, 0x08, 0x06);
David Millerea770782011-01-11 23:51:26 +0000525 svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x80);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800526
527 /* Blank screen and turn off sync */
David Millerd907ec02011-01-11 23:51:08 +0000528 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
David Millerea770782011-01-11 23:51:26 +0000529 svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800530
531 /* Set default values */
David Millere2fade22011-01-11 23:50:04 +0000532 svga_set_default_gfx_regs(par->state.vgabase);
David Millerf51a14d2011-01-11 23:50:36 +0000533 svga_set_default_atc_regs(par->state.vgabase);
David Millera4ade8392011-01-11 23:50:54 +0000534 svga_set_default_seq_regs(par->state.vgabase);
David Miller1d28fca2011-01-11 23:51:41 +0000535 svga_set_default_crt_regs(par->state.vgabase);
David Miller21da3862011-01-11 23:49:34 +0000536 svga_wcrt_multi(par->state.vgabase, s3_line_compare_regs, 0xFFFFFFFF);
537 svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, 0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800538
539 /* S3 specific initialization */
David Millerea770782011-01-11 23:51:26 +0000540 svga_wcrt_mask(par->state.vgabase, 0x58, 0x10, 0x10); /* enable linear framebuffer */
541 svga_wcrt_mask(par->state.vgabase, 0x31, 0x08, 0x08); /* enable sequencer access to framebuffer above 256 kB */
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800542
David Millerea770782011-01-11 23:51:26 +0000543/* svga_wcrt_mask(par->state.vgabase, 0x33, 0x08, 0x08); */ /* DDR ? */
544/* svga_wcrt_mask(par->state.vgabase, 0x43, 0x01, 0x01); */ /* DDR ? */
545 svga_wcrt_mask(par->state.vgabase, 0x33, 0x00, 0x08); /* no DDR ? */
546 svga_wcrt_mask(par->state.vgabase, 0x43, 0x00, 0x01); /* no DDR ? */
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800547
David Millerea770782011-01-11 23:51:26 +0000548 svga_wcrt_mask(par->state.vgabase, 0x5D, 0x00, 0x28); /* Clear strange HSlen bits */
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800549
David Millerea770782011-01-11 23:51:26 +0000550/* svga_wcrt_mask(par->state.vgabase, 0x58, 0x03, 0x03); */
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800551
David Millerea770782011-01-11 23:51:26 +0000552/* svga_wcrt_mask(par->state.vgabase, 0x53, 0x12, 0x13); */ /* enable MMIO */
553/* svga_wcrt_mask(par->state.vgabase, 0x40, 0x08, 0x08); */ /* enable write buffer */
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800554
555
556 /* Set the offset register */
557 pr_debug("fb%d: offset register : %d\n", info->node, offset_value);
David Miller21da3862011-01-11 23:49:34 +0000558 svga_wcrt_multi(par->state.vgabase, s3_offset_regs, offset_value);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800559
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700560 if (par->chip != CHIP_360_TRIO3D_1X &&
561 par->chip != CHIP_362_TRIO3D_2X &&
562 par->chip != CHIP_368_TRIO3D_2X) {
David Millerf8645932011-01-11 23:52:57 +0000563 vga_wcrt(par->state.vgabase, 0x54, 0x18); /* M parameter */
564 vga_wcrt(par->state.vgabase, 0x60, 0xff); /* N parameter */
565 vga_wcrt(par->state.vgabase, 0x61, 0xff); /* L parameter */
566 vga_wcrt(par->state.vgabase, 0x62, 0xff); /* L parameter */
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700567 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800568
David Millerf8645932011-01-11 23:52:57 +0000569 vga_wcrt(par->state.vgabase, 0x3A, 0x35);
David Millerf6b0cc42011-01-11 23:49:18 +0000570 svga_wattr(par->state.vgabase, 0x33, 0x00);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800571
572 if (info->var.vmode & FB_VMODE_DOUBLE)
David Millerea770782011-01-11 23:51:26 +0000573 svga_wcrt_mask(par->state.vgabase, 0x09, 0x80, 0x80);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800574 else
David Millerea770782011-01-11 23:51:26 +0000575 svga_wcrt_mask(par->state.vgabase, 0x09, 0x00, 0x80);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800576
577 if (info->var.vmode & FB_VMODE_INTERLACED)
David Millerea770782011-01-11 23:51:26 +0000578 svga_wcrt_mask(par->state.vgabase, 0x42, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800579 else
David Millerea770782011-01-11 23:51:26 +0000580 svga_wcrt_mask(par->state.vgabase, 0x42, 0x00, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800581
582 /* Disable hardware graphics cursor */
David Millerea770782011-01-11 23:51:26 +0000583 svga_wcrt_mask(par->state.vgabase, 0x45, 0x00, 0x01);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800584 /* Disable Streams engine */
David Millerea770782011-01-11 23:51:26 +0000585 svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0x0C);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800586
587 mode = svga_match_format(s3fb_formats, &(info->var), &(info->fix));
588
589 /* S3 virge DX hack */
590 if (par->chip == CHIP_375_VIRGE_DX) {
David Millerf8645932011-01-11 23:52:57 +0000591 vga_wcrt(par->state.vgabase, 0x86, 0x80);
592 vga_wcrt(par->state.vgabase, 0x90, 0x00);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800593 }
594
595 /* S3 virge VX hack */
596 if (par->chip == CHIP_988_VIRGE_VX) {
David Millerf8645932011-01-11 23:52:57 +0000597 vga_wcrt(par->state.vgabase, 0x50, 0x00);
598 vga_wcrt(par->state.vgabase, 0x67, 0x50);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800599
David Millerf8645932011-01-11 23:52:57 +0000600 vga_wcrt(par->state.vgabase, 0x63, (mode <= 2) ? 0x90 : 0x09);
601 vga_wcrt(par->state.vgabase, 0x66, 0x90);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800602 }
603
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700604 if (par->chip == CHIP_360_TRIO3D_1X ||
605 par->chip == CHIP_362_TRIO3D_2X ||
Ondrej Zary5694f9c2011-03-01 19:18:17 +0000606 par->chip == CHIP_368_TRIO3D_2X ||
607 par->chip == CHIP_365_TRIO3D) {
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700608 dbytes = info->var.xres * ((bpp+7)/8);
David Millerf8645932011-01-11 23:52:57 +0000609 vga_wcrt(par->state.vgabase, 0x91, (dbytes + 7) / 8);
610 vga_wcrt(par->state.vgabase, 0x90, (((dbytes + 7) / 8) >> 8) | 0x80);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700611
David Millerf8645932011-01-11 23:52:57 +0000612 vga_wcrt(par->state.vgabase, 0x66, 0x81);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700613 }
614
David Millerea770782011-01-11 23:51:26 +0000615 svga_wcrt_mask(par->state.vgabase, 0x31, 0x00, 0x40);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800616 multiplex = 0;
617 hmul = 1;
618
619 /* Set mode-specific register values */
620 switch (mode) {
621 case 0:
622 pr_debug("fb%d: text mode\n", info->node);
David Miller9c963942011-01-11 23:51:56 +0000623 svga_set_textmode_vga_regs(par->state.vgabase);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800624
625 /* Set additional registers like in 8-bit mode */
David Millerea770782011-01-11 23:51:26 +0000626 svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
627 svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800628
629 /* Disable enhanced mode */
David Millerea770782011-01-11 23:51:26 +0000630 svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800631
632 if (fasttext) {
633 pr_debug("fb%d: high speed text mode set\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000634 svga_wcrt_mask(par->state.vgabase, 0x31, 0x40, 0x40);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800635 }
636 break;
637 case 1:
638 pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
David Millerf8645932011-01-11 23:52:57 +0000639 vga_wgfx(par->state.vgabase, VGA_GFX_MODE, 0x40);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800640
641 /* Set additional registers like in 8-bit mode */
David Millerea770782011-01-11 23:51:26 +0000642 svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
643 svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800644
645 /* disable enhanced mode */
David Millerea770782011-01-11 23:51:26 +0000646 svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800647 break;
648 case 2:
649 pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
650
651 /* Set additional registers like in 8-bit mode */
David Millerea770782011-01-11 23:51:26 +0000652 svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
653 svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800654
655 /* disable enhanced mode */
David Millerea770782011-01-11 23:51:26 +0000656 svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800657 break;
658 case 3:
659 pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000660 svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700661 if (info->var.pixclock > 20000 ||
662 par->chip == CHIP_360_TRIO3D_1X ||
663 par->chip == CHIP_362_TRIO3D_2X ||
664 par->chip == CHIP_368_TRIO3D_2X)
David Millerea770782011-01-11 23:51:26 +0000665 svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700666 else {
David Millerea770782011-01-11 23:51:26 +0000667 svga_wcrt_mask(par->state.vgabase, 0x67, 0x10, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800668 multiplex = 1;
669 }
670 break;
671 case 4:
672 pr_debug("fb%d: 5/5/5 truecolor\n", info->node);
673 if (par->chip == CHIP_988_VIRGE_VX) {
674 if (info->var.pixclock > 20000)
David Millerea770782011-01-11 23:51:26 +0000675 svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800676 else
David Millerea770782011-01-11 23:51:26 +0000677 svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
Ondrej Zary3827d102011-03-01 19:18:27 +0000678 } else if (par->chip == CHIP_365_TRIO3D) {
679 svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
680 if (info->var.pixclock > 8695) {
681 svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
682 hmul = 2;
683 } else {
684 svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0);
685 multiplex = 1;
686 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800687 } else {
David Millerea770782011-01-11 23:51:26 +0000688 svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
689 svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700690 if (par->chip != CHIP_360_TRIO3D_1X &&
691 par->chip != CHIP_362_TRIO3D_2X &&
692 par->chip != CHIP_368_TRIO3D_2X)
693 hmul = 2;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800694 }
695 break;
696 case 5:
697 pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
698 if (par->chip == CHIP_988_VIRGE_VX) {
699 if (info->var.pixclock > 20000)
David Millerea770782011-01-11 23:51:26 +0000700 svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800701 else
David Millerea770782011-01-11 23:51:26 +0000702 svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
Ondrej Zary3827d102011-03-01 19:18:27 +0000703 } else if (par->chip == CHIP_365_TRIO3D) {
704 svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
705 if (info->var.pixclock > 8695) {
706 svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
707 hmul = 2;
708 } else {
709 svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0);
710 multiplex = 1;
711 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800712 } else {
David Millerea770782011-01-11 23:51:26 +0000713 svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
714 svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700715 if (par->chip != CHIP_360_TRIO3D_1X &&
716 par->chip != CHIP_362_TRIO3D_2X &&
717 par->chip != CHIP_368_TRIO3D_2X)
718 hmul = 2;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800719 }
720 break;
721 case 6:
722 /* VIRGE VX case */
723 pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000724 svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800725 break;
726 case 7:
727 pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000728 svga_wcrt_mask(par->state.vgabase, 0x50, 0x30, 0x30);
729 svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800730 break;
731 default:
732 printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node);
733 return -EINVAL;
734 }
735
736 if (par->chip != CHIP_988_VIRGE_VX) {
David Millerd907ec02011-01-11 23:51:08 +0000737 svga_wseq_mask(par->state.vgabase, 0x15, multiplex ? 0x10 : 0x00, 0x10);
738 svga_wseq_mask(par->state.vgabase, 0x18, multiplex ? 0x80 : 0x00, 0x80);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800739 }
740
741 s3_set_pixclock(info, info->var.pixclock);
David Miller38d26202011-01-11 23:52:25 +0000742 svga_set_timings(par->state.vgabase, &s3_timing_regs, &(info->var), hmul, 1,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800743 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
744 (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
745 hmul, info->node);
746
747 /* Set interlaced mode start/end register */
748 value = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
749 value = ((value * hmul) / 8) - 5;
David Millerf8645932011-01-11 23:52:57 +0000750 vga_wcrt(par->state.vgabase, 0x3C, (value + 1) / 2);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800751
Antonino A. Daplas75814d82007-05-08 00:38:49 -0700752 memset_io(info->screen_base, 0x00, screen_size);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800753 /* Device and screen back on */
David Millerea770782011-01-11 23:51:26 +0000754 svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
David Millerd907ec02011-01-11 23:51:08 +0000755 svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800756
757 return 0;
758}
759
760/* Set a colour register */
761
762static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
763 u_int transp, struct fb_info *fb)
764{
765 switch (fb->var.bits_per_pixel) {
766 case 0:
767 case 4:
768 if (regno >= 16)
769 return -EINVAL;
770
771 if ((fb->var.bits_per_pixel == 4) &&
772 (fb->var.nonstd == 0)) {
773 outb(0xF0, VGA_PEL_MSK);
774 outb(regno*16, VGA_PEL_IW);
775 } else {
776 outb(0x0F, VGA_PEL_MSK);
777 outb(regno, VGA_PEL_IW);
778 }
779 outb(red >> 10, VGA_PEL_D);
780 outb(green >> 10, VGA_PEL_D);
781 outb(blue >> 10, VGA_PEL_D);
782 break;
783 case 8:
784 if (regno >= 256)
785 return -EINVAL;
786
787 outb(0xFF, VGA_PEL_MSK);
788 outb(regno, VGA_PEL_IW);
789 outb(red >> 10, VGA_PEL_D);
790 outb(green >> 10, VGA_PEL_D);
791 outb(blue >> 10, VGA_PEL_D);
792 break;
793 case 16:
794 if (regno >= 16)
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700795 return 0;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800796
797 if (fb->var.green.length == 5)
798 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
799 ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
800 else if (fb->var.green.length == 6)
801 ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
802 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
803 else return -EINVAL;
804 break;
805 case 24:
806 case 32:
807 if (regno >= 16)
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700808 return 0;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800809
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700810 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800811 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
812 break;
813 default:
814 return -EINVAL;
815 }
816
817 return 0;
818}
819
820
821/* Set the display blanking state */
822
823static int s3fb_blank(int blank_mode, struct fb_info *info)
824{
David Millerd907ec02011-01-11 23:51:08 +0000825 struct s3fb_info *par = info->par;
826
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800827 switch (blank_mode) {
828 case FB_BLANK_UNBLANK:
829 pr_debug("fb%d: unblank\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000830 svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000831 svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800832 break;
833 case FB_BLANK_NORMAL:
834 pr_debug("fb%d: blank\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000835 svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000836 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800837 break;
838 case FB_BLANK_HSYNC_SUSPEND:
839 pr_debug("fb%d: hsync\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000840 svga_wcrt_mask(par->state.vgabase, 0x56, 0x02, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000841 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800842 break;
843 case FB_BLANK_VSYNC_SUSPEND:
844 pr_debug("fb%d: vsync\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000845 svga_wcrt_mask(par->state.vgabase, 0x56, 0x04, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000846 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800847 break;
848 case FB_BLANK_POWERDOWN:
849 pr_debug("fb%d: sync down\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000850 svga_wcrt_mask(par->state.vgabase, 0x56, 0x06, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000851 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800852 break;
853 }
854
855 return 0;
856}
857
858
859/* Pan the display */
860
David Miller21da3862011-01-11 23:49:34 +0000861static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
862{
863 struct s3fb_info *par = info->par;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800864 unsigned int offset;
865
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800866 /* Calculate the offset */
867 if (var->bits_per_pixel == 0) {
868 offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
869 offset = offset >> 2;
870 } else {
871 offset = (var->yoffset * info->fix.line_length) +
872 (var->xoffset * var->bits_per_pixel / 8);
873 offset = offset >> 2;
874 }
875
876 /* Set the offset */
David Miller21da3862011-01-11 23:49:34 +0000877 svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, offset);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800878
879 return 0;
880}
881
882/* ------------------------------------------------------------------------- */
883
884/* Frame buffer operations */
885
886static struct fb_ops s3fb_ops = {
887 .owner = THIS_MODULE,
888 .fb_open = s3fb_open,
889 .fb_release = s3fb_release,
890 .fb_check_var = s3fb_check_var,
891 .fb_set_par = s3fb_set_par,
892 .fb_setcolreg = s3fb_setcolreg,
893 .fb_blank = s3fb_blank,
894 .fb_pan_display = s3fb_pan_display,
895 .fb_fillrect = s3fb_fillrect,
896 .fb_copyarea = cfb_copyarea,
897 .fb_imageblit = s3fb_imageblit,
Antonino A. Daplas5a87ede2007-05-09 02:35:32 -0700898 .fb_get_caps = svga_get_caps,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800899};
900
901/* ------------------------------------------------------------------------- */
902
David Millerf8645932011-01-11 23:52:57 +0000903static int __devinit s3_identification(struct s3fb_info *par)
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800904{
David Millerf8645932011-01-11 23:52:57 +0000905 int chip = par->chip;
906
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800907 if (chip == CHIP_XXX_TRIO) {
David Millerf8645932011-01-11 23:52:57 +0000908 u8 cr30 = vga_rcrt(par->state.vgabase, 0x30);
909 u8 cr2e = vga_rcrt(par->state.vgabase, 0x2e);
910 u8 cr2f = vga_rcrt(par->state.vgabase, 0x2f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800911
912 if ((cr30 == 0xE0) || (cr30 == 0xE1)) {
913 if (cr2e == 0x10)
914 return CHIP_732_TRIO32;
915 if (cr2e == 0x11) {
916 if (! (cr2f & 0x40))
917 return CHIP_764_TRIO64;
918 else
919 return CHIP_765_TRIO64VP;
920 }
921 }
922 }
923
924 if (chip == CHIP_XXX_TRIO64V2_DXGX) {
David Millerf8645932011-01-11 23:52:57 +0000925 u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800926
927 if (! (cr6f & 0x01))
928 return CHIP_775_TRIO64V2_DX;
929 else
930 return CHIP_785_TRIO64V2_GX;
931 }
932
933 if (chip == CHIP_XXX_VIRGE_DXGX) {
David Millerf8645932011-01-11 23:52:57 +0000934 u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800935
936 if (! (cr6f & 0x01))
937 return CHIP_375_VIRGE_DX;
938 else
939 return CHIP_385_VIRGE_GX;
940 }
941
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700942 if (chip == CHIP_36X_TRIO3D_1X_2X) {
David Millerf8645932011-01-11 23:52:57 +0000943 switch (vga_rcrt(par->state.vgabase, 0x2f)) {
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700944 case 0x00:
945 return CHIP_360_TRIO3D_1X;
946 case 0x01:
947 return CHIP_362_TRIO3D_2X;
948 case 0x02:
949 return CHIP_368_TRIO3D_2X;
950 }
951 }
952
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800953 return CHIP_UNKNOWN;
954}
955
956
957/* PCI probe */
958
959static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
960{
David Miller94c322c2011-01-11 23:54:21 +0000961 struct pci_bus_region bus_reg;
962 struct resource vga_res;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800963 struct fb_info *info;
964 struct s3fb_info *par;
965 int rc;
966 u8 regval, cr38, cr39;
967
968 /* Ignore secondary VGA device because there is no VGA arbitration */
969 if (! svga_primary_device(dev)) {
970 dev_info(&(dev->dev), "ignoring secondary device\n");
971 return -ENODEV;
972 }
973
974 /* Allocate and fill driver data structure */
Ondrej Zajicek20e061f2008-04-28 02:15:18 -0700975 info = framebuffer_alloc(sizeof(struct s3fb_info), &(dev->dev));
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800976 if (!info) {
977 dev_err(&(dev->dev), "cannot allocate memory\n");
978 return -ENOMEM;
979 }
980
981 par = info->par;
982 mutex_init(&par->open_lock);
983
984 info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
985 info->fbops = &s3fb_ops;
986
987 /* Prepare PCI device */
988 rc = pci_enable_device(dev);
989 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -0700990 dev_err(info->device, "cannot enable PCI device\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800991 goto err_enable_device;
992 }
993
994 rc = pci_request_regions(dev, "s3fb");
995 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -0700996 dev_err(info->device, "cannot reserve framebuffer region\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800997 goto err_request_regions;
998 }
999
1000
1001 info->fix.smem_start = pci_resource_start(dev, 0);
1002 info->fix.smem_len = pci_resource_len(dev, 0);
1003
1004 /* Map physical IO memory address into kernel space */
1005 info->screen_base = pci_iomap(dev, 0, 0);
1006 if (! info->screen_base) {
1007 rc = -ENOMEM;
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001008 dev_err(info->device, "iomap for framebuffer failed\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001009 goto err_iomap;
1010 }
1011
David Miller94c322c2011-01-11 23:54:21 +00001012 bus_reg.start = 0;
1013 bus_reg.end = 64 * 1024;
1014
1015 vga_res.flags = IORESOURCE_IO;
1016
1017 pcibios_bus_to_resource(dev, &vga_res, &bus_reg);
1018
1019 par->state.vgabase = (void __iomem *) vga_res.start;
1020
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001021 /* Unlock regs */
David Millerf8645932011-01-11 23:52:57 +00001022 cr38 = vga_rcrt(par->state.vgabase, 0x38);
1023 cr39 = vga_rcrt(par->state.vgabase, 0x39);
1024 vga_wseq(par->state.vgabase, 0x08, 0x06);
1025 vga_wcrt(par->state.vgabase, 0x38, 0x48);
1026 vga_wcrt(par->state.vgabase, 0x39, 0xA5);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001027
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001028 /* Identify chip type */
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001029 par->chip = id->driver_data & CHIP_MASK;
David Millerf8645932011-01-11 23:52:57 +00001030 par->rev = vga_rcrt(par->state.vgabase, 0x2f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001031 if (par->chip & CHIP_UNDECIDED_FLAG)
David Millerf8645932011-01-11 23:52:57 +00001032 par->chip = s3_identification(par);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001033
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001034 /* Find how many physical memory there is on card */
1035 /* 0x36 register is accessible even if other registers are locked */
David Millerf8645932011-01-11 23:52:57 +00001036 regval = vga_rcrt(par->state.vgabase, 0x36);
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001037 if (par->chip == CHIP_360_TRIO3D_1X ||
1038 par->chip == CHIP_362_TRIO3D_2X ||
Ondrej Zary5694f9c2011-03-01 19:18:17 +00001039 par->chip == CHIP_368_TRIO3D_2X ||
1040 par->chip == CHIP_365_TRIO3D) {
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001041 switch ((regval & 0xE0) >> 5) {
1042 case 0: /* 8MB -- only 4MB usable for display */
1043 case 1: /* 4MB with 32-bit bus */
1044 case 2: /* 4MB */
1045 info->screen_size = 4 << 20;
1046 break;
Ondrej Zary5694f9c2011-03-01 19:18:17 +00001047 case 4: /* 2MB on 365 Trio3D */
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001048 case 6: /* 2MB */
1049 info->screen_size = 2 << 20;
1050 break;
1051 }
1052 } else
1053 info->screen_size = s3_memsizes[regval >> 5] << 10;
1054 info->fix.smem_len = info->screen_size;
1055
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001056 /* Find MCLK frequency */
David Millerf8645932011-01-11 23:52:57 +00001057 regval = vga_rseq(par->state.vgabase, 0x10);
1058 par->mclk_freq = ((vga_rseq(par->state.vgabase, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001059 par->mclk_freq = par->mclk_freq >> (regval >> 5);
1060
1061 /* Restore locks */
David Millerf8645932011-01-11 23:52:57 +00001062 vga_wcrt(par->state.vgabase, 0x38, cr38);
1063 vga_wcrt(par->state.vgabase, 0x39, cr39);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001064
1065 strcpy(info->fix.id, s3_names [par->chip]);
1066 info->fix.mmio_start = 0;
1067 info->fix.mmio_len = 0;
1068 info->fix.type = FB_TYPE_PACKED_PIXELS;
1069 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1070 info->fix.ypanstep = 0;
1071 info->fix.accel = FB_ACCEL_NONE;
1072 info->pseudo_palette = (void*) (par->pseudo_palette);
1073
1074 /* Prepare startup mode */
Krzysztof Helta8140542008-04-28 02:15:09 -07001075 rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001076 if (! ((rc == 1) || (rc == 2))) {
1077 rc = -EINVAL;
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001078 dev_err(info->device, "mode %s not found\n", mode_option);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001079 goto err_find_mode;
1080 }
1081
Ondrej Zary99d054d2011-03-01 19:18:08 +00001082 /* maximize virtual vertical size for fast scrolling */
1083 info->var.yres_virtual = info->fix.smem_len * 8 /
1084 (info->var.bits_per_pixel * info->var.xres_virtual);
1085 if (info->var.yres_virtual < info->var.yres) {
1086 dev_err(info->device, "virtual vertical size smaller than real\n");
1087 goto err_find_mode;
1088 }
1089
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001090 rc = fb_alloc_cmap(&info->cmap, 256, 0);
1091 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001092 dev_err(info->device, "cannot allocate colormap\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001093 goto err_alloc_cmap;
1094 }
1095
1096 rc = register_framebuffer(info);
1097 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001098 dev_err(info->device, "cannot register framebuffer\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001099 goto err_reg_fb;
1100 }
1101
1102 printk(KERN_INFO "fb%d: %s on %s, %d MB RAM, %d MHz MCLK\n", info->node, info->fix.id,
1103 pci_name(dev), info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000);
1104
1105 if (par->chip == CHIP_UNKNOWN)
1106 printk(KERN_INFO "fb%d: unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n",
David Millerf8645932011-01-11 23:52:57 +00001107 info->node, vga_rcrt(par->state.vgabase, 0x2d), vga_rcrt(par->state.vgabase, 0x2e),
1108 vga_rcrt(par->state.vgabase, 0x2f), vga_rcrt(par->state.vgabase, 0x30));
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001109
1110 /* Record a reference to the driver data */
1111 pci_set_drvdata(dev, info);
1112
1113#ifdef CONFIG_MTRR
1114 if (mtrr) {
1115 par->mtrr_reg = -1;
1116 par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
1117 }
1118#endif
1119
1120 return 0;
1121
1122 /* Error handling */
1123err_reg_fb:
1124 fb_dealloc_cmap(&info->cmap);
1125err_alloc_cmap:
1126err_find_mode:
1127 pci_iounmap(dev, info->screen_base);
1128err_iomap:
1129 pci_release_regions(dev);
1130err_request_regions:
1131/* pci_disable_device(dev); */
1132err_enable_device:
1133 framebuffer_release(info);
1134 return rc;
1135}
1136
1137
1138/* PCI remove */
1139
1140static void __devexit s3_pci_remove(struct pci_dev *dev)
1141{
1142 struct fb_info *info = pci_get_drvdata(dev);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001143
1144 if (info) {
1145
1146#ifdef CONFIG_MTRR
Adrian Bunk47ebea82007-03-22 00:11:16 -08001147 struct s3fb_info *par = info->par;
1148
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001149 if (par->mtrr_reg >= 0) {
1150 mtrr_del(par->mtrr_reg, 0, 0);
1151 par->mtrr_reg = -1;
1152 }
1153#endif
1154
1155 unregister_framebuffer(info);
1156 fb_dealloc_cmap(&info->cmap);
1157
1158 pci_iounmap(dev, info->screen_base);
1159 pci_release_regions(dev);
1160/* pci_disable_device(dev); */
1161
1162 pci_set_drvdata(dev, NULL);
1163 framebuffer_release(info);
1164 }
1165}
1166
1167/* PCI suspend */
1168
1169static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state)
1170{
1171 struct fb_info *info = pci_get_drvdata(dev);
1172 struct s3fb_info *par = info->par;
1173
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001174 dev_info(info->device, "suspend\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001175
Torben Hohnac751ef2011-01-25 15:07:35 -08001176 console_lock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001177 mutex_lock(&(par->open_lock));
1178
1179 if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
1180 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001181 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001182 return 0;
1183 }
1184
1185 fb_set_suspend(info, 1);
1186
1187 pci_save_state(dev);
1188 pci_disable_device(dev);
1189 pci_set_power_state(dev, pci_choose_state(dev, state));
1190
1191 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001192 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001193
1194 return 0;
1195}
1196
1197
1198/* PCI resume */
1199
1200static int s3_pci_resume(struct pci_dev* dev)
1201{
1202 struct fb_info *info = pci_get_drvdata(dev);
1203 struct s3fb_info *par = info->par;
Randy Dunlap6314db42007-05-08 00:38:11 -07001204 int err;
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001205
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001206 dev_info(info->device, "resume\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001207
Torben Hohnac751ef2011-01-25 15:07:35 -08001208 console_lock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001209 mutex_lock(&(par->open_lock));
1210
1211 if (par->ref_count == 0) {
1212 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001213 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001214 return 0;
1215 }
1216
1217 pci_set_power_state(dev, PCI_D0);
1218 pci_restore_state(dev);
Randy Dunlap6314db42007-05-08 00:38:11 -07001219 err = pci_enable_device(dev);
1220 if (err) {
1221 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001222 console_unlock();
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001223 dev_err(info->device, "error %d enabling device for resume\n", err);
Randy Dunlap6314db42007-05-08 00:38:11 -07001224 return err;
1225 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001226 pci_set_master(dev);
1227
1228 s3fb_set_par(info);
1229 fb_set_suspend(info, 0);
1230
1231 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001232 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001233
1234 return 0;
1235}
1236
1237
1238/* List of boards that we are trying to support */
1239
1240static struct pci_device_id s3_devices[] __devinitdata = {
1241 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO},
1242 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO},
1243 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP},
1244 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP},
1245 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX},
1246 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX},
1247
1248 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE},
1249 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX},
1250 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX},
1251 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_356_VIRGE_GX2},
1252 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_357_VIRGE_GX2P},
1253 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P},
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001254 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A13), .driver_data = CHIP_36X_TRIO3D_1X_2X},
Ondrej Zary5694f9c2011-03-01 19:18:17 +00001255 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8904), .driver_data = CHIP_365_TRIO3D},
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001256
1257 {0, 0, 0, 0, 0, 0, 0}
1258};
1259
1260
1261MODULE_DEVICE_TABLE(pci, s3_devices);
1262
1263static struct pci_driver s3fb_pci_driver = {
1264 .name = "s3fb",
1265 .id_table = s3_devices,
1266 .probe = s3_pci_probe,
1267 .remove = __devexit_p(s3_pci_remove),
1268 .suspend = s3_pci_suspend,
1269 .resume = s3_pci_resume,
1270};
1271
1272/* Parse user speficied options */
1273
1274#ifndef MODULE
1275static int __init s3fb_setup(char *options)
1276{
1277 char *opt;
1278
1279 if (!options || !*options)
1280 return 0;
1281
1282 while ((opt = strsep(&options, ",")) != NULL) {
1283
1284 if (!*opt)
1285 continue;
1286#ifdef CONFIG_MTRR
Ondrej Zajicek62fa4dc2007-02-22 17:00:41 +01001287 else if (!strncmp(opt, "mtrr:", 5))
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001288 mtrr = simple_strtoul(opt + 5, NULL, 0);
1289#endif
Ondrej Zajicek62fa4dc2007-02-22 17:00:41 +01001290 else if (!strncmp(opt, "fasttext:", 9))
1291 fasttext = simple_strtoul(opt + 9, NULL, 0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001292 else
Krzysztof Helta8140542008-04-28 02:15:09 -07001293 mode_option = opt;
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001294 }
1295
1296 return 0;
1297}
1298#endif
1299
1300/* Cleanup */
1301
1302static void __exit s3fb_cleanup(void)
1303{
1304 pr_debug("s3fb: cleaning up\n");
1305 pci_unregister_driver(&s3fb_pci_driver);
1306}
1307
1308/* Driver Initialisation */
1309
1310static int __init s3fb_init(void)
1311{
1312
1313#ifndef MODULE
1314 char *option = NULL;
1315
1316 if (fb_get_options("s3fb", &option))
1317 return -ENODEV;
1318 s3fb_setup(option);
1319#endif
1320
1321 pr_debug("s3fb: initializing\n");
1322 return pci_register_driver(&s3fb_pci_driver);
1323}
1324
1325/* ------------------------------------------------------------------------- */
1326
1327/* Modularization */
1328
1329module_init(s3fb_init);
1330module_exit(s3fb_cleanup);