sed13806.c 9.0 KB

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