2 * linux/drivers/video/vt8623fb.c - fbdev driver for
3 * integrated graphic core in VIA VT8623 [CLE266] chipset
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
11 * Code is based on s3fb, some parts are from David Boucher's viafb
12 * (http://davesdomain.org.uk/viafb/)
15 #include <linux/aperture.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/string.h>
21 #include <linux/tty.h>
22 #include <linux/delay.h>
24 #include <linux/svga.h>
25 #include <linux/init.h>
26 #include <linux/pci.h>
27 #include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */
28 #include <video/vga.h>
30 struct vt8623fb_info {
31 char __iomem *mmio_base;
33 struct vgastate state;
34 struct mutex open_lock;
35 unsigned int ref_count;
36 u32 pseudo_palette[16];
41 /* ------------------------------------------------------------------------- */
43 static const struct svga_fb_format vt8623fb_formats[] = {
44 { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
45 FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP8, FB_VISUAL_PSEUDOCOLOR, 16, 16},
46 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
47 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 16, 16},
48 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1,
49 FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 16, 16},
50 { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
51 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 8},
52 /* {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
53 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4}, */
54 {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
55 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4},
56 {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
57 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 2},
61 static const struct svga_pll vt8623_pll = {2, 127, 2, 7, 0, 3,
62 60000, 300000, 14318};
64 /* CRT timing register sets */
66 static const struct vga_regset vt8623_h_total_regs[] = {{0x00, 0, 7}, {0x36, 3, 3}, VGA_REGSET_END};
67 static const struct vga_regset vt8623_h_display_regs[] = {{0x01, 0, 7}, VGA_REGSET_END};
68 static const struct vga_regset vt8623_h_blank_start_regs[] = {{0x02, 0, 7}, VGA_REGSET_END};
69 static const struct vga_regset vt8623_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7}, {0x33, 5, 5}, VGA_REGSET_END};
70 static const struct vga_regset vt8623_h_sync_start_regs[] = {{0x04, 0, 7}, {0x33, 4, 4}, VGA_REGSET_END};
71 static const struct vga_regset vt8623_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
73 static const struct vga_regset vt8623_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x35, 0, 0}, VGA_REGSET_END};
74 static const struct vga_regset vt8623_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x35, 2, 2}, VGA_REGSET_END};
75 static const struct vga_regset vt8623_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x35, 3, 3}, VGA_REGSET_END};
76 static const struct vga_regset vt8623_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
77 static const struct vga_regset vt8623_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x35, 1, 1}, VGA_REGSET_END};
78 static const struct vga_regset vt8623_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
80 static const struct vga_regset vt8623_offset_regs[] = {{0x13, 0, 7}, {0x35, 5, 7}, VGA_REGSET_END};
81 static const 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};
82 static const struct vga_regset vt8623_fetch_count_regs[] = {{0x1C, 0, 7}, {0x1D, 0, 1}, VGA_REGSET_END};
83 static const struct vga_regset vt8623_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x34, 0, 7}, {0x48, 0, 1}, VGA_REGSET_END};
85 static const struct svga_timing_regs vt8623_timing_regs = {
86 vt8623_h_total_regs, vt8623_h_display_regs, vt8623_h_blank_start_regs,
87 vt8623_h_blank_end_regs, vt8623_h_sync_start_regs, vt8623_h_sync_end_regs,
88 vt8623_v_total_regs, vt8623_v_display_regs, vt8623_v_blank_start_regs,
89 vt8623_v_blank_end_regs, vt8623_v_sync_start_regs, vt8623_v_sync_end_regs,
93 /* ------------------------------------------------------------------------- */
96 /* Module parameters */
98 static char *mode_option = "640x480-8@60";
102 MODULE_LICENSE("GPL");
103 MODULE_DESCRIPTION("fbdev driver for integrated graphics core in VIA VT8623 [CLE266]");
105 module_param(mode_option, charp, 0644);
106 MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)");
107 module_param_named(mode, mode_option, charp, 0);
108 MODULE_PARM_DESC(mode, "Default video mode e.g. '648x480-8@60' (deprecated)");
109 module_param(mtrr, int, 0444);
110 MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
113 /* ------------------------------------------------------------------------- */
115 static void vt8623fb_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor)
117 struct vt8623fb_info *par = info->par;
119 svga_tilecursor(par->state.vgabase, info, cursor);
122 static struct fb_tile_ops vt8623fb_tile_ops = {
123 .fb_settile = svga_settile,
124 .fb_tilecopy = svga_tilecopy,
125 .fb_tilefill = svga_tilefill,
126 .fb_tileblit = svga_tileblit,
127 .fb_tilecursor = vt8623fb_tilecursor,
128 .fb_get_tilemax = svga_get_tilemax,
132 /* ------------------------------------------------------------------------- */
135 /* image data is MSB-first, fb structure is MSB-first too */
136 static inline u32 expand_color(u32 c)
138 return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
141 /* vt8623fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
142 static void vt8623fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
144 u32 fg = expand_color(image->fg_color);
145 u32 bg = expand_color(image->bg_color);
146 const u8 *src1, *src;
153 dst1 = info->screen_base + (image->dy * info->fix.line_length)
154 + ((image->dx / 8) * 4);
156 for (y = 0; y < image->height; y++) {
158 dst = (u32 __iomem *) dst1;
159 for (x = 0; x < image->width; x += 8) {
160 val = *(src++) * 0x01010101;
161 val = (val & fg) | (~val & bg);
162 fb_writel(val, dst++);
164 src1 += image->width / 8;
165 dst1 += info->fix.line_length;
169 /* vt8623fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
170 static void vt8623fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
172 u32 fg = expand_color(rect->color);
177 dst1 = info->screen_base + (rect->dy * info->fix.line_length)
178 + ((rect->dx / 8) * 4);
180 for (y = 0; y < rect->height; y++) {
181 dst = (u32 __iomem *) dst1;
182 for (x = 0; x < rect->width; x += 8) {
183 fb_writel(fg, dst++);
185 dst1 += info->fix.line_length;
190 /* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
191 static inline u32 expand_pixel(u32 c)
193 return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
194 ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
197 /* vt8623fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
198 static void vt8623fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
200 u32 fg = image->fg_color * 0x11111111;
201 u32 bg = image->bg_color * 0x11111111;
202 const u8 *src1, *src;
209 dst1 = info->screen_base + (image->dy * info->fix.line_length)
210 + ((image->dx / 8) * 4);
212 for (y = 0; y < image->height; y++) {
214 dst = (u32 __iomem *) dst1;
215 for (x = 0; x < image->width; x += 8) {
216 val = expand_pixel(*(src++));
217 val = (val & fg) | (~val & bg);
218 fb_writel(val, dst++);
220 src1 += image->width / 8;
221 dst1 += info->fix.line_length;
225 static void vt8623fb_imageblit(struct fb_info *info, const struct fb_image *image)
227 if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
228 && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
229 if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
230 vt8623fb_iplan_imageblit(info, image);
232 vt8623fb_cfb4_imageblit(info, image);
234 cfb_imageblit(info, image);
237 static void vt8623fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
239 if ((info->var.bits_per_pixel == 4)
240 && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
241 && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
242 vt8623fb_iplan_fillrect(info, rect);
244 cfb_fillrect(info, rect);
248 /* ------------------------------------------------------------------------- */
251 static void vt8623_set_pixclock(struct fb_info *info, u32 pixclock)
253 struct vt8623fb_info *par = info->par;
258 rv = svga_compute_pll(&vt8623_pll, 1000000000 / pixclock, &m, &n, &r, info->node);
260 fb_err(info, "cannot set requested pixclock, keeping old value\n");
264 /* Set VGA misc register */
265 regval = vga_r(par->state.vgabase, VGA_MIS_R);
266 vga_w(par->state.vgabase, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
268 /* Set clock registers */
269 vga_wseq(par->state.vgabase, 0x46, (n | (r << 6)));
270 vga_wseq(par->state.vgabase, 0x47, m);
275 svga_wseq_mask(par->state.vgabase, 0x40, 0x02, 0x02);
276 svga_wseq_mask(par->state.vgabase, 0x40, 0x00, 0x02);
280 static int vt8623fb_open(struct fb_info *info, int user)
282 struct vt8623fb_info *par = info->par;
284 mutex_lock(&(par->open_lock));
285 if (par->ref_count == 0) {
286 void __iomem *vgabase = par->state.vgabase;
288 memset(&(par->state), 0, sizeof(struct vgastate));
289 par->state.vgabase = vgabase;
290 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
291 par->state.num_crtc = 0xA2;
292 par->state.num_seq = 0x50;
293 save_vga(&(par->state));
297 mutex_unlock(&(par->open_lock));
302 static int vt8623fb_release(struct fb_info *info, int user)
304 struct vt8623fb_info *par = info->par;
306 mutex_lock(&(par->open_lock));
307 if (par->ref_count == 0) {
308 mutex_unlock(&(par->open_lock));
312 if (par->ref_count == 1)
313 restore_vga(&(par->state));
316 mutex_unlock(&(par->open_lock));
321 static int vt8623fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
328 /* Find appropriate format */
329 rv = svga_match_format (vt8623fb_formats, var, NULL);
332 fb_err(info, "unsupported mode requested\n");
336 /* Do not allow to have real resoulution larger than virtual */
337 if (var->xres > var->xres_virtual)
338 var->xres_virtual = var->xres;
340 if (var->yres > var->yres_virtual)
341 var->yres_virtual = var->yres;
343 /* Round up xres_virtual to have proper alignment of lines */
344 step = vt8623fb_formats[rv].xresstep - 1;
345 var->xres_virtual = (var->xres_virtual+step) & ~step;
347 /* Check whether have enough memory */
348 mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
349 if (mem > info->screen_size)
351 fb_err(info, "not enough framebuffer memory (%d kB requested, %d kB available)\n",
352 mem >> 10, (unsigned int) (info->screen_size >> 10));
356 /* Text mode is limited to 256 kB of memory */
357 if ((var->bits_per_pixel == 0) && (mem > (256*1024)))
359 fb_err(info, "text framebuffer size too large (%d kB requested, 256 kB possible)\n",
364 rv = svga_check_timings (&vt8623_timing_regs, var, info->node);
367 fb_err(info, "invalid timings requested\n");
371 /* Interlaced mode not supported */
372 if (var->vmode & FB_VMODE_INTERLACED)
379 static int vt8623fb_set_par(struct fb_info *info)
381 u32 mode, offset_value, fetch_value, screen_size;
382 struct vt8623fb_info *par = info->par;
383 u32 bpp = info->var.bits_per_pixel;
386 info->fix.ypanstep = 1;
387 info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
389 info->flags &= ~FBINFO_MISC_TILEBLITTING;
390 info->tileops = NULL;
392 /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
393 info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
394 info->pixmap.blit_y = ~(u32)0;
396 offset_value = (info->var.xres_virtual * bpp) / 64;
397 fetch_value = ((info->var.xres * bpp) / 128) + 4;
400 fetch_value = (info->var.xres / 8) + 8; /* + 0 is OK */
402 screen_size = info->var.yres_virtual * info->fix.line_length;
404 info->fix.ypanstep = 16;
405 info->fix.line_length = 0;
407 info->flags |= FBINFO_MISC_TILEBLITTING;
408 info->tileops = &vt8623fb_tile_ops;
410 /* supports 8x16 tiles only */
411 info->pixmap.blit_x = 1 << (8 - 1);
412 info->pixmap.blit_y = 1 << (16 - 1);
414 offset_value = info->var.xres_virtual / 16;
415 fetch_value = (info->var.xres / 8) + 8;
416 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
419 info->var.xoffset = 0;
420 info->var.yoffset = 0;
421 info->var.activate = FB_ACTIVATE_NOW;
423 /* Unlock registers */
424 svga_wseq_mask(par->state.vgabase, 0x10, 0x01, 0x01);
425 svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x80);
426 svga_wcrt_mask(par->state.vgabase, 0x47, 0x00, 0x01);
428 /* Device, screen and sync off */
429 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
430 svga_wcrt_mask(par->state.vgabase, 0x36, 0x30, 0x30);
431 svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80);
433 /* Set default values */
434 svga_set_default_gfx_regs(par->state.vgabase);
435 svga_set_default_atc_regs(par->state.vgabase);
436 svga_set_default_seq_regs(par->state.vgabase);
437 svga_set_default_crt_regs(par->state.vgabase);
438 svga_wcrt_multi(par->state.vgabase, vt8623_line_compare_regs, 0xFFFFFFFF);
439 svga_wcrt_multi(par->state.vgabase, vt8623_start_address_regs, 0);
441 svga_wcrt_multi(par->state.vgabase, vt8623_offset_regs, offset_value);
442 svga_wseq_multi(par->state.vgabase, vt8623_fetch_count_regs, fetch_value);
445 svga_wcrt_mask(par->state.vgabase, 0x03, 0x00, 0x60);
446 svga_wcrt_mask(par->state.vgabase, 0x05, 0x00, 0x60);
448 if (info->var.vmode & FB_VMODE_DOUBLE)
449 svga_wcrt_mask(par->state.vgabase, 0x09, 0x80, 0x80);
451 svga_wcrt_mask(par->state.vgabase, 0x09, 0x00, 0x80);
453 svga_wseq_mask(par->state.vgabase, 0x1E, 0xF0, 0xF0); // DI/DVP bus
454 svga_wseq_mask(par->state.vgabase, 0x2A, 0x0F, 0x0F); // DI/DVP bus
455 svga_wseq_mask(par->state.vgabase, 0x16, 0x08, 0xBF); // FIFO read threshold
456 vga_wseq(par->state.vgabase, 0x17, 0x1F); // FIFO depth
457 vga_wseq(par->state.vgabase, 0x18, 0x4E);
458 svga_wseq_mask(par->state.vgabase, 0x1A, 0x08, 0x08); // enable MMIO ?
460 vga_wcrt(par->state.vgabase, 0x32, 0x00);
461 vga_wcrt(par->state.vgabase, 0x34, 0x00);
462 vga_wcrt(par->state.vgabase, 0x6A, 0x80);
463 vga_wcrt(par->state.vgabase, 0x6A, 0xC0);
465 vga_wgfx(par->state.vgabase, 0x20, 0x00);
466 vga_wgfx(par->state.vgabase, 0x21, 0x00);
467 vga_wgfx(par->state.vgabase, 0x22, 0x00);
469 /* Set SR15 according to number of bits per pixel */
470 mode = svga_match_format(vt8623fb_formats, &(info->var), &(info->fix));
473 fb_dbg(info, "text mode\n");
474 svga_set_textmode_vga_regs(par->state.vgabase);
475 svga_wseq_mask(par->state.vgabase, 0x15, 0x00, 0xFE);
476 svga_wcrt_mask(par->state.vgabase, 0x11, 0x60, 0x70);
479 fb_dbg(info, "4 bit pseudocolor\n");
480 vga_wgfx(par->state.vgabase, VGA_GFX_MODE, 0x40);
481 svga_wseq_mask(par->state.vgabase, 0x15, 0x20, 0xFE);
482 svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x70);
485 fb_dbg(info, "4 bit pseudocolor, planar\n");
486 svga_wseq_mask(par->state.vgabase, 0x15, 0x00, 0xFE);
487 svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x70);
490 fb_dbg(info, "8 bit pseudocolor\n");
491 svga_wseq_mask(par->state.vgabase, 0x15, 0x22, 0xFE);
494 fb_dbg(info, "5/6/5 truecolor\n");
495 svga_wseq_mask(par->state.vgabase, 0x15, 0xB6, 0xFE);
498 fb_dbg(info, "8/8/8 truecolor\n");
499 svga_wseq_mask(par->state.vgabase, 0x15, 0xAE, 0xFE);
502 printk(KERN_ERR "vt8623fb: unsupported mode - bug\n");
506 vt8623_set_pixclock(info, info->var.pixclock);
507 svga_set_timings(par->state.vgabase, &vt8623_timing_regs, &(info->var), 1, 1,
508 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1, 1,
511 if (screen_size > info->screen_size)
512 screen_size = info->screen_size;
513 memset_io(info->screen_base, 0x00, screen_size);
515 /* Device and screen back on */
516 svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
517 svga_wcrt_mask(par->state.vgabase, 0x36, 0x00, 0x30);
518 svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
524 static int vt8623fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
525 u_int transp, struct fb_info *fb)
527 switch (fb->var.bits_per_pixel) {
533 outb(0x0F, VGA_PEL_MSK);
534 outb(regno, VGA_PEL_IW);
535 outb(red >> 10, VGA_PEL_D);
536 outb(green >> 10, VGA_PEL_D);
537 outb(blue >> 10, VGA_PEL_D);
543 outb(0xFF, VGA_PEL_MSK);
544 outb(regno, VGA_PEL_IW);
545 outb(red >> 10, VGA_PEL_D);
546 outb(green >> 10, VGA_PEL_D);
547 outb(blue >> 10, VGA_PEL_D);
553 if (fb->var.green.length == 5)
554 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
555 ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
556 else if (fb->var.green.length == 6)
557 ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
558 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
567 /* ((transp & 0xFF00) << 16) */
568 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
569 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
579 static int vt8623fb_blank(int blank_mode, struct fb_info *info)
581 struct vt8623fb_info *par = info->par;
583 switch (blank_mode) {
584 case FB_BLANK_UNBLANK:
585 fb_dbg(info, "unblank\n");
586 svga_wcrt_mask(par->state.vgabase, 0x36, 0x00, 0x30);
587 svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
589 case FB_BLANK_NORMAL:
590 fb_dbg(info, "blank\n");
591 svga_wcrt_mask(par->state.vgabase, 0x36, 0x00, 0x30);
592 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
594 case FB_BLANK_HSYNC_SUSPEND:
595 fb_dbg(info, "DPMS standby (hsync off)\n");
596 svga_wcrt_mask(par->state.vgabase, 0x36, 0x10, 0x30);
597 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
599 case FB_BLANK_VSYNC_SUSPEND:
600 fb_dbg(info, "DPMS suspend (vsync off)\n");
601 svga_wcrt_mask(par->state.vgabase, 0x36, 0x20, 0x30);
602 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
604 case FB_BLANK_POWERDOWN:
605 fb_dbg(info, "DPMS off (no sync)\n");
606 svga_wcrt_mask(par->state.vgabase, 0x36, 0x30, 0x30);
607 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
615 static int vt8623fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
617 struct vt8623fb_info *par = info->par;
620 /* Calculate the offset */
621 if (info->var.bits_per_pixel == 0) {
622 offset = (var->yoffset / 16) * info->var.xres_virtual
624 offset = offset >> 3;
626 offset = (var->yoffset * info->fix.line_length) +
627 (var->xoffset * info->var.bits_per_pixel / 8);
628 offset = offset >> ((info->var.bits_per_pixel == 4) ? 2 : 1);
632 svga_wcrt_multi(par->state.vgabase, vt8623_start_address_regs, offset);
638 /* ------------------------------------------------------------------------- */
641 /* Frame buffer operations */
643 static const struct fb_ops vt8623fb_ops = {
644 .owner = THIS_MODULE,
645 .fb_open = vt8623fb_open,
646 .fb_release = vt8623fb_release,
647 .fb_check_var = vt8623fb_check_var,
648 .fb_set_par = vt8623fb_set_par,
649 .fb_setcolreg = vt8623fb_setcolreg,
650 .fb_blank = vt8623fb_blank,
651 .fb_pan_display = vt8623fb_pan_display,
652 .fb_fillrect = vt8623fb_fillrect,
653 .fb_copyarea = cfb_copyarea,
654 .fb_imageblit = vt8623fb_imageblit,
655 .fb_get_caps = svga_get_caps,
661 static int vt8623_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
663 struct pci_bus_region bus_reg;
664 struct resource vga_res;
665 struct fb_info *info;
666 struct vt8623fb_info *par;
667 unsigned int memsize1, memsize2;
670 /* Ignore secondary VGA device because there is no VGA arbitration */
671 if (! svga_primary_device(dev)) {
672 dev_info(&(dev->dev), "ignoring secondary device\n");
676 rc = aperture_remove_conflicting_pci_devices(dev, "vt8623fb");
680 /* Allocate and fill driver data structure */
681 info = framebuffer_alloc(sizeof(struct vt8623fb_info), &(dev->dev));
686 mutex_init(&par->open_lock);
688 info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
689 info->fbops = &vt8623fb_ops;
691 /* Prepare PCI device */
693 rc = pci_enable_device(dev);
695 dev_err(info->device, "cannot enable PCI device\n");
696 goto err_enable_device;
699 rc = pci_request_regions(dev, "vt8623fb");
701 dev_err(info->device, "cannot reserve framebuffer region\n");
702 goto err_request_regions;
705 info->fix.smem_start = pci_resource_start(dev, 0);
706 info->fix.smem_len = pci_resource_len(dev, 0);
707 info->fix.mmio_start = pci_resource_start(dev, 1);
708 info->fix.mmio_len = pci_resource_len(dev, 1);
710 /* Map physical IO memory address into kernel space */
711 info->screen_base = pci_iomap_wc(dev, 0, 0);
712 if (! info->screen_base) {
714 dev_err(info->device, "iomap for framebuffer failed\n");
718 par->mmio_base = pci_iomap(dev, 1, 0);
719 if (! par->mmio_base) {
721 dev_err(info->device, "iomap for MMIO failed\n");
726 bus_reg.end = 64 * 1024;
728 vga_res.flags = IORESOURCE_IO;
730 pcibios_bus_to_resource(dev->bus, &vga_res, &bus_reg);
732 par->state.vgabase = (void __iomem *) (unsigned long) vga_res.start;
734 /* Find how many physical memory there is on card */
735 memsize1 = (vga_rseq(par->state.vgabase, 0x34) + 1) >> 1;
736 memsize2 = vga_rseq(par->state.vgabase, 0x39) << 2;
738 if ((16 <= memsize1) && (memsize1 <= 64) && (memsize1 == memsize2))
739 info->screen_size = memsize1 << 20;
741 dev_err(info->device, "memory size detection failed (%x %x), suppose 16 MB\n", memsize1, memsize2);
742 info->screen_size = 16 << 20;
745 info->fix.smem_len = info->screen_size;
746 strcpy(info->fix.id, "VIA VT8623");
747 info->fix.type = FB_TYPE_PACKED_PIXELS;
748 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
749 info->fix.ypanstep = 0;
750 info->fix.accel = FB_ACCEL_NONE;
751 info->pseudo_palette = (void*)par->pseudo_palette;
753 /* Prepare startup mode */
755 kernel_param_lock(THIS_MODULE);
756 rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8);
757 kernel_param_unlock(THIS_MODULE);
758 if (! ((rc == 1) || (rc == 2))) {
760 dev_err(info->device, "mode %s not found\n", mode_option);
764 rc = fb_alloc_cmap(&info->cmap, 256, 0);
766 dev_err(info->device, "cannot allocate colormap\n");
770 rc = register_framebuffer(info);
772 dev_err(info->device, "cannot register framebuffer\n");
776 fb_info(info, "%s on %s, %d MB RAM\n",
777 info->fix.id, pci_name(dev), info->fix.smem_len >> 20);
779 /* Record a reference to the driver data */
780 pci_set_drvdata(dev, info);
783 par->wc_cookie = arch_phys_wc_add(info->fix.smem_start,
790 fb_dealloc_cmap(&info->cmap);
793 pci_iounmap(dev, par->mmio_base);
795 pci_iounmap(dev, info->screen_base);
797 pci_release_regions(dev);
799 /* pci_disable_device(dev); */
801 framebuffer_release(info);
807 static void vt8623_pci_remove(struct pci_dev *dev)
809 struct fb_info *info = pci_get_drvdata(dev);
812 struct vt8623fb_info *par = info->par;
814 arch_phys_wc_del(par->wc_cookie);
815 unregister_framebuffer(info);
816 fb_dealloc_cmap(&info->cmap);
818 pci_iounmap(dev, info->screen_base);
819 pci_iounmap(dev, par->mmio_base);
820 pci_release_regions(dev);
821 /* pci_disable_device(dev); */
823 framebuffer_release(info);
830 static int __maybe_unused vt8623_pci_suspend(struct device *dev)
832 struct fb_info *info = dev_get_drvdata(dev);
833 struct vt8623fb_info *par = info->par;
835 dev_info(info->device, "suspend\n");
838 mutex_lock(&(par->open_lock));
840 if (par->ref_count == 0) {
841 mutex_unlock(&(par->open_lock));
846 fb_set_suspend(info, 1);
848 mutex_unlock(&(par->open_lock));
857 static int __maybe_unused vt8623_pci_resume(struct device *dev)
859 struct fb_info *info = dev_get_drvdata(dev);
860 struct vt8623fb_info *par = info->par;
862 dev_info(info->device, "resume\n");
865 mutex_lock(&(par->open_lock));
867 if (par->ref_count == 0)
870 vt8623fb_set_par(info);
871 fb_set_suspend(info, 0);
874 mutex_unlock(&(par->open_lock));
880 static const struct dev_pm_ops vt8623_pci_pm_ops = {
881 #ifdef CONFIG_PM_SLEEP
882 .suspend = vt8623_pci_suspend,
883 .resume = vt8623_pci_resume,
885 .thaw = vt8623_pci_resume,
886 .poweroff = vt8623_pci_suspend,
887 .restore = vt8623_pci_resume,
888 #endif /* CONFIG_PM_SLEEP */
891 /* List of boards that we are trying to support */
893 static const struct pci_device_id vt8623_devices[] = {
894 {PCI_DEVICE(PCI_VENDOR_ID_VIA, 0x3122)},
895 {0, 0, 0, 0, 0, 0, 0}
898 MODULE_DEVICE_TABLE(pci, vt8623_devices);
900 static struct pci_driver vt8623fb_pci_driver = {
902 .id_table = vt8623_devices,
903 .probe = vt8623_pci_probe,
904 .remove = vt8623_pci_remove,
905 .driver.pm = &vt8623_pci_pm_ops,
910 static void __exit vt8623fb_cleanup(void)
912 pr_debug("vt8623fb: cleaning up\n");
913 pci_unregister_driver(&vt8623fb_pci_driver);
916 /* Driver Initialisation */
918 static int __init vt8623fb_init(void)
925 if (fb_modesetting_disabled("vt8623fb"))
929 if (fb_get_options("vt8623fb", &option))
932 if (option && *option)
933 mode_option = option;
936 pr_debug("vt8623fb: initializing\n");
937 return pci_register_driver(&vt8623fb_pci_driver);
940 /* ------------------------------------------------------------------------- */
944 module_init(vt8623fb_init);
945 module_exit(vt8623fb_cleanup);