* better
[mascara-docs.git] / i386 / linux-2.3.21 / drivers / video / fbcon-cfb16.c
blob0c3c79ab788ead0fee2bb1b907d136ad4ca4023b
1 /*
2 * linux/drivers/video/cfb16.c -- Low level frame buffer operations for 16 bpp
3 * truecolor packed pixels
5 * Created 5 Apr 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>
17 #include <asm/io.h>
19 #include <video/fbcon.h>
20 #include <video/fbcon-cfb16.h>
24 * 16 bpp packed pixels
27 static u32 tab_cfb16[] = {
28 #if defined(__BIG_ENDIAN)
29 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
30 #elif defined(__LITTLE_ENDIAN)
31 0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff
32 #else
33 #error FIXME: No endianness??
34 #endif
37 void fbcon_cfb16_setup(struct display *p)
39 p->next_line = p->line_length ? p->line_length : p->var.xres_virtual<<1;
40 p->next_plane = 0;
43 void fbcon_cfb16_bmove(struct display *p, int sy, int sx, int dy, int dx,
44 int height, int width)
46 int bytes = p->next_line, linesize = bytes * fontheight(p), rows;
47 u8 *src, *dst;
49 if (sx == 0 && dx == 0 && width * fontwidth(p) * 2 == bytes) {
50 fb_memmove(p->screen_base + dy * linesize,
51 p->screen_base + sy * linesize,
52 height * linesize);
53 return;
55 if (fontwidthlog(p)) {
56 sx <<= fontwidthlog(p)+1;
57 dx <<= fontwidthlog(p)+1;
58 width <<= fontwidthlog(p)+1;
59 } else {
60 sx *= fontwidth(p)*2;
61 dx *= fontwidth(p)*2;
62 width *= fontwidth(p)*2;
64 if (dy < sy || (dy == sy && dx < sx)) {
65 src = p->screen_base + sy * linesize + sx;
66 dst = p->screen_base + dy * linesize + dx;
67 for (rows = height * fontheight(p); rows--;) {
68 fb_memmove(dst, src, width);
69 src += bytes;
70 dst += bytes;
72 } else {
73 src = p->screen_base + (sy+height) * linesize + sx - bytes;
74 dst = p->screen_base + (dy+height) * linesize + dx - bytes;
75 for (rows = height * fontheight(p); rows--;) {
76 fb_memmove(dst, src, width);
77 src -= bytes;
78 dst -= bytes;
83 static inline void rectfill(u8 *dest, int width, int height, u32 data,
84 int linesize)
86 int i;
88 data |= data<<16;
90 while (height-- > 0) {
91 u32 *p = (u32 *)dest;
92 for (i = 0; i < width/4; i++) {
93 fb_writel(data, p++);
94 fb_writel(data, p++);
96 if (width & 2)
97 fb_writel(data, p++);
98 if (width & 1)
99 fb_writew(data, (u16*)p);
100 dest += linesize;
104 void fbcon_cfb16_clear(struct vc_data *conp, struct display *p, int sy, int sx,
105 int height, int width)
107 u8 *dest;
108 int bytes = p->next_line, lines = height * fontheight(p);
109 u32 bgx;
111 dest = p->screen_base + sy * fontheight(p) * bytes + sx * fontwidth(p) * 2;
113 bgx = ((u16 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
115 width *= fontwidth(p)/4;
116 if (width * 8 == bytes)
117 rectfill(dest, lines * width * 4, 1, bgx, bytes);
118 else
119 rectfill(dest, width * 4, lines, bgx, bytes);
122 void fbcon_cfb16_putc(struct vc_data *conp, struct display *p, int c, int yy,
123 int xx)
125 u8 *dest, *cdat, bits;
126 int bytes = p->next_line, rows;
127 u32 eorx, fgx, bgx;
129 dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 2;
131 fgx = ((u16 *)p->dispsw_data)[attr_fgcol(p, c)];
132 bgx = ((u16 *)p->dispsw_data)[attr_bgcol(p, c)];
133 fgx |= (fgx << 16);
134 bgx |= (bgx << 16);
135 eorx = fgx ^ bgx;
137 switch (fontwidth(p)) {
138 case 4:
139 case 8:
140 cdat = p->fontdata + (c & p->charmask) * fontheight(p);
141 for (rows = fontheight(p); rows--; dest += bytes) {
142 bits = *cdat++;
143 fb_writel((tab_cfb16[bits >> 6] & eorx) ^ bgx, dest);
144 fb_writel((tab_cfb16[bits >> 4 & 3] & eorx) ^ bgx, dest+4);
145 if (fontwidth(p) == 8) {
146 fb_writel((tab_cfb16[bits >> 2 & 3] & eorx) ^ bgx, dest+8);
147 fb_writel((tab_cfb16[bits & 3] & eorx) ^ bgx, dest+12);
150 break;
151 case 12:
152 case 16:
153 cdat = p->fontdata + ((c & p->charmask) * fontheight(p) << 1);
154 for (rows = fontheight(p); rows--; dest += bytes) {
155 bits = *cdat++;
156 fb_writel((tab_cfb16[bits >> 6] & eorx) ^ bgx, dest);
157 fb_writel((tab_cfb16[bits >> 4 & 3] & eorx) ^ bgx, dest+4);
158 fb_writel((tab_cfb16[bits >> 2 & 3] & eorx) ^ bgx, dest+8);
159 fb_writel((tab_cfb16[bits & 3] & eorx) ^ bgx, dest+12);
160 bits = *cdat++;
161 fb_writel((tab_cfb16[bits >> 6] & eorx) ^ bgx, dest+16);
162 fb_writel((tab_cfb16[bits >> 4 & 3] & eorx) ^ bgx, dest+20);
163 if (fontwidth(p) == 16) {
164 fb_writel((tab_cfb16[bits >> 2 & 3] & eorx) ^ bgx, dest+24);
165 fb_writel((tab_cfb16[bits & 3] & eorx) ^ bgx, dest+28);
168 break;
172 void fbcon_cfb16_putcs(struct vc_data *conp, struct display *p,
173 const unsigned short *s, int count, int yy, int xx)
175 u8 *cdat, *dest, *dest0;
176 u16 c;
177 int rows, bytes = p->next_line;
178 u32 eorx, fgx, bgx;
180 dest0 = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 2;
181 fgx = ((u16 *)p->dispsw_data)[attr_fgcol(p, scr_readw(s))];
182 bgx = ((u16 *)p->dispsw_data)[attr_bgcol(p, scr_readw(s))];
183 fgx |= (fgx << 16);
184 bgx |= (bgx << 16);
185 eorx = fgx ^ bgx;
187 switch (fontwidth(p)) {
188 case 4:
189 case 8:
190 while (count--) {
191 c = scr_readw(s++) & p->charmask;
192 cdat = p->fontdata + c * fontheight(p);
193 for (rows = fontheight(p), dest = dest0; rows--; dest += bytes) {
194 u8 bits = *cdat++;
195 fb_writel((tab_cfb16[bits >> 6] & eorx) ^ bgx, dest);
196 fb_writel((tab_cfb16[bits >> 4 & 3] & eorx) ^ bgx, dest+4);
197 if (fontwidth(p) == 8) {
198 fb_writel((tab_cfb16[bits >> 2 & 3] & eorx) ^ bgx, dest+8);
199 fb_writel((tab_cfb16[bits & 3] & eorx) ^ bgx, dest+12);
202 dest0 += fontwidth(p)*2;;
204 break;
205 case 12:
206 case 16:
207 while (count--) {
208 c = scr_readw(s++) & p->charmask;
209 cdat = p->fontdata + (c * fontheight(p) << 1);
210 for (rows = fontheight(p), dest = dest0; rows--; dest += bytes) {
211 u8 bits = *cdat++;
212 fb_writel((tab_cfb16[bits >> 6] & eorx) ^ bgx, dest);
213 fb_writel((tab_cfb16[bits >> 4 & 3] & eorx) ^ bgx, dest+4);
214 fb_writel((tab_cfb16[bits >> 2 & 3] & eorx) ^ bgx, dest+8);
215 fb_writel((tab_cfb16[bits & 3] & eorx) ^ bgx, dest+12);
216 bits = *cdat++;
217 fb_writel((tab_cfb16[bits >> 6] & eorx) ^ bgx, dest+16);
218 fb_writel((tab_cfb16[bits >> 4 & 3] & eorx) ^ bgx, dest+20);
219 if (fontwidth(p) == 16) {
220 fb_writel((tab_cfb16[bits >> 2 & 3] & eorx) ^ bgx, dest+24);
221 fb_writel((tab_cfb16[bits & 3] & eorx) ^ bgx, dest+28);
224 dest0 += fontwidth(p)*2;
226 break;
230 void fbcon_cfb16_revc(struct display *p, int xx, int yy)
232 u8 *dest;
233 int bytes = p->next_line, rows;
235 dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p)*2;
236 for (rows = fontheight(p); rows--; dest += bytes) {
237 switch (fontwidth(p)) {
238 case 16:
239 fb_writel(fb_readl(dest+24) ^ 0xffffffff, dest+24);
240 fb_writel(fb_readl(dest+28) ^ 0xffffffff, dest+28);
241 /* FALL THROUGH */
242 case 12:
243 fb_writel(fb_readl(dest+16) ^ 0xffffffff, dest+16);
244 fb_writel(fb_readl(dest+20) ^ 0xffffffff, dest+20);
245 /* FALL THROUGH */
246 case 8:
247 fb_writel(fb_readl(dest+8) ^ 0xffffffff, dest+8);
248 fb_writel(fb_readl(dest+12) ^ 0xffffffff, dest+12);
249 /* FALL THROUGH */
250 case 4:
251 fb_writel(fb_readl(dest+0) ^ 0xffffffff, dest+0);
252 fb_writel(fb_readl(dest+4) ^ 0xffffffff, dest+4);
257 void fbcon_cfb16_clear_margins(struct vc_data *conp, struct display *p,
258 int bottom_only)
260 int bytes = p->next_line;
261 u32 bgx;
263 unsigned int right_start = conp->vc_cols*fontwidth(p);
264 unsigned int bottom_start = conp->vc_rows*fontheight(p);
265 unsigned int right_width, bottom_width;
267 bgx = ((u16 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
269 if (!bottom_only && (right_width = p->var.xres-right_start))
270 rectfill(p->screen_base+right_start*2, right_width,
271 p->var.yres_virtual, bgx, bytes);
272 if ((bottom_width = p->var.yres-bottom_start))
273 rectfill(p->screen_base+(p->var.yoffset+bottom_start)*bytes,
274 right_start, bottom_width, bgx, bytes);
279 * `switch' for the low level operations
282 struct display_switch fbcon_cfb16 = {
283 fbcon_cfb16_setup, fbcon_cfb16_bmove, fbcon_cfb16_clear, fbcon_cfb16_putc,
284 fbcon_cfb16_putcs, fbcon_cfb16_revc, NULL, NULL, fbcon_cfb16_clear_margins,
285 FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
289 #ifdef MODULE
290 int init_module(void)
292 return 0;
295 void cleanup_module(void)
297 #endif /* MODULE */
301 * Visible symbols for modules
304 EXPORT_SYMBOL(fbcon_cfb16);
305 EXPORT_SYMBOL(fbcon_cfb16_setup);
306 EXPORT_SYMBOL(fbcon_cfb16_bmove);
307 EXPORT_SYMBOL(fbcon_cfb16_clear);
308 EXPORT_SYMBOL(fbcon_cfb16_putc);
309 EXPORT_SYMBOL(fbcon_cfb16_putcs);
310 EXPORT_SYMBOL(fbcon_cfb16_revc);
311 EXPORT_SYMBOL(fbcon_cfb16_clear_margins);