pata_hpt3x2n: fix clock turnaround
[safe/jmp/linux-2.6] / drivers / video / cg6.c
index 137e475..0d47c60 100644 (file)
@@ -17,9 +17,9 @@
 #include <linux/init.h>
 #include <linux/fb.h>
 #include <linux/mm.h>
+#include <linux/of_device.h>
 
 #include <asm/io.h>
-#include <asm/of_device.h>
 #include <asm/fbio.h>
 
 #include "sbuslib.h"
@@ -34,9 +34,11 @@ static int cg6_blank(int, struct fb_info *);
 
 static void cg6_imageblit(struct fb_info *, const struct fb_image *);
 static void cg6_fillrect(struct fb_info *, const struct fb_fillrect *);
+static void cg6_copyarea(struct fb_info *info, const struct fb_copyarea *area);
 static int cg6_sync(struct fb_info *);
 static int cg6_mmap(struct fb_info *, struct vm_area_struct *);
 static int cg6_ioctl(struct fb_info *, unsigned int, unsigned long);
+static int cg6_pan_display(struct fb_var_screeninfo *, struct fb_info *);
 
 /*
  *  Frame buffer operations
@@ -46,8 +48,9 @@ static struct fb_ops cg6_ops = {
        .owner                  = THIS_MODULE,
        .fb_setcolreg           = cg6_setcolreg,
        .fb_blank               = cg6_blank,
+       .fb_pan_display         = cg6_pan_display,
        .fb_fillrect            = cg6_fillrect,
-       .fb_copyarea            = cfb_copyarea,
+       .fb_copyarea            = cg6_copyarea,
        .fb_imageblit           = cg6_imageblit,
        .fb_sync                = cg6_sync,
        .fb_mmap                = cg6_mmap,
@@ -160,6 +163,7 @@ static struct fb_ops cg6_ops = {
 #define CG6_THC_MISC_INT_ENAB          (1 << 5)
 #define CG6_THC_MISC_INT               (1 << 4)
 #define CG6_THC_MISC_INIT              0x9f
+#define CG6_THC_CURSOFF                        ((65536-32) | ((65536-32) << 16))
 
 /* The contents are unknown */
 struct cg6_tec {
@@ -259,9 +263,7 @@ struct cg6_par {
        u32                     flags;
 #define CG6_FLAG_BLANKED       0x00000001
 
-       unsigned long           physbase;
        unsigned long           which_io;
-       unsigned long           fbsize;
 };
 
 static int cg6_sync(struct fb_info *info)
@@ -279,6 +281,33 @@ static int cg6_sync(struct fb_info *info)
        return 0;
 }
 
+static void cg6_switch_from_graph(struct cg6_par *par)
+{
+       struct cg6_thc __iomem *thc = par->thc;
+       unsigned long flags;
+
+       spin_lock_irqsave(&par->lock, flags);
+
+       /* Hide the cursor. */
+       sbus_writel(CG6_THC_CURSOFF, &thc->thc_cursxy);
+
+       spin_unlock_irqrestore(&par->lock, flags);
+}
+
+static int cg6_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
+{
+       struct cg6_par *par = (struct cg6_par *)info->par;
+
+       /* We just use this to catch switches out of
+        * graphics mode.
+        */
+       cg6_switch_from_graph(par);
+
+       if (var->xoffset || var->yoffset || var->vmode)
+               return -EINVAL;
+       return 0;
+}
+
 /**
  *     cg6_fillrect -  Draws a rectangle on the screen.
  *
@@ -292,10 +321,12 @@ static void cg6_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
        unsigned long flags;
        s32 val;
 
-       /* XXX doesn't handle ROP_XOR */
+       /* CG6 doesn't handle ROP_XOR */
 
        spin_lock_irqsave(&par->lock, flags);
+
        cg6_sync(info);
+
        sbus_writel(rect->color, &fbc->fg);
        sbus_writel(~(u32)0, &fbc->pixelm);
        sbus_writel(0xea80ff00, &fbc->alu);
@@ -313,6 +344,48 @@ static void cg6_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
 }
 
 /**
+ *     cg6_copyarea - Copies one area of the screen to another area.
+ *
+ *     @info: frame buffer structure that represents a single frame buffer
+ *     @area: Structure providing the data to copy the framebuffer contents
+ *             from one region to another.
+ *
+ *     This drawing operation copies a rectangular area from one area of the
+ *     screen to another area.
+ */
+static void cg6_copyarea(struct fb_info *info, const struct fb_copyarea *area)
+{
+       struct cg6_par *par = (struct cg6_par *)info->par;
+       struct cg6_fbc __iomem *fbc = par->fbc;
+       unsigned long flags;
+       int i;
+
+       spin_lock_irqsave(&par->lock, flags);
+
+       cg6_sync(info);
+
+       sbus_writel(0xff, &fbc->fg);
+       sbus_writel(0x00, &fbc->bg);
+       sbus_writel(~0, &fbc->pixelm);
+       sbus_writel(0xe880cccc, &fbc->alu);
+       sbus_writel(0, &fbc->s);
+       sbus_writel(0, &fbc->clip);
+
+       sbus_writel(area->sy, &fbc->y0);
+       sbus_writel(area->sx, &fbc->x0);
+       sbus_writel(area->sy + area->height - 1, &fbc->y1);
+       sbus_writel(area->sx + area->width - 1, &fbc->x1);
+       sbus_writel(area->dy, &fbc->y2);
+       sbus_writel(area->dx, &fbc->x2);
+       sbus_writel(area->dy + area->height - 1, &fbc->y3);
+       sbus_writel(area->dx + area->width - 1, &fbc->x3);
+       do {
+               i = sbus_readl(&fbc->blit);
+       } while (i < 0 && (i & 0x20000000));
+       spin_unlock_irqrestore(&par->lock, flags);
+}
+
+/**
  *     cg6_imageblit - Copies a image from system memory to the screen.
  *
  *     @info: frame buffer structure that represents a single frame buffer
@@ -521,16 +594,14 @@ static int cg6_mmap(struct fb_info *info, struct vm_area_struct *vma)
        struct cg6_par *par = (struct cg6_par *)info->par;
 
        return sbusfb_mmap_helper(cg6_mmap_map,
-                                 par->physbase, par->fbsize,
+                                 info->fix.smem_start, info->fix.smem_len,
                                  par->which_io, vma);
 }
 
 static int cg6_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
 {
-       struct cg6_par *par = (struct cg6_par *)info->par;
-
        return sbusfb_ioctl_helper(cmd, arg, info,
-                                  FBTYPE_SUNFAST_COLOR, 8, par->fbsize);
+                                  FBTYPE_SUNFAST_COLOR, 8, info->fix.smem_len);
 }
 
 /*
@@ -556,12 +627,12 @@ static void __devinit cg6_init_fix(struct fb_info *info, int linebytes)
                break;
        };
        if (((conf >> CG6_FHC_REV_SHIFT) & CG6_FHC_REV_MASK) >= 11) {
-               if (par->fbsize <= 0x100000)
+               if (info->fix.smem_len <= 0x100000)
                        cg6_card_name = "TGX";
                else
                        cg6_card_name = "TGX+";
        } else {
-               if (par->fbsize <= 0x100000)
+               if (info->fix.smem_len <= 0x100000)
                        cg6_card_name = "GX";
                else
                        cg6_card_name = "GX+";
@@ -598,9 +669,13 @@ static void __devinit cg6_chip_init(struct fb_info *info)
        struct cg6_par *par = (struct cg6_par *)info->par;
        struct cg6_tec __iomem *tec = par->tec;
        struct cg6_fbc __iomem *fbc = par->fbc;
+       struct cg6_thc __iomem *thc = par->thc;
        u32 rev, conf, mode;
        int i;
 
+       /* Hide the cursor. */
+       sbus_writel(CG6_THC_CURSOFF, &thc->thc_cursxy);
+
        /* Turn off stuff in the Transform Engine. */
        sbus_writel(0, &tec->tec_matrix);
        sbus_writel(0, &tec->tec_clip);
@@ -659,7 +734,8 @@ static void cg6_unmap_regs(struct of_device *op, struct fb_info *info,
                of_iounmap(&op->resource[0], par->fhc, sizeof(u32));
 
        if (info->screen_base)
-               of_iounmap(&op->resource[0], info->screen_base, par->fbsize);
+               of_iounmap(&op->resource[0], info->screen_base,
+                          info->fix.smem_len);
 }
 
 static int __devinit cg6_probe(struct of_device *op,
@@ -680,21 +756,21 @@ static int __devinit cg6_probe(struct of_device *op,
 
        spin_lock_init(&par->lock);
 
-       par->physbase = op->resource[0].start;
+       info->fix.smem_start = op->resource[0].start;
        par->which_io = op->resource[0].flags & IORESOURCE_BITS;
 
-       sbusfb_fill_var(&info->var, dp->node, 8);
+       sbusfb_fill_var(&info->var, dp, 8);
        info->var.red.length = 8;
        info->var.green.length = 8;
        info->var.blue.length = 8;
 
        linebytes = of_getintprop_default(dp, "linebytes",
                                          info->var.xres);
-       par->fbsize = PAGE_ALIGN(linebytes * info->var.yres);
+       info->fix.smem_len = PAGE_ALIGN(linebytes * info->var.yres);
 
        dblbuf = of_getintprop_default(dp, "dblbuf", 0);
        if (dblbuf)
-               par->fbsize *= 4;
+               info->fix.smem_len *= 4;
 
        par->fbc = of_ioremap(&op->resource[0], CG6_FBC_OFFSET,
                                4096, "cgsix fbc");
@@ -708,11 +784,12 @@ static int __devinit cg6_probe(struct of_device *op,
                                sizeof(u32), "cgsix fhc");
 
        info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_IMAGEBLIT |
-                       FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT;
+                       FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
+                       FBINFO_READS_FAST;
        info->fbops = &cg6_ops;
 
        info->screen_base = of_ioremap(&op->resource[0], CG6_RAM_OFFSET,
-                                       par->fbsize, "cgsix ram");
+                                       info->fix.smem_len, "cgsix ram");
        if (!par->fbc || !par->tec || !par->thc ||
            !par->bt || !par->fhc || !info->screen_base)
                goto out_unmap_regs;
@@ -721,7 +798,7 @@ static int __devinit cg6_probe(struct of_device *op,
 
        cg6_bt_init(par);
        cg6_chip_init(info);
-       cg6_blank(0, info);
+       cg6_blank(FB_BLANK_UNBLANK, info);
 
        if (fb_alloc_cmap(&info->cmap, 256, 0))
                goto out_unmap_regs;
@@ -735,9 +812,9 @@ static int __devinit cg6_probe(struct of_device *op,
 
        dev_set_drvdata(&op->dev, info);
 
-       printk("%s: CGsix [%s] at %lx:%lx\n",
+       printk(KERN_INFO "%s: CGsix [%s] at %lx:%lx\n",
               dp->full_name, info->fix.id,
-              par->which_io, par->physbase);
+              par->which_io, info->fix.smem_start);
 
        return 0;
 
@@ -768,7 +845,7 @@ static int __devexit cg6_remove(struct of_device *op)
        return 0;
 }
 
-static struct of_device_id cg6_match[] = {
+static const struct of_device_id cg6_match[] = {
        {
                .name = "cgsix",
        },