2 * framebuffer driver for VBE 2.0 compliant graphic boards
4 * switching to graphics mode happens at boot time (while
5 * running in real mode, see arch/i386/video.S).
7 * (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/string.h>
16 #include <linux/tty.h>
17 #include <linux/malloc.h>
18 #include <linux/delay.h>
20 #include <linux/console.h>
21 #include <linux/selection.h>
22 #include <linux/ioport.h>
23 #include <linux/init.h>
28 #include <video/fbcon.h>
29 #include <video/fbcon-cfb8.h>
30 #include <video/fbcon-cfb16.h>
31 #include <video/fbcon-cfb24.h>
32 #include <video/fbcon-cfb32.h>
34 #define dac_reg (0x3c8)
35 #define dac_val (0x3c9)
37 /* --------------------------------------------------------------------- */
44 unsigned long video_base
; /* physical addr */
46 char *video_vbase
; /* mapped */
52 int video_height_virtual
;
53 int video_type
= FB_TYPE_PACKED_PIXELS
;
58 /* --------------------------------------------------------------------- */
60 static struct fb_var_screeninfo vesafb_defined
= {
61 0,0,0,0, /* W,H, W, H (virtual) load xres,xres_virtual*/
62 0,0, /* virtual -> visible no offset */
63 8, /* depth -> load bits_per_pixel */
68 {0,0,0}, /* transparency */
69 0, /* standard pixel format */
74 0L,0L,0, /* No sync info */
75 FB_VMODE_NONINTERLACED
,
79 static struct display disp
;
80 static struct fb_info fb_info
;
81 static struct { u_short blue
, green
, red
, pad
; } palette
[256];
83 #ifdef FBCON_HAS_CFB16
86 #ifdef FBCON_HAS_CFB24
89 #ifdef FBCON_HAS_CFB32
94 static int inverse
= 0;
96 static int currcon
= 0;
98 static int pmi_setpal
= 0; /* pmi for palette changes ??? */
99 static int ypan
= 0; /* 0..nothing, 1..ypan, 2..ywrap */
100 static unsigned short *pmi_base
= 0;
101 static void (*pmi_start
)(void);
102 static void (*pmi_pal
)(void);
104 static struct display_switch vesafb_sw
;
106 /* --------------------------------------------------------------------- */
109 * Open/Release the frame buffer device
112 static int vesafb_open(struct fb_info
*info
, int user
)
115 * Nothing, only a usage count for the moment
121 static int vesafb_release(struct fb_info
*info
, int user
)
127 static int vesafb_pan_display(struct fb_var_screeninfo
*var
, int con
,
128 struct fb_info
*info
)
136 if (var
->yoffset
> var
->yres_virtual
)
138 if ((ypan
==1) && var
->yoffset
+var
->yres
> var
->yres_virtual
)
141 offset
= (var
->yoffset
* video_linelength
+ var
->xoffset
) / 4;
143 __asm__
__volatile__(
145 : /* no return value */
146 : "a" (0x4f07), /* EAX */
148 "c" (offset
), /* ECX */
149 "d" (offset
>> 16), /* EDX */
150 "D" (&pmi_start
)); /* EDI */
154 static int vesafb_update_var(int con
, struct fb_info
*info
)
156 if (con
== currcon
&& ypan
) {
157 struct fb_var_screeninfo
*var
= &fb_display
[currcon
].var
;
158 return vesafb_pan_display(var
,con
,info
);
163 static int vesafb_get_fix(struct fb_fix_screeninfo
*fix
, int con
,
164 struct fb_info
*info
)
166 memset(fix
, 0, sizeof(struct fb_fix_screeninfo
));
167 strcpy(fix
->id
,"VESA VGA");
169 fix
->smem_start
=video_base
;
170 fix
->smem_len
=video_size
;
171 fix
->type
= video_type
;
172 fix
->visual
= video_visual
;
174 fix
->ypanstep
= ypan
? 1 : 0;
175 fix
->ywrapstep
= (ypan
>1) ? 1 : 0;
176 fix
->line_length
=video_linelength
;
180 static int vesafb_get_var(struct fb_var_screeninfo
*var
, int con
,
181 struct fb_info
*info
)
184 memcpy(var
, &vesafb_defined
, sizeof(struct fb_var_screeninfo
));
186 *var
=fb_display
[con
].var
;
190 static void vesafb_set_disp(int con
)
192 struct fb_fix_screeninfo fix
;
193 struct display
*display
;
194 struct display_switch
*sw
;
197 display
= &fb_display
[con
];
199 display
= &disp
; /* used during initialization */
201 vesafb_get_fix(&fix
, con
, 0);
203 memset(display
, 0, sizeof(struct display
));
204 display
->screen_base
= video_vbase
;
205 display
->visual
= fix
.visual
;
206 display
->type
= fix
.type
;
207 display
->type_aux
= fix
.type_aux
;
208 display
->ypanstep
= fix
.ypanstep
;
209 display
->ywrapstep
= fix
.ywrapstep
;
210 display
->line_length
= fix
.line_length
;
211 display
->next_line
= fix
.line_length
;
212 display
->can_soft_blank
= 0;
213 display
->inverse
= inverse
;
214 vesafb_get_var(&display
->var
, -1, &fb_info
);
217 #ifdef FBCON_HAS_CFB8
222 #ifdef FBCON_HAS_CFB16
226 display
->dispsw_data
= fbcon_cmap
.cfb16
;
229 #ifdef FBCON_HAS_CFB24
232 display
->dispsw_data
= fbcon_cmap
.cfb24
;
235 #ifdef FBCON_HAS_CFB32
238 display
->dispsw_data
= fbcon_cmap
.cfb32
;
245 memcpy(&vesafb_sw
, sw
, sizeof(*sw
));
246 display
->dispsw
= &vesafb_sw
;
248 display
->scrollmode
= SCROLL_YREDRAW
;
249 vesafb_sw
.bmove
= fbcon_redraw_bmove
;
253 static int vesafb_set_var(struct fb_var_screeninfo
*var
, int con
,
254 struct fb_info
*info
)
256 static int first
= 1;
258 if (var
->xres
!= vesafb_defined
.xres
||
259 var
->yres
!= vesafb_defined
.yres
||
260 var
->xres_virtual
!= vesafb_defined
.xres_virtual
||
261 var
->yres_virtual
> video_height_virtual
||
262 var
->yres_virtual
< video_height
||
264 var
->bits_per_pixel
!= vesafb_defined
.bits_per_pixel
||
267 printk(KERN_ERR
"Vesafb does not support changing the video mode\n");
273 if ((var
->activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_TEST
)
277 if (vesafb_defined
.yres_virtual
!= var
->yres_virtual
) {
278 vesafb_defined
.yres_virtual
= var
->yres_virtual
;
280 fb_display
[con
].var
= vesafb_defined
;
281 info
->changevar(con
);
285 if (var
->yoffset
!= vesafb_defined
.yoffset
)
286 return vesafb_pan_display(var
,con
,info
);
295 static int vesa_getcolreg(unsigned regno
, unsigned *red
, unsigned *green
,
296 unsigned *blue
, unsigned *transp
,
297 struct fb_info
*fb_info
)
300 * Read a single color register and split it into colors/transparent.
301 * Return != 0 for invalid regno.
304 if (regno
>= video_cmap_len
)
307 *red
= palette
[regno
].red
;
308 *green
= palette
[regno
].green
;
309 *blue
= palette
[regno
].blue
;
314 #ifdef FBCON_HAS_CFB8
316 static void vesa_setpalette(int regno
, unsigned red
, unsigned green
, unsigned blue
)
318 struct { u_char blue
, green
, red
, pad
; } entry
;
321 entry
.red
= red
>> 10;
322 entry
.green
= green
>> 10;
323 entry
.blue
= blue
>> 10;
325 __asm__
__volatile__(
327 : /* no return value */
328 : "a" (0x4f09), /* EAX */
331 "d" (regno
), /* EDX */
332 "D" (&entry
), /* EDI */
333 "S" (&pmi_pal
)); /* ESI */
335 /* without protected mode interface, try VGA registers... */
336 outb_p(regno
, dac_reg
);
337 outb_p(red
>> 10, dac_val
);
338 outb_p(green
>> 10, dac_val
);
339 outb_p(blue
>> 10, dac_val
);
345 static int vesa_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
346 unsigned blue
, unsigned transp
,
347 struct fb_info
*fb_info
)
350 * Set a single color register. The values supplied are
351 * already rounded down to the hardware's capabilities
352 * (according to the entries in the `var' structure). Return
353 * != 0 for invalid regno.
356 if (regno
>= video_cmap_len
)
359 palette
[regno
].red
= red
;
360 palette
[regno
].green
= green
;
361 palette
[regno
].blue
= blue
;
364 #ifdef FBCON_HAS_CFB8
366 vesa_setpalette(regno
,red
,green
,blue
);
369 #ifdef FBCON_HAS_CFB16
372 if (vesafb_defined
.red
.offset
== 10) {
374 fbcon_cmap
.cfb16
[regno
] =
375 ((red
& 0xf800) >> 1) |
376 ((green
& 0xf800) >> 6) |
377 ((blue
& 0xf800) >> 11);
380 fbcon_cmap
.cfb16
[regno
] =
382 ((green
& 0xfc00) >> 5) |
383 ((blue
& 0xf800) >> 11);
387 #ifdef FBCON_HAS_CFB24
392 fbcon_cmap
.cfb24
[regno
] =
393 (red
<< vesafb_defined
.red
.offset
) |
394 (green
<< vesafb_defined
.green
.offset
) |
395 (blue
<< vesafb_defined
.blue
.offset
);
398 #ifdef FBCON_HAS_CFB32
403 fbcon_cmap
.cfb32
[regno
] =
404 (red
<< vesafb_defined
.red
.offset
) |
405 (green
<< vesafb_defined
.green
.offset
) |
406 (blue
<< vesafb_defined
.blue
.offset
);
413 static void do_install_cmap(int con
, struct fb_info
*info
)
417 if (fb_display
[con
].cmap
.len
)
418 fb_set_cmap(&fb_display
[con
].cmap
, 1, vesa_setcolreg
, info
);
420 fb_set_cmap(fb_default_cmap(video_cmap_len
), 1, vesa_setcolreg
,
424 static int vesafb_get_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
425 struct fb_info
*info
)
427 if (con
== currcon
) /* current console? */
428 return fb_get_cmap(cmap
, kspc
, vesa_getcolreg
, info
);
429 else if (fb_display
[con
].cmap
.len
) /* non default colormap? */
430 fb_copy_cmap(&fb_display
[con
].cmap
, cmap
, kspc
? 0 : 2);
432 fb_copy_cmap(fb_default_cmap(video_cmap_len
),
437 static int vesafb_set_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
438 struct fb_info
*info
)
442 if (!fb_display
[con
].cmap
.len
) { /* no colormap allocated? */
443 err
= fb_alloc_cmap(&fb_display
[con
].cmap
,video_cmap_len
,0);
447 if (con
== currcon
) /* current console? */
448 return fb_set_cmap(cmap
, kspc
, vesa_setcolreg
, info
);
450 fb_copy_cmap(cmap
, &fb_display
[con
].cmap
, kspc
? 0 : 1);
454 static int vesafb_ioctl(struct inode
*inode
, struct file
*file
,
455 unsigned int cmd
, unsigned long arg
, int con
,
456 struct fb_info
*info
)
461 static struct fb_ops vesafb_ops
= {
473 int vesafb_setup(char *options
)
477 fb_info
.fontname
[0] = '\0';
479 if (!options
|| !*options
)
482 for(this_opt
=strtok(options
,","); this_opt
; this_opt
=strtok(NULL
,",")) {
483 if (!*this_opt
) continue;
485 if (! strcmp(this_opt
, "inverse"))
487 else if (! strcmp(this_opt
, "redraw"))
489 else if (! strcmp(this_opt
, "ypan"))
491 else if (! strcmp(this_opt
, "ywrap"))
493 else if (! strcmp(this_opt
, "vgapal"))
495 else if (! strcmp(this_opt
, "pmipal"))
497 else if (! strcmp(this_opt
, "mtrr"))
499 else if (!strncmp(this_opt
, "font:", 5))
500 strcpy(fb_info
.fontname
, this_opt
+5);
505 static int vesafb_switch(int con
, struct fb_info
*info
)
507 /* Do we have to save the colormap? */
508 if (fb_display
[currcon
].cmap
.len
)
509 fb_get_cmap(&fb_display
[currcon
].cmap
, 1, vesa_getcolreg
,
513 /* Install new colormap */
514 do_install_cmap(con
, info
);
515 vesafb_update_var(con
,info
);
519 /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
521 static void vesafb_blank(int blank
, struct fb_info
*info
)
526 int __init
vesafb_init(void)
530 if (screen_info
.orig_video_isVGA
!= VIDEO_TYPE_VLFB
)
533 video_base
= screen_info
.lfb_base
;
534 video_bpp
= screen_info
.lfb_depth
;
537 video_width
= screen_info
.lfb_width
;
538 video_height
= screen_info
.lfb_height
;
539 video_linelength
= screen_info
.lfb_linelength
;
540 video_size
= screen_info
.lfb_size
* 65536;
541 video_visual
= (video_bpp
== 8) ?
542 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
544 if (!__request_region(&iomem_resource
, video_base
, video_size
,
547 "vesafb: abort, cannot reserve video memory at 0x%lu\n",
552 video_vbase
= ioremap(video_base
, video_size
);
554 printk(KERN_INFO
"vesafb: framebuffer at 0x%lu, mapped to 0x%p, size %dk\n",
555 video_base
, video_vbase
, video_size
/1024);
556 printk(KERN_INFO
"vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
557 video_width
, video_height
, video_bpp
, video_linelength
, screen_info
.pages
);
559 if (screen_info
.vesapm_seg
) {
560 printk(KERN_INFO
"vesafb: protected mode interface info at %04x:%04x\n",
561 screen_info
.vesapm_seg
,screen_info
.vesapm_off
);
564 if (screen_info
.vesapm_seg
< 0xc000)
565 ypan
= pmi_setpal
= 0; /* not available or some DOS TSR ... */
567 if (ypan
|| pmi_setpal
) {
568 pmi_base
= (unsigned short*)bus_to_virt(((unsigned long)screen_info
.vesapm_seg
<< 4) + screen_info
.vesapm_off
);
569 pmi_start
= (void*)((char*)pmi_base
+ pmi_base
[1]);
570 pmi_pal
= (void*)((char*)pmi_base
+ pmi_base
[2]);
571 printk(KERN_INFO
"vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start
,pmi_pal
);
573 printk(KERN_INFO
"vesafb: pmi: ports = ");
574 for (i
= pmi_base
[3]/2; pmi_base
[i
] != 0xffff; i
++)
575 printk("%x ",pmi_base
[i
]);
577 if (pmi_base
[i
] != 0xffff) {
579 * memory areas not supported (yet?)
581 * Rules are: we have to set up a descriptor for the requested
582 * memory area and pass it in the ES register to the BIOS function.
584 printk(KERN_INFO
"vesafb: can't handle memory requests, pmi disabled\n");
585 ypan
= pmi_setpal
= 0;
590 vesafb_defined
.xres
=video_width
;
591 vesafb_defined
.yres
=video_height
;
592 vesafb_defined
.xres_virtual
=video_width
;
593 vesafb_defined
.yres_virtual
=video_size
/ video_linelength
;
594 vesafb_defined
.bits_per_pixel
=video_bpp
;
596 if (ypan
&& vesafb_defined
.yres_virtual
> video_height
) {
597 printk(KERN_INFO
"vesafb: scrolling: %s using protected mode interface, yres_virtual=%d\n",
598 (ypan
> 1) ? "ywrap" : "ypan",vesafb_defined
.yres_virtual
);
600 printk(KERN_INFO
"vesafb: scrolling: redraw\n");
601 vesafb_defined
.yres_virtual
= video_height
;
604 video_height_virtual
= vesafb_defined
.yres_virtual
;
606 /* some dummy values for timing to make fbset happy */
607 vesafb_defined
.pixclock
= 10000000 / video_width
* 1000 / video_height
;
608 vesafb_defined
.left_margin
= (video_width
/ 8) & 0xf8;
609 vesafb_defined
.right_margin
= 32;
610 vesafb_defined
.upper_margin
= 16;
611 vesafb_defined
.lower_margin
= 4;
612 vesafb_defined
.hsync_len
= (video_width
/ 8) & 0xf8;
613 vesafb_defined
.vsync_len
= 4;
616 vesafb_defined
.red
.offset
= screen_info
.red_pos
;
617 vesafb_defined
.red
.length
= screen_info
.red_size
;
618 vesafb_defined
.green
.offset
= screen_info
.green_pos
;
619 vesafb_defined
.green
.length
= screen_info
.green_size
;
620 vesafb_defined
.blue
.offset
= screen_info
.blue_pos
;
621 vesafb_defined
.blue
.length
= screen_info
.blue_size
;
622 vesafb_defined
.transp
.offset
= screen_info
.rsvd_pos
;
623 vesafb_defined
.transp
.length
= screen_info
.rsvd_size
;
624 printk(KERN_INFO
"vesafb: directcolor: "
625 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
626 screen_info
.rsvd_size
,
627 screen_info
.red_size
,
628 screen_info
.green_size
,
629 screen_info
.blue_size
,
630 screen_info
.rsvd_pos
,
632 screen_info
.green_pos
,
633 screen_info
.blue_pos
);
636 vesafb_defined
.red
.length
= 6;
637 vesafb_defined
.green
.length
= 6;
638 vesafb_defined
.blue
.length
= 6;
639 for(i
= 0; i
< 16; i
++) {
641 palette
[i
].red
= default_red
[j
];
642 palette
[i
].green
= default_grn
[j
];
643 palette
[i
].blue
= default_blu
[j
];
645 video_cmap_len
= 256;
648 /* request failure does not faze us, as vgacon probably has this
649 * region already (FIXME) */
650 __request_region(&ioport_resource
, 0x3c0, 32, "vesafb");
653 mtrr_add(video_base
, video_size
, MTRR_TYPE_WRCOMB
, 1);
655 strcpy(fb_info
.modename
, "VESA VGA");
656 fb_info
.changevar
= NULL
;
658 fb_info
.fbops
= &vesafb_ops
;
660 fb_info
.switch_con
=&vesafb_switch
;
661 fb_info
.updatevar
=&vesafb_update_var
;
662 fb_info
.blank
=&vesafb_blank
;
663 fb_info
.flags
=FBINFO_FLAG_DEFAULT
;
666 if (register_framebuffer(&fb_info
)<0)
669 printk(KERN_INFO
"fb%d: %s frame buffer device\n",
670 GET_FB_IDX(fb_info
.node
), fb_info
.modename
);
675 * Overrides for Emacs so that we follow Linus's tabbing style.
676 * ---------------------------------------------------------------------------