setup enviroment for compilation
[linux-2.4.21-pre4.git] / drivers / video / fbcon-cfb8.c
1 /*
2  *  linux/drivers/video/cfb8.c -- Low level frame buffer operations for 8 bpp
3  *                                packed pixels
4  *
5  *      Created 5 Apr 1997 by Geert Uytterhoeven
6  *
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.
10  */
11
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
18 #include <video/fbcon.h>
19 #include <video/fbcon-cfb8.h>
20
21
22     /*
23      *  8 bpp packed pixels
24      */
25
26 static u32 nibbletab_cfb8[] = {
27 #if defined(__BIG_ENDIAN)
28     0x00000000,0x000000ff,0x0000ff00,0x0000ffff,
29     0x00ff0000,0x00ff00ff,0x00ffff00,0x00ffffff,
30     0xff000000,0xff0000ff,0xff00ff00,0xff00ffff,
31     0xffff0000,0xffff00ff,0xffffff00,0xffffffff
32 #elif defined(__LITTLE_ENDIAN)
33     0x00000000,0xff000000,0x00ff0000,0xffff0000,
34     0x0000ff00,0xff00ff00,0x00ffff00,0xffffff00,
35     0x000000ff,0xff0000ff,0x00ff00ff,0xffff00ff,
36     0x0000ffff,0xff00ffff,0x00ffffff,0xffffffff
37 #else
38 #error FIXME: No endianness??
39 #endif
40 };
41
42 void fbcon_cfb8_setup(struct display *p)
43 {
44     p->next_line = p->line_length ? p->line_length : p->var.xres_virtual;
45     p->next_plane = 0;
46 }
47
48 void fbcon_cfb8_bmove(struct display *p, int sy, int sx, int dy, int dx,
49                       int height, int width)
50 {
51     int bytes = p->next_line, linesize = bytes * fontheight(p), rows;
52     u8 *src,*dst;
53
54     if (sx == 0 && dx == 0 && width * fontwidth(p) == bytes) {
55         fb_memmove(p->screen_base + dy * linesize,
56                   p->screen_base + sy * linesize,
57                   height * linesize);
58         return;
59     }
60     if (fontwidthlog(p)) {
61         sx <<= fontwidthlog(p); dx <<= fontwidthlog(p); width <<= fontwidthlog(p);
62     } else {
63         sx *= fontwidth(p); dx *= fontwidth(p); width *= fontwidth(p);
64     }
65     if (dy < sy || (dy == sy && dx < sx)) {
66         src = p->screen_base + sy * linesize + sx;
67         dst = p->screen_base + dy * linesize + dx;
68         for (rows = height * fontheight(p) ; rows-- ;) {
69             fb_memmove(dst, src, width);
70             src += bytes;
71             dst += bytes;
72         }
73     } else {
74         src = p->screen_base + (sy+height) * linesize + sx - bytes;
75         dst = p->screen_base + (dy+height) * linesize + dx - bytes;
76         for (rows = height * fontheight(p) ; rows-- ;) {
77             fb_memmove(dst, src, width);
78             src -= bytes;
79             dst -= bytes;
80         }
81     }
82 }
83
84 static inline void rectfill(u8 *dest, int width, int height, u8 data,
85                             int linesize)
86 {
87     while (height-- > 0) {
88         fb_memset(dest, data, width);
89         dest += linesize;
90     }
91 }
92
93 void fbcon_cfb8_clear(struct vc_data *conp, struct display *p, int sy, int sx,
94                       int height, int width)
95 {
96     u8 *dest;
97     int bytes=p->next_line,lines=height * fontheight(p);
98     u8 bgx;
99
100     dest = p->screen_base + sy * fontheight(p) * bytes + sx * fontwidth(p);
101
102     bgx=attr_bgcol_ec(p,conp);
103
104     width *= fontwidth(p);
105     if (width == bytes)
106         rectfill(dest, lines * width, 1, bgx, bytes);
107     else
108         rectfill(dest, width, lines, bgx, bytes);
109 }
110
111 void fbcon_cfb8_putc(struct vc_data *conp, struct display *p, int c, int yy,
112                      int xx)
113 {
114     u8 *dest,*cdat;
115     int bytes=p->next_line,rows;
116     u32 eorx,fgx,bgx;
117
118     dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p);
119     if (fontwidth(p) <= 8)
120         cdat = p->fontdata + (c & p->charmask) * fontheight(p);
121     else
122         cdat = p->fontdata + ((c & p->charmask) * fontheight(p) << 1);
123
124     fgx=attr_fgcol(p,c);
125     bgx=attr_bgcol(p,c);
126     fgx |= (fgx << 8);
127     fgx |= (fgx << 16);
128     bgx |= (bgx << 8);
129     bgx |= (bgx << 16);
130     eorx = fgx ^ bgx;
131
132     switch (fontwidth(p)) {
133     case 4:
134         for (rows = fontheight(p) ; rows-- ; dest += bytes)
135             fb_writel((nibbletab_cfb8[*cdat++ >> 4] & eorx) ^ bgx, dest);
136         break;
137     case 8:
138         for (rows = fontheight(p) ; rows-- ; dest += bytes) {
139             fb_writel((nibbletab_cfb8[*cdat >> 4] & eorx) ^ bgx, dest);
140             fb_writel((nibbletab_cfb8[*cdat++ & 0xf] & eorx) ^ bgx, dest+4);
141         }
142         break;
143     case 12:
144     case 16:
145         for (rows = fontheight(p) ; rows-- ; dest += bytes) {
146             fb_writel((nibbletab_cfb8[*cdat >> 4] & eorx) ^ bgx, dest);
147             fb_writel((nibbletab_cfb8[*cdat++ & 0xf] & eorx) ^ bgx, dest+4);
148             fb_writel((nibbletab_cfb8[(*cdat >> 4) & 0xf] & eorx) ^ bgx, dest+8);
149             if (fontwidth(p) == 16)
150                 fb_writel((nibbletab_cfb8[*cdat & 0xf] & eorx) ^ bgx, dest+12);
151             cdat++;
152         }
153         break;
154     }
155 }
156
157 void fbcon_cfb8_putcs(struct vc_data *conp, struct display *p, 
158                       const unsigned short *s, int count, int yy, int xx)
159 {
160     u8 *cdat, *dest, *dest0;
161     u16 c;
162     int rows,bytes=p->next_line;
163     u32 eorx, fgx, bgx;
164
165     dest0 = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p);
166     c = scr_readw(s);
167     fgx = attr_fgcol(p, c);
168     bgx = attr_bgcol(p, c);
169     fgx |= (fgx << 8);
170     fgx |= (fgx << 16);
171     bgx |= (bgx << 8);
172     bgx |= (bgx << 16);
173     eorx = fgx ^ bgx;
174     switch (fontwidth(p)) {
175     case 4:
176         while (count--) {
177             c = scr_readw(s++) & p->charmask;
178             cdat = p->fontdata + c * fontheight(p);
179
180             for (rows = fontheight(p), dest = dest0; rows-- ; dest += bytes)
181                 fb_writel((nibbletab_cfb8[*cdat++ >> 4] & eorx) ^ bgx, dest);
182             dest0+=4;
183         }
184         break;
185     case 8:
186         while (count--) {
187             c = scr_readw(s++) & p->charmask;
188             cdat = p->fontdata + c * fontheight(p);
189
190             for (rows = fontheight(p), dest = dest0; rows-- ; dest += bytes) {
191                 fb_writel((nibbletab_cfb8[*cdat >> 4] & eorx) ^ bgx, dest);
192                 fb_writel((nibbletab_cfb8[*cdat++ & 0xf] & eorx) ^ bgx, dest+4);
193             }
194             dest0+=8;
195         }
196         break;
197     case 12:
198     case 16:
199         while (count--) {
200             c = scr_readw(s++) & p->charmask;
201             cdat = p->fontdata + (c * fontheight(p) << 1);
202
203             for (rows = fontheight(p), dest = dest0; rows-- ; dest += bytes) {
204                 fb_writel((nibbletab_cfb8[*cdat >> 4] & eorx) ^ bgx, dest);
205                 fb_writel((nibbletab_cfb8[*cdat++ & 0xf] & eorx) ^ bgx, dest+4);
206                 fb_writel((nibbletab_cfb8[(*cdat >> 4) & 0xf] & eorx) ^ bgx, dest+8);
207                 if (fontwidth(p) == 16)
208                    fb_writel((nibbletab_cfb8[*cdat & 0xf] & eorx) ^ bgx, dest+12);
209                 cdat++;
210             }
211             dest0+=fontwidth(p);
212         }
213         break;
214     }
215 }
216
217 void fbcon_cfb8_revc(struct display *p, int xx, int yy)
218 {
219     u8 *dest;
220     int bytes=p->next_line, rows;
221
222     dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p);
223     for (rows = fontheight(p) ; rows-- ; dest += bytes) {
224         switch (fontwidth(p)) {
225         case 16: fb_writel(fb_readl(dest+12) ^ 0x0f0f0f0f, dest+12); /* fall thru */
226         case 12: fb_writel(fb_readl(dest+8) ^ 0x0f0f0f0f, dest+8); /* fall thru */
227         case 8: fb_writel(fb_readl(dest+4) ^ 0x0f0f0f0f, dest+4); /* fall thru */
228         case 4: fb_writel(fb_readl(dest) ^ 0x0f0f0f0f, dest); /* fall thru */
229         default: break;
230         }
231     }
232 }
233
234 void fbcon_cfb8_clear_margins(struct vc_data *conp, struct display *p,
235                               int bottom_only)
236 {
237     int bytes=p->next_line;
238     u8 bgx;
239
240     unsigned int right_start = conp->vc_cols*fontwidth(p);
241     unsigned int bottom_start = conp->vc_rows*fontheight(p);
242     unsigned int right_width, bottom_width;
243
244     bgx=attr_bgcol_ec(p,conp);
245
246     if (!bottom_only && (right_width = p->var.xres-right_start))
247         rectfill(p->screen_base+right_start, right_width, p->var.yres_virtual,
248                  bgx, bytes);
249     if ((bottom_width = p->var.yres-bottom_start))
250         rectfill(p->screen_base+(p->var.yoffset+bottom_start)*bytes,
251                  right_start, bottom_width, bgx, bytes);
252 }
253
254
255     /*
256      *  `switch' for the low level operations
257      */
258
259 struct display_switch fbcon_cfb8 = {
260     setup:              fbcon_cfb8_setup,
261     bmove:              fbcon_cfb8_bmove,
262     clear:              fbcon_cfb8_clear,
263     putc:               fbcon_cfb8_putc,
264     putcs:              fbcon_cfb8_putcs,
265     revc:               fbcon_cfb8_revc,
266     clear_margins:      fbcon_cfb8_clear_margins,
267     fontwidthmask:      FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
268 };
269
270
271 #ifdef MODULE
272 MODULE_LICENSE("GPL");
273
274 int init_module(void)
275 {
276     return 0;
277 }
278
279 void cleanup_module(void)
280 {}
281 #endif /* MODULE */
282
283
284     /*
285      *  Visible symbols for modules
286      */
287
288 EXPORT_SYMBOL(fbcon_cfb8);
289 EXPORT_SYMBOL(fbcon_cfb8_setup);
290 EXPORT_SYMBOL(fbcon_cfb8_bmove);
291 EXPORT_SYMBOL(fbcon_cfb8_clear);
292 EXPORT_SYMBOL(fbcon_cfb8_putc);
293 EXPORT_SYMBOL(fbcon_cfb8_putcs);
294 EXPORT_SYMBOL(fbcon_cfb8_revc);
295 EXPORT_SYMBOL(fbcon_cfb8_clear_margins);