Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * framebuffer driver for VBE 2.0 compliant graphic boards |
| 3 | * |
| 4 | * switching to graphics mode happens at boot time (while |
| 5 | * running in real mode, see arch/i386/boot/video.S). |
| 6 | * |
| 7 | * (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de> |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/string.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/tty.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/fb.h> |
| 20 | #include <linux/ioport.h> |
| 21 | #include <linux/init.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
| 23 | |
Antonino A. Daplas | d2d5838 | 2005-09-09 13:04:31 -0700 | [diff] [blame] | 24 | #include <video/vga.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/io.h> |
| 26 | #include <asm/mtrr.h> |
| 27 | |
| 28 | #define dac_reg (0x3c8) |
| 29 | #define dac_val (0x3c9) |
| 30 | |
| 31 | /* --------------------------------------------------------------------- */ |
| 32 | |
| 33 | static struct fb_var_screeninfo vesafb_defined __initdata = { |
| 34 | .activate = FB_ACTIVATE_NOW, |
| 35 | .height = -1, |
| 36 | .width = -1, |
| 37 | .right_margin = 32, |
| 38 | .upper_margin = 16, |
| 39 | .lower_margin = 4, |
| 40 | .vsync_len = 4, |
| 41 | .vmode = FB_VMODE_NONINTERLACED, |
| 42 | }; |
| 43 | |
| 44 | static struct fb_fix_screeninfo vesafb_fix __initdata = { |
| 45 | .id = "VESA VGA", |
| 46 | .type = FB_TYPE_PACKED_PIXELS, |
| 47 | .accel = FB_ACCEL_NONE, |
| 48 | }; |
| 49 | |
| 50 | static int inverse = 0; |
Antonino A. Daplas | 8a0934f | 2005-11-07 01:00:49 -0800 | [diff] [blame] | 51 | static int mtrr = 0; /* disable mtrr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static int vram_remap __initdata = 0; /* Set amount of memory to be used */ |
| 53 | static int vram_total __initdata = 0; /* Set total amount of memory */ |
| 54 | static int pmi_setpal = 0; /* pmi for palette changes ??? */ |
| 55 | static int ypan = 0; /* 0..nothing, 1..ypan, 2..ywrap */ |
| 56 | static unsigned short *pmi_base = NULL; |
| 57 | static void (*pmi_start)(void); |
| 58 | static void (*pmi_pal)(void); |
| 59 | static int depth; |
Antonino A. Daplas | d2d5838 | 2005-09-09 13:04:31 -0700 | [diff] [blame] | 60 | static int vga_compat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | /* --------------------------------------------------------------------- */ |
| 63 | |
| 64 | static int vesafb_pan_display(struct fb_var_screeninfo *var, |
| 65 | struct fb_info *info) |
| 66 | { |
| 67 | #ifdef __i386__ |
| 68 | int offset; |
| 69 | |
| 70 | if (!ypan) |
| 71 | return -EINVAL; |
| 72 | if (var->xoffset) |
| 73 | return -EINVAL; |
| 74 | if (var->yoffset > var->yres_virtual) |
| 75 | return -EINVAL; |
| 76 | if ((ypan==1) && var->yoffset+var->yres > var->yres_virtual) |
| 77 | return -EINVAL; |
| 78 | |
| 79 | offset = (var->yoffset * info->fix.line_length + var->xoffset) / 4; |
| 80 | |
| 81 | __asm__ __volatile__( |
| 82 | "call *(%%edi)" |
| 83 | : /* no return value */ |
| 84 | : "a" (0x4f07), /* EAX */ |
| 85 | "b" (0), /* EBX */ |
| 86 | "c" (offset), /* ECX */ |
| 87 | "d" (offset >> 16), /* EDX */ |
| 88 | "D" (&pmi_start)); /* EDI */ |
| 89 | #endif |
| 90 | return 0; |
| 91 | } |
| 92 | |
Antonino A. Daplas | d2d5838 | 2005-09-09 13:04:31 -0700 | [diff] [blame] | 93 | static int vesafb_blank(int blank, struct fb_info *info) |
| 94 | { |
| 95 | int err = 1; |
| 96 | |
| 97 | if (vga_compat) { |
| 98 | int loop = 10000; |
| 99 | u8 seq = 0, crtc17 = 0; |
| 100 | |
Antonino A. Daplas | bb7e257 | 2005-10-18 15:59:52 +0800 | [diff] [blame] | 101 | if (blank == FB_BLANK_POWERDOWN) { |
Antonino A. Daplas | d2d5838 | 2005-09-09 13:04:31 -0700 | [diff] [blame] | 102 | seq = 0x20; |
| 103 | crtc17 = 0x00; |
Antonino A. Daplas | bb7e257 | 2005-10-18 15:59:52 +0800 | [diff] [blame] | 104 | err = 0; |
Antonino A. Daplas | d2d5838 | 2005-09-09 13:04:31 -0700 | [diff] [blame] | 105 | } else { |
| 106 | seq = 0x00; |
| 107 | crtc17 = 0x80; |
Antonino A. Daplas | bb7e257 | 2005-10-18 15:59:52 +0800 | [diff] [blame] | 108 | err = (blank == FB_BLANK_UNBLANK) ? 0 : -EINVAL; |
Antonino A. Daplas | d2d5838 | 2005-09-09 13:04:31 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | vga_wseq(NULL, 0x00, 0x01); |
| 112 | seq |= vga_rseq(NULL, 0x01) & ~0x20; |
| 113 | vga_wseq(NULL, 0x00, seq); |
| 114 | |
| 115 | crtc17 |= vga_rcrt(NULL, 0x17) & ~0x80; |
| 116 | while (loop--); |
| 117 | vga_wcrt(NULL, 0x17, crtc17); |
| 118 | vga_wseq(NULL, 0x00, 0x03); |
| 119 | } |
| 120 | |
| 121 | return err; |
| 122 | } |
| 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | static void vesa_setpalette(int regno, unsigned red, unsigned green, |
| 125 | unsigned blue) |
| 126 | { |
| 127 | #ifdef __i386__ |
| 128 | struct { u_char blue, green, red, pad; } entry; |
| 129 | int shift = 16 - depth; |
| 130 | |
| 131 | if (pmi_setpal) { |
| 132 | entry.red = red >> shift; |
| 133 | entry.green = green >> shift; |
| 134 | entry.blue = blue >> shift; |
| 135 | entry.pad = 0; |
| 136 | __asm__ __volatile__( |
| 137 | "call *(%%esi)" |
| 138 | : /* no return value */ |
| 139 | : "a" (0x4f09), /* EAX */ |
| 140 | "b" (0), /* EBX */ |
| 141 | "c" (1), /* ECX */ |
| 142 | "d" (regno), /* EDX */ |
| 143 | "D" (&entry), /* EDI */ |
| 144 | "S" (&pmi_pal)); /* ESI */ |
| 145 | } else { |
| 146 | /* without protected mode interface, try VGA registers... */ |
| 147 | outb_p(regno, dac_reg); |
| 148 | outb_p(red >> shift, dac_val); |
| 149 | outb_p(green >> shift, dac_val); |
| 150 | outb_p(blue >> shift, dac_val); |
| 151 | } |
| 152 | #endif |
| 153 | } |
| 154 | |
| 155 | static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 156 | unsigned blue, unsigned transp, |
| 157 | struct fb_info *info) |
| 158 | { |
| 159 | /* |
| 160 | * Set a single color register. The values supplied are |
| 161 | * already rounded down to the hardware's capabilities |
| 162 | * (according to the entries in the `var' structure). Return |
| 163 | * != 0 for invalid regno. |
| 164 | */ |
| 165 | |
| 166 | if (regno >= info->cmap.len) |
| 167 | return 1; |
| 168 | |
Antonino A. Daplas | eba5085 | 2005-11-07 01:00:40 -0800 | [diff] [blame] | 169 | if (info->var.bits_per_pixel == 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | vesa_setpalette(regno,red,green,blue); |
Antonino A. Daplas | eba5085 | 2005-11-07 01:00:40 -0800 | [diff] [blame] | 171 | else if (regno < 16) { |
| 172 | switch (info->var.bits_per_pixel) { |
| 173 | case 16: |
| 174 | if (info->var.red.offset == 10) { |
| 175 | /* 1:5:5:5 */ |
| 176 | ((u32*) (info->pseudo_palette))[regno] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | ((red & 0xf800) >> 1) | |
| 178 | ((green & 0xf800) >> 6) | |
| 179 | ((blue & 0xf800) >> 11); |
Antonino A. Daplas | eba5085 | 2005-11-07 01:00:40 -0800 | [diff] [blame] | 180 | } else { |
| 181 | /* 0:5:6:5 */ |
| 182 | ((u32*) (info->pseudo_palette))[regno] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | ((red & 0xf800) ) | |
| 184 | ((green & 0xfc00) >> 5) | |
| 185 | ((blue & 0xf800) >> 11); |
Antonino A. Daplas | eba5085 | 2005-11-07 01:00:40 -0800 | [diff] [blame] | 186 | } |
| 187 | break; |
| 188 | case 24: |
| 189 | case 32: |
| 190 | red >>= 8; |
| 191 | green >>= 8; |
| 192 | blue >>= 8; |
| 193 | ((u32 *)(info->pseudo_palette))[regno] = |
| 194 | (red << info->var.red.offset) | |
| 195 | (green << info->var.green.offset) | |
| 196 | (blue << info->var.blue.offset); |
| 197 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
Antonino A. Daplas | eba5085 | 2005-11-07 01:00:40 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static struct fb_ops vesafb_ops = { |
| 205 | .owner = THIS_MODULE, |
| 206 | .fb_setcolreg = vesafb_setcolreg, |
| 207 | .fb_pan_display = vesafb_pan_display, |
Antonino A. Daplas | d2d5838 | 2005-09-09 13:04:31 -0700 | [diff] [blame] | 208 | .fb_blank = vesafb_blank, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | .fb_fillrect = cfb_fillrect, |
| 210 | .fb_copyarea = cfb_copyarea, |
| 211 | .fb_imageblit = cfb_imageblit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | static int __init vesafb_setup(char *options) |
| 215 | { |
| 216 | char *this_opt; |
| 217 | |
| 218 | if (!options || !*options) |
| 219 | return 0; |
| 220 | |
| 221 | while ((this_opt = strsep(&options, ",")) != NULL) { |
| 222 | if (!*this_opt) continue; |
| 223 | |
| 224 | if (! strcmp(this_opt, "inverse")) |
| 225 | inverse=1; |
| 226 | else if (! strcmp(this_opt, "redraw")) |
| 227 | ypan=0; |
| 228 | else if (! strcmp(this_opt, "ypan")) |
| 229 | ypan=1; |
| 230 | else if (! strcmp(this_opt, "ywrap")) |
| 231 | ypan=2; |
| 232 | else if (! strcmp(this_opt, "vgapal")) |
| 233 | pmi_setpal=0; |
| 234 | else if (! strcmp(this_opt, "pmipal")) |
| 235 | pmi_setpal=1; |
Antonino A. Daplas | 8062594 | 2005-07-29 14:03:31 -0700 | [diff] [blame] | 236 | else if (! strncmp(this_opt, "mtrr:", 5)) |
| 237 | mtrr = simple_strtoul(this_opt+5, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | else if (! strcmp(this_opt, "nomtrr")) |
| 239 | mtrr=0; |
| 240 | else if (! strncmp(this_opt, "vtotal:", 7)) |
| 241 | vram_total = simple_strtoul(this_opt+7, NULL, 0); |
| 242 | else if (! strncmp(this_opt, "vremap:", 7)) |
| 243 | vram_remap = simple_strtoul(this_opt+7, NULL, 0); |
| 244 | } |
| 245 | return 0; |
| 246 | } |
| 247 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame^] | 248 | static int __init vesafb_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | struct fb_info *info; |
| 251 | int i, err; |
| 252 | unsigned int size_vmode; |
| 253 | unsigned int size_remap; |
| 254 | unsigned int size_total; |
| 255 | |
| 256 | if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) |
| 257 | return -ENODEV; |
| 258 | |
| 259 | vesafb_fix.smem_start = screen_info.lfb_base; |
| 260 | vesafb_defined.bits_per_pixel = screen_info.lfb_depth; |
| 261 | if (15 == vesafb_defined.bits_per_pixel) |
| 262 | vesafb_defined.bits_per_pixel = 16; |
| 263 | vesafb_defined.xres = screen_info.lfb_width; |
| 264 | vesafb_defined.yres = screen_info.lfb_height; |
| 265 | vesafb_fix.line_length = screen_info.lfb_linelength; |
| 266 | vesafb_fix.visual = (vesafb_defined.bits_per_pixel == 8) ? |
| 267 | FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
| 268 | |
| 269 | /* size_vmode -- that is the amount of memory needed for the |
| 270 | * used video mode, i.e. the minimum amount of |
| 271 | * memory we need. */ |
| 272 | size_vmode = vesafb_defined.yres * vesafb_fix.line_length; |
| 273 | |
| 274 | /* size_total -- all video memory we have. Used for mtrr |
| 275 | * entries, ressource allocation and bounds |
| 276 | * checking. */ |
| 277 | size_total = screen_info.lfb_size * 65536; |
| 278 | if (vram_total) |
| 279 | size_total = vram_total * 1024 * 1024; |
| 280 | if (size_total < size_vmode) |
| 281 | size_total = size_vmode; |
| 282 | |
| 283 | /* size_remap -- the amount of video memory we are going to |
| 284 | * use for vesafb. With modern cards it is no |
| 285 | * option to simply use size_total as that |
| 286 | * wastes plenty of kernel address space. */ |
| 287 | size_remap = size_vmode * 2; |
| 288 | if (vram_remap) |
| 289 | size_remap = vram_remap * 1024 * 1024; |
| 290 | if (size_remap < size_vmode) |
| 291 | size_remap = size_vmode; |
| 292 | if (size_remap > size_total) |
| 293 | size_remap = size_total; |
| 294 | vesafb_fix.smem_len = size_remap; |
| 295 | |
| 296 | #ifndef __i386__ |
| 297 | screen_info.vesapm_seg = 0; |
| 298 | #endif |
| 299 | |
| 300 | if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) { |
| 301 | printk(KERN_WARNING |
Gerd Knorr | 78c0371 | 2005-06-21 17:16:56 -0700 | [diff] [blame] | 302 | "vesafb: cannot reserve video memory at 0x%lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | vesafb_fix.smem_start); |
| 304 | /* We cannot make this fatal. Sometimes this comes from magic |
| 305 | spaces our resource handlers simply don't know about */ |
| 306 | } |
| 307 | |
| 308 | info = framebuffer_alloc(sizeof(u32) * 256, &dev->dev); |
| 309 | if (!info) { |
Gerd Knorr | 78c0371 | 2005-06-21 17:16:56 -0700 | [diff] [blame] | 310 | release_mem_region(vesafb_fix.smem_start, size_total); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | return -ENOMEM; |
| 312 | } |
| 313 | info->pseudo_palette = info->par; |
| 314 | info->par = NULL; |
| 315 | |
Gerd Knorr | 78c0371 | 2005-06-21 17:16:56 -0700 | [diff] [blame] | 316 | info->screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if (!info->screen_base) { |
| 318 | printk(KERN_ERR |
| 319 | "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n", |
| 320 | vesafb_fix.smem_len, vesafb_fix.smem_start); |
| 321 | err = -EIO; |
| 322 | goto err; |
| 323 | } |
| 324 | |
| 325 | printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, " |
| 326 | "using %dk, total %dk\n", |
| 327 | vesafb_fix.smem_start, info->screen_base, |
| 328 | size_remap/1024, size_total/1024); |
| 329 | printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n", |
| 330 | vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages); |
| 331 | |
| 332 | if (screen_info.vesapm_seg) { |
| 333 | printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n", |
| 334 | screen_info.vesapm_seg,screen_info.vesapm_off); |
| 335 | } |
| 336 | |
| 337 | if (screen_info.vesapm_seg < 0xc000) |
| 338 | ypan = pmi_setpal = 0; /* not available or some DOS TSR ... */ |
| 339 | |
| 340 | if (ypan || pmi_setpal) { |
| 341 | pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off); |
| 342 | pmi_start = (void*)((char*)pmi_base + pmi_base[1]); |
| 343 | pmi_pal = (void*)((char*)pmi_base + pmi_base[2]); |
| 344 | printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal); |
| 345 | if (pmi_base[3]) { |
| 346 | printk(KERN_INFO "vesafb: pmi: ports = "); |
| 347 | for (i = pmi_base[3]/2; pmi_base[i] != 0xffff; i++) |
| 348 | printk("%x ",pmi_base[i]); |
| 349 | printk("\n"); |
| 350 | if (pmi_base[i] != 0xffff) { |
| 351 | /* |
| 352 | * memory areas not supported (yet?) |
| 353 | * |
| 354 | * Rules are: we have to set up a descriptor for the requested |
| 355 | * memory area and pass it in the ES register to the BIOS function. |
| 356 | */ |
| 357 | printk(KERN_INFO "vesafb: can't handle memory requests, pmi disabled\n"); |
| 358 | ypan = pmi_setpal = 0; |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | vesafb_defined.xres_virtual = vesafb_defined.xres; |
| 364 | vesafb_defined.yres_virtual = vesafb_fix.smem_len / vesafb_fix.line_length; |
| 365 | if (ypan && vesafb_defined.yres_virtual > vesafb_defined.yres) { |
| 366 | printk(KERN_INFO "vesafb: scrolling: %s using protected mode interface, yres_virtual=%d\n", |
| 367 | (ypan > 1) ? "ywrap" : "ypan",vesafb_defined.yres_virtual); |
| 368 | } else { |
| 369 | printk(KERN_INFO "vesafb: scrolling: redraw\n"); |
| 370 | vesafb_defined.yres_virtual = vesafb_defined.yres; |
| 371 | ypan = 0; |
| 372 | } |
| 373 | |
| 374 | /* some dummy values for timing to make fbset happy */ |
| 375 | vesafb_defined.pixclock = 10000000 / vesafb_defined.xres * 1000 / vesafb_defined.yres; |
| 376 | vesafb_defined.left_margin = (vesafb_defined.xres / 8) & 0xf8; |
| 377 | vesafb_defined.hsync_len = (vesafb_defined.xres / 8) & 0xf8; |
| 378 | |
| 379 | vesafb_defined.red.offset = screen_info.red_pos; |
| 380 | vesafb_defined.red.length = screen_info.red_size; |
| 381 | vesafb_defined.green.offset = screen_info.green_pos; |
| 382 | vesafb_defined.green.length = screen_info.green_size; |
| 383 | vesafb_defined.blue.offset = screen_info.blue_pos; |
| 384 | vesafb_defined.blue.length = screen_info.blue_size; |
| 385 | vesafb_defined.transp.offset = screen_info.rsvd_pos; |
| 386 | vesafb_defined.transp.length = screen_info.rsvd_size; |
| 387 | |
| 388 | if (vesafb_defined.bits_per_pixel <= 8) { |
| 389 | depth = vesafb_defined.green.length; |
| 390 | vesafb_defined.red.length = |
| 391 | vesafb_defined.green.length = |
| 392 | vesafb_defined.blue.length = |
| 393 | vesafb_defined.bits_per_pixel; |
| 394 | } |
| 395 | |
| 396 | printk(KERN_INFO "vesafb: %s: " |
| 397 | "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n", |
| 398 | (vesafb_defined.bits_per_pixel > 8) ? |
| 399 | "Truecolor" : "Pseudocolor", |
| 400 | screen_info.rsvd_size, |
| 401 | screen_info.red_size, |
| 402 | screen_info.green_size, |
| 403 | screen_info.blue_size, |
| 404 | screen_info.rsvd_pos, |
| 405 | screen_info.red_pos, |
| 406 | screen_info.green_pos, |
| 407 | screen_info.blue_pos); |
| 408 | |
| 409 | vesafb_fix.ypanstep = ypan ? 1 : 0; |
| 410 | vesafb_fix.ywrapstep = (ypan>1) ? 1 : 0; |
| 411 | |
| 412 | /* request failure does not faze us, as vgacon probably has this |
| 413 | * region already (FIXME) */ |
| 414 | request_region(0x3c0, 32, "vesafb"); |
| 415 | |
| 416 | if (mtrr) { |
Gerd Knorr | 78c0371 | 2005-06-21 17:16:56 -0700 | [diff] [blame] | 417 | unsigned int temp_size = size_total; |
Antonino A. Daplas | 8062594 | 2005-07-29 14:03:31 -0700 | [diff] [blame] | 418 | unsigned int type = 0; |
Dave Jones | d7496cb | 2005-06-25 14:58:30 -0700 | [diff] [blame] | 419 | |
Antonino A. Daplas | 8062594 | 2005-07-29 14:03:31 -0700 | [diff] [blame] | 420 | switch (mtrr) { |
| 421 | case 1: |
| 422 | type = MTRR_TYPE_UNCACHABLE; |
| 423 | break; |
| 424 | case 2: |
| 425 | type = MTRR_TYPE_WRBACK; |
| 426 | break; |
| 427 | case 3: |
| 428 | type = MTRR_TYPE_WRCOMB; |
| 429 | break; |
| 430 | case 4: |
| 431 | type = MTRR_TYPE_WRTHROUGH; |
| 432 | break; |
| 433 | default: |
| 434 | type = 0; |
| 435 | break; |
| 436 | } |
| 437 | |
| 438 | if (type) { |
| 439 | int rc; |
| 440 | |
| 441 | /* Find the largest power-of-two */ |
| 442 | while (temp_size & (temp_size - 1)) |
| 443 | temp_size &= (temp_size - 1); |
| 444 | |
| 445 | /* Try and find a power of two to add */ |
| 446 | do { |
| 447 | rc = mtrr_add(vesafb_fix.smem_start, temp_size, |
| 448 | type, 1); |
| 449 | temp_size >>= 1; |
| 450 | } while (temp_size >= PAGE_SIZE && rc == -EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | |
| 454 | info->fbops = &vesafb_ops; |
| 455 | info->var = vesafb_defined; |
| 456 | info->fix = vesafb_fix; |
| 457 | info->flags = FBINFO_FLAG_DEFAULT | |
| 458 | (ypan) ? FBINFO_HWACCEL_YPAN : 0; |
| 459 | |
Antonino A. Daplas | d2d5838 | 2005-09-09 13:04:31 -0700 | [diff] [blame] | 460 | vga_compat = (screen_info.capabilities & 2) ? 0 : 1; |
| 461 | printk("vesafb: Mode is %sVGA compatible\n", |
| 462 | (vga_compat) ? "" : "not "); |
| 463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { |
| 465 | err = -ENOMEM; |
| 466 | goto err; |
| 467 | } |
| 468 | if (register_framebuffer(info)<0) { |
| 469 | err = -EINVAL; |
| 470 | fb_dealloc_cmap(&info->cmap); |
| 471 | goto err; |
| 472 | } |
| 473 | printk(KERN_INFO "fb%d: %s frame buffer device\n", |
| 474 | info->node, info->fix.id); |
| 475 | return 0; |
| 476 | err: |
| 477 | framebuffer_release(info); |
| 478 | release_mem_region(vesafb_fix.smem_start, size_total); |
| 479 | return err; |
| 480 | } |
| 481 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame^] | 482 | static struct platform_driver vesafb_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | .probe = vesafb_probe, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame^] | 484 | .driver = { |
| 485 | .name = "vesafb", |
| 486 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | }; |
| 488 | |
| 489 | static struct platform_device vesafb_device = { |
| 490 | .name = "vesafb", |
| 491 | }; |
| 492 | |
| 493 | static int __init vesafb_init(void) |
| 494 | { |
| 495 | int ret; |
| 496 | char *option = NULL; |
| 497 | |
| 498 | /* ignore error return of fb_get_options */ |
| 499 | fb_get_options("vesafb", &option); |
| 500 | vesafb_setup(option); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame^] | 501 | ret = platform_driver_register(&vesafb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
| 503 | if (!ret) { |
| 504 | ret = platform_device_register(&vesafb_device); |
| 505 | if (ret) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame^] | 506 | platform_driver_unregister(&vesafb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
| 508 | return ret; |
| 509 | } |
| 510 | module_init(vesafb_init); |
| 511 | |
| 512 | MODULE_LICENSE("GPL"); |