* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / video / fbcon-cfb24.c
blob74ace660f83fd4973c9038d4593d0e41752c974f
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 fb_memmove(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 fb_memmove(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 fb_memmove(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 u32 o1, o2, o3;
94 convert4to3(d1, d2, d3, d4, o1, o2, o3);
95 fb_writel (o1, dest++);
96 fb_writel (o2, dest++);
97 fb_writel (o3, dest);
100 static inline void rectfill(u8 *dest, int width, int height, u32 data,
101 int linesize)
103 u32 d1, d2, d3;
104 int i;
106 convert4to3(data, data, data, data, d1, d2, d3);
107 while (height-- > 0) {
108 u32 *p = (u32 *)dest;
109 for (i = 0; i < width/4; i++) {
110 fb_writel(d1, p++);
111 fb_writel(d2, p++);
112 fb_writel(d3, p++);
114 dest += linesize;
118 void fbcon_cfb24_clear(struct vc_data *conp, struct display *p, int sy, int sx,
119 int height, int width)
121 u8 *dest;
122 int bytes = p->next_line, lines = height * fontheight(p);
123 u32 bgx;
125 dest = p->screen_base + sy * fontheight(p) * bytes + sx * fontwidth(p) * 3;
127 bgx = ((u32 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
129 width *= fontwidth(p)/4;
130 if (width * 12 == bytes)
131 rectfill(dest, lines * width * 4, 1, bgx, bytes);
132 else
133 rectfill(dest, width * 4, lines, bgx, bytes);
136 void fbcon_cfb24_putc(struct vc_data *conp, struct display *p, int c, int yy,
137 int xx)
139 u8 *dest, *cdat, bits;
140 int bytes = p->next_line, rows;
141 u32 eorx, fgx, bgx, d1, d2, d3, d4;
143 dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 3;
144 if (fontwidth(p) <= 8)
145 cdat = p->fontdata + (c & p->charmask) * fontheight(p);
146 else
147 cdat = p->fontdata + ((c & p->charmask) * fontheight(p) << 1);
149 fgx = ((u32 *)p->dispsw_data)[attr_fgcol(p, c)];
150 bgx = ((u32 *)p->dispsw_data)[attr_bgcol(p, c)];
151 eorx = fgx ^ bgx;
153 for (rows = fontheight(p); rows--; dest += bytes) {
154 bits = *cdat++;
155 d1 = (-(bits >> 7) & eorx) ^ bgx;
156 d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
157 d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
158 d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
159 store4pixels(d1, d2, d3, d4, (u32 *)dest);
160 if (fontwidth(p) < 8)
161 continue;
162 d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
163 d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
164 d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
165 d4 = (-(bits & 1) & eorx) ^ bgx;
166 store4pixels(d1, d2, d3, d4, (u32 *)(dest+12));
167 if (fontwidth(p) < 12)
168 continue;
169 bits = *cdat++;
170 d1 = (-(bits >> 7) & eorx) ^ bgx;
171 d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
172 d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
173 d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
174 store4pixels(d1, d2, d3, d4, (u32 *)(dest+24));
175 if (fontwidth(p) < 16)
176 continue;
177 d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
178 d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
179 d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
180 d4 = (-(bits & 1) & eorx) ^ bgx;
181 store4pixels(d1, d2, d3, d4, (u32 *)(dest+36));
185 void fbcon_cfb24_putcs(struct vc_data *conp, struct display *p,
186 const unsigned short *s, int count, int yy, int xx)
188 u8 *cdat, *dest, *dest0, bits;
189 u16 c;
190 int rows, bytes = p->next_line;
191 u32 eorx, fgx, bgx, d1, d2, d3, d4;
193 dest0 = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 3;
194 fgx = ((u32 *)p->dispsw_data)[attr_fgcol(p, scr_readw(s))];
195 bgx = ((u32 *)p->dispsw_data)[attr_bgcol(p, scr_readw(s))];
196 eorx = fgx ^ bgx;
197 while (count--) {
198 c = scr_readw(s++) & p->charmask;
199 if (fontwidth(p) <= 8)
200 cdat = p->fontdata + c * fontheight(p);
202 else
203 cdat = p->fontdata + (c * fontheight(p) << 1);
204 for (rows = fontheight(p), dest = dest0; rows--; dest += bytes) {
205 bits = *cdat++;
206 d1 = (-(bits >> 7) & eorx) ^ bgx;
207 d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
208 d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
209 d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
210 store4pixels(d1, d2, d3, d4, (u32 *)dest);
211 if (fontwidth(p) < 8)
212 continue;
213 d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
214 d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
215 d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
216 d4 = (-(bits & 1) & eorx) ^ bgx;
217 store4pixels(d1, d2, d3, d4, (u32 *)(dest+12));
218 if (fontwidth(p) < 12)
219 continue;
220 bits = *cdat++;
221 d1 = (-(bits >> 7) & eorx) ^ bgx;
222 d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
223 d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
224 d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
225 store4pixels(d1, d2, d3, d4, (u32 *)(dest+24));
226 if (fontwidth(p) < 16)
227 continue;
228 d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
229 d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
230 d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
231 d4 = (-(bits & 1) & eorx) ^ bgx;
232 store4pixels(d1, d2, d3, d4, (u32 *)(dest+36));
234 dest0 += fontwidth(p)*3;
238 void fbcon_cfb24_revc(struct display *p, int xx, int yy)
240 u8 *dest;
241 int bytes = p->next_line, rows;
243 dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 3;
244 for (rows = fontheight(p); rows--; dest += bytes) {
245 switch (fontwidth(p)) {
246 case 16:
247 fb_writel(fb_readl(dest+36) ^ 0xffffffff, dest+36);
248 fb_writel(fb_readl(dest+40) ^ 0xffffffff, dest+40);
249 fb_writel(fb_readl(dest+44) ^ 0xffffffff, dest+44);
250 /* FALL THROUGH */
251 case 12:
252 fb_writel(fb_readl(dest+24) ^ 0xffffffff, dest+24);
253 fb_writel(fb_readl(dest+28) ^ 0xffffffff, dest+28);
254 fb_writel(fb_readl(dest+32) ^ 0xffffffff, dest+32);
255 /* FALL THROUGH */
256 case 8:
257 fb_writel(fb_readl(dest+12) ^ 0xffffffff, dest+12);
258 fb_writel(fb_readl(dest+16) ^ 0xffffffff, dest+16);
259 fb_writel(fb_readl(dest+20) ^ 0xffffffff, dest+20);
260 /* FALL THROUGH */
261 case 4:
262 fb_writel(fb_readl(dest+0) ^ 0xffffffff, dest+0);
263 fb_writel(fb_readl(dest+4) ^ 0xffffffff, dest+4);
264 fb_writel(fb_readl(dest+8) ^ 0xffffffff, dest+8);
269 void fbcon_cfb24_clear_margins(struct vc_data *conp, struct display *p,
270 int bottom_only)
272 int bytes = p->next_line;
273 u32 bgx;
275 unsigned int right_start = conp->vc_cols*fontwidth(p);
276 unsigned int bottom_start = conp->vc_rows*fontheight(p);
277 unsigned int right_width, bottom_width;
279 bgx = ((u32 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
281 if (!bottom_only && (right_width = p->var.xres-right_start))
282 rectfill(p->screen_base+right_start*3, right_width,
283 p->var.yres_virtual, bgx, bytes);
284 if ((bottom_width = p->var.yres-bottom_start))
285 rectfill(p->screen_base+(p->var.yoffset+bottom_start)*bytes,
286 right_start, bottom_width, bgx, bytes);
291 * `switch' for the low level operations
294 struct display_switch fbcon_cfb24 = {
295 fbcon_cfb24_setup, fbcon_cfb24_bmove, fbcon_cfb24_clear, fbcon_cfb24_putc,
296 fbcon_cfb24_putcs, fbcon_cfb24_revc, NULL, NULL, fbcon_cfb24_clear_margins,
297 FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
301 #ifdef MODULE
302 int init_module(void)
304 return 0;
307 void cleanup_module(void)
309 #endif /* MODULE */
313 * Visible symbols for modules
316 EXPORT_SYMBOL(fbcon_cfb24);
317 EXPORT_SYMBOL(fbcon_cfb24_setup);
318 EXPORT_SYMBOL(fbcon_cfb24_bmove);
319 EXPORT_SYMBOL(fbcon_cfb24_clear);
320 EXPORT_SYMBOL(fbcon_cfb24_putc);
321 EXPORT_SYMBOL(fbcon_cfb24_putcs);
322 EXPORT_SYMBOL(fbcon_cfb24_revc);
323 EXPORT_SYMBOL(fbcon_cfb24_clear_margins);