fbcon_cw.c 11 KB

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