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/delay.h>
18 #include <linux/ioport.h>
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/screen_info.h>
24 #include <video/vga.h>
26 #define dac_reg (0x3c8)
27 #define dac_val (0x3c9)
29 /* --------------------------------------------------------------------- */
32 u32 pseudo_palette
[256];
36 static struct fb_var_screeninfo vesafb_defined
= {
37 .activate
= FB_ACTIVATE_NOW
,
44 .vmode
= FB_VMODE_NONINTERLACED
,
47 static struct fb_fix_screeninfo vesafb_fix
= {
49 .type
= FB_TYPE_PACKED_PIXELS
,
50 .accel
= FB_ACCEL_NONE
,
53 static int inverse __read_mostly
;
54 static int mtrr __read_mostly
; /* disable mtrr */
55 static int vram_remap
; /* Set amount of memory to be used */
56 static int vram_total
; /* Set total amount of memory */
57 static int pmi_setpal __read_mostly
= 1; /* pmi for palette changes ??? */
58 static int ypan __read_mostly
; /* 0..nothing, 1..ypan, 2..ywrap */
59 static void (*pmi_start
)(void) __read_mostly
;
60 static void (*pmi_pal
) (void) __read_mostly
;
61 static int depth __read_mostly
;
62 static int vga_compat __read_mostly
;
63 /* --------------------------------------------------------------------- */
65 static int vesafb_pan_display(struct fb_var_screeninfo
*var
,
71 offset
= (var
->yoffset
* info
->fix
.line_length
+ var
->xoffset
) / 4;
75 : /* no return value */
76 : "a" (0x4f07), /* EAX */
78 "c" (offset
), /* ECX */
79 "d" (offset
>> 16), /* EDX */
80 "D" (&pmi_start
)); /* EDI */
85 static int vesa_setpalette(int regno
, unsigned red
, unsigned green
,
88 int shift
= 16 - depth
;
92 * Try VGA registers first...
95 outb_p(regno
, dac_reg
);
96 outb_p(red
>> shift
, dac_val
);
97 outb_p(green
>> shift
, dac_val
);
98 outb_p(blue
>> shift
, dac_val
);
104 * Fallback to the PMI....
106 if (err
&& pmi_setpal
) {
107 struct { u_char blue
, green
, red
, pad
; } entry
;
109 entry
.red
= red
>> shift
;
110 entry
.green
= green
>> shift
;
111 entry
.blue
= blue
>> shift
;
113 __asm__
__volatile__(
115 : /* no return value */
116 : "a" (0x4f09), /* EAX */
119 "d" (regno
), /* EDX */
120 "D" (&entry
), /* EDI */
121 "S" (&pmi_pal
)); /* ESI */
129 static int vesafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
130 unsigned blue
, unsigned transp
,
131 struct fb_info
*info
)
136 * Set a single color register. The values supplied are
137 * already rounded down to the hardware's capabilities
138 * (according to the entries in the `var' structure). Return
139 * != 0 for invalid regno.
142 if (regno
>= info
->cmap
.len
)
145 if (info
->var
.bits_per_pixel
== 8)
146 err
= vesa_setpalette(regno
,red
,green
,blue
);
147 else if (regno
< 16) {
148 switch (info
->var
.bits_per_pixel
) {
150 if (info
->var
.red
.offset
== 10) {
152 ((u32
*) (info
->pseudo_palette
))[regno
] =
153 ((red
& 0xf800) >> 1) |
154 ((green
& 0xf800) >> 6) |
155 ((blue
& 0xf800) >> 11);
158 ((u32
*) (info
->pseudo_palette
))[regno
] =
160 ((green
& 0xfc00) >> 5) |
161 ((blue
& 0xf800) >> 11);
169 ((u32
*)(info
->pseudo_palette
))[regno
] =
170 (red
<< info
->var
.red
.offset
) |
171 (green
<< info
->var
.green
.offset
) |
172 (blue
<< info
->var
.blue
.offset
);
180 static void vesafb_destroy(struct fb_info
*info
)
182 struct vesafb_par
*par
= info
->par
;
184 fb_dealloc_cmap(&info
->cmap
);
185 arch_phys_wc_del(par
->wc_cookie
);
186 if (info
->screen_base
)
187 iounmap(info
->screen_base
);
188 release_mem_region(info
->apertures
->ranges
[0].base
, info
->apertures
->ranges
[0].size
);
191 static struct fb_ops vesafb_ops
= {
192 .owner
= THIS_MODULE
,
193 .fb_destroy
= vesafb_destroy
,
194 .fb_setcolreg
= vesafb_setcolreg
,
195 .fb_pan_display
= vesafb_pan_display
,
196 .fb_fillrect
= cfb_fillrect
,
197 .fb_copyarea
= cfb_copyarea
,
198 .fb_imageblit
= cfb_imageblit
,
201 static int vesafb_setup(char *options
)
205 if (!options
|| !*options
)
208 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
209 if (!*this_opt
) continue;
211 if (! strcmp(this_opt
, "inverse"))
213 else if (! strcmp(this_opt
, "redraw"))
215 else if (! strcmp(this_opt
, "ypan"))
217 else if (! strcmp(this_opt
, "ywrap"))
219 else if (! strcmp(this_opt
, "vgapal"))
221 else if (! strcmp(this_opt
, "pmipal"))
223 else if (! strncmp(this_opt
, "mtrr:", 5))
224 mtrr
= simple_strtoul(this_opt
+5, NULL
, 0);
225 else if (! strcmp(this_opt
, "nomtrr"))
227 else if (! strncmp(this_opt
, "vtotal:", 7))
228 vram_total
= simple_strtoul(this_opt
+7, NULL
, 0);
229 else if (! strncmp(this_opt
, "vremap:", 7))
230 vram_remap
= simple_strtoul(this_opt
+7, NULL
, 0);
235 static int vesafb_probe(struct platform_device
*dev
)
237 struct fb_info
*info
;
238 struct vesafb_par
*par
;
240 unsigned int size_vmode
;
241 unsigned int size_remap
;
242 unsigned int size_total
;
245 /* ignore error return of fb_get_options */
246 fb_get_options("vesafb", &option
);
247 vesafb_setup(option
);
249 if (screen_info
.orig_video_isVGA
!= VIDEO_TYPE_VLFB
)
252 vga_compat
= (screen_info
.capabilities
& 2) ? 0 : 1;
253 vesafb_fix
.smem_start
= screen_info
.lfb_base
;
254 vesafb_defined
.bits_per_pixel
= screen_info
.lfb_depth
;
255 if (15 == vesafb_defined
.bits_per_pixel
)
256 vesafb_defined
.bits_per_pixel
= 16;
257 vesafb_defined
.xres
= screen_info
.lfb_width
;
258 vesafb_defined
.yres
= screen_info
.lfb_height
;
259 vesafb_fix
.line_length
= screen_info
.lfb_linelength
;
260 vesafb_fix
.visual
= (vesafb_defined
.bits_per_pixel
== 8) ?
261 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
263 /* size_vmode -- that is the amount of memory needed for the
264 * used video mode, i.e. the minimum amount of
266 size_vmode
= vesafb_defined
.yres
* vesafb_fix
.line_length
;
268 /* size_total -- all video memory we have. Used for mtrr
269 * entries, resource allocation and bounds
271 size_total
= screen_info
.lfb_size
* 65536;
273 size_total
= vram_total
* 1024 * 1024;
274 if (size_total
< size_vmode
)
275 size_total
= size_vmode
;
277 /* size_remap -- the amount of video memory we are going to
278 * use for vesafb. With modern cards it is no
279 * option to simply use size_total as that
280 * wastes plenty of kernel address space. */
281 size_remap
= size_vmode
* 2;
283 size_remap
= vram_remap
* 1024 * 1024;
284 if (size_remap
< size_vmode
)
285 size_remap
= size_vmode
;
286 if (size_remap
> size_total
)
287 size_remap
= size_total
;
288 vesafb_fix
.smem_len
= size_remap
;
291 screen_info
.vesapm_seg
= 0;
294 if (!request_mem_region(vesafb_fix
.smem_start
, size_total
, "vesafb")) {
296 "vesafb: cannot reserve video memory at 0x%lx\n",
297 vesafb_fix
.smem_start
);
298 /* We cannot make this fatal. Sometimes this comes from magic
299 spaces our resource handlers simply don't know about */
302 info
= framebuffer_alloc(sizeof(struct vesafb_par
), &dev
->dev
);
304 release_mem_region(vesafb_fix
.smem_start
, size_total
);
307 platform_set_drvdata(dev
, info
);
309 info
->pseudo_palette
= par
->pseudo_palette
;
311 /* set vesafb aperture size for generic probing */
312 info
->apertures
= alloc_apertures(1);
313 if (!info
->apertures
) {
317 info
->apertures
->ranges
[0].base
= screen_info
.lfb_base
;
318 info
->apertures
->ranges
[0].size
= size_total
;
320 printk(KERN_INFO
"vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
321 vesafb_defined
.xres
, vesafb_defined
.yres
, vesafb_defined
.bits_per_pixel
, vesafb_fix
.line_length
, screen_info
.pages
);
323 if (screen_info
.vesapm_seg
) {
324 printk(KERN_INFO
"vesafb: protected mode interface info at %04x:%04x\n",
325 screen_info
.vesapm_seg
,screen_info
.vesapm_off
);
328 if (screen_info
.vesapm_seg
< 0xc000)
329 ypan
= pmi_setpal
= 0; /* not available or some DOS TSR ... */
331 if (ypan
|| pmi_setpal
) {
332 unsigned short *pmi_base
;
333 pmi_base
= (unsigned short*)phys_to_virt(((unsigned long)screen_info
.vesapm_seg
<< 4) + screen_info
.vesapm_off
);
334 pmi_start
= (void*)((char*)pmi_base
+ pmi_base
[1]);
335 pmi_pal
= (void*)((char*)pmi_base
+ pmi_base
[2]);
336 printk(KERN_INFO
"vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start
,pmi_pal
);
338 printk(KERN_INFO
"vesafb: pmi: ports = ");
339 for (i
= pmi_base
[3]/2; pmi_base
[i
] != 0xffff; i
++)
340 printk("%x ",pmi_base
[i
]);
342 if (pmi_base
[i
] != 0xffff) {
344 * memory areas not supported (yet?)
346 * Rules are: we have to set up a descriptor for the requested
347 * memory area and pass it in the ES register to the BIOS function.
349 printk(KERN_INFO
"vesafb: can't handle memory requests, pmi disabled\n");
350 ypan
= pmi_setpal
= 0;
355 if (vesafb_defined
.bits_per_pixel
== 8 && !pmi_setpal
&& !vga_compat
) {
356 printk(KERN_WARNING
"vesafb: hardware palette is unchangeable,\n"
357 " colors may be incorrect\n");
358 vesafb_fix
.visual
= FB_VISUAL_STATIC_PSEUDOCOLOR
;
361 vesafb_defined
.xres_virtual
= vesafb_defined
.xres
;
362 vesafb_defined
.yres_virtual
= vesafb_fix
.smem_len
/ vesafb_fix
.line_length
;
363 if (ypan
&& vesafb_defined
.yres_virtual
> vesafb_defined
.yres
) {
364 printk(KERN_INFO
"vesafb: scrolling: %s using protected mode interface, yres_virtual=%d\n",
365 (ypan
> 1) ? "ywrap" : "ypan",vesafb_defined
.yres_virtual
);
367 printk(KERN_INFO
"vesafb: scrolling: redraw\n");
368 vesafb_defined
.yres_virtual
= vesafb_defined
.yres
;
372 /* some dummy values for timing to make fbset happy */
373 vesafb_defined
.pixclock
= 10000000 / vesafb_defined
.xres
* 1000 / vesafb_defined
.yres
;
374 vesafb_defined
.left_margin
= (vesafb_defined
.xres
/ 8) & 0xf8;
375 vesafb_defined
.hsync_len
= (vesafb_defined
.xres
/ 8) & 0xf8;
377 vesafb_defined
.red
.offset
= screen_info
.red_pos
;
378 vesafb_defined
.red
.length
= screen_info
.red_size
;
379 vesafb_defined
.green
.offset
= screen_info
.green_pos
;
380 vesafb_defined
.green
.length
= screen_info
.green_size
;
381 vesafb_defined
.blue
.offset
= screen_info
.blue_pos
;
382 vesafb_defined
.blue
.length
= screen_info
.blue_size
;
383 vesafb_defined
.transp
.offset
= screen_info
.rsvd_pos
;
384 vesafb_defined
.transp
.length
= screen_info
.rsvd_size
;
386 if (vesafb_defined
.bits_per_pixel
<= 8) {
387 depth
= vesafb_defined
.green
.length
;
388 vesafb_defined
.red
.length
=
389 vesafb_defined
.green
.length
=
390 vesafb_defined
.blue
.length
=
391 vesafb_defined
.bits_per_pixel
;
394 printk(KERN_INFO
"vesafb: %s: "
395 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
396 (vesafb_defined
.bits_per_pixel
> 8) ?
397 "Truecolor" : (vga_compat
|| pmi_setpal
) ?
398 "Pseudocolor" : "Static Pseudocolor",
399 screen_info
.rsvd_size
,
400 screen_info
.red_size
,
401 screen_info
.green_size
,
402 screen_info
.blue_size
,
403 screen_info
.rsvd_pos
,
405 screen_info
.green_pos
,
406 screen_info
.blue_pos
);
408 vesafb_fix
.ypanstep
= ypan
? 1 : 0;
409 vesafb_fix
.ywrapstep
= (ypan
>1) ? 1 : 0;
411 /* request failure does not faze us, as vgacon probably has this
412 * region already (FIXME) */
413 request_region(0x3c0, 32, "vesafb");
416 unsigned int temp_size
= size_total
;
418 /* Find the largest power-of-two */
419 temp_size
= roundup_pow_of_two(temp_size
);
421 /* Try and find a power of two to add */
424 arch_phys_wc_add(vesafb_fix
.smem_start
,
427 } while (temp_size
>= PAGE_SIZE
&& par
->wc_cookie
< 0);
429 info
->screen_base
= ioremap_wc(vesafb_fix
.smem_start
, vesafb_fix
.smem_len
);
431 if (mtrr
&& mtrr
!= 3)
432 WARN_ONCE(1, "Only MTRR_TYPE_WRCOMB (3) make sense\n");
433 info
->screen_base
= ioremap(vesafb_fix
.smem_start
, vesafb_fix
.smem_len
);
436 if (!info
->screen_base
) {
438 "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n",
439 vesafb_fix
.smem_len
, vesafb_fix
.smem_start
);
444 printk(KERN_INFO
"vesafb: framebuffer at 0x%lx, mapped to 0x%p, "
445 "using %dk, total %dk\n",
446 vesafb_fix
.smem_start
, info
->screen_base
,
447 size_remap
/1024, size_total
/1024);
449 info
->fbops
= &vesafb_ops
;
450 info
->var
= vesafb_defined
;
451 info
->fix
= vesafb_fix
;
452 info
->flags
= FBINFO_FLAG_DEFAULT
| FBINFO_MISC_FIRMWARE
|
453 (ypan
? FBINFO_HWACCEL_YPAN
: 0);
456 info
->fbops
->fb_pan_display
= NULL
;
458 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0) {
462 if (register_framebuffer(info
)<0) {
464 fb_dealloc_cmap(&info
->cmap
);
467 fb_info(info
, "%s frame buffer device\n", info
->fix
.id
);
470 arch_phys_wc_del(par
->wc_cookie
);
471 if (info
->screen_base
)
472 iounmap(info
->screen_base
);
473 framebuffer_release(info
);
474 release_mem_region(vesafb_fix
.smem_start
, size_total
);
478 static int vesafb_remove(struct platform_device
*pdev
)
480 struct fb_info
*info
= platform_get_drvdata(pdev
);
482 unregister_framebuffer(info
);
483 framebuffer_release(info
);
488 static struct platform_driver vesafb_driver
= {
490 .name
= "vesa-framebuffer",
492 .probe
= vesafb_probe
,
493 .remove
= vesafb_remove
,
496 module_platform_driver(vesafb_driver
);
497 MODULE_LICENSE("GPL");