video.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 <stdio_dev.h>
  17. #define DMA_SIZE16 2
  18. #include <asm/mach-common/bits/ppi.h>
  19. #include <asm/mach-common/bits/timer.h>
  20. #include <asm/bfin_logo_230x230.h>
  21. #define LCD_X_RES 320 /* Horizontal Resolution */
  22. #define LCD_Y_RES 240 /* Vertical Resolution */
  23. #define LCD_BPP 24 /* Bit Per Pixel */
  24. #define LCD_PIXEL_SIZE (LCD_BPP / 8)
  25. #define DMA_BUS_SIZE 16
  26. #define LCD_CLK (12*1000*1000) /* 12MHz */
  27. #define CLOCKS_PER_PIX 3
  28. /* HS and VS timing parameters (all in number of PPI clk ticks) */
  29. #define H_ACTPIX (LCD_X_RES * CLOCKS_PER_PIX) /* active horizontal pixel */
  30. #define H_PERIOD (408 * CLOCKS_PER_PIX) /* HS period */
  31. #define H_PULSE 90 /* HS pulse width */
  32. #define H_START 204 /* first valid pixel */
  33. #define U_LINE 1 /* Blanking Lines */
  34. #define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */
  35. #define V_PULSE (3 * H_PERIOD) /* VS pulse width (1-5 H_PERIODs) */
  36. #define V_PERIOD (H_PERIOD * V_LINES) /* VS period */
  37. #define ACTIVE_VIDEO_MEM_OFFSET (U_LINE * H_ACTPIX)
  38. #define PPI_TX_MODE 0x2
  39. #define PPI_XFER_TYPE_11 0xC
  40. #define PPI_PORT_CFG_01 0x10
  41. #define PPI_PACK_EN 0x80
  42. #define PPI_POLS_1 0x8000
  43. /* enable and disable PPI functions */
  44. void EnablePPI(void)
  45. {
  46. *pPPI_CONTROL |= PORT_EN;
  47. }
  48. void DisablePPI(void)
  49. {
  50. *pPPI_CONTROL &= ~PORT_EN;
  51. }
  52. void Init_Ports(void)
  53. {
  54. *pPORTF_MUX &= ~PORT_x_MUX_0_MASK;
  55. *pPORTF_MUX |= PORT_x_MUX_0_FUNC_1;
  56. *pPORTF_FER |= PF0 | PF1 | PF2 | PF3 | PF4 | PF5 | PF6 | PF7;
  57. *pPORTG_MUX &= ~PORT_x_MUX_1_MASK;
  58. *pPORTG_MUX |= PORT_x_MUX_1_FUNC_1;
  59. *pPORTG_FER |= PG5;
  60. }
  61. void Init_PPI(void)
  62. {
  63. *pPPI_DELAY = H_START;
  64. *pPPI_COUNT = (H_ACTPIX-1);
  65. *pPPI_FRAME = 0;
  66. /* PPI control, to be replaced with definitions */
  67. *pPPI_CONTROL = PPI_TX_MODE | /* output mode , PORT_DIR */
  68. PPI_XFER_TYPE_11 | /* sync mode XFR_TYPE */
  69. PPI_PORT_CFG_01 | /* two frame sync PORT_CFG */
  70. PPI_PACK_EN | /* packing enabled PACK_EN */
  71. PPI_POLS_1; /* faling edge syncs POLS */
  72. }
  73. void Init_DMA(void *dst)
  74. {
  75. *pDMA0_START_ADDR = dst;
  76. /* X count */
  77. *pDMA0_X_COUNT = H_ACTPIX / 2;
  78. *pDMA0_X_MODIFY = DMA_BUS_SIZE / 8;
  79. /* Y count */
  80. *pDMA0_Y_COUNT = V_LINES;
  81. *pDMA0_Y_MODIFY = DMA_BUS_SIZE / 8;
  82. /* DMA Config */
  83. *pDMA0_CONFIG =
  84. WDSIZE_16 | /* 16 bit DMA */
  85. DMA2D | /* 2D DMA */
  86. FLOW_AUTO; /* autobuffer mode */
  87. }
  88. void EnableDMA(void)
  89. {
  90. *pDMA0_CONFIG |= DMAEN;
  91. }
  92. void DisableDMA(void)
  93. {
  94. *pDMA0_CONFIG &= ~DMAEN;
  95. }
  96. /* Init TIMER0 as Frame Sync 1 generator */
  97. void InitTIMER0(void)
  98. {
  99. *pTIMER_DISABLE |= TIMDIS0; /* disable Timer */
  100. SSYNC();
  101. *pTIMER_STATUS |= TIMIL0 | TOVF_ERR0 | TRUN0; /* clear status */
  102. SSYNC();
  103. *pTIMER0_PERIOD = H_PERIOD;
  104. SSYNC();
  105. *pTIMER0_WIDTH = H_PULSE;
  106. SSYNC();
  107. *pTIMER0_CONFIG = PWM_OUT |
  108. PERIOD_CNT |
  109. TIN_SEL |
  110. CLK_SEL |
  111. EMU_RUN;
  112. SSYNC();
  113. }
  114. void EnableTIMER0(void)
  115. {
  116. *pTIMER_ENABLE |= TIMEN0;
  117. SSYNC();
  118. }
  119. void DisableTIMER0(void)
  120. {
  121. *pTIMER_DISABLE |= TIMDIS0;
  122. SSYNC();
  123. }
  124. void InitTIMER1(void)
  125. {
  126. *pTIMER_DISABLE |= TIMDIS1; /* disable Timer */
  127. SSYNC();
  128. *pTIMER_STATUS |= TIMIL1 | TOVF_ERR1 | TRUN1; /* clear status */
  129. SSYNC();
  130. *pTIMER1_PERIOD = V_PERIOD;
  131. SSYNC();
  132. *pTIMER1_WIDTH = V_PULSE;
  133. SSYNC();
  134. *pTIMER1_CONFIG = PWM_OUT |
  135. PERIOD_CNT |
  136. TIN_SEL |
  137. CLK_SEL |
  138. EMU_RUN;
  139. SSYNC();
  140. }
  141. void EnableTIMER1(void)
  142. {
  143. *pTIMER_ENABLE |= TIMEN1;
  144. SSYNC();
  145. }
  146. void DisableTIMER1(void)
  147. {
  148. *pTIMER_DISABLE |= TIMDIS1;
  149. SSYNC();
  150. }
  151. int video_init(void *dst)
  152. {
  153. Init_Ports();
  154. Init_DMA(dst);
  155. EnableDMA();
  156. InitTIMER0();
  157. InitTIMER1();
  158. Init_PPI();
  159. EnablePPI();
  160. /* Frame sync 2 (VS) needs to start at least one PPI clk earlier */
  161. EnableTIMER1();
  162. /* Add Some Delay ... */
  163. SSYNC();
  164. SSYNC();
  165. SSYNC();
  166. SSYNC();
  167. /* now start frame sync 1 */
  168. EnableTIMER0();
  169. return 0;
  170. }
  171. static void dma_bitblit(void *dst, fastimage_t *logo, int x, int y)
  172. {
  173. if (dcache_status())
  174. blackfin_dcache_flush_range(logo->data, logo->data + logo->size);
  175. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  176. /* Setup destination start address */
  177. bfin_write_MDMA_D0_START_ADDR(dst + ((x & -2) * LCD_PIXEL_SIZE)
  178. + (y * LCD_X_RES * LCD_PIXEL_SIZE));
  179. /* Setup destination xcount */
  180. bfin_write_MDMA_D0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
  181. /* Setup destination xmodify */
  182. bfin_write_MDMA_D0_X_MODIFY(DMA_SIZE16);
  183. /* Setup destination ycount */
  184. bfin_write_MDMA_D0_Y_COUNT(logo->height);
  185. /* Setup destination ymodify */
  186. bfin_write_MDMA_D0_Y_MODIFY((LCD_X_RES - logo->width) * LCD_PIXEL_SIZE + DMA_SIZE16);
  187. /* Setup Source start address */
  188. bfin_write_MDMA_S0_START_ADDR(logo->data);
  189. /* Setup Source xcount */
  190. bfin_write_MDMA_S0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
  191. /* Setup Source xmodify */
  192. bfin_write_MDMA_S0_X_MODIFY(DMA_SIZE16);
  193. /* Setup Source ycount */
  194. bfin_write_MDMA_S0_Y_COUNT(logo->height);
  195. /* Setup Source ymodify */
  196. bfin_write_MDMA_S0_Y_MODIFY(DMA_SIZE16);
  197. /* Enable source DMA */
  198. bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16 | DMA2D);
  199. SSYNC();
  200. bfin_write_MDMA_D0_CONFIG(WNR | DMAEN | WDSIZE_16 | DMA2D);
  201. while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN);
  202. bfin_write_MDMA_S0_IRQ_STATUS(bfin_read_MDMA_S0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
  203. bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
  204. }
  205. void video_putc(const char c)
  206. {
  207. }
  208. void video_puts(const char *s)
  209. {
  210. }
  211. int drv_video_init(void)
  212. {
  213. int error, devices = 1;
  214. struct stdio_dev videodev;
  215. u8 *dst;
  216. u32 fbmem_size = LCD_X_RES * LCD_Y_RES * LCD_PIXEL_SIZE + ACTIVE_VIDEO_MEM_OFFSET;
  217. dst = malloc(fbmem_size);
  218. if (dst == NULL) {
  219. printf("Failed to alloc FB memory\n");
  220. return -1;
  221. }
  222. #ifdef EASYLOGO_ENABLE_GZIP
  223. unsigned char *data = EASYLOGO_DECOMP_BUFFER;
  224. unsigned long src_len = EASYLOGO_ENABLE_GZIP;
  225. if (gunzip(data, bfin_logo.size, bfin_logo.data, &src_len)) {
  226. puts("Failed to decompress logo\n");
  227. free(dst);
  228. return -1;
  229. }
  230. bfin_logo.data = data;
  231. #endif
  232. memset(dst + ACTIVE_VIDEO_MEM_OFFSET, bfin_logo.data[0], fbmem_size - ACTIVE_VIDEO_MEM_OFFSET);
  233. dma_bitblit(dst + ACTIVE_VIDEO_MEM_OFFSET, &bfin_logo,
  234. (LCD_X_RES - bfin_logo.width) / 2,
  235. (LCD_Y_RES - bfin_logo.height) / 2);
  236. video_init(dst); /* Video initialization */
  237. memset(&videodev, 0, sizeof(videodev));
  238. strcpy(videodev.name, "video");
  239. videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
  240. videodev.flags = DEV_FLAGS_SYSTEM; /* No Output */
  241. videodev.putc = video_putc; /* 'putc' function */
  242. videodev.puts = video_puts; /* 'puts' function */
  243. error = stdio_register(&videodev);
  244. return (error == 0) ? devices : error;
  245. }