blob: be12145681f6a87ab9653718921fde53767dd1a4 [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 Zajicekd4b766a2007-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 Zajiceka2684222007-02-12 00:54:49 -0800678 } else {
David Millerea770782011-01-11 23:51:26 +0000679 svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
680 svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700681 if (par->chip != CHIP_360_TRIO3D_1X &&
682 par->chip != CHIP_362_TRIO3D_2X &&
683 par->chip != CHIP_368_TRIO3D_2X)
684 hmul = 2;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800685 }
686 break;
687 case 5:
688 pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
689 if (par->chip == CHIP_988_VIRGE_VX) {
690 if (info->var.pixclock > 20000)
David Millerea770782011-01-11 23:51:26 +0000691 svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800692 else
David Millerea770782011-01-11 23:51:26 +0000693 svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800694 } else {
David Millerea770782011-01-11 23:51:26 +0000695 svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
696 svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700697 if (par->chip != CHIP_360_TRIO3D_1X &&
698 par->chip != CHIP_362_TRIO3D_2X &&
699 par->chip != CHIP_368_TRIO3D_2X)
700 hmul = 2;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800701 }
702 break;
703 case 6:
704 /* VIRGE VX case */
705 pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000706 svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800707 break;
708 case 7:
709 pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000710 svga_wcrt_mask(par->state.vgabase, 0x50, 0x30, 0x30);
711 svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800712 break;
713 default:
714 printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node);
715 return -EINVAL;
716 }
717
718 if (par->chip != CHIP_988_VIRGE_VX) {
David Millerd907ec02011-01-11 23:51:08 +0000719 svga_wseq_mask(par->state.vgabase, 0x15, multiplex ? 0x10 : 0x00, 0x10);
720 svga_wseq_mask(par->state.vgabase, 0x18, multiplex ? 0x80 : 0x00, 0x80);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800721 }
722
723 s3_set_pixclock(info, info->var.pixclock);
David Miller38d26202011-01-11 23:52:25 +0000724 svga_set_timings(par->state.vgabase, &s3_timing_regs, &(info->var), hmul, 1,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800725 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
726 (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
727 hmul, info->node);
728
729 /* Set interlaced mode start/end register */
730 value = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
731 value = ((value * hmul) / 8) - 5;
David Millerf8645932011-01-11 23:52:57 +0000732 vga_wcrt(par->state.vgabase, 0x3C, (value + 1) / 2);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800733
Antonino A. Daplas75814d82007-05-08 00:38:49 -0700734 memset_io(info->screen_base, 0x00, screen_size);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800735 /* Device and screen back on */
David Millerea770782011-01-11 23:51:26 +0000736 svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
David Millerd907ec02011-01-11 23:51:08 +0000737 svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800738
739 return 0;
740}
741
742/* Set a colour register */
743
744static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
745 u_int transp, struct fb_info *fb)
746{
747 switch (fb->var.bits_per_pixel) {
748 case 0:
749 case 4:
750 if (regno >= 16)
751 return -EINVAL;
752
753 if ((fb->var.bits_per_pixel == 4) &&
754 (fb->var.nonstd == 0)) {
755 outb(0xF0, VGA_PEL_MSK);
756 outb(regno*16, VGA_PEL_IW);
757 } else {
758 outb(0x0F, VGA_PEL_MSK);
759 outb(regno, VGA_PEL_IW);
760 }
761 outb(red >> 10, VGA_PEL_D);
762 outb(green >> 10, VGA_PEL_D);
763 outb(blue >> 10, VGA_PEL_D);
764 break;
765 case 8:
766 if (regno >= 256)
767 return -EINVAL;
768
769 outb(0xFF, VGA_PEL_MSK);
770 outb(regno, VGA_PEL_IW);
771 outb(red >> 10, VGA_PEL_D);
772 outb(green >> 10, VGA_PEL_D);
773 outb(blue >> 10, VGA_PEL_D);
774 break;
775 case 16:
776 if (regno >= 16)
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700777 return 0;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800778
779 if (fb->var.green.length == 5)
780 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
781 ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
782 else if (fb->var.green.length == 6)
783 ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
784 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
785 else return -EINVAL;
786 break;
787 case 24:
788 case 32:
789 if (regno >= 16)
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700790 return 0;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800791
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700792 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800793 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
794 break;
795 default:
796 return -EINVAL;
797 }
798
799 return 0;
800}
801
802
803/* Set the display blanking state */
804
805static int s3fb_blank(int blank_mode, struct fb_info *info)
806{
David Millerd907ec02011-01-11 23:51:08 +0000807 struct s3fb_info *par = info->par;
808
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800809 switch (blank_mode) {
810 case FB_BLANK_UNBLANK:
811 pr_debug("fb%d: unblank\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000812 svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000813 svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800814 break;
815 case FB_BLANK_NORMAL:
816 pr_debug("fb%d: blank\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000817 svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000818 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800819 break;
820 case FB_BLANK_HSYNC_SUSPEND:
821 pr_debug("fb%d: hsync\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000822 svga_wcrt_mask(par->state.vgabase, 0x56, 0x02, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000823 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800824 break;
825 case FB_BLANK_VSYNC_SUSPEND:
826 pr_debug("fb%d: vsync\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000827 svga_wcrt_mask(par->state.vgabase, 0x56, 0x04, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000828 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800829 break;
830 case FB_BLANK_POWERDOWN:
831 pr_debug("fb%d: sync down\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000832 svga_wcrt_mask(par->state.vgabase, 0x56, 0x06, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000833 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800834 break;
835 }
836
837 return 0;
838}
839
840
841/* Pan the display */
842
David Miller21da3862011-01-11 23:49:34 +0000843static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
844{
845 struct s3fb_info *par = info->par;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800846 unsigned int offset;
847
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800848 /* Calculate the offset */
849 if (var->bits_per_pixel == 0) {
850 offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
851 offset = offset >> 2;
852 } else {
853 offset = (var->yoffset * info->fix.line_length) +
854 (var->xoffset * var->bits_per_pixel / 8);
855 offset = offset >> 2;
856 }
857
858 /* Set the offset */
David Miller21da3862011-01-11 23:49:34 +0000859 svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, offset);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800860
861 return 0;
862}
863
864/* ------------------------------------------------------------------------- */
865
866/* Frame buffer operations */
867
868static struct fb_ops s3fb_ops = {
869 .owner = THIS_MODULE,
870 .fb_open = s3fb_open,
871 .fb_release = s3fb_release,
872 .fb_check_var = s3fb_check_var,
873 .fb_set_par = s3fb_set_par,
874 .fb_setcolreg = s3fb_setcolreg,
875 .fb_blank = s3fb_blank,
876 .fb_pan_display = s3fb_pan_display,
877 .fb_fillrect = s3fb_fillrect,
878 .fb_copyarea = cfb_copyarea,
879 .fb_imageblit = s3fb_imageblit,
Antonino A. Daplas5a87ede2007-05-09 02:35:32 -0700880 .fb_get_caps = svga_get_caps,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800881};
882
883/* ------------------------------------------------------------------------- */
884
David Millerf8645932011-01-11 23:52:57 +0000885static int __devinit s3_identification(struct s3fb_info *par)
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800886{
David Millerf8645932011-01-11 23:52:57 +0000887 int chip = par->chip;
888
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800889 if (chip == CHIP_XXX_TRIO) {
David Millerf8645932011-01-11 23:52:57 +0000890 u8 cr30 = vga_rcrt(par->state.vgabase, 0x30);
891 u8 cr2e = vga_rcrt(par->state.vgabase, 0x2e);
892 u8 cr2f = vga_rcrt(par->state.vgabase, 0x2f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800893
894 if ((cr30 == 0xE0) || (cr30 == 0xE1)) {
895 if (cr2e == 0x10)
896 return CHIP_732_TRIO32;
897 if (cr2e == 0x11) {
898 if (! (cr2f & 0x40))
899 return CHIP_764_TRIO64;
900 else
901 return CHIP_765_TRIO64VP;
902 }
903 }
904 }
905
906 if (chip == CHIP_XXX_TRIO64V2_DXGX) {
David Millerf8645932011-01-11 23:52:57 +0000907 u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800908
909 if (! (cr6f & 0x01))
910 return CHIP_775_TRIO64V2_DX;
911 else
912 return CHIP_785_TRIO64V2_GX;
913 }
914
915 if (chip == CHIP_XXX_VIRGE_DXGX) {
David Millerf8645932011-01-11 23:52:57 +0000916 u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800917
918 if (! (cr6f & 0x01))
919 return CHIP_375_VIRGE_DX;
920 else
921 return CHIP_385_VIRGE_GX;
922 }
923
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700924 if (chip == CHIP_36X_TRIO3D_1X_2X) {
David Millerf8645932011-01-11 23:52:57 +0000925 switch (vga_rcrt(par->state.vgabase, 0x2f)) {
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700926 case 0x00:
927 return CHIP_360_TRIO3D_1X;
928 case 0x01:
929 return CHIP_362_TRIO3D_2X;
930 case 0x02:
931 return CHIP_368_TRIO3D_2X;
932 }
933 }
934
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800935 return CHIP_UNKNOWN;
936}
937
938
939/* PCI probe */
940
941static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
942{
David Miller94c322c2011-01-11 23:54:21 +0000943 struct pci_bus_region bus_reg;
944 struct resource vga_res;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800945 struct fb_info *info;
946 struct s3fb_info *par;
947 int rc;
948 u8 regval, cr38, cr39;
949
950 /* Ignore secondary VGA device because there is no VGA arbitration */
951 if (! svga_primary_device(dev)) {
952 dev_info(&(dev->dev), "ignoring secondary device\n");
953 return -ENODEV;
954 }
955
956 /* Allocate and fill driver data structure */
Ondrej Zajicek20e061f2008-04-28 02:15:18 -0700957 info = framebuffer_alloc(sizeof(struct s3fb_info), &(dev->dev));
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800958 if (!info) {
959 dev_err(&(dev->dev), "cannot allocate memory\n");
960 return -ENOMEM;
961 }
962
963 par = info->par;
964 mutex_init(&par->open_lock);
965
966 info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
967 info->fbops = &s3fb_ops;
968
969 /* Prepare PCI device */
970 rc = pci_enable_device(dev);
971 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -0700972 dev_err(info->device, "cannot enable PCI device\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800973 goto err_enable_device;
974 }
975
976 rc = pci_request_regions(dev, "s3fb");
977 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -0700978 dev_err(info->device, "cannot reserve framebuffer region\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800979 goto err_request_regions;
980 }
981
982
983 info->fix.smem_start = pci_resource_start(dev, 0);
984 info->fix.smem_len = pci_resource_len(dev, 0);
985
986 /* Map physical IO memory address into kernel space */
987 info->screen_base = pci_iomap(dev, 0, 0);
988 if (! info->screen_base) {
989 rc = -ENOMEM;
Ondrej Zajicek594a8812008-08-05 13:01:06 -0700990 dev_err(info->device, "iomap for framebuffer failed\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800991 goto err_iomap;
992 }
993
David Miller94c322c2011-01-11 23:54:21 +0000994 bus_reg.start = 0;
995 bus_reg.end = 64 * 1024;
996
997 vga_res.flags = IORESOURCE_IO;
998
999 pcibios_bus_to_resource(dev, &vga_res, &bus_reg);
1000
1001 par->state.vgabase = (void __iomem *) vga_res.start;
1002
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001003 /* Unlock regs */
David Millerf8645932011-01-11 23:52:57 +00001004 cr38 = vga_rcrt(par->state.vgabase, 0x38);
1005 cr39 = vga_rcrt(par->state.vgabase, 0x39);
1006 vga_wseq(par->state.vgabase, 0x08, 0x06);
1007 vga_wcrt(par->state.vgabase, 0x38, 0x48);
1008 vga_wcrt(par->state.vgabase, 0x39, 0xA5);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001009
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001010 /* Identify chip type */
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001011 par->chip = id->driver_data & CHIP_MASK;
David Millerf8645932011-01-11 23:52:57 +00001012 par->rev = vga_rcrt(par->state.vgabase, 0x2f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001013 if (par->chip & CHIP_UNDECIDED_FLAG)
David Millerf8645932011-01-11 23:52:57 +00001014 par->chip = s3_identification(par);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001015
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001016 /* Find how many physical memory there is on card */
1017 /* 0x36 register is accessible even if other registers are locked */
David Millerf8645932011-01-11 23:52:57 +00001018 regval = vga_rcrt(par->state.vgabase, 0x36);
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001019 if (par->chip == CHIP_360_TRIO3D_1X ||
1020 par->chip == CHIP_362_TRIO3D_2X ||
Ondrej Zary5694f9c2011-03-01 19:18:17 +00001021 par->chip == CHIP_368_TRIO3D_2X ||
1022 par->chip == CHIP_365_TRIO3D) {
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001023 switch ((regval & 0xE0) >> 5) {
1024 case 0: /* 8MB -- only 4MB usable for display */
1025 case 1: /* 4MB with 32-bit bus */
1026 case 2: /* 4MB */
1027 info->screen_size = 4 << 20;
1028 break;
Ondrej Zary5694f9c2011-03-01 19:18:17 +00001029 case 4: /* 2MB on 365 Trio3D */
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001030 case 6: /* 2MB */
1031 info->screen_size = 2 << 20;
1032 break;
1033 }
1034 } else
1035 info->screen_size = s3_memsizes[regval >> 5] << 10;
1036 info->fix.smem_len = info->screen_size;
1037
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001038 /* Find MCLK frequency */
David Millerf8645932011-01-11 23:52:57 +00001039 regval = vga_rseq(par->state.vgabase, 0x10);
1040 par->mclk_freq = ((vga_rseq(par->state.vgabase, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001041 par->mclk_freq = par->mclk_freq >> (regval >> 5);
1042
1043 /* Restore locks */
David Millerf8645932011-01-11 23:52:57 +00001044 vga_wcrt(par->state.vgabase, 0x38, cr38);
1045 vga_wcrt(par->state.vgabase, 0x39, cr39);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001046
1047 strcpy(info->fix.id, s3_names [par->chip]);
1048 info->fix.mmio_start = 0;
1049 info->fix.mmio_len = 0;
1050 info->fix.type = FB_TYPE_PACKED_PIXELS;
1051 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1052 info->fix.ypanstep = 0;
1053 info->fix.accel = FB_ACCEL_NONE;
1054 info->pseudo_palette = (void*) (par->pseudo_palette);
1055
1056 /* Prepare startup mode */
Krzysztof Helta8140542008-04-28 02:15:09 -07001057 rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001058 if (! ((rc == 1) || (rc == 2))) {
1059 rc = -EINVAL;
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001060 dev_err(info->device, "mode %s not found\n", mode_option);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001061 goto err_find_mode;
1062 }
1063
Ondrej Zary99d054d2011-03-01 19:18:08 +00001064 /* maximize virtual vertical size for fast scrolling */
1065 info->var.yres_virtual = info->fix.smem_len * 8 /
1066 (info->var.bits_per_pixel * info->var.xres_virtual);
1067 if (info->var.yres_virtual < info->var.yres) {
1068 dev_err(info->device, "virtual vertical size smaller than real\n");
1069 goto err_find_mode;
1070 }
1071
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001072 rc = fb_alloc_cmap(&info->cmap, 256, 0);
1073 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001074 dev_err(info->device, "cannot allocate colormap\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001075 goto err_alloc_cmap;
1076 }
1077
1078 rc = register_framebuffer(info);
1079 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001080 dev_err(info->device, "cannot register framebuffer\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001081 goto err_reg_fb;
1082 }
1083
1084 printk(KERN_INFO "fb%d: %s on %s, %d MB RAM, %d MHz MCLK\n", info->node, info->fix.id,
1085 pci_name(dev), info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000);
1086
1087 if (par->chip == CHIP_UNKNOWN)
1088 printk(KERN_INFO "fb%d: unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n",
David Millerf8645932011-01-11 23:52:57 +00001089 info->node, vga_rcrt(par->state.vgabase, 0x2d), vga_rcrt(par->state.vgabase, 0x2e),
1090 vga_rcrt(par->state.vgabase, 0x2f), vga_rcrt(par->state.vgabase, 0x30));
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001091
1092 /* Record a reference to the driver data */
1093 pci_set_drvdata(dev, info);
1094
1095#ifdef CONFIG_MTRR
1096 if (mtrr) {
1097 par->mtrr_reg = -1;
1098 par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
1099 }
1100#endif
1101
1102 return 0;
1103
1104 /* Error handling */
1105err_reg_fb:
1106 fb_dealloc_cmap(&info->cmap);
1107err_alloc_cmap:
1108err_find_mode:
1109 pci_iounmap(dev, info->screen_base);
1110err_iomap:
1111 pci_release_regions(dev);
1112err_request_regions:
1113/* pci_disable_device(dev); */
1114err_enable_device:
1115 framebuffer_release(info);
1116 return rc;
1117}
1118
1119
1120/* PCI remove */
1121
1122static void __devexit s3_pci_remove(struct pci_dev *dev)
1123{
1124 struct fb_info *info = pci_get_drvdata(dev);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001125
1126 if (info) {
1127
1128#ifdef CONFIG_MTRR
Adrian Bunk47ebea82007-03-22 00:11:16 -08001129 struct s3fb_info *par = info->par;
1130
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001131 if (par->mtrr_reg >= 0) {
1132 mtrr_del(par->mtrr_reg, 0, 0);
1133 par->mtrr_reg = -1;
1134 }
1135#endif
1136
1137 unregister_framebuffer(info);
1138 fb_dealloc_cmap(&info->cmap);
1139
1140 pci_iounmap(dev, info->screen_base);
1141 pci_release_regions(dev);
1142/* pci_disable_device(dev); */
1143
1144 pci_set_drvdata(dev, NULL);
1145 framebuffer_release(info);
1146 }
1147}
1148
1149/* PCI suspend */
1150
1151static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state)
1152{
1153 struct fb_info *info = pci_get_drvdata(dev);
1154 struct s3fb_info *par = info->par;
1155
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001156 dev_info(info->device, "suspend\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001157
Torben Hohnac751ef2011-01-25 15:07:35 -08001158 console_lock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001159 mutex_lock(&(par->open_lock));
1160
1161 if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
1162 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001163 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001164 return 0;
1165 }
1166
1167 fb_set_suspend(info, 1);
1168
1169 pci_save_state(dev);
1170 pci_disable_device(dev);
1171 pci_set_power_state(dev, pci_choose_state(dev, state));
1172
1173 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001174 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001175
1176 return 0;
1177}
1178
1179
1180/* PCI resume */
1181
1182static int s3_pci_resume(struct pci_dev* dev)
1183{
1184 struct fb_info *info = pci_get_drvdata(dev);
1185 struct s3fb_info *par = info->par;
Randy Dunlap6314db42007-05-08 00:38:11 -07001186 int err;
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001187
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001188 dev_info(info->device, "resume\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001189
Torben Hohnac751ef2011-01-25 15:07:35 -08001190 console_lock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001191 mutex_lock(&(par->open_lock));
1192
1193 if (par->ref_count == 0) {
1194 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001195 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001196 return 0;
1197 }
1198
1199 pci_set_power_state(dev, PCI_D0);
1200 pci_restore_state(dev);
Randy Dunlap6314db42007-05-08 00:38:11 -07001201 err = pci_enable_device(dev);
1202 if (err) {
1203 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001204 console_unlock();
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001205 dev_err(info->device, "error %d enabling device for resume\n", err);
Randy Dunlap6314db42007-05-08 00:38:11 -07001206 return err;
1207 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001208 pci_set_master(dev);
1209
1210 s3fb_set_par(info);
1211 fb_set_suspend(info, 0);
1212
1213 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001214 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001215
1216 return 0;
1217}
1218
1219
1220/* List of boards that we are trying to support */
1221
1222static struct pci_device_id s3_devices[] __devinitdata = {
1223 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO},
1224 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO},
1225 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP},
1226 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP},
1227 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX},
1228 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX},
1229
1230 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE},
1231 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX},
1232 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX},
1233 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_356_VIRGE_GX2},
1234 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_357_VIRGE_GX2P},
1235 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P},
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001236 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A13), .driver_data = CHIP_36X_TRIO3D_1X_2X},
Ondrej Zary5694f9c2011-03-01 19:18:17 +00001237 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8904), .driver_data = CHIP_365_TRIO3D},
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001238
1239 {0, 0, 0, 0, 0, 0, 0}
1240};
1241
1242
1243MODULE_DEVICE_TABLE(pci, s3_devices);
1244
1245static struct pci_driver s3fb_pci_driver = {
1246 .name = "s3fb",
1247 .id_table = s3_devices,
1248 .probe = s3_pci_probe,
1249 .remove = __devexit_p(s3_pci_remove),
1250 .suspend = s3_pci_suspend,
1251 .resume = s3_pci_resume,
1252};
1253
1254/* Parse user speficied options */
1255
1256#ifndef MODULE
1257static int __init s3fb_setup(char *options)
1258{
1259 char *opt;
1260
1261 if (!options || !*options)
1262 return 0;
1263
1264 while ((opt = strsep(&options, ",")) != NULL) {
1265
1266 if (!*opt)
1267 continue;
1268#ifdef CONFIG_MTRR
Ondrej Zajicek62fa4dc2007-02-22 17:00:41 +01001269 else if (!strncmp(opt, "mtrr:", 5))
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001270 mtrr = simple_strtoul(opt + 5, NULL, 0);
1271#endif
Ondrej Zajicek62fa4dc2007-02-22 17:00:41 +01001272 else if (!strncmp(opt, "fasttext:", 9))
1273 fasttext = simple_strtoul(opt + 9, NULL, 0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001274 else
Krzysztof Helta8140542008-04-28 02:15:09 -07001275 mode_option = opt;
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001276 }
1277
1278 return 0;
1279}
1280#endif
1281
1282/* Cleanup */
1283
1284static void __exit s3fb_cleanup(void)
1285{
1286 pr_debug("s3fb: cleaning up\n");
1287 pci_unregister_driver(&s3fb_pci_driver);
1288}
1289
1290/* Driver Initialisation */
1291
1292static int __init s3fb_init(void)
1293{
1294
1295#ifndef MODULE
1296 char *option = NULL;
1297
1298 if (fb_get_options("s3fb", &option))
1299 return -ENODEV;
1300 s3fb_setup(option);
1301#endif
1302
1303 pr_debug("s3fb: initializing\n");
1304 return pci_register_driver(&s3fb_pci_driver);
1305}
1306
1307/* ------------------------------------------------------------------------- */
1308
1309/* Modularization */
1310
1311module_init(s3fb_init);
1312module_exit(s3fb_cleanup);