sed13806.c 9.7 KB

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