fbcon_ccw.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. #include <linux/module.h>
  11. #include <linux/slab.h>
  12. #include <linux/string.h>
  13. #include <linux/fb.h>
  14. #include <linux/vt_kern.h>
  15. #include <linux/console.h>
  16. #include <asm/types.h>
  17. #include "fbcon.h"
  18. #include "fbcon_rotate.h"
  19. /*
  20. * Rotation 270 degrees
  21. */
  22. static void ccw_update_attr(u8 *dst, u8 *src, int attribute,
  23. struct vc_data *vc)
  24. {
  25. int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2;
  26. int width = (vc->vc_font.height + 7) >> 3;
  27. int mod = vc->vc_font.height % 8;
  28. u8 c, msk = ~(0xff << offset), msk1 = 0;
  29. if (mod)
  30. msk <<= (8 - mod);
  31. if (offset > mod)
  32. msk1 |= 0x01;
  33. for (i = 0; i < vc->vc_font.width; i++) {
  34. for (j = 0; j < width; j++) {
  35. c = *src;
  36. if (attribute & FBCON_ATTRIBUTE_UNDERLINE) {
  37. if (j == width - 1)
  38. c |= msk;
  39. if (msk1 && j == width - 2)
  40. c |= msk1;
  41. }
  42. if (attribute & FBCON_ATTRIBUTE_BOLD && i)
  43. *(dst - width) |= c;
  44. if (attribute & FBCON_ATTRIBUTE_REVERSE)
  45. c = ~c;
  46. src++;
  47. *dst++ = c;
  48. }
  49. }
  50. }
  51. static void ccw_bmove(struct vc_data *vc, struct fb_info *info, int sy,
  52. int sx, int dy, int dx, int height, int width)
  53. {
  54. struct fbcon_ops *ops = info->fbcon_par;
  55. struct fb_copyarea area;
  56. u32 vyres = GETVYRES(ops->p->scrollmode, info);
  57. area.sx = sy * vc->vc_font.height;
  58. area.sy = vyres - ((sx + width) * vc->vc_font.width);
  59. area.dx = dy * vc->vc_font.height;
  60. area.dy = vyres - ((dx + width) * vc->vc_font.width);
  61. area.width = height * vc->vc_font.height;
  62. area.height = width * vc->vc_font.width;
  63. info->fbops->fb_copyarea(info, &area);
  64. }
  65. static void ccw_clear(struct vc_data *vc, struct fb_info *info, int sy,
  66. int sx, int height, int width)
  67. {
  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. region.color = attr_bgcol_ec(bgshift,vc,info);
  73. region.dx = sy * vc->vc_font.height;
  74. region.dy = vyres - ((sx + width) * vc->vc_font.width);
  75. region.height = width * vc->vc_font.width;
  76. region.width = height * vc->vc_font.height;
  77. region.rop = ROP_COPY;
  78. info->fbops->fb_fillrect(info, &region);
  79. }
  80. static inline void ccw_putcs_aligned(struct vc_data *vc, struct fb_info *info,
  81. const u16 *s, u32 attr, u32 cnt,
  82. u32 d_pitch, u32 s_pitch, u32 cellsize,
  83. struct fb_image *image, u8 *buf, u8 *dst)
  84. {
  85. struct fbcon_ops *ops = info->fbcon_par;
  86. u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
  87. u32 idx = (vc->vc_font.height + 7) >> 3;
  88. u8 *src;
  89. while (cnt--) {
  90. src = ops->fontbuffer + (scr_readw(s--) & charmask)*cellsize;
  91. if (attr) {
  92. ccw_update_attr(buf, src, attr, vc);
  93. src = buf;
  94. }
  95. if (likely(idx == 1))
  96. __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
  97. vc->vc_font.width);
  98. else
  99. fb_pad_aligned_buffer(dst, d_pitch, src, idx,
  100. vc->vc_font.width);
  101. dst += d_pitch * vc->vc_font.width;
  102. }
  103. info->fbops->fb_imageblit(info, image);
  104. }
  105. static void ccw_putcs(struct vc_data *vc, struct fb_info *info,
  106. const unsigned short *s, int count, int yy, int xx,
  107. int fg, int bg)
  108. {
  109. struct fb_image image;
  110. struct fbcon_ops *ops = info->fbcon_par;
  111. u32 width = (vc->vc_font.height + 7)/8;
  112. u32 cellsize = width * vc->vc_font.width;
  113. u32 maxcnt = info->pixmap.size/cellsize;
  114. u32 scan_align = info->pixmap.scan_align - 1;
  115. u32 buf_align = info->pixmap.buf_align - 1;
  116. u32 cnt, pitch, size;
  117. u32 attribute = get_attribute(info, scr_readw(s));
  118. u8 *dst, *buf = NULL;
  119. u32 vyres = GETVYRES(ops->p->scrollmode, info);
  120. if (!ops->fontbuffer)
  121. return;
  122. image.fg_color = fg;
  123. image.bg_color = bg;
  124. image.dx = yy * vc->vc_font.height;
  125. image.dy = vyres - ((xx + count) * vc->vc_font.width);
  126. image.width = vc->vc_font.height;
  127. image.depth = 1;
  128. if (attribute) {
  129. buf = kmalloc(cellsize, GFP_KERNEL);
  130. if (!buf)
  131. return;
  132. }
  133. s += count - 1;
  134. while (count) {
  135. if (count > maxcnt)
  136. cnt = maxcnt;
  137. else
  138. cnt = count;
  139. image.height = vc->vc_font.width * cnt;
  140. pitch = ((image.width + 7) >> 3) + scan_align;
  141. pitch &= ~scan_align;
  142. size = pitch * image.height + buf_align;
  143. size &= ~buf_align;
  144. dst = fb_get_buffer_offset(info, &info->pixmap, size);
  145. image.data = dst;
  146. ccw_putcs_aligned(vc, info, s, attribute, cnt, pitch,
  147. width, cellsize, &image, buf, dst);
  148. image.dy += image.height;
  149. count -= cnt;
  150. s -= cnt;
  151. }
  152. /* buf is always NULL except when in monochrome mode, so in this case
  153. it's a gain to check buf against NULL even though kfree() handles
  154. NULL pointers just fine */
  155. if (unlikely(buf))
  156. kfree(buf);
  157. }
  158. static void ccw_clear_margins(struct vc_data *vc, struct fb_info *info,
  159. int bottom_only)
  160. {
  161. unsigned int cw = vc->vc_font.width;
  162. unsigned int ch = vc->vc_font.height;
  163. unsigned int rw = info->var.yres - (vc->vc_cols*cw);
  164. unsigned int bh = info->var.xres - (vc->vc_rows*ch);
  165. unsigned int bs = vc->vc_rows*ch;
  166. struct fb_fillrect region;
  167. region.color = 0;
  168. region.rop = ROP_COPY;
  169. if (rw && !bottom_only) {
  170. region.dx = 0;
  171. region.dy = info->var.yoffset;
  172. region.height = rw;
  173. region.width = info->var.xres_virtual;
  174. info->fbops->fb_fillrect(info, &region);
  175. }
  176. if (bh) {
  177. region.dx = info->var.xoffset + bs;
  178. region.dy = 0;
  179. region.height = info->var.yres_virtual;
  180. region.width = bh;
  181. info->fbops->fb_fillrect(info, &region);
  182. }
  183. }
  184. static void ccw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
  185. int softback_lines, int fg, int bg)
  186. {
  187. struct fb_cursor cursor;
  188. struct fbcon_ops *ops = info->fbcon_par;
  189. unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
  190. int w = (vc->vc_font.height + 7) >> 3, c;
  191. int y = real_y(ops->p, vc->vc_y);
  192. int attribute, use_sw = (vc->vc_cursor_type & 0x10);
  193. int err = 1, dx, dy;
  194. char *src;
  195. u32 vyres = GETVYRES(ops->p->scrollmode, info);
  196. if (!ops->fontbuffer)
  197. return;
  198. cursor.set = 0;
  199. if (softback_lines) {
  200. if (y + softback_lines >= vc->vc_rows) {
  201. mode = CM_ERASE;
  202. ops->cursor_flash = 0;
  203. return;
  204. } else
  205. y += softback_lines;
  206. }
  207. c = scr_readw((u16 *) vc->vc_pos);
  208. attribute = get_attribute(info, c);
  209. src = ops->fontbuffer + ((c & charmask) * (w * vc->vc_font.width));
  210. if (ops->cursor_state.image.data != src ||
  211. ops->cursor_reset) {
  212. ops->cursor_state.image.data = src;
  213. cursor.set |= FB_CUR_SETIMAGE;
  214. }
  215. if (attribute) {
  216. u8 *dst;
  217. dst = kmalloc(w * vc->vc_font.width, GFP_ATOMIC);
  218. if (!dst)
  219. return;
  220. kfree(ops->cursor_data);
  221. ops->cursor_data = dst;
  222. ccw_update_attr(dst, src, attribute, vc);
  223. src = dst;
  224. }
  225. if (ops->cursor_state.image.fg_color != fg ||
  226. ops->cursor_state.image.bg_color != bg ||
  227. ops->cursor_reset) {
  228. ops->cursor_state.image.fg_color = fg;
  229. ops->cursor_state.image.bg_color = bg;
  230. cursor.set |= FB_CUR_SETCMAP;
  231. }
  232. if (ops->cursor_state.image.height != vc->vc_font.width ||
  233. ops->cursor_state.image.width != vc->vc_font.height ||
  234. ops->cursor_reset) {
  235. ops->cursor_state.image.height = vc->vc_font.width;
  236. ops->cursor_state.image.width = vc->vc_font.height;
  237. cursor.set |= FB_CUR_SETSIZE;
  238. }
  239. dx = y * vc->vc_font.height;
  240. dy = vyres - ((vc->vc_x + 1) * vc->vc_font.width);
  241. if (ops->cursor_state.image.dx != dx ||
  242. ops->cursor_state.image.dy != dy ||
  243. ops->cursor_reset) {
  244. ops->cursor_state.image.dx = dx;
  245. ops->cursor_state.image.dy = dy;
  246. cursor.set |= FB_CUR_SETPOS;
  247. }
  248. if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
  249. ops->cursor_reset) {
  250. ops->cursor_state.hot.x = cursor.hot.y = 0;
  251. cursor.set |= FB_CUR_SETHOT;
  252. }
  253. if (cursor.set & FB_CUR_SETSIZE ||
  254. vc->vc_cursor_type != ops->p->cursor_shape ||
  255. ops->cursor_state.mask == NULL ||
  256. ops->cursor_reset) {
  257. char *tmp, *mask = kmalloc(w*vc->vc_font.width, GFP_ATOMIC);
  258. int cur_height, size, i = 0;
  259. int width = (vc->vc_font.width + 7)/8;
  260. if (!mask)
  261. return;
  262. tmp = kmalloc(width * vc->vc_font.height, GFP_ATOMIC);
  263. if (!tmp) {
  264. kfree(mask);
  265. return;
  266. }
  267. kfree(ops->cursor_state.mask);
  268. ops->cursor_state.mask = mask;
  269. ops->p->cursor_shape = vc->vc_cursor_type;
  270. cursor.set |= FB_CUR_SETSHAPE;
  271. switch (ops->p->cursor_shape & CUR_HWMASK) {
  272. case CUR_NONE:
  273. cur_height = 0;
  274. break;
  275. case CUR_UNDERLINE:
  276. cur_height = (vc->vc_font.height < 10) ? 1 : 2;
  277. break;
  278. case CUR_LOWER_THIRD:
  279. cur_height = vc->vc_font.height/3;
  280. break;
  281. case CUR_LOWER_HALF:
  282. cur_height = vc->vc_font.height >> 1;
  283. break;
  284. case CUR_TWO_THIRDS:
  285. cur_height = (vc->vc_font.height << 1)/3;
  286. break;
  287. case CUR_BLOCK:
  288. default:
  289. cur_height = vc->vc_font.height;
  290. break;
  291. }
  292. size = (vc->vc_font.height - cur_height) * width;
  293. while (size--)
  294. tmp[i++] = 0;
  295. size = cur_height * width;
  296. while (size--)
  297. tmp[i++] = 0xff;
  298. memset(mask, 0, w * vc->vc_font.width);
  299. rotate_ccw(tmp, mask, vc->vc_font.width, vc->vc_font.height);
  300. kfree(tmp);
  301. }
  302. switch (mode) {
  303. case CM_ERASE:
  304. ops->cursor_state.enable = 0;
  305. break;
  306. case CM_DRAW:
  307. case CM_MOVE:
  308. default:
  309. ops->cursor_state.enable = (use_sw) ? 0 : 1;
  310. break;
  311. }
  312. cursor.image.data = src;
  313. cursor.image.fg_color = ops->cursor_state.image.fg_color;
  314. cursor.image.bg_color = ops->cursor_state.image.bg_color;
  315. cursor.image.dx = ops->cursor_state.image.dx;
  316. cursor.image.dy = ops->cursor_state.image.dy;
  317. cursor.image.height = ops->cursor_state.image.height;
  318. cursor.image.width = ops->cursor_state.image.width;
  319. cursor.hot.x = ops->cursor_state.hot.x;
  320. cursor.hot.y = ops->cursor_state.hot.y;
  321. cursor.mask = ops->cursor_state.mask;
  322. cursor.enable = ops->cursor_state.enable;
  323. cursor.image.depth = 1;
  324. cursor.rop = ROP_XOR;
  325. if (info->fbops->fb_cursor)
  326. err = info->fbops->fb_cursor(info, &cursor);
  327. if (err)
  328. soft_cursor(info, &cursor);
  329. ops->cursor_reset = 0;
  330. }
  331. static int ccw_update_start(struct fb_info *info)
  332. {
  333. struct fbcon_ops *ops = info->fbcon_par;
  334. u32 yoffset;
  335. u32 vyres = GETVYRES(ops->p->scrollmode, info);
  336. int err;
  337. yoffset = (vyres - info->var.yres) - ops->var.xoffset;
  338. ops->var.xoffset = ops->var.yoffset;
  339. ops->var.yoffset = yoffset;
  340. err = fb_pan_display(info, &ops->var);
  341. ops->var.xoffset = info->var.xoffset;
  342. ops->var.yoffset = info->var.yoffset;
  343. ops->var.vmode = info->var.vmode;
  344. return err;
  345. }
  346. void fbcon_rotate_ccw(struct fbcon_ops *ops)
  347. {
  348. ops->bmove = ccw_bmove;
  349. ops->clear = ccw_clear;
  350. ops->putcs = ccw_putcs;
  351. ops->clear_margins = ccw_clear_margins;
  352. ops->cursor = ccw_cursor;
  353. ops->update_start = ccw_update_start;
  354. }
  355. EXPORT_SYMBOL(fbcon_rotate_ccw);
  356. MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
  357. MODULE_DESCRIPTION("Console Rotation (270 degrees) Support");
  358. MODULE_LICENSE("GPL");