2 * linux/drivers/video/console/fbcon_ccw.c -- Software Rotation - 270 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/config.h>
12 #include <linux/module.h>
13 #include <linux/string.h>
15 #include <linux/vt_kern.h>
16 #include <linux/console.h>
17 #include <asm/types.h>
19 #include "fbcon_rotate.h"
22 * Rotation 270 degrees
25 static inline void ccw_update_attr(u8 *dst, u8 *src, int attribute,
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;
39 for (i = 0; i < vc->vc_font.width; i++) {
40 for (j = 0; j < width; j++) {
43 if (attribute & FBCON_ATTRIBUTE_UNDERLINE) {
47 if (msk1 && j == width - 2)
51 if (attribute & FBCON_ATTRIBUTE_BOLD && i)
54 if (attribute & FBCON_ATTRIBUTE_REVERSE)
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)
66 struct fbcon_ops *ops = info->fbcon_par;
67 struct fb_copyarea area;
68 u32 vyres = GETVYRES(ops->p->scrollmode, info);
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;
77 info->fbops->fb_copyarea(info, &area);
80 static void ccw_clear(struct vc_data *vc, struct fb_info *info, int sy,
81 int sx, int height, int width)
83 struct fbcon_ops *ops = info->fbcon_par;
84 struct fb_fillrect region;
85 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
86 u32 vyres = GETVYRES(ops->p->scrollmode, info);
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;
95 info->fbops->fb_fillrect(info, ®ion);
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)
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;
109 src = ops->fontbuffer + (scr_readw(s--) & charmask)*cellsize;
112 ccw_update_attr(buf, src, attr, vc);
116 if (likely(idx == 1))
117 __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
120 fb_pad_aligned_buffer(dst, d_pitch, src, idx,
123 dst += d_pitch * vc->vc_font.width;
126 info->fbops->fb_imageblit(info, image);
129 static void ccw_putcs(struct vc_data *vc, struct fb_info *info,
130 const unsigned short *s, int count, int yy, int xx,
133 struct fb_image image;
134 struct fbcon_ops *ops = info->fbcon_par;
135 u32 width = (vc->vc_font.height + 7)/8;
136 u32 cellsize = width * vc->vc_font.width;
137 u32 maxcnt = info->pixmap.size/cellsize;
138 u32 scan_align = info->pixmap.scan_align - 1;
139 u32 buf_align = info->pixmap.buf_align - 1;
140 u32 cnt, pitch, size;
141 u32 attribute = get_attribute(info, scr_readw(s));
142 u8 *dst, *buf = NULL;
143 u32 vyres = GETVYRES(ops->p->scrollmode, info);
145 if (!ops->fontbuffer)
150 image.dx = yy * vc->vc_font.height;
151 image.dy = vyres - ((xx + count) * vc->vc_font.width);
152 image.width = vc->vc_font.height;
156 buf = kmalloc(cellsize, GFP_KERNEL);
169 image.height = vc->vc_font.width * cnt;
170 pitch = ((image.width + 7) >> 3) + scan_align;
171 pitch &= ~scan_align;
172 size = pitch * image.height + buf_align;
174 dst = fb_get_buffer_offset(info, &info->pixmap, size);
176 ccw_putcs_aligned(vc, info, s, attribute, cnt, pitch,
177 width, cellsize, &image, buf, dst);
178 image.dy += image.height;
183 /* buf is always NULL except when in monochrome mode, so in this case
184 it's a gain to check buf against NULL even though kfree() handles
185 NULL pointers just fine */
191 static void ccw_clear_margins(struct vc_data *vc, struct fb_info *info,
194 unsigned int cw = vc->vc_font.width;
195 unsigned int ch = vc->vc_font.height;
196 unsigned int rw = info->var.yres - (vc->vc_cols*cw);
197 unsigned int bh = info->var.xres - (vc->vc_rows*ch);
198 unsigned int bs = vc->vc_rows*ch;
199 struct fb_fillrect region;
200 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
202 region.color = attr_bgcol_ec(bgshift,vc);
203 region.rop = ROP_COPY;
205 if (rw && !bottom_only) {
207 region.dy = info->var.yoffset;
209 region.width = info->var.xres_virtual;
210 info->fbops->fb_fillrect(info, ®ion);
214 region.dx = info->var.xoffset + bs;
216 region.height = info->var.yres_virtual;
218 info->fbops->fb_fillrect(info, ®ion);
222 static void ccw_cursor(struct vc_data *vc, struct fb_info *info,
223 struct display *p, int mode, int softback_lines,
226 struct fb_cursor cursor;
227 struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
228 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
229 int w = (vc->vc_font.height + 7) >> 3, c;
230 int y = real_y(p, vc->vc_y);
231 int attribute, use_sw = (vc->vc_cursor_type & 0x10);
234 u32 vyres = GETVYRES(p->scrollmode, info);
236 if (!ops->fontbuffer)
241 if (softback_lines) {
242 if (y + softback_lines >= vc->vc_rows) {
244 ops->cursor_flash = 0;
250 c = scr_readw((u16 *) vc->vc_pos);
251 attribute = get_attribute(info, c);
252 src = ops->fontbuffer + ((c & charmask) * (w * vc->vc_font.width));
254 if (ops->cursor_state.image.data != src ||
256 ops->cursor_state.image.data = src;
257 cursor.set |= FB_CUR_SETIMAGE;
263 dst = kmalloc(w * vc->vc_font.width, GFP_ATOMIC);
266 kfree(ops->cursor_data);
267 ops->cursor_data = dst;
268 ccw_update_attr(dst, src, attribute, vc);
272 if (ops->cursor_state.image.fg_color != fg ||
273 ops->cursor_state.image.bg_color != bg ||
275 ops->cursor_state.image.fg_color = fg;
276 ops->cursor_state.image.bg_color = bg;
277 cursor.set |= FB_CUR_SETCMAP;
280 if (ops->cursor_state.image.height != vc->vc_font.width ||
281 ops->cursor_state.image.width != vc->vc_font.height ||
283 ops->cursor_state.image.height = vc->vc_font.width;
284 ops->cursor_state.image.width = vc->vc_font.height;
285 cursor.set |= FB_CUR_SETSIZE;
288 dx = y * vc->vc_font.height;
289 dy = vyres - ((vc->vc_x + 1) * vc->vc_font.width);
291 if (ops->cursor_state.image.dx != dx ||
292 ops->cursor_state.image.dy != dy ||
294 ops->cursor_state.image.dx = dx;
295 ops->cursor_state.image.dy = dy;
296 cursor.set |= FB_CUR_SETPOS;
299 if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
301 ops->cursor_state.hot.x = cursor.hot.y = 0;
302 cursor.set |= FB_CUR_SETHOT;
305 if (cursor.set & FB_CUR_SETSIZE ||
306 vc->vc_cursor_type != p->cursor_shape ||
307 ops->cursor_state.mask == NULL ||
309 char *tmp, *mask = kmalloc(w*vc->vc_font.width, GFP_ATOMIC);
310 int cur_height, size, i = 0;
311 int width = (vc->vc_font.width + 7)/8;
316 tmp = kmalloc(width * vc->vc_font.height, GFP_ATOMIC);
323 kfree(ops->cursor_state.mask);
324 ops->cursor_state.mask = mask;
326 p->cursor_shape = vc->vc_cursor_type;
327 cursor.set |= FB_CUR_SETSHAPE;
329 switch (p->cursor_shape & CUR_HWMASK) {
334 cur_height = (vc->vc_font.height < 10) ? 1 : 2;
336 case CUR_LOWER_THIRD:
337 cur_height = vc->vc_font.height/3;
340 cur_height = vc->vc_font.height >> 1;
343 cur_height = (vc->vc_font.height << 1)/3;
347 cur_height = vc->vc_font.height;
351 size = (vc->vc_font.height - cur_height) * width;
354 size = cur_height * width;
357 memset(mask, 0, w * vc->vc_font.width);
358 rotate_ccw(tmp, mask, vc->vc_font.width, vc->vc_font.height);
364 ops->cursor_state.enable = 0;
369 ops->cursor_state.enable = (use_sw) ? 0 : 1;
373 cursor.image.data = src;
374 cursor.image.fg_color = ops->cursor_state.image.fg_color;
375 cursor.image.bg_color = ops->cursor_state.image.bg_color;
376 cursor.image.dx = ops->cursor_state.image.dx;
377 cursor.image.dy = ops->cursor_state.image.dy;
378 cursor.image.height = ops->cursor_state.image.height;
379 cursor.image.width = ops->cursor_state.image.width;
380 cursor.hot.x = ops->cursor_state.hot.x;
381 cursor.hot.y = ops->cursor_state.hot.y;
382 cursor.mask = ops->cursor_state.mask;
383 cursor.enable = ops->cursor_state.enable;
384 cursor.image.depth = 1;
385 cursor.rop = ROP_XOR;
387 if (info->fbops->fb_cursor)
388 err = info->fbops->fb_cursor(info, &cursor);
391 soft_cursor(info, &cursor);
393 ops->cursor_reset = 0;
396 int ccw_update_start(struct fb_info *info)
398 struct fbcon_ops *ops = info->fbcon_par;
400 u32 vyres = GETVYRES(ops->p->scrollmode, info);
403 yoffset = (vyres - info->var.yres) - ops->var.xoffset;
404 ops->var.xoffset = ops->var.yoffset;
405 ops->var.yoffset = yoffset;
406 err = fb_pan_display(info, &ops->var);
407 ops->var.xoffset = info->var.xoffset;
408 ops->var.yoffset = info->var.yoffset;
409 ops->var.vmode = info->var.vmode;
413 void fbcon_rotate_ccw(struct fbcon_ops *ops)
415 ops->bmove = ccw_bmove;
416 ops->clear = ccw_clear;
417 ops->putcs = ccw_putcs;
418 ops->clear_margins = ccw_clear_margins;
419 ops->cursor = ccw_cursor;
420 ops->update_start = ccw_update_start;
422 EXPORT_SYMBOL(fbcon_rotate_ccw);
424 MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
425 MODULE_DESCRIPTION("Console Rotation (270 degrees) Support");
426 MODULE_LICENSE("GPL");