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
12 #include <linux/module.h>
13 #include <linux/tty.h>
14 #include <linux/console.h>
15 #include <linux/string.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
33 #error FIXME: No endianness??
37 void fbcon_cfb16_setup(struct display *p)
39 p->next_line = p->line_length ? p->line_length : p->var.xres_virtual<<1;
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;
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,
55 if (fontwidthlog(p)) {
56 sx <<= fontwidthlog(p)+1;
57 dx <<= fontwidthlog(p)+1;
58 width <<= fontwidthlog(p)+1;
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);
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);
83 static inline void rectfill(u8 *dest, int width, int height, u32 data,
90 while (height-- > 0) {
92 for (i = 0; i < width/4; i++) {
99 fb_writew(data, (u16*)p);
104 void fbcon_cfb16_clear(struct vc_data *conp, struct display *p, int sy, int sx,
105 int height, int width)
108 int bytes = p->next_line, lines = height * fontheight(p);
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);
119 rectfill(dest, width * 4, lines, bgx, bytes);
122 void fbcon_cfb16_putc(struct vc_data *conp, struct display *p, int c, int yy,
125 u8 *dest, *cdat, bits;
126 int bytes = p->next_line, rows;
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)];
137 switch (fontwidth(p)) {
140 cdat = p->fontdata + (c & p->charmask) * fontheight(p);
141 for (rows = fontheight(p); rows--; dest += bytes) {
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);
153 cdat = p->fontdata + ((c & p->charmask) * fontheight(p) << 1);
154 for (rows = fontheight(p); rows--; dest += bytes) {
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);
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);
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;
177 int rows, bytes = p->next_line;
180 dest0 = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 2;
182 fgx = ((u16 *)p->dispsw_data)[attr_fgcol(p, c)];
183 bgx = ((u16 *)p->dispsw_data)[attr_bgcol(p, c)];
188 switch (fontwidth(p)) {
192 c = scr_readw(s++) & p->charmask;
193 cdat = p->fontdata + c * fontheight(p);
194 for (rows = fontheight(p), dest = dest0; rows--; dest += bytes) {
196 fb_writel((tab_cfb16[bits >> 6] & eorx) ^ bgx, dest);
197 fb_writel((tab_cfb16[bits >> 4 & 3] & eorx) ^ bgx, dest+4);
198 if (fontwidth(p) == 8) {
199 fb_writel((tab_cfb16[bits >> 2 & 3] & eorx) ^ bgx, dest+8);
200 fb_writel((tab_cfb16[bits & 3] & eorx) ^ bgx, dest+12);
203 dest0 += fontwidth(p)*2;;
209 c = scr_readw(s++) & p->charmask;
210 cdat = p->fontdata + (c * fontheight(p) << 1);
211 for (rows = fontheight(p), dest = dest0; rows--; dest += bytes) {
213 fb_writel((tab_cfb16[bits >> 6] & eorx) ^ bgx, dest);
214 fb_writel((tab_cfb16[bits >> 4 & 3] & eorx) ^ bgx, dest+4);
215 fb_writel((tab_cfb16[bits >> 2 & 3] & eorx) ^ bgx, dest+8);
216 fb_writel((tab_cfb16[bits & 3] & eorx) ^ bgx, dest+12);
218 fb_writel((tab_cfb16[bits >> 6] & eorx) ^ bgx, dest+16);
219 fb_writel((tab_cfb16[bits >> 4 & 3] & eorx) ^ bgx, dest+20);
220 if (fontwidth(p) == 16) {
221 fb_writel((tab_cfb16[bits >> 2 & 3] & eorx) ^ bgx, dest+24);
222 fb_writel((tab_cfb16[bits & 3] & eorx) ^ bgx, dest+28);
225 dest0 += fontwidth(p)*2;
231 void fbcon_cfb16_revc(struct display *p, int xx, int yy)
234 int bytes = p->next_line, rows;
236 dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p)*2;
237 for (rows = fontheight(p); rows--; dest += bytes) {
238 switch (fontwidth(p)) {
240 fb_writel(fb_readl(dest+24) ^ 0xffffffff, dest+24);
241 fb_writel(fb_readl(dest+28) ^ 0xffffffff, dest+28);
244 fb_writel(fb_readl(dest+16) ^ 0xffffffff, dest+16);
245 fb_writel(fb_readl(dest+20) ^ 0xffffffff, dest+20);
248 fb_writel(fb_readl(dest+8) ^ 0xffffffff, dest+8);
249 fb_writel(fb_readl(dest+12) ^ 0xffffffff, dest+12);
252 fb_writel(fb_readl(dest+0) ^ 0xffffffff, dest+0);
253 fb_writel(fb_readl(dest+4) ^ 0xffffffff, dest+4);
258 void fbcon_cfb16_clear_margins(struct vc_data *conp, struct display *p,
261 int bytes = p->next_line;
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 = ((u16 *)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*2, 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_cfb16 = {
284 setup: fbcon_cfb16_setup,
285 bmove: fbcon_cfb16_bmove,
286 clear: fbcon_cfb16_clear,
287 putc: fbcon_cfb16_putc,
288 putcs: fbcon_cfb16_putcs,
289 revc: fbcon_cfb16_revc,
290 clear_margins: fbcon_cfb16_clear_margins,
291 fontwidthmask: FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
296 MODULE_LICENSE("GPL");
298 int init_module(void)
303 void cleanup_module(void)
309 * Visible symbols for modules
312 EXPORT_SYMBOL(fbcon_cfb16);
313 EXPORT_SYMBOL(fbcon_cfb16_setup);
314 EXPORT_SYMBOL(fbcon_cfb16_bmove);
315 EXPORT_SYMBOL(fbcon_cfb16_clear);
316 EXPORT_SYMBOL(fbcon_cfb16_putc);
317 EXPORT_SYMBOL(fbcon_cfb16_putcs);
318 EXPORT_SYMBOL(fbcon_cfb16_revc);
319 EXPORT_SYMBOL(fbcon_cfb16_clear_margins);