mb862xxfb_accel.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * drivers/mb862xx/mb862xxfb_accel.c
  3. *
  4. * Fujitsu Carmine/Coral-P(A)/Lime framebuffer driver acceleration support
  5. *
  6. * (C) 2007 Alexander Shishkin <virtuoso@slind.org>
  7. * (C) 2009 Valentin Sitdikov <v.sitdikov@gmail.com>
  8. * (C) 2009 Siemens AG
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. */
  15. #include <linux/fb.h>
  16. #include <linux/delay.h>
  17. #include <linux/init.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/module.h>
  20. #include <linux/pci.h>
  21. #include <linux/slab.h>
  22. #if defined(CONFIG_OF)
  23. #include <linux/of_platform.h>
  24. #endif
  25. #include "mb862xxfb.h"
  26. #include "mb862xx_reg.h"
  27. #include "mb862xxfb_accel.h"
  28. static void mb862xxfb_write_fifo(u32 count, u32 *data, struct fb_info *info)
  29. {
  30. struct mb862xxfb_par *par = info->par;
  31. static u32 free;
  32. u32 total = 0;
  33. while (total < count) {
  34. if (free) {
  35. outreg(geo, GDC_GEO_REG_INPUT_FIFO, data[total]);
  36. total++;
  37. free--;
  38. } else {
  39. free = (u32) inreg(draw, GDC_REG_FIFO_COUNT);
  40. }
  41. }
  42. }
  43. static void mb86290fb_copyarea(struct fb_info *info,
  44. const struct fb_copyarea *area)
  45. {
  46. __u32 cmd[6];
  47. cmd[0] = (GDC_TYPE_SETREGISTER << 24) | (1 << 16) | GDC_REG_MODE_BITMAP;
  48. /* Set raster operation */
  49. cmd[1] = (2 << 7) | (GDC_ROP_COPY << 9);
  50. cmd[2] = GDC_TYPE_BLTCOPYP << 24;
  51. if (area->sx >= area->dx && area->sy >= area->dy)
  52. cmd[2] |= GDC_CMD_BLTCOPY_TOP_LEFT << 16;
  53. else if (area->sx >= area->dx && area->sy <= area->dy)
  54. cmd[2] |= GDC_CMD_BLTCOPY_BOTTOM_LEFT << 16;
  55. else if (area->sx <= area->dx && area->sy >= area->dy)
  56. cmd[2] |= GDC_CMD_BLTCOPY_TOP_RIGHT << 16;
  57. else
  58. cmd[2] |= GDC_CMD_BLTCOPY_BOTTOM_RIGHT << 16;
  59. cmd[3] = (area->sy << 16) | area->sx;
  60. cmd[4] = (area->dy << 16) | area->dx;
  61. cmd[5] = (area->height << 16) | area->width;
  62. mb862xxfb_write_fifo(6, cmd, info);
  63. }
  64. /*
  65. * Fill in the cmd array /GDC FIFO commands/ to draw a 1bit image.
  66. * Make sure cmd has enough room!
  67. */
  68. static void mb86290fb_imageblit1(u32 *cmd, u16 step, u16 dx, u16 dy,
  69. u16 width, u16 height, u32 fgcolor,
  70. u32 bgcolor, const struct fb_image *image,
  71. struct fb_info *info)
  72. {
  73. int i;
  74. unsigned const char *line;
  75. u16 bytes;
  76. /* set colors and raster operation regs */
  77. cmd[0] = (GDC_TYPE_SETREGISTER << 24) | (1 << 16) | GDC_REG_MODE_BITMAP;
  78. /* Set raster operation */
  79. cmd[1] = (2 << 7) | (GDC_ROP_COPY << 9);
  80. cmd[2] =
  81. (GDC_TYPE_SETCOLORREGISTER << 24) | (GDC_CMD_BODY_FORE_COLOR << 16);
  82. cmd[3] = fgcolor;
  83. cmd[4] =
  84. (GDC_TYPE_SETCOLORREGISTER << 24) | (GDC_CMD_BODY_BACK_COLOR << 16);
  85. cmd[5] = bgcolor;
  86. i = 0;
  87. line = image->data;
  88. bytes = (image->width + 7) >> 3;
  89. /* and the image */
  90. cmd[6] = (GDC_TYPE_DRAWBITMAPP << 24) |
  91. (GDC_CMD_BITMAP << 16) | (2 + (step * height));
  92. cmd[7] = (dy << 16) | dx;
  93. cmd[8] = (height << 16) | width;
  94. while (i < height) {
  95. memcpy(&cmd[9 + i * step], line, step << 2);
  96. #ifdef __LITTLE_ENDIAN
  97. {
  98. int k = 0;
  99. for (k = 0; k < step; k++)
  100. cmd[9 + i * step + k] =
  101. cpu_to_be32(cmd[9 + i * step + k]);
  102. }
  103. #endif
  104. line += bytes;
  105. i++;
  106. }
  107. }
  108. /*
  109. * Fill in the cmd array /GDC FIFO commands/ to draw a 8bit image.
  110. * Make sure cmd has enough room!
  111. */
  112. static void mb86290fb_imageblit8(u32 *cmd, u16 step, u16 dx, u16 dy,
  113. u16 width, u16 height, u32 fgcolor,
  114. u32 bgcolor, const struct fb_image *image,
  115. struct fb_info *info)
  116. {
  117. int i, j;
  118. unsigned const char *line, *ptr;
  119. u16 bytes;
  120. cmd[0] = (GDC_TYPE_DRAWBITMAPP << 24) |
  121. (GDC_CMD_BLT_DRAW << 16) | (2 + (height * step));
  122. cmd[1] = (dy << 16) | dx;
  123. cmd[2] = (height << 16) | width;
  124. i = 0;
  125. line = ptr = image->data;
  126. bytes = image->width;
  127. while (i < height) {
  128. ptr = line;
  129. for (j = 0; j < step; j++) {
  130. cmd[3 + i * step + j] =
  131. (((u32 *) (info->pseudo_palette))[*ptr]) & 0xffff;
  132. ptr++;
  133. cmd[3 + i * step + j] |=
  134. ((((u32 *) (info->
  135. pseudo_palette))[*ptr]) & 0xffff) << 16;
  136. ptr++;
  137. }
  138. line += bytes;
  139. i++;
  140. }
  141. }
  142. /*
  143. * Fill in the cmd array /GDC FIFO commands/ to draw a 16bit image.
  144. * Make sure cmd has enough room!
  145. */
  146. static void mb86290fb_imageblit16(u32 *cmd, u16 step, u16 dx, u16 dy,
  147. u16 width, u16 height, u32 fgcolor,
  148. u32 bgcolor, const struct fb_image *image,
  149. struct fb_info *info)
  150. {
  151. int i;
  152. unsigned const char *line;
  153. u16 bytes;
  154. i = 0;
  155. line = image->data;
  156. bytes = image->width << 1;
  157. cmd[0] = (GDC_TYPE_DRAWBITMAPP << 24) |
  158. (GDC_CMD_BLT_DRAW << 16) | (2 + step * height);
  159. cmd[1] = (dy << 16) | dx;
  160. cmd[2] = (height << 16) | width;
  161. while (i < height) {
  162. memcpy(&cmd[3 + i * step], line, step);
  163. line += bytes;
  164. i++;
  165. }
  166. }
  167. static void mb86290fb_imageblit(struct fb_info *info,
  168. const struct fb_image *image)
  169. {
  170. int mdr;
  171. u32 *cmd = NULL;
  172. void (*cmdfn) (u32 *, u16, u16, u16, u16, u16, u32, u32,
  173. const struct fb_image *, struct fb_info *) = NULL;
  174. u32 cmdlen;
  175. u32 fgcolor = 0, bgcolor = 0;
  176. u16 step;
  177. u16 width = image->width, height = image->height;
  178. u16 dx = image->dx, dy = image->dy;
  179. int x2, y2, vxres, vyres;
  180. mdr = (GDC_ROP_COPY << 9);
  181. x2 = image->dx + image->width;
  182. y2 = image->dy + image->height;
  183. vxres = info->var.xres_virtual;
  184. vyres = info->var.yres_virtual;
  185. x2 = min(x2, vxres);
  186. y2 = min(y2, vyres);
  187. width = x2 - dx;
  188. height = y2 - dy;
  189. switch (image->depth) {
  190. case 1:
  191. step = (width + 31) >> 5;
  192. cmdlen = 9 + height * step;
  193. cmdfn = mb86290fb_imageblit1;
  194. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  195. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  196. fgcolor =
  197. ((u32 *) (info->pseudo_palette))[image->fg_color];
  198. bgcolor =
  199. ((u32 *) (info->pseudo_palette))[image->bg_color];
  200. } else {
  201. fgcolor = image->fg_color;
  202. bgcolor = image->bg_color;
  203. }
  204. break;
  205. case 8:
  206. step = (width + 1) >> 1;
  207. cmdlen = 3 + height * step;
  208. cmdfn = mb86290fb_imageblit8;
  209. break;
  210. case 16:
  211. step = (width + 1) >> 1;
  212. cmdlen = 3 + height * step;
  213. cmdfn = mb86290fb_imageblit16;
  214. break;
  215. default:
  216. cfb_imageblit(info, image);
  217. return;
  218. }
  219. cmd = kmalloc(cmdlen * 4, GFP_DMA);
  220. if (!cmd)
  221. return cfb_imageblit(info, image);
  222. cmdfn(cmd, step, dx, dy, width, height, fgcolor, bgcolor, image, info);
  223. mb862xxfb_write_fifo(cmdlen, cmd, info);
  224. kfree(cmd);
  225. }
  226. static void mb86290fb_fillrect(struct fb_info *info,
  227. const struct fb_fillrect *rect)
  228. {
  229. u32 x2, y2, vxres, vyres, height, width, fg;
  230. u32 cmd[7];
  231. vxres = info->var.xres_virtual;
  232. vyres = info->var.yres_virtual;
  233. if (!rect->width || !rect->height || rect->dx > vxres
  234. || rect->dy > vyres)
  235. return;
  236. /* We could use hardware clipping but on many cards you get around
  237. * hardware clipping by writing to framebuffer directly. */
  238. x2 = rect->dx + rect->width;
  239. y2 = rect->dy + rect->height;
  240. x2 = min(x2, vxres);
  241. y2 = min(y2, vyres);
  242. width = x2 - rect->dx;
  243. height = y2 - rect->dy;
  244. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  245. info->fix.visual == FB_VISUAL_DIRECTCOLOR)
  246. fg = ((u32 *) (info->pseudo_palette))[rect->color];
  247. else
  248. fg = rect->color;
  249. switch (rect->rop) {
  250. case ROP_XOR:
  251. /* Set raster operation */
  252. cmd[1] = (2 << 7) | (GDC_ROP_XOR << 9);
  253. break;
  254. case ROP_COPY:
  255. /* Set raster operation */
  256. cmd[1] = (2 << 7) | (GDC_ROP_COPY << 9);
  257. break;
  258. }
  259. cmd[0] = (GDC_TYPE_SETREGISTER << 24) | (1 << 16) | GDC_REG_MODE_BITMAP;
  260. /* cmd[1] set earlier */
  261. cmd[2] =
  262. (GDC_TYPE_SETCOLORREGISTER << 24) | (GDC_CMD_BODY_FORE_COLOR << 16);
  263. cmd[3] = fg;
  264. cmd[4] = (GDC_TYPE_DRAWRECTP << 24) | (GDC_CMD_BLT_FILL << 16);
  265. cmd[5] = (rect->dy << 16) | (rect->dx);
  266. cmd[6] = (height << 16) | width;
  267. mb862xxfb_write_fifo(7, cmd, info);
  268. }
  269. void mb862xxfb_init_accel(struct fb_info *info, int xres)
  270. {
  271. struct mb862xxfb_par *par = info->par;
  272. if (info->var.bits_per_pixel == 32) {
  273. info->fbops->fb_fillrect = cfb_fillrect;
  274. info->fbops->fb_copyarea = cfb_copyarea;
  275. info->fbops->fb_imageblit = cfb_imageblit;
  276. } else {
  277. outreg(disp, GC_L0EM, 3);
  278. info->fbops->fb_fillrect = mb86290fb_fillrect;
  279. info->fbops->fb_copyarea = mb86290fb_copyarea;
  280. info->fbops->fb_imageblit = mb86290fb_imageblit;
  281. }
  282. outreg(draw, GDC_REG_DRAW_BASE, 0);
  283. outreg(draw, GDC_REG_MODE_MISC, 0x8000);
  284. outreg(draw, GDC_REG_X_RESOLUTION, xres);
  285. info->flags |=
  286. FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
  287. FBINFO_HWACCEL_IMAGEBLIT;
  288. info->fix.accel = 0xff; /*FIXME: add right define */
  289. }
  290. EXPORT_SYMBOL(mb862xxfb_init_accel);
  291. MODULE_LICENSE("GPL v2");