Correct comments in genrtc.c to refer to correct /proc file.
[powerpc.git] / drivers / video / pm2fb.c
index 49a203e..1ac5264 100644 (file)
@@ -33,7 +33,6 @@
 #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>
@@ -82,8 +81,6 @@ static int lowvsync;
 struct pm2fb_par
 {
        pm2type_t       type;           /* Board type */
-       u32             fb_size;        /* framebuffer memory size */
-       unsigned char   __iomem *v_fb;  /* virtual address of frame buffer */
        unsigned char   __iomem *v_regs;/* virtual address of p_regs */
        u32             memclock;       /* memclock */
        u32             video;          /* video flags before blanking */
@@ -104,7 +101,7 @@ static struct fb_fix_screeninfo pm2fb_fix __devinitdata = {
        .xpanstep =     1,
        .ypanstep =     1,
        .ywrapstep =    0, 
-       .accel =        FB_ACCEL_NONE,
+       .accel =        FB_ACCEL_3DLABS_PERMEDIA2,
 };
 
 /*
@@ -207,6 +204,17 @@ static inline void WAIT_FIFO(struct pm2fb_par* p, u32 a)
 }
 #endif
 
+static void wait_pm2(struct pm2fb_par* par) {
+
+       WAIT_FIFO(par, 1);
+       pm2_WR(par, PM2R_SYNC, 0);
+       mb();
+       do {
+               while (pm2_RD(par, PM2R_OUT_FIFO_WORDS) == 0);
+               rmb();
+       } while (pm2_RD(par, PM2R_OUT_FIFO) != PM2TAG(PM2R_SYNC));
+}
+
 /*
  * partial products for the supported horizontal resolutions.
  */
@@ -303,10 +311,10 @@ static void pm2v_mnp(u32 clk, unsigned char* mm, unsigned char* nn,
        s32 delta = 1000;
 
        *mm = *nn = *pp = 0;
-       for (n = 1; n; n++) {
-               for ( m = 1; m; m++) {
+       for ( m = 1; m < 128; m++) {
+               for (n = 2 * m + 1; n; n++) {
                        for ( p = 0; p < 2; p++) {
-                               f = PM2_REFERENCE_CLOCK * n / (m * (1 << (p + 1)));
+                               f = ( PM2_REFERENCE_CLOCK >> ( p + 1 )) * n / m;
                                if ( clk > f - delta && clk < f + delta ) {
                                        delta = ( clk > f ) ? clk - f : f - clk;
                                        *mm=m;
@@ -463,21 +471,43 @@ static void set_memclock(struct pm2fb_par* par, u32 clk)
        int i;
        unsigned char m, n, p;
 
-       pm2_mnp(clk, &m, &n, &p);
-       WAIT_FIFO(par, 10);
-       pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 6);
-       wmb();
-       pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_1, m);
-       pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_2, n);
-       wmb();
-       pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 8|p);
-       wmb();
-       pm2_RDAC_RD(par, PM2I_RD_MEMORY_CLOCK_STATUS);
-       rmb();
-       for (i = 256;
-            i && !(pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED);
-            i--)
-               ;
+       switch (par->type) {
+       case PM2_TYPE_PERMEDIA2V:
+               pm2v_mnp(clk/2, &m, &n, &p);
+               WAIT_FIFO(par, 8);
+               pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_MCLK_CONTROL >> 8);
+               pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 0);
+               wmb();
+               pm2v_RDAC_WR(par, PM2VI_RD_MCLK_PRESCALE, m);
+               pm2v_RDAC_WR(par, PM2VI_RD_MCLK_FEEDBACK, n);
+               pm2v_RDAC_WR(par, PM2VI_RD_MCLK_POSTSCALE, p);
+               wmb();
+               pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 1);
+               rmb();
+               for (i = 256;
+                    i && !(pm2_RDAC_RD(par, PM2VI_RD_MCLK_CONTROL) & 2);
+                    i--)
+                       ;
+               pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
+               break;
+       case PM2_TYPE_PERMEDIA2:
+               pm2_mnp(clk, &m, &n, &p);
+               WAIT_FIFO(par, 10);
+               pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 6);
+               wmb();
+               pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_1, m);
+               pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_2, n);
+               wmb();
+               pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 8|p);
+               wmb();
+               pm2_RDAC_RD(par, PM2I_RD_MEMORY_CLOCK_STATUS);
+               rmb();
+               for (i = 256;
+                    i && !(pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED);
+                    i--)
+                       ;
+               break;
+       }
 }
 
 static void set_pixclock(struct pm2fb_par* par, u32 clk)
@@ -624,6 +654,8 @@ static int pm2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
                return -EINVAL;
        }
 
+       var->transp.offset = 0;
+       var->transp.length = 0;
        switch(var->bits_per_pixel) {
        case 8:
                var->red.length = var->green.length = var->blue.length = 8;
@@ -1018,6 +1050,117 @@ static int pm2fb_blank(int blank_mode, struct fb_info *info)
        return 0;
 }
 
+/*
+ * block operation. copy=0: rectangle fill, copy=1: rectangle copy.
+ */
+static void pm2fb_block_op(struct pm2fb_par* par, int copy,
+                               s32 xsrc, s32 ysrc,
+                               s32 x, s32 y, s32 w, s32 h,
+                               u32 color) {
+
+       if (!w || !h)
+               return;
+       WAIT_FIFO(par, 6);
+       pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE |
+               PM2F_CONFIG_FB_READ_SOURCE_ENABLE);
+       pm2_WR(par, PM2R_FB_PIXEL_OFFSET, 0);
+       if (copy)
+               pm2_WR(par, PM2R_FB_SOURCE_DELTA,
+                       ((ysrc-y) & 0xfff) << 16 | ((xsrc-x) & 0xfff));
+       else
+               pm2_WR(par, PM2R_FB_BLOCK_COLOR, color);
+       pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (y << 16) | x);
+       pm2_WR(par, PM2R_RECTANGLE_SIZE, (h << 16) | w);
+       wmb();
+       pm2_WR(par, PM2R_RENDER,PM2F_RENDER_RECTANGLE |
+                               (x<xsrc ? PM2F_INCREASE_X : 0) |
+                               (y<ysrc ? PM2F_INCREASE_Y : 0) |
+                               (copy ? 0 : PM2F_RENDER_FASTFILL));
+       wait_pm2(par);
+}
+
+static void pm2fb_fillrect (struct fb_info *info,
+                               const struct fb_fillrect *region)
+{
+       struct pm2fb_par *par = info->par;
+       struct fb_fillrect modded;
+       int vxres, vyres;
+       u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
+               ((u32*)info->pseudo_palette)[region->color] : region->color;
+
+       if (info->state != FBINFO_STATE_RUNNING)
+               return;
+       if ((info->flags & FBINFO_HWACCEL_DISABLED) ||
+               region->rop != ROP_COPY ) {
+               cfb_fillrect(info, region);
+               return;
+       }
+
+       vxres = info->var.xres_virtual;
+       vyres = info->var.yres_virtual;
+
+       memcpy(&modded, region, sizeof(struct fb_fillrect));
+
+       if(!modded.width || !modded.height ||
+          modded.dx >= vxres || modded.dy >= vyres)
+               return;
+
+       if(modded.dx + modded.width  > vxres)
+               modded.width  = vxres - modded.dx;
+       if(modded.dy + modded.height > vyres)
+               modded.height = vyres - modded.dy;
+
+       if(info->var.bits_per_pixel == 8)
+               color |= color << 8;
+       if(info->var.bits_per_pixel <= 16)
+               color |= color << 16;
+
+       if(info->var.bits_per_pixel != 24)
+               pm2fb_block_op(par, 0, 0, 0,
+                               modded.dx, modded.dy,
+                               modded.width, modded.height, color);
+       else
+               cfb_fillrect(info, region);
+}
+
+static void pm2fb_copyarea(struct fb_info *info,
+                               const struct fb_copyarea *area)
+{
+       struct pm2fb_par *par = info->par;
+       struct fb_copyarea modded;
+       u32 vxres, vyres;
+
+       if (info->state != FBINFO_STATE_RUNNING)
+               return;
+       if (info->flags & FBINFO_HWACCEL_DISABLED) {
+               cfb_copyarea(info, area);
+               return;
+       }
+
+       memcpy(&modded, area, sizeof(struct fb_copyarea));
+
+       vxres = info->var.xres_virtual;
+       vyres = info->var.yres_virtual;
+
+       if(!modded.width || !modded.height ||
+          modded.sx >= vxres || modded.sy >= vyres ||
+          modded.dx >= vxres || modded.dy >= vyres)
+               return;
+
+       if(modded.sx + modded.width > vxres)
+               modded.width = vxres - modded.sx;
+       if(modded.dx + modded.width > vxres)
+               modded.width = vxres - modded.dx;
+       if(modded.sy + modded.height > vyres)
+               modded.height = vyres - modded.sy;
+       if(modded.dy + modded.height > vyres)
+               modded.height = vyres - modded.dy;
+
+       pm2fb_block_op(par, 1, modded.sx, modded.sy,
+                       modded.dx, modded.dy,
+                       modded.width, modded.height, 0);
+}
+
 /* ------------ Hardware Independent Functions ------------ */
 
 /*
@@ -1031,8 +1174,8 @@ static struct fb_ops pm2fb_ops = {
        .fb_setcolreg   = pm2fb_setcolreg,
        .fb_blank       = pm2fb_blank,
        .fb_pan_display = pm2fb_pan_display,
-       .fb_fillrect    = cfb_fillrect,
-       .fb_copyarea    = cfb_copyarea,
+       .fb_fillrect    = pm2fb_fillrect,
+       .fb_copyarea    = pm2fb_copyarea,
        .fb_imageblit   = cfb_imageblit,
 };
 
@@ -1120,38 +1263,47 @@ static int __devinit pm2fb_probe(struct pci_dev *pdev,
 
        if(default_par->mem_control == 0 &&
                default_par->boot_address == 0x31 &&
-               default_par->mem_config == 0x259fffff &&
-               pdev->subsystem_vendor == 0x1048 &&
-               pdev->subsystem_device == 0x0a31) {
-               DPRINTK("subsystem_vendor: %04x, subsystem_device: %04x\n",
-                       pdev->subsystem_vendor, pdev->subsystem_device);
-               DPRINTK("We have not been initialized by VGA BIOS "
-                       "and are running on an Elsa Winner 2000 Office\n");
-               DPRINTK("Initializing card timings manually...\n");
+               default_par->mem_config == 0x259fffff) {
+               default_par->memclock = CVPPC_MEMCLOCK;
                default_par->mem_control=0;
                default_par->boot_address=0x20;
                default_par->mem_config=0xe6002021;
-               default_par->memclock=100000;
+               if (pdev->subsystem_vendor == 0x1048 &&
+                       pdev->subsystem_device == 0x0a31) {
+                       DPRINTK("subsystem_vendor: %04x, subsystem_device: %04x\n",
+                               pdev->subsystem_vendor, pdev->subsystem_device);
+                       DPRINTK("We have not been initialized by VGA BIOS "
+                               "and are running on an Elsa Winner 2000 Office\n");
+                       DPRINTK("Initializing card timings manually...\n");
+                       default_par->memclock=70000;
+               }
+               if (pdev->subsystem_vendor == 0x3d3d &&
+                       pdev->subsystem_device == 0x0100) {
+                       DPRINTK("subsystem_vendor: %04x, subsystem_device: %04x\n",
+                               pdev->subsystem_vendor, pdev->subsystem_device);
+                       DPRINTK("We have not been initialized by VGA BIOS "
+                               "and are running on an 3dlabs reference board\n");
+                       DPRINTK("Initializing card timings manually...\n");
+                       default_par->memclock=74894;
+               }
        }
 
        /* Now work out how big lfb is going to be. */
        switch(default_par->mem_config & PM2F_MEM_CONFIG_RAM_MASK) {
        case PM2F_MEM_BANKS_1:
-               default_par->fb_size=0x200000;
+               pm2fb_fix.smem_len=0x200000;
                break;
        case PM2F_MEM_BANKS_2:
-               default_par->fb_size=0x400000;
+               pm2fb_fix.smem_len=0x400000;
                break;
        case PM2F_MEM_BANKS_3:
-               default_par->fb_size=0x600000;
+               pm2fb_fix.smem_len=0x600000;
                break;
        case PM2F_MEM_BANKS_4:
-               default_par->fb_size=0x800000;
+               pm2fb_fix.smem_len=0x800000;
                break;
        }
-       default_par->memclock = CVPPC_MEMCLOCK;
        pm2fb_fix.smem_start = pci_resource_start(pdev, 1);
-       pm2fb_fix.smem_len = default_par->fb_size;
 
        /* Linear frame buffer - request region and map it. */
        if ( !request_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len,
@@ -1159,9 +1311,9 @@ static int __devinit pm2fb_probe(struct pci_dev *pdev,
                printk(KERN_WARNING "pm2fb: Can't reserve smem.\n");
                goto err_exit_mmio;
        }
-       info->screen_base = default_par->v_fb =
+       info->screen_base =
                ioremap_nocache(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
-       if ( !default_par->v_fb ) {
+       if ( !info->screen_base ) {
                printk(KERN_WARNING "pm2fb: Can't ioremap smem area.\n");
                release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
                goto err_exit_mmio;
@@ -1171,7 +1323,9 @@ static int __devinit pm2fb_probe(struct pci_dev *pdev,
        info->fix               = pm2fb_fix;    
        info->pseudo_palette    = default_par->palette;
        info->flags             = FBINFO_DEFAULT |
-                                  FBINFO_HWACCEL_YPAN;
+                                  FBINFO_HWACCEL_YPAN |
+                                 FBINFO_HWACCEL_COPYAREA |
+                                 FBINFO_HWACCEL_FILLRECT;
 
        if (!mode)
                mode = "640x480@60";
@@ -1181,13 +1335,13 @@ static int __devinit pm2fb_probe(struct pci_dev *pdev,
                info->var = pm2fb_var;
 
        if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
-               goto err_exit_all;
+               goto err_exit_both;
 
        if (register_framebuffer(info) < 0)
-               goto err_exit_both;
+               goto err_exit_all;
 
        printk(KERN_INFO "fb%d: %s frame buffer device, memory = %dK.\n",
-              info->node, info->fix.id, default_par->fb_size / 1024);
+              info->node, info->fix.id, pm2fb_fix.smem_len / 1024);
 
        /*
         * Our driver data
@@ -1243,6 +1397,9 @@ static struct pci_device_id pm2fb_id_table[] = {
        { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2V,
          PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
          0xff0000, 0 },
+       { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2V,
+         PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NOT_DEFINED_VGA << 8,
+         0xff00, 0 },
        { 0, }
 };