fbdev: move FBIO_WAITFORVSYNC to linux/fb.h
[safe/jmp/linux-2.6] / drivers / video / s3fb.c
index a96ac43..d4471b4 100644 (file)
  * which is based on the code of neofb.
  */
 
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/mm.h>
 #include <linux/tty.h>
-#include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/fb.h>
 #include <linux/svga.h>
@@ -46,11 +44,11 @@ struct s3fb_info {
 static const struct svga_fb_format s3fb_formats[] = {
        { 0,  {0, 6, 0},  {0, 6, 0},  {0, 6, 0}, {0, 0, 0}, 0,
                FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4,   FB_VISUAL_PSEUDOCOLOR, 8, 16},
-       { 4,  {0, 6, 0},  {0, 6, 0},  {0, 6, 0}, {0, 0, 0}, 0,
+       { 4,  {0, 4, 0},  {0, 4, 0},  {0, 4, 0}, {0, 0, 0}, 0,
                FB_TYPE_PACKED_PIXELS, 0,               FB_VISUAL_PSEUDOCOLOR, 8, 16},
-       { 4,  {0, 6, 0},  {0, 6, 0},  {0, 6, 0}, {0, 0, 0}, 1,
+       { 4,  {0, 4, 0},  {0, 4, 0},  {0, 4, 0}, {0, 0, 0}, 1,
                FB_TYPE_INTERLEAVED_PLANES, 1,          FB_VISUAL_PSEUDOCOLOR, 8, 16},
-       { 8,  {0, 6, 0},  {0, 6, 0},  {0, 6, 0}, {0, 0, 0}, 0,
+       { 8,  {0, 8, 0},  {0, 8, 0},  {0, 8, 0}, {0, 0, 0}, 0,
                FB_TYPE_PACKED_PIXELS, 0,               FB_VISUAL_PSEUDOCOLOR, 4, 8},
        {16,  {10, 5, 0}, {5, 5, 0},  {0, 5, 0}, {0, 0, 0}, 0,
                FB_TYPE_PACKED_PIXELS, 0,               FB_VISUAL_TRUECOLOR, 2, 4},
@@ -132,10 +130,10 @@ static const struct svga_timing_regs s3_timing_regs     = {
 /* Module parameters */
 
 
-static char *mode = "640x480-8@60";
+static char *mode_option __devinitdata = "640x480-8@60";
 
 #ifdef CONFIG_MTRR
-static int mtrr = 1;
+static int mtrr __devinitdata = 1;
 #endif
 
 static int fasttext = 1;
@@ -145,8 +143,10 @@ MODULE_AUTHOR("(c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("fbdev driver for S3 Trio/Virge");
 
-module_param(mode, charp, 0444);
-MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc)");
+module_param(mode_option, charp, 0444);
+MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)");
+module_param_named(mode, mode_option, charp, 0444);
+MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc) (deprecated)");
 
 #ifdef CONFIG_MTRR
 module_param(mtrr, int, 0444);
@@ -400,6 +400,7 @@ static int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 {
        struct s3fb_info *par = info->par;
        int rv, mem, step;
+       u16 m, n, r;
 
        /* Find appropriate format */
        rv = svga_match_format (s3fb_formats, var, NULL);
@@ -427,20 +428,26 @@ static int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 
        /* Check whether have enough memory */
        mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
-       if (mem > info->screen_size)
-       {
+       if (mem > info->screen_size) {
                printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n",
                        info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
                return -EINVAL;
        }
 
        rv = svga_check_timings (&s3_timing_regs, var, info->node);
-       if (rv < 0)
-       {
+       if (rv < 0) {
                printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
                return rv;
        }
 
+       rv = svga_compute_pll(&s3_pll, PICOS2KHZ(var->pixclock), &m, &n, &r,
+                               info->node);
+       if (rv < 0) {
+               printk(KERN_ERR "fb%d: invalid pixclock value requested\n",
+                       info->node);
+               return rv;
+       }
+
        return 0;
 }
 
@@ -879,7 +886,7 @@ static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_i
        }
 
        /* Allocate and fill driver data structure */
-       info = framebuffer_alloc(sizeof(struct s3fb_info), NULL);
+       info = framebuffer_alloc(sizeof(struct s3fb_info), &(dev->dev));
        if (!info) {
                dev_err(&(dev->dev), "cannot allocate memory\n");
                return -ENOMEM;
@@ -894,13 +901,13 @@ static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_i
        /* Prepare PCI device */
        rc = pci_enable_device(dev);
        if (rc < 0) {
-               dev_err(&(dev->dev), "cannot enable PCI device\n");
+               dev_err(info->device, "cannot enable PCI device\n");
                goto err_enable_device;
        }
 
        rc = pci_request_regions(dev, "s3fb");
        if (rc < 0) {
-               dev_err(&(dev->dev), "cannot reserve framebuffer region\n");
+               dev_err(info->device, "cannot reserve framebuffer region\n");
                goto err_request_regions;
        }
 
@@ -912,7 +919,7 @@ static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_i
        info->screen_base = pci_iomap(dev, 0, 0);
        if (! info->screen_base) {
                rc = -ENOMEM;
-               dev_err(&(dev->dev), "iomap for framebuffer failed\n");
+               dev_err(info->device, "iomap for framebuffer failed\n");
                goto err_iomap;
        }
 
@@ -953,22 +960,22 @@ static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_i
        info->pseudo_palette = (void*) (par->pseudo_palette);
 
        /* Prepare startup mode */
-       rc = fb_find_mode(&(info->var), info, mode, NULL, 0, NULL, 8);
+       rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8);
        if (! ((rc == 1) || (rc == 2))) {
                rc = -EINVAL;
-               dev_err(&(dev->dev), "mode %s not found\n", mode);
+               dev_err(info->device, "mode %s not found\n", mode_option);
                goto err_find_mode;
        }
 
        rc = fb_alloc_cmap(&info->cmap, 256, 0);
        if (rc < 0) {
-               dev_err(&(dev->dev), "cannot allocate colormap\n");
+               dev_err(info->device, "cannot allocate colormap\n");
                goto err_alloc_cmap;
        }
 
        rc = register_framebuffer(info);
        if (rc < 0) {
-               dev_err(&(dev->dev), "cannot register framebuffer\n");
+               dev_err(info->device, "cannot register framebuffer\n");
                goto err_reg_fb;
        }
 
@@ -1044,7 +1051,7 @@ static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state)
        struct fb_info *info = pci_get_drvdata(dev);
        struct s3fb_info *par = info->par;
 
-       dev_info(&(dev->dev), "suspend\n");
+       dev_info(info->device, "suspend\n");
 
        acquire_console_sem();
        mutex_lock(&(par->open_lock));
@@ -1076,7 +1083,7 @@ static int s3_pci_resume(struct pci_dev* dev)
        struct s3fb_info *par = info->par;
        int err;
 
-       dev_info(&(dev->dev), "resume\n");
+       dev_info(info->device, "resume\n");
 
        acquire_console_sem();
        mutex_lock(&(par->open_lock));
@@ -1093,7 +1100,7 @@ static int s3_pci_resume(struct pci_dev* dev)
        if (err) {
                mutex_unlock(&(par->open_lock));
                release_console_sem();
-               dev_err(&(dev->dev), "error %d enabling device for resume\n", err);
+               dev_err(info->device, "error %d enabling device for resume\n", err);
                return err;
        }
        pci_set_master(dev);
@@ -1161,7 +1168,7 @@ static int  __init s3fb_setup(char *options)
                else if (!strncmp(opt, "fasttext:", 9))
                        fasttext = simple_strtoul(opt + 9, NULL, 0);
                else
-                       mode = opt;
+                       mode_option = opt;
        }
 
        return 0;