V4L/DVB (6715): ivtv: Remove unnecessary register update
[linux-2.6/verdex.git] / drivers / video / cfbimgblt.c
blobf598907b42adfa71adaa5f237e07e7ab8cd1757d
1 /*
2 * Generic BitBLT function for frame buffer with packed pixels of any depth.
4 * Copyright (C) June 1999 James Simmons
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive for
8 * more details.
10 * NOTES:
12 * This function copys a image from system memory to video memory. The
13 * image can be a bitmap where each 0 represents the background color and
14 * each 1 represents the foreground color. Great for font handling. It can
15 * also be a color image. This is determined by image_depth. The color image
16 * must be laid out exactly in the same format as the framebuffer. Yes I know
17 * their are cards with hardware that coverts images of various depths to the
18 * framebuffer depth. But not every card has this. All images must be rounded
19 * up to the nearest byte. For example a bitmap 12 bits wide must be two
20 * bytes width.
22 * Tony:
23 * Incorporate mask tables similar to fbcon-cfb*.c in 2.4 API. This speeds
24 * up the code significantly.
26 * Code for depths not multiples of BITS_PER_LONG is still kludgy, which is
27 * still processed a bit at a time.
29 * Also need to add code to deal with cards endians that are different than
30 * the native cpu endians. I also need to deal with MSB position in the word.
32 #include <linux/module.h>
33 #include <linux/string.h>
34 #include <linux/fb.h>
35 #include <asm/types.h>
36 #include "fb_draw.h"
38 #define DEBUG
40 #ifdef DEBUG
41 #define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt,__FUNCTION__,## args)
42 #else
43 #define DPRINTK(fmt, args...)
44 #endif
46 static const u32 cfb_tab8[] = {
47 #if defined(__BIG_ENDIAN)
48 0x00000000,0x000000ff,0x0000ff00,0x0000ffff,
49 0x00ff0000,0x00ff00ff,0x00ffff00,0x00ffffff,
50 0xff000000,0xff0000ff,0xff00ff00,0xff00ffff,
51 0xffff0000,0xffff00ff,0xffffff00,0xffffffff
52 #elif defined(__LITTLE_ENDIAN)
53 0x00000000,0xff000000,0x00ff0000,0xffff0000,
54 0x0000ff00,0xff00ff00,0x00ffff00,0xffffff00,
55 0x000000ff,0xff0000ff,0x00ff00ff,0xffff00ff,
56 0x0000ffff,0xff00ffff,0x00ffffff,0xffffffff
57 #else
58 #error FIXME: No endianness??
59 #endif
62 static const u32 cfb_tab16[] = {
63 #if defined(__BIG_ENDIAN)
64 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
65 #elif defined(__LITTLE_ENDIAN)
66 0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff
67 #else
68 #error FIXME: No endianness??
69 #endif
72 static const u32 cfb_tab32[] = {
73 0x00000000, 0xffffffff
76 #define FB_WRITEL fb_writel
77 #define FB_READL fb_readl
79 static inline void color_imageblit(const struct fb_image *image,
80 struct fb_info *p, u8 __iomem *dst1,
81 u32 start_index,
82 u32 pitch_index)
84 /* Draw the penguin */
85 u32 __iomem *dst, *dst2;
86 u32 color = 0, val, shift;
87 int i, n, bpp = p->var.bits_per_pixel;
88 u32 null_bits = 32 - bpp;
89 u32 *palette = (u32 *) p->pseudo_palette;
90 const u8 *src = image->data;
91 u32 bswapmask = fb_compute_bswapmask(p);
93 dst2 = (u32 __iomem *) dst1;
94 for (i = image->height; i--; ) {
95 n = image->width;
96 dst = (u32 __iomem *) dst1;
97 shift = 0;
98 val = 0;
100 if (start_index) {
101 u32 start_mask = ~fb_shifted_pixels_mask_u32(start_index, bswapmask);
102 val = FB_READL(dst) & start_mask;
103 shift = start_index;
105 while (n--) {
106 if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
107 p->fix.visual == FB_VISUAL_DIRECTCOLOR )
108 color = palette[*src];
109 else
110 color = *src;
111 color <<= FB_LEFT_POS(bpp);
112 val |= FB_SHIFT_HIGH(color, shift ^ bswapmask);
113 if (shift >= null_bits) {
114 FB_WRITEL(val, dst++);
116 val = (shift == null_bits) ? 0 :
117 FB_SHIFT_LOW(color, 32 - shift);
119 shift += bpp;
120 shift &= (32 - 1);
121 src++;
123 if (shift) {
124 u32 end_mask = fb_shifted_pixels_mask_u32(shift, bswapmask);
126 FB_WRITEL((FB_READL(dst) & end_mask) | val, dst);
128 dst1 += p->fix.line_length;
129 if (pitch_index) {
130 dst2 += p->fix.line_length;
131 dst1 = (u8 __iomem *)((long __force)dst2 & ~(sizeof(u32) - 1));
133 start_index += pitch_index;
134 start_index &= 32 - 1;
139 static inline void slow_imageblit(const struct fb_image *image, struct fb_info *p,
140 u8 __iomem *dst1, u32 fgcolor,
141 u32 bgcolor,
142 u32 start_index,
143 u32 pitch_index)
145 u32 shift, color = 0, bpp = p->var.bits_per_pixel;
146 u32 __iomem *dst, *dst2;
147 u32 val, pitch = p->fix.line_length;
148 u32 null_bits = 32 - bpp;
149 u32 spitch = (image->width+7)/8;
150 const u8 *src = image->data, *s;
151 u32 i, j, l;
152 u32 bswapmask = fb_compute_bswapmask(p);
154 dst2 = (u32 __iomem *) dst1;
155 fgcolor <<= FB_LEFT_POS(bpp);
156 bgcolor <<= FB_LEFT_POS(bpp);
158 for (i = image->height; i--; ) {
159 shift = val = 0;
160 l = 8;
161 j = image->width;
162 dst = (u32 __iomem *) dst1;
163 s = src;
165 /* write leading bits */
166 if (start_index) {
167 u32 start_mask = ~fb_shifted_pixels_mask_u32(start_index, bswapmask);
168 val = FB_READL(dst) & start_mask;
169 shift = start_index;
172 while (j--) {
173 l--;
174 color = (*s & (1 << l)) ? fgcolor : bgcolor;
175 val |= FB_SHIFT_HIGH(color, shift ^ bswapmask);
177 /* Did the bitshift spill bits to the next long? */
178 if (shift >= null_bits) {
179 FB_WRITEL(val, dst++);
180 val = (shift == null_bits) ? 0 :
181 FB_SHIFT_LOW(color,32 - shift);
183 shift += bpp;
184 shift &= (32 - 1);
185 if (!l) { l = 8; s++; };
188 /* write trailing bits */
189 if (shift) {
190 u32 end_mask = fb_shifted_pixels_mask_u32(shift, bswapmask);
192 FB_WRITEL((FB_READL(dst) & end_mask) | val, dst);
195 dst1 += pitch;
196 src += spitch;
197 if (pitch_index) {
198 dst2 += pitch;
199 dst1 = (u8 __iomem *)((long __force)dst2 & ~(sizeof(u32) - 1));
200 start_index += pitch_index;
201 start_index &= 32 - 1;
208 * fast_imageblit - optimized monochrome color expansion
210 * Only if: bits_per_pixel == 8, 16, or 32
211 * image->width is divisible by pixel/dword (ppw);
212 * fix->line_legth is divisible by 4;
213 * beginning and end of a scanline is dword aligned
215 static inline void fast_imageblit(const struct fb_image *image, struct fb_info *p,
216 u8 __iomem *dst1, u32 fgcolor,
217 u32 bgcolor)
219 u32 fgx = fgcolor, bgx = bgcolor, bpp = p->var.bits_per_pixel;
220 u32 ppw = 32/bpp, spitch = (image->width + 7)/8;
221 u32 bit_mask, end_mask, eorx, shift;
222 const char *s = image->data, *src;
223 u32 __iomem *dst;
224 const u32 *tab = NULL;
225 int i, j, k;
227 switch (bpp) {
228 case 8:
229 tab = cfb_tab8;
230 break;
231 case 16:
232 tab = cfb_tab16;
233 break;
234 case 32:
235 default:
236 tab = cfb_tab32;
237 break;
240 for (i = ppw-1; i--; ) {
241 fgx <<= bpp;
242 bgx <<= bpp;
243 fgx |= fgcolor;
244 bgx |= bgcolor;
247 bit_mask = (1 << ppw) - 1;
248 eorx = fgx ^ bgx;
249 k = image->width/ppw;
251 for (i = image->height; i--; ) {
252 dst = (u32 __iomem *) dst1, shift = 8; src = s;
254 for (j = k; j--; ) {
255 shift -= ppw;
256 end_mask = tab[(*src >> shift) & bit_mask];
257 FB_WRITEL((end_mask & eorx)^bgx, dst++);
258 if (!shift) { shift = 8; src++; }
260 dst1 += p->fix.line_length;
261 s += spitch;
265 void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
267 u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
268 u32 bpl = sizeof(u32), bpp = p->var.bits_per_pixel;
269 u32 width = image->width;
270 u32 dx = image->dx, dy = image->dy;
271 u8 __iomem *dst1;
273 if (p->state != FBINFO_STATE_RUNNING)
274 return;
276 bitstart = (dy * p->fix.line_length * 8) + (dx * bpp);
277 start_index = bitstart & (32 - 1);
278 pitch_index = (p->fix.line_length & (bpl - 1)) * 8;
280 bitstart /= 8;
281 bitstart &= ~(bpl - 1);
282 dst1 = p->screen_base + bitstart;
284 if (p->fbops->fb_sync)
285 p->fbops->fb_sync(p);
287 if (image->depth == 1) {
288 if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
289 p->fix.visual == FB_VISUAL_DIRECTCOLOR) {
290 fgcolor = ((u32*)(p->pseudo_palette))[image->fg_color];
291 bgcolor = ((u32*)(p->pseudo_palette))[image->bg_color];
292 } else {
293 fgcolor = image->fg_color;
294 bgcolor = image->bg_color;
297 if (32 % bpp == 0 && !start_index && !pitch_index &&
298 ((width & (32/bpp-1)) == 0) &&
299 bpp >= 8 && bpp <= 32)
300 fast_imageblit(image, p, dst1, fgcolor, bgcolor);
301 else
302 slow_imageblit(image, p, dst1, fgcolor, bgcolor,
303 start_index, pitch_index);
304 } else
305 color_imageblit(image, p, dst1, start_index, pitch_index);
308 EXPORT_SYMBOL(cfb_imageblit);
310 MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
311 MODULE_DESCRIPTION("Generic software accelerated imaging drawing");
312 MODULE_LICENSE("GPL");