video.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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/mach-common/bits/dma.h>
  14. #include <i2c.h>
  15. #include <linux/types.h>
  16. #include <devices.h>
  17. int gunzip(void *, int, unsigned char *, unsigned long *);
  18. #define DMA_SIZE16 2
  19. #include <asm/mach-common/bits/eppi.h>
  20. #include <asm/bfin_logo_230x230.h>
  21. #define LCD_X_RES 480 /*Horizontal Resolution */
  22. #define LCD_Y_RES 272 /* Vertical Resolution */
  23. #define LCD_BPP 24 /* Bit Per Pixel */
  24. #define LCD_PIXEL_SIZE (LCD_BPP / 8)
  25. #define DMA_BUS_SIZE 32
  26. #define ACTIVE_VIDEO_MEM_OFFSET 0
  27. /* -- Horizontal synchronizing --
  28. *
  29. * Timing characteristics taken from the SHARP LQ043T1DG01 datasheet
  30. * (LCY-W-06602A Page 9 of 22)
  31. *
  32. * Clock Frequency 1/Tc Min 7.83 Typ 9.00 Max 9.26 MHz
  33. *
  34. * Period TH - 525 - Clock
  35. * Pulse width THp - 41 - Clock
  36. * Horizontal period THd - 480 - Clock
  37. * Back porch THb - 2 - Clock
  38. * Front porch THf - 2 - Clock
  39. *
  40. * -- Vertical synchronizing --
  41. * Period TV - 286 - Line
  42. * Pulse width TVp - 10 - Line
  43. * Vertical period TVd - 272 - Line
  44. * Back porch TVb - 2 - Line
  45. * Front porch TVf - 2 - Line
  46. */
  47. #define LCD_CLK (8*1000*1000) /* 8MHz */
  48. /* # active data to transfer after Horizontal Delay clock */
  49. #define EPPI_HCOUNT LCD_X_RES
  50. /* # active lines to transfer after Vertical Delay clock */
  51. #define EPPI_VCOUNT LCD_Y_RES
  52. /* Samples per Line = 480 (active data) + 45 (padding) */
  53. #define EPPI_LINE 525
  54. /* Lines per Frame = 272 (active data) + 14 (padding) */
  55. #define EPPI_FRAME 286
  56. /* FS1 (Hsync) Width (Typical)*/
  57. #define EPPI_FS1W_HBL 41
  58. /* FS1 (Hsync) Period (Typical) */
  59. #define EPPI_FS1P_AVPL EPPI_LINE
  60. /* Horizontal Delay clock after assertion of Hsync (Typical) */
  61. #define EPPI_HDELAY 43
  62. /* FS2 (Vsync) Width = FS1 (Hsync) Period * 10 */
  63. #define EPPI_FS2W_LVB (EPPI_LINE * 10)
  64. /* FS2 (Vsync) Period = FS1 (Hsync) Period * Lines per Frame */
  65. #define EPPI_FS2P_LAVF (EPPI_LINE * EPPI_FRAME)
  66. /* Vertical Delay after assertion of Vsync (2 Lines) */
  67. #define EPPI_VDELAY 12
  68. #define EPPI_CLIP 0xFF00FF00
  69. /* EPPI Control register configuration value for RGB out
  70. * - EPPI as Output
  71. * GP 2 frame sync mode,
  72. * Internal Clock generation disabled, Internal FS generation enabled,
  73. * Receives samples on EPPI_CLK raising edge, Transmits samples on EPPI_CLK falling edge,
  74. * FS1 & FS2 are active high,
  75. * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out)
  76. * DMA Unpacking disabled when RGB Formating is enabled, otherwise DMA unpacking enabled
  77. * Swapping Enabled,
  78. * One (DMA) Channel Mode,
  79. * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output
  80. * Regular watermark - when FIFO is 100% full,
  81. * Urgent watermark - when FIFO is 75% full
  82. */
  83. #define EPPI_CONTROL (0x20136E2E)
  84. static inline u16 get_eppi_clkdiv(u32 target_ppi_clk)
  85. {
  86. u32 sclk = get_sclk();
  87. /* EPPI_CLK = (SCLK) / (2 * (EPPI_CLKDIV[15:0] + 1)) */
  88. return (((sclk / target_ppi_clk) / 2) - 1);
  89. }
  90. void Init_PPI(void)
  91. {
  92. u16 eppi_clkdiv = get_eppi_clkdiv(LCD_CLK);
  93. bfin_write_EPPI0_FS1W_HBL(EPPI_FS1W_HBL);
  94. bfin_write_EPPI0_FS1P_AVPL(EPPI_FS1P_AVPL);
  95. bfin_write_EPPI0_FS2W_LVB(EPPI_FS2W_LVB);
  96. bfin_write_EPPI0_FS2P_LAVF(EPPI_FS2P_LAVF);
  97. bfin_write_EPPI0_CLIP(EPPI_CLIP);
  98. bfin_write_EPPI0_FRAME(EPPI_FRAME);
  99. bfin_write_EPPI0_LINE(EPPI_LINE);
  100. bfin_write_EPPI0_HCOUNT(EPPI_HCOUNT);
  101. bfin_write_EPPI0_HDELAY(EPPI_HDELAY);
  102. bfin_write_EPPI0_VCOUNT(EPPI_VCOUNT);
  103. bfin_write_EPPI0_VDELAY(EPPI_VDELAY);
  104. bfin_write_EPPI0_CLKDIV(eppi_clkdiv);
  105. /*
  106. * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out)
  107. * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output
  108. */
  109. #if defined(CONFIG_VIDEO_RGB666)
  110. bfin_write_EPPI0_CONTROL((EPPI_CONTROL & ~DLENGTH) | DLEN_18 |
  111. RGB_FMT_EN);
  112. #else
  113. bfin_write_EPPI0_CONTROL(((EPPI_CONTROL & ~DLENGTH) | DLEN_24) &
  114. ~RGB_FMT_EN);
  115. #endif
  116. }
  117. #define DEB2_URGENT 0x2000 /* DEB2 Urgent */
  118. void Init_DMA(void *dst)
  119. {
  120. #if defined(CONFIG_DEB_DMA_URGENT)
  121. *pEBIU_DDRQUE |= DEB2_URGENT;
  122. #endif
  123. *pDMA12_START_ADDR = dst;
  124. /* X count */
  125. *pDMA12_X_COUNT = (LCD_X_RES * LCD_BPP) / DMA_BUS_SIZE;
  126. *pDMA12_X_MODIFY = DMA_BUS_SIZE / 8;
  127. /* Y count */
  128. *pDMA12_Y_COUNT = LCD_Y_RES;
  129. *pDMA12_Y_MODIFY = DMA_BUS_SIZE / 8;
  130. /* DMA Config */
  131. *pDMA12_CONFIG =
  132. WDSIZE_32 | /* 32 bit DMA */
  133. DMA2D | /* 2D DMA */
  134. FLOW_AUTO; /* autobuffer mode */
  135. }
  136. void Init_Ports(void)
  137. {
  138. *pPORTF_MUX = 0x00000000;
  139. *pPORTF_FER |= 0xFFFF; /* PPI0..15 */
  140. *pPORTG_MUX &= ~(PORT_x_MUX_0_MASK | PORT_x_MUX_1_MASK | PORT_x_MUX_2_MASK | PORT_x_MUX_3_MASK | PORT_x_MUX_4_MASK);
  141. *pPORTG_FER |= PG0 | PG1 | PG2 | PG3 | PG4; /* CLK, FS1, FS2, PPI16..17 */
  142. #if !defined(CONFIG_VIDEO_RGB666)
  143. *pPORTD_MUX &= ~(PORT_x_MUX_0_MASK | PORT_x_MUX_1_MASK | PORT_x_MUX_2_MASK | PORT_x_MUX_3_MASK | PORT_x_MUX_4_MASK | PORT_x_MUX_5_MASK);
  144. *pPORTD_MUX |= (PORT_x_MUX_0_FUNC_4 | PORT_x_MUX_1_FUNC_4 | PORT_x_MUX_2_FUNC_4 | PORT_x_MUX_3_FUNC_4 | PORT_x_MUX_4_FUNC_4 | PORT_x_MUX_5_FUNC_4);
  145. *pPORTD_FER |= PD0 | PD1 | PD2 | PD3 | PD4 | PD5; /* PPI18..23 */
  146. #endif
  147. *pPORTE_FER &= ~PE3; /* DISP */
  148. *pPORTE_DIR_SET = PE3;
  149. *pPORTE_SET = PE3;
  150. }
  151. void EnableDMA(void)
  152. {
  153. *pDMA12_CONFIG |= DMAEN;
  154. }
  155. void DisableDMA(void)
  156. {
  157. *pDMA12_CONFIG &= ~DMAEN;
  158. }
  159. /* enable and disable PPI functions */
  160. void EnablePPI(void)
  161. {
  162. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN);
  163. }
  164. void DisablePPI(void)
  165. {
  166. bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN);
  167. }
  168. int video_init(void *dst)
  169. {
  170. Init_Ports();
  171. Init_DMA(dst);
  172. EnableDMA();
  173. Init_PPI();
  174. EnablePPI();
  175. return 0;
  176. }
  177. static void dma_bitblit(void *dst, fastimage_t *logo, int x, int y)
  178. {
  179. if (dcache_status())
  180. blackfin_dcache_flush_range(logo->data, logo->data + logo->size);
  181. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  182. /* Setup destination start address */
  183. bfin_write_MDMA_D0_START_ADDR(dst + ((x & -2) * LCD_PIXEL_SIZE)
  184. + (y * LCD_X_RES * LCD_PIXEL_SIZE));
  185. /* Setup destination xcount */
  186. bfin_write_MDMA_D0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
  187. /* Setup destination xmodify */
  188. bfin_write_MDMA_D0_X_MODIFY(DMA_SIZE16);
  189. /* Setup destination ycount */
  190. bfin_write_MDMA_D0_Y_COUNT(logo->height);
  191. /* Setup destination ymodify */
  192. bfin_write_MDMA_D0_Y_MODIFY((LCD_X_RES - logo->width) * LCD_PIXEL_SIZE + DMA_SIZE16);
  193. /* Setup Source start address */
  194. bfin_write_MDMA_S0_START_ADDR(logo->data);
  195. /* Setup Source xcount */
  196. bfin_write_MDMA_S0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
  197. /* Setup Source xmodify */
  198. bfin_write_MDMA_S0_X_MODIFY(DMA_SIZE16);
  199. /* Setup Source ycount */
  200. bfin_write_MDMA_S0_Y_COUNT(logo->height);
  201. /* Setup Source ymodify */
  202. bfin_write_MDMA_S0_Y_MODIFY(DMA_SIZE16);
  203. /* Enable source DMA */
  204. bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16 | DMA2D);
  205. SSYNC();
  206. bfin_write_MDMA_D0_CONFIG(WNR | DMAEN | WDSIZE_16 | DMA2D);
  207. while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN);
  208. bfin_write_MDMA_S0_IRQ_STATUS(bfin_read_MDMA_S0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
  209. bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
  210. }
  211. void video_putc(const char c)
  212. {
  213. }
  214. void video_puts(const char *s)
  215. {
  216. }
  217. int drv_video_init(void)
  218. {
  219. int error, devices = 1;
  220. device_t videodev;
  221. u8 *dst;
  222. u32 fbmem_size = LCD_X_RES * LCD_Y_RES * LCD_PIXEL_SIZE + ACTIVE_VIDEO_MEM_OFFSET;
  223. dst = malloc(fbmem_size);
  224. if (dst == NULL) {
  225. printf("Failed to alloc FB memory\n");
  226. return -1;
  227. }
  228. #ifdef EASYLOGO_ENABLE_GZIP
  229. unsigned char *data = EASYLOGO_DECOMP_BUFFER;
  230. unsigned long src_len = EASYLOGO_ENABLE_GZIP;
  231. if (gunzip(data, bfin_logo.size, bfin_logo.data, &src_len)) {
  232. puts("Failed to decompress logo\n");
  233. free(dst);
  234. return -1;
  235. }
  236. bfin_logo.data = data;
  237. #endif
  238. memset(dst + ACTIVE_VIDEO_MEM_OFFSET, bfin_logo.data[0], fbmem_size - ACTIVE_VIDEO_MEM_OFFSET);
  239. dma_bitblit(dst + ACTIVE_VIDEO_MEM_OFFSET, &bfin_logo,
  240. (LCD_X_RES - bfin_logo.width) / 2,
  241. (LCD_Y_RES - bfin_logo.height) / 2);
  242. video_init(dst); /* Video initialization */
  243. memset(&videodev, 0, sizeof(videodev));
  244. strcpy(videodev.name, "video");
  245. videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
  246. videodev.flags = DEV_FLAGS_SYSTEM; /* No Output */
  247. videodev.putc = video_putc; /* 'putc' function */
  248. videodev.puts = video_puts; /* 'puts' function */
  249. error = device_register(&videodev);
  250. return (error == 0) ? devices : error;
  251. }