fbcon-cfb24.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:9k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/drivers/video/cfb24.c -- Low level frame buffer operations for 24 bpp
  3.  *    truecolor packed pixels
  4.  *
  5.  * Created 7 Mar 1998 by Geert Uytterhoeven
  6.  *
  7.  *  This file is subject to the terms and conditions of the GNU General Public
  8.  *  License.  See the file COPYING in the main directory of this archive for
  9.  *  more details.
  10.  */
  11. #include <linux/module.h>
  12. #include <linux/tty.h>
  13. #include <linux/console.h>
  14. #include <linux/string.h>
  15. #include <linux/fb.h>
  16. #include <video/fbcon.h>
  17. #include <video/fbcon-cfb24.h>
  18.     /*
  19.      *  24 bpp packed pixels
  20.      */
  21. void fbcon_cfb24_setup(struct display *p)
  22. {
  23.     p->next_line = p->line_length ? p->line_length : p->var.xres_virtual*3;
  24.     p->next_plane = 0;
  25. }
  26. void fbcon_cfb24_bmove(struct display *p, int sy, int sx, int dy, int dx,
  27.        int height, int width)
  28. {
  29.     int bytes = p->next_line, linesize = bytes * fontheight(p), rows;
  30.     u8 *src, *dst;
  31.     if (sx == 0 && dx == 0 && width * fontwidth(p) * 3 == bytes) {
  32. fb_memmove(p->screen_base + dy * linesize,
  33.   p->screen_base + sy * linesize,
  34.   height * linesize);
  35. return;
  36.     }
  37.     if (fontwidthlog(p)) {
  38. sx <<= fontwidthlog(p);
  39. dx <<= fontwidthlog(p);
  40. width <<= fontwidthlog(p);
  41.     } else {
  42. sx *= fontwidth(p);
  43. dx *= fontwidth(p);
  44. width *= fontwidth(p);
  45.     }
  46.     sx *= 3; dx *= 3; width *= 3;
  47.     if (dy < sy || (dy == sy && dx < sx)) {
  48. src = p->screen_base + sy * linesize + sx;
  49. dst = p->screen_base + dy * linesize + dx;
  50. for (rows = height * fontheight(p); rows--;) {
  51.     fb_memmove(dst, src, width);
  52.     src += bytes;
  53.     dst += bytes;
  54. }
  55.     } else {
  56. src = p->screen_base + (sy+height) * linesize + sx - bytes;
  57. dst = p->screen_base + (dy+height) * linesize + dx - bytes;
  58. for (rows = height * fontheight(p); rows--;) {
  59.     fb_memmove(dst, src, width);
  60.     src -= bytes;
  61.     dst -= bytes;
  62. }
  63.     }
  64. }
  65. #if defined(__BIG_ENDIAN)
  66. #define convert4to3(in1, in2, in3, in4, out1, out2, out3) 
  67.     do { 
  68. out1 = (in1<<8)  | (in2>>16); 
  69. out2 = (in2<<16) | (in3>>8); 
  70. out3 = (in3<<24) | in4; 
  71.     } while (0);
  72. #elif defined(__LITTLE_ENDIAN)
  73. #define convert4to3(in1, in2, in3, in4, out1, out2, out3) 
  74.     do { 
  75. out1 = in1       | (in2<<24); 
  76. out2 = (in2>> 8) | (in3<<16); 
  77. out3 = (in3>>16) | (in4<< 8); 
  78.     } while (0);
  79. #else
  80. #error FIXME: No endianness??
  81. #endif
  82. static inline void store4pixels(u32 d1, u32 d2, u32 d3, u32 d4, u32 *dest)
  83. {
  84.     u32 o1, o2, o3;
  85.     convert4to3(d1, d2, d3, d4, o1, o2, o3);
  86.     fb_writel (o1, dest++);
  87.     fb_writel (o2, dest++);
  88.     fb_writel (o3, dest);
  89. }
  90. static inline void rectfill(u8 *dest, int width, int height, u32 data,
  91.     int linesize)
  92. {
  93.     u32 d1, d2, d3;
  94.     int i;
  95.     convert4to3(data, data, data, data, d1, d2, d3);
  96.     while (height-- > 0) {
  97. u32 *p = (u32 *)dest;
  98. for (i = 0; i < width/4; i++) {
  99.     fb_writel(d1, p++);
  100.     fb_writel(d2, p++);
  101.     fb_writel(d3, p++);
  102. }
  103. dest += linesize;
  104.     }
  105. }
  106. void fbcon_cfb24_clear(struct vc_data *conp, struct display *p, int sy, int sx,
  107.        int height, int width)
  108. {
  109.     u8 *dest;
  110.     int bytes = p->next_line, lines = height * fontheight(p);
  111.     u32 bgx;
  112.     dest = p->screen_base + sy * fontheight(p) * bytes + sx * fontwidth(p) * 3;
  113.     bgx = ((u32 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
  114.     width *= fontwidth(p)/4;
  115.     if (width * 12 == bytes)
  116. rectfill(dest, lines * width * 4, 1, bgx, bytes);
  117.     else
  118. rectfill(dest, width * 4, lines, bgx, bytes);
  119. }
  120. void fbcon_cfb24_putc(struct vc_data *conp, struct display *p, int c, int yy,
  121.       int xx)
  122. {
  123.     u8 *dest, *cdat, bits;
  124.     int bytes = p->next_line, rows;
  125.     u32 eorx, fgx, bgx, d1, d2, d3, d4;
  126.     dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 3;
  127.     if (fontwidth(p) <= 8)
  128. cdat = p->fontdata + (c & p->charmask) * fontheight(p);
  129.     else
  130. cdat = p->fontdata + ((c & p->charmask) * fontheight(p) << 1);
  131.     fgx = ((u32 *)p->dispsw_data)[attr_fgcol(p, c)];
  132.     bgx = ((u32 *)p->dispsw_data)[attr_bgcol(p, c)];
  133.     eorx = fgx ^ bgx;
  134.     for (rows = fontheight(p); rows--; dest += bytes) {
  135. bits = *cdat++;
  136. d1 = (-(bits >> 7) & eorx) ^ bgx;
  137. d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
  138. d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
  139. d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
  140. store4pixels(d1, d2, d3, d4, (u32 *)dest);
  141. if (fontwidth(p) < 8)
  142.     continue;
  143. d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
  144. d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
  145. d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
  146. d4 = (-(bits & 1) & eorx) ^ bgx;
  147. store4pixels(d1, d2, d3, d4, (u32 *)(dest+12));
  148. if (fontwidth(p) < 12)
  149.     continue;
  150. bits = *cdat++;
  151. d1 = (-(bits >> 7) & eorx) ^ bgx;
  152. d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
  153. d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
  154. d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
  155. store4pixels(d1, d2, d3, d4, (u32 *)(dest+24));
  156. if (fontwidth(p) < 16)
  157.     continue;
  158. d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
  159. d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
  160. d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
  161. d4 = (-(bits & 1) & eorx) ^ bgx;
  162. store4pixels(d1, d2, d3, d4, (u32 *)(dest+36));
  163.     }
  164. }
  165. void fbcon_cfb24_putcs(struct vc_data *conp, struct display *p,
  166.        const unsigned short *s, int count, int yy, int xx)
  167. {
  168.     u8 *cdat, *dest, *dest0, bits;
  169.     u16 c;
  170.     int rows, bytes = p->next_line;
  171.     u32 eorx, fgx, bgx, d1, d2, d3, d4;
  172.     dest0 = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 3;
  173.     c = scr_readw(s);
  174.     fgx = ((u32 *)p->dispsw_data)[attr_fgcol(p, c)];
  175.     bgx = ((u32 *)p->dispsw_data)[attr_bgcol(p, c)];
  176.     eorx = fgx ^ bgx;
  177.     while (count--) {
  178. c = scr_readw(s++) & p->charmask;
  179. if (fontwidth(p) <= 8)
  180.     cdat = p->fontdata + c * fontheight(p);
  181.   
  182. else
  183.     cdat = p->fontdata + (c * fontheight(p) << 1);
  184. for (rows = fontheight(p), dest = dest0; rows--; dest += bytes) {
  185.     bits = *cdat++;
  186.     d1 = (-(bits >> 7) & eorx) ^ bgx;
  187.     d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
  188.     d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
  189.     d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
  190.     store4pixels(d1, d2, d3, d4, (u32 *)dest);
  191.     if (fontwidth(p) < 8)
  192. continue;
  193.     d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
  194.     d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
  195.     d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
  196.     d4 = (-(bits & 1) & eorx) ^ bgx;
  197.     store4pixels(d1, d2, d3, d4, (u32 *)(dest+12));
  198.     if (fontwidth(p) < 12)
  199. continue;
  200.     bits = *cdat++;
  201.     d1 = (-(bits >> 7) & eorx) ^ bgx;
  202.     d2 = (-(bits >> 6 & 1) & eorx) ^ bgx;
  203.     d3 = (-(bits >> 5 & 1) & eorx) ^ bgx;
  204.     d4 = (-(bits >> 4 & 1) & eorx) ^ bgx;
  205.     store4pixels(d1, d2, d3, d4, (u32 *)(dest+24));
  206.     if (fontwidth(p) < 16)
  207. continue;
  208.     d1 = (-(bits >> 3 & 1) & eorx) ^ bgx;
  209.     d2 = (-(bits >> 2 & 1) & eorx) ^ bgx;
  210.     d3 = (-(bits >> 1 & 1) & eorx) ^ bgx;
  211.     d4 = (-(bits & 1) & eorx) ^ bgx;
  212.     store4pixels(d1, d2, d3, d4, (u32 *)(dest+36));
  213. }
  214. dest0 += fontwidth(p)*3;
  215.     }
  216. }
  217. void fbcon_cfb24_revc(struct display *p, int xx, int yy)
  218. {
  219.     u8 *dest;
  220.     int bytes = p->next_line, rows;
  221.     dest = p->screen_base + yy * fontheight(p) * bytes + xx * fontwidth(p) * 3;
  222.     for (rows = fontheight(p); rows--; dest += bytes) {
  223. switch (fontwidth(p)) {
  224. case 16:
  225.     fb_writel(fb_readl(dest+36) ^ 0xffffffff, dest+36);
  226.     fb_writel(fb_readl(dest+40) ^ 0xffffffff, dest+40);
  227.     fb_writel(fb_readl(dest+44) ^ 0xffffffff, dest+44);
  228.     /* FALL THROUGH */
  229. case 12:
  230.     fb_writel(fb_readl(dest+24) ^ 0xffffffff, dest+24);
  231.     fb_writel(fb_readl(dest+28) ^ 0xffffffff, dest+28);
  232.     fb_writel(fb_readl(dest+32) ^ 0xffffffff, dest+32);
  233.     /* FALL THROUGH */
  234. case 8:
  235.     fb_writel(fb_readl(dest+12) ^ 0xffffffff, dest+12);
  236.     fb_writel(fb_readl(dest+16) ^ 0xffffffff, dest+16);
  237.     fb_writel(fb_readl(dest+20) ^ 0xffffffff, dest+20);
  238.     /* FALL THROUGH */
  239. case 4:
  240.     fb_writel(fb_readl(dest+0) ^ 0xffffffff, dest+0);
  241.     fb_writel(fb_readl(dest+4) ^ 0xffffffff, dest+4);
  242.     fb_writel(fb_readl(dest+8) ^ 0xffffffff, dest+8);
  243. }
  244.     }
  245. }
  246. void fbcon_cfb24_clear_margins(struct vc_data *conp, struct display *p,
  247.        int bottom_only)
  248. {
  249.     int bytes = p->next_line;
  250.     u32 bgx;
  251.     unsigned int right_start = conp->vc_cols*fontwidth(p);
  252.     unsigned int bottom_start = conp->vc_rows*fontheight(p);
  253.     unsigned int right_width, bottom_width;
  254.     bgx = ((u32 *)p->dispsw_data)[attr_bgcol_ec(p, conp)];
  255.     if (!bottom_only && (right_width = p->var.xres-right_start))
  256. rectfill(p->screen_base+right_start*3, right_width,
  257.  p->var.yres_virtual, bgx, bytes);
  258.     if ((bottom_width = p->var.yres-bottom_start))
  259. rectfill(p->screen_base+(p->var.yoffset+bottom_start)*bytes,
  260.  right_start, bottom_width, bgx, bytes);
  261. }
  262.     /*
  263.      *  `switch' for the low level operations
  264.      */
  265. struct display_switch fbcon_cfb24 = {
  266.     setup: fbcon_cfb24_setup,
  267.     bmove: fbcon_cfb24_bmove,
  268.     clear: fbcon_cfb24_clear,
  269.     putc: fbcon_cfb24_putc,
  270.     putcs: fbcon_cfb24_putcs,
  271.     revc: fbcon_cfb24_revc,
  272.     clear_margins: fbcon_cfb24_clear_margins,
  273.     fontwidthmask: FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
  274. };
  275. #ifdef MODULE
  276. MODULE_LICENSE("GPL");
  277. int init_module(void)
  278. {
  279.     return 0;
  280. }
  281. void cleanup_module(void)
  282. {}
  283. #endif /* MODULE */
  284.     /*
  285.      *  Visible symbols for modules
  286.      */
  287. EXPORT_SYMBOL(fbcon_cfb24);
  288. EXPORT_SYMBOL(fbcon_cfb24_setup);
  289. EXPORT_SYMBOL(fbcon_cfb24_bmove);
  290. EXPORT_SYMBOL(fbcon_cfb24_clear);
  291. EXPORT_SYMBOL(fbcon_cfb24_putc);
  292. EXPORT_SYMBOL(fbcon_cfb24_putcs);
  293. EXPORT_SYMBOL(fbcon_cfb24_revc);
  294. EXPORT_SYMBOL(fbcon_cfb24_clear_margins);