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>
25 #define dac_reg (0x3c8)
26 #define dac_val (0x3c9)
28 /* --------------------------------------------------------------------- */
30 static struct fb_var_screeninfo vesafb_defined __initdata
= {
31 .activate
= FB_ACTIVATE_NOW
,
38 .vmode
= FB_VMODE_NONINTERLACED
,
41 static struct fb_fix_screeninfo vesafb_fix __initdata
= {
43 .type
= FB_TYPE_PACKED_PIXELS
,
44 .accel
= FB_ACCEL_NONE
,
47 static int inverse
= 0;
49 static int vram_remap __initdata
= 0; /* Set amount of memory to be used */
50 static int vram_total __initdata
= 0; /* Set total amount of memory */
51 static int pmi_setpal
= 0; /* pmi for palette changes ??? */
52 static int ypan
= 0; /* 0..nothing, 1..ypan, 2..ywrap */
53 static unsigned short *pmi_base
= NULL
;
54 static void (*pmi_start
)(void);
55 static void (*pmi_pal
)(void);
58 /* --------------------------------------------------------------------- */
60 static int vesafb_pan_display(struct fb_var_screeninfo
*var
,
70 if (var
->yoffset
> var
->yres_virtual
)
72 if ((ypan
==1) && var
->yoffset
+var
->yres
> var
->yres_virtual
)
75 offset
= (var
->yoffset
* info
->fix
.line_length
+ var
->xoffset
) / 4;
79 : /* no return value */
80 : "a" (0x4f07), /* EAX */
82 "c" (offset
), /* ECX */
83 "d" (offset
>> 16), /* EDX */
84 "D" (&pmi_start
)); /* EDI */
89 static void vesa_setpalette(int regno
, unsigned red
, unsigned green
,
93 struct { u_char blue
, green
, red
, pad
; } entry
;
94 int shift
= 16 - depth
;
97 entry
.red
= red
>> shift
;
98 entry
.green
= green
>> shift
;
99 entry
.blue
= blue
>> shift
;
101 __asm__
__volatile__(
103 : /* no return value */
104 : "a" (0x4f09), /* EAX */
107 "d" (regno
), /* EDX */
108 "D" (&entry
), /* EDI */
109 "S" (&pmi_pal
)); /* ESI */
111 /* without protected mode interface, try VGA registers... */
112 outb_p(regno
, dac_reg
);
113 outb_p(red
>> shift
, dac_val
);
114 outb_p(green
>> shift
, dac_val
);
115 outb_p(blue
>> shift
, dac_val
);
120 static int vesafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
121 unsigned blue
, unsigned transp
,
122 struct fb_info
*info
)
125 * Set a single color register. The values supplied are
126 * already rounded down to the hardware's capabilities
127 * (according to the entries in the `var' structure). Return
128 * != 0 for invalid regno.
131 if (regno
>= info
->cmap
.len
)
134 switch (info
->var
.bits_per_pixel
) {
136 vesa_setpalette(regno
,red
,green
,blue
);
139 if (info
->var
.red
.offset
== 10) {
141 ((u32
*) (info
->pseudo_palette
))[regno
] =
142 ((red
& 0xf800) >> 1) |
143 ((green
& 0xf800) >> 6) |
144 ((blue
& 0xf800) >> 11);
147 ((u32
*) (info
->pseudo_palette
))[regno
] =
149 ((green
& 0xfc00) >> 5) |
150 ((blue
& 0xf800) >> 11);
157 ((u32
*)(info
->pseudo_palette
))[regno
] =
158 (red
<< info
->var
.red
.offset
) |
159 (green
<< info
->var
.green
.offset
) |
160 (blue
<< info
->var
.blue
.offset
);
166 ((u32
*)(info
->pseudo_palette
))[regno
] =
167 (red
<< info
->var
.red
.offset
) |
168 (green
<< info
->var
.green
.offset
) |
169 (blue
<< info
->var
.blue
.offset
);
175 static struct fb_ops vesafb_ops
= {
176 .owner
= THIS_MODULE
,
177 .fb_setcolreg
= vesafb_setcolreg
,
178 .fb_pan_display
= vesafb_pan_display
,
179 .fb_fillrect
= cfb_fillrect
,
180 .fb_copyarea
= cfb_copyarea
,
181 .fb_imageblit
= cfb_imageblit
,
182 .fb_cursor
= soft_cursor
,
185 static int __init
vesafb_setup(char *options
)
189 if (!options
|| !*options
)
192 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
193 if (!*this_opt
) continue;
195 if (! strcmp(this_opt
, "inverse"))
197 else if (! strcmp(this_opt
, "redraw"))
199 else if (! strcmp(this_opt
, "ypan"))
201 else if (! strcmp(this_opt
, "ywrap"))
203 else if (! strcmp(this_opt
, "vgapal"))
205 else if (! strcmp(this_opt
, "pmipal"))
207 else if (! strcmp(this_opt
, "mtrr"))
209 else if (! strcmp(this_opt
, "nomtrr"))
211 else if (! strncmp(this_opt
, "vtotal:", 7))
212 vram_total
= simple_strtoul(this_opt
+7, NULL
, 0);
213 else if (! strncmp(this_opt
, "vremap:", 7))
214 vram_remap
= simple_strtoul(this_opt
+7, NULL
, 0);
219 static int __init
vesafb_probe(struct device
*device
)
221 struct platform_device
*dev
= to_platform_device(device
);
222 struct fb_info
*info
;
224 unsigned int size_vmode
;
225 unsigned int size_remap
;
226 unsigned int size_total
;
228 if (screen_info
.orig_video_isVGA
!= VIDEO_TYPE_VLFB
)
231 vesafb_fix
.smem_start
= screen_info
.lfb_base
;
232 vesafb_defined
.bits_per_pixel
= screen_info
.lfb_depth
;
233 if (15 == vesafb_defined
.bits_per_pixel
)
234 vesafb_defined
.bits_per_pixel
= 16;
235 vesafb_defined
.xres
= screen_info
.lfb_width
;
236 vesafb_defined
.yres
= screen_info
.lfb_height
;
237 vesafb_fix
.line_length
= screen_info
.lfb_linelength
;
238 vesafb_fix
.visual
= (vesafb_defined
.bits_per_pixel
== 8) ?
239 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
241 /* size_vmode -- that is the amount of memory needed for the
242 * used video mode, i.e. the minimum amount of
244 size_vmode
= vesafb_defined
.yres
* vesafb_fix
.line_length
;
246 /* size_total -- all video memory we have. Used for mtrr
247 * entries, ressource allocation and bounds
249 size_total
= screen_info
.lfb_size
* 65536;
251 size_total
= vram_total
* 1024 * 1024;
252 if (size_total
< size_vmode
)
253 size_total
= size_vmode
;
255 /* size_remap -- the amount of video memory we are going to
256 * use for vesafb. With modern cards it is no
257 * option to simply use size_total as that
258 * wastes plenty of kernel address space. */
259 size_remap
= size_vmode
* 2;
261 size_remap
= vram_remap
* 1024 * 1024;
262 if (size_remap
< size_vmode
)
263 size_remap
= size_vmode
;
264 if (size_remap
> size_total
)
265 size_remap
= size_total
;
266 vesafb_fix
.smem_len
= size_remap
;
269 screen_info
.vesapm_seg
= 0;
272 if (!request_mem_region(vesafb_fix
.smem_start
, size_total
, "vesafb")) {
274 "vesafb: abort, cannot reserve video memory at 0x%lx\n",
275 vesafb_fix
.smem_start
);
276 /* We cannot make this fatal. Sometimes this comes from magic
277 spaces our resource handlers simply don't know about */
280 info
= framebuffer_alloc(sizeof(u32
) * 256, &dev
->dev
);
282 release_mem_region(vesafb_fix
.smem_start
, vesafb_fix
.smem_len
);
285 info
->pseudo_palette
= info
->par
;
288 info
->screen_base
= ioremap(vesafb_fix
.smem_start
, vesafb_fix
.smem_len
);
289 if (!info
->screen_base
) {
291 "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n",
292 vesafb_fix
.smem_len
, vesafb_fix
.smem_start
);
297 printk(KERN_INFO
"vesafb: framebuffer at 0x%lx, mapped to 0x%p, "
298 "using %dk, total %dk\n",
299 vesafb_fix
.smem_start
, info
->screen_base
,
300 size_remap
/1024, size_total
/1024);
301 printk(KERN_INFO
"vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
302 vesafb_defined
.xres
, vesafb_defined
.yres
, vesafb_defined
.bits_per_pixel
, vesafb_fix
.line_length
, screen_info
.pages
);
304 if (screen_info
.vesapm_seg
) {
305 printk(KERN_INFO
"vesafb: protected mode interface info at %04x:%04x\n",
306 screen_info
.vesapm_seg
,screen_info
.vesapm_off
);
309 if (screen_info
.vesapm_seg
< 0xc000)
310 ypan
= pmi_setpal
= 0; /* not available or some DOS TSR ... */
312 if (ypan
|| pmi_setpal
) {
313 pmi_base
= (unsigned short*)phys_to_virt(((unsigned long)screen_info
.vesapm_seg
<< 4) + screen_info
.vesapm_off
);
314 pmi_start
= (void*)((char*)pmi_base
+ pmi_base
[1]);
315 pmi_pal
= (void*)((char*)pmi_base
+ pmi_base
[2]);
316 printk(KERN_INFO
"vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start
,pmi_pal
);
318 printk(KERN_INFO
"vesafb: pmi: ports = ");
319 for (i
= pmi_base
[3]/2; pmi_base
[i
] != 0xffff; i
++)
320 printk("%x ",pmi_base
[i
]);
322 if (pmi_base
[i
] != 0xffff) {
324 * memory areas not supported (yet?)
326 * Rules are: we have to set up a descriptor for the requested
327 * memory area and pass it in the ES register to the BIOS function.
329 printk(KERN_INFO
"vesafb: can't handle memory requests, pmi disabled\n");
330 ypan
= pmi_setpal
= 0;
335 vesafb_defined
.xres_virtual
= vesafb_defined
.xres
;
336 vesafb_defined
.yres_virtual
= vesafb_fix
.smem_len
/ vesafb_fix
.line_length
;
337 if (ypan
&& vesafb_defined
.yres_virtual
> vesafb_defined
.yres
) {
338 printk(KERN_INFO
"vesafb: scrolling: %s using protected mode interface, yres_virtual=%d\n",
339 (ypan
> 1) ? "ywrap" : "ypan",vesafb_defined
.yres_virtual
);
341 printk(KERN_INFO
"vesafb: scrolling: redraw\n");
342 vesafb_defined
.yres_virtual
= vesafb_defined
.yres
;
346 /* some dummy values for timing to make fbset happy */
347 vesafb_defined
.pixclock
= 10000000 / vesafb_defined
.xres
* 1000 / vesafb_defined
.yres
;
348 vesafb_defined
.left_margin
= (vesafb_defined
.xres
/ 8) & 0xf8;
349 vesafb_defined
.hsync_len
= (vesafb_defined
.xres
/ 8) & 0xf8;
351 vesafb_defined
.red
.offset
= screen_info
.red_pos
;
352 vesafb_defined
.red
.length
= screen_info
.red_size
;
353 vesafb_defined
.green
.offset
= screen_info
.green_pos
;
354 vesafb_defined
.green
.length
= screen_info
.green_size
;
355 vesafb_defined
.blue
.offset
= screen_info
.blue_pos
;
356 vesafb_defined
.blue
.length
= screen_info
.blue_size
;
357 vesafb_defined
.transp
.offset
= screen_info
.rsvd_pos
;
358 vesafb_defined
.transp
.length
= screen_info
.rsvd_size
;
360 if (vesafb_defined
.bits_per_pixel
<= 8) {
361 depth
= vesafb_defined
.green
.length
;
362 vesafb_defined
.red
.length
=
363 vesafb_defined
.green
.length
=
364 vesafb_defined
.blue
.length
=
365 vesafb_defined
.bits_per_pixel
;
368 printk(KERN_INFO
"vesafb: %s: "
369 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
370 (vesafb_defined
.bits_per_pixel
> 8) ?
371 "Truecolor" : "Pseudocolor",
372 screen_info
.rsvd_size
,
373 screen_info
.red_size
,
374 screen_info
.green_size
,
375 screen_info
.blue_size
,
376 screen_info
.rsvd_pos
,
378 screen_info
.green_pos
,
379 screen_info
.blue_pos
);
381 vesafb_fix
.ypanstep
= ypan
? 1 : 0;
382 vesafb_fix
.ywrapstep
= (ypan
>1) ? 1 : 0;
384 /* request failure does not faze us, as vgacon probably has this
385 * region already (FIXME) */
386 request_region(0x3c0, 32, "vesafb");
389 int temp_size
= size_total
;
390 /* Find the largest power-of-two */
391 while (temp_size
& (temp_size
- 1))
392 temp_size
&= (temp_size
- 1);
394 /* Try and find a power of two to add */
395 while (temp_size
&& mtrr_add(vesafb_fix
.smem_start
, temp_size
, MTRR_TYPE_WRCOMB
, 1)==-EINVAL
) {
400 info
->fbops
= &vesafb_ops
;
401 info
->var
= vesafb_defined
;
402 info
->fix
= vesafb_fix
;
403 info
->flags
= FBINFO_FLAG_DEFAULT
|
404 (ypan
) ? FBINFO_HWACCEL_YPAN
: 0;
406 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0) {
410 if (register_framebuffer(info
)<0) {
412 fb_dealloc_cmap(&info
->cmap
);
415 printk(KERN_INFO
"fb%d: %s frame buffer device\n",
416 info
->node
, info
->fix
.id
);
419 framebuffer_release(info
);
420 release_mem_region(vesafb_fix
.smem_start
, size_total
);
424 static struct device_driver vesafb_driver
= {
426 .bus
= &platform_bus_type
,
427 .probe
= vesafb_probe
,
430 static struct platform_device vesafb_device
= {
434 static int __init
vesafb_init(void)
439 /* ignore error return of fb_get_options */
440 fb_get_options("vesafb", &option
);
441 vesafb_setup(option
);
442 ret
= driver_register(&vesafb_driver
);
445 ret
= platform_device_register(&vesafb_device
);
447 driver_unregister(&vesafb_driver
);
451 module_init(vesafb_init
);
453 MODULE_LICENSE("GPL");