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/aperture.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 console_lock() */
28 #include <video/vga.h>
35 struct vgastate state
;
36 struct mutex open_lock
;
37 unsigned int ref_count
;
38 u32 pseudo_palette
[16];
42 /* ------------------------------------------------------------------------- */
45 static const struct svga_fb_format arkfb_formats
[] = {
46 { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
47 FB_TYPE_TEXT
, FB_AUX_TEXT_SVGA_STEP4
, FB_VISUAL_PSEUDOCOLOR
, 8, 8},
48 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
49 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_PSEUDOCOLOR
, 8, 16},
50 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1,
51 FB_TYPE_INTERLEAVED_PLANES
, 1, FB_VISUAL_PSEUDOCOLOR
, 8, 16},
52 { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
53 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_PSEUDOCOLOR
, 8, 8},
54 {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
55 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_TRUECOLOR
, 4, 4},
56 {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
57 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_TRUECOLOR
, 4, 4},
58 {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
59 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_TRUECOLOR
, 8, 8},
60 {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
61 FB_TYPE_PACKED_PIXELS
, 0, FB_VISUAL_TRUECOLOR
, 2, 2},
66 /* CRT timing register sets */
68 static const struct vga_regset ark_h_total_regs
[] = {{0x00, 0, 7}, {0x41, 7, 7}, VGA_REGSET_END
};
69 static const struct vga_regset ark_h_display_regs
[] = {{0x01, 0, 7}, {0x41, 6, 6}, VGA_REGSET_END
};
70 static const struct vga_regset ark_h_blank_start_regs
[] = {{0x02, 0, 7}, {0x41, 5, 5}, VGA_REGSET_END
};
71 static const struct vga_regset ark_h_blank_end_regs
[] = {{0x03, 0, 4}, {0x05, 7, 7 }, VGA_REGSET_END
};
72 static const struct vga_regset ark_h_sync_start_regs
[] = {{0x04, 0, 7}, {0x41, 4, 4}, VGA_REGSET_END
};
73 static const struct vga_regset ark_h_sync_end_regs
[] = {{0x05, 0, 4}, VGA_REGSET_END
};
75 static const struct vga_regset ark_v_total_regs
[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x40, 7, 7}, VGA_REGSET_END
};
76 static const struct vga_regset ark_v_display_regs
[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x40, 6, 6}, VGA_REGSET_END
};
77 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
};
78 // const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 6}, VGA_REGSET_END};
79 static const struct vga_regset ark_v_blank_end_regs
[] = {{0x16, 0, 7}, VGA_REGSET_END
};
80 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
};
81 static const struct vga_regset ark_v_sync_end_regs
[] = {{0x11, 0, 3}, VGA_REGSET_END
};
83 static const struct vga_regset ark_line_compare_regs
[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, VGA_REGSET_END
};
84 static const struct vga_regset ark_start_address_regs
[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x40, 0, 2}, VGA_REGSET_END
};
85 static const struct vga_regset ark_offset_regs
[] = {{0x13, 0, 7}, {0x41, 3, 3}, VGA_REGSET_END
};
87 static const struct svga_timing_regs ark_timing_regs
= {
88 ark_h_total_regs
, ark_h_display_regs
, ark_h_blank_start_regs
,
89 ark_h_blank_end_regs
, ark_h_sync_start_regs
, ark_h_sync_end_regs
,
90 ark_v_total_regs
, ark_v_display_regs
, ark_v_blank_start_regs
,
91 ark_v_blank_end_regs
, ark_v_sync_start_regs
, ark_v_sync_end_regs
,
95 /* ------------------------------------------------------------------------- */
98 /* Module parameters */
100 static char *mode_option
= "640x480-8@60";
102 MODULE_AUTHOR("(c) 2007 Ondrej Zajicek <santiago@crfreenet.org>");
103 MODULE_LICENSE("GPL");
104 MODULE_DESCRIPTION("fbdev driver for ARK 2000PV");
106 module_param(mode_option
, charp
, 0444);
107 MODULE_PARM_DESC(mode_option
, "Default video mode ('640x480-8@60', etc)");
108 module_param_named(mode
, mode_option
, charp
, 0444);
109 MODULE_PARM_DESC(mode
, "Default video mode ('640x480-8@60', etc) (deprecated)");
111 static int threshold
= 4;
113 module_param(threshold
, int, 0644);
114 MODULE_PARM_DESC(threshold
, "FIFO threshold");
117 /* ------------------------------------------------------------------------- */
120 static void arkfb_settile(struct fb_info
*info
, struct fb_tilemap
*map
)
122 const u8
*font
= map
->data
;
123 u8 __iomem
*fb
= (u8 __iomem
*)info
->screen_base
;
126 if ((map
->width
!= 8) || (map
->height
!= 16) ||
127 (map
->depth
!= 1) || (map
->length
!= 256)) {
128 fb_err(info
, "unsupported font parameters: width %d, height %d, depth %d, length %d\n",
129 map
->width
, map
->height
, map
->depth
, map
->length
);
134 for (c
= 0; c
< map
->length
; c
++) {
135 for (i
= 0; i
< map
->height
; i
++) {
136 fb_writeb(font
[i
], &fb
[i
* 4]);
137 fb_writeb(font
[i
], &fb
[i
* 4 + (128 * 8)]);
148 static void arkfb_tilecursor(struct fb_info
*info
, struct fb_tilecursor
*cursor
)
150 struct arkfb_info
*par
= info
->par
;
152 svga_tilecursor(par
->state
.vgabase
, info
, cursor
);
155 static struct fb_tile_ops arkfb_tile_ops
= {
156 .fb_settile
= arkfb_settile
,
157 .fb_tilecopy
= svga_tilecopy
,
158 .fb_tilefill
= svga_tilefill
,
159 .fb_tileblit
= svga_tileblit
,
160 .fb_tilecursor
= arkfb_tilecursor
,
161 .fb_get_tilemax
= svga_get_tilemax
,
165 /* ------------------------------------------------------------------------- */
168 /* image data is MSB-first, fb structure is MSB-first too */
169 static inline u32
expand_color(u32 c
)
171 return ((c
& 1) | ((c
& 2) << 7) | ((c
& 4) << 14) | ((c
& 8) << 21)) * 0xFF;
174 /* arkfb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
175 static void arkfb_iplan_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
177 u32 fg
= expand_color(image
->fg_color
);
178 u32 bg
= expand_color(image
->bg_color
);
179 const u8
*src1
, *src
;
186 dst1
= info
->screen_base
+ (image
->dy
* info
->fix
.line_length
)
187 + ((image
->dx
/ 8) * 4);
189 for (y
= 0; y
< image
->height
; y
++) {
191 dst
= (u32 __iomem
*) dst1
;
192 for (x
= 0; x
< image
->width
; x
+= 8) {
193 val
= *(src
++) * 0x01010101;
194 val
= (val
& fg
) | (~val
& bg
);
195 fb_writel(val
, dst
++);
197 src1
+= image
->width
/ 8;
198 dst1
+= info
->fix
.line_length
;
203 /* arkfb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
204 static void arkfb_iplan_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
206 u32 fg
= expand_color(rect
->color
);
211 dst1
= info
->screen_base
+ (rect
->dy
* info
->fix
.line_length
)
212 + ((rect
->dx
/ 8) * 4);
214 for (y
= 0; y
< rect
->height
; y
++) {
215 dst
= (u32 __iomem
*) dst1
;
216 for (x
= 0; x
< rect
->width
; x
+= 8) {
217 fb_writel(fg
, dst
++);
219 dst1
+= info
->fix
.line_length
;
225 /* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
226 static inline u32
expand_pixel(u32 c
)
228 return (((c
& 1) << 24) | ((c
& 2) << 27) | ((c
& 4) << 14) | ((c
& 8) << 17) |
229 ((c
& 16) << 4) | ((c
& 32) << 7) | ((c
& 64) >> 6) | ((c
& 128) >> 3)) * 0xF;
232 /* arkfb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
233 static void arkfb_cfb4_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
235 u32 fg
= image
->fg_color
* 0x11111111;
236 u32 bg
= image
->bg_color
* 0x11111111;
237 const u8
*src1
, *src
;
244 dst1
= info
->screen_base
+ (image
->dy
* info
->fix
.line_length
)
245 + ((image
->dx
/ 8) * 4);
247 for (y
= 0; y
< image
->height
; y
++) {
249 dst
= (u32 __iomem
*) dst1
;
250 for (x
= 0; x
< image
->width
; x
+= 8) {
251 val
= expand_pixel(*(src
++));
252 val
= (val
& fg
) | (~val
& bg
);
253 fb_writel(val
, dst
++);
255 src1
+= image
->width
/ 8;
256 dst1
+= info
->fix
.line_length
;
261 static void arkfb_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
263 if ((info
->var
.bits_per_pixel
== 4) && (image
->depth
== 1)
264 && ((image
->width
% 8) == 0) && ((image
->dx
% 8) == 0)) {
265 if (info
->fix
.type
== FB_TYPE_INTERLEAVED_PLANES
)
266 arkfb_iplan_imageblit(info
, image
);
268 arkfb_cfb4_imageblit(info
, image
);
270 cfb_imageblit(info
, image
);
273 static void arkfb_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
275 if ((info
->var
.bits_per_pixel
== 4)
276 && ((rect
->width
% 8) == 0) && ((rect
->dx
% 8) == 0)
277 && (info
->fix
.type
== FB_TYPE_INTERLEAVED_PLANES
))
278 arkfb_iplan_fillrect(info
, rect
);
280 cfb_fillrect(info
, rect
);
284 /* ------------------------------------------------------------------------- */
303 int (*dac_get_mode
)(struct dac_info
*info
);
304 int (*dac_set_mode
)(struct dac_info
*info
, int mode
);
305 int (*dac_get_freq
)(struct dac_info
*info
, int channel
);
306 int (*dac_set_freq
)(struct dac_info
*info
, int channel
, u32 freq
);
307 void (*dac_release
)(struct dac_info
*info
);
310 typedef void (*dac_read_regs_t
)(void *data
, u8
*code
, int count
);
311 typedef void (*dac_write_regs_t
)(void *data
, u8
*code
, int count
);
315 struct dac_ops
*dacops
;
316 dac_read_regs_t dac_read_regs
;
317 dac_write_regs_t dac_write_regs
;
321 static inline void dac_read_regs(struct dac_info
*info
, u8
*code
, int count
)
323 info
->dac_read_regs(info
->data
, code
, count
);
326 static inline void dac_write_reg(struct dac_info
*info
, u8 reg
, u8 val
)
328 u8 code
[2] = {reg
, val
};
329 info
->dac_write_regs(info
->data
, code
, 1);
332 static inline void dac_write_regs(struct dac_info
*info
, u8
*code
, int count
)
334 info
->dac_write_regs(info
->data
, code
, count
);
337 static inline int dac_set_mode(struct dac_info
*info
, int mode
)
339 return info
->dacops
->dac_set_mode(info
, mode
);
342 static inline int dac_set_freq(struct dac_info
*info
, int channel
, u32 freq
)
344 return info
->dacops
->dac_set_freq(info
, channel
, freq
);
347 static inline void dac_release(struct dac_info
*info
)
349 info
->dacops
->dac_release(info
);
353 /* ------------------------------------------------------------------------- */
364 #define DAC_PAR(info) ((struct ics5342_info *) info)
366 /* LSB is set to distinguish unused slots */
367 static const u8 ics5342_mode_table
[DAC_MAX
] = {
368 [DAC_PSEUDO8_8
] = 0x01, [DAC_RGB1555_8
] = 0x21, [DAC_RGB0565_8
] = 0x61,
369 [DAC_RGB0888_8
] = 0x41, [DAC_PSEUDO8_16
] = 0x11, [DAC_RGB1555_16
] = 0x31,
370 [DAC_RGB0565_16
] = 0x51, [DAC_RGB0888_16
] = 0x91, [DAC_RGB8888_16
] = 0x71
373 static int ics5342_set_mode(struct dac_info
*info
, int mode
)
380 code
= ics5342_mode_table
[mode
];
385 dac_write_reg(info
, 6, code
& 0xF0);
386 DAC_PAR(info
)->mode
= mode
;
391 static const struct svga_pll ics5342_pll
= {3, 129, 3, 33, 0, 3,
392 60000, 250000, 14318};
394 /* pd4 - allow only posdivider 4 (r=2) */
395 static const struct svga_pll ics5342_pll_pd4
= {3, 129, 3, 33, 2, 2,
396 60000, 335000, 14318};
398 /* 270 MHz should be upper bound for VCO clock according to specs,
399 but that is too restrictive in pd4 case */
401 static int ics5342_set_freq(struct dac_info
*info
, int channel
, u32 freq
)
405 /* only postdivider 4 (r=2) is valid in mode DAC_PSEUDO8_16 */
406 int rv
= svga_compute_pll((DAC_PAR(info
)->mode
== DAC_PSEUDO8_16
)
407 ? &ics5342_pll_pd4
: &ics5342_pll
,
408 freq
, &m
, &n
, &r
, 0);
413 u8 code
[6] = {4, 3, 5, m
-2, 5, (n
-2) | (r
<< 5)};
414 dac_write_regs(info
, code
, 3);
419 static void ics5342_release(struct dac_info
*info
)
421 ics5342_set_mode(info
, DAC_PSEUDO8_8
);
425 static struct dac_ops ics5342_ops
= {
426 .dac_set_mode
= ics5342_set_mode
,
427 .dac_set_freq
= ics5342_set_freq
,
428 .dac_release
= ics5342_release
432 static struct dac_info
* ics5342_init(dac_read_regs_t drr
, dac_write_regs_t dwr
, void *data
)
434 struct dac_info
*info
= kzalloc(sizeof(struct ics5342_info
), GFP_KERNEL
);
439 info
->dacops
= &ics5342_ops
;
440 info
->dac_read_regs
= drr
;
441 info
->dac_write_regs
= dwr
;
443 DAC_PAR(info
)->mode
= DAC_PSEUDO8_8
; /* estimation */
448 /* ------------------------------------------------------------------------- */
451 static unsigned short dac_regs
[4] = {0x3c8, 0x3c9, 0x3c6, 0x3c7};
453 static void ark_dac_read_regs(void *data
, u8
*code
, int count
)
455 struct fb_info
*info
= data
;
456 struct arkfb_info
*par
;
460 regval
= vga_rseq(par
->state
.vgabase
, 0x1C);
463 vga_wseq(par
->state
.vgabase
, 0x1C, regval
| (code
[0] & 4 ? 0x80 : 0));
464 code
[1] = vga_r(par
->state
.vgabase
, dac_regs
[code
[0] & 3]);
469 vga_wseq(par
->state
.vgabase
, 0x1C, regval
);
472 static void ark_dac_write_regs(void *data
, u8
*code
, int count
)
474 struct fb_info
*info
= data
;
475 struct arkfb_info
*par
;
479 regval
= vga_rseq(par
->state
.vgabase
, 0x1C);
482 vga_wseq(par
->state
.vgabase
, 0x1C, regval
| (code
[0] & 4 ? 0x80 : 0));
483 vga_w(par
->state
.vgabase
, dac_regs
[code
[0] & 3], code
[1]);
488 vga_wseq(par
->state
.vgabase
, 0x1C, regval
);
492 static void ark_set_pixclock(struct fb_info
*info
, u32 pixclock
)
494 struct arkfb_info
*par
= info
->par
;
497 int rv
= dac_set_freq(par
->dac
, 0, 1000000000 / pixclock
);
499 fb_err(info
, "cannot set requested pixclock, keeping old value\n");
503 /* Set VGA misc register */
504 regval
= vga_r(par
->state
.vgabase
, VGA_MIS_R
);
505 vga_w(par
->state
.vgabase
, VGA_MIS_W
, regval
| VGA_MIS_ENB_PLL_LOAD
);
509 /* Open framebuffer */
511 static int arkfb_open(struct fb_info
*info
, int user
)
513 struct arkfb_info
*par
= info
->par
;
515 mutex_lock(&(par
->open_lock
));
516 if (par
->ref_count
== 0) {
517 void __iomem
*vgabase
= par
->state
.vgabase
;
519 memset(&(par
->state
), 0, sizeof(struct vgastate
));
520 par
->state
.vgabase
= vgabase
;
521 par
->state
.flags
= VGA_SAVE_MODE
| VGA_SAVE_FONTS
| VGA_SAVE_CMAP
;
522 par
->state
.num_crtc
= 0x60;
523 par
->state
.num_seq
= 0x30;
524 save_vga(&(par
->state
));
528 mutex_unlock(&(par
->open_lock
));
533 /* Close framebuffer */
535 static int arkfb_release(struct fb_info
*info
, int user
)
537 struct arkfb_info
*par
= info
->par
;
539 mutex_lock(&(par
->open_lock
));
540 if (par
->ref_count
== 0) {
541 mutex_unlock(&(par
->open_lock
));
545 if (par
->ref_count
== 1) {
546 restore_vga(&(par
->state
));
547 dac_set_mode(par
->dac
, DAC_PSEUDO8_8
);
551 mutex_unlock(&(par
->open_lock
));
556 /* Validate passed in var */
558 static int arkfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
565 /* Find appropriate format */
566 rv
= svga_match_format (arkfb_formats
, var
, NULL
);
569 fb_err(info
, "unsupported mode requested\n");
573 /* Do not allow to have real resoulution larger than virtual */
574 if (var
->xres
> var
->xres_virtual
)
575 var
->xres_virtual
= var
->xres
;
577 if (var
->yres
> var
->yres_virtual
)
578 var
->yres_virtual
= var
->yres
;
580 /* Round up xres_virtual to have proper alignment of lines */
581 step
= arkfb_formats
[rv
].xresstep
- 1;
582 var
->xres_virtual
= (var
->xres_virtual
+step
) & ~step
;
585 /* Check whether have enough memory */
586 mem
= ((var
->bits_per_pixel
* var
->xres_virtual
) >> 3) * var
->yres_virtual
;
587 if (mem
> info
->screen_size
)
589 fb_err(info
, "not enough framebuffer memory (%d kB requested, %d kB available)\n",
590 mem
>> 10, (unsigned int) (info
->screen_size
>> 10));
594 rv
= svga_check_timings (&ark_timing_regs
, var
, info
->node
);
597 fb_err(info
, "invalid timings requested\n");
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 */
626 bitmap_zero(info
->pixmap
.blit_x
, FB_MAX_BLIT_WIDTH
);
627 set_bit(8 - 1, info
->pixmap
.blit_x
);
629 bitmap_fill(info
->pixmap
.blit_x
, FB_MAX_BLIT_WIDTH
);
631 bitmap_fill(info
->pixmap
.blit_y
, FB_MAX_BLIT_HEIGHT
);
633 offset_value
= (info
->var
.xres_virtual
* bpp
) / 64;
634 screen_size
= info
->var
.yres_virtual
* info
->fix
.line_length
;
636 info
->fix
.ypanstep
= 16;
637 info
->fix
.line_length
= 0;
639 info
->flags
|= FBINFO_MISC_TILEBLITTING
;
640 info
->tileops
= &arkfb_tile_ops
;
642 /* supports 8x16 tiles only */
643 bitmap_zero(info
->pixmap
.blit_x
, FB_MAX_BLIT_WIDTH
);
644 set_bit(8 - 1, info
->pixmap
.blit_x
);
645 bitmap_zero(info
->pixmap
.blit_y
, FB_MAX_BLIT_HEIGHT
);
646 set_bit(16 - 1, info
->pixmap
.blit_y
);
648 offset_value
= info
->var
.xres_virtual
/ 16;
649 screen_size
= (info
->var
.xres_virtual
* info
->var
.yres_virtual
) / 64;
652 info
->var
.xoffset
= 0;
653 info
->var
.yoffset
= 0;
654 info
->var
.activate
= FB_ACTIVATE_NOW
;
656 /* Unlock registers */
657 svga_wcrt_mask(par
->state
.vgabase
, 0x11, 0x00, 0x80);
659 /* Blank screen and turn off sync */
660 svga_wseq_mask(par
->state
.vgabase
, 0x01, 0x20, 0x20);
661 svga_wcrt_mask(par
->state
.vgabase
, 0x17, 0x00, 0x80);
663 /* Set default values */
664 svga_set_default_gfx_regs(par
->state
.vgabase
);
665 svga_set_default_atc_regs(par
->state
.vgabase
);
666 svga_set_default_seq_regs(par
->state
.vgabase
);
667 svga_set_default_crt_regs(par
->state
.vgabase
);
668 svga_wcrt_multi(par
->state
.vgabase
, ark_line_compare_regs
, 0xFFFFFFFF);
669 svga_wcrt_multi(par
->state
.vgabase
, ark_start_address_regs
, 0);
671 /* ARK specific initialization */
672 svga_wseq_mask(par
->state
.vgabase
, 0x10, 0x1F, 0x1F); /* enable linear framebuffer and full memory access */
673 svga_wseq_mask(par
->state
.vgabase
, 0x12, 0x03, 0x03); /* 4 MB linear framebuffer size */
675 vga_wseq(par
->state
.vgabase
, 0x13, info
->fix
.smem_start
>> 16);
676 vga_wseq(par
->state
.vgabase
, 0x14, info
->fix
.smem_start
>> 24);
677 vga_wseq(par
->state
.vgabase
, 0x15, 0);
678 vga_wseq(par
->state
.vgabase
, 0x16, 0);
680 /* Set the FIFO threshold register */
681 /* It is fascinating way to store 5-bit value in 8-bit register */
682 regval
= 0x10 | ((threshold
& 0x0E) >> 1) | (threshold
& 0x01) << 7 | (threshold
& 0x10) << 1;
683 vga_wseq(par
->state
.vgabase
, 0x18, regval
);
685 /* Set the offset register */
686 fb_dbg(info
, "offset register : %d\n", offset_value
);
687 svga_wcrt_multi(par
->state
.vgabase
, ark_offset_regs
, offset_value
);
689 /* fix for hi-res textmode */
690 svga_wcrt_mask(par
->state
.vgabase
, 0x40, 0x08, 0x08);
692 if (info
->var
.vmode
& FB_VMODE_DOUBLE
)
693 svga_wcrt_mask(par
->state
.vgabase
, 0x09, 0x80, 0x80);
695 svga_wcrt_mask(par
->state
.vgabase
, 0x09, 0x00, 0x80);
697 if (info
->var
.vmode
& FB_VMODE_INTERLACED
)
698 svga_wcrt_mask(par
->state
.vgabase
, 0x44, 0x04, 0x04);
700 svga_wcrt_mask(par
->state
.vgabase
, 0x44, 0x00, 0x04);
704 mode
= svga_match_format(arkfb_formats
, &(info
->var
), &(info
->fix
));
706 /* Set mode-specific register values */
709 fb_dbg(info
, "text mode\n");
710 svga_set_textmode_vga_regs(par
->state
.vgabase
);
712 vga_wseq(par
->state
.vgabase
, 0x11, 0x10); /* basic VGA mode */
713 svga_wcrt_mask(par
->state
.vgabase
, 0x46, 0x00, 0x04); /* 8bit pixel path */
714 dac_set_mode(par
->dac
, DAC_PSEUDO8_8
);
718 fb_dbg(info
, "4 bit pseudocolor\n");
719 vga_wgfx(par
->state
.vgabase
, VGA_GFX_MODE
, 0x40);
721 vga_wseq(par
->state
.vgabase
, 0x11, 0x10); /* basic VGA mode */
722 svga_wcrt_mask(par
->state
.vgabase
, 0x46, 0x00, 0x04); /* 8bit pixel path */
723 dac_set_mode(par
->dac
, DAC_PSEUDO8_8
);
726 fb_dbg(info
, "4 bit pseudocolor, planar\n");
728 vga_wseq(par
->state
.vgabase
, 0x11, 0x10); /* basic VGA mode */
729 svga_wcrt_mask(par
->state
.vgabase
, 0x46, 0x00, 0x04); /* 8bit pixel path */
730 dac_set_mode(par
->dac
, DAC_PSEUDO8_8
);
733 fb_dbg(info
, "8 bit pseudocolor\n");
735 vga_wseq(par
->state
.vgabase
, 0x11, 0x16); /* 8bpp accel mode */
737 if (info
->var
.pixclock
> 20000) {
738 fb_dbg(info
, "not using multiplex\n");
739 svga_wcrt_mask(par
->state
.vgabase
, 0x46, 0x00, 0x04); /* 8bit pixel path */
740 dac_set_mode(par
->dac
, DAC_PSEUDO8_8
);
742 fb_dbg(info
, "using multiplex\n");
743 svga_wcrt_mask(par
->state
.vgabase
, 0x46, 0x04, 0x04); /* 16bit pixel path */
744 dac_set_mode(par
->dac
, DAC_PSEUDO8_16
);
749 fb_dbg(info
, "5/5/5 truecolor\n");
751 vga_wseq(par
->state
.vgabase
, 0x11, 0x1A); /* 16bpp accel mode */
752 svga_wcrt_mask(par
->state
.vgabase
, 0x46, 0x04, 0x04); /* 16bit pixel path */
753 dac_set_mode(par
->dac
, DAC_RGB1555_16
);
756 fb_dbg(info
, "5/6/5 truecolor\n");
758 vga_wseq(par
->state
.vgabase
, 0x11, 0x1A); /* 16bpp accel mode */
759 svga_wcrt_mask(par
->state
.vgabase
, 0x46, 0x04, 0x04); /* 16bit pixel path */
760 dac_set_mode(par
->dac
, DAC_RGB0565_16
);
763 fb_dbg(info
, "8/8/8 truecolor\n");
765 vga_wseq(par
->state
.vgabase
, 0x11, 0x16); /* 8bpp accel mode ??? */
766 svga_wcrt_mask(par
->state
.vgabase
, 0x46, 0x04, 0x04); /* 16bit pixel path */
767 dac_set_mode(par
->dac
, DAC_RGB0888_16
);
772 fb_dbg(info
, "8/8/8/8 truecolor\n");
774 vga_wseq(par
->state
.vgabase
, 0x11, 0x1E); /* 32bpp accel mode */
775 svga_wcrt_mask(par
->state
.vgabase
, 0x46, 0x04, 0x04); /* 16bit pixel path */
776 dac_set_mode(par
->dac
, DAC_RGB8888_16
);
780 fb_err(info
, "unsupported mode - bug\n");
784 value
= (hdiv
* info
->var
.pixclock
) / hmul
;
786 fb_dbg(info
, "invalid pixclock\n");
789 ark_set_pixclock(info
, value
);
790 svga_set_timings(par
->state
.vgabase
, &ark_timing_regs
, &(info
->var
), hmul
, hdiv
,
791 (info
->var
.vmode
& FB_VMODE_DOUBLE
) ? 2 : 1,
792 (info
->var
.vmode
& FB_VMODE_INTERLACED
) ? 2 : 1,
795 /* Set interlaced mode start/end register */
796 value
= info
->var
.xres
+ info
->var
.left_margin
+ info
->var
.right_margin
+ info
->var
.hsync_len
;
797 value
= ((value
* hmul
/ hdiv
) / 8) - 5;
798 vga_wcrt(par
->state
.vgabase
, 0x42, (value
+ 1) / 2);
800 if (screen_size
> info
->screen_size
)
801 screen_size
= info
->screen_size
;
802 memset_io(info
->screen_base
, 0x00, screen_size
);
803 /* Device and screen back on */
804 svga_wcrt_mask(par
->state
.vgabase
, 0x17, 0x80, 0x80);
805 svga_wseq_mask(par
->state
.vgabase
, 0x01, 0x00, 0x20);
810 /* Set a colour register */
812 static int arkfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
813 u_int transp
, struct fb_info
*fb
)
815 switch (fb
->var
.bits_per_pixel
) {
821 if ((fb
->var
.bits_per_pixel
== 4) &&
822 (fb
->var
.nonstd
== 0)) {
823 outb(0xF0, VGA_PEL_MSK
);
824 outb(regno
*16, VGA_PEL_IW
);
826 outb(0x0F, VGA_PEL_MSK
);
827 outb(regno
, VGA_PEL_IW
);
829 outb(red
>> 10, VGA_PEL_D
);
830 outb(green
>> 10, VGA_PEL_D
);
831 outb(blue
>> 10, VGA_PEL_D
);
837 outb(0xFF, VGA_PEL_MSK
);
838 outb(regno
, VGA_PEL_IW
);
839 outb(red
>> 10, VGA_PEL_D
);
840 outb(green
>> 10, VGA_PEL_D
);
841 outb(blue
>> 10, VGA_PEL_D
);
847 if (fb
->var
.green
.length
== 5)
848 ((u32
*)fb
->pseudo_palette
)[regno
] = ((red
& 0xF800) >> 1) |
849 ((green
& 0xF800) >> 6) | ((blue
& 0xF800) >> 11);
850 else if (fb
->var
.green
.length
== 6)
851 ((u32
*)fb
->pseudo_palette
)[regno
] = (red
& 0xF800) |
852 ((green
& 0xFC00) >> 5) | ((blue
& 0xF800) >> 11);
861 ((u32
*)fb
->pseudo_palette
)[regno
] = ((red
& 0xFF00) << 8) |
862 (green
& 0xFF00) | ((blue
& 0xFF00) >> 8);
871 /* Set the display blanking state */
873 static int arkfb_blank(int blank_mode
, struct fb_info
*info
)
875 struct arkfb_info
*par
= info
->par
;
877 switch (blank_mode
) {
878 case FB_BLANK_UNBLANK
:
879 fb_dbg(info
, "unblank\n");
880 svga_wseq_mask(par
->state
.vgabase
, 0x01, 0x00, 0x20);
881 svga_wcrt_mask(par
->state
.vgabase
, 0x17, 0x80, 0x80);
883 case FB_BLANK_NORMAL
:
884 fb_dbg(info
, "blank\n");
885 svga_wseq_mask(par
->state
.vgabase
, 0x01, 0x20, 0x20);
886 svga_wcrt_mask(par
->state
.vgabase
, 0x17, 0x80, 0x80);
888 case FB_BLANK_POWERDOWN
:
889 case FB_BLANK_HSYNC_SUSPEND
:
890 case FB_BLANK_VSYNC_SUSPEND
:
891 fb_dbg(info
, "sync down\n");
892 svga_wseq_mask(par
->state
.vgabase
, 0x01, 0x20, 0x20);
893 svga_wcrt_mask(par
->state
.vgabase
, 0x17, 0x00, 0x80);
900 /* Pan the display */
902 static int arkfb_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
904 struct arkfb_info
*par
= info
->par
;
907 /* Calculate the offset */
908 if (info
->var
.bits_per_pixel
== 0) {
909 offset
= (var
->yoffset
/ 16) * (info
->var
.xres_virtual
/ 2)
910 + (var
->xoffset
/ 2);
911 offset
= offset
>> 2;
913 offset
= (var
->yoffset
* info
->fix
.line_length
) +
914 (var
->xoffset
* info
->var
.bits_per_pixel
/ 8);
915 offset
= offset
>> ((info
->var
.bits_per_pixel
== 4) ? 2 : 3);
919 svga_wcrt_multi(par
->state
.vgabase
, ark_start_address_regs
, offset
);
925 /* ------------------------------------------------------------------------- */
928 /* Frame buffer operations */
930 static const struct fb_ops arkfb_ops
= {
931 .owner
= THIS_MODULE
,
932 .fb_open
= arkfb_open
,
933 .fb_release
= arkfb_release
,
934 __FB_DEFAULT_IOMEM_OPS_RDWR
,
935 .fb_check_var
= arkfb_check_var
,
936 .fb_set_par
= arkfb_set_par
,
937 .fb_setcolreg
= arkfb_setcolreg
,
938 .fb_blank
= arkfb_blank
,
939 .fb_pan_display
= arkfb_pan_display
,
940 .fb_fillrect
= arkfb_fillrect
,
941 .fb_copyarea
= cfb_copyarea
,
942 .fb_imageblit
= arkfb_imageblit
,
943 __FB_DEFAULT_IOMEM_OPS_MMAP
,
944 .fb_get_caps
= svga_get_caps
,
948 /* ------------------------------------------------------------------------- */
952 static int ark_pci_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
954 struct pci_bus_region bus_reg
;
955 struct resource vga_res
;
956 struct fb_info
*info
;
957 struct arkfb_info
*par
;
961 rc
= aperture_remove_conflicting_pci_devices(dev
, "arkfb");
965 /* Ignore secondary VGA device because there is no VGA arbitration */
966 if (! svga_primary_device(dev
)) {
967 dev_info(&(dev
->dev
), "ignoring secondary device\n");
971 /* Allocate and fill driver data structure */
972 info
= framebuffer_alloc(sizeof(struct arkfb_info
), &(dev
->dev
));
977 mutex_init(&par
->open_lock
);
979 info
->flags
= FBINFO_PARTIAL_PAN_OK
| FBINFO_HWACCEL_YPAN
;
980 info
->fbops
= &arkfb_ops
;
982 /* Prepare PCI device */
983 rc
= pci_enable_device(dev
);
985 dev_err(info
->device
, "cannot enable PCI device\n");
986 goto err_enable_device
;
989 rc
= pci_request_regions(dev
, "arkfb");
991 dev_err(info
->device
, "cannot reserve framebuffer region\n");
992 goto err_request_regions
;
995 par
->dac
= ics5342_init(ark_dac_read_regs
, ark_dac_write_regs
, info
);
998 dev_err(info
->device
, "RAMDAC initialization failed\n");
1002 info
->fix
.smem_start
= pci_resource_start(dev
, 0);
1003 info
->fix
.smem_len
= pci_resource_len(dev
, 0);
1005 /* Map physical IO memory address into kernel space */
1006 info
->screen_base
= pci_iomap_wc(dev
, 0, 0);
1007 if (! info
->screen_base
) {
1009 dev_err(info
->device
, "iomap for framebuffer failed\n");
1014 bus_reg
.end
= 64 * 1024;
1016 vga_res
.flags
= IORESOURCE_IO
;
1018 pcibios_bus_to_resource(dev
->bus
, &vga_res
, &bus_reg
);
1020 par
->state
.vgabase
= (void __iomem
*) (unsigned long) vga_res
.start
;
1022 /* FIXME get memsize */
1023 regval
= vga_rseq(par
->state
.vgabase
, 0x10);
1024 info
->screen_size
= (1 << (regval
>> 6)) << 20;
1025 info
->fix
.smem_len
= info
->screen_size
;
1027 strcpy(info
->fix
.id
, "ARK 2000PV");
1028 info
->fix
.mmio_start
= 0;
1029 info
->fix
.mmio_len
= 0;
1030 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1031 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
1032 info
->fix
.ypanstep
= 0;
1033 info
->fix
.accel
= FB_ACCEL_NONE
;
1034 info
->pseudo_palette
= (void*) (par
->pseudo_palette
);
1036 /* Prepare startup mode */
1037 rc
= fb_find_mode(&(info
->var
), info
, mode_option
, NULL
, 0, NULL
, 8);
1038 if (! ((rc
== 1) || (rc
== 2))) {
1040 dev_err(info
->device
, "mode %s not found\n", mode_option
);
1044 rc
= fb_alloc_cmap(&info
->cmap
, 256, 0);
1046 dev_err(info
->device
, "cannot allocate colormap\n");
1047 goto err_alloc_cmap
;
1050 rc
= register_framebuffer(info
);
1052 dev_err(info
->device
, "cannot register framebuffer\n");
1056 fb_info(info
, "%s on %s, %d MB RAM\n",
1057 info
->fix
.id
, pci_name(dev
), info
->fix
.smem_len
>> 20);
1059 /* Record a reference to the driver data */
1060 pci_set_drvdata(dev
, info
);
1061 par
->wc_cookie
= arch_phys_wc_add(info
->fix
.smem_start
,
1062 info
->fix
.smem_len
);
1065 /* Error handling */
1067 fb_dealloc_cmap(&info
->cmap
);
1070 pci_iounmap(dev
, info
->screen_base
);
1072 dac_release(par
->dac
);
1074 pci_release_regions(dev
);
1075 err_request_regions
:
1076 /* pci_disable_device(dev); */
1078 framebuffer_release(info
);
1084 static void ark_pci_remove(struct pci_dev
*dev
)
1086 struct fb_info
*info
= pci_get_drvdata(dev
);
1089 struct arkfb_info
*par
= info
->par
;
1090 arch_phys_wc_del(par
->wc_cookie
);
1091 dac_release(par
->dac
);
1092 unregister_framebuffer(info
);
1093 fb_dealloc_cmap(&info
->cmap
);
1095 pci_iounmap(dev
, info
->screen_base
);
1096 pci_release_regions(dev
);
1097 /* pci_disable_device(dev); */
1099 framebuffer_release(info
);
1106 static int __maybe_unused
ark_pci_suspend(struct device
*dev
)
1108 struct fb_info
*info
= dev_get_drvdata(dev
);
1109 struct arkfb_info
*par
= info
->par
;
1111 dev_info(info
->device
, "suspend\n");
1114 mutex_lock(&(par
->open_lock
));
1116 if (par
->ref_count
== 0) {
1117 mutex_unlock(&(par
->open_lock
));
1122 fb_set_suspend(info
, 1);
1124 mutex_unlock(&(par
->open_lock
));
1133 static int __maybe_unused
ark_pci_resume(struct device
*dev
)
1135 struct fb_info
*info
= dev_get_drvdata(dev
);
1136 struct arkfb_info
*par
= info
->par
;
1138 dev_info(info
->device
, "resume\n");
1141 mutex_lock(&(par
->open_lock
));
1143 if (par
->ref_count
== 0)
1146 arkfb_set_par(info
);
1147 fb_set_suspend(info
, 0);
1150 mutex_unlock(&(par
->open_lock
));
1155 static const struct dev_pm_ops ark_pci_pm_ops
= {
1156 #ifdef CONFIG_PM_SLEEP
1157 .suspend
= ark_pci_suspend
,
1158 .resume
= ark_pci_resume
,
1160 .thaw
= ark_pci_resume
,
1161 .poweroff
= ark_pci_suspend
,
1162 .restore
= ark_pci_resume
,
1166 /* List of boards that we are trying to support */
1168 static const struct pci_device_id ark_devices
[] = {
1169 {PCI_DEVICE(0xEDD8, 0xA099)},
1170 {0, 0, 0, 0, 0, 0, 0}
1174 MODULE_DEVICE_TABLE(pci
, ark_devices
);
1176 static struct pci_driver arkfb_pci_driver
= {
1178 .id_table
= ark_devices
,
1179 .probe
= ark_pci_probe
,
1180 .remove
= ark_pci_remove
,
1181 .driver
.pm
= &ark_pci_pm_ops
,
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
;
1201 if (fb_modesetting_disabled("arkfb"))
1205 if (fb_get_options("arkfb", &option
))
1208 if (option
&& *option
)
1209 mode_option
= option
;
1212 pr_debug("arkfb: initializing\n");
1213 return pci_register_driver(&arkfb_pci_driver
);
1216 module_init(arkfb_init
);
1217 module_exit(arkfb_cleanup
);