mb862xxfb_accel.c 8.0 KB

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