1 /*
2 * linux/drivers/video/mfb.c -- Low level frame buffer operations for
3 * monochrome
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-mfb.h>
20
21
22 /*
23 * Monochrome
24 */
25
fbcon_mfb_setup(struct display * p)26 void fbcon_mfb_setup(struct display *p)
27 {
28 if (p->line_length)
29 p->next_line = p->line_length;
30 else
31 p->next_line = p->var.xres_virtual>>3;
32 p->next_plane = 0;
33 }
34
fbcon_mfb_bmove(struct display * p,int sy,int sx,int dy,int dx,int height,int width)35 void fbcon_mfb_bmove(struct display *p, int sy, int sx, int dy, int dx,
36 int height, int width)
37 {
38 u8 *src, *dest;
39 u_int rows;
40
41 if (sx == 0 && dx == 0 && width == p->next_line) {
42 src = p->screen_base+sy*fontheight(p)*width;
43 dest = p->screen_base+dy*fontheight(p)*width;
44 fb_memmove(dest, src, height*fontheight(p)*width);
45 } else if (dy <= sy) {
46 src = p->screen_base+sy*fontheight(p)*p->next_line+sx;
47 dest = p->screen_base+dy*fontheight(p)*p->next_line+dx;
48 for (rows = height*fontheight(p); rows--;) {
49 fb_memmove(dest, src, width);
50 src += p->next_line;
51 dest += p->next_line;
52 }
53 } else {
54 src = p->screen_base+((sy+height)*fontheight(p)-1)*p->next_line+sx;
55 dest = p->screen_base+((dy+height)*fontheight(p)-1)*p->next_line+dx;
56 for (rows = height*fontheight(p); rows--;) {
57 fb_memmove(dest, src, width);
58 src -= p->next_line;
59 dest -= p->next_line;
60 }
61 }
62 }
63
fbcon_mfb_clear(struct vc_data * conp,struct display * p,int sy,int sx,int height,int width)64 void fbcon_mfb_clear(struct vc_data *conp, struct display *p, int sy, int sx,
65 int height, int width)
66 {
67 u8 *dest;
68 u_int rows;
69 int inverse = conp ? attr_reverse(p,conp->vc_video_erase_char) : 0;
70
71 dest = p->screen_base+sy*fontheight(p)*p->next_line+sx;
72
73 if (sx == 0 && width == p->next_line) {
74 if (inverse)
75 fb_memset255(dest, height*fontheight(p)*width);
76 else
77 fb_memclear(dest, height*fontheight(p)*width);
78 } else
79 for (rows = height*fontheight(p); rows--; dest += p->next_line)
80 if (inverse)
81 fb_memset255(dest, width);
82 else
83 fb_memclear_small(dest, width);
84 }
85
fbcon_mfb_putc(struct vc_data * conp,struct display * p,int c,int yy,int xx)86 void fbcon_mfb_putc(struct vc_data *conp, struct display *p, int c, int yy,
87 int xx)
88 {
89 u8 *dest, *cdat;
90 u_int rows, bold, revs, underl;
91 u8 d;
92
93 dest = p->screen_base+yy*fontheight(p)*p->next_line+xx;
94 cdat = p->fontdata+(c&p->charmask)*fontheight(p);
95 bold = attr_bold(p,c);
96 revs = attr_reverse(p,c);
97 underl = attr_underline(p,c);
98
99 for (rows = fontheight(p); rows--; dest += p->next_line) {
100 d = *cdat++;
101 if (underl && !rows)
102 d = 0xff;
103 else if (bold)
104 d |= d>>1;
105 if (revs)
106 d = ~d;
107 fb_writeb (d, dest);
108 }
109 }
110
fbcon_mfb_putcs(struct vc_data * conp,struct display * p,const unsigned short * s,int count,int yy,int xx)111 void fbcon_mfb_putcs(struct vc_data *conp, struct display *p,
112 const unsigned short *s, int count, int yy, int xx)
113 {
114 u8 *dest, *dest0, *cdat;
115 u_int rows, bold, revs, underl;
116 u8 d;
117 u16 c;
118
119 dest0 = p->screen_base+yy*fontheight(p)*p->next_line+xx;
120 c = scr_readw(s);
121 bold = attr_bold(p, c);
122 revs = attr_reverse(p, c);
123 underl = attr_underline(p, c);
124
125 while (count--) {
126 c = scr_readw(s++) & p->charmask;
127 dest = dest0++;
128 cdat = p->fontdata+c*fontheight(p);
129 for (rows = fontheight(p); rows--; dest += p->next_line) {
130 d = *cdat++;
131 if (underl && !rows)
132 d = 0xff;
133 else if (bold)
134 d |= d>>1;
135 if (revs)
136 d = ~d;
137 fb_writeb (d, dest);
138 }
139 }
140 }
141
fbcon_mfb_revc(struct display * p,int xx,int yy)142 void fbcon_mfb_revc(struct display *p, int xx, int yy)
143 {
144 u8 *dest, d;
145 u_int rows;
146
147 dest = p->screen_base+yy*fontheight(p)*p->next_line+xx;
148 for (rows = fontheight(p); rows--; dest += p->next_line) {
149 d = fb_readb(dest);
150 fb_writeb (~d, dest);
151 }
152 }
153
fbcon_mfb_clear_margins(struct vc_data * conp,struct display * p,int bottom_only)154 void fbcon_mfb_clear_margins(struct vc_data *conp, struct display *p,
155 int bottom_only)
156 {
157 u8 *dest;
158 int height, bottom;
159 int inverse = conp ? attr_reverse(p,conp->vc_video_erase_char) : 0;
160
161 /* XXX Need to handle right margin? */
162
163 height = p->var.yres - conp->vc_rows * fontheight(p);
164 if (!height)
165 return;
166 bottom = conp->vc_rows + p->yscroll;
167 if (bottom >= p->vrows)
168 bottom -= p->vrows;
169 dest = p->screen_base + bottom * fontheight(p) * p->next_line;
170 if (inverse)
171 fb_memset255(dest, height * p->next_line);
172 else
173 fb_memclear(dest, height * p->next_line);
174 }
175
176
177 /*
178 * `switch' for the low level operations
179 */
180
181 struct display_switch fbcon_mfb = {
182 setup: fbcon_mfb_setup,
183 bmove: fbcon_mfb_bmove,
184 clear: fbcon_mfb_clear,
185 putc: fbcon_mfb_putc,
186 putcs: fbcon_mfb_putcs,
187 revc: fbcon_mfb_revc,
188 clear_margins: fbcon_mfb_clear_margins,
189 fontwidthmask: FONTWIDTH(8)
190 };
191
192
193 #ifdef MODULE
194 MODULE_LICENSE("GPL");
195
init_module(void)196 int init_module(void)
197 {
198 return 0;
199 }
200
cleanup_module(void)201 void cleanup_module(void)
202 {}
203 #endif /* MODULE */
204
205
206 /*
207 * Visible symbols for modules
208 */
209
210 EXPORT_SYMBOL(fbcon_mfb);
211 EXPORT_SYMBOL(fbcon_mfb_setup);
212 EXPORT_SYMBOL(fbcon_mfb_bmove);
213 EXPORT_SYMBOL(fbcon_mfb_clear);
214 EXPORT_SYMBOL(fbcon_mfb_putc);
215 EXPORT_SYMBOL(fbcon_mfb_putcs);
216 EXPORT_SYMBOL(fbcon_mfb_revc);
217 EXPORT_SYMBOL(fbcon_mfb_clear_margins);
218