sed13806.c 9.7 KB

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