2 * linux/drivers/video/arkfb.c -- Frame buffer device driver for ARK 2000PV
3 * with ICS 5342 dac (it is easy to add support for different dacs).
5 * Copyright (c) 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
11 * Code is based on s3fb
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
19 #include <linux/tty.h>
20 #include <linux/slab.h>
21 #include <linux/delay.h>
23 #include <linux/svga.h>
24 #include <linux/init.h>
25 #include <linux/pci.h>
26 #include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */
27 #include <video/vga.h>
34 struct vgastate state;
35 struct mutex open_lock;
36 unsigned int ref_count;
37 u32 pseudo_palette[16];
41 /* ------------------------------------------------------------------------- */
44 static const struct svga_fb_format arkfb_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, 8},
47 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
48 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16},
49 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1,
50 FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16},
51 { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
52 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 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, 4, 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, 4, 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, 8, 8},
59 {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
60 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 2},
65 /* CRT timing register sets */
67 static const struct vga_regset ark_h_total_regs[] = {{0x00, 0, 7}, {0x41, 7, 7}, VGA_REGSET_END};
68 static const struct vga_regset ark_h_display_regs[] = {{0x01, 0, 7}, {0x41, 6, 6}, VGA_REGSET_END};
69 static const struct vga_regset ark_h_blank_start_regs[] = {{0x02, 0, 7}, {0x41, 5, 5}, VGA_REGSET_END};
70 static const struct vga_regset ark_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7 }, VGA_REGSET_END};
71 static const struct vga_regset ark_h_sync_start_regs[] = {{0x04, 0, 7}, {0x41, 4, 4}, VGA_REGSET_END};
72 static const struct vga_regset ark_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
74 static const struct vga_regset ark_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x40, 7, 7}, VGA_REGSET_END};
75 static const struct vga_regset ark_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x40, 6, 6}, VGA_REGSET_END};
76 static const struct vga_regset ark_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x40, 5, 5}, VGA_REGSET_END};
77 // const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 6}, VGA_REGSET_END};
78 static const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
79 static const struct vga_regset ark_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x40, 4, 4}, VGA_REGSET_END};
80 static const struct vga_regset ark_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
82 static const struct vga_regset ark_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, VGA_REGSET_END};
83 static const struct vga_regset ark_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x40, 0, 2}, VGA_REGSET_END};
84 static const struct vga_regset ark_offset_regs[] = {{0x13, 0, 7}, {0x41, 3, 3}, VGA_REGSET_END};
86 static const struct svga_timing_regs ark_timing_regs = {
87 ark_h_total_regs, ark_h_display_regs, ark_h_blank_start_regs,
88 ark_h_blank_end_regs, ark_h_sync_start_regs, ark_h_sync_end_regs,
89 ark_v_total_regs, ark_v_display_regs, ark_v_blank_start_regs,
90 ark_v_blank_end_regs, ark_v_sync_start_regs, ark_v_sync_end_regs,
94 /* ------------------------------------------------------------------------- */
97 /* Module parameters */
99 static char *mode_option = "640x480-8@60";
101 MODULE_AUTHOR("(c) 2007 Ondrej Zajicek <santiago@crfreenet.org>");
102 MODULE_LICENSE("GPL");
103 MODULE_DESCRIPTION("fbdev driver for ARK 2000PV");
105 module_param(mode_option, charp, 0444);
106 MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)");
107 module_param_named(mode, mode_option, charp, 0444);
108 MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc) (deprecated)");
110 static int threshold = 4;
112 module_param(threshold, int, 0644);
113 MODULE_PARM_DESC(threshold, "FIFO threshold");
116 /* ------------------------------------------------------------------------- */
119 static void arkfb_settile(struct fb_info *info, struct fb_tilemap *map)
121 const u8 *font = map->data;
122 u8 __iomem *fb = (u8 __iomem *)info->screen_base;
125 if ((map->width != 8) || (map->height != 16) ||
126 (map->depth != 1) || (map->length != 256)) {
127 fb_err(info, "unsupported font parameters: width %d, height %d, depth %d, length %d\n",
128 map->width, map->height, map->depth, map->length);
133 for (c = 0; c < map->length; c++) {
134 for (i = 0; i < map->height; i++) {
135 fb_writeb(font[i], &fb[i * 4]);
136 fb_writeb(font[i], &fb[i * 4 + (128 * 8)]);
147 static void arkfb_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor)
149 struct arkfb_info *par = info->par;
151 svga_tilecursor(par->state.vgabase, info, cursor);
154 static struct fb_tile_ops arkfb_tile_ops = {
155 .fb_settile = arkfb_settile,
156 .fb_tilecopy = svga_tilecopy,
157 .fb_tilefill = svga_tilefill,
158 .fb_tileblit = svga_tileblit,
159 .fb_tilecursor = arkfb_tilecursor,
160 .fb_get_tilemax = svga_get_tilemax,
164 /* ------------------------------------------------------------------------- */
167 /* image data is MSB-first, fb structure is MSB-first too */
168 static inline u32 expand_color(u32 c)
170 return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
173 /* arkfb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
174 static void arkfb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
176 u32 fg = expand_color(image->fg_color);
177 u32 bg = expand_color(image->bg_color);
178 const u8 *src1, *src;
185 dst1 = info->screen_base + (image->dy * info->fix.line_length)
186 + ((image->dx / 8) * 4);
188 for (y = 0; y < image->height; y++) {
190 dst = (u32 __iomem *) dst1;
191 for (x = 0; x < image->width; x += 8) {
192 val = *(src++) * 0x01010101;
193 val = (val & fg) | (~val & bg);
194 fb_writel(val, dst++);
196 src1 += image->width / 8;
197 dst1 += info->fix.line_length;
202 /* arkfb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
203 static void arkfb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
205 u32 fg = expand_color(rect->color);
210 dst1 = info->screen_base + (rect->dy * info->fix.line_length)
211 + ((rect->dx / 8) * 4);
213 for (y = 0; y < rect->height; y++) {
214 dst = (u32 __iomem *) dst1;
215 for (x = 0; x < rect->width; x += 8) {
216 fb_writel(fg, dst++);
218 dst1 += info->fix.line_length;
224 /* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
225 static inline u32 expand_pixel(u32 c)
227 return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
228 ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
231 /* arkfb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
232 static void arkfb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
234 u32 fg = image->fg_color * 0x11111111;
235 u32 bg = image->bg_color * 0x11111111;
236 const u8 *src1, *src;
243 dst1 = info->screen_base + (image->dy * info->fix.line_length)
244 + ((image->dx / 8) * 4);
246 for (y = 0; y < image->height; y++) {
248 dst = (u32 __iomem *) dst1;
249 for (x = 0; x < image->width; x += 8) {
250 val = expand_pixel(*(src++));
251 val = (val & fg) | (~val & bg);
252 fb_writel(val, dst++);
254 src1 += image->width / 8;
255 dst1 += info->fix.line_length;
260 static void arkfb_imageblit(struct fb_info *info, const struct fb_image *image)
262 if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
263 && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
264 if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
265 arkfb_iplan_imageblit(info, image);
267 arkfb_cfb4_imageblit(info, image);
269 cfb_imageblit(info, image);
272 static void arkfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
274 if ((info->var.bits_per_pixel == 4)
275 && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
276 && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
277 arkfb_iplan_fillrect(info, rect);
279 cfb_fillrect(info, rect);
283 /* ------------------------------------------------------------------------- */
302 int (*dac_get_mode)(struct dac_info *info);
303 int (*dac_set_mode)(struct dac_info *info, int mode);
304 int (*dac_get_freq)(struct dac_info *info, int channel);
305 int (*dac_set_freq)(struct dac_info *info, int channel, u32 freq);
306 void (*dac_release)(struct dac_info *info);
309 typedef void (*dac_read_regs_t)(void *data, u8 *code, int count);
310 typedef void (*dac_write_regs_t)(void *data, u8 *code, int count);
314 struct dac_ops *dacops;
315 dac_read_regs_t dac_read_regs;
316 dac_write_regs_t dac_write_regs;
321 static inline u8 dac_read_reg(struct dac_info *info, u8 reg)
323 u8 code[2] = {reg, 0};
324 info->dac_read_regs(info->data, code, 1);
328 static inline void dac_read_regs(struct dac_info *info, u8 *code, int count)
330 info->dac_read_regs(info->data, code, count);
333 static inline void dac_write_reg(struct dac_info *info, u8 reg, u8 val)
335 u8 code[2] = {reg, val};
336 info->dac_write_regs(info->data, code, 1);
339 static inline void dac_write_regs(struct dac_info *info, u8 *code, int count)
341 info->dac_write_regs(info->data, code, count);
344 static inline int dac_set_mode(struct dac_info *info, int mode)
346 return info->dacops->dac_set_mode(info, mode);
349 static inline int dac_set_freq(struct dac_info *info, int channel, u32 freq)
351 return info->dacops->dac_set_freq(info, channel, freq);
354 static inline void dac_release(struct dac_info *info)
356 info->dacops->dac_release(info);
360 /* ------------------------------------------------------------------------- */
371 #define DAC_PAR(info) ((struct ics5342_info *) info)
373 /* LSB is set to distinguish unused slots */
374 static const u8 ics5342_mode_table[DAC_MAX] = {
375 [DAC_PSEUDO8_8] = 0x01, [DAC_RGB1555_8] = 0x21, [DAC_RGB0565_8] = 0x61,
376 [DAC_RGB0888_8] = 0x41, [DAC_PSEUDO8_16] = 0x11, [DAC_RGB1555_16] = 0x31,
377 [DAC_RGB0565_16] = 0x51, [DAC_RGB0888_16] = 0x91, [DAC_RGB8888_16] = 0x71
380 static int ics5342_set_mode(struct dac_info *info, int mode)
387 code = ics5342_mode_table[mode];
392 dac_write_reg(info, 6, code & 0xF0);
393 DAC_PAR(info)->mode = mode;
398 static const struct svga_pll ics5342_pll = {3, 129, 3, 33, 0, 3,
399 60000, 250000, 14318};
401 /* pd4 - allow only posdivider 4 (r=2) */
402 static const struct svga_pll ics5342_pll_pd4 = {3, 129, 3, 33, 2, 2,
403 60000, 335000, 14318};
405 /* 270 MHz should be upper bound for VCO clock according to specs,
406 but that is too restrictive in pd4 case */
408 static int ics5342_set_freq(struct dac_info *info, int channel, u32 freq)
412 /* only postdivider 4 (r=2) is valid in mode DAC_PSEUDO8_16 */
413 int rv = svga_compute_pll((DAC_PAR(info)->mode == DAC_PSEUDO8_16)
414 ? &ics5342_pll_pd4 : &ics5342_pll,
415 freq, &m, &n, &r, 0);
420 u8 code[6] = {4, 3, 5, m-2, 5, (n-2) | (r << 5)};
421 dac_write_regs(info, code, 3);
426 static void ics5342_release(struct dac_info *info)
428 ics5342_set_mode(info, DAC_PSEUDO8_8);
432 static struct dac_ops ics5342_ops = {
433 .dac_set_mode = ics5342_set_mode,
434 .dac_set_freq = ics5342_set_freq,
435 .dac_release = ics5342_release
439 static struct dac_info * ics5342_init(dac_read_regs_t drr, dac_write_regs_t dwr, void *data)
441 struct dac_info *info = kzalloc(sizeof(struct ics5342_info), GFP_KERNEL);
446 info->dacops = &ics5342_ops;
447 info->dac_read_regs = drr;
448 info->dac_write_regs = dwr;
450 DAC_PAR(info)->mode = DAC_PSEUDO8_8; /* estimation */
455 /* ------------------------------------------------------------------------- */
458 static unsigned short dac_regs[4] = {0x3c8, 0x3c9, 0x3c6, 0x3c7};
460 static void ark_dac_read_regs(void *data, u8 *code, int count)
462 struct fb_info *info = data;
463 struct arkfb_info *par;
467 regval = vga_rseq(par->state.vgabase, 0x1C);
470 vga_wseq(par->state.vgabase, 0x1C, regval | (code[0] & 4 ? 0x80 : 0));
471 code[1] = vga_r(par->state.vgabase, dac_regs[code[0] & 3]);
476 vga_wseq(par->state.vgabase, 0x1C, regval);
479 static void ark_dac_write_regs(void *data, u8 *code, int count)
481 struct fb_info *info = data;
482 struct arkfb_info *par;
486 regval = vga_rseq(par->state.vgabase, 0x1C);
489 vga_wseq(par->state.vgabase, 0x1C, regval | (code[0] & 4 ? 0x80 : 0));
490 vga_w(par->state.vgabase, dac_regs[code[0] & 3], code[1]);
495 vga_wseq(par->state.vgabase, 0x1C, regval);
499 static void ark_set_pixclock(struct fb_info *info, u32 pixclock)
501 struct arkfb_info *par = info->par;
504 int rv = dac_set_freq(par->dac, 0, 1000000000 / pixclock);
506 fb_err(info, "cannot set requested pixclock, keeping old value\n");
510 /* Set VGA misc register */
511 regval = vga_r(par->state.vgabase, VGA_MIS_R);
512 vga_w(par->state.vgabase, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
516 /* Open framebuffer */
518 static int arkfb_open(struct fb_info *info, int user)
520 struct arkfb_info *par = info->par;
522 mutex_lock(&(par->open_lock));
523 if (par->ref_count == 0) {
524 void __iomem *vgabase = par->state.vgabase;
526 memset(&(par->state), 0, sizeof(struct vgastate));
527 par->state.vgabase = vgabase;
528 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
529 par->state.num_crtc = 0x60;
530 par->state.num_seq = 0x30;
531 save_vga(&(par->state));
535 mutex_unlock(&(par->open_lock));
540 /* Close framebuffer */
542 static int arkfb_release(struct fb_info *info, int user)
544 struct arkfb_info *par = info->par;
546 mutex_lock(&(par->open_lock));
547 if (par->ref_count == 0) {
548 mutex_unlock(&(par->open_lock));
552 if (par->ref_count == 1) {
553 restore_vga(&(par->state));
554 dac_set_mode(par->dac, DAC_PSEUDO8_8);
558 mutex_unlock(&(par->open_lock));
563 /* Validate passed in var */
565 static int arkfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
569 /* Find appropriate format */
570 rv = svga_match_format (arkfb_formats, var, NULL);
573 fb_err(info, "unsupported mode requested\n");
577 /* Do not allow to have real resoulution larger than virtual */
578 if (var->xres > var->xres_virtual)
579 var->xres_virtual = var->xres;
581 if (var->yres > var->yres_virtual)
582 var->yres_virtual = var->yres;
584 /* Round up xres_virtual to have proper alignment of lines */
585 step = arkfb_formats[rv].xresstep - 1;
586 var->xres_virtual = (var->xres_virtual+step) & ~step;
589 /* Check whether have enough memory */
590 mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
591 if (mem > info->screen_size)
593 fb_err(info, "not enough framebuffer memory (%d kB requested, %d kB available)\n",
594 mem >> 10, (unsigned int) (info->screen_size >> 10));
598 rv = svga_check_timings (&ark_timing_regs, var, info->node);
601 fb_err(info, "invalid timings requested\n");
605 /* Interlaced mode is broken */
606 if (var->vmode & FB_VMODE_INTERLACED)
612 /* Set video mode from par */
614 static int arkfb_set_par(struct fb_info *info)
616 struct arkfb_info *par = info->par;
617 u32 value, mode, hmul, hdiv, offset_value, screen_size;
618 u32 bpp = info->var.bits_per_pixel;
622 info->fix.ypanstep = 1;
623 info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
625 info->flags &= ~FBINFO_MISC_TILEBLITTING;
626 info->tileops = NULL;
628 /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
629 info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
630 info->pixmap.blit_y = ~(u32)0;
632 offset_value = (info->var.xres_virtual * bpp) / 64;
633 screen_size = info->var.yres_virtual * info->fix.line_length;
635 info->fix.ypanstep = 16;
636 info->fix.line_length = 0;
638 info->flags |= FBINFO_MISC_TILEBLITTING;
639 info->tileops = &arkfb_tile_ops;
641 /* supports 8x16 tiles only */
642 info->pixmap.blit_x = 1 << (8 - 1);
643 info->pixmap.blit_y = 1 << (16 - 1);
645 offset_value = info->var.xres_virtual / 16;
646 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
649 info->var.xoffset = 0;
650 info->var.yoffset = 0;
651 info->var.activate = FB_ACTIVATE_NOW;
653 /* Unlock registers */
654 svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x80);
656 /* Blank screen and turn off sync */
657 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
658 svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80);
660 /* Set default values */
661 svga_set_default_gfx_regs(par->state.vgabase);
662 svga_set_default_atc_regs(par->state.vgabase);
663 svga_set_default_seq_regs(par->state.vgabase);
664 svga_set_default_crt_regs(par->state.vgabase);
665 svga_wcrt_multi(par->state.vgabase, ark_line_compare_regs, 0xFFFFFFFF);
666 svga_wcrt_multi(par->state.vgabase, ark_start_address_regs, 0);
668 /* ARK specific initialization */
669 svga_wseq_mask(par->state.vgabase, 0x10, 0x1F, 0x1F); /* enable linear framebuffer and full memory access */
670 svga_wseq_mask(par->state.vgabase, 0x12, 0x03, 0x03); /* 4 MB linear framebuffer size */
672 vga_wseq(par->state.vgabase, 0x13, info->fix.smem_start >> 16);
673 vga_wseq(par->state.vgabase, 0x14, info->fix.smem_start >> 24);
674 vga_wseq(par->state.vgabase, 0x15, 0);
675 vga_wseq(par->state.vgabase, 0x16, 0);
677 /* Set the FIFO threshold register */
678 /* It is fascinating way to store 5-bit value in 8-bit register */
679 regval = 0x10 | ((threshold & 0x0E) >> 1) | (threshold & 0x01) << 7 | (threshold & 0x10) << 1;
680 vga_wseq(par->state.vgabase, 0x18, regval);
682 /* Set the offset register */
683 fb_dbg(info, "offset register : %d\n", offset_value);
684 svga_wcrt_multi(par->state.vgabase, ark_offset_regs, offset_value);
686 /* fix for hi-res textmode */
687 svga_wcrt_mask(par->state.vgabase, 0x40, 0x08, 0x08);
689 if (info->var.vmode & FB_VMODE_DOUBLE)
690 svga_wcrt_mask(par->state.vgabase, 0x09, 0x80, 0x80);
692 svga_wcrt_mask(par->state.vgabase, 0x09, 0x00, 0x80);
694 if (info->var.vmode & FB_VMODE_INTERLACED)
695 svga_wcrt_mask(par->state.vgabase, 0x44, 0x04, 0x04);
697 svga_wcrt_mask(par->state.vgabase, 0x44, 0x00, 0x04);
701 mode = svga_match_format(arkfb_formats, &(info->var), &(info->fix));
703 /* Set mode-specific register values */
706 fb_dbg(info, "text mode\n");
707 svga_set_textmode_vga_regs(par->state.vgabase);
709 vga_wseq(par->state.vgabase, 0x11, 0x10); /* basic VGA mode */
710 svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */
711 dac_set_mode(par->dac, DAC_PSEUDO8_8);
715 fb_dbg(info, "4 bit pseudocolor\n");
716 vga_wgfx(par->state.vgabase, VGA_GFX_MODE, 0x40);
718 vga_wseq(par->state.vgabase, 0x11, 0x10); /* basic VGA mode */
719 svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */
720 dac_set_mode(par->dac, DAC_PSEUDO8_8);
723 fb_dbg(info, "4 bit pseudocolor, planar\n");
725 vga_wseq(par->state.vgabase, 0x11, 0x10); /* basic VGA mode */
726 svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */
727 dac_set_mode(par->dac, DAC_PSEUDO8_8);
730 fb_dbg(info, "8 bit pseudocolor\n");
732 vga_wseq(par->state.vgabase, 0x11, 0x16); /* 8bpp accel mode */
734 if (info->var.pixclock > 20000) {
735 fb_dbg(info, "not using multiplex\n");
736 svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */
737 dac_set_mode(par->dac, DAC_PSEUDO8_8);
739 fb_dbg(info, "using multiplex\n");
740 svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */
741 dac_set_mode(par->dac, DAC_PSEUDO8_16);
746 fb_dbg(info, "5/5/5 truecolor\n");
748 vga_wseq(par->state.vgabase, 0x11, 0x1A); /* 16bpp accel mode */
749 svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */
750 dac_set_mode(par->dac, DAC_RGB1555_16);
753 fb_dbg(info, "5/6/5 truecolor\n");
755 vga_wseq(par->state.vgabase, 0x11, 0x1A); /* 16bpp accel mode */
756 svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */
757 dac_set_mode(par->dac, DAC_RGB0565_16);
760 fb_dbg(info, "8/8/8 truecolor\n");
762 vga_wseq(par->state.vgabase, 0x11, 0x16); /* 8bpp accel mode ??? */
763 svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */
764 dac_set_mode(par->dac, DAC_RGB0888_16);
769 fb_dbg(info, "8/8/8/8 truecolor\n");
771 vga_wseq(par->state.vgabase, 0x11, 0x1E); /* 32bpp accel mode */
772 svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */
773 dac_set_mode(par->dac, DAC_RGB8888_16);
777 fb_err(info, "unsupported mode - bug\n");
781 value = (hdiv * info->var.pixclock) / hmul;
783 fb_dbg(info, "invalid pixclock\n");
786 ark_set_pixclock(info, value);
787 svga_set_timings(par->state.vgabase, &ark_timing_regs, &(info->var), hmul, hdiv,
788 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
789 (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
792 /* Set interlaced mode start/end register */
793 value = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
794 value = ((value * hmul / hdiv) / 8) - 5;
795 vga_wcrt(par->state.vgabase, 0x42, (value + 1) / 2);
797 if (screen_size > info->screen_size)
798 screen_size = info->screen_size;
799 memset_io(info->screen_base, 0x00, screen_size);
800 /* Device and screen back on */
801 svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
802 svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
807 /* Set a colour register */
809 static int arkfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
810 u_int transp, struct fb_info *fb)
812 switch (fb->var.bits_per_pixel) {
818 if ((fb->var.bits_per_pixel == 4) &&
819 (fb->var.nonstd == 0)) {
820 outb(0xF0, VGA_PEL_MSK);
821 outb(regno*16, VGA_PEL_IW);
823 outb(0x0F, VGA_PEL_MSK);
824 outb(regno, VGA_PEL_IW);
826 outb(red >> 10, VGA_PEL_D);
827 outb(green >> 10, VGA_PEL_D);
828 outb(blue >> 10, VGA_PEL_D);
834 outb(0xFF, VGA_PEL_MSK);
835 outb(regno, VGA_PEL_IW);
836 outb(red >> 10, VGA_PEL_D);
837 outb(green >> 10, VGA_PEL_D);
838 outb(blue >> 10, VGA_PEL_D);
844 if (fb->var.green.length == 5)
845 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
846 ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
847 else if (fb->var.green.length == 6)
848 ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
849 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
858 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
859 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
868 /* Set the display blanking state */
870 static int arkfb_blank(int blank_mode, struct fb_info *info)
872 struct arkfb_info *par = info->par;
874 switch (blank_mode) {
875 case FB_BLANK_UNBLANK:
876 fb_dbg(info, "unblank\n");
877 svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
878 svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
880 case FB_BLANK_NORMAL:
881 fb_dbg(info, "blank\n");
882 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
883 svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
885 case FB_BLANK_POWERDOWN:
886 case FB_BLANK_HSYNC_SUSPEND:
887 case FB_BLANK_VSYNC_SUSPEND:
888 fb_dbg(info, "sync down\n");
889 svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
890 svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80);
897 /* Pan the display */
899 static int arkfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
901 struct arkfb_info *par = info->par;
904 /* Calculate the offset */
905 if (info->var.bits_per_pixel == 0) {
906 offset = (var->yoffset / 16) * (info->var.xres_virtual / 2)
907 + (var->xoffset / 2);
908 offset = offset >> 2;
910 offset = (var->yoffset * info->fix.line_length) +
911 (var->xoffset * info->var.bits_per_pixel / 8);
912 offset = offset >> ((info->var.bits_per_pixel == 4) ? 2 : 3);
916 svga_wcrt_multi(par->state.vgabase, ark_start_address_regs, offset);
922 /* ------------------------------------------------------------------------- */
925 /* Frame buffer operations */
927 static struct fb_ops arkfb_ops = {
928 .owner = THIS_MODULE,
929 .fb_open = arkfb_open,
930 .fb_release = arkfb_release,
931 .fb_check_var = arkfb_check_var,
932 .fb_set_par = arkfb_set_par,
933 .fb_setcolreg = arkfb_setcolreg,
934 .fb_blank = arkfb_blank,
935 .fb_pan_display = arkfb_pan_display,
936 .fb_fillrect = arkfb_fillrect,
937 .fb_copyarea = cfb_copyarea,
938 .fb_imageblit = arkfb_imageblit,
939 .fb_get_caps = svga_get_caps,
943 /* ------------------------------------------------------------------------- */
947 static int ark_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
949 struct pci_bus_region bus_reg;
950 struct resource vga_res;
951 struct fb_info *info;
952 struct arkfb_info *par;
956 /* Ignore secondary VGA device because there is no VGA arbitration */
957 if (! svga_primary_device(dev)) {
958 dev_info(&(dev->dev), "ignoring secondary device\n");
962 /* Allocate and fill driver data structure */
963 info = framebuffer_alloc(sizeof(struct arkfb_info), &(dev->dev));
965 dev_err(&(dev->dev), "cannot allocate memory\n");
970 mutex_init(&par->open_lock);
972 info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
973 info->fbops = &arkfb_ops;
975 /* Prepare PCI device */
976 rc = pci_enable_device(dev);
978 dev_err(info->device, "cannot enable PCI device\n");
979 goto err_enable_device;
982 rc = pci_request_regions(dev, "arkfb");
984 dev_err(info->device, "cannot reserve framebuffer region\n");
985 goto err_request_regions;
988 par->dac = ics5342_init(ark_dac_read_regs, ark_dac_write_regs, info);
991 dev_err(info->device, "RAMDAC initialization failed\n");
995 info->fix.smem_start = pci_resource_start(dev, 0);
996 info->fix.smem_len = pci_resource_len(dev, 0);
998 /* Map physical IO memory address into kernel space */
999 info->screen_base = pci_iomap_wc(dev, 0, 0);
1000 if (! info->screen_base) {
1002 dev_err(info->device, "iomap for framebuffer failed\n");
1007 bus_reg.end = 64 * 1024;
1009 vga_res.flags = IORESOURCE_IO;
1011 pcibios_bus_to_resource(dev->bus, &vga_res, &bus_reg);
1013 par->state.vgabase = (void __iomem *) (unsigned long) vga_res.start;
1015 /* FIXME get memsize */
1016 regval = vga_rseq(par->state.vgabase, 0x10);
1017 info->screen_size = (1 << (regval >> 6)) << 20;
1018 info->fix.smem_len = info->screen_size;
1020 strcpy(info->fix.id, "ARK 2000PV");
1021 info->fix.mmio_start = 0;
1022 info->fix.mmio_len = 0;
1023 info->fix.type = FB_TYPE_PACKED_PIXELS;
1024 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1025 info->fix.ypanstep = 0;
1026 info->fix.accel = FB_ACCEL_NONE;
1027 info->pseudo_palette = (void*) (par->pseudo_palette);
1029 /* Prepare startup mode */
1030 rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8);
1031 if (! ((rc == 1) || (rc == 2))) {
1033 dev_err(info->device, "mode %s not found\n", mode_option);
1037 rc = fb_alloc_cmap(&info->cmap, 256, 0);
1039 dev_err(info->device, "cannot allocate colormap\n");
1040 goto err_alloc_cmap;
1043 rc = register_framebuffer(info);
1045 dev_err(info->device, "cannot register framebuffer\n");
1049 fb_info(info, "%s on %s, %d MB RAM\n",
1050 info->fix.id, pci_name(dev), info->fix.smem_len >> 20);
1052 /* Record a reference to the driver data */
1053 pci_set_drvdata(dev, info);
1054 par->wc_cookie = arch_phys_wc_add(info->fix.smem_start,
1055 info->fix.smem_len);
1058 /* Error handling */
1060 fb_dealloc_cmap(&info->cmap);
1063 pci_iounmap(dev, info->screen_base);
1065 dac_release(par->dac);
1067 pci_release_regions(dev);
1068 err_request_regions:
1069 /* pci_disable_device(dev); */
1071 framebuffer_release(info);
1077 static void ark_pci_remove(struct pci_dev *dev)
1079 struct fb_info *info = pci_get_drvdata(dev);
1082 struct arkfb_info *par = info->par;
1083 arch_phys_wc_del(par->wc_cookie);
1084 dac_release(par->dac);
1085 unregister_framebuffer(info);
1086 fb_dealloc_cmap(&info->cmap);
1088 pci_iounmap(dev, info->screen_base);
1089 pci_release_regions(dev);
1090 /* pci_disable_device(dev); */
1092 framebuffer_release(info);
1100 static int ark_pci_suspend (struct pci_dev* dev, pm_message_t state)
1102 struct fb_info *info = pci_get_drvdata(dev);
1103 struct arkfb_info *par = info->par;
1105 dev_info(info->device, "suspend\n");
1108 mutex_lock(&(par->open_lock));
1110 if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
1111 mutex_unlock(&(par->open_lock));
1116 fb_set_suspend(info, 1);
1118 pci_save_state(dev);
1119 pci_disable_device(dev);
1120 pci_set_power_state(dev, pci_choose_state(dev, state));
1122 mutex_unlock(&(par->open_lock));
1131 static int ark_pci_resume (struct pci_dev* dev)
1133 struct fb_info *info = pci_get_drvdata(dev);
1134 struct arkfb_info *par = info->par;
1136 dev_info(info->device, "resume\n");
1139 mutex_lock(&(par->open_lock));
1141 if (par->ref_count == 0)
1144 pci_set_power_state(dev, PCI_D0);
1145 pci_restore_state(dev);
1147 if (pci_enable_device(dev))
1150 pci_set_master(dev);
1152 arkfb_set_par(info);
1153 fb_set_suspend(info, 0);
1156 mutex_unlock(&(par->open_lock));
1161 #define ark_pci_suspend NULL
1162 #define ark_pci_resume NULL
1163 #endif /* CONFIG_PM */
1165 /* List of boards that we are trying to support */
1167 static const struct pci_device_id ark_devices[] = {
1168 {PCI_DEVICE(0xEDD8, 0xA099)},
1169 {0, 0, 0, 0, 0, 0, 0}
1173 MODULE_DEVICE_TABLE(pci, ark_devices);
1175 static struct pci_driver arkfb_pci_driver = {
1177 .id_table = ark_devices,
1178 .probe = ark_pci_probe,
1179 .remove = ark_pci_remove,
1180 .suspend = ark_pci_suspend,
1181 .resume = ark_pci_resume,
1186 static void __exit arkfb_cleanup(void)
1188 pr_debug("arkfb: cleaning up\n");
1189 pci_unregister_driver(&arkfb_pci_driver);
1192 /* Driver Initialisation */
1194 static int __init arkfb_init(void)
1198 char *option = NULL;
1200 if (fb_get_options("arkfb", &option))
1203 if (option && *option)
1204 mode_option = option;
1207 pr_debug("arkfb: initializing\n");
1208 return pci_register_driver(&arkfb_pci_driver);
1211 module_init(arkfb_init);
1212 module_exit(arkfb_cleanup);