fbcon_cw.c 11 KB

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