sed13806.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * (C) Copyright 2002
  3. * Stäubli Faverges - <www.staubli.com>
  4. * Pierre AUBERT p.aubert@staubli.com
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. /* Video support for Epson SED13806 chipset */
  9. #include <common.h>
  10. #include <video_fb.h>
  11. #include <sed13806.h>
  12. #define readByte(ptrReg) \
  13. *(volatile unsigned char *)(sed13806.isaBase + ptrReg)
  14. #define writeByte(ptrReg,value) \
  15. *(volatile unsigned char *)(sed13806.isaBase + ptrReg) = value
  16. #define writeWord(ptrReg,value) \
  17. (*(volatile unsigned short *)(sed13806.isaBase + ptrReg) = ((value >> 8 ) & 0xff) | ((value << 8) & 0xff00))
  18. GraphicDevice sed13806;
  19. /*-----------------------------------------------------------------------------
  20. * EpsonSetRegs --
  21. *-----------------------------------------------------------------------------
  22. */
  23. static void EpsonSetRegs (void)
  24. {
  25. /* the content of the chipset register depends on the board (clocks, ...)*/
  26. const S1D_REGS *preg = board_get_regs ();
  27. while (preg -> Index) {
  28. writeByte (preg -> Index, preg -> Value);
  29. preg ++;
  30. }
  31. }
  32. /*-----------------------------------------------------------------------------
  33. * video_hw_init --
  34. *-----------------------------------------------------------------------------
  35. */
  36. void *video_hw_init (void)
  37. {
  38. unsigned int *vm, i;
  39. memset (&sed13806, 0, sizeof (GraphicDevice));
  40. /* Initialization of the access to the graphic chipset
  41. Retreive base address of the chipset
  42. (see board/RPXClassic/eccx.c) */
  43. if ((sed13806.isaBase = board_video_init ()) == 0) {
  44. return (NULL);
  45. }
  46. sed13806.frameAdrs = sed13806.isaBase + FRAME_BUFFER_OFFSET;
  47. sed13806.winSizeX = board_get_width ();
  48. sed13806.winSizeY = board_get_height ();
  49. #if defined(CONFIG_VIDEO_SED13806_8BPP)
  50. sed13806.gdfIndex = GDF__8BIT_INDEX;
  51. sed13806.gdfBytesPP = 1;
  52. #elif defined(CONFIG_VIDEO_SED13806_16BPP)
  53. sed13806.gdfIndex = GDF_16BIT_565RGB;
  54. sed13806.gdfBytesPP = 2;
  55. #else
  56. #error Unsupported SED13806 BPP
  57. #endif
  58. sed13806.memSize = sed13806.winSizeX * sed13806.winSizeY * sed13806.gdfBytesPP;
  59. /* Load SED registers */
  60. EpsonSetRegs ();
  61. /* (see board/RPXClassic/RPXClassic.c) */
  62. board_validate_screen (sed13806.isaBase);
  63. /* Clear video memory */
  64. i = sed13806.memSize/4;
  65. vm = (unsigned int *)sed13806.frameAdrs;
  66. while(i--)
  67. *vm++ = 0;
  68. return (&sed13806);
  69. }
  70. /*-----------------------------------------------------------------------------
  71. * Epson_wait_idle -- Wait for hardware to become idle
  72. *-----------------------------------------------------------------------------
  73. */
  74. static void Epson_wait_idle (void)
  75. {
  76. while (readByte (BLT_CTRL0) & 0x80);
  77. /* Read a word in the BitBLT memory area to shutdown the BitBLT engine */
  78. *(volatile unsigned short *)(sed13806.isaBase + BLT_REG);
  79. }
  80. /*-----------------------------------------------------------------------------
  81. * video_hw_bitblt --
  82. *-----------------------------------------------------------------------------
  83. */
  84. void video_hw_bitblt (
  85. unsigned int bpp, /* bytes per pixel */
  86. unsigned int src_x, /* source pos x */
  87. unsigned int src_y, /* source pos y */
  88. unsigned int dst_x, /* dest pos x */
  89. unsigned int dst_y, /* dest pos y */
  90. unsigned int dim_x, /* frame width */
  91. unsigned int dim_y /* frame height */
  92. )
  93. {
  94. register GraphicDevice *pGD = (GraphicDevice *)&sed13806;
  95. unsigned long srcAddr, dstAddr;
  96. unsigned int stride = bpp * pGD -> winSizeX;
  97. srcAddr = (src_y * stride) + (src_x * bpp);
  98. dstAddr = (dst_y * stride) + (dst_x * bpp);
  99. Epson_wait_idle ();
  100. writeByte(BLT_ROP,0x0C); /* source */
  101. writeByte(BLT_OP,0x02);/* move blit in positive direction with ROP */
  102. writeWord(BLT_MEM_OFF0, stride / 2);
  103. if (pGD -> gdfIndex == GDF__8BIT_INDEX) {
  104. writeByte(BLT_CTRL1,0x00);
  105. }
  106. else {
  107. writeByte(BLT_CTRL1,0x01);
  108. }
  109. writeWord(BLT_WIDTH0,(dim_x - 1));
  110. writeWord(BLT_HEIGHT0,(dim_y - 1));
  111. /* set up blit registers */
  112. writeByte(BLT_SRC_ADDR0,srcAddr);
  113. writeByte(BLT_SRC_ADDR1,srcAddr>>8);
  114. writeByte(BLT_SRC_ADDR2,srcAddr>>16);
  115. writeByte(BLT_DST_ADDR0,dstAddr);
  116. writeByte(BLT_DST_ADDR1,dstAddr>>8);
  117. writeByte(BLT_DST_ADDR2,dstAddr>>16);
  118. /* Engage the blt engine */
  119. /* rectangular region for src and dst */
  120. writeByte(BLT_CTRL0,0x80);
  121. /* wait untill current blits finished */
  122. Epson_wait_idle ();
  123. }
  124. /*-----------------------------------------------------------------------------
  125. * video_hw_rectfill --
  126. *-----------------------------------------------------------------------------
  127. */
  128. void video_hw_rectfill (
  129. unsigned int bpp, /* bytes per pixel */
  130. unsigned int dst_x, /* dest pos x */
  131. unsigned int dst_y, /* dest pos y */
  132. unsigned int dim_x, /* frame width */
  133. unsigned int dim_y, /* frame height */
  134. unsigned int color /* fill color */
  135. )
  136. {
  137. register GraphicDevice *pGD = (GraphicDevice *)&sed13806;
  138. unsigned long dstAddr;
  139. unsigned int stride = bpp * pGD -> winSizeX;
  140. dstAddr = (dst_y * stride) + (dst_x * bpp);
  141. Epson_wait_idle ();
  142. /* set up blit registers */
  143. writeByte(BLT_DST_ADDR0,dstAddr);
  144. writeByte(BLT_DST_ADDR1,dstAddr>>8);
  145. writeByte(BLT_DST_ADDR2,dstAddr>>16);
  146. writeWord(BLT_WIDTH0,(dim_x - 1));
  147. writeWord(BLT_HEIGHT0,(dim_y - 1));
  148. writeWord(BLT_FGCOLOR0,color);
  149. writeByte(BLT_OP,0x0C); /* solid fill */
  150. writeWord(BLT_MEM_OFF0,stride / 2);
  151. if (pGD -> gdfIndex == GDF__8BIT_INDEX) {
  152. writeByte(BLT_CTRL1,0x00);
  153. }
  154. else {
  155. writeByte(BLT_CTRL1,0x01);
  156. }
  157. /* Engage the blt engine */
  158. /* rectangular region for src and dst */
  159. writeByte(BLT_CTRL0,0x80);
  160. /* wait untill current blits finished */
  161. Epson_wait_idle ();
  162. }
  163. /*-----------------------------------------------------------------------------
  164. * video_set_lut --
  165. *-----------------------------------------------------------------------------
  166. */
  167. void video_set_lut (
  168. unsigned int index, /* color number */
  169. unsigned char r, /* red */
  170. unsigned char g, /* green */
  171. unsigned char b /* blue */
  172. )
  173. {
  174. writeByte(REG_LUT_ADDR, index );
  175. writeByte(REG_LUT_DATA, r);
  176. writeByte(REG_LUT_DATA, g);
  177. writeByte(REG_LUT_DATA, b);
  178. }
  179. #ifdef CONFIG_VIDEO_HW_CURSOR
  180. /*-----------------------------------------------------------------------------
  181. * video_set_hw_cursor --
  182. *-----------------------------------------------------------------------------
  183. */
  184. void video_set_hw_cursor (int x, int y)
  185. {
  186. writeByte (LCD_CURSOR_XL, (x & 0xff));
  187. writeByte (LCD_CURSOR_XM, (x >> 8));
  188. writeByte (LCD_CURSOR_YL, (y & 0xff));
  189. writeByte (LCD_CURSOR_YM, (y >> 8));
  190. }
  191. /*-----------------------------------------------------------------------------
  192. * video_init_hw_cursor --
  193. *-----------------------------------------------------------------------------
  194. */
  195. void video_init_hw_cursor (int font_width, int font_height)
  196. {
  197. volatile unsigned char *ptr;
  198. unsigned char pattern;
  199. int i;
  200. /* Init cursor content
  201. Cursor size is 64x64 pixels
  202. Start of the cursor memory depends on panel type (dual panel ...) */
  203. if ((i = readByte (LCD_CURSOR_START)) == 0) {
  204. ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - HWCURSORSIZE);
  205. }
  206. else {
  207. ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - (i * 8192));
  208. }
  209. /* Fill the first line and the first empty line after cursor */
  210. for (i = 0, pattern = 0; i < 64; i++) {
  211. if (i < font_width) {
  212. /* Invert background */
  213. pattern |= 0x3;
  214. }
  215. else {
  216. /* Background */
  217. pattern |= 0x2;
  218. }
  219. if ((i & 3) == 3) {
  220. *ptr = pattern;
  221. *(ptr + font_height * 16) = 0xaa;
  222. ptr ++;
  223. pattern = 0;
  224. }
  225. pattern <<= 2;
  226. }
  227. /* Duplicate this line */
  228. for (i = 1; i < font_height; i++) {
  229. memcpy ((void *)ptr, (void *)(ptr - 16), 16);
  230. ptr += 16;
  231. }
  232. for (; i < 64; i++) {
  233. memcpy ((void *)(ptr + 16), (void *)ptr, 16);
  234. ptr += 16;
  235. }
  236. /* Select cursor mode */
  237. writeByte (LCD_CURSOR_CNTL, 1);
  238. }
  239. #endif