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/string.h>
  12. #include <linux/fb.h>
  13. #include <linux/vt_kern.h>
  14. #include <linux/console.h>
  15. #include <asm/types.h>
  16. #include "fbcon.h"
  17. #include "fbcon_rotate.h"
  18. /*
  19. * Rotation 270 degrees
  20. */
  21. static inline void ccw_update_attr(u8 *dst, u8 *src, int attribute,
  22. struct vc_data *vc)
  23. {
  24. int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2;
  25. int width = (vc->vc_font.height + 7) >> 3;
  26. int mod = vc->vc_font.height % 8;
  27. u8 c, msk = ~(0xff << offset), msk1 = 0;
  28. if (mod)
  29. msk <<= (8 - mod);
  30. if (offset > mod)
  31. msk1 |= 0x01;
  32. for (i = 0; i < vc->vc_font.width; i++) {
  33. for (j = 0; j < width; j++) {
  34. c = *src;
  35. if (attribute & FBCON_ATTRIBUTE_UNDERLINE) {
  36. if (j == width - 1)
  37. c |= msk;
  38. if (msk1 && j == width - 2)
  39. c |= msk1;
  40. }
  41. if (attribute & FBCON_ATTRIBUTE_BOLD && i)
  42. *(dst - width) |= c;
  43. if (attribute & FBCON_ATTRIBUTE_REVERSE)
  44. c = ~c;
  45. src++;
  46. *dst++ = c;
  47. }
  48. }
  49. }
  50. static void ccw_bmove(struct vc_data *vc, struct fb_info *info, int sy,
  51. int sx, int dy, int dx, int height, int width)
  52. {
  53. struct fbcon_ops *ops = info->fbcon_par;
  54. struct fb_copyarea area;
  55. u32 vyres = GETVYRES(ops->p->scrollmode, info);
  56. area.sx = sy * vc->vc_font.height;
  57. area.sy = vyres - ((sx + width) * vc->vc_font.width);
  58. area.dx = dy * vc->vc_font.height;
  59. area.dy = vyres - ((dx + width) * vc->vc_font.width);
  60. area.width = height * vc->vc_font.height;
  61. area.height = width * vc->vc_font.width;
  62. info->fbops->fb_copyarea(info, &area);
  63. }
  64. static void ccw_clear(struct vc_data *vc, struct fb_info *info, int sy,
  65. int sx, int height, int width)
  66. {
  67. struct fbcon_ops *ops = info->fbcon_par;
  68. struct fb_fillrect region;
  69. int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
  70. u32 vyres = GETVYRES(ops->p->scrollmode, info);
  71. region.color = attr_bgcol_ec(bgshift,vc,info);
  72. region.dx = sy * vc->vc_font.height;
  73. region.dy = vyres - ((sx + width) * vc->vc_font.width);
  74. region.height = width * vc->vc_font.width;
  75. region.width = height * vc->vc_font.height;
  76. region.rop = ROP_COPY;
  77. info->fbops->fb_fillrect(info, &region);
  78. }
  79. static inline void ccw_putcs_aligned(struct vc_data *vc, struct fb_info *info,
  80. const u16 *s, u32 attr, u32 cnt,
  81. u32 d_pitch, u32 s_pitch, u32 cellsize,
  82. struct fb_image *image, u8 *buf, u8 *dst)
  83. {
  84. struct fbcon_ops *ops = info->fbcon_par;
  85. u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
  86. u32 idx = (vc->vc_font.height + 7) >> 3;
  87. u8 *src;
  88. while (cnt--) {
  89. src = ops->fontbuffer + (scr_readw(s--) & charmask)*cellsize;
  90. if (attr) {
  91. ccw_update_attr(buf, src, attr, vc);
  92. src = buf;
  93. }
  94. if (likely(idx == 1))
  95. __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
  96. vc->vc_font.width);
  97. else
  98. fb_pad_aligned_buffer(dst, d_pitch, src, idx,
  99. vc->vc_font.width);
  100. dst += d_pitch * vc->vc_font.width;
  101. }
  102. info->fbops->fb_imageblit(info, image);
  103. }
  104. static void ccw_putcs(struct vc_data *vc, struct fb_info *info,
  105. const unsigned short *s, int count, int yy, int xx,
  106. int fg, int bg)
  107. {
  108. struct fb_image image;
  109. struct fbcon_ops *ops = info->fbcon_par;
  110. u32 width = (vc->vc_font.height + 7)/8;
  111. u32 cellsize = width * vc->vc_font.width;
  112. u32 maxcnt = info->pixmap.size/cellsize;
  113. u32 scan_align = info->pixmap.scan_align - 1;
  114. u32 buf_align = info->pixmap.buf_align - 1;
  115. u32 cnt, pitch, size;
  116. u32 attribute = get_attribute(info, scr_readw(s));
  117. u8 *dst, *buf = NULL;
  118. u32 vyres = GETVYRES(ops->p->scrollmode, info);
  119. if (!ops->fontbuffer)
  120. return;
  121. image.fg_color = fg;
  122. image.bg_color = bg;
  123. image.dx = yy * vc->vc_font.height;
  124. image.dy = vyres - ((xx + count) * vc->vc_font.width);
  125. image.width = vc->vc_font.height;
  126. image.depth = 1;
  127. if (attribute) {
  128. buf = kmalloc(cellsize, GFP_KERNEL);
  129. if (!buf)
  130. return;
  131. }
  132. s += count - 1;
  133. while (count) {
  134. if (count > maxcnt)
  135. cnt = maxcnt;
  136. else
  137. cnt = count;
  138. image.height = vc->vc_font.width * cnt;
  139. pitch = ((image.width + 7) >> 3) + scan_align;
  140. pitch &= ~scan_align;
  141. size = pitch * image.height + buf_align;
  142. size &= ~buf_align;
  143. dst = fb_get_buffer_offset(info, &info->pixmap, size);
  144. image.data = dst;
  145. ccw_putcs_aligned(vc, info, s, attribute, cnt, pitch,
  146. width, cellsize, &image, buf, dst);
  147. image.dy += image.height;
  148. count -= cnt;
  149. s -= cnt;
  150. }
  151. /* buf is always NULL except when in monochrome mode, so in this case
  152. it's a gain to check buf against NULL even though kfree() handles
  153. NULL pointers just fine */
  154. if (unlikely(buf))
  155. kfree(buf);
  156. }
  157. static void ccw_clear_margins(struct vc_data *vc, struct fb_info *info,
  158. int bottom_only)
  159. {
  160. unsigned int cw = vc->vc_font.width;
  161. unsigned int ch = vc->vc_font.height;
  162. unsigned int rw = info->var.yres - (vc->vc_cols*cw);
  163. unsigned int bh = info->var.xres - (vc->vc_rows*ch);
  164. unsigned int bs = vc->vc_rows*ch;
  165. struct fb_fillrect region;
  166. int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
  167. region.color = attr_bgcol_ec(bgshift,vc,info);
  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");