fbcon_cw.c 10 KB

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