fbdev/amifb: Correct check for video memory size
[linux-2.6.git] / drivers / video / cg14.c
index 0db0fec..f188950 100644 (file)
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/string.h>
-#include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/fb.h>
 #include <linux/mm.h>
 #include <linux/uaccess.h>
+#include <linux/of_device.h>
 
 #include <asm/io.h>
-#include <asm/prom.h>
-#include <asm/of_device.h>
 #include <asm/fbio.h>
 
 #include "sbuslib.h"
@@ -197,9 +195,7 @@ struct cg14_par {
        u32                     flags;
 #define CG14_FLAG_BLANKED      0x00000001
 
-       unsigned long           physbase;
        unsigned long           iospace;
-       unsigned long           fbsize;
 
        struct sbus_mmap_map    mmap_map[CG14_MMAP_ENTRIES];
 
@@ -272,7 +268,7 @@ static int cg14_mmap(struct fb_info *info, struct vm_area_struct *vma)
        struct cg14_par *par = (struct cg14_par *) info->par;
 
        return sbusfb_mmap_helper(par->mmap_map,
-                                 par->physbase, par->fbsize,
+                                 info->fix.smem_start, info->fix.smem_len,
                                  par->iospace, vma);
 }
 
@@ -344,7 +340,8 @@ static int cg14_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
 
        default:
                ret = sbusfb_ioctl_helper(cmd, arg, info,
-                                         FBTYPE_MDICOLOR, 8, par->fbsize);
+                                         FBTYPE_MDICOLOR, 8,
+                                         info->fix.smem_len);
                break;
        };
 
@@ -449,7 +446,7 @@ static struct sbus_mmap_map __cg14_mmap_map[CG14_MMAP_ENTRIES] __devinitdata = {
        { .size = 0 }
 };
 
-static void cg14_unmap_regs(struct of_device *op, struct fb_info *info,
+static void cg14_unmap_regs(struct platform_device *op, struct fb_info *info,
                            struct cg14_par *par)
 {
        if (par->regs)
@@ -463,12 +460,12 @@ static void cg14_unmap_regs(struct of_device *op, struct fb_info *info,
                           par->cursor, sizeof(struct cg14_cursor));
        if (info->screen_base)
                of_iounmap(&op->resource[1],
-                          info->screen_base, par->fbsize);
+                          info->screen_base, info->fix.smem_len);
 }
 
-static int __devinit cg14_probe(struct of_device *op, const struct of_device_id *match)
+static int __devinit cg14_probe(struct platform_device *op)
 {
-       struct device_node *dp = op->node;
+       struct device_node *dp = op->dev.of_node;
        struct fb_info *info;
        struct cg14_par *par;
        int is_8mb, linebytes, i, err;
@@ -482,21 +479,21 @@ static int __devinit cg14_probe(struct of_device *op, const struct of_device_id
 
        spin_lock_init(&par->lock);
 
-       sbusfb_fill_var(&info->var, dp->node, 8);
+       sbusfb_fill_var(&info->var, dp, 8);
        info->var.red.length = 8;
        info->var.green.length = 8;
        info->var.blue.length = 8;
 
        linebytes = of_getintprop_default(dp, "linebytes",
                                          info->var.xres);
-       par->fbsize = PAGE_ALIGN(linebytes * info->var.yres);
+       info->fix.smem_len = PAGE_ALIGN(linebytes * info->var.yres);
 
        if (!strcmp(dp->parent->name, "sbus") ||
            !strcmp(dp->parent->name, "sbi")) {
-               par->physbase = op->resource[0].start;
+               info->fix.smem_start = op->resource[0].start;
                par->iospace = op->resource[0].flags & IORESOURCE_BITS;
        } else {
-               par->physbase = op->resource[1].start;
+               info->fix.smem_start = op->resource[1].start;
                par->iospace = op->resource[0].flags & IORESOURCE_BITS;
        }
 
@@ -508,7 +505,7 @@ static int __devinit cg14_probe(struct of_device *op, const struct of_device_id
                                 sizeof(struct cg14_cursor), "cg14 cursor");
 
        info->screen_base = of_ioremap(&op->resource[1], 0,
-                                      par->fbsize, "cg14 ram");
+                                      info->fix.smem_len, "cg14 ram");
 
        if (!par->regs || !par->clut || !par->cursor || !info->screen_base)
                goto out_unmap_regs;
@@ -558,7 +555,7 @@ static int __devinit cg14_probe(struct of_device *op, const struct of_device_id
 
        printk(KERN_INFO "%s: cgfourteen at %lx:%lx, %dMB\n",
               dp->full_name,
-              par->iospace, par->physbase,
+              par->iospace, info->fix.smem_start,
               par->ramsize >> 20);
 
        return 0;
@@ -568,12 +565,13 @@ out_dealloc_cmap:
 
 out_unmap_regs:
        cg14_unmap_regs(op, info, par);
+       framebuffer_release(info);
 
 out_err:
        return err;
 }
 
-static int __devexit cg14_remove(struct of_device *op)
+static int __devexit cg14_remove(struct platform_device *op)
 {
        struct fb_info *info = dev_get_drvdata(&op->dev);
        struct cg14_par *par = info->par;
@@ -590,7 +588,7 @@ static int __devexit cg14_remove(struct of_device *op)
        return 0;
 }
 
-static struct of_device_id cg14_match[] = {
+static const struct of_device_id cg14_match[] = {
        {
                .name = "cgfourteen",
        },
@@ -598,9 +596,12 @@ static struct of_device_id cg14_match[] = {
 };
 MODULE_DEVICE_TABLE(of, cg14_match);
 
-static struct of_platform_driver cg14_driver = {
-       .name           = "cg14",
-       .match_table    = cg14_match,
+static struct platform_driver cg14_driver = {
+       .driver = {
+               .name = "cg14",
+               .owner = THIS_MODULE,
+               .of_match_table = cg14_match,
+       },
        .probe          = cg14_probe,
        .remove         = __devexit_p(cg14_remove),
 };
@@ -610,12 +611,12 @@ static int __init cg14_init(void)
        if (fb_get_options("cg14fb", NULL))
                return -ENODEV;
 
-       return of_register_driver(&cg14_driver, &of_bus_type);
+       return platform_driver_register(&cg14_driver);
 }
 
 static void __exit cg14_exit(void)
 {
-       of_unregister_driver(&cg14_driver);
+       platform_driver_unregister(&cg14_driver);
 }
 
 module_init(cg14_init);