mb862xxfb_accel.c 8.2 KB

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