sed13806.c 9.6 KB

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