2 * linux/drivers/video/console/fbcon_ud.c -- Software Rotation - 180 degrees
4 * Copyright (C) 2005 Antonino Daplas <adaplas @pol.net>
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
11 #include <linux/module.h>
12 #include <linux/string.h>
14 #include <linux/vt_kern.h>
15 #include <linux/console.h>
16 #include <asm/types.h>
18 #include "fbcon_rotate.h"
21 * Rotation 180 degrees
24 static inline void ud_update_attr(u8 *dst, u8 *src, int attribute,
27 int i, offset = (vc->vc_font.height < 10) ? 1 : 2;
28 int width = (vc->vc_font.width + 7) >> 3;
29 unsigned int cellsize = vc->vc_font.height * width;
32 offset = offset * width;
34 for (i = 0; i < cellsize; i++) {
36 if (attribute & FBCON_ATTRIBUTE_UNDERLINE && i < offset)
38 if (attribute & FBCON_ATTRIBUTE_BOLD)
40 if (attribute & FBCON_ATTRIBUTE_REVERSE)
47 static void ud_bmove(struct vc_data *vc, struct fb_info *info, int sy,
48 int sx, int dy, int dx, int height, int width)
50 struct fbcon_ops *ops = info->fbcon_par;
51 struct fb_copyarea area;
52 u32 vyres = GETVYRES(ops->p->scrollmode, info);
53 u32 vxres = GETVXRES(ops->p->scrollmode, info);
55 area.sy = vyres - ((sy + height) * vc->vc_font.height);
56 area.sx = vxres - ((sx + width) * vc->vc_font.width);
57 area.dy = vyres - ((dy + height) * vc->vc_font.height);
58 area.dx = vxres - ((dx + width) * vc->vc_font.width);
59 area.height = height * vc->vc_font.height;
60 area.width = width * vc->vc_font.width;
62 info->fbops->fb_copyarea(info, &area);
65 static void ud_clear(struct vc_data *vc, struct fb_info *info, int sy,
66 int sx, int height, int width)
68 struct fbcon_ops *ops = info->fbcon_par;
69 struct fb_fillrect region;
70 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
71 u32 vyres = GETVYRES(ops->p->scrollmode, info);
72 u32 vxres = GETVXRES(ops->p->scrollmode, info);
74 region.color = attr_bgcol_ec(bgshift,vc,info);
75 region.dy = vyres - ((sy + height) * vc->vc_font.height);
76 region.dx = vxres - ((sx + width) * vc->vc_font.width);
77 region.width = width * vc->vc_font.width;
78 region.height = height * vc->vc_font.height;
79 region.rop = ROP_COPY;
81 info->fbops->fb_fillrect(info, ®ion);
84 static inline void ud_putcs_aligned(struct vc_data *vc, struct fb_info *info,
85 const u16 *s, u32 attr, u32 cnt,
86 u32 d_pitch, u32 s_pitch, u32 cellsize,
87 struct fb_image *image, u8 *buf, u8 *dst)
89 struct fbcon_ops *ops = info->fbcon_par;
90 u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
91 u32 idx = vc->vc_font.width >> 3;
95 src = ops->fontbuffer + (scr_readw(s--) & charmask)*cellsize;
98 ud_update_attr(buf, src, attr, vc);
102 if (likely(idx == 1))
103 __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
106 fb_pad_aligned_buffer(dst, d_pitch, src, idx,
112 info->fbops->fb_imageblit(info, image);
115 static inline void ud_putcs_unaligned(struct vc_data *vc,
116 struct fb_info *info, const u16 *s,
117 u32 attr, u32 cnt, u32 d_pitch,
118 u32 s_pitch, u32 cellsize,
119 struct fb_image *image, u8 *buf,
122 struct fbcon_ops *ops = info->fbcon_par;
123 u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
124 u32 shift_low = 0, mod = vc->vc_font.width % 8;
126 u32 idx = vc->vc_font.width >> 3;
130 src = ops->fontbuffer + (scr_readw(s--) & charmask)*cellsize;
133 ud_update_attr(buf, src, attr, vc);
137 fb_pad_unaligned_buffer(dst, d_pitch, src, idx,
138 image->height, shift_high,
141 dst += (shift_low >= 8) ? s_pitch : s_pitch - 1;
143 shift_high = 8 - shift_low;
146 info->fbops->fb_imageblit(info, image);
150 static void ud_putcs(struct vc_data *vc, struct fb_info *info,
151 const unsigned short *s, int count, int yy, int xx,
154 struct fb_image image;
155 struct fbcon_ops *ops = info->fbcon_par;
156 u32 width = (vc->vc_font.width + 7)/8;
157 u32 cellsize = width * vc->vc_font.height;
158 u32 maxcnt = info->pixmap.size/cellsize;
159 u32 scan_align = info->pixmap.scan_align - 1;
160 u32 buf_align = info->pixmap.buf_align - 1;
161 u32 mod = vc->vc_font.width % 8, cnt, pitch, size;
162 u32 attribute = get_attribute(info, scr_readw(s));
163 u8 *dst, *buf = NULL;
164 u32 vyres = GETVYRES(ops->p->scrollmode, info);
165 u32 vxres = GETVXRES(ops->p->scrollmode, info);
167 if (!ops->fontbuffer)
172 image.dy = vyres - ((yy * vc->vc_font.height) + vc->vc_font.height);
173 image.dx = vxres - ((xx + count) * vc->vc_font.width);
174 image.height = vc->vc_font.height;
178 buf = kmalloc(cellsize, GFP_KERNEL);
191 image.width = vc->vc_font.width * cnt;
192 pitch = ((image.width + 7) >> 3) + scan_align;
193 pitch &= ~scan_align;
194 size = pitch * image.height + buf_align;
196 dst = fb_get_buffer_offset(info, &info->pixmap, size);
200 ud_putcs_aligned(vc, info, s, attribute, cnt, pitch,
201 width, cellsize, &image, buf, dst);
203 ud_putcs_unaligned(vc, info, s, attribute, cnt, pitch,
204 width, cellsize, &image,
207 image.dx += image.width;
213 /* buf is always NULL except when in monochrome mode, so in this case
214 it's a gain to check buf against NULL even though kfree() handles
215 NULL pointers just fine */
221 static void ud_clear_margins(struct vc_data *vc, struct fb_info *info,
224 unsigned int cw = vc->vc_font.width;
225 unsigned int ch = vc->vc_font.height;
226 unsigned int rw = info->var.xres - (vc->vc_cols*cw);
227 unsigned int bh = info->var.yres - (vc->vc_rows*ch);
228 struct fb_fillrect region;
229 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
231 region.color = attr_bgcol_ec(bgshift,vc,info);
232 region.rop = ROP_COPY;
234 if (rw && !bottom_only) {
236 region.dx = info->var.xoffset;
238 region.height = info->var.yres_virtual;
239 info->fbops->fb_fillrect(info, ®ion);
243 region.dy = info->var.yoffset;
244 region.dx = info->var.xoffset;
246 region.width = info->var.xres;
247 info->fbops->fb_fillrect(info, ®ion);
251 static void ud_cursor(struct vc_data *vc, struct fb_info *info, int mode,
252 int softback_lines, int fg, int bg)
254 struct fb_cursor cursor;
255 struct fbcon_ops *ops = info->fbcon_par;
256 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
257 int w = (vc->vc_font.width + 7) >> 3, c;
258 int y = real_y(ops->p, vc->vc_y);
259 int attribute, use_sw = (vc->vc_cursor_type & 0x10);
262 u32 vyres = GETVYRES(ops->p->scrollmode, info);
263 u32 vxres = GETVXRES(ops->p->scrollmode, info);
265 if (!ops->fontbuffer)
270 if (softback_lines) {
271 if (y + softback_lines >= vc->vc_rows) {
273 ops->cursor_flash = 0;
279 c = scr_readw((u16 *) vc->vc_pos);
280 attribute = get_attribute(info, c);
281 src = ops->fontbuffer + ((c & charmask) * (w * vc->vc_font.height));
283 if (ops->cursor_state.image.data != src ||
285 ops->cursor_state.image.data = src;
286 cursor.set |= FB_CUR_SETIMAGE;
292 dst = kmalloc(w * vc->vc_font.height, GFP_ATOMIC);
295 kfree(ops->cursor_data);
296 ops->cursor_data = dst;
297 ud_update_attr(dst, src, attribute, vc);
301 if (ops->cursor_state.image.fg_color != fg ||
302 ops->cursor_state.image.bg_color != bg ||
304 ops->cursor_state.image.fg_color = fg;
305 ops->cursor_state.image.bg_color = bg;
306 cursor.set |= FB_CUR_SETCMAP;
309 if (ops->cursor_state.image.height != vc->vc_font.height ||
310 ops->cursor_state.image.width != vc->vc_font.width ||
312 ops->cursor_state.image.height = vc->vc_font.height;
313 ops->cursor_state.image.width = vc->vc_font.width;
314 cursor.set |= FB_CUR_SETSIZE;
317 dy = vyres - ((y * vc->vc_font.height) + vc->vc_font.height);
318 dx = vxres - ((vc->vc_x * vc->vc_font.width) + vc->vc_font.width);
320 if (ops->cursor_state.image.dx != dx ||
321 ops->cursor_state.image.dy != dy ||
323 ops->cursor_state.image.dx = dx;
324 ops->cursor_state.image.dy = dy;
325 cursor.set |= FB_CUR_SETPOS;
328 if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
330 ops->cursor_state.hot.x = cursor.hot.y = 0;
331 cursor.set |= FB_CUR_SETHOT;
334 if (cursor.set & FB_CUR_SETSIZE ||
335 vc->vc_cursor_type != ops->p->cursor_shape ||
336 ops->cursor_state.mask == NULL ||
338 char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
339 int cur_height, size, i = 0;
345 kfree(ops->cursor_state.mask);
346 ops->cursor_state.mask = mask;
348 ops->p->cursor_shape = vc->vc_cursor_type;
349 cursor.set |= FB_CUR_SETSHAPE;
351 switch (ops->p->cursor_shape & CUR_HWMASK) {
356 cur_height = (vc->vc_font.height < 10) ? 1 : 2;
358 case CUR_LOWER_THIRD:
359 cur_height = vc->vc_font.height/3;
362 cur_height = vc->vc_font.height >> 1;
365 cur_height = (vc->vc_font.height << 1)/3;
369 cur_height = vc->vc_font.height;
373 size = cur_height * w;
378 size = (vc->vc_font.height - cur_height) * w;
386 ops->cursor_state.enable = 0;
391 ops->cursor_state.enable = (use_sw) ? 0 : 1;
395 cursor.image.data = src;
396 cursor.image.fg_color = ops->cursor_state.image.fg_color;
397 cursor.image.bg_color = ops->cursor_state.image.bg_color;
398 cursor.image.dx = ops->cursor_state.image.dx;
399 cursor.image.dy = ops->cursor_state.image.dy;
400 cursor.image.height = ops->cursor_state.image.height;
401 cursor.image.width = ops->cursor_state.image.width;
402 cursor.hot.x = ops->cursor_state.hot.x;
403 cursor.hot.y = ops->cursor_state.hot.y;
404 cursor.mask = ops->cursor_state.mask;
405 cursor.enable = ops->cursor_state.enable;
406 cursor.image.depth = 1;
407 cursor.rop = ROP_XOR;
409 if (info->fbops->fb_cursor)
410 err = info->fbops->fb_cursor(info, &cursor);
413 soft_cursor(info, &cursor);
415 ops->cursor_reset = 0;
418 static int ud_update_start(struct fb_info *info)
420 struct fbcon_ops *ops = info->fbcon_par;
421 int xoffset, yoffset;
422 u32 vyres = GETVYRES(ops->p->scrollmode, info);
423 u32 vxres = GETVXRES(ops->p->scrollmode, info);
426 xoffset = vxres - info->var.xres - ops->var.xoffset;
427 yoffset = vyres - info->var.yres - ops->var.yoffset;
430 ops->var.xoffset = xoffset;
431 ops->var.yoffset = yoffset;
432 err = fb_pan_display(info, &ops->var);
433 ops->var.xoffset = info->var.xoffset;
434 ops->var.yoffset = info->var.yoffset;
435 ops->var.vmode = info->var.vmode;
439 void fbcon_rotate_ud(struct fbcon_ops *ops)
441 ops->bmove = ud_bmove;
442 ops->clear = ud_clear;
443 ops->putcs = ud_putcs;
444 ops->clear_margins = ud_clear_margins;
445 ops->cursor = ud_cursor;
446 ops->update_start = ud_update_start;
448 EXPORT_SYMBOL(fbcon_rotate_ud);
450 MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
451 MODULE_DESCRIPTION("Console Rotation (180 degrees) Support");
452 MODULE_LICENSE("GPL");