fbdev: move FBIO_WAITFORVSYNC to linux/fb.h
[safe/jmp/linux-2.6] / drivers / video / pvr2fb.c
index 2ba959a..f997510 100644 (file)
@@ -1,16 +1,12 @@
-/* drivers/video/pvr2fb.c
+/*
+ * drivers/video/pvr2fb.c
  *
  * Frame buffer and fbcon support for the NEC PowerVR2 found within the Sega
  * Dreamcast.
  *
  * Copyright (c) 2001 M. R. Brown <mrbrown@0xd6.org>
- * Copyright (c) 2001, 2002, 2003, 2004, 2005 Paul Mundt <lethal@linux-sh.org>
- *
- * This file is part of the LinuxDC project (linuxdc.sourceforge.net).
+ * Copyright (c) 2001 - 2008  Paul Mundt <lethal@linux-sh.org>
  *
- */
-
-/*
  * This driver is mostly based on the excellent amifb and vfb sources.  It uses
  * an odd scheme for converting hardware values to/from framebuffer values,
  * here are some hacked-up formulas:
 
 #ifdef CONFIG_SH_DREAMCAST
 #include <asm/machvec.h>
-#include <asm/mach/sysasic.h>
+#include <mach-dreamcast/mach/sysasic.h>
 #endif
 
-#ifdef CONFIG_SH_DMA
+#ifdef CONFIG_PVR2_DMA
 #include <linux/pagemap.h>
-#include <asm/mach/dma.h>
+#include <mach/dma.h>
 #include <asm/dma.h>
 #endif
 
 #ifdef CONFIG_SH_STORE_QUEUES
-#include <asm/uaccess.h>
-#include <asm/cpu/sq.h>
+#include <linux/uaccess.h>
+#include <cpu/sq.h>
 #endif
 
 #ifndef PCI_DEVICE_ID_NEC_NEON250
@@ -94,6 +90,7 @@
 #define DISP_DIWCONF (DISP_BASE + 0xe8)
 #define DISP_DIWHSTRT (DISP_BASE + 0xec)
 #define DISP_DIWVSTRT (DISP_BASE + 0xf0)
+#define DISP_PIXDEPTH (DISP_BASE + 0x108)
 
 /* Pixel clocks, one for TV output, doubled for VGA output */
 #define TV_CLK 74239
@@ -143,6 +140,7 @@ static struct pvr2fb_par {
        unsigned char is_lowres;        /* Is horizontal pixel-doubling enabled? */
 
        unsigned long mmio_base;        /* MMIO base */
+       u32 palette[16];
 } *currentpar;
 
 static struct fb_info *fb_info;
@@ -190,7 +188,7 @@ static unsigned int is_blanked = 0;         /* Is the screen blanked? */
 static unsigned long pvr2fb_map;
 #endif
 
-#ifdef CONFIG_SH_DMA
+#ifdef CONFIG_PVR2_DMA
 static unsigned int shdma = PVR2_CASCADE_CHAN;
 static unsigned int pvr2dma = ONCHIP_NR_DMA_CHANNELS;
 #endif
@@ -209,7 +207,7 @@ static irqreturn_t pvr2fb_interrupt(int irq, void *dev_id);
 static int pvr2_init_cable(void);
 static int pvr2_get_param(const struct pvr2_params *p, const char *s,
                             int val, int size);
-#ifdef CONFIG_SH_DMA
+#ifdef CONFIG_PVR2_DMA
 static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
                            size_t count, loff_t *ppos);
 #endif
@@ -220,7 +218,7 @@ static struct fb_ops pvr2fb_ops = {
        .fb_blank       = pvr2fb_blank,
        .fb_check_var   = pvr2fb_check_var,
        .fb_set_par     = pvr2fb_set_par,
-#ifdef CONFIG_SH_DMA
+#ifdef CONFIG_PVR2_DMA
        .fb_write       = pvr2fb_write,
 #endif
        .fb_fillrect    = cfb_fillrect,
@@ -333,24 +331,25 @@ static int pvr2fb_setcolreg(unsigned int regno, unsigned int red,
                      ((blue  & 0xf800) >> 11);
 
                pvr2fb_set_pal_entry(par, regno, tmp);
-               ((u16*)(info->pseudo_palette))[regno] = tmp;
                break;
            case 24: /* RGB 888 */
                red >>= 8; green >>= 8; blue >>= 8;
-               ((u32*)(info->pseudo_palette))[regno] = (red << 16) | (green << 8) | blue;
+               tmp = (red << 16) | (green << 8) | blue;
                break;
            case 32: /* ARGB 8888 */
                red >>= 8; green >>= 8; blue >>= 8;
                tmp = (transp << 24) | (red << 16) | (green << 8) | blue;
 
                pvr2fb_set_pal_entry(par, regno, tmp);
-               ((u32*)(info->pseudo_palette))[regno] = tmp;
                break;
            default:
                pr_debug("Invalid bit depth %d?!?\n", info->var.bits_per_pixel);
                return 1;
        }
 
+       if (regno < 16)
+               ((u32*)(info->pseudo_palette))[regno] = tmp;
+
        return 0;
 }
 
@@ -487,7 +486,7 @@ static int pvr2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
        } else {
                var->sync &= ~FB_SYNC_BROADCAST;
                var->vmode &= ~FB_VMODE_INTERLACED;
-               var->vmode |= pvr2_var.vmode;
+               var->vmode |= FB_VMODE_NONINTERLACED;
        }
 
        if ((var->activate & FB_ACTIVATE_MASK) != FB_ACTIVATE_TEST) {
@@ -598,6 +597,7 @@ static void pvr2_init_display(struct fb_info *info)
 
        /* bits per pixel */
        fb_writel(fb_readl(DISP_DIWMODE) | (--bytesperpixel << 2), DISP_DIWMODE);
+       fb_writel(bytesperpixel << 2, DISP_PIXDEPTH);
 
        /* video enable, color sync, interlace,
         * hsync and vsync polarity (currently unused) */
@@ -663,13 +663,15 @@ static int pvr2_init_cable(void)
          related */
        if (cable_type == CT_COMPOSITE)
                fb_writel(3 << 8, VOUTC);
+       else if (cable_type == CT_RGB)
+               fb_writel(1 << 9, VOUTC);
        else
                fb_writel(0, VOUTC);
 
        return cable_type;
 }
 
-#ifdef CONFIG_SH_DMA
+#ifdef CONFIG_PVR2_DMA
 static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
                            size_t count, loff_t *ppos)
 {
@@ -741,7 +743,7 @@ out_unmap:
 
        return ret;
 }
-#endif /* CONFIG_SH_DMA */
+#endif /* CONFIG_PVR2_DMA */
 
 /**
  * pvr2fb_common_init
@@ -789,7 +791,7 @@ static int __devinit pvr2fb_common_init(void)
        fb_info->fbops          = &pvr2fb_ops;
        fb_info->fix            = pvr2_fix;
        fb_info->par            = currentpar;
-       fb_info->pseudo_palette = (void *)(fb_info->par + 1);
+       fb_info->pseudo_palette = currentpar->palette;
        fb_info->flags          = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
 
        if (video_output == VO_VGA)
@@ -806,6 +808,8 @@ static int __devinit pvr2fb_common_init(void)
 
        if (register_framebuffer(fb_info) < 0)
                goto out_err;
+       /*Must write PIXDEPTH to register before anything is displayed - so force init */
+       pvr2_init_display(fb_info);
 
        modememused = get_line_length(fb_info->var.xres_virtual,
                                      fb_info->var.bits_per_pixel);
@@ -827,7 +831,7 @@ static int __devinit pvr2fb_common_init(void)
        printk(KERN_NOTICE "fb%d: registering with SQ API\n", fb_info->node);
 
        pvr2fb_map = sq_remap(fb_info->fix.smem_start, fb_info->fix.smem_len,
-                             fb_info->fix.id, pgprot_val(PAGE_SHARED));
+                             fb_info->fix.id, PAGE_SHARED);
 
        printk(KERN_NOTICE "fb%d: Mapped video memory to SQ addr 0x%lx\n",
               fb_info->node, pvr2fb_map);
@@ -884,12 +888,12 @@ static int __init pvr2fb_dc_init(void)
        pvr2_fix.mmio_start     = 0xa05f8000;   /* registers start here */
        pvr2_fix.mmio_len       = 0x2000;
 
-       if (request_irq(HW_EVENT_VSYNC, pvr2fb_interrupt, 0,
+       if (request_irq(HW_EVENT_VSYNC, pvr2fb_interrupt, IRQF_SHARED,
                        "pvr2 VBL handler", fb_info)) {
                return -EBUSY;
        }
 
-#ifdef CONFIG_SH_DMA
+#ifdef CONFIG_PVR2_DMA
        if (request_dma(pvr2dma, "pvr2") != 0) {
                free_irq(HW_EVENT_VSYNC, 0);
                return -EBUSY;
@@ -911,7 +915,7 @@ static void __exit pvr2fb_dc_exit(void)
        }
 
        free_irq(HW_EVENT_VSYNC, 0);
-#ifdef CONFIG_SH_DMA
+#ifdef CONFIG_PVR2_DMA
        free_dma(pvr2dma);
 #endif
 }
@@ -1081,15 +1085,15 @@ static int __init pvr2fb_init(void)
 #endif
        size = sizeof(struct fb_info) + sizeof(struct pvr2fb_par) + 16 * sizeof(u32);
 
-       fb_info = kmalloc(size, GFP_KERNEL);
+       fb_info = framebuffer_alloc(sizeof(struct pvr2fb_par), NULL);
+
        if (!fb_info) {
                printk(KERN_ERR "Failed to allocate memory for fb_info\n");
                return -ENOMEM;
        }
 
-       memset(fb_info, 0, size);
 
-       currentpar = (struct pvr2fb_par *)(fb_info + 1);
+       currentpar = fb_info->par;
 
        for (i = 0; i < ARRAY_SIZE(board_driver); i++) {
                struct pvr2_board *pvr_board = board_driver + i;
@@ -1102,7 +1106,7 @@ static int __init pvr2fb_init(void)
                if (ret != 0) {
                        printk(KERN_ERR "pvr2fb: Failed init of %s device\n",
                                pvr_board->name);
-                       kfree(fb_info);
+                       framebuffer_release(fb_info);
                        break;
                }
        }
@@ -1126,7 +1130,7 @@ static void __exit pvr2fb_exit(void)
 #endif
 
        unregister_framebuffer(fb_info);
-       kfree(fb_info);
+       framebuffer_release(fb_info);
 }
 
 module_init(pvr2fb_init);