linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / video / vesafb.c
index 7b37ee8..8982e54 100644 (file)
@@ -19,9 +19,9 @@
 #include <linux/fb.h>
 #include <linux/ioport.h>
 #include <linux/init.h>
-#ifdef __i386__
-#include <video/edid.h>
-#endif
+#include <linux/platform_device.h>
+
+#include <video/vga.h>
 #include <asm/io.h>
 #include <asm/mtrr.h>
 
@@ -48,7 +48,7 @@ static struct fb_fix_screeninfo vesafb_fix __initdata = {
 };
 
 static int             inverse   = 0;
-static int             mtrr      = 1;
+static int             mtrr      = 0; /* disable mtrr */
 static int            vram_remap __initdata = 0; /* Set amount of memory to be used */
 static int            vram_total __initdata = 0; /* Set total amount of memory */
 static int             pmi_setpal = 0; /* pmi for palette changes ??? */
@@ -66,15 +66,6 @@ static int vesafb_pan_display(struct fb_var_screeninfo *var,
 #ifdef __i386__
        int offset;
 
-       if (!ypan)
-               return -EINVAL;
-       if (var->xoffset)
-               return -EINVAL;
-       if (var->yoffset > var->yres_virtual)
-               return -EINVAL;
-       if ((ypan==1) && var->yoffset+var->yres > var->yres_virtual)
-               return -EINVAL;
-
        offset = (var->yoffset * info->fix.line_length + var->xoffset) / 4;
 
         __asm__ __volatile__(
@@ -134,45 +125,39 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
        if (regno >= info->cmap.len)
                return 1;
 
-       switch (info->var.bits_per_pixel) {
-       case 8:
+       if (info->var.bits_per_pixel == 8)
                vesa_setpalette(regno,red,green,blue);
-               break;
-       case 16:
-               if (info->var.red.offset == 10) {
-                       /* 1:5:5:5 */
-                       ((u32*) (info->pseudo_palette))[regno] =        
+       else if (regno < 16) {
+               switch (info->var.bits_per_pixel) {
+               case 16:
+                       if (info->var.red.offset == 10) {
+                               /* 1:5:5:5 */
+                               ((u32*) (info->pseudo_palette))[regno] =
                                        ((red   & 0xf800) >>  1) |
                                        ((green & 0xf800) >>  6) |
                                        ((blue  & 0xf800) >> 11);
-               } else {
-                       /* 0:5:6:5 */
-                       ((u32*) (info->pseudo_palette))[regno] =        
+                       } else {
+                               /* 0:5:6:5 */
+                               ((u32*) (info->pseudo_palette))[regno] =
                                        ((red   & 0xf800)      ) |
                                        ((green & 0xfc00) >>  5) |
                                        ((blue  & 0xf800) >> 11);
+                       }
+                       break;
+               case 24:
+               case 32:
+                       red   >>= 8;
+                       green >>= 8;
+                       blue  >>= 8;
+                       ((u32 *)(info->pseudo_palette))[regno] =
+                               (red   << info->var.red.offset)   |
+                               (green << info->var.green.offset) |
+                               (blue  << info->var.blue.offset);
+                       break;
                }
-               break;
-       case 24:
-               red   >>= 8;
-               green >>= 8;
-               blue  >>= 8;
-               ((u32 *)(info->pseudo_palette))[regno] =
-                       (red   << info->var.red.offset)   |
-                       (green << info->var.green.offset) |
-                       (blue  << info->var.blue.offset);
-               break;
-       case 32:
-               red   >>= 8;
-               green >>= 8;
-               blue  >>= 8;
-               ((u32 *)(info->pseudo_palette))[regno] =
-                       (red   << info->var.red.offset)   |
-                       (green << info->var.green.offset) |
-                       (blue  << info->var.blue.offset);
-               break;
-    }
-    return 0;
+       }
+
+       return 0;
 }
 
 static struct fb_ops vesafb_ops = {
@@ -182,10 +167,9 @@ static struct fb_ops vesafb_ops = {
        .fb_fillrect    = cfb_fillrect,
        .fb_copyarea    = cfb_copyarea,
        .fb_imageblit   = cfb_imageblit,
-       .fb_cursor      = soft_cursor,
 };
 
-int __init vesafb_setup(char *options)
+static int __init vesafb_setup(char *options)
 {
        char *this_opt;
        
@@ -207,8 +191,8 @@ int __init vesafb_setup(char *options)
                        pmi_setpal=0;
                else if (! strcmp(this_opt, "pmipal"))
                        pmi_setpal=1;
-               else if (! strcmp(this_opt, "mtrr"))
-                       mtrr=1;
+               else if (! strncmp(this_opt, "mtrr:", 5))
+                       mtrr = simple_strtoul(this_opt+5, NULL, 0);
                else if (! strcmp(this_opt, "nomtrr"))
                        mtrr=0;
                else if (! strncmp(this_opt, "vtotal:", 7))
@@ -219,9 +203,8 @@ int __init vesafb_setup(char *options)
        return 0;
 }
 
-static int __init vesafb_probe(struct device *device)
+static int __init vesafb_probe(struct platform_device *dev)
 {
-       struct platform_device *dev = to_platform_device(device);
        struct fb_info *info;
        int i, err;
        unsigned int size_vmode;
@@ -229,7 +212,7 @@ static int __init vesafb_probe(struct device *device)
        unsigned int size_total;
 
        if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
-               return -ENXIO;
+               return -ENODEV;
 
        vesafb_fix.smem_start = screen_info.lfb_base;
        vesafb_defined.bits_per_pixel = screen_info.lfb_depth;
@@ -274,7 +257,7 @@ static int __init vesafb_probe(struct device *device)
 
        if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
                printk(KERN_WARNING
-                      "vesafb: abort, cannot reserve video memory at 0x%lx\n",
+                      "vesafb: cannot reserve video memory at 0x%lx\n",
                        vesafb_fix.smem_start);
                /* We cannot make this fatal. Sometimes this comes from magic
                   spaces our resource handlers simply don't know about */
@@ -282,13 +265,13 @@ static int __init vesafb_probe(struct device *device)
 
        info = framebuffer_alloc(sizeof(u32) * 256, &dev->dev);
        if (!info) {
-               release_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len);
+               release_mem_region(vesafb_fix.smem_start, size_total);
                return -ENOMEM;
        }
        info->pseudo_palette = info->par;
        info->par = NULL;
 
-        info->screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len);
+       info->screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len);
        if (!info->screen_base) {
                printk(KERN_ERR
                       "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n",
@@ -388,17 +371,45 @@ static int __init vesafb_probe(struct device *device)
         * region already (FIXME) */
        request_region(0x3c0, 32, "vesafb");
 
+#ifdef CONFIG_MTRR
        if (mtrr) {
-               int temp_size = size_total;
-               /* Find the largest power-of-two */
-               while (temp_size & (temp_size - 1))
-                       temp_size &= (temp_size - 1);
-                        
-                /* Try and find a power of two to add */
-               while (temp_size && mtrr_add(vesafb_fix.smem_start, temp_size, MTRR_TYPE_WRCOMB, 1)==-EINVAL) {
-                       temp_size >>= 1;
+               unsigned int temp_size = size_total;
+               unsigned int type = 0;
+
+               switch (mtrr) {
+               case 1:
+                       type = MTRR_TYPE_UNCACHABLE;
+                       break;
+               case 2:
+                       type = MTRR_TYPE_WRBACK;
+                       break;
+               case 3:
+                       type = MTRR_TYPE_WRCOMB;
+                       break;
+               case 4:
+                       type = MTRR_TYPE_WRTHROUGH;
+                       break;
+               default:
+                       type = 0;
+                       break;
+               }
+
+               if (type) {
+                       int rc;
+
+                       /* Find the largest power-of-two */
+                       while (temp_size & (temp_size - 1))
+                               temp_size &= (temp_size - 1);
+
+                       /* Try and find a power of two to add */
+                       do {
+                               rc = mtrr_add(vesafb_fix.smem_start, temp_size,
+                                             type, 1);
+                               temp_size >>= 1;
+                       } while (temp_size >= PAGE_SIZE && rc == -EINVAL);
                }
        }
+#endif
        
        info->fbops = &vesafb_ops;
        info->var = vesafb_defined;
@@ -406,8 +417,11 @@ static int __init vesafb_probe(struct device *device)
        info->flags = FBINFO_FLAG_DEFAULT |
                (ypan) ? FBINFO_HWACCEL_YPAN : 0;
 
+       if (!ypan)
+               info->fbops->fb_pan_display = NULL;
+
        if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
-               err = -ENXIO;
+               err = -ENOMEM;
                goto err;
        }
        if (register_framebuffer(info)<0) {
@@ -424,17 +438,18 @@ err:
        return err;
 }
 
-static struct device_driver vesafb_driver = {
-       .name   = "vesafb",
-       .bus    = &platform_bus_type,
+static struct platform_driver vesafb_driver = {
        .probe  = vesafb_probe,
+       .driver = {
+               .name   = "vesafb",
+       },
 };
 
 static struct platform_device vesafb_device = {
        .name   = "vesafb",
 };
 
-int __init vesafb_init(void)
+static int __init vesafb_init(void)
 {
        int ret;
        char *option = NULL;
@@ -442,23 +457,15 @@ int __init vesafb_init(void)
        /* ignore error return of fb_get_options */
        fb_get_options("vesafb", &option);
        vesafb_setup(option);
-       ret = driver_register(&vesafb_driver);
+       ret = platform_driver_register(&vesafb_driver);
 
        if (!ret) {
                ret = platform_device_register(&vesafb_device);
                if (ret)
-                       driver_unregister(&vesafb_driver);
+                       platform_driver_unregister(&vesafb_driver);
        }
        return ret;
 }
 module_init(vesafb_init);
 
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-basic-offset: 8
- * End:
- */
-
 MODULE_LICENSE("GPL");