Merge branch 'xen/fbdev' of git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen
[safe/jmp/linux-2.6] / drivers / video / bfin-t350mcqb-fb.c
index a2bb2de..5cc36cf 100644 (file)
@@ -91,6 +91,7 @@ struct bfin_t350mcqbfb_info {
        int lq043_open_cnt;
        int irq;
        spinlock_t lock;        /* lock */
+       u32 pseudo_pal[16];
 };
 
 static int nocursor;
@@ -182,13 +183,13 @@ static void bfin_t350mcqb_config_dma(struct bfin_t350mcqbfb_info *fbi)
 
 }
 
-static int bfin_t350mcqb_request_ports(int action)
-{
-       u16 ppi0_req_8[] = {P_PPI0_CLK, P_PPI0_FS1, P_PPI0_FS2,
+static u16 ppi0_req_8[] = {P_PPI0_CLK, P_PPI0_FS1, P_PPI0_FS2,
                            P_PPI0_D0, P_PPI0_D1, P_PPI0_D2,
                            P_PPI0_D3, P_PPI0_D4, P_PPI0_D5,
                            P_PPI0_D6, P_PPI0_D7, 0};
 
+static int bfin_t350mcqb_request_ports(int action)
+{
        if (action) {
                if (peripheral_request_list(ppi0_req_8, DRIVER_NAME)) {
                        printk(KERN_ERR "Requesting Peripherals faild\n");
@@ -241,7 +242,6 @@ static int bfin_t350mcqb_fb_release(struct fb_info *info, int user)
                SSYNC();
                disable_dma(CH_PPI);
                bfin_t350mcqb_stop_timers();
-               memset(fbi->fb_buffer, 0, info->fix.smem_len);
        }
 
        spin_unlock(&fbi->lock);
@@ -253,8 +253,21 @@ static int bfin_t350mcqb_fb_check_var(struct fb_var_screeninfo *var,
                                   struct fb_info *info)
 {
 
-       if (var->bits_per_pixel != LCD_BPP) {
-               pr_debug("%s: depth not supported: %u BPP\n", __FUNCTION__,
+       switch (var->bits_per_pixel) {
+       case 24:/* TRUECOLOUR, 16m */
+               var->red.offset = 0;
+               var->green.offset = 8;
+               var->blue.offset = 16;
+               var->red.length = var->green.length = var->blue.length = 8;
+               var->transp.offset = 0;
+               var->transp.length = 0;
+               var->transp.msb_right = 0;
+               var->red.msb_right = 0;
+               var->green.msb_right = 0;
+               var->blue.msb_right = 0;
+               break;
+       default:
+               pr_debug("%s: depth not supported: %u BPP\n", __func__,
                         var->bits_per_pixel);
                return -EINVAL;
        }
@@ -263,7 +276,7 @@ static int bfin_t350mcqb_fb_check_var(struct fb_var_screeninfo *var,
            info->var.xres_virtual != var->xres_virtual ||
            info->var.yres_virtual != var->yres_virtual) {
                pr_debug("%s: Resolution not supported: X%u x Y%u \n",
-                        __FUNCTION__, var->xres, var->yres);
+                        __func__, var->xres, var->yres);
                return -EINVAL;
        }
 
@@ -273,7 +286,7 @@ static int bfin_t350mcqb_fb_check_var(struct fb_var_screeninfo *var,
 
        if ((info->fix.line_length * var->yres_virtual) > info->fix.smem_len) {
                pr_debug("%s: Memory Limit requested yres_virtual = %u\n",
-                        __FUNCTION__, var->yres_virtual);
+                        __func__, var->yres_virtual);
                return -ENOMEM;
        }
 
@@ -301,7 +314,7 @@ static int bfin_t350mcqb_fb_mmap(struct fb_info *info, struct vm_area_struct *vm
         *   Other flags can be set, and are documented in
         *   include/linux/mm.h
         */
-       vma->vm_flags |= VM_MAYSHARE;
+       vma->vm_flags |= VM_MAYSHARE | VM_SHARED;
 
        return 0;
 }
@@ -395,7 +408,7 @@ static int bfin_lcd_set_contrast(struct lcd_device *dev, int contrast)
        return 0;
 }
 
-static int bfin_lcd_check_fb(struct fb_info *fi)
+static int bfin_lcd_check_fb(struct lcd_device *dev, struct fb_info *fi)
 {
        if (!fi || (fi == &bfin_t350mcqb_fb))
                return 1;
@@ -433,7 +446,7 @@ static irqreturn_t bfin_t350mcqb_irq_error(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
-static int __init bfin_t350mcqb_probe(struct platform_device *pdev)
+static int __devinit bfin_t350mcqb_probe(struct platform_device *pdev)
 {
        struct bfin_t350mcqbfb_info *info;
        struct fb_info *fbinfo;
@@ -513,23 +526,12 @@ static int __init bfin_t350mcqb_probe(struct platform_device *pdev)
                goto out3;
        }
 
-       memset(info->fb_buffer, 0, fbinfo->fix.smem_len);
-
        fbinfo->screen_base = (void *)info->fb_buffer + ACTIVE_VIDEO_MEM_OFFSET;
        fbinfo->fix.smem_start = (int)info->fb_buffer + ACTIVE_VIDEO_MEM_OFFSET;
 
        fbinfo->fbops = &bfin_t350mcqb_fb_ops;
 
-       fbinfo->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL);
-       if (!fbinfo->pseudo_palette) {
-               printk(KERN_ERR DRIVER_NAME
-                      "Fail to allocate pseudo_palette\n");
-
-               ret = -ENOMEM;
-               goto out4;
-       }
-
-       memset(fbinfo->pseudo_palette, 0, sizeof(u32) * 16);
+       fbinfo->pseudo_palette = &info->pseudo_pal;
 
        if (fb_alloc_cmap(&fbinfo->cmap, BFIN_LCD_NBR_PALETTE_ENTRIES, 0)
            < 0) {
@@ -537,7 +539,7 @@ static int __init bfin_t350mcqb_probe(struct platform_device *pdev)
                       "Fail to allocate colormap (%d entries)\n",
                       BFIN_LCD_NBR_PALETTE_ENTRIES);
                ret = -EFAULT;
-               goto out5;
+               goto out4;
        }
 
        if (bfin_t350mcqb_request_ports(1)) {
@@ -552,11 +554,11 @@ static int __init bfin_t350mcqb_probe(struct platform_device *pdev)
                goto out7;
        }
 
-       if (request_irq(info->irq, (void *)bfin_t350mcqb_irq_error, IRQF_DISABLED,
-                       "PPI ERROR", info) < 0) {
+       ret = request_irq(info->irq, bfin_t350mcqb_irq_error, IRQF_DISABLED,
+                       "PPI ERROR", info);
+       if (ret < 0) {
                printk(KERN_ERR DRIVER_NAME
                       ": unable to request PPI ERROR IRQ\n");
-               ret = -EFAULT;
                goto out7;
        }
 
@@ -584,8 +586,6 @@ out7:
        bfin_t350mcqb_request_ports(0);
 out6:
        fb_dealloc_cmap(&fbinfo->cmap);
-out5:
-       kfree(fbinfo->pseudo_palette);
 out4:
        dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
                          info->dma_handle);
@@ -599,12 +599,14 @@ out1:
        return ret;
 }
 
-static int bfin_t350mcqb_remove(struct platform_device *pdev)
+static int __devexit bfin_t350mcqb_remove(struct platform_device *pdev)
 {
 
        struct fb_info *fbinfo = platform_get_drvdata(pdev);
        struct bfin_t350mcqbfb_info *info = fbinfo->par;
 
+       unregister_framebuffer(fbinfo);
+
        free_dma(CH_PPI);
        free_irq(info->irq, info);
 
@@ -612,7 +614,6 @@ static int bfin_t350mcqb_remove(struct platform_device *pdev)
                dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
                                  info->dma_handle);
 
-       kfree(fbinfo->pseudo_palette);
        fb_dealloc_cmap(&fbinfo->cmap);
 
 #ifndef NO_BL_SUPPORT
@@ -620,10 +621,11 @@ static int bfin_t350mcqb_remove(struct platform_device *pdev)
        backlight_device_unregister(bl_dev);
 #endif
 
-       unregister_framebuffer(fbinfo);
-
        bfin_t350mcqb_request_ports(0);
 
+       platform_set_drvdata(pdev, NULL);
+       framebuffer_release(fbinfo);
+
        printk(KERN_INFO DRIVER_NAME ": Unregister LCD driver.\n");
 
        return 0;
@@ -632,9 +634,6 @@ static int bfin_t350mcqb_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM
 static int bfin_t350mcqb_suspend(struct platform_device *pdev, pm_message_t state)
 {
-       struct fb_info *fbinfo = platform_get_drvdata(pdev);
-       struct bfin_t350mcqbfb_info *info = fbinfo->par;
-
        bfin_t350mcqb_disable_ppi();
        disable_dma(CH_PPI);
        bfin_write_PPI_STATUS(0xFFFF);
@@ -644,9 +643,6 @@ static int bfin_t350mcqb_suspend(struct platform_device *pdev, pm_message_t stat
 
 static int bfin_t350mcqb_resume(struct platform_device *pdev)
 {
-       struct fb_info *fbinfo = platform_get_drvdata(pdev);
-       struct bfin_t350mcqbfb_info *info = fbinfo->par;
-
        enable_dma(CH_PPI);
        bfin_t350mcqb_enable_ppi();
 
@@ -659,7 +655,7 @@ static int bfin_t350mcqb_resume(struct platform_device *pdev)
 
 static struct platform_driver bfin_t350mcqb_driver = {
        .probe = bfin_t350mcqb_probe,
-       .remove = bfin_t350mcqb_remove,
+       .remove = __devexit_p(bfin_t350mcqb_remove),
        .suspend = bfin_t350mcqb_suspend,
        .resume = bfin_t350mcqb_resume,
        .driver = {
@@ -668,7 +664,7 @@ static struct platform_driver bfin_t350mcqb_driver = {
                   },
 };
 
-static int __devinit bfin_t350mcqb_driver_init(void)
+static int __init bfin_t350mcqb_driver_init(void)
 {
        return platform_driver_register(&bfin_t350mcqb_driver);
 }