blob: ddedad9cd06971aa94a598f4a8930185e43982c7 [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};
Ondrej Zary7fe029d2011-03-01 19:18:43 +0000126static const struct vga_regset s3_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x69, 0, 4}, VGA_REGSET_END};
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800127static const struct vga_regset s3_offset_regs[] = {{0x13, 0, 7}, {0x51, 4, 5}, VGA_REGSET_END}; /* set 0x43 bit 2 to 0 */
128
Ondrej Zarycb11c042011-03-01 19:18:35 +0000129static const struct vga_regset s3_dtpc_regs[] = {{0x3B, 0, 7}, {0x5D, 6, 6}, VGA_REGSET_END};
130
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800131static const struct svga_timing_regs s3_timing_regs = {
132 s3_h_total_regs, s3_h_display_regs, s3_h_blank_start_regs,
133 s3_h_blank_end_regs, s3_h_sync_start_regs, s3_h_sync_end_regs,
134 s3_v_total_regs, s3_v_display_regs, s3_v_blank_start_regs,
135 s3_v_blank_end_regs, s3_v_sync_start_regs, s3_v_sync_end_regs,
136};
137
138
139/* ------------------------------------------------------------------------- */
140
141/* Module parameters */
142
143
Krzysztof Helta8140542008-04-28 02:15:09 -0700144static char *mode_option __devinitdata = "640x480-8@60";
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800145
146#ifdef CONFIG_MTRR
Krzysztof Helta8140542008-04-28 02:15:09 -0700147static int mtrr __devinitdata = 1;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800148#endif
149
150static int fasttext = 1;
151
152
153MODULE_AUTHOR("(c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>");
154MODULE_LICENSE("GPL");
155MODULE_DESCRIPTION("fbdev driver for S3 Trio/Virge");
156
Krzysztof Helta8140542008-04-28 02:15:09 -0700157module_param(mode_option, charp, 0444);
158MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)");
159module_param_named(mode, mode_option, charp, 0444);
160MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc) (deprecated)");
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800161
162#ifdef CONFIG_MTRR
163module_param(mtrr, int, 0444);
164MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
165#endif
166
167module_param(fasttext, int, 0644);
168MODULE_PARM_DESC(fasttext, "Enable S3 fast text mode (1=enable, 0=disable, default=1)");
169
170
171/* ------------------------------------------------------------------------- */
172
173/* Set font in S3 fast text mode */
174
175static void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map)
176{
177 const u8 *font = map->data;
Antonino A. Daplas75814d82007-05-08 00:38:49 -0700178 u8 __iomem *fb = (u8 __iomem *) info->screen_base;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800179 int i, c;
180
181 if ((map->width != 8) || (map->height != 16) ||
182 (map->depth != 1) || (map->length != 256)) {
183 printk(KERN_ERR "fb%d: unsupported font parameters: width %d, height %d, depth %d, length %d\n",
184 info->node, map->width, map->height, map->depth, map->length);
185 return;
186 }
187
188 fb += 2;
189 for (i = 0; i < map->height; i++) {
190 for (c = 0; c < map->length; c++) {
Antonino A. Daplas75814d82007-05-08 00:38:49 -0700191 fb_writeb(font[c * map->height + i], fb + c * 4);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800192 }
193 fb += 1024;
194 }
195}
196
David Miller55db0922011-01-11 23:52:11 +0000197static void s3fb_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor)
198{
199 struct s3fb_info *par = info->par;
200
201 svga_tilecursor(par->state.vgabase, info, cursor);
202}
203
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800204static struct fb_tile_ops s3fb_tile_ops = {
205 .fb_settile = svga_settile,
206 .fb_tilecopy = svga_tilecopy,
207 .fb_tilefill = svga_tilefill,
208 .fb_tileblit = svga_tileblit,
David Miller55db0922011-01-11 23:52:11 +0000209 .fb_tilecursor = s3fb_tilecursor,
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700210 .fb_get_tilemax = svga_get_tilemax,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800211};
212
213static struct fb_tile_ops s3fb_fast_tile_ops = {
214 .fb_settile = s3fb_settile_fast,
215 .fb_tilecopy = svga_tilecopy,
216 .fb_tilefill = svga_tilefill,
217 .fb_tileblit = svga_tileblit,
David Miller55db0922011-01-11 23:52:11 +0000218 .fb_tilecursor = s3fb_tilecursor,
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700219 .fb_get_tilemax = svga_get_tilemax,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800220};
221
222
223/* ------------------------------------------------------------------------- */
224
225/* image data is MSB-first, fb structure is MSB-first too */
226static inline u32 expand_color(u32 c)
227{
228 return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
229}
230
231/* s3fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
232static void s3fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
233{
234 u32 fg = expand_color(image->fg_color);
235 u32 bg = expand_color(image->bg_color);
236 const u8 *src1, *src;
237 u8 __iomem *dst1;
238 u32 __iomem *dst;
239 u32 val;
240 int x, y;
241
242 src1 = image->data;
243 dst1 = info->screen_base + (image->dy * info->fix.line_length)
244 + ((image->dx / 8) * 4);
245
246 for (y = 0; y < image->height; y++) {
247 src = src1;
248 dst = (u32 __iomem *) dst1;
249 for (x = 0; x < image->width; x += 8) {
250 val = *(src++) * 0x01010101;
251 val = (val & fg) | (~val & bg);
252 fb_writel(val, dst++);
253 }
254 src1 += image->width / 8;
255 dst1 += info->fix.line_length;
256 }
257
258}
259
260/* s3fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
261static void s3fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
262{
263 u32 fg = expand_color(rect->color);
264 u8 __iomem *dst1;
265 u32 __iomem *dst;
266 int x, y;
267
268 dst1 = info->screen_base + (rect->dy * info->fix.line_length)
269 + ((rect->dx / 8) * 4);
270
271 for (y = 0; y < rect->height; y++) {
272 dst = (u32 __iomem *) dst1;
273 for (x = 0; x < rect->width; x += 8) {
274 fb_writel(fg, dst++);
275 }
276 dst1 += info->fix.line_length;
277 }
278}
279
280
281/* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
282static inline u32 expand_pixel(u32 c)
283{
284 return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
285 ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
286}
287
288/* s3fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
289static void s3fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
290{
291 u32 fg = image->fg_color * 0x11111111;
292 u32 bg = image->bg_color * 0x11111111;
293 const u8 *src1, *src;
294 u8 __iomem *dst1;
295 u32 __iomem *dst;
296 u32 val;
297 int x, y;
298
299 src1 = image->data;
300 dst1 = info->screen_base + (image->dy * info->fix.line_length)
301 + ((image->dx / 8) * 4);
302
303 for (y = 0; y < image->height; y++) {
304 src = src1;
305 dst = (u32 __iomem *) dst1;
306 for (x = 0; x < image->width; x += 8) {
307 val = expand_pixel(*(src++));
308 val = (val & fg) | (~val & bg);
309 fb_writel(val, dst++);
310 }
311 src1 += image->width / 8;
312 dst1 += info->fix.line_length;
313 }
314}
315
316static void s3fb_imageblit(struct fb_info *info, const struct fb_image *image)
317{
318 if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
319 && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
320 if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
321 s3fb_iplan_imageblit(info, image);
322 else
323 s3fb_cfb4_imageblit(info, image);
324 } else
325 cfb_imageblit(info, image);
326}
327
328static void s3fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
329{
330 if ((info->var.bits_per_pixel == 4)
331 && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
332 && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
333 s3fb_iplan_fillrect(info, rect);
334 else
335 cfb_fillrect(info, rect);
336}
337
338
339
340/* ------------------------------------------------------------------------- */
341
342
343static void s3_set_pixclock(struct fb_info *info, u32 pixclock)
344{
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700345 struct s3fb_info *par = info->par;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800346 u16 m, n, r;
347 u8 regval;
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700348 int rv;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800349
Ondrej Zary5694f9c2011-03-01 19:18:17 +0000350 rv = svga_compute_pll((par->chip == CHIP_365_TRIO3D) ? &s3_trio3d_pll : &s3_pll,
351 1000000000 / pixclock, &m, &n, &r, info->node);
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700352 if (rv < 0) {
353 printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node);
354 return;
355 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800356
357 /* Set VGA misc register */
David Millerf8645932011-01-11 23:52:57 +0000358 regval = vga_r(par->state.vgabase, VGA_MIS_R);
359 vga_w(par->state.vgabase, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800360
361 /* Set S3 clock registers */
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700362 if (par->chip == CHIP_360_TRIO3D_1X ||
363 par->chip == CHIP_362_TRIO3D_2X ||
364 par->chip == CHIP_368_TRIO3D_2X) {
David Millerf8645932011-01-11 23:52:57 +0000365 vga_wseq(par->state.vgabase, 0x12, (n - 2) | ((r & 3) << 6)); /* n and two bits of r */
366 vga_wseq(par->state.vgabase, 0x29, r >> 2); /* remaining highest bit of r */
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700367 } else
David Millerf8645932011-01-11 23:52:57 +0000368 vga_wseq(par->state.vgabase, 0x12, (n - 2) | (r << 5));
369 vga_wseq(par->state.vgabase, 0x13, m - 2);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800370
371 udelay(1000);
372
373 /* Activate clock - write 0, 1, 0 to seq/15 bit 5 */
David Millerf8645932011-01-11 23:52:57 +0000374 regval = vga_rseq (par->state.vgabase, 0x15); /* | 0x80; */
375 vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5));
376 vga_wseq(par->state.vgabase, 0x15, regval | (1<<5));
377 vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5));
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800378}
379
380
381/* Open framebuffer */
382
383static int s3fb_open(struct fb_info *info, int user)
384{
385 struct s3fb_info *par = info->par;
386
387 mutex_lock(&(par->open_lock));
388 if (par->ref_count == 0) {
David Miller3ff259f2011-01-11 23:53:53 +0000389 void __iomem *vgabase = par->state.vgabase;
390
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800391 memset(&(par->state), 0, sizeof(struct vgastate));
David Miller3ff259f2011-01-11 23:53:53 +0000392 par->state.vgabase = vgabase;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800393 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
394 par->state.num_crtc = 0x70;
395 par->state.num_seq = 0x20;
396 save_vga(&(par->state));
397 }
398
399 par->ref_count++;
400 mutex_unlock(&(par->open_lock));
401
402 return 0;
403}
404
405/* Close framebuffer */
406
407static int s3fb_release(struct fb_info *info, int user)
408{
409 struct s3fb_info *par = info->par;
410
411 mutex_lock(&(par->open_lock));
412 if (par->ref_count == 0) {
413 mutex_unlock(&(par->open_lock));
414 return -EINVAL;
415 }
416
417 if (par->ref_count == 1)
418 restore_vga(&(par->state));
419
420 par->ref_count--;
421 mutex_unlock(&(par->open_lock));
422
423 return 0;
424}
425
426/* Validate passed in var */
427
428static int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
429{
430 struct s3fb_info *par = info->par;
431 int rv, mem, step;
Krzysztof Heltc3ca34f2007-10-16 01:29:54 -0700432 u16 m, n, r;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800433
434 /* Find appropriate format */
435 rv = svga_match_format (s3fb_formats, var, NULL);
Ondrej Zajicekd4b766a2007-10-16 01:29:52 -0700436
437 /* 32bpp mode is not supported on VIRGE VX,
438 24bpp is not supported on others */
439 if ((par->chip == CHIP_988_VIRGE_VX) ? (rv == 7) : (rv == 6))
440 rv = -EINVAL;
441
442 if (rv < 0) {
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800443 printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node);
444 return rv;
445 }
446
447 /* Do not allow to have real resoulution larger than virtual */
448 if (var->xres > var->xres_virtual)
449 var->xres_virtual = var->xres;
450
451 if (var->yres > var->yres_virtual)
452 var->yres_virtual = var->yres;
453
454 /* Round up xres_virtual to have proper alignment of lines */
455 step = s3fb_formats[rv].xresstep - 1;
456 var->xres_virtual = (var->xres_virtual+step) & ~step;
457
458 /* Check whether have enough memory */
459 mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
Krzysztof Heltc3ca34f2007-10-16 01:29:54 -0700460 if (mem > info->screen_size) {
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800461 printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n",
462 info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
463 return -EINVAL;
464 }
465
466 rv = svga_check_timings (&s3_timing_regs, var, info->node);
Krzysztof Heltc3ca34f2007-10-16 01:29:54 -0700467 if (rv < 0) {
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800468 printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
469 return rv;
470 }
471
Krzysztof Heltc3ca34f2007-10-16 01:29:54 -0700472 rv = svga_compute_pll(&s3_pll, PICOS2KHZ(var->pixclock), &m, &n, &r,
473 info->node);
474 if (rv < 0) {
475 printk(KERN_ERR "fb%d: invalid pixclock value requested\n",
476 info->node);
477 return rv;
478 }
479
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800480 return 0;
481}
482
483/* Set video mode from par */
484
485static int s3fb_set_par(struct fb_info *info)
486{
487 struct s3fb_info *par = info->par;
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700488 u32 value, mode, hmul, offset_value, screen_size, multiplex, dbytes;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800489 u32 bpp = info->var.bits_per_pixel;
Ondrej Zarycb11c042011-03-01 19:18:35 +0000490 u32 htotal, hsstart;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800491
492 if (bpp != 0) {
493 info->fix.ypanstep = 1;
494 info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
495
496 info->flags &= ~FBINFO_MISC_TILEBLITTING;
497 info->tileops = NULL;
498
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700499 /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
500 info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
Antonino A. Daplas8db51662007-05-08 00:39:14 -0700501 info->pixmap.blit_y = ~(u32)0;
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700502
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800503 offset_value = (info->var.xres_virtual * bpp) / 64;
504 screen_size = info->var.yres_virtual * info->fix.line_length;
505 } else {
506 info->fix.ypanstep = 16;
507 info->fix.line_length = 0;
508
509 info->flags |= FBINFO_MISC_TILEBLITTING;
510 info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops;
Ondrej Zajicek34ed25f2007-05-08 00:40:00 -0700511
Antonino A. Daplas8db51662007-05-08 00:39:14 -0700512 /* supports 8x16 tiles only */
513 info->pixmap.blit_x = 1 << (8 - 1);
514 info->pixmap.blit_y = 1 << (16 - 1);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800515
516 offset_value = info->var.xres_virtual / 16;
517 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
518 }
519
520 info->var.xoffset = 0;
521 info->var.yoffset = 0;
522 info->var.activate = FB_ACTIVATE_NOW;
523
524 /* Unlock registers */
David Millerf8645932011-01-11 23:52:57 +0000525 vga_wcrt(par->state.vgabase, 0x38, 0x48);
526 vga_wcrt(par->state.vgabase, 0x39, 0xA5);
527 vga_wseq(par->state.vgabase, 0x08, 0x06);
David Millerea770782011-01-11 23:51:26 +0000528 svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x80);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800529
530 /* Blank screen and turn off sync */
David Millerd907ec02011-01-11 23:51:08 +0000531 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
David Millerea770782011-01-11 23:51:26 +0000532 svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800533
534 /* Set default values */
David Millere2fade22011-01-11 23:50:04 +0000535 svga_set_default_gfx_regs(par->state.vgabase);
David Millerf51a14d2011-01-11 23:50:36 +0000536 svga_set_default_atc_regs(par->state.vgabase);
David Millera4ade8392011-01-11 23:50:54 +0000537 svga_set_default_seq_regs(par->state.vgabase);
David Miller1d28fca2011-01-11 23:51:41 +0000538 svga_set_default_crt_regs(par->state.vgabase);
David Miller21da3862011-01-11 23:49:34 +0000539 svga_wcrt_multi(par->state.vgabase, s3_line_compare_regs, 0xFFFFFFFF);
540 svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, 0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800541
542 /* S3 specific initialization */
David Millerea770782011-01-11 23:51:26 +0000543 svga_wcrt_mask(par->state.vgabase, 0x58, 0x10, 0x10); /* enable linear framebuffer */
544 svga_wcrt_mask(par->state.vgabase, 0x31, 0x08, 0x08); /* enable sequencer access to framebuffer above 256 kB */
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800545
David Millerea770782011-01-11 23:51:26 +0000546/* svga_wcrt_mask(par->state.vgabase, 0x33, 0x08, 0x08); */ /* DDR ? */
547/* svga_wcrt_mask(par->state.vgabase, 0x43, 0x01, 0x01); */ /* DDR ? */
548 svga_wcrt_mask(par->state.vgabase, 0x33, 0x00, 0x08); /* no DDR ? */
549 svga_wcrt_mask(par->state.vgabase, 0x43, 0x00, 0x01); /* no DDR ? */
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800550
David Millerea770782011-01-11 23:51:26 +0000551 svga_wcrt_mask(par->state.vgabase, 0x5D, 0x00, 0x28); /* Clear strange HSlen bits */
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800552
David Millerea770782011-01-11 23:51:26 +0000553/* svga_wcrt_mask(par->state.vgabase, 0x58, 0x03, 0x03); */
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800554
David Millerea770782011-01-11 23:51:26 +0000555/* svga_wcrt_mask(par->state.vgabase, 0x53, 0x12, 0x13); */ /* enable MMIO */
556/* svga_wcrt_mask(par->state.vgabase, 0x40, 0x08, 0x08); */ /* enable write buffer */
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800557
558
559 /* Set the offset register */
560 pr_debug("fb%d: offset register : %d\n", info->node, offset_value);
David Miller21da3862011-01-11 23:49:34 +0000561 svga_wcrt_multi(par->state.vgabase, s3_offset_regs, offset_value);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800562
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700563 if (par->chip != CHIP_360_TRIO3D_1X &&
564 par->chip != CHIP_362_TRIO3D_2X &&
565 par->chip != CHIP_368_TRIO3D_2X) {
David Millerf8645932011-01-11 23:52:57 +0000566 vga_wcrt(par->state.vgabase, 0x54, 0x18); /* M parameter */
567 vga_wcrt(par->state.vgabase, 0x60, 0xff); /* N parameter */
568 vga_wcrt(par->state.vgabase, 0x61, 0xff); /* L parameter */
569 vga_wcrt(par->state.vgabase, 0x62, 0xff); /* L parameter */
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700570 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800571
David Millerf8645932011-01-11 23:52:57 +0000572 vga_wcrt(par->state.vgabase, 0x3A, 0x35);
David Millerf6b0cc42011-01-11 23:49:18 +0000573 svga_wattr(par->state.vgabase, 0x33, 0x00);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800574
575 if (info->var.vmode & FB_VMODE_DOUBLE)
David Millerea770782011-01-11 23:51:26 +0000576 svga_wcrt_mask(par->state.vgabase, 0x09, 0x80, 0x80);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800577 else
David Millerea770782011-01-11 23:51:26 +0000578 svga_wcrt_mask(par->state.vgabase, 0x09, 0x00, 0x80);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800579
580 if (info->var.vmode & FB_VMODE_INTERLACED)
David Millerea770782011-01-11 23:51:26 +0000581 svga_wcrt_mask(par->state.vgabase, 0x42, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800582 else
David Millerea770782011-01-11 23:51:26 +0000583 svga_wcrt_mask(par->state.vgabase, 0x42, 0x00, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800584
585 /* Disable hardware graphics cursor */
David Millerea770782011-01-11 23:51:26 +0000586 svga_wcrt_mask(par->state.vgabase, 0x45, 0x00, 0x01);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800587 /* Disable Streams engine */
David Millerea770782011-01-11 23:51:26 +0000588 svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0x0C);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800589
590 mode = svga_match_format(s3fb_formats, &(info->var), &(info->fix));
591
592 /* S3 virge DX hack */
593 if (par->chip == CHIP_375_VIRGE_DX) {
David Millerf8645932011-01-11 23:52:57 +0000594 vga_wcrt(par->state.vgabase, 0x86, 0x80);
595 vga_wcrt(par->state.vgabase, 0x90, 0x00);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800596 }
597
598 /* S3 virge VX hack */
599 if (par->chip == CHIP_988_VIRGE_VX) {
David Millerf8645932011-01-11 23:52:57 +0000600 vga_wcrt(par->state.vgabase, 0x50, 0x00);
601 vga_wcrt(par->state.vgabase, 0x67, 0x50);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800602
David Millerf8645932011-01-11 23:52:57 +0000603 vga_wcrt(par->state.vgabase, 0x63, (mode <= 2) ? 0x90 : 0x09);
604 vga_wcrt(par->state.vgabase, 0x66, 0x90);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800605 }
606
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700607 if (par->chip == CHIP_360_TRIO3D_1X ||
608 par->chip == CHIP_362_TRIO3D_2X ||
Ondrej Zary5694f9c2011-03-01 19:18:17 +0000609 par->chip == CHIP_368_TRIO3D_2X ||
Ondrej Zarycb11c042011-03-01 19:18:35 +0000610 par->chip == CHIP_365_TRIO3D ||
611 par->chip == CHIP_375_VIRGE_DX ||
612 par->chip == CHIP_385_VIRGE_GX) {
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700613 dbytes = info->var.xres * ((bpp+7)/8);
David Millerf8645932011-01-11 23:52:57 +0000614 vga_wcrt(par->state.vgabase, 0x91, (dbytes + 7) / 8);
615 vga_wcrt(par->state.vgabase, 0x90, (((dbytes + 7) / 8) >> 8) | 0x80);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700616
David Millerf8645932011-01-11 23:52:57 +0000617 vga_wcrt(par->state.vgabase, 0x66, 0x81);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700618 }
619
Ondrej Zarycb11c042011-03-01 19:18:35 +0000620 if (par->chip == CHIP_356_VIRGE_GX2 ||
621 par->chip == CHIP_357_VIRGE_GX2P ||
622 par->chip == CHIP_359_VIRGE_GX2P ||
623 par->chip == CHIP_360_TRIO3D_1X ||
624 par->chip == CHIP_362_TRIO3D_2X ||
625 par->chip == CHIP_368_TRIO3D_2X)
626 vga_wcrt(par->state.vgabase, 0x34, 0x00);
627 else /* enable Data Transfer Position Control (DTPC) */
628 vga_wcrt(par->state.vgabase, 0x34, 0x10);
629
David Millerea770782011-01-11 23:51:26 +0000630 svga_wcrt_mask(par->state.vgabase, 0x31, 0x00, 0x40);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800631 multiplex = 0;
632 hmul = 1;
633
634 /* Set mode-specific register values */
635 switch (mode) {
636 case 0:
637 pr_debug("fb%d: text mode\n", info->node);
David Miller9c963942011-01-11 23:51:56 +0000638 svga_set_textmode_vga_regs(par->state.vgabase);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800639
640 /* Set additional registers like in 8-bit mode */
David Millerea770782011-01-11 23:51:26 +0000641 svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
642 svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800643
644 /* Disable enhanced mode */
David Millerea770782011-01-11 23:51:26 +0000645 svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800646
647 if (fasttext) {
648 pr_debug("fb%d: high speed text mode set\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000649 svga_wcrt_mask(par->state.vgabase, 0x31, 0x40, 0x40);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800650 }
651 break;
652 case 1:
653 pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
David Millerf8645932011-01-11 23:52:57 +0000654 vga_wgfx(par->state.vgabase, VGA_GFX_MODE, 0x40);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800655
656 /* Set additional registers like in 8-bit mode */
David Millerea770782011-01-11 23:51:26 +0000657 svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
658 svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800659
660 /* disable enhanced mode */
David Millerea770782011-01-11 23:51:26 +0000661 svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800662 break;
663 case 2:
664 pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
665
666 /* Set additional registers like in 8-bit mode */
David Millerea770782011-01-11 23:51:26 +0000667 svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
668 svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800669
670 /* disable enhanced mode */
David Millerea770782011-01-11 23:51:26 +0000671 svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800672 break;
673 case 3:
674 pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000675 svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700676 if (info->var.pixclock > 20000 ||
677 par->chip == CHIP_360_TRIO3D_1X ||
678 par->chip == CHIP_362_TRIO3D_2X ||
679 par->chip == CHIP_368_TRIO3D_2X)
David Millerea770782011-01-11 23:51:26 +0000680 svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700681 else {
David Millerea770782011-01-11 23:51:26 +0000682 svga_wcrt_mask(par->state.vgabase, 0x67, 0x10, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800683 multiplex = 1;
684 }
685 break;
686 case 4:
687 pr_debug("fb%d: 5/5/5 truecolor\n", info->node);
688 if (par->chip == CHIP_988_VIRGE_VX) {
689 if (info->var.pixclock > 20000)
David Millerea770782011-01-11 23:51:26 +0000690 svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800691 else
David Millerea770782011-01-11 23:51:26 +0000692 svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
Ondrej Zary3827d102011-03-01 19:18:27 +0000693 } else if (par->chip == CHIP_365_TRIO3D) {
694 svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
695 if (info->var.pixclock > 8695) {
696 svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
697 hmul = 2;
698 } else {
699 svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0);
700 multiplex = 1;
701 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800702 } else {
David Millerea770782011-01-11 23:51:26 +0000703 svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
704 svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700705 if (par->chip != CHIP_360_TRIO3D_1X &&
706 par->chip != CHIP_362_TRIO3D_2X &&
707 par->chip != CHIP_368_TRIO3D_2X)
708 hmul = 2;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800709 }
710 break;
711 case 5:
712 pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
713 if (par->chip == CHIP_988_VIRGE_VX) {
714 if (info->var.pixclock > 20000)
David Millerea770782011-01-11 23:51:26 +0000715 svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800716 else
David Millerea770782011-01-11 23:51:26 +0000717 svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
Ondrej Zary3827d102011-03-01 19:18:27 +0000718 } else if (par->chip == CHIP_365_TRIO3D) {
719 svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
720 if (info->var.pixclock > 8695) {
721 svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
722 hmul = 2;
723 } else {
724 svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0);
725 multiplex = 1;
726 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800727 } else {
David Millerea770782011-01-11 23:51:26 +0000728 svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
729 svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700730 if (par->chip != CHIP_360_TRIO3D_1X &&
731 par->chip != CHIP_362_TRIO3D_2X &&
732 par->chip != CHIP_368_TRIO3D_2X)
733 hmul = 2;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800734 }
735 break;
736 case 6:
737 /* VIRGE VX case */
738 pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000739 svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800740 break;
741 case 7:
742 pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000743 svga_wcrt_mask(par->state.vgabase, 0x50, 0x30, 0x30);
744 svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800745 break;
746 default:
747 printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node);
748 return -EINVAL;
749 }
750
751 if (par->chip != CHIP_988_VIRGE_VX) {
David Millerd907ec02011-01-11 23:51:08 +0000752 svga_wseq_mask(par->state.vgabase, 0x15, multiplex ? 0x10 : 0x00, 0x10);
753 svga_wseq_mask(par->state.vgabase, 0x18, multiplex ? 0x80 : 0x00, 0x80);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800754 }
755
756 s3_set_pixclock(info, info->var.pixclock);
David Miller38d26202011-01-11 23:52:25 +0000757 svga_set_timings(par->state.vgabase, &s3_timing_regs, &(info->var), hmul, 1,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800758 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
759 (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
760 hmul, info->node);
761
762 /* Set interlaced mode start/end register */
Ondrej Zarycb11c042011-03-01 19:18:35 +0000763 htotal = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
764 htotal = ((htotal * hmul) / 8) - 5;
765 vga_wcrt(par->state.vgabase, 0x3C, (htotal + 1) / 2);
766
767 /* Set Data Transfer Position */
768 hsstart = ((info->var.xres + info->var.right_margin) * hmul) / 8;
769 value = clamp((htotal + hsstart + 1) / 2, hsstart + 4, htotal + 1);
770 svga_wcrt_multi(par->state.vgabase, s3_dtpc_regs, value);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800771
Antonino A. Daplas75814d82007-05-08 00:38:49 -0700772 memset_io(info->screen_base, 0x00, screen_size);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800773 /* Device and screen back on */
David Millerea770782011-01-11 23:51:26 +0000774 svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
David Millerd907ec02011-01-11 23:51:08 +0000775 svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800776
777 return 0;
778}
779
780/* Set a colour register */
781
782static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
783 u_int transp, struct fb_info *fb)
784{
785 switch (fb->var.bits_per_pixel) {
786 case 0:
787 case 4:
788 if (regno >= 16)
789 return -EINVAL;
790
791 if ((fb->var.bits_per_pixel == 4) &&
792 (fb->var.nonstd == 0)) {
793 outb(0xF0, VGA_PEL_MSK);
794 outb(regno*16, VGA_PEL_IW);
795 } else {
796 outb(0x0F, VGA_PEL_MSK);
797 outb(regno, VGA_PEL_IW);
798 }
799 outb(red >> 10, VGA_PEL_D);
800 outb(green >> 10, VGA_PEL_D);
801 outb(blue >> 10, VGA_PEL_D);
802 break;
803 case 8:
804 if (regno >= 256)
805 return -EINVAL;
806
807 outb(0xFF, VGA_PEL_MSK);
808 outb(regno, VGA_PEL_IW);
809 outb(red >> 10, VGA_PEL_D);
810 outb(green >> 10, VGA_PEL_D);
811 outb(blue >> 10, VGA_PEL_D);
812 break;
813 case 16:
814 if (regno >= 16)
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700815 return 0;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800816
817 if (fb->var.green.length == 5)
818 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
819 ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
820 else if (fb->var.green.length == 6)
821 ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
822 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
823 else return -EINVAL;
824 break;
825 case 24:
826 case 32:
827 if (regno >= 16)
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700828 return 0;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800829
Ondrej Zajicek249bdbb2007-05-08 00:39:24 -0700830 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800831 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
832 break;
833 default:
834 return -EINVAL;
835 }
836
837 return 0;
838}
839
840
841/* Set the display blanking state */
842
843static int s3fb_blank(int blank_mode, struct fb_info *info)
844{
David Millerd907ec02011-01-11 23:51:08 +0000845 struct s3fb_info *par = info->par;
846
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800847 switch (blank_mode) {
848 case FB_BLANK_UNBLANK:
849 pr_debug("fb%d: unblank\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000850 svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000851 svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800852 break;
853 case FB_BLANK_NORMAL:
854 pr_debug("fb%d: blank\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000855 svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000856 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800857 break;
858 case FB_BLANK_HSYNC_SUSPEND:
859 pr_debug("fb%d: hsync\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000860 svga_wcrt_mask(par->state.vgabase, 0x56, 0x02, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000861 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800862 break;
863 case FB_BLANK_VSYNC_SUSPEND:
864 pr_debug("fb%d: vsync\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000865 svga_wcrt_mask(par->state.vgabase, 0x56, 0x04, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000866 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800867 break;
868 case FB_BLANK_POWERDOWN:
869 pr_debug("fb%d: sync down\n", info->node);
David Millerea770782011-01-11 23:51:26 +0000870 svga_wcrt_mask(par->state.vgabase, 0x56, 0x06, 0x06);
David Millerd907ec02011-01-11 23:51:08 +0000871 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800872 break;
873 }
874
875 return 0;
876}
877
878
879/* Pan the display */
880
David Miller21da3862011-01-11 23:49:34 +0000881static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
882{
883 struct s3fb_info *par = info->par;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800884 unsigned int offset;
885
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800886 /* Calculate the offset */
887 if (var->bits_per_pixel == 0) {
888 offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
889 offset = offset >> 2;
890 } else {
891 offset = (var->yoffset * info->fix.line_length) +
892 (var->xoffset * var->bits_per_pixel / 8);
893 offset = offset >> 2;
894 }
895
896 /* Set the offset */
David Miller21da3862011-01-11 23:49:34 +0000897 svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, offset);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800898
899 return 0;
900}
901
902/* ------------------------------------------------------------------------- */
903
904/* Frame buffer operations */
905
906static struct fb_ops s3fb_ops = {
907 .owner = THIS_MODULE,
908 .fb_open = s3fb_open,
909 .fb_release = s3fb_release,
910 .fb_check_var = s3fb_check_var,
911 .fb_set_par = s3fb_set_par,
912 .fb_setcolreg = s3fb_setcolreg,
913 .fb_blank = s3fb_blank,
914 .fb_pan_display = s3fb_pan_display,
915 .fb_fillrect = s3fb_fillrect,
916 .fb_copyarea = cfb_copyarea,
917 .fb_imageblit = s3fb_imageblit,
Antonino A. Daplas5a87ede2007-05-09 02:35:32 -0700918 .fb_get_caps = svga_get_caps,
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800919};
920
921/* ------------------------------------------------------------------------- */
922
David Millerf8645932011-01-11 23:52:57 +0000923static int __devinit s3_identification(struct s3fb_info *par)
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800924{
David Millerf8645932011-01-11 23:52:57 +0000925 int chip = par->chip;
926
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800927 if (chip == CHIP_XXX_TRIO) {
David Millerf8645932011-01-11 23:52:57 +0000928 u8 cr30 = vga_rcrt(par->state.vgabase, 0x30);
929 u8 cr2e = vga_rcrt(par->state.vgabase, 0x2e);
930 u8 cr2f = vga_rcrt(par->state.vgabase, 0x2f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800931
932 if ((cr30 == 0xE0) || (cr30 == 0xE1)) {
933 if (cr2e == 0x10)
934 return CHIP_732_TRIO32;
935 if (cr2e == 0x11) {
936 if (! (cr2f & 0x40))
937 return CHIP_764_TRIO64;
938 else
939 return CHIP_765_TRIO64VP;
940 }
941 }
942 }
943
944 if (chip == CHIP_XXX_TRIO64V2_DXGX) {
David Millerf8645932011-01-11 23:52:57 +0000945 u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800946
947 if (! (cr6f & 0x01))
948 return CHIP_775_TRIO64V2_DX;
949 else
950 return CHIP_785_TRIO64V2_GX;
951 }
952
953 if (chip == CHIP_XXX_VIRGE_DXGX) {
David Millerf8645932011-01-11 23:52:57 +0000954 u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800955
956 if (! (cr6f & 0x01))
957 return CHIP_375_VIRGE_DX;
958 else
959 return CHIP_385_VIRGE_GX;
960 }
961
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700962 if (chip == CHIP_36X_TRIO3D_1X_2X) {
David Millerf8645932011-01-11 23:52:57 +0000963 switch (vga_rcrt(par->state.vgabase, 0x2f)) {
Ondrej Zary9966c4f2010-05-26 14:42:27 -0700964 case 0x00:
965 return CHIP_360_TRIO3D_1X;
966 case 0x01:
967 return CHIP_362_TRIO3D_2X;
968 case 0x02:
969 return CHIP_368_TRIO3D_2X;
970 }
971 }
972
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800973 return CHIP_UNKNOWN;
974}
975
976
977/* PCI probe */
978
979static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
980{
David Miller94c322c2011-01-11 23:54:21 +0000981 struct pci_bus_region bus_reg;
982 struct resource vga_res;
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800983 struct fb_info *info;
984 struct s3fb_info *par;
985 int rc;
986 u8 regval, cr38, cr39;
987
988 /* Ignore secondary VGA device because there is no VGA arbitration */
989 if (! svga_primary_device(dev)) {
990 dev_info(&(dev->dev), "ignoring secondary device\n");
991 return -ENODEV;
992 }
993
994 /* Allocate and fill driver data structure */
Ondrej Zajicek20e061f2008-04-28 02:15:18 -0700995 info = framebuffer_alloc(sizeof(struct s3fb_info), &(dev->dev));
Ondrej Zajiceka2684222007-02-12 00:54:49 -0800996 if (!info) {
997 dev_err(&(dev->dev), "cannot allocate memory\n");
998 return -ENOMEM;
999 }
1000
1001 par = info->par;
1002 mutex_init(&par->open_lock);
1003
1004 info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
1005 info->fbops = &s3fb_ops;
1006
1007 /* Prepare PCI device */
1008 rc = pci_enable_device(dev);
1009 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001010 dev_err(info->device, "cannot enable PCI device\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001011 goto err_enable_device;
1012 }
1013
1014 rc = pci_request_regions(dev, "s3fb");
1015 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001016 dev_err(info->device, "cannot reserve framebuffer region\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001017 goto err_request_regions;
1018 }
1019
1020
1021 info->fix.smem_start = pci_resource_start(dev, 0);
1022 info->fix.smem_len = pci_resource_len(dev, 0);
1023
1024 /* Map physical IO memory address into kernel space */
1025 info->screen_base = pci_iomap(dev, 0, 0);
1026 if (! info->screen_base) {
1027 rc = -ENOMEM;
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001028 dev_err(info->device, "iomap for framebuffer failed\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001029 goto err_iomap;
1030 }
1031
David Miller94c322c2011-01-11 23:54:21 +00001032 bus_reg.start = 0;
1033 bus_reg.end = 64 * 1024;
1034
1035 vga_res.flags = IORESOURCE_IO;
1036
1037 pcibios_bus_to_resource(dev, &vga_res, &bus_reg);
1038
1039 par->state.vgabase = (void __iomem *) vga_res.start;
1040
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001041 /* Unlock regs */
David Millerf8645932011-01-11 23:52:57 +00001042 cr38 = vga_rcrt(par->state.vgabase, 0x38);
1043 cr39 = vga_rcrt(par->state.vgabase, 0x39);
1044 vga_wseq(par->state.vgabase, 0x08, 0x06);
1045 vga_wcrt(par->state.vgabase, 0x38, 0x48);
1046 vga_wcrt(par->state.vgabase, 0x39, 0xA5);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001047
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001048 /* Identify chip type */
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001049 par->chip = id->driver_data & CHIP_MASK;
David Millerf8645932011-01-11 23:52:57 +00001050 par->rev = vga_rcrt(par->state.vgabase, 0x2f);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001051 if (par->chip & CHIP_UNDECIDED_FLAG)
David Millerf8645932011-01-11 23:52:57 +00001052 par->chip = s3_identification(par);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001053
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001054 /* Find how many physical memory there is on card */
1055 /* 0x36 register is accessible even if other registers are locked */
David Millerf8645932011-01-11 23:52:57 +00001056 regval = vga_rcrt(par->state.vgabase, 0x36);
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001057 if (par->chip == CHIP_360_TRIO3D_1X ||
1058 par->chip == CHIP_362_TRIO3D_2X ||
Ondrej Zary5694f9c2011-03-01 19:18:17 +00001059 par->chip == CHIP_368_TRIO3D_2X ||
1060 par->chip == CHIP_365_TRIO3D) {
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001061 switch ((regval & 0xE0) >> 5) {
1062 case 0: /* 8MB -- only 4MB usable for display */
1063 case 1: /* 4MB with 32-bit bus */
1064 case 2: /* 4MB */
1065 info->screen_size = 4 << 20;
1066 break;
Ondrej Zary5694f9c2011-03-01 19:18:17 +00001067 case 4: /* 2MB on 365 Trio3D */
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001068 case 6: /* 2MB */
1069 info->screen_size = 2 << 20;
1070 break;
1071 }
1072 } else
1073 info->screen_size = s3_memsizes[regval >> 5] << 10;
1074 info->fix.smem_len = info->screen_size;
1075
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001076 /* Find MCLK frequency */
David Millerf8645932011-01-11 23:52:57 +00001077 regval = vga_rseq(par->state.vgabase, 0x10);
1078 par->mclk_freq = ((vga_rseq(par->state.vgabase, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001079 par->mclk_freq = par->mclk_freq >> (regval >> 5);
1080
1081 /* Restore locks */
David Millerf8645932011-01-11 23:52:57 +00001082 vga_wcrt(par->state.vgabase, 0x38, cr38);
1083 vga_wcrt(par->state.vgabase, 0x39, cr39);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001084
1085 strcpy(info->fix.id, s3_names [par->chip]);
1086 info->fix.mmio_start = 0;
1087 info->fix.mmio_len = 0;
1088 info->fix.type = FB_TYPE_PACKED_PIXELS;
1089 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1090 info->fix.ypanstep = 0;
1091 info->fix.accel = FB_ACCEL_NONE;
1092 info->pseudo_palette = (void*) (par->pseudo_palette);
1093
1094 /* Prepare startup mode */
Krzysztof Helta8140542008-04-28 02:15:09 -07001095 rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001096 if (! ((rc == 1) || (rc == 2))) {
1097 rc = -EINVAL;
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001098 dev_err(info->device, "mode %s not found\n", mode_option);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001099 goto err_find_mode;
1100 }
1101
Ondrej Zary99d054d2011-03-01 19:18:08 +00001102 /* maximize virtual vertical size for fast scrolling */
1103 info->var.yres_virtual = info->fix.smem_len * 8 /
1104 (info->var.bits_per_pixel * info->var.xres_virtual);
1105 if (info->var.yres_virtual < info->var.yres) {
1106 dev_err(info->device, "virtual vertical size smaller than real\n");
1107 goto err_find_mode;
1108 }
1109
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001110 rc = fb_alloc_cmap(&info->cmap, 256, 0);
1111 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001112 dev_err(info->device, "cannot allocate colormap\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001113 goto err_alloc_cmap;
1114 }
1115
1116 rc = register_framebuffer(info);
1117 if (rc < 0) {
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001118 dev_err(info->device, "cannot register framebuffer\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001119 goto err_reg_fb;
1120 }
1121
1122 printk(KERN_INFO "fb%d: %s on %s, %d MB RAM, %d MHz MCLK\n", info->node, info->fix.id,
1123 pci_name(dev), info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000);
1124
1125 if (par->chip == CHIP_UNKNOWN)
1126 printk(KERN_INFO "fb%d: unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n",
David Millerf8645932011-01-11 23:52:57 +00001127 info->node, vga_rcrt(par->state.vgabase, 0x2d), vga_rcrt(par->state.vgabase, 0x2e),
1128 vga_rcrt(par->state.vgabase, 0x2f), vga_rcrt(par->state.vgabase, 0x30));
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001129
1130 /* Record a reference to the driver data */
1131 pci_set_drvdata(dev, info);
1132
1133#ifdef CONFIG_MTRR
1134 if (mtrr) {
1135 par->mtrr_reg = -1;
1136 par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
1137 }
1138#endif
1139
1140 return 0;
1141
1142 /* Error handling */
1143err_reg_fb:
1144 fb_dealloc_cmap(&info->cmap);
1145err_alloc_cmap:
1146err_find_mode:
1147 pci_iounmap(dev, info->screen_base);
1148err_iomap:
1149 pci_release_regions(dev);
1150err_request_regions:
1151/* pci_disable_device(dev); */
1152err_enable_device:
1153 framebuffer_release(info);
1154 return rc;
1155}
1156
1157
1158/* PCI remove */
1159
1160static void __devexit s3_pci_remove(struct pci_dev *dev)
1161{
1162 struct fb_info *info = pci_get_drvdata(dev);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001163
1164 if (info) {
1165
1166#ifdef CONFIG_MTRR
Adrian Bunk47ebea82007-03-22 00:11:16 -08001167 struct s3fb_info *par = info->par;
1168
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001169 if (par->mtrr_reg >= 0) {
1170 mtrr_del(par->mtrr_reg, 0, 0);
1171 par->mtrr_reg = -1;
1172 }
1173#endif
1174
1175 unregister_framebuffer(info);
1176 fb_dealloc_cmap(&info->cmap);
1177
1178 pci_iounmap(dev, info->screen_base);
1179 pci_release_regions(dev);
1180/* pci_disable_device(dev); */
1181
1182 pci_set_drvdata(dev, NULL);
1183 framebuffer_release(info);
1184 }
1185}
1186
1187/* PCI suspend */
1188
1189static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state)
1190{
1191 struct fb_info *info = pci_get_drvdata(dev);
1192 struct s3fb_info *par = info->par;
1193
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001194 dev_info(info->device, "suspend\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001195
Torben Hohnac751ef2011-01-25 15:07:35 -08001196 console_lock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001197 mutex_lock(&(par->open_lock));
1198
1199 if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
1200 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001201 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001202 return 0;
1203 }
1204
1205 fb_set_suspend(info, 1);
1206
1207 pci_save_state(dev);
1208 pci_disable_device(dev);
1209 pci_set_power_state(dev, pci_choose_state(dev, state));
1210
1211 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001212 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001213
1214 return 0;
1215}
1216
1217
1218/* PCI resume */
1219
1220static int s3_pci_resume(struct pci_dev* dev)
1221{
1222 struct fb_info *info = pci_get_drvdata(dev);
1223 struct s3fb_info *par = info->par;
Randy Dunlap6314db42007-05-08 00:38:11 -07001224 int err;
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001225
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001226 dev_info(info->device, "resume\n");
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001227
Torben Hohnac751ef2011-01-25 15:07:35 -08001228 console_lock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001229 mutex_lock(&(par->open_lock));
1230
1231 if (par->ref_count == 0) {
1232 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001233 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001234 return 0;
1235 }
1236
1237 pci_set_power_state(dev, PCI_D0);
1238 pci_restore_state(dev);
Randy Dunlap6314db42007-05-08 00:38:11 -07001239 err = pci_enable_device(dev);
1240 if (err) {
1241 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001242 console_unlock();
Ondrej Zajicek594a8812008-08-05 13:01:06 -07001243 dev_err(info->device, "error %d enabling device for resume\n", err);
Randy Dunlap6314db42007-05-08 00:38:11 -07001244 return err;
1245 }
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001246 pci_set_master(dev);
1247
1248 s3fb_set_par(info);
1249 fb_set_suspend(info, 0);
1250
1251 mutex_unlock(&(par->open_lock));
Torben Hohnac751ef2011-01-25 15:07:35 -08001252 console_unlock();
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001253
1254 return 0;
1255}
1256
1257
1258/* List of boards that we are trying to support */
1259
1260static struct pci_device_id s3_devices[] __devinitdata = {
1261 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO},
1262 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO},
1263 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP},
1264 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP},
1265 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX},
1266 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX},
1267
1268 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE},
1269 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX},
1270 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX},
1271 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_356_VIRGE_GX2},
1272 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_357_VIRGE_GX2P},
1273 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P},
Ondrej Zary9966c4f2010-05-26 14:42:27 -07001274 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A13), .driver_data = CHIP_36X_TRIO3D_1X_2X},
Ondrej Zary5694f9c2011-03-01 19:18:17 +00001275 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8904), .driver_data = CHIP_365_TRIO3D},
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001276
1277 {0, 0, 0, 0, 0, 0, 0}
1278};
1279
1280
1281MODULE_DEVICE_TABLE(pci, s3_devices);
1282
1283static struct pci_driver s3fb_pci_driver = {
1284 .name = "s3fb",
1285 .id_table = s3_devices,
1286 .probe = s3_pci_probe,
1287 .remove = __devexit_p(s3_pci_remove),
1288 .suspend = s3_pci_suspend,
1289 .resume = s3_pci_resume,
1290};
1291
1292/* Parse user speficied options */
1293
1294#ifndef MODULE
1295static int __init s3fb_setup(char *options)
1296{
1297 char *opt;
1298
1299 if (!options || !*options)
1300 return 0;
1301
1302 while ((opt = strsep(&options, ",")) != NULL) {
1303
1304 if (!*opt)
1305 continue;
1306#ifdef CONFIG_MTRR
Ondrej Zajicek62fa4dc2007-02-22 17:00:41 +01001307 else if (!strncmp(opt, "mtrr:", 5))
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001308 mtrr = simple_strtoul(opt + 5, NULL, 0);
1309#endif
Ondrej Zajicek62fa4dc2007-02-22 17:00:41 +01001310 else if (!strncmp(opt, "fasttext:", 9))
1311 fasttext = simple_strtoul(opt + 9, NULL, 0);
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001312 else
Krzysztof Helta8140542008-04-28 02:15:09 -07001313 mode_option = opt;
Ondrej Zajiceka2684222007-02-12 00:54:49 -08001314 }
1315
1316 return 0;
1317}
1318#endif
1319
1320/* Cleanup */
1321
1322static void __exit s3fb_cleanup(void)
1323{
1324 pr_debug("s3fb: cleaning up\n");
1325 pci_unregister_driver(&s3fb_pci_driver);
1326}
1327
1328/* Driver Initialisation */
1329
1330static int __init s3fb_init(void)
1331{
1332
1333#ifndef MODULE
1334 char *option = NULL;
1335
1336 if (fb_get_options("s3fb", &option))
1337 return -ENODEV;
1338 s3fb_setup(option);
1339#endif
1340
1341 pr_debug("s3fb: initializing\n");
1342 return pci_register_driver(&s3fb_pci_driver);
1343}
1344
1345/* ------------------------------------------------------------------------- */
1346
1347/* Modularization */
1348
1349module_init(s3fb_init);
1350module_exit(s3fb_cleanup);