Merge branch 'topic/hda' into for-linus
[pandora-kernel.git] / drivers / video / cfbfillrect.c
index 23d70a1..ba9f58b 100644 (file)
@@ -9,10 +9,6 @@
  *
  * NOTES:
  *
- *  The code for depths like 24 that don't have integer number of pixels per
- *  long is broken and needs to be fixed. For now I turned these types of
- *  mode off.
- *
  *  Also need to add code to deal with cards endians that are different than
  *  the native cpu endians. I also need to deal with MSB position in the word.
  *
      */
 
 static void
-bitfill_aligned(unsigned long __iomem *dst, int dst_idx, unsigned long pat,
-               unsigned n, int bits, u32 bswapmask)
+bitfill_aligned(struct fb_info *p, unsigned long __iomem *dst, int dst_idx,
+               unsigned long pat, unsigned n, int bits, u32 bswapmask)
 {
        unsigned long first, last;
 
        if (!n)
                return;
 
-       first = fb_shifted_pixels_mask_long(dst_idx, bswapmask);
-       last = ~fb_shifted_pixels_mask_long((dst_idx+n) % bits, bswapmask);
+       first = fb_shifted_pixels_mask_long(p, dst_idx, bswapmask);
+       last = ~fb_shifted_pixels_mask_long(p, (dst_idx+n) % bits, bswapmask);
 
        if (dst_idx+n <= bits) {
                // Single word
@@ -93,16 +89,16 @@ bitfill_aligned(unsigned long __iomem *dst, int dst_idx, unsigned long pat,
      */
 
 static void
-bitfill_unaligned(unsigned long __iomem *dst, int dst_idx, unsigned long pat,
-                       int left, int right, unsigned n, int bits)
+bitfill_unaligned(struct fb_info *p, unsigned long __iomem *dst, int dst_idx,
+                 unsigned long pat, int left, int right, unsigned n, int bits)
 {
        unsigned long first, last;
 
        if (!n)
                return;
 
-       first = FB_SHIFT_HIGH(~0UL, dst_idx);
-       last = ~(FB_SHIFT_HIGH(~0UL, (dst_idx+n) % bits));
+       first = FB_SHIFT_HIGH(p, ~0UL, dst_idx);
+       last = ~(FB_SHIFT_HIGH(p, ~0UL, (dst_idx+n) % bits));
 
        if (dst_idx+n <= bits) {
                // Single word
@@ -139,7 +135,7 @@ bitfill_unaligned(unsigned long __iomem *dst, int dst_idx, unsigned long pat,
 
                // Trailing bits
                if (last)
-                       FB_WRITEL(comp(pat, FB_READL(dst), first), dst);
+                       FB_WRITEL(comp(pat, FB_READL(dst), last), dst);
        }
 }
 
@@ -147,8 +143,9 @@ bitfill_unaligned(unsigned long __iomem *dst, int dst_idx, unsigned long pat,
      *  Aligned pattern invert using 32/64-bit memory accesses
      */
 static void
-bitfill_aligned_rev(unsigned long __iomem *dst, int dst_idx, unsigned long pat,
-               unsigned n, int bits, u32 bswapmask)
+bitfill_aligned_rev(struct fb_info *p, unsigned long __iomem *dst,
+                   int dst_idx, unsigned long pat, unsigned n, int bits,
+                   u32 bswapmask)
 {
        unsigned long val = pat, dat;
        unsigned long first, last;
@@ -156,8 +153,8 @@ bitfill_aligned_rev(unsigned long __iomem *dst, int dst_idx, unsigned long pat,
        if (!n)
                return;
 
-       first = fb_shifted_pixels_mask_long(dst_idx, bswapmask);
-       last = ~fb_shifted_pixels_mask_long((dst_idx+n) % bits, bswapmask);
+       first = fb_shifted_pixels_mask_long(p, dst_idx, bswapmask);
+       last = ~fb_shifted_pixels_mask_long(p, (dst_idx+n) % bits, bswapmask);
 
        if (dst_idx+n <= bits) {
                // Single word
@@ -217,16 +214,17 @@ bitfill_aligned_rev(unsigned long __iomem *dst, int dst_idx, unsigned long pat,
      */
 
 static void
-bitfill_unaligned_rev(unsigned long __iomem *dst, int dst_idx, unsigned long pat,
-                       int left, int right, unsigned n, int bits)
+bitfill_unaligned_rev(struct fb_info *p, unsigned long __iomem *dst,
+                     int dst_idx, unsigned long pat, int left, int right,
+                     unsigned n, int bits)
 {
        unsigned long first, last, dat;
 
        if (!n)
                return;
 
-       first = FB_SHIFT_HIGH(~0UL, dst_idx);
-       last = ~(FB_SHIFT_HIGH(~0UL, (dst_idx+n) % bits));
+       first = FB_SHIFT_HIGH(p, ~0UL, dst_idx);
+       last = ~(FB_SHIFT_HIGH(p, ~0UL, (dst_idx+n) % bits));
 
        if (dst_idx+n <= bits) {
                // Single word
@@ -279,7 +277,7 @@ bitfill_unaligned_rev(unsigned long __iomem *dst, int dst_idx, unsigned long pat
 
 void cfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
 {
-       unsigned long pat, fg;
+       unsigned long pat, pat2, fg;
        unsigned long width = rect->width, height = rect->height;
        int bits = BITS_PER_LONG, bytes = bits >> 3;
        u32 bpp = p->var.bits_per_pixel;
@@ -295,7 +293,7 @@ void cfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
        else
                fg = rect->color;
 
-       pat = pixel_to_pat( bpp, fg);
+       pat = pixel_to_pat(bpp, fg);
 
        dst = (unsigned long __iomem *)((unsigned long)p->screen_base & ~(bytes-1));
        dst_idx = ((unsigned long)p->screen_base & (bytes - 1))*8;
@@ -306,7 +304,8 @@ void cfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
                p->fbops->fb_sync(p);
        if (!left) {
                u32 bswapmask = fb_compute_bswapmask(p);
-               void (*fill_op32)(unsigned long __iomem *dst, int dst_idx,
+               void (*fill_op32)(struct fb_info *p,
+                                 unsigned long __iomem *dst, int dst_idx,
                                  unsigned long pat, unsigned n, int bits,
                                  u32 bswapmask) = NULL;
 
@@ -325,21 +324,21 @@ void cfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
                while (height--) {
                        dst += dst_idx >> (ffs(bits) - 1);
                        dst_idx &= (bits - 1);
-                       fill_op32(dst, dst_idx, pat, width*bpp, bits, bswapmask);
+                       fill_op32(p, dst, dst_idx, pat, width*bpp, bits,
+                                 bswapmask);
                        dst_idx += p->fix.line_length*8;
                }
        } else {
-               int right;
-               int r;
-               int rot = (left-dst_idx) % bpp;
-               void (*fill_op)(unsigned long __iomem *dst, int dst_idx,
-                               unsigned long pat, int left, int right,
-                               unsigned n, int bits) = NULL;
-
-               /* rotate pattern to correct start position */
-               pat = pat << rot | pat >> (bpp-rot);
-
-               right = bpp-left;
+               int right, r;
+               void (*fill_op)(struct fb_info *p, unsigned long __iomem *dst,
+                               int dst_idx, unsigned long pat, int left,
+                               int right, unsigned n, int bits) = NULL;
+#ifdef __LITTLE_ENDIAN
+               right = left;
+               left = bpp - right;
+#else
+               right = bpp - left;
+#endif
                switch (rect->rop) {
                case ROP_XOR:
                        fill_op = bitfill_unaligned_rev;
@@ -348,17 +347,18 @@ void cfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
                        fill_op = bitfill_unaligned;
                        break;
                default:
-                       printk( KERN_ERR "cfb_fillrect(): unknown rop, defaulting to ROP_COPY\n");
+                       printk(KERN_ERR "cfb_fillrect(): unknown rop, defaulting to ROP_COPY\n");
                        fill_op = bitfill_unaligned;
                        break;
                }
                while (height--) {
-                       dst += dst_idx >> (ffs(bits) - 1);
+                       dst += dst_idx / bits;
                        dst_idx &= (bits - 1);
-                       fill_op(dst, dst_idx, pat, left, right,
+                       r = dst_idx % bpp;
+                       /* rotate pattern to the correct start position */
+                       pat2 = le_long_to_cpu(rolx(cpu_to_le_long(pat), r, bpp));
+                       fill_op(p, dst, dst_idx, pat2, left, right,
                                width*bpp, bits);
-                       r = (p->fix.line_length*8) % bpp;
-                       pat = pat << (bpp-r) | pat >> r;
                        dst_idx += p->fix.line_length*8;
                }
        }