2 * linux/drivers/video/cfb4.c -- Low level frame buffer operations for 4 bpp
5 * Created 26 Dec 1997 by Michael Schmitz
6 * Based on the old macfb.c 4bpp code by Alan Cox
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for
13 #include <linux/module.h>
14 #include <linux/tty.h>
15 #include <linux/console.h>
16 #include <linux/string.h>
19 #include <video/fbcon.h>
20 #include <video/fbcon-cfb4.h>
28 * IFF the font is even pixel aligned (that is to say each
29 * character start is a byte start in the pixel pairs). That
30 * avoids us having to mask bytes and means we won't be here
31 * all week. On a MacII that matters _lots_
34 static u16 nibbletab_cfb4
[] = {
35 #if defined(__BIG_ENDIAN)
36 0x0000,0x000f,0x00f0,0x00ff,
37 0x0f00,0x0f0f,0x0ff0,0x0fff,
38 0xf000,0xf00f,0xf0f0,0xf0ff,
39 0xff00,0xff0f,0xfff0,0xffff
40 #elif defined(__LITTLE_ENDIAN)
41 0x0000,0xf000,0x0f00,0xff00,
42 0x00f0,0xf0f0,0x0ff0,0xfff0,
43 0x000f,0xf00f,0x0f0f,0xff0f,
44 0x00ff,0xf0ff,0x0fff,0xffff
46 #error FIXME: No endianness??
51 void fbcon_cfb4_setup(struct display
*p
)
53 p
->next_line
= p
->line_length
? p
->line_length
: p
->var
.xres_virtual
>>1;
57 void fbcon_cfb4_bmove(struct display
*p
, int sy
, int sx
, int dy
, int dx
,
58 int height
, int width
)
60 int bytes
= p
->next_line
, linesize
= bytes
* fontheight(p
), rows
;
63 if (sx
== 0 && dx
== 0 && width
* 4 == bytes
) {
64 fb_memmove(p
->screen_base
+ dy
* linesize
,
65 p
->screen_base
+ sy
* linesize
,
69 if (dy
< sy
|| (dy
== sy
&& dx
< sx
)) {
70 src
= p
->screen_base
+ sy
* linesize
+ sx
* 4;
71 dst
= p
->screen_base
+ dy
* linesize
+ dx
* 4;
72 for (rows
= height
* fontheight(p
) ; rows
-- ;) {
73 fb_memmove(dst
, src
, width
* 4);
79 src
= p
->screen_base
+ (sy
+height
) * linesize
+ sx
* 4
81 dst
= p
->screen_base
+ (dy
+height
) * linesize
+ dx
* 4
83 for (rows
= height
* fontheight(p
) ; rows
-- ;) {
84 fb_memmove(dst
, src
, width
* 4);
92 void fbcon_cfb4_clear(struct vc_data
*conp
, struct display
*p
, int sy
, int sx
,
93 int height
, int width
)
96 int bytes
=p
->next_line
,lines
=height
* fontheight(p
), rows
, i
;
99 /* if(p->screen_base!=0xFDD00020)
101 dest
= p
->screen_base
+ sy
* fontheight(p
) * bytes
+ sx
* 4;
103 bgx
=attr_bgcol_ec(p
,conp
);
104 bgx
|= (bgx
<< 4); /* expand the colour to 32bits */
108 if (sx
== 0 && width
* 4 == bytes
) {
109 for (i
= 0 ; i
< lines
* width
; i
++) {
110 fb_writel (bgx
, dest
);
115 for (rows
= lines
; rows
-- ; dest0
+= bytes
) {
117 for (i
= 0 ; i
< width
; i
++) {
119 fb_writel (bgx
, dest
);
126 void fbcon_cfb4_putc(struct vc_data
*conp
, struct display
*p
, int c
, int yy
,
130 int bytes
=p
->next_line
,rows
;
133 dest
= p
->screen_base
+ yy
* fontheight(p
) * bytes
+ xx
* 4;
134 cdat
= p
->fontdata
+ (c
& p
->charmask
) * fontheight(p
);
144 for (rows
= fontheight(p
) ; rows
-- ; dest
+= bytes
) {
145 fb_writew((nibbletab_cfb4
[*cdat
>> 4] & eorx
) ^ bgx
, dest
+0);
146 fb_writew((nibbletab_cfb4
[*cdat
++ & 0xf] & eorx
) ^ bgx
, dest
+2);
150 void fbcon_cfb4_putcs(struct vc_data
*conp
, struct display
*p
,
151 const unsigned short *s
, int count
, int yy
, int xx
)
153 u8
*cdat
, *dest
, *dest0
;
155 int rows
,bytes
=p
->next_line
;
158 dest0
= p
->screen_base
+ yy
* fontheight(p
) * bytes
+ xx
* 4;
159 fgx
=attr_fgcol(p
,scr_readw(s
));
160 bgx
=attr_bgcol(p
,scr_readw(s
));
169 c
= scr_readw(s
++) & p
->charmask
;
170 cdat
= p
->fontdata
+ c
* fontheight(p
);
172 for (rows
= fontheight(p
), dest
= dest0
; rows
-- ; dest
+= bytes
) {
173 fb_writew((nibbletab_cfb4
[*cdat
>> 4] & eorx
) ^ bgx
, dest
+0);
174 fb_writew((nibbletab_cfb4
[*cdat
++ & 0xf] & eorx
) ^ bgx
, dest
+2);
180 void fbcon_cfb4_revc(struct display
*p
, int xx
, int yy
)
183 int bytes
=p
->next_line
, rows
;
185 dest
= p
->screen_base
+ yy
* fontheight(p
) * bytes
+ xx
* 4;
186 for (rows
= fontheight(p
) ; rows
-- ; dest
+= bytes
) {
187 fb_writel(fb_readl(dest
+0) ^ 0xffffffff, dest
+0);
193 * `switch' for the low level operations
196 struct display_switch fbcon_cfb4
= {
197 setup
: fbcon_cfb4_setup
,
198 bmove
: fbcon_cfb4_bmove
,
199 clear
: fbcon_cfb4_clear
,
200 putc
: fbcon_cfb4_putc
,
201 putcs
: fbcon_cfb4_putcs
,
202 revc
: fbcon_cfb4_revc
,
203 fontwidthmask
: FONTWIDTH(8)
208 int init_module(void)
213 void cleanup_module(void)
219 * Visible symbols for modules
222 EXPORT_SYMBOL(fbcon_cfb4
);
223 EXPORT_SYMBOL(fbcon_cfb4_setup
);
224 EXPORT_SYMBOL(fbcon_cfb4_bmove
);
225 EXPORT_SYMBOL(fbcon_cfb4_clear
);
226 EXPORT_SYMBOL(fbcon_cfb4_putc
);
227 EXPORT_SYMBOL(fbcon_cfb4_putcs
);
228 EXPORT_SYMBOL(fbcon_cfb4_revc
);