Import 2.3.18pre1
[davej-history.git] / drivers / video / fbcon-cfb24.c
blob17e8ee08afa0765782e1372f4ff2d81b99b33ea1
1 /*
2 * linux/drivers/video/cfb24.c -- Low level frame buffer operations for 24 bpp
3 * truecolor packed pixels
5 * Created 7 Mar 1998 by Geert Uytterhoeven
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
9 * more details.
12 #include <linux/module.h>
13 #include <linux/tty.h>
14 #include <linux/console.h>
15 #include <linux/string.h>
16 #include <linux/fb.h>
18 #include <video/fbcon.h>
19 #include <video/fbcon-cfb24.h>
23 * 24 bpp packed pixels
26 void fbcon_cfb24_setup(struct display *p)
28 p->next_line = p->line_length ? p->line_length : p->var.xres_virtual*3;
29 p->next_plane = 0;
32 void fbcon_cfb24_bmove(struct display *p, int sy, int sx, int dy, int dx,
33 int height, int width)
35 int bytes = p->next_line, linesize = bytes * fontheight(p), rows;
36 u8 *src, *dst;
38 if (sx == 0 && dx == 0 && width * fontwidth(p) * 3 == bytes) {
39 mymemmove(p->screen_base + dy * linesize,
40 p->screen_base + sy * linesize,
41 height * linesize);
42 return;
44 if (fontwidthlog(p)) {
45 sx <<= fontwidthlog(p);
46 dx <<= fontwidthlog(p);
47 width <<= fontwidthlog(p);
48 } else {
49 sx *= fontwidth(p);
50 dx *= fontwidth(p);
51 width *= fontwidth(p);
53 sx *= 3; dx *= 3; width *= 3;
54 if (dy < sy || (dy == sy && dx < sx)) {
55 src = p->screen_base + sy * linesize + sx;
56 dst = p->screen_base + dy * linesize + dx;
57 for (rows = height * fontheight(p); rows--;) {
58 mymemmove(dst, src, width);
59 src += bytes;
60 dst += bytes;
62 } else {
63 src = p->screen_base + (sy+height) * linesize + sx - bytes;
64 dst = p->screen_base + (dy+height) * linesize + dx - bytes;
65 for (rows = height * fontheight(p); rows--;) {
66 mymemmove(dst, src, width);
67 src -= bytes;
68 dst -= bytes;
73 #if defined(__BIG_ENDIAN)
74 #define convert4to3(in1, in2, in3, in4, out1, out2, out3) \
75 do { \
76 out1 = (in1<<8) | (in2>>16); \
77 out2 = (in2<<16) | (in3>>8); \
78 out3 = (in3<<24) | in4; \
79 } while (0);
80 #elif defined(__LITTLE_ENDIAN)
81 #define convert4to3(in1, in2, in3, in4, out1, out2, out3) \
82 do { \
83 out1 = in1 | (in2<<24); \
84 out2 = (in2>> 8) | (in3<<16); \
85 out3 = (in3>>16) | (in4<< 8); \
86 } while (0);
87 #else
88 #error FIXME: No endianness??
89 #endif
91 static inline void store4pixels(u32 d1, u32 d2, u32 d3, u32 d4, u32 *dest)
93 convert4to3(d1, d2, d3, d4, *dest++, *dest++, *dest++);
96 static inline void rectfill(u8 *dest, int width, int height, u32 data,
97 int linesize)
99 u32 d1, d2, d3;
100 int i;
102 convert4to3(data, data, data, data, d1, d2, d3);
103 while (height-- > 0) {
104 u32 *p = (u32 *)dest;
105 for (i = 0; i < width/4; i++) {
106 *p++ = d1;
107 *p++ = d2;
108 *p++ = d3;
110 dest += linesize;
114 void fbcon_cfb24_clear(struct vc_data *conp, struct display *p, int sy, int sx,
115 int height, int width)
117 u8 *dest;
118 int bytes = p->next_line, lines = height * fontheight(p);
119 u32 bgx;
121 dest = p->screen_base + sy * fontheight(p) * bytes + sx * fontwidth(p) * 3;
123 bgx = ((u32 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
125 width *= fontwidth(p)/4;
126 if (width * 12 == bytes)
127 rectfill(dest, lines * width * 4, 1, bgx, bytes);
128 else
129 rectfill(dest, width * 4, lines, bgx, bytes);
132 void fbcon_cfb24_putc(struct vc_data *conp, struct display *p, int c, int yy,
133 int xx)
135 u8 *dest, *cdat, bits;
136 int bytes = p->next_line, rows;
137 u32 eorx, fgx, bgx, d1, d2, d3, d4;
139 dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 3;
140 if (fontwidth(p) <= 8)
141 cdat = p->fontdata + (c & p->charmask) * fontheight(p);
142 else
143 cdat = p->fontdata + ((c & p->charmask) * fontheight(p) << 1);
145 fgx = ((u32 *)p->dispsw_data)[attr_fgcol(p, c)];
146 bgx = ((u32 *)p->dispsw_data)[attr_bgcol(p, c)];
147 eorx = fgx ^ bgx;
149 for (rows = fontheight(p); rows--; dest += bytes) {
150 bits = *cdat++;
151 d1 = (-(bits >> 7) & eorx) ^ bgx;
152 d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
153 d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
154 d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
155 store4pixels(d1, d2, d3, d4, (u32 *)dest);
156 if (fontwidth(p) < 8)
157 continue;
158 d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
159 d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
160 d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
161 d4 = (-(bits & 1) & eorx) ^ bgx;
162 store4pixels(d1, d2, d3, d4, (u32 *)(dest+12));
163 if (fontwidth(p) < 12)
164 continue;
165 bits = *cdat++;
166 d1 = (-(bits >> 7) & eorx) ^ bgx;
167 d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
168 d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
169 d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
170 store4pixels(d1, d2, d3, d4, (u32 *)(dest+24));
171 if (fontwidth(p) < 16)
172 continue;
173 d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
174 d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
175 d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
176 d4 = (-(bits & 1) & eorx) ^ bgx;
177 store4pixels(d1, d2, d3, d4, (u32 *)(dest+32));
181 void fbcon_cfb24_putcs(struct vc_data *conp, struct display *p,
182 const unsigned short *s, int count, int yy, int xx)
184 u8 *cdat, *dest, *dest0, bits;
185 u16 c;
186 int rows, bytes = p->next_line;
187 u32 eorx, fgx, bgx, d1, d2, d3, d4;
189 dest0 = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 3;
190 fgx = ((u32 *)p->dispsw_data)[attr_fgcol(p, scr_readw(s))];
191 bgx = ((u32 *)p->dispsw_data)[attr_bgcol(p, scr_readw(s))];
192 eorx = fgx ^ bgx;
193 while (count--) {
194 c = scr_readw(s++) & p->charmask;
195 if (fontwidth(p) <= 8)
196 cdat = p->fontdata + c * fontheight(p);
198 else
199 cdat = p->fontdata + (c * fontheight(p) << 1);
200 for (rows = fontheight(p), dest = dest0; rows--; dest += bytes) {
201 bits = *cdat++;
202 d1 = (-(bits >> 7) & eorx) ^ bgx;
203 d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
204 d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
205 d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
206 store4pixels(d1, d2, d3, d4, (u32 *)dest);
207 if (fontwidth(p) < 8)
208 continue;
209 d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
210 d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
211 d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
212 d4 = (-(bits & 1) & eorx) ^ bgx;
213 store4pixels(d1, d2, d3, d4, (u32 *)(dest+12));
214 if (fontwidth(p) < 12)
215 continue;
216 bits = *cdat++;
217 d1 = (-(bits >> 7) & eorx) ^ bgx;
218 d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
219 d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
220 d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
221 store4pixels(d1, d2, d3, d4, (u32 *)(dest+24));
222 if (fontwidth(p) < 16)
223 continue;
224 d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
225 d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
226 d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
227 d4 = (-(bits & 1) & eorx) ^ bgx;
228 store4pixels(d1, d2, d3, d4, (u32 *)(dest+32));
230 dest0 += fontwidth(p)*3;
234 void fbcon_cfb24_revc(struct display *p, int xx, int yy)
236 u8 *dest;
237 int bytes = p->next_line, rows;
239 dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 3;
240 for (rows = fontheight(p); rows--; dest += bytes) {
241 switch (fontwidth(p)) {
242 case 16:
243 ((u32 *)dest)[9] ^= 0xffffffff; ((u32 *)dest)[10] ^= 0xffffffff;
244 ((u32 *)dest)[11] ^= 0xffffffff; /* FALL THROUGH */
245 case 12:
246 ((u32 *)dest)[6] ^= 0xffffffff; ((u32 *)dest)[7] ^= 0xffffffff;
247 ((u32 *)dest)[8] ^= 0xffffffff; /* FALL THROUGH */
248 case 8:
249 ((u32 *)dest)[3] ^= 0xffffffff; ((u32 *)dest)[4] ^= 0xffffffff;
250 ((u32 *)dest)[5] ^= 0xffffffff; /* FALL THROUGH */
251 case 4:
252 ((u32 *)dest)[0] ^= 0xffffffff; ((u32 *)dest)[1] ^= 0xffffffff;
253 ((u32 *)dest)[2] ^= 0xffffffff;
258 void fbcon_cfb24_clear_margins(struct vc_data *conp, struct display *p,
259 int bottom_only)
261 int bytes = p->next_line;
262 u32 bgx;
264 unsigned int right_start = conp->vc_cols*fontwidth(p);
265 unsigned int bottom_start = conp->vc_rows*fontheight(p);
266 unsigned int right_width, bottom_width;
268 bgx = ((u32 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
270 if (!bottom_only && (right_width = p->var.xres-right_start))
271 rectfill(p->screen_base+right_start*3, right_width,
272 p->var.yres_virtual, bgx, bytes);
273 if ((bottom_width = p->var.yres-bottom_start))
274 rectfill(p->screen_base+(p->var.yoffset+bottom_start)*bytes,
275 right_start, bottom_width, bgx, bytes);
280 * `switch' for the low level operations
283 struct display_switch fbcon_cfb24 = {
284 fbcon_cfb24_setup, fbcon_cfb24_bmove, fbcon_cfb24_clear, fbcon_cfb24_putc,
285 fbcon_cfb24_putcs, fbcon_cfb24_revc, NULL, NULL, fbcon_cfb24_clear_margins,
286 FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
290 #ifdef MODULE
291 int init_module(void)
293 return 0;
296 void cleanup_module(void)
298 #endif /* MODULE */
302 * Visible symbols for modules
305 EXPORT_SYMBOL(fbcon_cfb24);
306 EXPORT_SYMBOL(fbcon_cfb24_setup);
307 EXPORT_SYMBOL(fbcon_cfb24_bmove);
308 EXPORT_SYMBOL(fbcon_cfb24_clear);
309 EXPORT_SYMBOL(fbcon_cfb24_putc);
310 EXPORT_SYMBOL(fbcon_cfb24_putcs);
311 EXPORT_SYMBOL(fbcon_cfb24_revc);
312 EXPORT_SYMBOL(fbcon_cfb24_clear_margins);