diff options
author | Antonino A. Daplas <adaplas@gmail.com> | 2005-11-09 00:39:14 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-11-09 10:56:34 -0500 |
commit | ed8c0e99f27451a9b980adf0de318d60e6de811f (patch) | |
tree | 5319e0c8669bddc682408bf113361a415a75a17f | |
parent | 33ee82978c4ecf7cbd56064391c9385264185de2 (diff) |
[PATCH] fbcon: Console Rotation - Add support for 270-degree rotation
Add support for 270-degree (counterclockwise) rotation of the console. To
activate, boot with:
fbcon=rotate:3
Signed-off-by: Antonino Daplas <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | drivers/video/console/Makefile | 3 | ||||
-rw-r--r-- | drivers/video/console/fbcon_ccw.c | 428 | ||||
-rw-r--r-- | drivers/video/console/fbcon_rotate.c | 3 | ||||
-rw-r--r-- | drivers/video/console/fbcon_rotate.h | 1 |
4 files changed, 434 insertions, 1 deletions
diff --git a/drivers/video/console/Makefile b/drivers/video/console/Makefile index 830ff46e0d1a..fed600c9ca55 100644 --- a/drivers/video/console/Makefile +++ b/drivers/video/console/Makefile | |||
@@ -32,7 +32,8 @@ ifeq ($(CONFIG_FB_TILEBLITTING),y) | |||
32 | obj-$(CONFIG_FRAMEBUFFER_CONSOLE) += tileblit.o | 32 | obj-$(CONFIG_FRAMEBUFFER_CONSOLE) += tileblit.o |
33 | endif | 33 | endif |
34 | ifeq ($(CONFIG_FRAMEBUFFER_CONSOLE_ROTATION),y) | 34 | ifeq ($(CONFIG_FRAMEBUFFER_CONSOLE_ROTATION),y) |
35 | obj-$(CONFIG_FRAMEBUFFER_CONSOLE) += fbcon_rotate.o fbcon_cw.o fbcon_ud.o | 35 | obj-$(CONFIG_FRAMEBUFFER_CONSOLE) += fbcon_rotate.o fbcon_cw.o fbcon_ud.o \ |
36 | fbcon_ccw.o | ||
36 | endif | 37 | endif |
37 | 38 | ||
38 | obj-$(CONFIG_FB_STI) += sticore.o font.o | 39 | obj-$(CONFIG_FB_STI) += sticore.o font.o |
diff --git a/drivers/video/console/fbcon_ccw.c b/drivers/video/console/fbcon_ccw.c new file mode 100644 index 000000000000..680aabab73c5 --- /dev/null +++ b/drivers/video/console/fbcon_ccw.c | |||
@@ -0,0 +1,428 @@ | |||
1 | /* | ||
2 | * linux/drivers/video/console/fbcon_ccw.c -- Software Rotation - 270 degrees | ||
3 | * | ||
4 | * Copyright (C) 2005 Antonino Daplas <adaplas @pol.net> | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of the GNU General Public | ||
7 | * License. See the file COPYING in the main directory of this archive for | ||
8 | * more details. | ||
9 | */ | ||
10 | |||
11 | #include <linux/config.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/string.h> | ||
14 | #include <linux/fb.h> | ||
15 | #include <linux/vt_kern.h> | ||
16 | #include <linux/console.h> | ||
17 | #include <asm/types.h> | ||
18 | #include "fbcon.h" | ||
19 | #include "fbcon_rotate.h" | ||
20 | |||
21 | /* | ||
22 | * Rotation 270 degrees | ||
23 | */ | ||
24 | |||
25 | static inline void ccw_update_attr(u8 *dst, u8 *src, int attribute, | ||
26 | struct vc_data *vc) | ||
27 | { | ||
28 | int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2; | ||
29 | int width = (vc->vc_font.height + 7) >> 3; | ||
30 | int mod = vc->vc_font.height % 8; | ||
31 | u8 c, msk = ~(0xff << offset), msk1 = 0; | ||
32 | |||
33 | if (mod) | ||
34 | msk <<= (8 - mod); | ||
35 | |||
36 | if (offset > mod) | ||
37 | set_bit(FBCON_BIT(7), (void *)&msk1); | ||
38 | |||
39 | for (i = 0; i < vc->vc_font.width; i++) { | ||
40 | for (j = 0; j < width; j++) { | ||
41 | c = *src; | ||
42 | |||
43 | if (attribute & FBCON_ATTRIBUTE_UNDERLINE) { | ||
44 | if (j == width - 1) | ||
45 | c |= msk; | ||
46 | |||
47 | if (msk1 && j == width - 2) | ||
48 | c |= msk1; | ||
49 | } | ||
50 | |||
51 | if (attribute & FBCON_ATTRIBUTE_BOLD && i) | ||
52 | *(dst - width) |= c; | ||
53 | |||
54 | if (attribute & FBCON_ATTRIBUTE_REVERSE) | ||
55 | c = ~c; | ||
56 | src++; | ||
57 | *dst++ = c; | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | |||
63 | static void ccw_bmove(struct vc_data *vc, struct fb_info *info, int sy, | ||
64 | int sx, int dy, int dx, int height, int width) | ||
65 | { | ||
66 | struct display *p = &fb_display[vc->vc_num]; | ||
67 | struct fb_copyarea area; | ||
68 | u32 vyres = GETVYRES(p->scrollmode, info); | ||
69 | |||
70 | area.sx = sy * vc->vc_font.height; | ||
71 | area.sy = vyres - ((sx + width) * vc->vc_font.width); | ||
72 | area.dx = dy * vc->vc_font.height; | ||
73 | area.dy = vyres - ((dx + width) * vc->vc_font.width); | ||
74 | area.width = height * vc->vc_font.height; | ||
75 | area.height = width * vc->vc_font.width; | ||
76 | |||
77 | info->fbops->fb_copyarea(info, &area); | ||
78 | } | ||
79 | |||
80 | static void ccw_clear(struct vc_data *vc, struct fb_info *info, int sy, | ||
81 | int sx, int height, int width) | ||
82 | { | ||
83 | struct display *p = &fb_display[vc->vc_num]; | ||
84 | struct fb_fillrect region; | ||
85 | int bgshift = (vc->vc_hi_font_mask) ? 13 : 12; | ||
86 | u32 vyres = GETVYRES(p->scrollmode, info); | ||
87 | |||
88 | region.color = attr_bgcol_ec(bgshift,vc); | ||
89 | region.dx = sy * vc->vc_font.height; | ||
90 | region.dy = vyres - ((sx + width) * vc->vc_font.width); | ||
91 | region.height = width * vc->vc_font.width; | ||
92 | region.width = height * vc->vc_font.height; | ||
93 | region.rop = ROP_COPY; | ||
94 | |||
95 | info->fbops->fb_fillrect(info, ®ion); | ||
96 | } | ||
97 | |||
98 | static inline void ccw_putcs_aligned(struct vc_data *vc, struct fb_info *info, | ||
99 | const u16 *s, u32 attr, u32 cnt, | ||
100 | u32 d_pitch, u32 s_pitch, u32 cellsize, | ||
101 | struct fb_image *image, u8 *buf, u8 *dst) | ||
102 | { | ||
103 | struct fbcon_ops *ops = info->fbcon_par; | ||
104 | u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; | ||
105 | u32 idx = (vc->vc_font.height + 7) >> 3; | ||
106 | u8 *src; | ||
107 | |||
108 | while (cnt--) { | ||
109 | src = ops->fontbuffer + (scr_readw(s--) & charmask)*cellsize; | ||
110 | |||
111 | if (attr) { | ||
112 | ccw_update_attr(buf, src, attr, vc); | ||
113 | src = buf; | ||
114 | } | ||
115 | |||
116 | if (likely(idx == 1)) | ||
117 | __fb_pad_aligned_buffer(dst, d_pitch, src, idx, | ||
118 | vc->vc_font.width); | ||
119 | else | ||
120 | fb_pad_aligned_buffer(dst, d_pitch, src, idx, | ||
121 | vc->vc_font.width); | ||
122 | |||
123 | dst += d_pitch * vc->vc_font.width; | ||
124 | } | ||
125 | |||
126 | info->fbops->fb_imageblit(info, image); | ||
127 | } | ||
128 | |||
129 | static void ccw_putcs(struct vc_data *vc, struct fb_info *info, | ||
130 | const unsigned short *s, int count, int yy, int xx, | ||
131 | int fg, int bg) | ||
132 | { | ||
133 | struct fb_image image; | ||
134 | struct display *p = &fb_display[vc->vc_num]; | ||
135 | struct fbcon_ops *ops = info->fbcon_par; | ||
136 | u32 width = (vc->vc_font.height + 7)/8; | ||
137 | u32 cellsize = width * vc->vc_font.width; | ||
138 | u32 maxcnt = info->pixmap.size/cellsize; | ||
139 | u32 scan_align = info->pixmap.scan_align - 1; | ||
140 | u32 buf_align = info->pixmap.buf_align - 1; | ||
141 | u32 cnt, pitch, size; | ||
142 | u32 attribute = get_attribute(info, scr_readw(s)); | ||
143 | u8 *dst, *buf = NULL; | ||
144 | u32 vyres = GETVYRES(p->scrollmode, info); | ||
145 | |||
146 | if (!ops->fontbuffer) | ||
147 | return; | ||
148 | |||
149 | image.fg_color = fg; | ||
150 | image.bg_color = bg; | ||
151 | image.dx = yy * vc->vc_font.height; | ||
152 | image.dy = vyres - ((xx + count) * vc->vc_font.width); | ||
153 | image.width = vc->vc_font.height; | ||
154 | image.depth = 1; | ||
155 | |||
156 | if (attribute) { | ||
157 | buf = kmalloc(cellsize, GFP_KERNEL); | ||
158 | if (!buf) | ||
159 | return; | ||
160 | } | ||
161 | |||
162 | s += count - 1; | ||
163 | |||
164 | while (count) { | ||
165 | if (count > maxcnt) | ||
166 | cnt = maxcnt; | ||
167 | else | ||
168 | cnt = count; | ||
169 | |||
170 | image.height = vc->vc_font.width * cnt; | ||
171 | pitch = ((image.width + 7) >> 3) + scan_align; | ||
172 | pitch &= ~scan_align; | ||
173 | size = pitch * image.height + buf_align; | ||
174 | size &= ~buf_align; | ||
175 | dst = fb_get_buffer_offset(info, &info->pixmap, size); | ||
176 | image.data = dst; | ||
177 | ccw_putcs_aligned(vc, info, s, attribute, cnt, pitch, | ||
178 | width, cellsize, &image, buf, dst); | ||
179 | image.dy += image.height; | ||
180 | count -= cnt; | ||
181 | s -= cnt; | ||
182 | } | ||
183 | |||
184 | /* buf is always NULL except when in monochrome mode, so in this case | ||
185 | it's a gain to check buf against NULL even though kfree() handles | ||
186 | NULL pointers just fine */ | ||
187 | if (unlikely(buf)) | ||
188 | kfree(buf); | ||
189 | |||
190 | } | ||
191 | |||
192 | static void ccw_clear_margins(struct vc_data *vc, struct fb_info *info, | ||
193 | int bottom_only) | ||
194 | { | ||
195 | unsigned int cw = vc->vc_font.width; | ||
196 | unsigned int ch = vc->vc_font.height; | ||
197 | unsigned int rw = info->var.yres - (vc->vc_cols*cw); | ||
198 | unsigned int bh = info->var.xres - (vc->vc_rows*ch); | ||
199 | unsigned int bs = vc->vc_rows*ch; | ||
200 | struct fb_fillrect region; | ||
201 | int bgshift = (vc->vc_hi_font_mask) ? 13 : 12; | ||
202 | |||
203 | region.color = attr_bgcol_ec(bgshift,vc); | ||
204 | region.rop = ROP_COPY; | ||
205 | |||
206 | if (rw && !bottom_only) { | ||
207 | region.dx = 0; | ||
208 | region.dy = info->var.yoffset; | ||
209 | region.height = rw; | ||
210 | region.width = info->var.xres_virtual; | ||
211 | info->fbops->fb_fillrect(info, ®ion); | ||
212 | } | ||
213 | |||
214 | if (bh) { | ||
215 | region.dx = info->var.xoffset + bs; | ||
216 | region.dy = 0; | ||
217 | region.height = info->var.yres_virtual; | ||
218 | region.width = bh; | ||
219 | info->fbops->fb_fillrect(info, ®ion); | ||
220 | } | ||
221 | } | ||
222 | |||
223 | static void ccw_cursor(struct vc_data *vc, struct fb_info *info, | ||
224 | struct display *p, int mode, int softback_lines, | ||
225 | int fg, int bg) | ||
226 | { | ||
227 | struct fb_cursor cursor; | ||
228 | struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par; | ||
229 | unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; | ||
230 | int w = (vc->vc_font.height + 7) >> 3, c; | ||
231 | int y = real_y(p, vc->vc_y); | ||
232 | int attribute, use_sw = (vc->vc_cursor_type & 0x10); | ||
233 | int err = 1, dx, dy; | ||
234 | char *src; | ||
235 | u32 vyres = GETVYRES(p->scrollmode, info); | ||
236 | |||
237 | if (!ops->fontbuffer) | ||
238 | return; | ||
239 | |||
240 | cursor.set = 0; | ||
241 | |||
242 | if (softback_lines) { | ||
243 | if (y + softback_lines >= vc->vc_rows) { | ||
244 | mode = CM_ERASE; | ||
245 | ops->cursor_flash = 0; | ||
246 | return; | ||
247 | } else | ||
248 | y += softback_lines; | ||
249 | } | ||
250 | |||
251 | c = scr_readw((u16 *) vc->vc_pos); | ||
252 | attribute = get_attribute(info, c); | ||
253 | src = ops->fontbuffer + ((c & charmask) * (w * vc->vc_font.width)); | ||
254 | |||
255 | if (ops->cursor_state.image.data != src || | ||
256 | ops->cursor_reset) { | ||
257 | ops->cursor_state.image.data = src; | ||
258 | cursor.set |= FB_CUR_SETIMAGE; | ||
259 | } | ||
260 | |||
261 | if (attribute) { | ||
262 | u8 *dst; | ||
263 | |||
264 | dst = kmalloc(w * vc->vc_font.width, GFP_ATOMIC); | ||
265 | if (!dst) | ||
266 | return; | ||
267 | kfree(ops->cursor_data); | ||
268 | ops->cursor_data = dst; | ||
269 | ccw_update_attr(dst, src, attribute, vc); | ||
270 | src = dst; | ||
271 | } | ||
272 | |||
273 | if (ops->cursor_state.image.fg_color != fg || | ||
274 | ops->cursor_state.image.bg_color != bg || | ||
275 | ops->cursor_reset) { | ||
276 | ops->cursor_state.image.fg_color = fg; | ||
277 | ops->cursor_state.image.bg_color = bg; | ||
278 | cursor.set |= FB_CUR_SETCMAP; | ||
279 | } | ||
280 | |||
281 | if (ops->cursor_state.image.height != vc->vc_font.width || | ||
282 | ops->cursor_state.image.width != vc->vc_font.height || | ||
283 | ops->cursor_reset) { | ||
284 | ops->cursor_state.image.height = vc->vc_font.width; | ||
285 | ops->cursor_state.image.width = vc->vc_font.height; | ||
286 | cursor.set |= FB_CUR_SETSIZE; | ||
287 | } | ||
288 | |||
289 | dx = y * vc->vc_font.height; | ||
290 | dy = vyres - ((vc->vc_x + 1) * vc->vc_font.width); | ||
291 | |||
292 | if (ops->cursor_state.image.dx != dx || | ||
293 | ops->cursor_state.image.dy != dy || | ||
294 | ops->cursor_reset) { | ||
295 | ops->cursor_state.image.dx = dx; | ||
296 | ops->cursor_state.image.dy = dy; | ||
297 | cursor.set |= FB_CUR_SETPOS; | ||
298 | } | ||
299 | |||
300 | if (ops->cursor_state.hot.x || ops->cursor_state.hot.y || | ||
301 | ops->cursor_reset) { | ||
302 | ops->cursor_state.hot.x = cursor.hot.y = 0; | ||
303 | cursor.set |= FB_CUR_SETHOT; | ||
304 | } | ||
305 | |||
306 | if (cursor.set & FB_CUR_SETSIZE || | ||
307 | vc->vc_cursor_type != p->cursor_shape || | ||
308 | ops->cursor_state.mask == NULL || | ||
309 | ops->cursor_reset) { | ||
310 | char *tmp, *mask = kmalloc(w*vc->vc_font.width, GFP_ATOMIC); | ||
311 | int cur_height, size, i = 0; | ||
312 | int width = (vc->vc_font.width + 7)/8; | ||
313 | |||
314 | if (!mask) | ||
315 | return; | ||
316 | |||
317 | tmp = kmalloc(width * vc->vc_font.height, GFP_ATOMIC); | ||
318 | |||
319 | if (!tmp) { | ||
320 | kfree(mask); | ||
321 | return; | ||
322 | } | ||
323 | |||
324 | kfree(ops->cursor_state.mask); | ||
325 | ops->cursor_state.mask = mask; | ||
326 | |||
327 | p->cursor_shape = vc->vc_cursor_type; | ||
328 | cursor.set |= FB_CUR_SETSHAPE; | ||
329 | |||
330 | switch (p->cursor_shape & CUR_HWMASK) { | ||
331 | case CUR_NONE: | ||
332 | cur_height = 0; | ||
333 | break; | ||
334 | case CUR_UNDERLINE: | ||
335 | cur_height = (vc->vc_font.height < 10) ? 1 : 2; | ||
336 | break; | ||
337 | case CUR_LOWER_THIRD: | ||
338 | cur_height = vc->vc_font.height/3; | ||
339 | break; | ||
340 | case CUR_LOWER_HALF: | ||
341 | cur_height = vc->vc_font.height >> 1; | ||
342 | break; | ||
343 | case CUR_TWO_THIRDS: | ||
344 | cur_height = (vc->vc_font.height << 1)/3; | ||
345 | break; | ||
346 | case CUR_BLOCK: | ||
347 | default: | ||
348 | cur_height = vc->vc_font.height; | ||
349 | break; | ||
350 | } | ||
351 | |||
352 | size = (vc->vc_font.height - cur_height) * width; | ||
353 | while (size--) | ||
354 | tmp[i++] = 0; | ||
355 | size = cur_height * width; | ||
356 | while (size--) | ||
357 | tmp[i++] = 0xff; | ||
358 | memset(mask, 0, w * vc->vc_font.width); | ||
359 | rotate_ccw(tmp, mask, vc->vc_font.width, vc->vc_font.height); | ||
360 | kfree(tmp); | ||
361 | } | ||
362 | |||
363 | switch (mode) { | ||
364 | case CM_ERASE: | ||
365 | ops->cursor_state.enable = 0; | ||
366 | break; | ||
367 | case CM_DRAW: | ||
368 | case CM_MOVE: | ||
369 | default: | ||
370 | ops->cursor_state.enable = (use_sw) ? 0 : 1; | ||
371 | break; | ||
372 | } | ||
373 | |||
374 | cursor.image.data = src; | ||
375 | cursor.image.fg_color = ops->cursor_state.image.fg_color; | ||
376 | cursor.image.bg_color = ops->cursor_state.image.bg_color; | ||
377 | cursor.image.dx = ops->cursor_state.image.dx; | ||
378 | cursor.image.dy = ops->cursor_state.image.dy; | ||
379 | cursor.image.height = ops->cursor_state.image.height; | ||
380 | cursor.image.width = ops->cursor_state.image.width; | ||
381 | cursor.hot.x = ops->cursor_state.hot.x; | ||
382 | cursor.hot.y = ops->cursor_state.hot.y; | ||
383 | cursor.mask = ops->cursor_state.mask; | ||
384 | cursor.enable = ops->cursor_state.enable; | ||
385 | cursor.image.depth = 1; | ||
386 | cursor.rop = ROP_XOR; | ||
387 | |||
388 | if (info->fbops->fb_cursor) | ||
389 | err = info->fbops->fb_cursor(info, &cursor); | ||
390 | |||
391 | if (err) | ||
392 | soft_cursor(info, &cursor); | ||
393 | |||
394 | ops->cursor_reset = 0; | ||
395 | } | ||
396 | |||
397 | int ccw_update_start(struct fb_info *info) | ||
398 | { | ||
399 | struct fbcon_ops *ops = info->fbcon_par; | ||
400 | struct display *p = &fb_display[ops->currcon]; | ||
401 | u32 yoffset; | ||
402 | u32 vyres = GETVYRES(p->scrollmode, info); | ||
403 | int err; | ||
404 | |||
405 | yoffset = (vyres - info->var.yres) - ops->var.xoffset; | ||
406 | ops->var.xoffset = ops->var.yoffset; | ||
407 | ops->var.yoffset = yoffset; | ||
408 | err = fb_pan_display(info, &ops->var); | ||
409 | ops->var.xoffset = info->var.xoffset; | ||
410 | ops->var.yoffset = info->var.yoffset; | ||
411 | ops->var.vmode = info->var.vmode; | ||
412 | return err; | ||
413 | } | ||
414 | |||
415 | void fbcon_rotate_ccw(struct fbcon_ops *ops) | ||
416 | { | ||
417 | ops->bmove = ccw_bmove; | ||
418 | ops->clear = ccw_clear; | ||
419 | ops->putcs = ccw_putcs; | ||
420 | ops->clear_margins = ccw_clear_margins; | ||
421 | ops->cursor = ccw_cursor; | ||
422 | ops->update_start = ccw_update_start; | ||
423 | } | ||
424 | EXPORT_SYMBOL(fbcon_rotate_ccw); | ||
425 | |||
426 | MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>"); | ||
427 | MODULE_DESCRIPTION("Console Rotation (270 degrees) Support"); | ||
428 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/video/console/fbcon_rotate.c b/drivers/video/console/fbcon_rotate.c index 3d64ad190ff8..ec0dd8fe241c 100644 --- a/drivers/video/console/fbcon_rotate.c +++ b/drivers/video/console/fbcon_rotate.c | |||
@@ -105,6 +105,9 @@ void fbcon_set_rotate(struct fbcon_ops *ops) | |||
105 | case FB_ROTATE_UD: | 105 | case FB_ROTATE_UD: |
106 | fbcon_rotate_ud(ops); | 106 | fbcon_rotate_ud(ops); |
107 | break; | 107 | break; |
108 | case FB_ROTATE_CCW: | ||
109 | fbcon_rotate_ccw(ops); | ||
110 | break; | ||
108 | } | 111 | } |
109 | } | 112 | } |
110 | EXPORT_SYMBOL(fbcon_set_rotate); | 113 | EXPORT_SYMBOL(fbcon_set_rotate); |
diff --git a/drivers/video/console/fbcon_rotate.h b/drivers/video/console/fbcon_rotate.h index f8ddcd6bd89c..90c672096c2e 100644 --- a/drivers/video/console/fbcon_rotate.h +++ b/drivers/video/console/fbcon_rotate.h | |||
@@ -101,4 +101,5 @@ static inline void rotate_ccw(const char *in, char *out, u32 width, u32 height) | |||
101 | 101 | ||
102 | extern void fbcon_rotate_cw(struct fbcon_ops *ops); | 102 | extern void fbcon_rotate_cw(struct fbcon_ops *ops); |
103 | extern void fbcon_rotate_ud(struct fbcon_ops *ops); | 103 | extern void fbcon_rotate_ud(struct fbcon_ops *ops); |
104 | extern void fbcon_rotate_ccw(struct fbcon_ops *ops); | ||
104 | #endif | 105 | #endif |