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/boot/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/slab.h>
18 #include <linux/delay.h>
20 #include <linux/ioport.h>
21 #include <linux/init.h>
23 #include <video/edid.h>
28 #define dac_reg (0x3c8)
29 #define dac_val (0x3c9)
31 /* --------------------------------------------------------------------- */
33 static struct fb_var_screeninfo vesafb_defined __initdata
= {
34 .activate
= FB_ACTIVATE_NOW
,
41 .vmode
= FB_VMODE_NONINTERLACED
,
44 static struct fb_fix_screeninfo vesafb_fix __initdata
= {
46 .type
= FB_TYPE_PACKED_PIXELS
,
47 .accel
= FB_ACCEL_NONE
,
50 static int inverse
= 0;
52 static int vram __initdata
= 0; /* Set amount of memory to be used */
53 static int pmi_setpal
= 0; /* pmi for palette changes ??? */
54 static int ypan
= 0; /* 0..nothing, 1..ypan, 2..ywrap */
55 static unsigned short *pmi_base
= NULL
;
56 static void (*pmi_start
)(void);
57 static void (*pmi_pal
)(void);
59 /* --------------------------------------------------------------------- */
61 static int vesafb_pan_display(struct fb_var_screeninfo
*var
,
71 if (var
->yoffset
> var
->yres_virtual
)
73 if ((ypan
==1) && var
->yoffset
+var
->yres
> var
->yres_virtual
)
76 offset
= (var
->yoffset
* info
->fix
.line_length
+ var
->xoffset
) / 4;
80 : /* no return value */
81 : "a" (0x4f07), /* EAX */
83 "c" (offset
), /* ECX */
84 "d" (offset
>> 16), /* EDX */
85 "D" (&pmi_start
)); /* EDI */
90 static void vesa_setpalette(int regno
, unsigned red
, unsigned green
,
91 unsigned blue
, struct fb_var_screeninfo
*var
)
94 struct { u_char blue
, green
, red
, pad
; } entry
;
95 int shift
= 16 - var
->green
.length
;
98 entry
.red
= red
>> shift
;
99 entry
.green
= green
>> shift
;
100 entry
.blue
= blue
>> shift
;
102 __asm__
__volatile__(
104 : /* no return value */
105 : "a" (0x4f09), /* EAX */
108 "d" (regno
), /* EDX */
109 "D" (&entry
), /* EDI */
110 "S" (&pmi_pal
)); /* ESI */
112 /* without protected mode interface, try VGA registers... */
113 outb_p(regno
, dac_reg
);
114 outb_p(red
>> shift
, dac_val
);
115 outb_p(green
>> shift
, dac_val
);
116 outb_p(blue
>> shift
, dac_val
);
121 static int vesafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
122 unsigned blue
, unsigned transp
,
123 struct fb_info
*info
)
126 * Set a single color register. The values supplied are
127 * already rounded down to the hardware's capabilities
128 * (according to the entries in the `var' structure). Return
129 * != 0 for invalid regno.
132 if (regno
>= info
->cmap
.len
)
135 switch (info
->var
.bits_per_pixel
) {
137 vesa_setpalette(regno
,red
,green
,blue
, &info
->var
);
140 if (info
->var
.red
.offset
== 10) {
142 ((u32
*) (info
->pseudo_palette
))[regno
] =
143 ((red
& 0xf800) >> 1) |
144 ((green
& 0xf800) >> 6) |
145 ((blue
& 0xf800) >> 11);
148 ((u32
*) (info
->pseudo_palette
))[regno
] =
150 ((green
& 0xfc00) >> 5) |
151 ((blue
& 0xf800) >> 11);
158 ((u32
*)(info
->pseudo_palette
))[regno
] =
159 (red
<< info
->var
.red
.offset
) |
160 (green
<< info
->var
.green
.offset
) |
161 (blue
<< info
->var
.blue
.offset
);
167 ((u32
*)(info
->pseudo_palette
))[regno
] =
168 (red
<< info
->var
.red
.offset
) |
169 (green
<< info
->var
.green
.offset
) |
170 (blue
<< info
->var
.blue
.offset
);
176 static struct fb_ops vesafb_ops
= {
177 .owner
= THIS_MODULE
,
178 .fb_setcolreg
= vesafb_setcolreg
,
179 .fb_pan_display
= vesafb_pan_display
,
180 .fb_fillrect
= cfb_fillrect
,
181 .fb_copyarea
= cfb_copyarea
,
182 .fb_imageblit
= cfb_imageblit
,
183 .fb_cursor
= soft_cursor
,
186 int __init
vesafb_setup(char *options
)
190 if (!options
|| !*options
)
193 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
194 if (!*this_opt
) continue;
196 if (! strcmp(this_opt
, "inverse"))
198 else if (! strcmp(this_opt
, "redraw"))
200 else if (! strcmp(this_opt
, "ypan"))
202 else if (! strcmp(this_opt
, "ywrap"))
204 else if (! strcmp(this_opt
, "vgapal"))
206 else if (! strcmp(this_opt
, "pmipal"))
208 else if (! strcmp(this_opt
, "mtrr"))
210 else if (! strcmp(this_opt
, "nomtrr"))
212 else if (! strncmp(this_opt
, "vram:", 5))
213 vram
= simple_strtoul(this_opt
+5, NULL
, 0);
218 static int __init
vesafb_probe(struct device
*device
)
220 struct platform_device
*dev
= to_platform_device(device
);
221 struct fb_info
*info
;
224 if (screen_info
.orig_video_isVGA
!= VIDEO_TYPE_VLFB
)
227 vesafb_fix
.smem_start
= screen_info
.lfb_base
;
228 vesafb_defined
.bits_per_pixel
= screen_info
.lfb_depth
;
229 if (15 == vesafb_defined
.bits_per_pixel
)
230 vesafb_defined
.bits_per_pixel
= 16;
231 vesafb_defined
.xres
= screen_info
.lfb_width
;
232 vesafb_defined
.yres
= screen_info
.lfb_height
;
233 vesafb_fix
.line_length
= screen_info
.lfb_linelength
;
235 /* Allocate enough memory for double buffering */
236 vesafb_fix
.smem_len
= screen_info
.lfb_width
* screen_info
.lfb_height
* vesafb_defined
.bits_per_pixel
>> 2;
238 /* check that we don't remap more memory than old cards have */
239 if (vesafb_fix
.smem_len
> (screen_info
.lfb_size
* 65536))
240 vesafb_fix
.smem_len
= screen_info
.lfb_size
* 65536;
242 /* Set video size according to vram boot option */
244 vesafb_fix
.smem_len
= vram
* 1024 * 1024;
246 vesafb_fix
.visual
= (vesafb_defined
.bits_per_pixel
== 8) ?
247 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
249 /* limit framebuffer size to 16 MB. Otherwise we'll eat tons of
250 * kernel address space for nothing if the gfx card has alot of
251 * memory (>= 128 MB isn't uncommon these days ...) */
252 if (vesafb_fix
.smem_len
> 16 * 1024 * 1024)
253 vesafb_fix
.smem_len
= 16 * 1024 * 1024;
256 screen_info
.vesapm_seg
= 0;
259 if (!request_mem_region(vesafb_fix
.smem_start
, vesafb_fix
.smem_len
, "vesafb")) {
261 "vesafb: abort, cannot reserve video memory at 0x%lx\n",
262 vesafb_fix
.smem_start
);
263 /* We cannot make this fatal. Sometimes this comes from magic
264 spaces our resource handlers simply don't know about */
267 info
= framebuffer_alloc(sizeof(u32
) * 256, &dev
->dev
);
269 release_mem_region(vesafb_fix
.smem_start
, vesafb_fix
.smem_len
);
272 info
->pseudo_palette
= info
->par
;
275 info
->screen_base
= ioremap(vesafb_fix
.smem_start
, vesafb_fix
.smem_len
);
276 if (!info
->screen_base
) {
278 "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n",
279 vesafb_fix
.smem_len
, vesafb_fix
.smem_start
);
284 printk(KERN_INFO
"vesafb: framebuffer at 0x%lx, mapped to 0x%p, size %dk\n",
285 vesafb_fix
.smem_start
, info
->screen_base
, vesafb_fix
.smem_len
/1024);
286 printk(KERN_INFO
"vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
287 vesafb_defined
.xres
, vesafb_defined
.yres
, vesafb_defined
.bits_per_pixel
, vesafb_fix
.line_length
, screen_info
.pages
);
289 if (screen_info
.vesapm_seg
) {
290 printk(KERN_INFO
"vesafb: protected mode interface info at %04x:%04x\n",
291 screen_info
.vesapm_seg
,screen_info
.vesapm_off
);
294 if (screen_info
.vesapm_seg
< 0xc000)
295 ypan
= pmi_setpal
= 0; /* not available or some DOS TSR ... */
297 if (ypan
|| pmi_setpal
) {
298 pmi_base
= (unsigned short*)phys_to_virt(((unsigned long)screen_info
.vesapm_seg
<< 4) + screen_info
.vesapm_off
);
299 pmi_start
= (void*)((char*)pmi_base
+ pmi_base
[1]);
300 pmi_pal
= (void*)((char*)pmi_base
+ pmi_base
[2]);
301 printk(KERN_INFO
"vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start
,pmi_pal
);
303 printk(KERN_INFO
"vesafb: pmi: ports = ");
304 for (i
= pmi_base
[3]/2; pmi_base
[i
] != 0xffff; i
++)
305 printk("%x ",pmi_base
[i
]);
307 if (pmi_base
[i
] != 0xffff) {
309 * memory areas not supported (yet?)
311 * Rules are: we have to set up a descriptor for the requested
312 * memory area and pass it in the ES register to the BIOS function.
314 printk(KERN_INFO
"vesafb: can't handle memory requests, pmi disabled\n");
315 ypan
= pmi_setpal
= 0;
320 vesafb_defined
.xres_virtual
= vesafb_defined
.xres
;
321 vesafb_defined
.yres_virtual
= vesafb_fix
.smem_len
/ vesafb_fix
.line_length
;
322 if (ypan
&& vesafb_defined
.yres_virtual
> vesafb_defined
.yres
) {
323 printk(KERN_INFO
"vesafb: scrolling: %s using protected mode interface, yres_virtual=%d\n",
324 (ypan
> 1) ? "ywrap" : "ypan",vesafb_defined
.yres_virtual
);
326 printk(KERN_INFO
"vesafb: scrolling: redraw\n");
327 vesafb_defined
.yres_virtual
= vesafb_defined
.yres
;
331 /* some dummy values for timing to make fbset happy */
332 vesafb_defined
.pixclock
= 10000000 / vesafb_defined
.xres
* 1000 / vesafb_defined
.yres
;
333 vesafb_defined
.left_margin
= (vesafb_defined
.xres
/ 8) & 0xf8;
334 vesafb_defined
.hsync_len
= (vesafb_defined
.xres
/ 8) & 0xf8;
336 vesafb_defined
.red
.offset
= screen_info
.red_pos
;
337 vesafb_defined
.red
.length
= screen_info
.red_size
;
338 vesafb_defined
.green
.offset
= screen_info
.green_pos
;
339 vesafb_defined
.green
.length
= screen_info
.green_size
;
340 vesafb_defined
.blue
.offset
= screen_info
.blue_pos
;
341 vesafb_defined
.blue
.length
= screen_info
.blue_size
;
342 vesafb_defined
.transp
.offset
= screen_info
.rsvd_pos
;
343 vesafb_defined
.transp
.length
= screen_info
.rsvd_size
;
344 printk(KERN_INFO
"vesafb: %s: "
345 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
346 (vesafb_defined
.bits_per_pixel
> 8) ?
347 "Truecolor" : "Pseudocolor",
348 screen_info
.rsvd_size
,
349 screen_info
.red_size
,
350 screen_info
.green_size
,
351 screen_info
.blue_size
,
352 screen_info
.rsvd_pos
,
354 screen_info
.green_pos
,
355 screen_info
.blue_pos
);
357 vesafb_fix
.ypanstep
= ypan
? 1 : 0;
358 vesafb_fix
.ywrapstep
= (ypan
>1) ? 1 : 0;
360 /* request failure does not faze us, as vgacon probably has this
361 * region already (FIXME) */
362 request_region(0x3c0, 32, "vesafb");
365 int temp_size
= vesafb_fix
.smem_len
;
366 /* Find the largest power-of-two */
367 while (temp_size
& (temp_size
- 1))
368 temp_size
&= (temp_size
- 1);
370 /* Try and find a power of two to add */
371 while (temp_size
&& mtrr_add(vesafb_fix
.smem_start
, temp_size
, MTRR_TYPE_WRCOMB
, 1)==-EINVAL
) {
376 info
->fbops
= &vesafb_ops
;
377 info
->var
= vesafb_defined
;
378 info
->fix
= vesafb_fix
;
379 info
->flags
= FBINFO_FLAG_DEFAULT
|
380 (ypan
) ? FBINFO_HWACCEL_YPAN
: 0;
382 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0) {
386 if (register_framebuffer(info
)<0) {
388 fb_dealloc_cmap(&info
->cmap
);
391 printk(KERN_INFO
"fb%d: %s frame buffer device\n",
392 info
->node
, info
->fix
.id
);
395 framebuffer_release(info
);
396 release_mem_region(vesafb_fix
.smem_start
, vesafb_fix
.smem_len
);
400 static struct device_driver vesafb_driver
= {
402 .bus
= &platform_bus_type
,
403 .probe
= vesafb_probe
,
406 static struct platform_device vesafb_device
= {
410 int __init
vesafb_init(void)
415 /* ignore error return of fb_get_options */
416 fb_get_options("vesafb", &option
);
417 vesafb_setup(option
);
418 ret
= driver_register(&vesafb_driver
);
421 ret
= platform_device_register(&vesafb_device
);
423 driver_unregister(&vesafb_driver
);
427 module_init(vesafb_init
);
430 * Overrides for Emacs so that we follow Linus's tabbing style.
431 * ---------------------------------------------------------------------------
437 MODULE_LICENSE("GPL");