fbcon_ccw.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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/config.h>
  11. #include <linux/module.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 inline 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);
  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. int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
  168. region.color = attr_bgcol_ec(bgshift,vc);
  169. region.rop = ROP_COPY;
  170. if (rw && !bottom_only) {
  171. region.dx = 0;
  172. region.dy = info->var.yoffset;
  173. region.height = rw;
  174. region.width = info->var.xres_virtual;
  175. info->fbops->fb_fillrect(info, &region);
  176. }
  177. if (bh) {
  178. region.dx = info->var.xoffset + bs;
  179. region.dy = 0;
  180. region.height = info->var.yres_virtual;
  181. region.width = bh;
  182. info->fbops->fb_fillrect(info, &region);
  183. }
  184. }
  185. static void ccw_cursor(struct vc_data *vc, struct fb_info *info,
  186. struct display *p, int mode, int softback_lines,
  187. int fg, int bg)
  188. {
  189. struct fb_cursor cursor;
  190. struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
  191. unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
  192. int w = (vc->vc_font.height + 7) >> 3, c;
  193. int y = real_y(p, vc->vc_y);
  194. int attribute, use_sw = (vc->vc_cursor_type & 0x10);
  195. int err = 1, dx, dy;
  196. char *src;
  197. u32 vyres = GETVYRES(p->scrollmode, info);
  198. if (!ops->fontbuffer)
  199. return;
  200. cursor.set = 0;
  201. if (softback_lines) {
  202. if (y + softback_lines >= vc->vc_rows) {
  203. mode = CM_ERASE;
  204. ops->cursor_flash = 0;
  205. return;
  206. } else
  207. y += softback_lines;
  208. }
  209. c = scr_readw((u16 *) vc->vc_pos);
  210. attribute = get_attribute(info, c);
  211. src = ops->fontbuffer + ((c & charmask) * (w * vc->vc_font.width));
  212. if (ops->cursor_state.image.data != src ||
  213. ops->cursor_reset) {
  214. ops->cursor_state.image.data = src;
  215. cursor.set |= FB_CUR_SETIMAGE;
  216. }
  217. if (attribute) {
  218. u8 *dst;
  219. dst = kmalloc(w * vc->vc_font.width, GFP_ATOMIC);
  220. if (!dst)
  221. return;
  222. kfree(ops->cursor_data);
  223. ops->cursor_data = dst;
  224. ccw_update_attr(dst, src, attribute, vc);
  225. src = dst;
  226. }
  227. if (ops->cursor_state.image.fg_color != fg ||
  228. ops->cursor_state.image.bg_color != bg ||
  229. ops->cursor_reset) {
  230. ops->cursor_state.image.fg_color = fg;
  231. ops->cursor_state.image.bg_color = bg;
  232. cursor.set |= FB_CUR_SETCMAP;
  233. }
  234. if (ops->cursor_state.image.height != vc->vc_font.width ||
  235. ops->cursor_state.image.width != vc->vc_font.height ||
  236. ops->cursor_reset) {
  237. ops->cursor_state.image.height = vc->vc_font.width;
  238. ops->cursor_state.image.width = vc->vc_font.height;
  239. cursor.set |= FB_CUR_SETSIZE;
  240. }
  241. dx = y * vc->vc_font.height;
  242. dy = vyres - ((vc->vc_x + 1) * vc->vc_font.width);
  243. if (ops->cursor_state.image.dx != dx ||
  244. ops->cursor_state.image.dy != dy ||
  245. ops->cursor_reset) {
  246. ops->cursor_state.image.dx = dx;
  247. ops->cursor_state.image.dy = dy;
  248. cursor.set |= FB_CUR_SETPOS;
  249. }
  250. if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
  251. ops->cursor_reset) {
  252. ops->cursor_state.hot.x = cursor.hot.y = 0;
  253. cursor.set |= FB_CUR_SETHOT;
  254. }
  255. if (cursor.set & FB_CUR_SETSIZE ||
  256. vc->vc_cursor_type != p->cursor_shape ||
  257. ops->cursor_state.mask == NULL ||
  258. ops->cursor_reset) {
  259. char *tmp, *mask = kmalloc(w*vc->vc_font.width, GFP_ATOMIC);
  260. int cur_height, size, i = 0;
  261. int width = (vc->vc_font.width + 7)/8;
  262. if (!mask)
  263. return;
  264. tmp = kmalloc(width * vc->vc_font.height, GFP_ATOMIC);
  265. if (!tmp) {
  266. kfree(mask);
  267. return;
  268. }
  269. kfree(ops->cursor_state.mask);
  270. ops->cursor_state.mask = mask;
  271. p->cursor_shape = vc->vc_cursor_type;
  272. cursor.set |= FB_CUR_SETSHAPE;
  273. switch (p->cursor_shape & CUR_HWMASK) {
  274. case CUR_NONE:
  275. cur_height = 0;
  276. break;
  277. case CUR_UNDERLINE:
  278. cur_height = (vc->vc_font.height < 10) ? 1 : 2;
  279. break;
  280. case CUR_LOWER_THIRD:
  281. cur_height = vc->vc_font.height/3;
  282. break;
  283. case CUR_LOWER_HALF:
  284. cur_height = vc->vc_font.height >> 1;
  285. break;
  286. case CUR_TWO_THIRDS:
  287. cur_height = (vc->vc_font.height << 1)/3;
  288. break;
  289. case CUR_BLOCK:
  290. default:
  291. cur_height = vc->vc_font.height;
  292. break;
  293. }
  294. size = (vc->vc_font.height - cur_height) * width;
  295. while (size--)
  296. tmp[i++] = 0;
  297. size = cur_height * width;
  298. while (size--)
  299. tmp[i++] = 0xff;
  300. memset(mask, 0, w * vc->vc_font.width);
  301. rotate_ccw(tmp, mask, vc->vc_font.width, vc->vc_font.height);
  302. kfree(tmp);
  303. }
  304. switch (mode) {
  305. case CM_ERASE:
  306. ops->cursor_state.enable = 0;
  307. break;
  308. case CM_DRAW:
  309. case CM_MOVE:
  310. default:
  311. ops->cursor_state.enable = (use_sw) ? 0 : 1;
  312. break;
  313. }
  314. cursor.image.data = src;
  315. cursor.image.fg_color = ops->cursor_state.image.fg_color;
  316. cursor.image.bg_color = ops->cursor_state.image.bg_color;
  317. cursor.image.dx = ops->cursor_state.image.dx;
  318. cursor.image.dy = ops->cursor_state.image.dy;
  319. cursor.image.height = ops->cursor_state.image.height;
  320. cursor.image.width = ops->cursor_state.image.width;
  321. cursor.hot.x = ops->cursor_state.hot.x;
  322. cursor.hot.y = ops->cursor_state.hot.y;
  323. cursor.mask = ops->cursor_state.mask;
  324. cursor.enable = ops->cursor_state.enable;
  325. cursor.image.depth = 1;
  326. cursor.rop = ROP_XOR;
  327. if (info->fbops->fb_cursor)
  328. err = info->fbops->fb_cursor(info, &cursor);
  329. if (err)
  330. soft_cursor(info, &cursor);
  331. ops->cursor_reset = 0;
  332. }
  333. int ccw_update_start(struct fb_info *info)
  334. {
  335. struct fbcon_ops *ops = info->fbcon_par;
  336. u32 yoffset;
  337. u32 vyres = GETVYRES(ops->p->scrollmode, info);
  338. int err;
  339. yoffset = (vyres - info->var.yres) - ops->var.xoffset;
  340. ops->var.xoffset = ops->var.yoffset;
  341. ops->var.yoffset = yoffset;
  342. err = fb_pan_display(info, &ops->var);
  343. ops->var.xoffset = info->var.xoffset;
  344. ops->var.yoffset = info->var.yoffset;
  345. ops->var.vmode = info->var.vmode;
  346. return err;
  347. }
  348. void fbcon_rotate_ccw(struct fbcon_ops *ops)
  349. {
  350. ops->bmove = ccw_bmove;
  351. ops->clear = ccw_clear;
  352. ops->putcs = ccw_putcs;
  353. ops->clear_margins = ccw_clear_margins;
  354. ops->cursor = ccw_cursor;
  355. ops->update_start = ccw_update_start;
  356. }
  357. EXPORT_SYMBOL(fbcon_rotate_ccw);
  358. MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
  359. MODULE_DESCRIPTION("Console Rotation (270 degrees) Support");
  360. MODULE_LICENSE("GPL");