PRCM: 34XX: Fix wrong shift value used in dpll4_m4x2_ck enable bit
[linux-ginger.git] / drivers / video / vt8623fb.c
blob536ab11623f01384cb79f0baa98e1e717b8e7e97
1 /*
2 * linux/drivers/video/vt8623fb.c - fbdev driver for
3 * integrated graphic core in VIA VT8623 [CLE266] chipset
5 * Copyright (c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
9 * more details.
11 * Code is based on s3fb, some parts are from David Boucher's viafb
12 * (http://davesdomain.org.uk/viafb/)
15 #include <linux/version.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/string.h>
20 #include <linux/mm.h>
21 #include <linux/tty.h>
22 #include <linux/slab.h>
23 #include <linux/delay.h>
24 #include <linux/fb.h>
25 #include <linux/svga.h>
26 #include <linux/init.h>
27 #include <linux/pci.h>
28 #include <linux/console.h> /* Why should fb driver call console functions? because acquire_console_sem() */
29 #include <video/vga.h>
31 #ifdef CONFIG_MTRR
32 #include <asm/mtrr.h>
33 #endif
35 struct vt8623fb_info {
36 char __iomem *mmio_base;
37 int mtrr_reg;
38 struct vgastate state;
39 struct mutex open_lock;
40 unsigned int ref_count;
41 u32 pseudo_palette[16];
46 /* ------------------------------------------------------------------------- */
48 static const struct svga_fb_format vt8623fb_formats[] = {
49 { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
50 FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP8, FB_VISUAL_PSEUDOCOLOR, 16, 16},
51 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
52 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 16, 16},
53 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1,
54 FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 16, 16},
55 { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
56 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 8},
57 /* {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
58 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4}, */
59 {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
60 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4},
61 {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
62 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 2},
63 SVGA_FORMAT_END
66 static const struct svga_pll vt8623_pll = {2, 127, 2, 7, 0, 3,
67 60000, 300000, 14318};
69 /* CRT timing register sets */
71 static struct vga_regset vt8623_h_total_regs[] = {{0x00, 0, 7}, {0x36, 3, 3}, VGA_REGSET_END};
72 static struct vga_regset vt8623_h_display_regs[] = {{0x01, 0, 7}, VGA_REGSET_END};
73 static struct vga_regset vt8623_h_blank_start_regs[] = {{0x02, 0, 7}, VGA_REGSET_END};
74 static struct vga_regset vt8623_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7}, {0x33, 5, 5}, VGA_REGSET_END};
75 static struct vga_regset vt8623_h_sync_start_regs[] = {{0x04, 0, 7}, {0x33, 4, 4}, VGA_REGSET_END};
76 static struct vga_regset vt8623_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
78 static struct vga_regset vt8623_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x35, 0, 0}, VGA_REGSET_END};
79 static struct vga_regset vt8623_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x35, 2, 2}, VGA_REGSET_END};
80 static struct vga_regset vt8623_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x35, 3, 3}, VGA_REGSET_END};
81 static struct vga_regset vt8623_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
82 static struct vga_regset vt8623_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x35, 1, 1}, VGA_REGSET_END};
83 static struct vga_regset vt8623_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
85 static struct vga_regset vt8623_offset_regs[] = {{0x13, 0, 7}, {0x35, 5, 7}, VGA_REGSET_END};
86 static struct vga_regset vt8623_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, {0x33, 0, 2}, {0x35, 4, 4}, VGA_REGSET_END};
87 static struct vga_regset vt8623_fetch_count_regs[] = {{0x1C, 0, 7}, {0x1D, 0, 1}, VGA_REGSET_END};
88 static struct vga_regset vt8623_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x34, 0, 7}, {0x48, 0, 1}, VGA_REGSET_END};
90 static struct svga_timing_regs vt8623_timing_regs = {
91 vt8623_h_total_regs, vt8623_h_display_regs, vt8623_h_blank_start_regs,
92 vt8623_h_blank_end_regs, vt8623_h_sync_start_regs, vt8623_h_sync_end_regs,
93 vt8623_v_total_regs, vt8623_v_display_regs, vt8623_v_blank_start_regs,
94 vt8623_v_blank_end_regs, vt8623_v_sync_start_regs, vt8623_v_sync_end_regs,
98 /* ------------------------------------------------------------------------- */
101 /* Module parameters */
103 static char *mode_option = "640x480-8@60";
105 #ifdef CONFIG_MTRR
106 static int mtrr = 1;
107 #endif
109 MODULE_AUTHOR("(c) 2006 Ondrej Zajicek <santiago@crfreenet.org>");
110 MODULE_LICENSE("GPL");
111 MODULE_DESCRIPTION("fbdev driver for integrated graphics core in VIA VT8623 [CLE266]");
113 module_param(mode_option, charp, 0644);
114 MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)");
115 module_param_named(mode, mode_option, charp, 0);
116 MODULE_PARM_DESC(mode, "Default video mode e.g. '648x480-8@60' (deprecated)");
118 #ifdef CONFIG_MTRR
119 module_param(mtrr, int, 0444);
120 MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
121 #endif
124 /* ------------------------------------------------------------------------- */
127 static struct fb_tile_ops vt8623fb_tile_ops = {
128 .fb_settile = svga_settile,
129 .fb_tilecopy = svga_tilecopy,
130 .fb_tilefill = svga_tilefill,
131 .fb_tileblit = svga_tileblit,
132 .fb_tilecursor = svga_tilecursor,
133 .fb_get_tilemax = svga_get_tilemax,
137 /* ------------------------------------------------------------------------- */
140 /* image data is MSB-first, fb structure is MSB-first too */
141 static inline u32 expand_color(u32 c)
143 return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
146 /* vt8623fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
147 static void vt8623fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
149 u32 fg = expand_color(image->fg_color);
150 u32 bg = expand_color(image->bg_color);
151 const u8 *src1, *src;
152 u8 __iomem *dst1;
153 u32 __iomem *dst;
154 u32 val;
155 int x, y;
157 src1 = image->data;
158 dst1 = info->screen_base + (image->dy * info->fix.line_length)
159 + ((image->dx / 8) * 4);
161 for (y = 0; y < image->height; y++) {
162 src = src1;
163 dst = (u32 __iomem *) dst1;
164 for (x = 0; x < image->width; x += 8) {
165 val = *(src++) * 0x01010101;
166 val = (val & fg) | (~val & bg);
167 fb_writel(val, dst++);
169 src1 += image->width / 8;
170 dst1 += info->fix.line_length;
174 /* vt8623fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
175 static void vt8623fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
177 u32 fg = expand_color(rect->color);
178 u8 __iomem *dst1;
179 u32 __iomem *dst;
180 int x, y;
182 dst1 = info->screen_base + (rect->dy * info->fix.line_length)
183 + ((rect->dx / 8) * 4);
185 for (y = 0; y < rect->height; y++) {
186 dst = (u32 __iomem *) dst1;
187 for (x = 0; x < rect->width; x += 8) {
188 fb_writel(fg, dst++);
190 dst1 += info->fix.line_length;
195 /* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
196 static inline u32 expand_pixel(u32 c)
198 return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
199 ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
202 /* vt8623fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
203 static void vt8623fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
205 u32 fg = image->fg_color * 0x11111111;
206 u32 bg = image->bg_color * 0x11111111;
207 const u8 *src1, *src;
208 u8 __iomem *dst1;
209 u32 __iomem *dst;
210 u32 val;
211 int x, y;
213 src1 = image->data;
214 dst1 = info->screen_base + (image->dy * info->fix.line_length)
215 + ((image->dx / 8) * 4);
217 for (y = 0; y < image->height; y++) {
218 src = src1;
219 dst = (u32 __iomem *) dst1;
220 for (x = 0; x < image->width; x += 8) {
221 val = expand_pixel(*(src++));
222 val = (val & fg) | (~val & bg);
223 fb_writel(val, dst++);
225 src1 += image->width / 8;
226 dst1 += info->fix.line_length;
230 static void vt8623fb_imageblit(struct fb_info *info, const struct fb_image *image)
232 if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
233 && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
234 if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
235 vt8623fb_iplan_imageblit(info, image);
236 else
237 vt8623fb_cfb4_imageblit(info, image);
238 } else
239 cfb_imageblit(info, image);
242 static void vt8623fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
244 if ((info->var.bits_per_pixel == 4)
245 && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
246 && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
247 vt8623fb_iplan_fillrect(info, rect);
248 else
249 cfb_fillrect(info, rect);
253 /* ------------------------------------------------------------------------- */
256 static void vt8623_set_pixclock(struct fb_info *info, u32 pixclock)
258 u16 m, n, r;
259 u8 regval;
260 int rv;
262 rv = svga_compute_pll(&vt8623_pll, 1000000000 / pixclock, &m, &n, &r, info->node);
263 if (rv < 0) {
264 printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node);
265 return;
268 /* Set VGA misc register */
269 regval = vga_r(NULL, VGA_MIS_R);
270 vga_w(NULL, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
272 /* Set clock registers */
273 vga_wseq(NULL, 0x46, (n | (r << 6)));
274 vga_wseq(NULL, 0x47, m);
276 udelay(1000);
278 /* PLL reset */
279 svga_wseq_mask(0x40, 0x02, 0x02);
280 svga_wseq_mask(0x40, 0x00, 0x02);
284 static int vt8623fb_open(struct fb_info *info, int user)
286 struct vt8623fb_info *par = info->par;
288 mutex_lock(&(par->open_lock));
289 if (par->ref_count == 0) {
290 memset(&(par->state), 0, sizeof(struct vgastate));
291 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
292 par->state.num_crtc = 0xA2;
293 par->state.num_seq = 0x50;
294 save_vga(&(par->state));
297 par->ref_count++;
298 mutex_unlock(&(par->open_lock));
300 return 0;
303 static int vt8623fb_release(struct fb_info *info, int user)
305 struct vt8623fb_info *par = info->par;
307 mutex_lock(&(par->open_lock));
308 if (par->ref_count == 0) {
309 mutex_unlock(&(par->open_lock));
310 return -EINVAL;
313 if (par->ref_count == 1)
314 restore_vga(&(par->state));
316 par->ref_count--;
317 mutex_unlock(&(par->open_lock));
319 return 0;
322 static int vt8623fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
324 int rv, mem, step;
326 /* Find appropriate format */
327 rv = svga_match_format (vt8623fb_formats, var, NULL);
328 if (rv < 0)
330 printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node);
331 return rv;
334 /* Do not allow to have real resoulution larger than virtual */
335 if (var->xres > var->xres_virtual)
336 var->xres_virtual = var->xres;
338 if (var->yres > var->yres_virtual)
339 var->yres_virtual = var->yres;
341 /* Round up xres_virtual to have proper alignment of lines */
342 step = vt8623fb_formats[rv].xresstep - 1;
343 var->xres_virtual = (var->xres_virtual+step) & ~step;
345 /* Check whether have enough memory */
346 mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
347 if (mem > info->screen_size)
349 printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n", info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
350 return -EINVAL;
353 /* Text mode is limited to 256 kB of memory */
354 if ((var->bits_per_pixel == 0) && (mem > (256*1024)))
356 printk(KERN_ERR "fb%d: text framebuffer size too large (%d kB requested, 256 kB possible)\n", info->node, mem >> 10);
357 return -EINVAL;
360 rv = svga_check_timings (&vt8623_timing_regs, var, info->node);
361 if (rv < 0)
363 printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
364 return rv;
367 /* Interlaced mode not supported */
368 if (var->vmode & FB_VMODE_INTERLACED)
369 return -EINVAL;
371 return 0;
375 static int vt8623fb_set_par(struct fb_info *info)
377 u32 mode, offset_value, fetch_value, screen_size;
378 u32 bpp = info->var.bits_per_pixel;
380 if (bpp != 0) {
381 info->fix.ypanstep = 1;
382 info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
384 info->flags &= ~FBINFO_MISC_TILEBLITTING;
385 info->tileops = NULL;
387 /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
388 info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
389 info->pixmap.blit_y = ~(u32)0;
391 offset_value = (info->var.xres_virtual * bpp) / 64;
392 fetch_value = ((info->var.xres * bpp) / 128) + 4;
394 if (bpp == 4)
395 fetch_value = (info->var.xres / 8) + 8; /* + 0 is OK */
397 screen_size = info->var.yres_virtual * info->fix.line_length;
398 } else {
399 info->fix.ypanstep = 16;
400 info->fix.line_length = 0;
402 info->flags |= FBINFO_MISC_TILEBLITTING;
403 info->tileops = &vt8623fb_tile_ops;
405 /* supports 8x16 tiles only */
406 info->pixmap.blit_x = 1 << (8 - 1);
407 info->pixmap.blit_y = 1 << (16 - 1);
409 offset_value = info->var.xres_virtual / 16;
410 fetch_value = (info->var.xres / 8) + 8;
411 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
414 info->var.xoffset = 0;
415 info->var.yoffset = 0;
416 info->var.activate = FB_ACTIVATE_NOW;
418 /* Unlock registers */
419 svga_wseq_mask(0x10, 0x01, 0x01);
420 svga_wcrt_mask(0x11, 0x00, 0x80);
421 svga_wcrt_mask(0x47, 0x00, 0x01);
423 /* Device, screen and sync off */
424 svga_wseq_mask(0x01, 0x20, 0x20);
425 svga_wcrt_mask(0x36, 0x30, 0x30);
426 svga_wcrt_mask(0x17, 0x00, 0x80);
428 /* Set default values */
429 svga_set_default_gfx_regs();
430 svga_set_default_atc_regs();
431 svga_set_default_seq_regs();
432 svga_set_default_crt_regs();
433 svga_wcrt_multi(vt8623_line_compare_regs, 0xFFFFFFFF);
434 svga_wcrt_multi(vt8623_start_address_regs, 0);
436 svga_wcrt_multi(vt8623_offset_regs, offset_value);
437 svga_wseq_multi(vt8623_fetch_count_regs, fetch_value);
439 /* Clear H/V Skew */
440 svga_wcrt_mask(0x03, 0x00, 0x60);
441 svga_wcrt_mask(0x05, 0x00, 0x60);
443 if (info->var.vmode & FB_VMODE_DOUBLE)
444 svga_wcrt_mask(0x09, 0x80, 0x80);
445 else
446 svga_wcrt_mask(0x09, 0x00, 0x80);
448 svga_wseq_mask(0x1E, 0xF0, 0xF0); // DI/DVP bus
449 svga_wseq_mask(0x2A, 0x0F, 0x0F); // DI/DVP bus
450 svga_wseq_mask(0x16, 0x08, 0xBF); // FIFO read treshold
451 vga_wseq(NULL, 0x17, 0x1F); // FIFO depth
452 vga_wseq(NULL, 0x18, 0x4E);
453 svga_wseq_mask(0x1A, 0x08, 0x08); // enable MMIO ?
455 vga_wcrt(NULL, 0x32, 0x00);
456 vga_wcrt(NULL, 0x34, 0x00);
457 vga_wcrt(NULL, 0x6A, 0x80);
458 vga_wcrt(NULL, 0x6A, 0xC0);
460 vga_wgfx(NULL, 0x20, 0x00);
461 vga_wgfx(NULL, 0x21, 0x00);
462 vga_wgfx(NULL, 0x22, 0x00);
464 /* Set SR15 according to number of bits per pixel */
465 mode = svga_match_format(vt8623fb_formats, &(info->var), &(info->fix));
466 switch (mode) {
467 case 0:
468 pr_debug("fb%d: text mode\n", info->node);
469 svga_set_textmode_vga_regs();
470 svga_wseq_mask(0x15, 0x00, 0xFE);
471 svga_wcrt_mask(0x11, 0x60, 0x70);
472 break;
473 case 1:
474 pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
475 vga_wgfx(NULL, VGA_GFX_MODE, 0x40);
476 svga_wseq_mask(0x15, 0x20, 0xFE);
477 svga_wcrt_mask(0x11, 0x00, 0x70);
478 break;
479 case 2:
480 pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
481 svga_wseq_mask(0x15, 0x00, 0xFE);
482 svga_wcrt_mask(0x11, 0x00, 0x70);
483 break;
484 case 3:
485 pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
486 svga_wseq_mask(0x15, 0x22, 0xFE);
487 break;
488 case 4:
489 pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
490 svga_wseq_mask(0x15, 0xB6, 0xFE);
491 break;
492 case 5:
493 pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
494 svga_wseq_mask(0x15, 0xAE, 0xFE);
495 break;
496 default:
497 printk(KERN_ERR "vt8623fb: unsupported mode - bug\n");
498 return (-EINVAL);
501 vt8623_set_pixclock(info, info->var.pixclock);
502 svga_set_timings(&vt8623_timing_regs, &(info->var), 1, 1,
503 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1, 1,
504 1, info->node);
506 memset_io(info->screen_base, 0x00, screen_size);
508 /* Device and screen back on */
509 svga_wcrt_mask(0x17, 0x80, 0x80);
510 svga_wcrt_mask(0x36, 0x00, 0x30);
511 svga_wseq_mask(0x01, 0x00, 0x20);
513 return 0;
517 static int vt8623fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
518 u_int transp, struct fb_info *fb)
520 switch (fb->var.bits_per_pixel) {
521 case 0:
522 case 4:
523 if (regno >= 16)
524 return -EINVAL;
526 outb(0x0F, VGA_PEL_MSK);
527 outb(regno, VGA_PEL_IW);
528 outb(red >> 10, VGA_PEL_D);
529 outb(green >> 10, VGA_PEL_D);
530 outb(blue >> 10, VGA_PEL_D);
531 break;
532 case 8:
533 if (regno >= 256)
534 return -EINVAL;
536 outb(0xFF, VGA_PEL_MSK);
537 outb(regno, VGA_PEL_IW);
538 outb(red >> 10, VGA_PEL_D);
539 outb(green >> 10, VGA_PEL_D);
540 outb(blue >> 10, VGA_PEL_D);
541 break;
542 case 16:
543 if (regno >= 16)
544 return 0;
546 if (fb->var.green.length == 5)
547 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
548 ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
549 else if (fb->var.green.length == 6)
550 ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
551 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
552 else
553 return -EINVAL;
554 break;
555 case 24:
556 case 32:
557 if (regno >= 16)
558 return 0;
560 /* ((transp & 0xFF00) << 16) */
561 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
562 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
563 break;
564 default:
565 return -EINVAL;
568 return 0;
572 static int vt8623fb_blank(int blank_mode, struct fb_info *info)
574 switch (blank_mode) {
575 case FB_BLANK_UNBLANK:
576 pr_debug("fb%d: unblank\n", info->node);
577 svga_wcrt_mask(0x36, 0x00, 0x30);
578 svga_wseq_mask(0x01, 0x00, 0x20);
579 break;
580 case FB_BLANK_NORMAL:
581 pr_debug("fb%d: blank\n", info->node);
582 svga_wcrt_mask(0x36, 0x00, 0x30);
583 svga_wseq_mask(0x01, 0x20, 0x20);
584 break;
585 case FB_BLANK_HSYNC_SUSPEND:
586 pr_debug("fb%d: DPMS standby (hsync off)\n", info->node);
587 svga_wcrt_mask(0x36, 0x10, 0x30);
588 svga_wseq_mask(0x01, 0x20, 0x20);
589 break;
590 case FB_BLANK_VSYNC_SUSPEND:
591 pr_debug("fb%d: DPMS suspend (vsync off)\n", info->node);
592 svga_wcrt_mask(0x36, 0x20, 0x30);
593 svga_wseq_mask(0x01, 0x20, 0x20);
594 break;
595 case FB_BLANK_POWERDOWN:
596 pr_debug("fb%d: DPMS off (no sync)\n", info->node);
597 svga_wcrt_mask(0x36, 0x30, 0x30);
598 svga_wseq_mask(0x01, 0x20, 0x20);
599 break;
602 return 0;
606 static int vt8623fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
608 unsigned int offset;
610 /* Calculate the offset */
611 if (var->bits_per_pixel == 0) {
612 offset = (var->yoffset / 16) * var->xres_virtual + var->xoffset;
613 offset = offset >> 3;
614 } else {
615 offset = (var->yoffset * info->fix.line_length) +
616 (var->xoffset * var->bits_per_pixel / 8);
617 offset = offset >> ((var->bits_per_pixel == 4) ? 2 : 1);
620 /* Set the offset */
621 svga_wcrt_multi(vt8623_start_address_regs, offset);
623 return 0;
627 /* ------------------------------------------------------------------------- */
630 /* Frame buffer operations */
632 static struct fb_ops vt8623fb_ops = {
633 .owner = THIS_MODULE,
634 .fb_open = vt8623fb_open,
635 .fb_release = vt8623fb_release,
636 .fb_check_var = vt8623fb_check_var,
637 .fb_set_par = vt8623fb_set_par,
638 .fb_setcolreg = vt8623fb_setcolreg,
639 .fb_blank = vt8623fb_blank,
640 .fb_pan_display = vt8623fb_pan_display,
641 .fb_fillrect = vt8623fb_fillrect,
642 .fb_copyarea = cfb_copyarea,
643 .fb_imageblit = vt8623fb_imageblit,
644 .fb_get_caps = svga_get_caps,
648 /* PCI probe */
650 static int __devinit vt8623_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
652 struct fb_info *info;
653 struct vt8623fb_info *par;
654 unsigned int memsize1, memsize2;
655 int rc;
657 /* Ignore secondary VGA device because there is no VGA arbitration */
658 if (! svga_primary_device(dev)) {
659 dev_info(&(dev->dev), "ignoring secondary device\n");
660 return -ENODEV;
663 /* Allocate and fill driver data structure */
664 info = framebuffer_alloc(sizeof(struct vt8623fb_info), &(dev->dev));
665 if (! info) {
666 dev_err(&(dev->dev), "cannot allocate memory\n");
667 return -ENOMEM;
670 par = info->par;
671 mutex_init(&par->open_lock);
673 info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
674 info->fbops = &vt8623fb_ops;
676 /* Prepare PCI device */
678 rc = pci_enable_device(dev);
679 if (rc < 0) {
680 dev_err(info->dev, "cannot enable PCI device\n");
681 goto err_enable_device;
684 rc = pci_request_regions(dev, "vt8623fb");
685 if (rc < 0) {
686 dev_err(info->dev, "cannot reserve framebuffer region\n");
687 goto err_request_regions;
690 info->fix.smem_start = pci_resource_start(dev, 0);
691 info->fix.smem_len = pci_resource_len(dev, 0);
692 info->fix.mmio_start = pci_resource_start(dev, 1);
693 info->fix.mmio_len = pci_resource_len(dev, 1);
695 /* Map physical IO memory address into kernel space */
696 info->screen_base = pci_iomap(dev, 0, 0);
697 if (! info->screen_base) {
698 rc = -ENOMEM;
699 dev_err(info->dev, "iomap for framebuffer failed\n");
700 goto err_iomap_1;
703 par->mmio_base = pci_iomap(dev, 1, 0);
704 if (! par->mmio_base) {
705 rc = -ENOMEM;
706 dev_err(info->dev, "iomap for MMIO failed\n");
707 goto err_iomap_2;
710 /* Find how many physical memory there is on card */
711 memsize1 = (vga_rseq(NULL, 0x34) + 1) >> 1;
712 memsize2 = vga_rseq(NULL, 0x39) << 2;
714 if ((16 <= memsize1) && (memsize1 <= 64) && (memsize1 == memsize2))
715 info->screen_size = memsize1 << 20;
716 else {
717 dev_err(info->dev, "memory size detection failed (%x %x), suppose 16 MB\n", memsize1, memsize2);
718 info->screen_size = 16 << 20;
721 info->fix.smem_len = info->screen_size;
722 strcpy(info->fix.id, "VIA VT8623");
723 info->fix.type = FB_TYPE_PACKED_PIXELS;
724 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
725 info->fix.ypanstep = 0;
726 info->fix.accel = FB_ACCEL_NONE;
727 info->pseudo_palette = (void*)par->pseudo_palette;
729 /* Prepare startup mode */
731 rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8);
732 if (! ((rc == 1) || (rc == 2))) {
733 rc = -EINVAL;
734 dev_err(info->dev, "mode %s not found\n", mode_option);
735 goto err_find_mode;
738 rc = fb_alloc_cmap(&info->cmap, 256, 0);
739 if (rc < 0) {
740 dev_err(info->dev, "cannot allocate colormap\n");
741 goto err_alloc_cmap;
744 rc = register_framebuffer(info);
745 if (rc < 0) {
746 dev_err(info->dev, "cannot register framebugger\n");
747 goto err_reg_fb;
750 printk(KERN_INFO "fb%d: %s on %s, %d MB RAM\n", info->node, info->fix.id,
751 pci_name(dev), info->fix.smem_len >> 20);
753 /* Record a reference to the driver data */
754 pci_set_drvdata(dev, info);
756 #ifdef CONFIG_MTRR
757 if (mtrr) {
758 par->mtrr_reg = -1;
759 par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
761 #endif
763 return 0;
765 /* Error handling */
766 err_reg_fb:
767 fb_dealloc_cmap(&info->cmap);
768 err_alloc_cmap:
769 err_find_mode:
770 pci_iounmap(dev, par->mmio_base);
771 err_iomap_2:
772 pci_iounmap(dev, info->screen_base);
773 err_iomap_1:
774 pci_release_regions(dev);
775 err_request_regions:
776 /* pci_disable_device(dev); */
777 err_enable_device:
778 framebuffer_release(info);
779 return rc;
782 /* PCI remove */
784 static void __devexit vt8623_pci_remove(struct pci_dev *dev)
786 struct fb_info *info = pci_get_drvdata(dev);
788 if (info) {
789 struct vt8623fb_info *par = info->par;
791 #ifdef CONFIG_MTRR
792 if (par->mtrr_reg >= 0) {
793 mtrr_del(par->mtrr_reg, 0, 0);
794 par->mtrr_reg = -1;
796 #endif
798 unregister_framebuffer(info);
799 fb_dealloc_cmap(&info->cmap);
801 pci_iounmap(dev, info->screen_base);
802 pci_iounmap(dev, par->mmio_base);
803 pci_release_regions(dev);
804 /* pci_disable_device(dev); */
806 pci_set_drvdata(dev, NULL);
807 framebuffer_release(info);
812 #ifdef CONFIG_PM
813 /* PCI suspend */
815 static int vt8623_pci_suspend(struct pci_dev* dev, pm_message_t state)
817 struct fb_info *info = pci_get_drvdata(dev);
818 struct vt8623fb_info *par = info->par;
820 dev_info(info->dev, "suspend\n");
822 acquire_console_sem();
823 mutex_lock(&(par->open_lock));
825 if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
826 mutex_unlock(&(par->open_lock));
827 release_console_sem();
828 return 0;
831 fb_set_suspend(info, 1);
833 pci_save_state(dev);
834 pci_disable_device(dev);
835 pci_set_power_state(dev, pci_choose_state(dev, state));
837 mutex_unlock(&(par->open_lock));
838 release_console_sem();
840 return 0;
844 /* PCI resume */
846 static int vt8623_pci_resume(struct pci_dev* dev)
848 struct fb_info *info = pci_get_drvdata(dev);
849 struct vt8623fb_info *par = info->par;
851 dev_info(info->dev, "resume\n");
853 acquire_console_sem();
854 mutex_lock(&(par->open_lock));
856 if (par->ref_count == 0) {
857 mutex_unlock(&(par->open_lock));
858 release_console_sem();
859 return 0;
862 pci_set_power_state(dev, PCI_D0);
863 pci_restore_state(dev);
865 if (pci_enable_device(dev))
866 goto fail;
868 pci_set_master(dev);
870 vt8623fb_set_par(info);
871 fb_set_suspend(info, 0);
873 mutex_unlock(&(par->open_lock));
874 fail:
875 release_console_sem();
877 return 0;
879 #else
880 #define vt8623_pci_suspend NULL
881 #define vt8623_pci_resume NULL
882 #endif /* CONFIG_PM */
884 /* List of boards that we are trying to support */
886 static struct pci_device_id vt8623_devices[] __devinitdata = {
887 {PCI_DEVICE(PCI_VENDOR_ID_VIA, 0x3122)},
888 {0, 0, 0, 0, 0, 0, 0}
891 MODULE_DEVICE_TABLE(pci, vt8623_devices);
893 static struct pci_driver vt8623fb_pci_driver = {
894 .name = "vt8623fb",
895 .id_table = vt8623_devices,
896 .probe = vt8623_pci_probe,
897 .remove = __devexit_p(vt8623_pci_remove),
898 .suspend = vt8623_pci_suspend,
899 .resume = vt8623_pci_resume,
902 /* Cleanup */
904 static void __exit vt8623fb_cleanup(void)
906 pr_debug("vt8623fb: cleaning up\n");
907 pci_unregister_driver(&vt8623fb_pci_driver);
910 /* Driver Initialisation */
912 static int __init vt8623fb_init(void)
915 #ifndef MODULE
916 char *option = NULL;
918 if (fb_get_options("vt8623fb", &option))
919 return -ENODEV;
921 if (option && *option)
922 mode_option = option;
923 #endif
925 pr_debug("vt8623fb: initializing\n");
926 return pci_register_driver(&vt8623fb_pci_driver);
929 /* ------------------------------------------------------------------------- */
931 /* Modularization */
933 module_init(vt8623fb_init);
934 module_exit(vt8623fb_cleanup);