video.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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/portmux.h>
  14. #include <asm/mach-common/bits/dma.h>
  15. #include <spi.h>
  16. #include <linux/types.h>
  17. #include <stdio_dev.h>
  18. #include <asm/mach-common/bits/ppi.h>
  19. #include <asm/mach-common/bits/timer.h>
  20. #define LCD_X_RES 320 /* Horizontal Resolution */
  21. #define LCD_Y_RES 240 /* Vertical Resolution */
  22. #define DMA_BUS_SIZE 16
  23. #ifdef CONFIG_BF527_EZKIT_REV_2_1 /* lq035q1 */
  24. #if !defined(CONFIG_LQ035Q1_USE_RGB888_8_BIT_PPI) && \
  25. !defined(CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI)
  26. # define CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI
  27. #endif
  28. /* Interface 16/18-bit TFT over an 8-bit wide PPI using a
  29. * small Programmable Logic Device (CPLD)
  30. * http://blackfin.uclinux.org/gf/project/stamp/frs/?action=FrsReleaseBrowse&frs_package_id=165
  31. */
  32. #ifdef CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI
  33. #include <asm/bfin_logo_rgb565_230x230.h>
  34. #define LCD_BPP 16 /* Bit Per Pixel */
  35. #define CLOCKS_PPIX 2 /* Clocks per pixel */
  36. #define CPLD_DELAY 3 /* RGB565 pipeline delay */
  37. #endif
  38. #ifdef CONFIG_LQ035Q1_USE_RGB888_8_BIT_PPI
  39. #include <asm/bfin_logo_230x230.h>
  40. #define LCD_BPP 24 /* Bit Per Pixel */
  41. #define CLOCKS_PPIX 3 /* Clocks per pixel */
  42. #define CPLD_DELAY 5 /* RGB888 pipeline delay */
  43. #endif
  44. /*
  45. * HS and VS timing parameters (all in number of PPI clk ticks)
  46. */
  47. #define H_ACTPIX (LCD_X_RES * CLOCKS_PPIX) /* active horizontal pixel */
  48. #define H_PERIOD (336 * CLOCKS_PPIX) /* HS period */
  49. #define H_PULSE (2 * CLOCKS_PPIX) /* HS pulse width */
  50. #define H_START (7 * CLOCKS_PPIX + CPLD_DELAY) /* first valid pixel */
  51. #define U_LINE 4 /* Blanking Lines */
  52. #define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */
  53. #define V_PULSE (2 * CLOCKS_PPIX) /* VS pulse width (1-5 H_PERIODs) */
  54. #define V_PERIOD (H_PERIOD * V_LINES) /* VS period */
  55. #define ACTIVE_VIDEO_MEM_OFFSET ((U_LINE / 2) * LCD_X_RES * (LCD_BPP / 8))
  56. /*
  57. * LCD Modes
  58. */
  59. #define LQ035_RL (0 << 8) /* Right -> Left Scan */
  60. #define LQ035_LR (1 << 8) /* Left -> Right Scan */
  61. #define LQ035_TB (1 << 9) /* Top -> Botton Scan */
  62. #define LQ035_BT (0 << 9) /* Botton -> Top Scan */
  63. #define LQ035_BGR (1 << 11) /* Use BGR format */
  64. #define LQ035_RGB (0 << 11) /* Use RGB format */
  65. #define LQ035_NORM (1 << 13) /* Reversal */
  66. #define LQ035_REV (0 << 13) /* Reversal */
  67. #define LQ035_INDEX 0x74
  68. #define LQ035_DATA 0x76
  69. #define LQ035_DRIVER_OUTPUT_CTL 0x1
  70. #define LQ035_SHUT_CTL 0x11
  71. #define LQ035_DRIVER_OUTPUT_MASK (LQ035_LR | LQ035_TB | LQ035_BGR | LQ035_REV)
  72. #define LQ035_DRIVER_OUTPUT_DEFAULT (0x2AEF & ~LQ035_DRIVER_OUTPUT_MASK)
  73. #define LQ035_SHUT (1 << 0) /* Shutdown */
  74. #define LQ035_ON (0 << 0) /* Shutdown */
  75. #ifndef CONFIG_LQ035Q1_LCD_MODE
  76. #define CONFIG_LQ035Q1_LCD_MODE (LQ035_NORM | LQ035_RL | LQ035_TB | LQ035_BGR)
  77. #endif
  78. #else /* t350mcqb */
  79. #include <asm/bfin_logo_230x230.h>
  80. #define LCD_BPP 24 /* Bit Per Pixel */
  81. #define CLOCKS_PPIX 3 /* Clocks per pixel */
  82. /* HS and VS timing parameters (all in number of PPI clk ticks) */
  83. #define H_ACTPIX (LCD_X_RES * CLOCKS_PPIX) /* active horizontal pixel */
  84. #define H_PERIOD (408 * CLOCKS_PPIX) /* HS period */
  85. #define H_PULSE 90 /* HS pulse width */
  86. #define H_START 204 /* first valid pixel */
  87. #define U_LINE 1 /* Blanking Lines */
  88. #define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */
  89. #define V_PULSE (3 * H_PERIOD) /* VS pulse width (1-5 H_PERIODs) */
  90. #define V_PERIOD (H_PERIOD * V_LINES) /* VS period */
  91. #define ACTIVE_VIDEO_MEM_OFFSET (U_LINE * H_ACTPIX)
  92. #endif
  93. #define LCD_PIXEL_SIZE (LCD_BPP / 8)
  94. #define DMA_SIZE16 2
  95. #define PPI_TX_MODE 0x2
  96. #define PPI_XFER_TYPE_11 0xC
  97. #define PPI_PORT_CFG_01 0x10
  98. #define PPI_PACK_EN 0x80
  99. #define PPI_POLS_1 0x8000
  100. #ifdef CONFIG_BF527_EZKIT_REV_2_1
  101. static struct spi_slave *slave;
  102. static int lq035q1_control(unsigned char reg, unsigned short value)
  103. {
  104. int ret;
  105. u8 regs[3] = {LQ035_INDEX, 0, 0};
  106. u8 data[3] = {LQ035_DATA, 0, 0};
  107. u8 dummy[3];
  108. regs[2] = reg;
  109. data[1] = value >> 8;
  110. data[2] = value & 0xFF;
  111. if (!slave) {
  112. /* FIXME: Verify the max SCK rate */
  113. slave = spi_setup_slave(CONFIG_LQ035Q1_SPI_BUS,
  114. CONFIG_LQ035Q1_SPI_CS, 20000000,
  115. SPI_MODE_3);
  116. if (!slave)
  117. return -1;
  118. }
  119. if (spi_claim_bus(slave))
  120. return -1;
  121. ret = spi_xfer(slave, 24, regs, dummy, SPI_XFER_BEGIN | SPI_XFER_END);
  122. ret |= spi_xfer(slave, 24, data, dummy, SPI_XFER_BEGIN | SPI_XFER_END);
  123. spi_release_bus(slave);
  124. return ret;
  125. }
  126. #endif
  127. /* enable and disable PPI functions */
  128. void EnablePPI(void)
  129. {
  130. bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() | PORT_EN);
  131. }
  132. void DisablePPI(void)
  133. {
  134. bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() & ~PORT_EN);
  135. }
  136. void Init_Ports(void)
  137. {
  138. const unsigned short pins[] = {
  139. P_PPI0_D0, P_PPI0_D1, P_PPI0_D2, P_PPI0_D3, P_PPI0_D4,
  140. P_PPI0_D5, P_PPI0_D6, P_PPI0_D7, P_PPI0_FS2, 0,
  141. };
  142. peripheral_request_list(pins, "lcd");
  143. }
  144. void Init_PPI(void)
  145. {
  146. bfin_write_PPI_DELAY(H_START);
  147. bfin_write_PPI_COUNT(H_ACTPIX - 1);
  148. bfin_write_PPI_FRAME(V_LINES);
  149. /* PPI control, to be replaced with definitions */
  150. bfin_write_PPI_CONTROL(
  151. PPI_TX_MODE | /* output mode , PORT_DIR */
  152. PPI_XFER_TYPE_11 | /* sync mode XFR_TYPE */
  153. PPI_PORT_CFG_01 | /* two frame sync PORT_CFG */
  154. PPI_PACK_EN | /* packing enabled PACK_EN */
  155. PPI_POLS_1 /* faling edge syncs POLS */
  156. );
  157. }
  158. void Init_DMA(void *dst)
  159. {
  160. bfin_write_DMA0_START_ADDR(dst);
  161. /* X count */
  162. bfin_write_DMA0_X_COUNT(H_ACTPIX / 2);
  163. bfin_write_DMA0_X_MODIFY(DMA_BUS_SIZE / 8);
  164. /* Y count */
  165. bfin_write_DMA0_Y_COUNT(V_LINES);
  166. bfin_write_DMA0_Y_MODIFY(DMA_BUS_SIZE / 8);
  167. /* DMA Config */
  168. bfin_write_DMA0_CONFIG(
  169. WDSIZE_16 | /* 16 bit DMA */
  170. DMA2D | /* 2D DMA */
  171. FLOW_AUTO /* autobuffer mode */
  172. );
  173. }
  174. void EnableDMA(void)
  175. {
  176. bfin_write_DMA0_CONFIG(bfin_read_DMA0_CONFIG() | DMAEN);
  177. }
  178. void DisableDMA(void)
  179. {
  180. bfin_write_DMA0_CONFIG(bfin_read_DMA0_CONFIG() & ~DMAEN);
  181. }
  182. /* Init TIMER0 as Frame Sync 1 generator */
  183. void InitTIMER0(void)
  184. {
  185. bfin_write_TIMER_DISABLE(TIMDIS0); /* disable Timer */
  186. SSYNC();
  187. bfin_write_TIMER_STATUS(TIMIL0 | TOVF_ERR0 | TRUN0); /* clear status */
  188. SSYNC();
  189. bfin_write_TIMER0_PERIOD(H_PERIOD);
  190. SSYNC();
  191. bfin_write_TIMER0_WIDTH(H_PULSE);
  192. SSYNC();
  193. bfin_write_TIMER0_CONFIG(
  194. PWM_OUT |
  195. PERIOD_CNT |
  196. TIN_SEL |
  197. CLK_SEL |
  198. EMU_RUN
  199. );
  200. SSYNC();
  201. }
  202. void EnableTIMER0(void)
  203. {
  204. bfin_write_TIMER_ENABLE(TIMEN0);
  205. SSYNC();
  206. }
  207. void DisableTIMER0(void)
  208. {
  209. bfin_write_TIMER_DISABLE(TIMDIS0);
  210. SSYNC();
  211. }
  212. void InitTIMER1(void)
  213. {
  214. bfin_write_TIMER_DISABLE(TIMDIS1); /* disable Timer */
  215. SSYNC();
  216. bfin_write_TIMER_STATUS(TIMIL1 | TOVF_ERR1 | TRUN1); /* clear status */
  217. SSYNC();
  218. bfin_write_TIMER1_PERIOD(V_PERIOD);
  219. SSYNC();
  220. bfin_write_TIMER1_WIDTH(V_PULSE);
  221. SSYNC();
  222. bfin_write_TIMER1_CONFIG(
  223. PWM_OUT |
  224. PERIOD_CNT |
  225. TIN_SEL |
  226. CLK_SEL |
  227. EMU_RUN
  228. );
  229. SSYNC();
  230. }
  231. void EnableTIMER1(void)
  232. {
  233. bfin_write_TIMER_ENABLE(TIMEN1);
  234. SSYNC();
  235. }
  236. void DisableTIMER1(void)
  237. {
  238. bfin_write_TIMER_DISABLE(TIMDIS1);
  239. SSYNC();
  240. }
  241. void EnableTIMER12(void)
  242. {
  243. bfin_write_TIMER_ENABLE(TIMEN1 | TIMEN0);
  244. SSYNC();
  245. }
  246. int video_init(void *dst)
  247. {
  248. #ifdef CONFIG_BF527_EZKIT_REV_2_1
  249. lq035q1_control(LQ035_SHUT_CTL, LQ035_ON);
  250. lq035q1_control(LQ035_DRIVER_OUTPUT_CTL, (CONFIG_LQ035Q1_LCD_MODE &
  251. LQ035_DRIVER_OUTPUT_MASK) | LQ035_DRIVER_OUTPUT_DEFAULT);
  252. #endif
  253. Init_Ports();
  254. Init_DMA(dst);
  255. EnableDMA();
  256. InitTIMER0();
  257. InitTIMER1();
  258. Init_PPI();
  259. EnablePPI();
  260. #ifdef CONFIG_BF527_EZKIT_REV_2_1
  261. EnableTIMER12();
  262. #else
  263. /* Frame sync 2 (VS) needs to start at least one PPI clk earlier */
  264. EnableTIMER1();
  265. /* Add Some Delay ... */
  266. SSYNC();
  267. SSYNC();
  268. SSYNC();
  269. SSYNC();
  270. /* now start frame sync 1 */
  271. EnableTIMER0();
  272. #endif
  273. return 0;
  274. }
  275. static void dma_bitblit(void *dst, fastimage_t *logo, int x, int y)
  276. {
  277. if (dcache_status())
  278. blackfin_dcache_flush_range(logo->data, logo->data + logo->size);
  279. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  280. /* Setup destination start address */
  281. bfin_write_MDMA_D0_START_ADDR(dst + ((x & -2) * LCD_PIXEL_SIZE)
  282. + (y * LCD_X_RES * LCD_PIXEL_SIZE));
  283. /* Setup destination xcount */
  284. bfin_write_MDMA_D0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
  285. /* Setup destination xmodify */
  286. bfin_write_MDMA_D0_X_MODIFY(DMA_SIZE16);
  287. /* Setup destination ycount */
  288. bfin_write_MDMA_D0_Y_COUNT(logo->height);
  289. /* Setup destination ymodify */
  290. bfin_write_MDMA_D0_Y_MODIFY((LCD_X_RES - logo->width) * LCD_PIXEL_SIZE + DMA_SIZE16);
  291. /* Setup Source start address */
  292. bfin_write_MDMA_S0_START_ADDR(logo->data);
  293. /* Setup Source xcount */
  294. bfin_write_MDMA_S0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
  295. /* Setup Source xmodify */
  296. bfin_write_MDMA_S0_X_MODIFY(DMA_SIZE16);
  297. /* Setup Source ycount */
  298. bfin_write_MDMA_S0_Y_COUNT(logo->height);
  299. /* Setup Source ymodify */
  300. bfin_write_MDMA_S0_Y_MODIFY(DMA_SIZE16);
  301. /* Enable source DMA */
  302. bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16 | DMA2D);
  303. SSYNC();
  304. bfin_write_MDMA_D0_CONFIG(WNR | DMAEN | WDSIZE_16 | DMA2D);
  305. while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN);
  306. bfin_write_MDMA_S0_IRQ_STATUS(bfin_read_MDMA_S0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
  307. bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
  308. }
  309. void video_stop(void)
  310. {
  311. DisablePPI();
  312. DisableDMA();
  313. DisableTIMER0();
  314. DisableTIMER1();
  315. #ifdef CONFIG_BF527_EZKIT_REV_2_1
  316. lq035q1_control(LQ035_SHUT_CTL, LQ035_SHUT);
  317. #endif
  318. }
  319. void video_putc(const char c)
  320. {
  321. }
  322. void video_puts(const char *s)
  323. {
  324. }
  325. int drv_video_init(void)
  326. {
  327. int error, devices = 1;
  328. struct stdio_dev videodev;
  329. u8 *dst;
  330. u32 fbmem_size = LCD_X_RES * LCD_Y_RES * LCD_PIXEL_SIZE + ACTIVE_VIDEO_MEM_OFFSET;
  331. dst = malloc(fbmem_size);
  332. if (dst == NULL) {
  333. printf("Failed to alloc FB memory\n");
  334. return -1;
  335. }
  336. #ifdef EASYLOGO_ENABLE_GZIP
  337. unsigned char *data = EASYLOGO_DECOMP_BUFFER;
  338. unsigned long src_len = EASYLOGO_ENABLE_GZIP;
  339. if (gunzip(data, bfin_logo.size, bfin_logo.data, &src_len)) {
  340. puts("Failed to decompress logo\n");
  341. free(dst);
  342. return -1;
  343. }
  344. bfin_logo.data = data;
  345. #endif
  346. memset(dst + ACTIVE_VIDEO_MEM_OFFSET, bfin_logo.data[0], fbmem_size - ACTIVE_VIDEO_MEM_OFFSET);
  347. dma_bitblit(dst + ACTIVE_VIDEO_MEM_OFFSET, &bfin_logo,
  348. (LCD_X_RES - bfin_logo.width) / 2,
  349. (LCD_Y_RES - bfin_logo.height) / 2);
  350. video_init(dst); /* Video initialization */
  351. memset(&videodev, 0, sizeof(videodev));
  352. strcpy(videodev.name, "video");
  353. videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
  354. videodev.flags = DEV_FLAGS_SYSTEM; /* No Output */
  355. videodev.putc = video_putc; /* 'putc' function */
  356. videodev.puts = video_puts; /* 'puts' function */
  357. error = stdio_register(&videodev);
  358. return (error == 0) ? devices : error;
  359. }