]> Pileus Git - ~andy/linux/blobdiff - drivers/video/tdfxfb.c
Merge branch 'nommu' of master.kernel.org:/home/rmk/linux-2.6-arm
[~andy/linux] / drivers / video / tdfxfb.c
index c8b0be2d8715dd07281dfaca797cab6e58200ddf..5e5328d682db52aee991d6b48fa11951395250ba 100644 (file)
@@ -184,7 +184,6 @@ static struct fb_ops tdfxfb_ops = {
        .fb_copyarea    = cfb_copyarea,
        .fb_imageblit   = cfb_imageblit,
 #endif
-       .fb_cursor      = soft_cursor,
 };
 
 /*
@@ -292,7 +291,7 @@ static inline void banshee_make_room(struct tdfx_par *par, int size)
  
 static int banshee_wait_idle(struct fb_info *info)
 {
-       struct tdfx_par *par = (struct tdfx_par *) info->par; 
+       struct tdfx_par *par = info->par;
        int i = 0;
 
        banshee_make_room(par, 1);
@@ -365,7 +364,7 @@ static u32 do_calc_pll(int freq, int* freq_out)
 
 static void do_write_regs(struct fb_info *info, struct banshee_reg* reg) 
 {
-       struct tdfx_par *par = (struct tdfx_par *) info->par; 
+       struct tdfx_par *par = info->par;
        int i;
 
        banshee_wait_idle(info);
@@ -430,36 +429,35 @@ static void do_write_regs(struct fb_info *info, struct banshee_reg* reg)
 
 static unsigned long do_lfb_size(struct tdfx_par *par, unsigned short dev_id) 
 {
-       u32 draminit0 = 0;
-       u32 draminit1 = 0;
-       u32 miscinit1 = 0;
-       u32 lfbsize   = 0;
-       int sgram_p   = 0;
+       u32 draminit0;
+       u32 draminit1;
+       u32 miscinit1;
+
+       int num_chips;
+       int chip_size; /* in MB */
+       u32 lfbsize;
+       int has_sgram;
 
        draminit0 = tdfx_inl(par, DRAMINIT0);  
        draminit1 = tdfx_inl(par, DRAMINIT1);
+
+       num_chips = (draminit0 & DRAMINIT0_SGRAM_NUM) ? 8 : 4;
  
-       if ((dev_id == PCI_DEVICE_ID_3DFX_BANSHEE) ||
-           (dev_id == PCI_DEVICE_ID_3DFX_VOODOO3)) {                    
-               sgram_p = (draminit1 & DRAMINIT1_MEM_SDRAM) ? 0 : 1;
-  
-       lfbsize = sgram_p ?
-               (((draminit0 & DRAMINIT0_SGRAM_NUM)  ? 2 : 1) * 
-               ((draminit0 & DRAMINIT0_SGRAM_TYPE) ? 8 : 4) * 1024 * 1024) :
-               16 * 1024 * 1024;
+       if (dev_id < PCI_DEVICE_ID_3DFX_VOODOO5) {
+               /* Banshee/Voodoo3 */
+               has_sgram = draminit1 & DRAMINIT1_MEM_SDRAM;
+               chip_size = has_sgram ? ((draminit0 & DRAMINIT0_SGRAM_TYPE) ? 2 : 1)
+                                     : 2;
        } else {
                /* Voodoo4/5 */
-               u32 chips, psize, banks;
-
-               chips = ((draminit0 & (1 << 26)) == 0) ? 4 : 8;
-               psize = 1 << ((draminit0 & 0x38000000) >> 28);
-               banks = ((draminit0 & (1 << 30)) == 0) ? 2 : 4;
-               lfbsize = chips * psize * banks;
-               lfbsize <<= 20;
-       }                 
-       /* disable block writes for SDRAM (why?) */
+               has_sgram = 0;
+               chip_size = 1 << ((draminit0 & DRAMINIT0_SGRAM_TYPE_MASK) >> DRAMINIT0_SGRAM_TYPE_SHIFT);
+       }
+       lfbsize = num_chips * chip_size * 1024 * 1024;
+
+       /* disable block writes for SDRAM */
        miscinit1 = tdfx_inl(par, MISCINIT1);
-       miscinit1 |= sgram_p ? 0 : MISCINIT1_2DBLOCK_DIS;
+       miscinit1 |= has_sgram ? 0 : MISCINIT1_2DBLOCK_DIS;
        miscinit1 |= MISCINIT1_CLUT_INV;
 
        banshee_make_room(par, 1); 
@@ -471,7 +469,7 @@ static unsigned long do_lfb_size(struct tdfx_par *par, unsigned short dev_id)
 
 static int tdfxfb_check_var(struct fb_var_screeninfo *var,struct fb_info *info) 
 {
-       struct tdfx_par *par = (struct tdfx_par *) info->par; 
+       struct tdfx_par *par = info->par;
        u32 lpitch;
 
        if (var->bits_per_pixel != 8  && var->bits_per_pixel != 16 &&
@@ -560,7 +558,7 @@ static int tdfxfb_check_var(struct fb_var_screeninfo *var,struct fb_info *info)
 
 static int tdfxfb_set_par(struct fb_info *info)
 {
-       struct tdfx_par *par = (struct tdfx_par *) info->par;   
+       struct tdfx_par *par = info->par;
        u32 hdispend, hsyncsta, hsyncend, htotal;
        u32 hd, hs, he, ht, hbs, hbe;
        u32 vd, vs, ve, vt, vbs, vbe;
@@ -782,37 +780,45 @@ static int tdfxfb_set_par(struct fb_info *info)
 static int tdfxfb_setcolreg(unsigned regno, unsigned red, unsigned green,  
                            unsigned blue,unsigned transp,struct fb_info *info) 
 {
-       struct tdfx_par *par = (struct tdfx_par *) info->par;
+       struct tdfx_par *par = info->par;
        u32 rgbcol;
    
        if (regno >= info->cmap.len || regno > 255) return 1;
    
        switch (info->fix.visual) {
-               case FB_VISUAL_PSEUDOCOLOR:
-                       rgbcol =(((u32)red   & 0xff00) << 8) |
-                               (((u32)green & 0xff00) << 0) |
-                               (((u32)blue  & 0xff00) >> 8);
-                       do_setpalentry(par, regno, rgbcol);
-                       break;
-               /* Truecolor has no hardware color palettes. */
-               case FB_VISUAL_TRUECOLOR:
-                       rgbcol = (CNVT_TOHW( red, info->var.red.length) << info->var.red.offset) |
-                                (CNVT_TOHW( green, info->var.green.length) << info->var.green.offset) |
-                                (CNVT_TOHW( blue, info->var.blue.length) << info->var.blue.offset) |
-                                (CNVT_TOHW( transp, info->var.transp.length) << info->var.transp.offset);
-                               ((u32*)(info->pseudo_palette))[regno] = rgbcol;
-                       break;
-               default:
-                       DPRINTK("bad depth %u\n", info->var.bits_per_pixel);
-                       break;
+       case FB_VISUAL_PSEUDOCOLOR:
+               rgbcol =(((u32)red   & 0xff00) << 8) |
+                       (((u32)green & 0xff00) << 0) |
+                       (((u32)blue  & 0xff00) >> 8);
+               do_setpalentry(par, regno, rgbcol);
+               break;
+       /* Truecolor has no hardware color palettes. */
+       case FB_VISUAL_TRUECOLOR:
+               if (regno < 16) {
+                       rgbcol = (CNVT_TOHW( red, info->var.red.length) <<
+                                 info->var.red.offset) |
+                               (CNVT_TOHW( green, info->var.green.length) <<
+                                info->var.green.offset) |
+                               (CNVT_TOHW( blue, info->var.blue.length) <<
+                                info->var.blue.offset) |
+                               (CNVT_TOHW( transp, info->var.transp.length) <<
+                                info->var.transp.offset);
+                       par->palette[regno] = rgbcol;
+               }
+
+               break;
+       default:
+               DPRINTK("bad depth %u\n", info->var.bits_per_pixel);
+               break;
        }
+
        return 0;
 }
 
 /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
 static int tdfxfb_blank(int blank, struct fb_info *info)
 { 
-       struct tdfx_par *par = (struct tdfx_par *) info->par;
+       struct tdfx_par *par = info->par;
        u32 dacmode, state = 0, vgablank = 0;
 
        dacmode = tdfx_inl(par, DACMODE);
@@ -857,7 +863,7 @@ static int tdfxfb_blank(int blank, struct fb_info *info)
 static int tdfxfb_pan_display(struct fb_var_screeninfo *var,
                              struct fb_info *info) 
 {
-       struct tdfx_par *par = (struct tdfx_par *) info->par;
+       struct tdfx_par *par = info->par;
        u32 addr;       
 
        if (nopan || var->xoffset || (var->yoffset > var->yres_virtual))
@@ -880,7 +886,7 @@ static int tdfxfb_pan_display(struct fb_var_screeninfo *var,
  */
 static void tdfxfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) 
 {
-       struct tdfx_par *par = (struct tdfx_par *) info->par;
+       struct tdfx_par *par = info->par;
        u32 bpp = info->var.bits_per_pixel;
        u32 stride = info->fix.line_length;
        u32 fmt= stride | ((bpp+((bpp==8) ? 0 : 8)) << 13); 
@@ -896,7 +902,7 @@ static void tdfxfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect
        if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
                tdfx_outl(par,  COLORFORE, rect->color);
        } else { /* FB_VISUAL_TRUECOLOR */
-               tdfx_outl(par, COLORFORE, ((u32*)(info->pseudo_palette))[rect->color]);
+               tdfx_outl(par, COLORFORE, par->palette[rect->color]);
        }
        tdfx_outl(par,  COMMAND_2D, COMMAND_2D_FILLRECT | (tdfx_rop << 24));
        tdfx_outl(par,  DSTSIZE,    rect->width | (rect->height << 16));
@@ -908,7 +914,7 @@ static void tdfxfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect
  */
 static void tdfxfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)  
 {
-       struct tdfx_par *par = (struct tdfx_par *) info->par;
+       struct tdfx_par *par = info->par;
        u32 sx = area->sx, sy = area->sy, dx = area->dx, dy = area->dy;
        u32 bpp = info->var.bits_per_pixel;
        u32 stride = info->fix.line_length;
@@ -940,7 +946,7 @@ static void tdfxfb_copyarea(struct fb_info *info, const struct fb_copyarea *area
 
 static void tdfxfb_imageblit(struct fb_info *info, const struct fb_image *image) 
 {
-       struct tdfx_par *par = (struct tdfx_par *) info->par;
+       struct tdfx_par *par = info->par;
        int size = image->height * ((image->width * image->depth + 7)>>3);
        int fifo_free;
        int i, stride = info->fix.line_length;
@@ -963,8 +969,10 @@ static void tdfxfb_imageblit(struct fb_info *info, const struct fb_image *image)
                                break;
                        case FB_VISUAL_TRUECOLOR:
                        default:
-                               tdfx_outl(par, COLORFORE, ((u32*)(info->pseudo_palette))[image->fg_color]);
-                               tdfx_outl(par, COLORBACK, ((u32*)(info->pseudo_palette))[image->bg_color]);
+                               tdfx_outl(par, COLORFORE,
+                                         par->palette[image->fg_color]);
+                               tdfx_outl(par, COLORBACK,
+                                         par->palette[image->bg_color]);
                }
 #ifdef __BIG_ENDIAN
                srcfmt = 0x400000 | BIT(20);
@@ -1009,7 +1017,7 @@ static void tdfxfb_imageblit(struct fb_info *info, const struct fb_image *image)
 #ifdef TDFX_HARDWARE_CURSOR
 static int tdfxfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
 {
-       struct tdfx_par *par = (struct tdfx_par *) info->par;
+       struct tdfx_par *par = info->par;
        unsigned long flags;
 
        /*
@@ -1159,18 +1167,17 @@ static int __devinit tdfxfb_probe(struct pci_dev *pdev,
 {
        struct tdfx_par *default_par;
        struct fb_info *info;
-       int size, err, lpitch;
+       int err, lpitch;
 
        if ((err = pci_enable_device(pdev))) {
                printk(KERN_WARNING "tdfxfb: Can't enable pdev: %d\n", err);
                return err;
        }
 
-       size = sizeof(struct tdfx_par)+256*sizeof(u32);
-
-       info = framebuffer_alloc(size, &pdev->dev);
+       info = framebuffer_alloc(sizeof(struct tdfx_par), &pdev->dev);
 
-       if (!info)      return -ENOMEM;
+       if (!info)
+               return -ENOMEM;
                
        default_par = info->par;
  
@@ -1250,7 +1257,7 @@ static int __devinit tdfxfb_probe(struct pci_dev *pdev,
    
        info->fbops             = &tdfxfb_ops;
        info->fix               = tdfx_fix;     
-       info->pseudo_palette    = (void *)(default_par + 1); 
+       info->pseudo_palette    = default_par->palette;
        info->flags             = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
 #ifdef CONFIG_FB_3DFX_ACCEL
        info->flags             |= FBINFO_HWACCEL_FILLRECT |
@@ -1309,7 +1316,7 @@ out_err:
 }
 
 #ifndef MODULE
-void tdfxfb_setup(char *options)
+static void tdfxfb_setup(char *options)
 {
        char* this_opt;
 
@@ -1342,7 +1349,7 @@ void tdfxfb_setup(char *options)
 static void __devexit tdfxfb_remove(struct pci_dev *pdev)
 {
        struct fb_info *info = pci_get_drvdata(pdev);
-       struct tdfx_par *par = (struct tdfx_par *) info->par;
+       struct tdfx_par *par = info->par;
 
        unregister_framebuffer(info);
        iounmap(par->regbase_virt);