Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/console/fbcon_rotate.c -- Software Rotation |
| 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 | |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 11 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 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 | |
Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 21 | static int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc) |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 22 | { |
| 23 | struct fbcon_ops *ops = info->fbcon_par; |
| 24 | int len, err = 0; |
| 25 | int s_cellsize, d_cellsize, i; |
| 26 | const u8 *src; |
| 27 | u8 *dst; |
| 28 | |
| 29 | if (vc->vc_font.data == ops->fontdata && |
Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 30 | ops->p->con_rotate == ops->cur_rotate) |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 31 | goto finished; |
| 32 | |
| 33 | src = ops->fontdata = vc->vc_font.data; |
Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 34 | ops->cur_rotate = ops->p->con_rotate; |
| 35 | len = (!ops->p->userfont) ? 256 : FNTCHARCNT(src); |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 36 | s_cellsize = ((vc->vc_font.width + 7)/8) * |
| 37 | vc->vc_font.height; |
| 38 | d_cellsize = s_cellsize; |
| 39 | |
| 40 | if (ops->rotate == FB_ROTATE_CW || |
| 41 | ops->rotate == FB_ROTATE_CCW) |
| 42 | d_cellsize = ((vc->vc_font.height + 7)/8) * |
| 43 | vc->vc_font.width; |
| 44 | |
| 45 | if (info->fbops->fb_sync) |
| 46 | info->fbops->fb_sync(info); |
| 47 | |
| 48 | if (ops->fd_size < d_cellsize * len) { |
| 49 | dst = kmalloc(d_cellsize * len, GFP_KERNEL); |
| 50 | |
| 51 | if (dst == NULL) { |
| 52 | err = -ENOMEM; |
| 53 | goto finished; |
| 54 | } |
| 55 | |
| 56 | ops->fd_size = d_cellsize * len; |
| 57 | kfree(ops->fontbuffer); |
| 58 | ops->fontbuffer = dst; |
| 59 | } |
| 60 | |
| 61 | dst = ops->fontbuffer; |
| 62 | memset(dst, 0, ops->fd_size); |
| 63 | |
| 64 | switch (ops->rotate) { |
| 65 | case FB_ROTATE_UD: |
| 66 | for (i = len; i--; ) { |
| 67 | rotate_ud(src, dst, vc->vc_font.width, |
| 68 | vc->vc_font.height); |
| 69 | |
| 70 | src += s_cellsize; |
| 71 | dst += d_cellsize; |
| 72 | } |
| 73 | break; |
| 74 | case FB_ROTATE_CW: |
| 75 | for (i = len; i--; ) { |
| 76 | rotate_cw(src, dst, vc->vc_font.width, |
| 77 | vc->vc_font.height); |
| 78 | src += s_cellsize; |
| 79 | dst += d_cellsize; |
| 80 | } |
| 81 | break; |
| 82 | case FB_ROTATE_CCW: |
| 83 | for (i = len; i--; ) { |
| 84 | rotate_ccw(src, dst, vc->vc_font.width, |
| 85 | vc->vc_font.height); |
| 86 | src += s_cellsize; |
| 87 | dst += d_cellsize; |
| 88 | } |
| 89 | break; |
| 90 | } |
| 91 | |
| 92 | finished: |
| 93 | return err; |
| 94 | } |
| 95 | |
| 96 | void fbcon_set_rotate(struct fbcon_ops *ops) |
| 97 | { |
| 98 | ops->rotate_font = fbcon_rotate_font; |
Antonino A. Daplas | dbcbfe1 | 2005-11-08 21:39:12 -0800 | [diff] [blame] | 99 | |
| 100 | switch(ops->rotate) { |
| 101 | case FB_ROTATE_CW: |
| 102 | fbcon_rotate_cw(ops); |
| 103 | break; |
Antonino A. Daplas | 33ee829 | 2005-11-08 21:39:13 -0800 | [diff] [blame] | 104 | case FB_ROTATE_UD: |
| 105 | fbcon_rotate_ud(ops); |
| 106 | break; |
Antonino A. Daplas | ed8c0e9 | 2005-11-08 21:39:14 -0800 | [diff] [blame] | 107 | case FB_ROTATE_CCW: |
| 108 | fbcon_rotate_ccw(ops); |
| 109 | break; |
Antonino A. Daplas | dbcbfe1 | 2005-11-08 21:39:12 -0800 | [diff] [blame] | 110 | } |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 111 | } |
| 112 | EXPORT_SYMBOL(fbcon_set_rotate); |
| 113 | |
| 114 | MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>"); |
| 115 | MODULE_DESCRIPTION("Console Rotation Support"); |
| 116 | MODULE_LICENSE("GPL"); |