1 /*
2 * linux/drivers/video/cfb16.c -- Low level frame buffer operations for 16 bpp
3 * truecolor 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 #include <asm/io.h>
18
19 #include <video/fbcon.h>
20 #include <video/fbcon-cfb16.h>
21
22
23 /*
24 * 16 bpp packed pixels
25 */
26
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
32 #else
33 #error FIXME: No endianness??
34 #endif
35 };
36
fbcon_cfb16_setup(struct display * p)37 void fbcon_cfb16_setup(struct display *p)
38 {
39 p->next_line = p->line_length ? p->line_length : p->var.xres_virtual<<1;
40 p->next_plane = 0;
41 }
42
fbcon_cfb16_bmove(struct display * p,int sy,int sx,int dy,int dx,int height,int width)43 void fbcon_cfb16_bmove(struct display *p, int sy, int sx, int dy, int dx,
44 int height, int width)
45 {
46 int bytes = p->next_line, linesize = bytes * fontheight(p), rows;
47 u8 *src, *dst;
48
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,
52 height * linesize);
53 return;
54 }
55 if (fontwidthlog(p)) {
56 sx <<= fontwidthlog(p)+1;
57 dx <<= fontwidthlog(p)+1;
58 width <<= fontwidthlog(p)+1;
59 } else {
60 sx *= fontwidth(p)*2;
61 dx *= fontwidth(p)*2;
62 width *= fontwidth(p)*2;
63 }
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);
69 src += bytes;
70 dst += bytes;
71 }
72 } else {
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);
77 src -= bytes;
78 dst -= bytes;
79 }
80 }
81 }
82
rectfill(u8 * dest,int width,int height,u32 data,int linesize)83 static inline void rectfill(u8 *dest, int width, int height, u32 data,
84 int linesize)
85 {
86 int i;
87
88 data |= data<<16;
89
90 while (height-- > 0) {
91 u32 *p = (u32 *)dest;
92 for (i = 0; i < width/4; i++) {
93 fb_writel(data, p++);
94 fb_writel(data, p++);
95 }
96 if (width & 2)
97 fb_writel(data, p++);
98 if (width & 1)
99 fb_writew(data, (u16*)p);
100 dest += linesize;
101 }
102 }
103
fbcon_cfb16_clear(struct vc_data * conp,struct display * p,int sy,int sx,int height,int width)104 void fbcon_cfb16_clear(struct vc_data *conp, struct display *p, int sy, int sx,
105 int height, int width)
106 {
107 u8 *dest;
108 int bytes = p->next_line, lines = height * fontheight(p);
109 u32 bgx;
110
111 dest = p->screen_base + sy * fontheight(p) * bytes + sx * fontwidth(p) * 2;
112
113 bgx = ((u16 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
114
115 width *= fontwidth(p)/4;
116 if (width * 8 == bytes)
117 rectfill(dest, lines * width * 4, 1, bgx, bytes);
118 else
119 rectfill(dest, width * 4, lines, bgx, bytes);
120 }
121
fbcon_cfb16_putc(struct vc_data * conp,struct display * p,int c,int yy,int xx)122 void fbcon_cfb16_putc(struct vc_data *conp, struct display *p, int c, int yy,
123 int xx)
124 {
125 u8 *dest, *cdat, bits;
126 int bytes = p->next_line, rows;
127 u32 eorx, fgx, bgx;
128
129 dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 2;
130
131 fgx = ((u16 *)p->dispsw_data)[attr_fgcol(p, c)];
132 bgx = ((u16 *)p->dispsw_data)[attr_bgcol(p, c)];
133 fgx |= (fgx << 16);
134 bgx |= (bgx << 16);
135 eorx = fgx ^ bgx;
136
137 switch (fontwidth(p)) {
138 case 4:
139 case 8:
140 cdat = p->fontdata + (c & p->charmask) * fontheight(p);
141 for (rows = fontheight(p); rows--; dest += bytes) {
142 bits = *cdat++;
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);
148 }
149 }
150 break;
151 case 12:
152 case 16:
153 cdat = p->fontdata + ((c & p->charmask) * fontheight(p) << 1);
154 for (rows = fontheight(p); rows--; dest += bytes) {
155 bits = *cdat++;
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);
160 bits = *cdat++;
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);
166 }
167 }
168 break;
169 }
170 }
171
fbcon_cfb16_putcs(struct vc_data * conp,struct display * p,const unsigned short * s,int count,int yy,int xx)172 void fbcon_cfb16_putcs(struct vc_data *conp, struct display *p,
173 const unsigned short *s, int count, int yy, int xx)
174 {
175 u8 *cdat, *dest, *dest0;
176 u16 c;
177 int rows, bytes = p->next_line;
178 u32 eorx, fgx, bgx;
179
180 dest0 = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 2;
181 c = scr_readw(s);
182 fgx = ((u16 *)p->dispsw_data)[attr_fgcol(p, c)];
183 bgx = ((u16 *)p->dispsw_data)[attr_bgcol(p, c)];
184 fgx |= (fgx << 16);
185 bgx |= (bgx << 16);
186 eorx = fgx ^ bgx;
187
188 switch (fontwidth(p)) {
189 case 4:
190 case 8:
191 while (count--) {
192 c = scr_readw(s++) & p->charmask;
193 cdat = p->fontdata + c * fontheight(p);
194 for (rows = fontheight(p), dest = dest0; rows--; dest += bytes) {
195 u8 bits = *cdat++;
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);
201 }
202 }
203 dest0 += fontwidth(p)*2;;
204 }
205 break;
206 case 12:
207 case 16:
208 while (count--) {
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) {
212 u8 bits = *cdat++;
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);
217 bits = *cdat++;
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);
223 }
224 }
225 dest0 += fontwidth(p)*2;
226 }
227 break;
228 }
229 }
230
fbcon_cfb16_revc(struct display * p,int xx,int yy)231 void fbcon_cfb16_revc(struct display *p, int xx, int yy)
232 {
233 u8 *dest;
234 int bytes = p->next_line, rows;
235
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)) {
239 case 16:
240 fb_writel(fb_readl(dest+24) ^ 0xffffffff, dest+24);
241 fb_writel(fb_readl(dest+28) ^ 0xffffffff, dest+28);
242 /* FALL THROUGH */
243 case 12:
244 fb_writel(fb_readl(dest+16) ^ 0xffffffff, dest+16);
245 fb_writel(fb_readl(dest+20) ^ 0xffffffff, dest+20);
246 /* FALL THROUGH */
247 case 8:
248 fb_writel(fb_readl(dest+8) ^ 0xffffffff, dest+8);
249 fb_writel(fb_readl(dest+12) ^ 0xffffffff, dest+12);
250 /* FALL THROUGH */
251 case 4:
252 fb_writel(fb_readl(dest+0) ^ 0xffffffff, dest+0);
253 fb_writel(fb_readl(dest+4) ^ 0xffffffff, dest+4);
254 }
255 }
256 }
257
fbcon_cfb16_clear_margins(struct vc_data * conp,struct display * p,int bottom_only)258 void fbcon_cfb16_clear_margins(struct vc_data *conp, struct display *p,
259 int bottom_only)
260 {
261 int bytes = p->next_line;
262 u32 bgx;
263
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;
267
268 bgx = ((u16 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
269
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);
276 }
277
278
279 /*
280 * `switch' for the low level operations
281 */
282
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)
292 };
293
294
295 #ifdef MODULE
296 MODULE_LICENSE("GPL");
297
init_module(void)298 int init_module(void)
299 {
300 return 0;
301 }
302
cleanup_module(void)303 void cleanup_module(void)
304 {}
305 #endif /* MODULE */
306
307
308 /*
309 * Visible symbols for modules
310 */
311
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);
320