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;
181 fgx
= ((u16
*)p
->dispsw_data
)[attr_fgcol(p
, scr_readw(s
))];
182 bgx
= ((u16
*)p
->dispsw_data
)[attr_bgcol(p
, scr_readw(s
))];
187 switch (fontwidth(p
)) {
191 c
= scr_readw(s
++) & p
->charmask
;
192 cdat
= p
->fontdata
+ c
* fontheight(p
);
193 for (rows
= fontheight(p
), dest
= dest0
; rows
--; dest
+= bytes
) {
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;;
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
) {
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);
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;
230 void fbcon_cfb16_revc(struct display
*p
, int xx
, int yy
)
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
)) {
239 fb_writel(fb_readl(dest
+24) ^ 0xffffffff, dest
+24);
240 fb_writel(fb_readl(dest
+28) ^ 0xffffffff, dest
+28);
243 fb_writel(fb_readl(dest
+16) ^ 0xffffffff, dest
+16);
244 fb_writel(fb_readl(dest
+20) ^ 0xffffffff, dest
+20);
247 fb_writel(fb_readl(dest
+8) ^ 0xffffffff, dest
+8);
248 fb_writel(fb_readl(dest
+12) ^ 0xffffffff, dest
+12);
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
,
260 int bytes
= p
->next_line
;
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)
290 int init_module(void)
295 void cleanup_module(void)
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
);