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/version.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/string.h>
20 #include <linux/tty.h>
21 #include <linux/slab.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 acquire_console_sem() */
28 #include <video/vga.h>
39 struct vgastate state
;
40 struct mutex open_lock
;
41 unsigned int ref_count
;
42 u32 pseudo_palette
[16];
46 /* ------------------------------------------------------------------------- */
49 static const struct svga_fb_format arkfb_formats
[] = {
50 { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
51 FB_TYPE_TEXT
, FB_AUX_TEXT_SVGA_STEP4
, FB_VISUAL_PSEUDOCOLOR
, 8, 8},
52 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
53 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_PSEUDOCOLOR
, 8, 16},
54 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1,
55 FB_TYPE_INTERLEAVED_PLANES
, 1, FB_VISUAL_PSEUDOCOLOR
, 8, 16},
56 { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
57 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_PSEUDOCOLOR
, 8, 8},
58 {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
59 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_TRUECOLOR
, 4, 4},
60 {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
61 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_TRUECOLOR
, 4, 4},
62 {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
63 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_TRUECOLOR
, 8, 8},
64 {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
65 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_TRUECOLOR
, 2, 2},
70 /* CRT timing register sets */
72 static const struct vga_regset ark_h_total_regs
[] = {{0x00, 0, 7}, {0x41, 7, 7}, VGA_REGSET_END
};
73 static const struct vga_regset ark_h_display_regs
[] = {{0x01, 0, 7}, {0x41, 6, 6}, VGA_REGSET_END
};
74 static const struct vga_regset ark_h_blank_start_regs
[] = {{0x02, 0, 7}, {0x41, 5, 5}, VGA_REGSET_END
};
75 static const struct vga_regset ark_h_blank_end_regs
[] = {{0x03, 0, 4}, {0x05, 7, 7 }, VGA_REGSET_END
};
76 static const struct vga_regset ark_h_sync_start_regs
[] = {{0x04, 0, 7}, {0x41, 4, 4}, VGA_REGSET_END
};
77 static const struct vga_regset ark_h_sync_end_regs
[] = {{0x05, 0, 4}, VGA_REGSET_END
};
79 static const struct vga_regset ark_v_total_regs
[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x40, 7, 7}, VGA_REGSET_END
};
80 static const struct vga_regset ark_v_display_regs
[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x40, 6, 6}, VGA_REGSET_END
};
81 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
};
82 // const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 6}, VGA_REGSET_END};
83 static const struct vga_regset ark_v_blank_end_regs
[] = {{0x16, 0, 7}, VGA_REGSET_END
};
84 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
};
85 static const struct vga_regset ark_v_sync_end_regs
[] = {{0x11, 0, 3}, VGA_REGSET_END
};
87 static const struct vga_regset ark_line_compare_regs
[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, VGA_REGSET_END
};
88 static const struct vga_regset ark_start_address_regs
[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x40, 0, 2}, VGA_REGSET_END
};
89 static const struct vga_regset ark_offset_regs
[] = {{0x13, 0, 7}, {0x41, 3, 3}, VGA_REGSET_END
};
91 static const struct svga_timing_regs ark_timing_regs
= {
92 ark_h_total_regs
, ark_h_display_regs
, ark_h_blank_start_regs
,
93 ark_h_blank_end_regs
, ark_h_sync_start_regs
, ark_h_sync_end_regs
,
94 ark_v_total_regs
, ark_v_display_regs
, ark_v_blank_start_regs
,
95 ark_v_blank_end_regs
, ark_v_sync_start_regs
, ark_v_sync_end_regs
,
99 /* ------------------------------------------------------------------------- */
102 /* Module parameters */
104 static char *mode_option __devinitdata
= "640x480-8@60";
110 MODULE_AUTHOR("(c) 2007 Ondrej Zajicek <santiago@crfreenet.org>");
111 MODULE_LICENSE("GPL");
112 MODULE_DESCRIPTION("fbdev driver for ARK 2000PV");
114 module_param(mode_option
, charp
, 0444);
115 MODULE_PARM_DESC(mode_option
, "Default video mode ('640x480-8@60', etc)");
116 module_param_named(mode
, mode_option
, charp
, 0444);
117 MODULE_PARM_DESC(mode
, "Default video mode ('640x480-8@60', etc) (deprecated)");
120 module_param(mtrr
, int, 0444);
121 MODULE_PARM_DESC(mtrr
, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
124 static int threshold
= 4;
126 module_param(threshold
, int, 0644);
127 MODULE_PARM_DESC(threshold
, "FIFO threshold");
130 /* ------------------------------------------------------------------------- */
133 static void arkfb_settile(struct fb_info
*info
, struct fb_tilemap
*map
)
135 const u8
*font
= map
->data
;
136 u8 __iomem
*fb
= (u8 __iomem
*)info
->screen_base
;
139 if ((map
->width
!= 8) || (map
->height
!= 16) ||
140 (map
->depth
!= 1) || (map
->length
!= 256)) {
141 printk(KERN_ERR
"fb%d: unsupported font parameters: width %d, "
142 "height %d, depth %d, length %d\n", info
->node
,
143 map
->width
, map
->height
, map
->depth
, map
->length
);
148 for (c
= 0; c
< map
->length
; c
++) {
149 for (i
= 0; i
< map
->height
; i
++) {
150 fb_writeb(font
[i
], &fb
[i
* 4]);
151 fb_writeb(font
[i
], &fb
[i
* 4 + (128 * 8)]);
162 static struct fb_tile_ops arkfb_tile_ops
= {
163 .fb_settile
= arkfb_settile
,
164 .fb_tilecopy
= svga_tilecopy
,
165 .fb_tilefill
= svga_tilefill
,
166 .fb_tileblit
= svga_tileblit
,
167 .fb_tilecursor
= svga_tilecursor
,
168 .fb_get_tilemax
= svga_get_tilemax
,
172 /* ------------------------------------------------------------------------- */
175 /* image data is MSB-first, fb structure is MSB-first too */
176 static inline u32
expand_color(u32 c
)
178 return ((c
& 1) | ((c
& 2) << 7) | ((c
& 4) << 14) | ((c
& 8) << 21)) * 0xFF;
181 /* arkfb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
182 static void arkfb_iplan_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
184 u32 fg
= expand_color(image
->fg_color
);
185 u32 bg
= expand_color(image
->bg_color
);
186 const u8
*src1
, *src
;
193 dst1
= info
->screen_base
+ (image
->dy
* info
->fix
.line_length
)
194 + ((image
->dx
/ 8) * 4);
196 for (y
= 0; y
< image
->height
; y
++) {
198 dst
= (u32 __iomem
*) dst1
;
199 for (x
= 0; x
< image
->width
; x
+= 8) {
200 val
= *(src
++) * 0x01010101;
201 val
= (val
& fg
) | (~val
& bg
);
202 fb_writel(val
, dst
++);
204 src1
+= image
->width
/ 8;
205 dst1
+= info
->fix
.line_length
;
210 /* arkfb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
211 static void arkfb_iplan_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
213 u32 fg
= expand_color(rect
->color
);
218 dst1
= info
->screen_base
+ (rect
->dy
* info
->fix
.line_length
)
219 + ((rect
->dx
/ 8) * 4);
221 for (y
= 0; y
< rect
->height
; y
++) {
222 dst
= (u32 __iomem
*) dst1
;
223 for (x
= 0; x
< rect
->width
; x
+= 8) {
224 fb_writel(fg
, dst
++);
226 dst1
+= info
->fix
.line_length
;
232 /* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
233 static inline u32
expand_pixel(u32 c
)
235 return (((c
& 1) << 24) | ((c
& 2) << 27) | ((c
& 4) << 14) | ((c
& 8) << 17) |
236 ((c
& 16) << 4) | ((c
& 32) << 7) | ((c
& 64) >> 6) | ((c
& 128) >> 3)) * 0xF;
239 /* arkfb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
240 static void arkfb_cfb4_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
242 u32 fg
= image
->fg_color
* 0x11111111;
243 u32 bg
= image
->bg_color
* 0x11111111;
244 const u8
*src1
, *src
;
251 dst1
= info
->screen_base
+ (image
->dy
* info
->fix
.line_length
)
252 + ((image
->dx
/ 8) * 4);
254 for (y
= 0; y
< image
->height
; y
++) {
256 dst
= (u32 __iomem
*) dst1
;
257 for (x
= 0; x
< image
->width
; x
+= 8) {
258 val
= expand_pixel(*(src
++));
259 val
= (val
& fg
) | (~val
& bg
);
260 fb_writel(val
, dst
++);
262 src1
+= image
->width
/ 8;
263 dst1
+= info
->fix
.line_length
;
268 static void arkfb_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
270 if ((info
->var
.bits_per_pixel
== 4) && (image
->depth
== 1)
271 && ((image
->width
% 8) == 0) && ((image
->dx
% 8) == 0)) {
272 if (info
->fix
.type
== FB_TYPE_INTERLEAVED_PLANES
)
273 arkfb_iplan_imageblit(info
, image
);
275 arkfb_cfb4_imageblit(info
, image
);
277 cfb_imageblit(info
, image
);
280 static void arkfb_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
282 if ((info
->var
.bits_per_pixel
== 4)
283 && ((rect
->width
% 8) == 0) && ((rect
->dx
% 8) == 0)
284 && (info
->fix
.type
== FB_TYPE_INTERLEAVED_PLANES
))
285 arkfb_iplan_fillrect(info
, rect
);
287 cfb_fillrect(info
, rect
);
291 /* ------------------------------------------------------------------------- */
310 int (*dac_get_mode
)(struct dac_info
*info
);
311 int (*dac_set_mode
)(struct dac_info
*info
, int mode
);
312 int (*dac_get_freq
)(struct dac_info
*info
, int channel
);
313 int (*dac_set_freq
)(struct dac_info
*info
, int channel
, u32 freq
);
314 void (*dac_release
)(struct dac_info
*info
);
317 typedef void (*dac_read_regs_t
)(void *data
, u8
*code
, int count
);
318 typedef void (*dac_write_regs_t
)(void *data
, u8
*code
, int count
);
322 struct dac_ops
*dacops
;
323 dac_read_regs_t dac_read_regs
;
324 dac_write_regs_t dac_write_regs
;
329 static inline u8
dac_read_reg(struct dac_info
*info
, u8 reg
)
331 u8 code
[2] = {reg
, 0};
332 info
->dac_read_regs(info
->data
, code
, 1);
336 static inline void dac_read_regs(struct dac_info
*info
, u8
*code
, int count
)
338 info
->dac_read_regs(info
->data
, code
, count
);
341 static inline void dac_write_reg(struct dac_info
*info
, u8 reg
, u8 val
)
343 u8 code
[2] = {reg
, val
};
344 info
->dac_write_regs(info
->data
, code
, 1);
347 static inline void dac_write_regs(struct dac_info
*info
, u8
*code
, int count
)
349 info
->dac_write_regs(info
->data
, code
, count
);
352 static inline int dac_set_mode(struct dac_info
*info
, int mode
)
354 return info
->dacops
->dac_set_mode(info
, mode
);
357 static inline int dac_set_freq(struct dac_info
*info
, int channel
, u32 freq
)
359 return info
->dacops
->dac_set_freq(info
, channel
, freq
);
362 static inline void dac_release(struct dac_info
*info
)
364 info
->dacops
->dac_release(info
);
368 /* ------------------------------------------------------------------------- */
379 #define DAC_PAR(info) ((struct ics5342_info *) info)
381 /* LSB is set to distinguish unused slots */
382 static const u8 ics5342_mode_table
[DAC_MAX
] = {
383 [DAC_PSEUDO8_8
] = 0x01, [DAC_RGB1555_8
] = 0x21, [DAC_RGB0565_8
] = 0x61,
384 [DAC_RGB0888_8
] = 0x41, [DAC_PSEUDO8_16
] = 0x11, [DAC_RGB1555_16
] = 0x31,
385 [DAC_RGB0565_16
] = 0x51, [DAC_RGB0888_16
] = 0x91, [DAC_RGB8888_16
] = 0x71
388 static int ics5342_set_mode(struct dac_info
*info
, int mode
)
395 code
= ics5342_mode_table
[mode
];
400 dac_write_reg(info
, 6, code
& 0xF0);
401 DAC_PAR(info
)->mode
= mode
;
406 static const struct svga_pll ics5342_pll
= {3, 129, 3, 33, 0, 3,
407 60000, 250000, 14318};
409 /* pd4 - allow only posdivider 4 (r=2) */
410 static const struct svga_pll ics5342_pll_pd4
= {3, 129, 3, 33, 2, 2,
411 60000, 335000, 14318};
413 /* 270 MHz should be upper bound for VCO clock according to specs,
414 but that is too restrictive in pd4 case */
416 static int ics5342_set_freq(struct dac_info
*info
, int channel
, u32 freq
)
420 /* only postdivider 4 (r=2) is valid in mode DAC_PSEUDO8_16 */
421 int rv
= svga_compute_pll((DAC_PAR(info
)->mode
== DAC_PSEUDO8_16
)
422 ? &ics5342_pll_pd4
: &ics5342_pll
,
423 freq
, &m
, &n
, &r
, 0);
428 u8 code
[6] = {4, 3, 5, m
-2, 5, (n
-2) | (r
<< 5)};
429 dac_write_regs(info
, code
, 3);
434 static void ics5342_release(struct dac_info
*info
)
436 ics5342_set_mode(info
, DAC_PSEUDO8_8
);
440 static struct dac_ops ics5342_ops
= {
441 .dac_set_mode
= ics5342_set_mode
,
442 .dac_set_freq
= ics5342_set_freq
,
443 .dac_release
= ics5342_release
447 static struct dac_info
* ics5342_init(dac_read_regs_t drr
, dac_write_regs_t dwr
, void *data
)
449 struct dac_info
*info
= kzalloc(sizeof(struct ics5342_info
), GFP_KERNEL
);
454 info
->dacops
= &ics5342_ops
;
455 info
->dac_read_regs
= drr
;
456 info
->dac_write_regs
= dwr
;
458 DAC_PAR(info
)->mode
= DAC_PSEUDO8_8
; /* estimation */
463 /* ------------------------------------------------------------------------- */
466 static unsigned short dac_regs
[4] = {0x3c8, 0x3c9, 0x3c6, 0x3c7};
468 static void ark_dac_read_regs(void *data
, u8
*code
, int count
)
470 u8 regval
= vga_rseq(NULL
, 0x1C);
474 vga_wseq(NULL
, 0x1C, regval
| (code
[0] & 4) ? 0x80 : 0);
475 code
[1] = vga_r(NULL
, dac_regs
[code
[0] & 3]);
480 vga_wseq(NULL
, 0x1C, regval
);
483 static void ark_dac_write_regs(void *data
, u8
*code
, int count
)
485 u8 regval
= vga_rseq(NULL
, 0x1C);
489 vga_wseq(NULL
, 0x1C, regval
| (code
[0] & 4) ? 0x80 : 0);
490 vga_w(NULL
, dac_regs
[code
[0] & 3], code
[1]);
495 vga_wseq(NULL
, 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 printk(KERN_ERR
"fb%d: cannot set requested pixclock, keeping old value\n", info
->node
);
510 /* Set VGA misc register */
511 regval
= vga_r(NULL
, VGA_MIS_R
);
512 vga_w(NULL
, 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 memset(&(par
->state
), 0, sizeof(struct vgastate
));
525 par
->state
.flags
= VGA_SAVE_MODE
| VGA_SAVE_FONTS
| VGA_SAVE_CMAP
;
526 par
->state
.num_crtc
= 0x60;
527 par
->state
.num_seq
= 0x30;
528 save_vga(&(par
->state
));
532 mutex_unlock(&(par
->open_lock
));
537 /* Close framebuffer */
539 static int arkfb_release(struct fb_info
*info
, int user
)
541 struct arkfb_info
*par
= info
->par
;
543 mutex_lock(&(par
->open_lock
));
544 if (par
->ref_count
== 0) {
545 mutex_unlock(&(par
->open_lock
));
549 if (par
->ref_count
== 1) {
550 restore_vga(&(par
->state
));
551 dac_set_mode(par
->dac
, DAC_PSEUDO8_8
);
555 mutex_unlock(&(par
->open_lock
));
560 /* Validate passed in var */
562 static int arkfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
566 /* Find appropriate format */
567 rv
= svga_match_format (arkfb_formats
, var
, NULL
);
570 printk(KERN_ERR
"fb%d: unsupported mode requested\n", info
->node
);
574 /* Do not allow to have real resoulution larger than virtual */
575 if (var
->xres
> var
->xres_virtual
)
576 var
->xres_virtual
= var
->xres
;
578 if (var
->yres
> var
->yres_virtual
)
579 var
->yres_virtual
= var
->yres
;
581 /* Round up xres_virtual to have proper alignment of lines */
582 step
= arkfb_formats
[rv
].xresstep
- 1;
583 var
->xres_virtual
= (var
->xres_virtual
+step
) & ~step
;
586 /* Check whether have enough memory */
587 mem
= ((var
->bits_per_pixel
* var
->xres_virtual
) >> 3) * var
->yres_virtual
;
588 if (mem
> info
->screen_size
)
590 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));
594 rv
= svga_check_timings (&ark_timing_regs
, var
, info
->node
);
597 printk(KERN_ERR
"fb%d: invalid timings requested\n", info
->node
);
601 /* Interlaced mode is broken */
602 if (var
->vmode
& FB_VMODE_INTERLACED
)
608 /* Set video mode from par */
610 static int arkfb_set_par(struct fb_info
*info
)
612 struct arkfb_info
*par
= info
->par
;
613 u32 value
, mode
, hmul
, hdiv
, offset_value
, screen_size
;
614 u32 bpp
= info
->var
.bits_per_pixel
;
618 info
->fix
.ypanstep
= 1;
619 info
->fix
.line_length
= (info
->var
.xres_virtual
* bpp
) / 8;
621 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
622 info
->tileops
= NULL
;
624 /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
625 info
->pixmap
.blit_x
= (bpp
== 4) ? (1 << (8 - 1)) : (~(u32
)0);
626 info
->pixmap
.blit_y
= ~(u32
)0;
628 offset_value
= (info
->var
.xres_virtual
* bpp
) / 64;
629 screen_size
= info
->var
.yres_virtual
* info
->fix
.line_length
;
631 info
->fix
.ypanstep
= 16;
632 info
->fix
.line_length
= 0;
634 info
->flags
|= FBINFO_MISC_TILEBLITTING
;
635 info
->tileops
= &arkfb_tile_ops
;
637 /* supports 8x16 tiles only */
638 info
->pixmap
.blit_x
= 1 << (8 - 1);
639 info
->pixmap
.blit_y
= 1 << (16 - 1);
641 offset_value
= info
->var
.xres_virtual
/ 16;
642 screen_size
= (info
->var
.xres_virtual
* info
->var
.yres_virtual
) / 64;
645 info
->var
.xoffset
= 0;
646 info
->var
.yoffset
= 0;
647 info
->var
.activate
= FB_ACTIVATE_NOW
;
649 /* Unlock registers */
650 svga_wcrt_mask(0x11, 0x00, 0x80);
652 /* Blank screen and turn off sync */
653 svga_wseq_mask(0x01, 0x20, 0x20);
654 svga_wcrt_mask(0x17, 0x00, 0x80);
656 /* Set default values */
657 svga_set_default_gfx_regs();
658 svga_set_default_atc_regs();
659 svga_set_default_seq_regs();
660 svga_set_default_crt_regs();
661 svga_wcrt_multi(ark_line_compare_regs
, 0xFFFFFFFF);
662 svga_wcrt_multi(ark_start_address_regs
, 0);
664 /* ARK specific initialization */
665 svga_wseq_mask(0x10, 0x1F, 0x1F); /* enable linear framebuffer and full memory access */
666 svga_wseq_mask(0x12, 0x03, 0x03); /* 4 MB linear framebuffer size */
668 vga_wseq(NULL
, 0x13, info
->fix
.smem_start
>> 16);
669 vga_wseq(NULL
, 0x14, info
->fix
.smem_start
>> 24);
670 vga_wseq(NULL
, 0x15, 0);
671 vga_wseq(NULL
, 0x16, 0);
673 /* Set the FIFO threshold register */
674 /* It is fascinating way to store 5-bit value in 8-bit register */
675 regval
= 0x10 | ((threshold
& 0x0E) >> 1) | (threshold
& 0x01) << 7 | (threshold
& 0x10) << 1;
676 vga_wseq(NULL
, 0x18, regval
);
678 /* Set the offset register */
679 pr_debug("fb%d: offset register : %d\n", info
->node
, offset_value
);
680 svga_wcrt_multi(ark_offset_regs
, offset_value
);
682 /* fix for hi-res textmode */
683 svga_wcrt_mask(0x40, 0x08, 0x08);
685 if (info
->var
.vmode
& FB_VMODE_DOUBLE
)
686 svga_wcrt_mask(0x09, 0x80, 0x80);
688 svga_wcrt_mask(0x09, 0x00, 0x80);
690 if (info
->var
.vmode
& FB_VMODE_INTERLACED
)
691 svga_wcrt_mask(0x44, 0x04, 0x04);
693 svga_wcrt_mask(0x44, 0x00, 0x04);
697 mode
= svga_match_format(arkfb_formats
, &(info
->var
), &(info
->fix
));
699 /* Set mode-specific register values */
702 pr_debug("fb%d: text mode\n", info
->node
);
703 svga_set_textmode_vga_regs();
705 vga_wseq(NULL
, 0x11, 0x10); /* basic VGA mode */
706 svga_wcrt_mask(0x46, 0x00, 0x04); /* 8bit pixel path */
707 dac_set_mode(par
->dac
, DAC_PSEUDO8_8
);
711 pr_debug("fb%d: 4 bit pseudocolor\n", info
->node
);
712 vga_wgfx(NULL
, VGA_GFX_MODE
, 0x40);
714 vga_wseq(NULL
, 0x11, 0x10); /* basic VGA mode */
715 svga_wcrt_mask(0x46, 0x00, 0x04); /* 8bit pixel path */
716 dac_set_mode(par
->dac
, DAC_PSEUDO8_8
);
719 pr_debug("fb%d: 4 bit pseudocolor, planar\n", info
->node
);
721 vga_wseq(NULL
, 0x11, 0x10); /* basic VGA mode */
722 svga_wcrt_mask(0x46, 0x00, 0x04); /* 8bit pixel path */
723 dac_set_mode(par
->dac
, DAC_PSEUDO8_8
);
726 pr_debug("fb%d: 8 bit pseudocolor\n", info
->node
);
728 vga_wseq(NULL
, 0x11, 0x16); /* 8bpp accel mode */
730 if (info
->var
.pixclock
> 20000) {
731 pr_debug("fb%d: not using multiplex\n", info
->node
);
732 svga_wcrt_mask(0x46, 0x00, 0x04); /* 8bit pixel path */
733 dac_set_mode(par
->dac
, DAC_PSEUDO8_8
);
735 pr_debug("fb%d: using multiplex\n", info
->node
);
736 svga_wcrt_mask(0x46, 0x04, 0x04); /* 16bit pixel path */
737 dac_set_mode(par
->dac
, DAC_PSEUDO8_16
);
742 pr_debug("fb%d: 5/5/5 truecolor\n", info
->node
);
744 vga_wseq(NULL
, 0x11, 0x1A); /* 16bpp accel mode */
745 svga_wcrt_mask(0x46, 0x04, 0x04); /* 16bit pixel path */
746 dac_set_mode(par
->dac
, DAC_RGB1555_16
);
749 pr_debug("fb%d: 5/6/5 truecolor\n", info
->node
);
751 vga_wseq(NULL
, 0x11, 0x1A); /* 16bpp accel mode */
752 svga_wcrt_mask(0x46, 0x04, 0x04); /* 16bit pixel path */
753 dac_set_mode(par
->dac
, DAC_RGB0565_16
);
756 pr_debug("fb%d: 8/8/8 truecolor\n", info
->node
);
758 vga_wseq(NULL
, 0x11, 0x16); /* 8bpp accel mode ??? */
759 svga_wcrt_mask(0x46, 0x04, 0x04); /* 16bit pixel path */
760 dac_set_mode(par
->dac
, DAC_RGB0888_16
);
765 pr_debug("fb%d: 8/8/8/8 truecolor\n", info
->node
);
767 vga_wseq(NULL
, 0x11, 0x1E); /* 32bpp accel mode */
768 svga_wcrt_mask(0x46, 0x04, 0x04); /* 16bit pixel path */
769 dac_set_mode(par
->dac
, DAC_RGB8888_16
);
773 printk(KERN_ERR
"fb%d: unsupported mode - bug\n", info
->node
);
777 ark_set_pixclock(info
, (hdiv
* info
->var
.pixclock
) / hmul
);
778 svga_set_timings(&ark_timing_regs
, &(info
->var
), hmul
, hdiv
,
779 (info
->var
.vmode
& FB_VMODE_DOUBLE
) ? 2 : 1,
780 (info
->var
.vmode
& FB_VMODE_INTERLACED
) ? 2 : 1,
783 /* Set interlaced mode start/end register */
784 value
= info
->var
.xres
+ info
->var
.left_margin
+ info
->var
.right_margin
+ info
->var
.hsync_len
;
785 value
= ((value
* hmul
/ hdiv
) / 8) - 5;
786 vga_wcrt(NULL
, 0x42, (value
+ 1) / 2);
788 memset_io(info
->screen_base
, 0x00, screen_size
);
789 /* Device and screen back on */
790 svga_wcrt_mask(0x17, 0x80, 0x80);
791 svga_wseq_mask(0x01, 0x00, 0x20);
796 /* Set a colour register */
798 static int arkfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
799 u_int transp
, struct fb_info
*fb
)
801 switch (fb
->var
.bits_per_pixel
) {
807 if ((fb
->var
.bits_per_pixel
== 4) &&
808 (fb
->var
.nonstd
== 0)) {
809 outb(0xF0, VGA_PEL_MSK
);
810 outb(regno
*16, VGA_PEL_IW
);
812 outb(0x0F, VGA_PEL_MSK
);
813 outb(regno
, VGA_PEL_IW
);
815 outb(red
>> 10, VGA_PEL_D
);
816 outb(green
>> 10, VGA_PEL_D
);
817 outb(blue
>> 10, VGA_PEL_D
);
823 outb(0xFF, VGA_PEL_MSK
);
824 outb(regno
, VGA_PEL_IW
);
825 outb(red
>> 10, VGA_PEL_D
);
826 outb(green
>> 10, VGA_PEL_D
);
827 outb(blue
>> 10, VGA_PEL_D
);
833 if (fb
->var
.green
.length
== 5)
834 ((u32
*)fb
->pseudo_palette
)[regno
] = ((red
& 0xF800) >> 1) |
835 ((green
& 0xF800) >> 6) | ((blue
& 0xF800) >> 11);
836 else if (fb
->var
.green
.length
== 6)
837 ((u32
*)fb
->pseudo_palette
)[regno
] = (red
& 0xF800) |
838 ((green
& 0xFC00) >> 5) | ((blue
& 0xF800) >> 11);
847 ((u32
*)fb
->pseudo_palette
)[regno
] = ((red
& 0xFF00) << 8) |
848 (green
& 0xFF00) | ((blue
& 0xFF00) >> 8);
857 /* Set the display blanking state */
859 static int arkfb_blank(int blank_mode
, struct fb_info
*info
)
861 switch (blank_mode
) {
862 case FB_BLANK_UNBLANK
:
863 pr_debug("fb%d: unblank\n", info
->node
);
864 svga_wseq_mask(0x01, 0x00, 0x20);
865 svga_wcrt_mask(0x17, 0x80, 0x80);
867 case FB_BLANK_NORMAL
:
868 pr_debug("fb%d: blank\n", info
->node
);
869 svga_wseq_mask(0x01, 0x20, 0x20);
870 svga_wcrt_mask(0x17, 0x80, 0x80);
872 case FB_BLANK_POWERDOWN
:
873 case FB_BLANK_HSYNC_SUSPEND
:
874 case FB_BLANK_VSYNC_SUSPEND
:
875 pr_debug("fb%d: sync down\n", info
->node
);
876 svga_wseq_mask(0x01, 0x20, 0x20);
877 svga_wcrt_mask(0x17, 0x00, 0x80);
884 /* Pan the display */
886 static int arkfb_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
890 /* Calculate the offset */
891 if (var
->bits_per_pixel
== 0) {
892 offset
= (var
->yoffset
/ 16) * (var
->xres_virtual
/ 2) + (var
->xoffset
/ 2);
893 offset
= offset
>> 2;
895 offset
= (var
->yoffset
* info
->fix
.line_length
) +
896 (var
->xoffset
* var
->bits_per_pixel
/ 8);
897 offset
= offset
>> ((var
->bits_per_pixel
== 4) ? 2 : 3);
901 svga_wcrt_multi(ark_start_address_regs
, offset
);
907 /* ------------------------------------------------------------------------- */
910 /* Frame buffer operations */
912 static struct fb_ops arkfb_ops
= {
913 .owner
= THIS_MODULE
,
914 .fb_open
= arkfb_open
,
915 .fb_release
= arkfb_release
,
916 .fb_check_var
= arkfb_check_var
,
917 .fb_set_par
= arkfb_set_par
,
918 .fb_setcolreg
= arkfb_setcolreg
,
919 .fb_blank
= arkfb_blank
,
920 .fb_pan_display
= arkfb_pan_display
,
921 .fb_fillrect
= arkfb_fillrect
,
922 .fb_copyarea
= cfb_copyarea
,
923 .fb_imageblit
= arkfb_imageblit
,
924 .fb_get_caps
= svga_get_caps
,
928 /* ------------------------------------------------------------------------- */
932 static int __devinit
ark_pci_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
934 struct fb_info
*info
;
935 struct arkfb_info
*par
;
939 /* Ignore secondary VGA device because there is no VGA arbitration */
940 if (! svga_primary_device(dev
)) {
941 dev_info(&(dev
->dev
), "ignoring secondary device\n");
945 /* Allocate and fill driver data structure */
946 info
= framebuffer_alloc(sizeof(struct arkfb_info
), &(dev
->dev
));
948 dev_err(&(dev
->dev
), "cannot allocate memory\n");
953 mutex_init(&par
->open_lock
);
955 info
->flags
= FBINFO_PARTIAL_PAN_OK
| FBINFO_HWACCEL_YPAN
;
956 info
->fbops
= &arkfb_ops
;
958 /* Prepare PCI device */
959 rc
= pci_enable_device(dev
);
961 dev_err(info
->dev
, "cannot enable PCI device\n");
962 goto err_enable_device
;
965 rc
= pci_request_regions(dev
, "arkfb");
967 dev_err(info
->dev
, "cannot reserve framebuffer region\n");
968 goto err_request_regions
;
971 par
->dac
= ics5342_init(ark_dac_read_regs
, ark_dac_write_regs
, info
);
974 dev_err(info
->dev
, "RAMDAC initialization failed\n");
978 info
->fix
.smem_start
= pci_resource_start(dev
, 0);
979 info
->fix
.smem_len
= pci_resource_len(dev
, 0);
981 /* Map physical IO memory address into kernel space */
982 info
->screen_base
= pci_iomap(dev
, 0, 0);
983 if (! info
->screen_base
) {
985 dev_err(info
->dev
, "iomap for framebuffer failed\n");
989 /* FIXME get memsize */
990 regval
= vga_rseq(NULL
, 0x10);
991 info
->screen_size
= (1 << (regval
>> 6)) << 20;
992 info
->fix
.smem_len
= info
->screen_size
;
994 strcpy(info
->fix
.id
, "ARK 2000PV");
995 info
->fix
.mmio_start
= 0;
996 info
->fix
.mmio_len
= 0;
997 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
998 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
999 info
->fix
.ypanstep
= 0;
1000 info
->fix
.accel
= FB_ACCEL_NONE
;
1001 info
->pseudo_palette
= (void*) (par
->pseudo_palette
);
1003 /* Prepare startup mode */
1004 rc
= fb_find_mode(&(info
->var
), info
, mode_option
, NULL
, 0, NULL
, 8);
1005 if (! ((rc
== 1) || (rc
== 2))) {
1007 dev_err(info
->dev
, "mode %s not found\n", mode_option
);
1011 rc
= fb_alloc_cmap(&info
->cmap
, 256, 0);
1013 dev_err(info
->dev
, "cannot allocate colormap\n");
1014 goto err_alloc_cmap
;
1017 rc
= register_framebuffer(info
);
1019 dev_err(info
->dev
, "cannot register framebugger\n");
1023 printk(KERN_INFO
"fb%d: %s on %s, %d MB RAM\n", info
->node
, info
->fix
.id
,
1024 pci_name(dev
), info
->fix
.smem_len
>> 20);
1026 /* Record a reference to the driver data */
1027 pci_set_drvdata(dev
, info
);
1032 par
->mtrr_reg
= mtrr_add(info
->fix
.smem_start
, info
->fix
.smem_len
, MTRR_TYPE_WRCOMB
, 1);
1038 /* Error handling */
1040 fb_dealloc_cmap(&info
->cmap
);
1043 pci_iounmap(dev
, info
->screen_base
);
1045 dac_release(par
->dac
);
1047 pci_release_regions(dev
);
1048 err_request_regions
:
1049 /* pci_disable_device(dev); */
1051 framebuffer_release(info
);
1057 static void __devexit
ark_pci_remove(struct pci_dev
*dev
)
1059 struct fb_info
*info
= pci_get_drvdata(dev
);
1062 struct arkfb_info
*par
= info
->par
;
1065 if (par
->mtrr_reg
>= 0) {
1066 mtrr_del(par
->mtrr_reg
, 0, 0);
1071 dac_release(par
->dac
);
1072 unregister_framebuffer(info
);
1073 fb_dealloc_cmap(&info
->cmap
);
1075 pci_iounmap(dev
, info
->screen_base
);
1076 pci_release_regions(dev
);
1077 /* pci_disable_device(dev); */
1079 pci_set_drvdata(dev
, NULL
);
1080 framebuffer_release(info
);
1088 static int ark_pci_suspend (struct pci_dev
* dev
, pm_message_t state
)
1090 struct fb_info
*info
= pci_get_drvdata(dev
);
1091 struct arkfb_info
*par
= info
->par
;
1093 dev_info(info
->dev
, "suspend\n");
1095 acquire_console_sem();
1096 mutex_lock(&(par
->open_lock
));
1098 if ((state
.event
== PM_EVENT_FREEZE
) || (par
->ref_count
== 0)) {
1099 mutex_unlock(&(par
->open_lock
));
1100 release_console_sem();
1104 fb_set_suspend(info
, 1);
1106 pci_save_state(dev
);
1107 pci_disable_device(dev
);
1108 pci_set_power_state(dev
, pci_choose_state(dev
, state
));
1110 mutex_unlock(&(par
->open_lock
));
1111 release_console_sem();
1119 static int ark_pci_resume (struct pci_dev
* dev
)
1121 struct fb_info
*info
= pci_get_drvdata(dev
);
1122 struct arkfb_info
*par
= info
->par
;
1124 dev_info(info
->dev
, "resume\n");
1126 acquire_console_sem();
1127 mutex_lock(&(par
->open_lock
));
1129 if (par
->ref_count
== 0) {
1130 mutex_unlock(&(par
->open_lock
));
1131 release_console_sem();
1135 pci_set_power_state(dev
, PCI_D0
);
1136 pci_restore_state(dev
);
1138 if (pci_enable_device(dev
))
1141 pci_set_master(dev
);
1143 arkfb_set_par(info
);
1144 fb_set_suspend(info
, 0);
1146 mutex_unlock(&(par
->open_lock
));
1148 release_console_sem();
1152 #define ark_pci_suspend NULL
1153 #define ark_pci_resume NULL
1154 #endif /* CONFIG_PM */
1156 /* List of boards that we are trying to support */
1158 static struct pci_device_id ark_devices
[] __devinitdata
= {
1159 {PCI_DEVICE(0xEDD8, 0xA099)},
1160 {0, 0, 0, 0, 0, 0, 0}
1164 MODULE_DEVICE_TABLE(pci
, ark_devices
);
1166 static struct pci_driver arkfb_pci_driver
= {
1168 .id_table
= ark_devices
,
1169 .probe
= ark_pci_probe
,
1170 .remove
= __devexit_p(ark_pci_remove
),
1171 .suspend
= ark_pci_suspend
,
1172 .resume
= ark_pci_resume
,
1177 static void __exit
arkfb_cleanup(void)
1179 pr_debug("arkfb: cleaning up\n");
1180 pci_unregister_driver(&arkfb_pci_driver
);
1183 /* Driver Initialisation */
1185 static int __init
arkfb_init(void)
1189 char *option
= NULL
;
1191 if (fb_get_options("arkfb", &option
))
1194 if (option
&& *option
)
1195 mode_option
= option
;
1198 pr_debug("arkfb: initializing\n");
1199 return pci_register_driver(&arkfb_pci_driver
);
1202 module_init(arkfb_init
);
1203 module_exit(arkfb_cleanup
);