video.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. * video.c - run splash screen on lcd
  3. *
  4. * Copyright (c) 2007-2008 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <stdarg.h>
  9. #include <common.h>
  10. #include <config.h>
  11. #include <malloc.h>
  12. #include <asm/blackfin.h>
  13. #include <asm/clock.h>
  14. #include <asm/gpio.h>
  15. #include <asm/portmux.h>
  16. #include <asm/mach-common/bits/dma.h>
  17. #include <i2c.h>
  18. #include <linux/types.h>
  19. #include <stdio_dev.h>
  20. #include <lzma/LzmaTypes.h>
  21. #include <lzma/LzmaDec.h>
  22. #include <lzma/LzmaTools.h>
  23. #define DMA_SIZE16 2
  24. #include <asm/mach-common/bits/eppi.h>
  25. #include EASYLOGO_HEADER
  26. #define LCD_X_RES 480 /*Horizontal Resolution */
  27. #define LCD_Y_RES 272 /* Vertical Resolution */
  28. #define LCD_BPP 24 /* Bit Per Pixel */
  29. #define LCD_PIXEL_SIZE (LCD_BPP / 8)
  30. #define DMA_BUS_SIZE 32
  31. #define ACTIVE_VIDEO_MEM_OFFSET 0
  32. /* -- Horizontal synchronizing --
  33. *
  34. * Timing characteristics taken from the SHARP LQ043T1DG01 datasheet
  35. * (LCY-W-06602A Page 9 of 22)
  36. *
  37. * Clock Frequency 1/Tc Min 7.83 Typ 9.00 Max 9.26 MHz
  38. *
  39. * Period TH - 525 - Clock
  40. * Pulse width THp - 41 - Clock
  41. * Horizontal period THd - 480 - Clock
  42. * Back porch THb - 2 - Clock
  43. * Front porch THf - 2 - Clock
  44. *
  45. * -- Vertical synchronizing --
  46. * Period TV - 286 - Line
  47. * Pulse width TVp - 10 - Line
  48. * Vertical period TVd - 272 - Line
  49. * Back porch TVb - 2 - Line
  50. * Front porch TVf - 2 - Line
  51. */
  52. #define LCD_CLK (8*1000*1000) /* 8MHz */
  53. /* # active data to transfer after Horizontal Delay clock */
  54. #define EPPI_HCOUNT LCD_X_RES
  55. /* # active lines to transfer after Vertical Delay clock */
  56. #define EPPI_VCOUNT LCD_Y_RES
  57. /* Samples per Line = 480 (active data) + 45 (padding) */
  58. #define EPPI_LINE 525
  59. /* Lines per Frame = 272 (active data) + 14 (padding) */
  60. #define EPPI_FRAME 286
  61. /* FS1 (Hsync) Width (Typical)*/
  62. #define EPPI_FS1W_HBL 41
  63. /* FS1 (Hsync) Period (Typical) */
  64. #define EPPI_FS1P_AVPL EPPI_LINE
  65. /* Horizontal Delay clock after assertion of Hsync (Typical) */
  66. #define EPPI_HDELAY 43
  67. /* FS2 (Vsync) Width = FS1 (Hsync) Period * 10 */
  68. #define EPPI_FS2W_LVB (EPPI_LINE * 10)
  69. /* FS2 (Vsync) Period = FS1 (Hsync) Period * Lines per Frame */
  70. #define EPPI_FS2P_LAVF (EPPI_LINE * EPPI_FRAME)
  71. /* Vertical Delay after assertion of Vsync (2 Lines) */
  72. #define EPPI_VDELAY 12
  73. #define EPPI_CLIP 0xFF00FF00
  74. /* EPPI Control register configuration value for RGB out
  75. * - EPPI as Output
  76. * GP 2 frame sync mode,
  77. * Internal Clock generation disabled, Internal FS generation enabled,
  78. * Receives samples on EPPI_CLK raising edge, Transmits samples on EPPI_CLK falling edge,
  79. * FS1 & FS2 are active high,
  80. * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out)
  81. * DMA Unpacking disabled when RGB Formating is enabled, otherwise DMA unpacking enabled
  82. * Swapping Enabled,
  83. * One (DMA) Channel Mode,
  84. * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output
  85. * Regular watermark - when FIFO is 100% full,
  86. * Urgent watermark - when FIFO is 75% full
  87. */
  88. #define EPPI_CONTROL (0x20136E2E)
  89. static inline u16 get_eppi_clkdiv(u32 target_ppi_clk)
  90. {
  91. u32 sclk = get_sclk();
  92. /* EPPI_CLK = (SCLK) / (2 * (EPPI_CLKDIV[15:0] + 1)) */
  93. return (((sclk / target_ppi_clk) / 2) - 1);
  94. }
  95. void Init_PPI(void)
  96. {
  97. u16 eppi_clkdiv = get_eppi_clkdiv(LCD_CLK);
  98. bfin_write_EPPI0_FS1W_HBL(EPPI_FS1W_HBL);
  99. bfin_write_EPPI0_FS1P_AVPL(EPPI_FS1P_AVPL);
  100. bfin_write_EPPI0_FS2W_LVB(EPPI_FS2W_LVB);
  101. bfin_write_EPPI0_FS2P_LAVF(EPPI_FS2P_LAVF);
  102. bfin_write_EPPI0_CLIP(EPPI_CLIP);
  103. bfin_write_EPPI0_FRAME(EPPI_FRAME);
  104. bfin_write_EPPI0_LINE(EPPI_LINE);
  105. bfin_write_EPPI0_HCOUNT(EPPI_HCOUNT);
  106. bfin_write_EPPI0_HDELAY(EPPI_HDELAY);
  107. bfin_write_EPPI0_VCOUNT(EPPI_VCOUNT);
  108. bfin_write_EPPI0_VDELAY(EPPI_VDELAY);
  109. bfin_write_EPPI0_CLKDIV(eppi_clkdiv);
  110. /*
  111. * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out)
  112. * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output
  113. */
  114. #if defined(CONFIG_VIDEO_RGB666)
  115. bfin_write_EPPI0_CONTROL((EPPI_CONTROL & ~DLENGTH) | DLEN_18 |
  116. RGB_FMT_EN);
  117. #else
  118. bfin_write_EPPI0_CONTROL(((EPPI_CONTROL & ~DLENGTH) | DLEN_24) &
  119. ~RGB_FMT_EN);
  120. #endif
  121. }
  122. #define DEB2_URGENT 0x2000 /* DEB2 Urgent */
  123. void Init_DMA(void *dst)
  124. {
  125. #if defined(CONFIG_DEB_DMA_URGENT)
  126. bfin_write_EBIU_DDRQUE(bfin_read_EBIU_DDRQUE() | DEB2_URGENT);
  127. #endif
  128. bfin_write_DMA12_START_ADDR(dst);
  129. /* X count */
  130. bfin_write_DMA12_X_COUNT((LCD_X_RES * LCD_BPP) / DMA_BUS_SIZE);
  131. bfin_write_DMA12_X_MODIFY(DMA_BUS_SIZE / 8);
  132. /* Y count */
  133. bfin_write_DMA12_Y_COUNT(LCD_Y_RES);
  134. bfin_write_DMA12_Y_MODIFY(DMA_BUS_SIZE / 8);
  135. /* DMA Config */
  136. bfin_write_DMA12_CONFIG(
  137. WDSIZE_32 | /* 32 bit DMA */
  138. DMA2D | /* 2D DMA */
  139. FLOW_AUTO /* autobuffer mode */
  140. );
  141. }
  142. void Init_Ports(void)
  143. {
  144. const unsigned short pins[] = {
  145. P_PPI0_D0, P_PPI0_D1, P_PPI0_D2, P_PPI0_D3, P_PPI0_D4,
  146. P_PPI0_D5, P_PPI0_D6, P_PPI0_D7, P_PPI0_D8, P_PPI0_D9,
  147. P_PPI0_D10, P_PPI0_D11, P_PPI0_D12, P_PPI0_D13, P_PPI0_D14,
  148. P_PPI0_D15, P_PPI0_D16, P_PPI0_D17,
  149. #if !defined(CONFIG_VIDEO_RGB666)
  150. P_PPI0_D18, P_PPI0_D19, P_PPI0_D20, P_PPI0_D21, P_PPI0_D22,
  151. P_PPI0_D23,
  152. #endif
  153. P_PPI0_CLK, P_PPI0_FS1, P_PPI0_FS2, 0,
  154. };
  155. peripheral_request_list(pins, "lcd");
  156. gpio_request(GPIO_PE3, "lcd-disp");
  157. gpio_direction_output(GPIO_PE3, 1);
  158. }
  159. void EnableDMA(void)
  160. {
  161. bfin_write_DMA12_CONFIG(bfin_read_DMA12_CONFIG() | DMAEN);
  162. }
  163. void DisableDMA(void)
  164. {
  165. bfin_write_DMA12_CONFIG(bfin_read_DMA12_CONFIG() & ~DMAEN);
  166. }
  167. /* enable and disable PPI functions */
  168. void EnablePPI(void)
  169. {
  170. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN);
  171. }
  172. void DisablePPI(void)
  173. {
  174. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN);
  175. }
  176. int video_init(void *dst)
  177. {
  178. Init_Ports();
  179. Init_DMA(dst);
  180. EnableDMA();
  181. Init_PPI();
  182. EnablePPI();
  183. return 0;
  184. }
  185. void video_stop(void)
  186. {
  187. DisablePPI();
  188. DisableDMA();
  189. }
  190. static void dma_bitblit(void *dst, fastimage_t *logo, int x, int y)
  191. {
  192. if (dcache_status())
  193. blackfin_dcache_flush_range(logo->data,
  194. logo->data + logo->size);
  195. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  196. /* Setup destination start address */
  197. bfin_write_MDMA_D0_START_ADDR(dst + ((x & -2) * LCD_PIXEL_SIZE)
  198. + (y * LCD_X_RES * LCD_PIXEL_SIZE));
  199. /* Setup destination xcount */
  200. bfin_write_MDMA_D0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
  201. /* Setup destination xmodify */
  202. bfin_write_MDMA_D0_X_MODIFY(DMA_SIZE16);
  203. /* Setup destination ycount */
  204. bfin_write_MDMA_D0_Y_COUNT(logo->height);
  205. /* Setup destination ymodify */
  206. bfin_write_MDMA_D0_Y_MODIFY((LCD_X_RES - logo->width) * LCD_PIXEL_SIZE +
  207. DMA_SIZE16);
  208. /* Setup Source start address */
  209. bfin_write_MDMA_S0_START_ADDR(logo->data);
  210. /* Setup Source xcount */
  211. bfin_write_MDMA_S0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
  212. /* Setup Source xmodify */
  213. bfin_write_MDMA_S0_X_MODIFY(DMA_SIZE16);
  214. /* Setup Source ycount */
  215. bfin_write_MDMA_S0_Y_COUNT(logo->height);
  216. /* Setup Source ymodify */
  217. bfin_write_MDMA_S0_Y_MODIFY(DMA_SIZE16);
  218. /* Enable source DMA */
  219. bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16 | DMA2D);
  220. SSYNC();
  221. bfin_write_MDMA_D0_CONFIG(WNR | DMAEN | WDSIZE_16 | DMA2D);
  222. while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN) ;
  223. bfin_write_MDMA_S0_IRQ_STATUS(bfin_read_MDMA_S0_IRQ_STATUS() | DMA_DONE
  224. | DMA_ERR);
  225. bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE
  226. | DMA_ERR);
  227. }
  228. int drv_video_init(void)
  229. {
  230. int error, devices = 1;
  231. struct stdio_dev videodev;
  232. u8 *dst;
  233. u32 fbmem_size =
  234. LCD_X_RES * LCD_Y_RES * LCD_PIXEL_SIZE + ACTIVE_VIDEO_MEM_OFFSET;
  235. dst = malloc(fbmem_size);
  236. if (dst == NULL) {
  237. printf("Failed to alloc FB memory\n");
  238. return -1;
  239. }
  240. #ifdef EASYLOGO_ENABLE_GZIP
  241. unsigned char *data = EASYLOGO_DECOMP_BUFFER;
  242. unsigned long src_len = EASYLOGO_ENABLE_GZIP;
  243. error = gunzip(data, bfin_logo.size, bfin_logo.data, &src_len);
  244. bfin_logo.data = data;
  245. #elif defined(EASYLOGO_ENABLE_LZMA)
  246. unsigned char *data = EASYLOGO_DECOMP_BUFFER;
  247. SizeT lzma_len = bfin_logo.size;
  248. error = lzmaBuffToBuffDecompress(data, &lzma_len,
  249. bfin_logo.data, EASYLOGO_ENABLE_LZMA);
  250. bfin_logo.data = data;
  251. #else
  252. error = 0;
  253. #endif
  254. if (error) {
  255. puts("Failed to decompress logo\n");
  256. free(dst);
  257. return -1;
  258. }
  259. memset(dst + ACTIVE_VIDEO_MEM_OFFSET, bfin_logo.data[0],
  260. fbmem_size - ACTIVE_VIDEO_MEM_OFFSET);
  261. dma_bitblit(dst + ACTIVE_VIDEO_MEM_OFFSET, &bfin_logo,
  262. (LCD_X_RES - bfin_logo.width) / 2,
  263. (LCD_Y_RES - bfin_logo.height) / 2);
  264. video_init(dst); /* Video initialization */
  265. memset(&videodev, 0, sizeof(videodev));
  266. strcpy(videodev.name, "video");
  267. error = stdio_register(&videodev);
  268. return (error == 0) ? devices : error;
  269. }