]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/video/vga16fb.c
device create: framebuffer: convert device_create to device_create_drvdata
[linux-2.6-omap-h63xx.git] / drivers / video / vga16fb.c
index f3f16fd9f2316d32c89a2d9ae63b47864cd28fb0..9b3c5923365e7dd62e60982f9d6c27341f68cdf5 100644 (file)
 #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/ioport.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
+#include <linux/screen_info.h>
 
 #include <asm/io.h>
 #include <video/vga.h>
@@ -70,7 +70,8 @@ struct vga16fb_par {
                unsigned char   ClockingMode;     /* Seq-Controller:01h */
        } vga_state;
        struct vgastate state;
-       atomic_t ref_count;
+       struct mutex open_lock;
+       unsigned int ref_count;
        int palette_blanked, vesa_blanked, mode, isVGA;
        u8 misc, pel_msk, vss, clkdiv;
        u8 crtc[VGA_CRT_C];
@@ -264,7 +265,7 @@ static void vga16fb_clock_chip(struct vga16fb_par *par,
                               const struct fb_info *info,
                               int mul, int div)
 {
-       static struct {
+       static const struct {
                u32 pixclock;
                u8  misc;
                u8  seq_clock_mode;
@@ -300,28 +301,33 @@ static void vga16fb_clock_chip(struct vga16fb_par *par,
 static int vga16fb_open(struct fb_info *info, int user)
 {
        struct vga16fb_par *par = info->par;
-       int cnt = atomic_read(&par->ref_count);
 
-       if (!cnt) {
+       mutex_lock(&par->open_lock);
+       if (!par->ref_count) {
                memset(&par->state, 0, sizeof(struct vgastate));
                par->state.flags = VGA_SAVE_FONTS | VGA_SAVE_MODE |
                        VGA_SAVE_CMAP;
                save_vga(&par->state);
        }
-       atomic_inc(&par->ref_count);
+       par->ref_count++;
+       mutex_unlock(&par->open_lock);
+
        return 0;
 }
 
 static int vga16fb_release(struct fb_info *info, int user)
 {
        struct vga16fb_par *par = info->par;
-       int cnt = atomic_read(&par->ref_count);
 
-       if (!cnt)
+       mutex_lock(&par->open_lock);
+       if (!par->ref_count) {
+               mutex_unlock(&par->open_lock);
                return -EINVAL;
-       if (cnt == 1)
+       }
+       if (par->ref_count == 1)
                restore_vga(&par->state);
-       atomic_dec(&par->ref_count);
+       par->ref_count--;
+       mutex_unlock(&par->open_lock);
 
        return 0;
 }
@@ -652,7 +658,7 @@ static int vga16fb_set_par(struct fb_info *info)
 
 static void ega16_setpalette(int regno, unsigned red, unsigned green, unsigned blue)
 {
-       static unsigned char map[] = { 000, 001, 010, 011 };
+       static const unsigned char map[] = { 000, 001, 010, 011 };
        int val;
        
        if (regno >= 16)
@@ -1139,23 +1145,19 @@ static void vga16fb_copyarea(struct fb_info *info, const struct fb_copyarea *are
        }
 }
 
-#ifdef __LITTLE_ENDIAN
-static unsigned int transl_l[] =
-{0x0,0x8,0x4,0xC,0x2,0xA,0x6,0xE,0x1,0x9,0x5,0xD,0x3,0xB,0x7,0xF};
-static unsigned int transl_h[] =
-{0x000, 0x800, 0x400, 0xC00, 0x200, 0xA00, 0x600, 0xE00,
- 0x100, 0x900, 0x500, 0xD00, 0x300, 0xB00, 0x700, 0xF00};
-#else
-#ifdef __BIG_ENDIAN
-static unsigned int transl_h[] =
-{0x0,0x8,0x4,0xC,0x2,0xA,0x6,0xE,0x1,0x9,0x5,0xD,0x3,0xB,0x7,0xF};
-static unsigned int transl_l[] =
-{0x000, 0x800, 0x400, 0xC00, 0x200, 0xA00, 0x600, 0xE00,
- 0x100, 0x900, 0x500, 0xD00, 0x300, 0xB00, 0x700, 0xF00};
+#define TRANS_MASK_LOW  {0x0,0x8,0x4,0xC,0x2,0xA,0x6,0xE,0x1,0x9,0x5,0xD,0x3,0xB,0x7,0xF}
+#define TRANS_MASK_HIGH {0x000, 0x800, 0x400, 0xC00, 0x200, 0xA00, 0x600, 0xE00, \
+                        0x100, 0x900, 0x500, 0xD00, 0x300, 0xB00, 0x700, 0xF00}
+
+#if defined(__LITTLE_ENDIAN)
+static const u16 transl_l[] = TRANS_MASK_LOW;
+static const u16 transl_h[] = TRANS_MASK_HIGH;
+#elif defined(__BIG_ENDIAN)
+static const u16 transl_l[] = TRANS_MASK_HIGH;
+static const u16 transl_h[] = TRANS_MASK_LOW;
 #else
 #error "Only __BIG_ENDIAN and __LITTLE_ENDIAN are supported in vga-planes"
 #endif
-#endif
 
 static void vga_8planes_imageblit(struct fb_info *info, const struct fb_image *image)
 {
@@ -1334,9 +1336,8 @@ static int vga16fb_setup(char *options)
 }
 #endif
 
-static int __init vga16fb_probe(struct device *device)
+static int __init vga16fb_probe(struct platform_device *dev)
 {
-       struct platform_device *dev = to_platform_device(device);
        struct fb_info *info;
        struct vga16fb_par *par;
        int i;
@@ -1351,7 +1352,7 @@ static int __init vga16fb_probe(struct device *device)
        }
 
        /* XXX share VGA_FB_PHYS and I/O region with vgacon and others */
-       info->screen_base = (void __iomem *)VGA_MAP_MEM(VGA_FB_PHYS);
+       info->screen_base = (void __iomem *)VGA_MAP_MEM(VGA_FB_PHYS, 0);
 
        if (!info->screen_base) {
                printk(KERN_ERR "vga16fb: unable to map device\n");
@@ -1362,7 +1363,8 @@ static int __init vga16fb_probe(struct device *device)
        printk(KERN_INFO "vga16fb: mapped to 0x%p\n", info->screen_base);
        par = info->par;
 
-       par->isVGA = ORIG_VIDEO_ISVGA;
+       mutex_init(&par->open_lock);
+       par->isVGA = screen_info.orig_video_isVGA;
        par->palette_blanked = 0;
        par->vesa_blanked = 0;
 
@@ -1376,6 +1378,8 @@ static int __init vga16fb_probe(struct device *device)
        info->fbops = &vga16fb_ops;
        info->var = vga16fb_defined;
        info->fix = vga16fb_fix;
+       /* supports rectangles with widths of multiples of 8 */
+       info->pixmap.blit_x = 1 << 7 | 1 << 15 | 1 << 23 | 1 << 31;
        info->flags = FBINFO_FLAG_DEFAULT |
                FBINFO_HWACCEL_YPAN;
 
@@ -1403,7 +1407,7 @@ static int __init vga16fb_probe(struct device *device)
 
        printk(KERN_INFO "fb%d: %s frame buffer device\n",
               info->node, info->fix.id);
-       dev_set_drvdata(device, info);
+       platform_set_drvdata(dev, info);
 
        return 0;
 
@@ -1417,9 +1421,9 @@ static int __init vga16fb_probe(struct device *device)
        return ret;
 }
 
-static int vga16fb_remove(struct device *device)
+static int vga16fb_remove(struct platform_device *dev)
 {
-       struct fb_info *info = dev_get_drvdata(device);
+       struct fb_info *info = platform_get_drvdata(dev);
 
        if (info) {
                unregister_framebuffer(info);
@@ -1432,16 +1436,15 @@ static int vga16fb_remove(struct device *device)
        return 0;
 }
 
-static struct device_driver vga16fb_driver = {
-       .name = "vga16fb",
-       .bus  = &platform_bus_type,
+static struct platform_driver vga16fb_driver = {
        .probe = vga16fb_probe,
        .remove = vga16fb_remove,
+       .driver = {
+               .name = "vga16fb",
+       },
 };
 
-static struct platform_device vga16fb_device = {
-       .name = "vga16fb",
-};
+static struct platform_device *vga16fb_device;
 
 static int __init vga16fb_init(void)
 {
@@ -1454,12 +1457,20 @@ static int __init vga16fb_init(void)
 
        vga16fb_setup(option);
 #endif
-       ret = driver_register(&vga16fb_driver);
+       ret = platform_driver_register(&vga16fb_driver);
 
        if (!ret) {
-               ret = platform_device_register(&vga16fb_device);
-               if (ret)
-                       driver_unregister(&vga16fb_driver);
+               vga16fb_device = platform_device_alloc("vga16fb", 0);
+
+               if (vga16fb_device)
+                       ret = platform_device_add(vga16fb_device);
+               else
+                       ret = -ENOMEM;
+
+               if (ret) {
+                       platform_device_put(vga16fb_device);
+                       platform_driver_unregister(&vga16fb_driver);
+               }
        }
 
        return ret;
@@ -1467,8 +1478,8 @@ static int __init vga16fb_init(void)
 
 static void __exit vga16fb_exit(void)
 {
-       platform_device_unregister(&vga16fb_device);
-       driver_unregister(&vga16fb_driver);
+       platform_device_unregister(vga16fb_device);
+       platform_driver_unregister(&vga16fb_driver);
 }
 
 MODULE_LICENSE("GPL");