Import 2.3.18pre1
[davej-history.git] / drivers / video / fbcon-cfb32.c
blobb66ec2badd4f056e4f91e8650f207b8e84ef5d61
1 /*
2 * linux/drivers/video/cfb32.c -- Low level frame buffer operations for 32 bpp
3 * truecolor packed pixels
5 * Created 28 Dec 1997 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-cfb32.h>
23 * 32 bpp packed pixels
26 void fbcon_cfb32_setup(struct display *p)
28 p->next_line = p->line_length ? p->line_length : p->var.xres_virtual<<2;
29 p->next_plane = 0;
32 void fbcon_cfb32_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) * 4 == 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)+2;
46 dx <<= fontwidthlog(p)+2;
47 width <<= fontwidthlog(p)+2;
48 } else {
49 sx *= fontwidth(p)*4;
50 dx *= fontwidth(p)*4;
51 width *= fontwidth(p)*4;
53 if (dy < sy || (dy == sy && dx < sx)) {
54 src = p->screen_base + sy * linesize + sx;
55 dst = p->screen_base + dy * linesize + dx;
56 for (rows = height * fontheight(p); rows--;) {
57 mymemmove(dst, src, width);
58 src += bytes;
59 dst += bytes;
61 } else {
62 src = p->screen_base + (sy+height) * linesize + sx - bytes;
63 dst = p->screen_base + (dy+height) * linesize + dx - bytes;
64 for (rows = height * fontheight(p); rows--;) {
65 mymemmove(dst, src, width);
66 src -= bytes;
67 dst -= bytes;
72 static inline void rectfill(u8 *dest, int width, int height, u32 data,
73 int linesize)
75 int i;
77 while (height-- > 0) {
78 u32 *p = (u32 *)dest;
79 for (i = 0; i < width/4; i++) {
80 *p++ = data;
81 *p++ = data;
82 *p++ = data;
83 *p++ = data;
85 if (width & 2) {
86 *p++ = data;
87 *p++ = data;
89 if (width & 1)
90 *p++ = data;
91 dest += linesize;
95 void fbcon_cfb32_clear(struct vc_data *conp, struct display *p, int sy, int sx,
96 int height, int width)
98 u8 *dest;
99 int bytes = p->next_line, lines = height * fontheight(p);
100 u32 bgx;
102 dest = p->screen_base + sy * fontheight(p) * bytes + sx * fontwidth(p) * 4;
104 bgx = ((u32 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
106 width *= fontwidth(p)/4;
107 if (width * 16 == bytes)
108 rectfill(dest, lines * width * 4, 1, bgx, bytes);
109 else
110 rectfill(dest, width * 4, lines, bgx, bytes);
113 void fbcon_cfb32_putc(struct vc_data *conp, struct display *p, int c, int yy,
114 int xx)
116 u8 *dest, *cdat, bits;
117 int bytes = p->next_line, rows;
118 u32 eorx, fgx, bgx;
120 dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 4;
121 if (fontwidth(p) <= 8)
122 cdat = p->fontdata + (c & p->charmask) * fontheight(p);
123 else
124 cdat = p->fontdata + ((c & p->charmask) * fontheight(p) << 1);
125 fgx = ((u32 *)p->dispsw_data)[attr_fgcol(p, c)];
126 bgx = ((u32 *)p->dispsw_data)[attr_bgcol(p, c)];
127 eorx = fgx ^ bgx;
129 for (rows = fontheight(p); rows--; dest += bytes) {
130 bits = *cdat++;
131 ((u32 *)dest)[0] = (-(bits >> 7) & eorx) ^ bgx;
132 ((u32 *)dest)[1] = (-(bits >> 6 & 1) & eorx) ^ bgx;
133 ((u32 *)dest)[2] = (-(bits >> 5 & 1) & eorx) ^ bgx;
134 ((u32 *)dest)[3] = (-(bits >> 4 & 1) & eorx) ^ bgx;
135 if (fontwidth(p) < 8)
136 continue;
137 ((u32 *)dest)[4] = (-(bits >> 3 & 1) & eorx) ^ bgx;
138 ((u32 *)dest)[5] = (-(bits >> 2 & 1) & eorx) ^ bgx;
139 ((u32 *)dest)[6] = (-(bits >> 1 & 1) & eorx) ^ bgx;
140 ((u32 *)dest)[7] = (-(bits & 1) & eorx) ^ bgx;
141 if (fontwidth(p) < 12)
142 continue;
143 bits = *cdat++;
144 ((u32 *)dest)[8] = (-(bits >> 7) & eorx) ^ bgx;
145 ((u32 *)dest)[9] = (-(bits >> 6 & 1) & eorx) ^ bgx;
146 ((u32 *)dest)[10] = (-(bits >> 5 & 1) & eorx) ^ bgx;
147 ((u32 *)dest)[11] = (-(bits >> 4 & 1) & eorx) ^ bgx;
148 if (fontwidth(p) < 16)
149 continue;
150 ((u32 *)dest)[12] = (-(bits >> 3 & 1) & eorx) ^ bgx;
151 ((u32 *)dest)[13] = (-(bits >> 2 & 1) & eorx) ^ bgx;
152 ((u32 *)dest)[14] = (-(bits >> 1 & 1) & eorx) ^ bgx;
153 ((u32 *)dest)[15] = (-(bits & 1) & eorx) ^ bgx;
157 void fbcon_cfb32_putcs(struct vc_data *conp, struct display *p,
158 const unsigned short *s, int count, int yy, int xx)
160 u8 *cdat, *dest, *dest0, bits;
161 u16 c;
162 int rows, bytes = p->next_line;
163 u32 eorx, fgx, bgx;
165 dest0 = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 4;
166 fgx = ((u32 *)p->dispsw_data)[attr_fgcol(p, scr_readw(s))];
167 bgx = ((u32 *)p->dispsw_data)[attr_bgcol(p, scr_readw(s))];
168 eorx = fgx ^ bgx;
169 while (count--) {
170 c = scr_readw(s++) & p->charmask;
171 if (fontwidth(p) <= 8)
172 cdat = p->fontdata + c * fontheight(p);
173 else
174 cdat = p->fontdata + (c * fontheight(p) << 1);
175 for (rows = fontheight(p), dest = dest0; rows--; dest += bytes) {
176 bits = *cdat++;
177 ((u32 *)dest)[0] = (-(bits >> 7) & eorx) ^ bgx;
178 ((u32 *)dest)[1] = (-(bits >> 6 & 1) & eorx) ^ bgx;
179 ((u32 *)dest)[2] = (-(bits >> 5 & 1) & eorx) ^ bgx;
180 ((u32 *)dest)[3] = (-(bits >> 4 & 1) & eorx) ^ bgx;
181 if (fontwidth(p) < 8)
182 continue;
183 ((u32 *)dest)[4] = (-(bits >> 3 & 1) & eorx) ^ bgx;
184 ((u32 *)dest)[5] = (-(bits >> 2 & 1) & eorx) ^ bgx;
185 ((u32 *)dest)[6] = (-(bits >> 1 & 1) & eorx) ^ bgx;
186 ((u32 *)dest)[7] = (-(bits & 1) & eorx) ^ bgx;
187 if (fontwidth(p) < 12)
188 continue;
189 bits = *cdat++;
190 ((u32 *)dest)[8] = (-(bits >> 7) & eorx) ^ bgx;
191 ((u32 *)dest)[9] = (-(bits >> 6 & 1) & eorx) ^ bgx;
192 ((u32 *)dest)[10] = (-(bits >> 5 & 1) & eorx) ^ bgx;
193 ((u32 *)dest)[11] = (-(bits >> 4 & 1) & eorx) ^ bgx;
194 if (fontwidth(p) < 16)
195 continue;
196 ((u32 *)dest)[12] = (-(bits >> 3 & 1) & eorx) ^ bgx;
197 ((u32 *)dest)[13] = (-(bits >> 2 & 1) & eorx) ^ bgx;
198 ((u32 *)dest)[14] = (-(bits >> 1 & 1) & eorx) ^ bgx;
199 ((u32 *)dest)[15] = (-(bits & 1) & eorx) ^ bgx;
201 dest0 += fontwidth(p)*4;
205 void fbcon_cfb32_revc(struct display *p, int xx, int yy)
207 u8 *dest;
208 int bytes = p->next_line, rows;
210 dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 4;
211 for (rows = fontheight(p); rows--; dest += bytes) {
212 switch (fontwidth(p)) {
213 case 16:
214 ((u32 *)dest)[12] ^= 0xffffffff; ((u32 *)dest)[13] ^= 0xffffffff;
215 ((u32 *)dest)[14] ^= 0xffffffff; ((u32 *)dest)[15] ^= 0xffffffff;
216 /* FALL THROUGH */
217 case 12:
218 ((u32 *)dest)[8] ^= 0xffffffff; ((u32 *)dest)[9] ^= 0xffffffff;
219 ((u32 *)dest)[10] ^= 0xffffffff; ((u32 *)dest)[11] ^= 0xffffffff;
220 /* FALL THROUGH */
221 case 8:
222 ((u32 *)dest)[4] ^= 0xffffffff; ((u32 *)dest)[5] ^= 0xffffffff;
223 ((u32 *)dest)[6] ^= 0xffffffff; ((u32 *)dest)[7] ^= 0xffffffff;
224 /* FALL THROUGH */
225 case 4:
226 ((u32 *)dest)[0] ^= 0xffffffff; ((u32 *)dest)[1] ^= 0xffffffff;
227 ((u32 *)dest)[2] ^= 0xffffffff; ((u32 *)dest)[3] ^= 0xffffffff;
228 /* FALL THROUGH */
233 void fbcon_cfb32_clear_margins(struct vc_data *conp, struct display *p,
234 int bottom_only)
236 int bytes = p->next_line;
237 u32 bgx;
239 unsigned int right_start = conp->vc_cols*fontwidth(p);
240 unsigned int bottom_start = conp->vc_rows*fontheight(p);
241 unsigned int right_width, bottom_width;
243 bgx = ((u32 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
245 if (!bottom_only && (right_width = p->var.xres-right_start))
246 rectfill(p->screen_base+right_start*4, right_width,
247 p->var.yres_virtual, bgx, bytes);
248 if ((bottom_width = p->var.yres-bottom_start))
249 rectfill(p->screen_base+(p->var.yoffset+bottom_start)*bytes,
250 right_start, bottom_width, bgx, bytes);
255 * `switch' for the low level operations
258 struct display_switch fbcon_cfb32 = {
259 fbcon_cfb32_setup, fbcon_cfb32_bmove, fbcon_cfb32_clear, fbcon_cfb32_putc,
260 fbcon_cfb32_putcs, fbcon_cfb32_revc, NULL, NULL, fbcon_cfb32_clear_margins,
261 FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
265 #ifdef MODULE
266 int init_module(void)
268 return 0;
271 void cleanup_module(void)
273 #endif /* MODULE */
277 * Visible symbols for modules
280 EXPORT_SYMBOL(fbcon_cfb32);
281 EXPORT_SYMBOL(fbcon_cfb32_setup);
282 EXPORT_SYMBOL(fbcon_cfb32_bmove);
283 EXPORT_SYMBOL(fbcon_cfb32_clear);
284 EXPORT_SYMBOL(fbcon_cfb32_putc);
285 EXPORT_SYMBOL(fbcon_cfb32_putcs);
286 EXPORT_SYMBOL(fbcon_cfb32_revc);
287 EXPORT_SYMBOL(fbcon_cfb32_clear_margins);