2 * linux/drivers/video/cfb8.c -- Low level frame buffer operations for 8 bpp
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>
18 #include <video/fbcon.h>
19 #include <video/fbcon-cfb8.h>
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
38 #error FIXME: No endianness??
42 void fbcon_cfb8_setup(struct display
*p
)
44 p
->next_line
= p
->line_length
? p
->line_length
: p
->var
.xres_virtual
;
48 void fbcon_cfb8_bmove(struct display
*p
, int sy
, int sx
, int dy
, int dx
,
49 int height
, int width
)
51 int bytes
= p
->next_line
, linesize
= bytes
* fontheight(p
), rows
;
54 if (sx
== 0 && dx
== 0 && width
* fontwidth(p
) == bytes
) {
55 fb_memmove(p
->screen_base
+ dy
* linesize
,
56 p
->screen_base
+ sy
* linesize
,
60 if (fontwidthlog(p
)) {
61 sx
<<= fontwidthlog(p
); dx
<<= fontwidthlog(p
); width
<<= fontwidthlog(p
);
63 sx
*= fontwidth(p
); dx
*= fontwidth(p
); width
*= fontwidth(p
);
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
);
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
);
84 static inline void rectfill(u8
*dest
, int width
, int height
, u8 data
,
87 while (height
-- > 0) {
88 fb_memset(dest
, data
, width
);
93 void fbcon_cfb8_clear(struct vc_data
*conp
, struct display
*p
, int sy
, int sx
,
94 int height
, int width
)
97 int bytes
=p
->next_line
,lines
=height
* fontheight(p
);
100 dest
= p
->screen_base
+ sy
* fontheight(p
) * bytes
+ sx
* fontwidth(p
);
102 bgx
=attr_bgcol_ec(p
,conp
);
104 width
*= fontwidth(p
);
106 rectfill(dest
, lines
* width
, 1, bgx
, bytes
);
108 rectfill(dest
, width
, lines
, bgx
, bytes
);
111 void fbcon_cfb8_putc(struct vc_data
*conp
, struct display
*p
, int c
, int yy
,
115 int bytes
=p
->next_line
,rows
;
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
);
122 cdat
= p
->fontdata
+ ((c
& p
->charmask
) * fontheight(p
) << 1);
132 switch (fontwidth(p
)) {
134 for (rows
= fontheight(p
) ; rows
-- ; dest
+= bytes
)
135 fb_writel((nibbletab_cfb8
[*cdat
++ >> 4] & eorx
) ^ bgx
, dest
);
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);
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);
157 void fbcon_cfb8_putcs(struct vc_data
*conp
, struct display
*p
,
158 const unsigned short *s
, int count
, int yy
, int xx
)
160 u8
*cdat
, *dest
, *dest0
;
162 int rows
,bytes
=p
->next_line
;
165 dest0
= p
->screen_base
+ yy
* fontheight(p
) * bytes
+ xx
* fontwidth(p
);
166 fgx
=attr_fgcol(p
,scr_readw(s
));
167 bgx
=attr_bgcol(p
,scr_readw(s
));
173 switch (fontwidth(p
)) {
176 c
= scr_readw(s
++) & p
->charmask
;
177 cdat
= p
->fontdata
+ c
* fontheight(p
);
179 for (rows
= fontheight(p
), dest
= dest0
; rows
-- ; dest
+= bytes
)
180 fb_writel((nibbletab_cfb8
[*cdat
++ >> 4] & eorx
) ^ bgx
, dest
);
186 c
= scr_readw(s
++) & p
->charmask
;
187 cdat
= p
->fontdata
+ c
* fontheight(p
);
189 for (rows
= fontheight(p
), dest
= dest0
; rows
-- ; dest
+= bytes
) {
190 fb_writel((nibbletab_cfb8
[*cdat
>> 4] & eorx
) ^ bgx
, dest
);
191 fb_writel((nibbletab_cfb8
[*cdat
++ & 0xf] & eorx
) ^ bgx
, dest
+4);
199 c
= scr_readw(s
++) & p
->charmask
;
200 cdat
= p
->fontdata
+ (c
* fontheight(p
) << 1);
202 for (rows
= fontheight(p
), dest
= dest0
; rows
-- ; dest
+= bytes
) {
203 fb_writel((nibbletab_cfb8
[*cdat
>> 4] & eorx
) ^ bgx
, dest
);
204 fb_writel((nibbletab_cfb8
[*cdat
++ & 0xf] & eorx
) ^ bgx
, dest
+4);
205 fb_writel((nibbletab_cfb8
[(*cdat
>> 4) & 0xf] & eorx
) ^ bgx
, dest
+8);
206 if (fontwidth(p
) == 16)
207 fb_writel((nibbletab_cfb8
[*cdat
& 0xf] & eorx
) ^ bgx
, dest
+12);
216 void fbcon_cfb8_revc(struct display
*p
, int xx
, int yy
)
219 int bytes
=p
->next_line
, rows
;
221 dest
= p
->screen_base
+ yy
* fontheight(p
) * bytes
+ xx
* fontwidth(p
);
222 for (rows
= fontheight(p
) ; rows
-- ; dest
+= bytes
) {
223 switch (fontwidth(p
)) {
224 case 16: fb_writel(fb_readl(dest
+12) ^ 0x0f0f0f0f, dest
+12); /* fall thru */
225 case 12: fb_writel(fb_readl(dest
+8) ^ 0x0f0f0f0f, dest
+8); /* fall thru */
226 case 8: fb_writel(fb_readl(dest
+4) ^ 0x0f0f0f0f, dest
+4); /* fall thru */
227 case 4: fb_writel(fb_readl(dest
) ^ 0x0f0f0f0f, dest
); /* fall thru */
233 void fbcon_cfb8_clear_margins(struct vc_data
*conp
, struct display
*p
,
236 int bytes
=p
->next_line
;
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
=attr_bgcol_ec(p
,conp
);
245 if (!bottom_only
&& (right_width
= p
->var
.xres
-right_start
))
246 rectfill(p
->screen_base
+right_start
, right_width
, p
->var
.yres_virtual
,
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_cfb8
= {
259 fbcon_cfb8_setup
, fbcon_cfb8_bmove
, fbcon_cfb8_clear
, fbcon_cfb8_putc
,
260 fbcon_cfb8_putcs
, fbcon_cfb8_revc
, NULL
, NULL
, fbcon_cfb8_clear_margins
,
261 FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
266 int init_module(void)
271 void cleanup_module(void)
277 * Visible symbols for modules
280 EXPORT_SYMBOL(fbcon_cfb8
);
281 EXPORT_SYMBOL(fbcon_cfb8_setup
);
282 EXPORT_SYMBOL(fbcon_cfb8_bmove
);
283 EXPORT_SYMBOL(fbcon_cfb8_clear
);
284 EXPORT_SYMBOL(fbcon_cfb8_putc
);
285 EXPORT_SYMBOL(fbcon_cfb8_putcs
);
286 EXPORT_SYMBOL(fbcon_cfb8_revc
);
287 EXPORT_SYMBOL(fbcon_cfb8_clear_margins
);