lcd.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  1. /*
  2. * Common LCD routines for supported CPUs
  3. *
  4. * (C) Copyright 2001-2002
  5. * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. /************************************************************************/
  10. /* ** HEADER FILES */
  11. /************************************************************************/
  12. /* #define DEBUG */
  13. #include <config.h>
  14. #include <common.h>
  15. #include <command.h>
  16. #include <stdarg.h>
  17. #include <search.h>
  18. #include <env_callback.h>
  19. #include <linux/types.h>
  20. #include <stdio_dev.h>
  21. #if defined(CONFIG_POST)
  22. #include <post.h>
  23. #endif
  24. #include <lcd.h>
  25. #include <watchdog.h>
  26. #include <asm/unaligned.h>
  27. #include <splash.h>
  28. #include <asm/io.h>
  29. #include <asm/unaligned.h>
  30. #include <fdt_support.h>
  31. #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
  32. defined(CONFIG_CPU_MONAHANS)
  33. #include <asm/byteorder.h>
  34. #endif
  35. #if defined(CONFIG_MPC823)
  36. #include <lcdvideo.h>
  37. #endif
  38. #if defined(CONFIG_ATMEL_LCD)
  39. #include <atmel_lcdc.h>
  40. #endif
  41. #if defined(CONFIG_LCD_DT_SIMPLEFB)
  42. #include <libfdt.h>
  43. #endif
  44. /************************************************************************/
  45. /* ** FONT DATA */
  46. /************************************************************************/
  47. #include <video_font.h> /* Get font data, width and height */
  48. /************************************************************************/
  49. /* ** LOGO DATA */
  50. /************************************************************************/
  51. #ifdef CONFIG_LCD_LOGO
  52. # include <bmp_logo.h> /* Get logo data, width and height */
  53. # include <bmp_logo_data.h>
  54. # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
  55. # error Default Color Map overlaps with Logo Color Map
  56. # endif
  57. #endif
  58. #ifdef CONFIG_SANDBOX
  59. #include <asm/sdl.h>
  60. #endif
  61. #ifndef CONFIG_LCD_ALIGNMENT
  62. #define CONFIG_LCD_ALIGNMENT PAGE_SIZE
  63. #endif
  64. #if (LCD_BPP != LCD_COLOR8) && (LCD_BPP != LCD_COLOR16) && \
  65. (LCD_BPP != LCD_COLOR32)
  66. # error Unsupported LCD BPP.
  67. #endif
  68. DECLARE_GLOBAL_DATA_PTR;
  69. static int lcd_init(void *lcdbase);
  70. static void *lcd_logo(void);
  71. static void lcd_setfgcolor(int color);
  72. static void lcd_setbgcolor(int color);
  73. static int lcd_color_fg;
  74. static int lcd_color_bg;
  75. int lcd_line_length;
  76. char lcd_is_enabled = 0;
  77. static void *lcd_base; /* Start of framebuffer memory */
  78. static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
  79. /************************************************************************/
  80. /* Flush LCD activity to the caches */
  81. void lcd_sync(void)
  82. {
  83. /*
  84. * flush_dcache_range() is declared in common.h but it seems that some
  85. * architectures do not actually implement it. Is there a way to find
  86. * out whether it exists? For now, ARM is safe.
  87. */
  88. #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
  89. int line_length;
  90. if (lcd_flush_dcache)
  91. flush_dcache_range((u32)lcd_base,
  92. (u32)(lcd_base + lcd_get_size(&line_length)));
  93. #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
  94. static ulong last_sync;
  95. if (get_timer(last_sync) > 10) {
  96. sandbox_sdl_sync(lcd_base);
  97. last_sync = get_timer(0);
  98. }
  99. #endif
  100. }
  101. void lcd_set_flush_dcache(int flush)
  102. {
  103. lcd_flush_dcache = (flush != 0);
  104. }
  105. /*----------------------------------------------------------------------*/
  106. static void lcd_stub_putc(struct stdio_dev *dev, const char c)
  107. {
  108. lcd_putc(c);
  109. }
  110. static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
  111. {
  112. lcd_puts(s);
  113. }
  114. /************************************************************************/
  115. /** Small utility to check that you got the colours right */
  116. /************************************************************************/
  117. #ifdef LCD_TEST_PATTERN
  118. #define N_BLK_VERT 2
  119. #define N_BLK_HOR 3
  120. static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
  121. CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
  122. CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
  123. };
  124. static void test_pattern(void)
  125. {
  126. ushort v_max = panel_info.vl_row;
  127. ushort h_max = panel_info.vl_col;
  128. ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
  129. ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
  130. ushort v, h;
  131. uchar *pix = (uchar *)lcd_base;
  132. printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
  133. h_max, v_max, h_step, v_step);
  134. /* WARNING: Code silently assumes 8bit/pixel */
  135. for (v = 0; v < v_max; ++v) {
  136. uchar iy = v / v_step;
  137. for (h = 0; h < h_max; ++h) {
  138. uchar ix = N_BLK_HOR * iy + h / h_step;
  139. *pix++ = test_colors[ix];
  140. }
  141. }
  142. }
  143. #endif /* LCD_TEST_PATTERN */
  144. /************************************************************************/
  145. /* ** GENERIC Initialization Routines */
  146. /************************************************************************/
  147. /*
  148. * With most lcd drivers the line length is set up
  149. * by calculating it from panel_info parameters. Some
  150. * drivers need to calculate the line length differently,
  151. * so make the function weak to allow overriding it.
  152. */
  153. __weak int lcd_get_size(int *line_length)
  154. {
  155. *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
  156. return *line_length * panel_info.vl_row;
  157. }
  158. int drv_lcd_init(void)
  159. {
  160. struct stdio_dev lcddev;
  161. int rc;
  162. lcd_base = map_sysmem(gd->fb_base, 0);
  163. lcd_init(lcd_base); /* LCD initialization */
  164. /* Device initialization */
  165. memset(&lcddev, 0, sizeof(lcddev));
  166. strcpy(lcddev.name, "lcd");
  167. lcddev.ext = 0; /* No extensions */
  168. lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
  169. lcddev.putc = lcd_stub_putc; /* 'putc' function */
  170. lcddev.puts = lcd_stub_puts; /* 'puts' function */
  171. rc = stdio_register(&lcddev);
  172. return (rc == 0) ? 1 : rc;
  173. }
  174. /*----------------------------------------------------------------------*/
  175. void lcd_clear(void)
  176. {
  177. short console_rows, console_cols;
  178. int bg_color;
  179. #if LCD_BPP == LCD_COLOR8
  180. /* Setting the palette */
  181. lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
  182. lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
  183. lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
  184. lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
  185. lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
  186. lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
  187. lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
  188. lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
  189. lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
  190. #endif
  191. #ifndef CONFIG_SYS_WHITE_ON_BLACK
  192. lcd_setfgcolor(CONSOLE_COLOR_BLACK);
  193. lcd_setbgcolor(CONSOLE_COLOR_WHITE);
  194. bg_color = CONSOLE_COLOR_WHITE;
  195. #else
  196. lcd_setfgcolor(CONSOLE_COLOR_WHITE);
  197. lcd_setbgcolor(CONSOLE_COLOR_BLACK);
  198. bg_color = CONSOLE_COLOR_BLACK;
  199. #endif /* CONFIG_SYS_WHITE_ON_BLACK */
  200. #ifdef LCD_TEST_PATTERN
  201. test_pattern();
  202. #else
  203. /* set framebuffer to background color */
  204. #if (LCD_BPP != LCD_COLOR32)
  205. memset((char *)lcd_base, bg_color, lcd_line_length * panel_info.vl_row);
  206. #else
  207. u32 *ppix = lcd_base;
  208. u32 i;
  209. for (i = 0;
  210. i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
  211. i++) {
  212. *ppix++ = bg_color;
  213. }
  214. #endif
  215. #endif
  216. /* Paint the logo and retrieve LCD base address */
  217. debug("[LCD] Drawing the logo...\n");
  218. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  219. console_rows = (panel_info.vl_row - BMP_LOGO_HEIGHT);
  220. console_rows /= VIDEO_FONT_HEIGHT;
  221. #else
  222. console_rows = panel_info.vl_row / VIDEO_FONT_HEIGHT;
  223. #endif
  224. console_cols = panel_info.vl_col / VIDEO_FONT_WIDTH;
  225. lcd_init_console(lcd_base, console_rows, console_cols);
  226. lcd_init_console(lcd_logo(), console_rows, console_cols);
  227. lcd_sync();
  228. }
  229. static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
  230. char *const argv[])
  231. {
  232. lcd_clear();
  233. return 0;
  234. }
  235. U_BOOT_CMD(
  236. cls, 1, 1, do_lcd_clear,
  237. "clear screen",
  238. ""
  239. );
  240. /*----------------------------------------------------------------------*/
  241. static int lcd_init(void *lcdbase)
  242. {
  243. /* Initialize the lcd controller */
  244. debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
  245. lcd_ctrl_init(lcdbase);
  246. /*
  247. * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
  248. * the 'lcdbase' argument and uses custom lcd base address
  249. * by setting up gd->fb_base. Check for this condition and fixup
  250. * 'lcd_base' address.
  251. */
  252. if (map_to_sysmem(lcdbase) != gd->fb_base)
  253. lcd_base = map_sysmem(gd->fb_base, 0);
  254. debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
  255. lcd_get_size(&lcd_line_length);
  256. lcd_is_enabled = 1;
  257. lcd_clear();
  258. lcd_enable();
  259. /* Initialize the console */
  260. lcd_set_col(0);
  261. #ifdef CONFIG_LCD_INFO_BELOW_LOGO
  262. lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT);
  263. #else
  264. lcd_set_row(1); /* leave 1 blank line below logo */
  265. #endif
  266. return 0;
  267. }
  268. /************************************************************************/
  269. /* ** ROM capable initialization part - needed to reserve FB memory */
  270. /************************************************************************/
  271. /*
  272. * This is called early in the system initialization to grab memory
  273. * for the LCD controller.
  274. * Returns new address for monitor, after reserving LCD buffer memory
  275. *
  276. * Note that this is running from ROM, so no write access to global data.
  277. */
  278. ulong lcd_setmem(ulong addr)
  279. {
  280. ulong size;
  281. int line_length;
  282. debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
  283. panel_info.vl_row, NBITS(panel_info.vl_bpix));
  284. size = lcd_get_size(&line_length);
  285. /* Round up to nearest full page, or MMU section if defined */
  286. size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
  287. addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
  288. /* Allocate pages for the frame buffer. */
  289. addr -= size;
  290. debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
  291. size >> 10, addr);
  292. return addr;
  293. }
  294. /*----------------------------------------------------------------------*/
  295. static void lcd_setfgcolor(int color)
  296. {
  297. lcd_color_fg = color;
  298. }
  299. int lcd_getfgcolor(void)
  300. {
  301. return lcd_color_fg;
  302. }
  303. /*----------------------------------------------------------------------*/
  304. static void lcd_setbgcolor(int color)
  305. {
  306. lcd_color_bg = color;
  307. }
  308. int lcd_getbgcolor(void)
  309. {
  310. return lcd_color_bg;
  311. }
  312. /************************************************************************/
  313. /* ** Chipset depending Bitmap / Logo stuff... */
  314. /************************************************************************/
  315. #ifdef CONFIG_LCD_LOGO
  316. __weak void lcd_logo_set_cmap(void)
  317. {
  318. }
  319. void bitmap_plot(int x, int y)
  320. {
  321. ushort *cmap = (ushort *)bmp_logo_palette;
  322. ushort i, j;
  323. uchar *bmap;
  324. uchar *fb;
  325. ushort *fb16;
  326. #if defined(CONFIG_MPC823)
  327. immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  328. cpm8xx_t *cp = &(immr->im_cpm);
  329. #endif
  330. unsigned bpix = NBITS(panel_info.vl_bpix);
  331. debug("Logo: width %d height %d colors %d cmap %d\n",
  332. BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
  333. ARRAY_SIZE(bmp_logo_palette));
  334. bmap = &bmp_logo_bitmap[0];
  335. fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
  336. if (bpix < 12) {
  337. /* Leave room for default color map
  338. * default case: generic system with no cmap (most likely 16bpp)
  339. * cmap was set to the source palette, so no change is done.
  340. * This avoids even more ifdefs in the next stanza
  341. */
  342. #if defined(CONFIG_MPC823)
  343. cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
  344. #else
  345. cmap = configuration_get_cmap();
  346. #endif
  347. WATCHDOG_RESET();
  348. /* Set color map */
  349. #ifdef CONFIG_ATMEL_LCD
  350. lcd_logo_set_cmap();
  351. #else
  352. for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
  353. ushort colreg = bmp_logo_palette[i];
  354. *cmap++ = colreg;
  355. }
  356. #endif
  357. WATCHDOG_RESET();
  358. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  359. memcpy(fb, bmap, BMP_LOGO_WIDTH);
  360. bmap += BMP_LOGO_WIDTH;
  361. fb += panel_info.vl_col;
  362. }
  363. }
  364. else { /* true color mode */
  365. u16 col16;
  366. fb16 = (ushort *)fb;
  367. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  368. for (j = 0; j < BMP_LOGO_WIDTH; j++) {
  369. col16 = bmp_logo_palette[(bmap[j]-16)];
  370. fb16[j] =
  371. ((col16 & 0x000F) << 1) |
  372. ((col16 & 0x00F0) << 3) |
  373. ((col16 & 0x0F00) << 4);
  374. }
  375. bmap += BMP_LOGO_WIDTH;
  376. fb16 += panel_info.vl_col;
  377. }
  378. }
  379. WATCHDOG_RESET();
  380. lcd_sync();
  381. }
  382. #else
  383. static inline void bitmap_plot(int x, int y) {}
  384. #endif /* CONFIG_LCD_LOGO */
  385. /*----------------------------------------------------------------------*/
  386. #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  387. /*
  388. * Display the BMP file located at address bmp_image.
  389. * Only uncompressed.
  390. */
  391. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  392. #define BMP_ALIGN_CENTER 0x7FFF
  393. static void splash_align_axis(int *axis, unsigned long panel_size,
  394. unsigned long picture_size)
  395. {
  396. unsigned long panel_picture_delta = panel_size - picture_size;
  397. unsigned long axis_alignment;
  398. if (*axis == BMP_ALIGN_CENTER)
  399. axis_alignment = panel_picture_delta / 2;
  400. else if (*axis < 0)
  401. axis_alignment = panel_picture_delta + *axis + 1;
  402. else
  403. return;
  404. *axis = max(0, (int)axis_alignment);
  405. }
  406. #endif
  407. #ifdef CONFIG_LCD_BMP_RLE8
  408. #define BMP_RLE8_ESCAPE 0
  409. #define BMP_RLE8_EOL 0
  410. #define BMP_RLE8_EOBMP 1
  411. #define BMP_RLE8_DELTA 2
  412. static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
  413. int cnt)
  414. {
  415. while (cnt > 0) {
  416. *(*fbp)++ = cmap[*bmap++];
  417. cnt--;
  418. }
  419. }
  420. static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
  421. {
  422. ushort *fb = *fbp;
  423. int cnt_8copy = cnt >> 3;
  424. cnt -= cnt_8copy << 3;
  425. while (cnt_8copy > 0) {
  426. *fb++ = c;
  427. *fb++ = c;
  428. *fb++ = c;
  429. *fb++ = c;
  430. *fb++ = c;
  431. *fb++ = c;
  432. *fb++ = c;
  433. *fb++ = c;
  434. cnt_8copy--;
  435. }
  436. while (cnt > 0) {
  437. *fb++ = c;
  438. cnt--;
  439. }
  440. *fbp = fb;
  441. }
  442. /*
  443. * Do not call this function directly, must be called from lcd_display_bitmap.
  444. */
  445. static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
  446. int x_off, int y_off)
  447. {
  448. uchar *bmap;
  449. ulong width, height;
  450. ulong cnt, runlen;
  451. int x, y;
  452. int decode = 1;
  453. width = get_unaligned_le32(&bmp->header.width);
  454. height = get_unaligned_le32(&bmp->header.height);
  455. bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
  456. x = 0;
  457. y = height - 1;
  458. while (decode) {
  459. if (bmap[0] == BMP_RLE8_ESCAPE) {
  460. switch (bmap[1]) {
  461. case BMP_RLE8_EOL:
  462. /* end of line */
  463. bmap += 2;
  464. x = 0;
  465. y--;
  466. /* 16bpix, 2-byte per pixel, width should *2 */
  467. fb -= (width * 2 + lcd_line_length);
  468. break;
  469. case BMP_RLE8_EOBMP:
  470. /* end of bitmap */
  471. decode = 0;
  472. break;
  473. case BMP_RLE8_DELTA:
  474. /* delta run */
  475. x += bmap[2];
  476. y -= bmap[3];
  477. /* 16bpix, 2-byte per pixel, x should *2 */
  478. fb = (uchar *) (lcd_base + (y + y_off - 1)
  479. * lcd_line_length + (x + x_off) * 2);
  480. bmap += 4;
  481. break;
  482. default:
  483. /* unencoded run */
  484. runlen = bmap[1];
  485. bmap += 2;
  486. if (y < height) {
  487. if (x < width) {
  488. if (x + runlen > width)
  489. cnt = width - x;
  490. else
  491. cnt = runlen;
  492. draw_unencoded_bitmap(
  493. (ushort **)&fb,
  494. bmap, cmap, cnt);
  495. }
  496. x += runlen;
  497. }
  498. bmap += runlen;
  499. if (runlen & 1)
  500. bmap++;
  501. }
  502. } else {
  503. /* encoded run */
  504. if (y < height) {
  505. runlen = bmap[0];
  506. if (x < width) {
  507. /* aggregate the same code */
  508. while (bmap[0] == 0xff &&
  509. bmap[2] != BMP_RLE8_ESCAPE &&
  510. bmap[1] == bmap[3]) {
  511. runlen += bmap[2];
  512. bmap += 2;
  513. }
  514. if (x + runlen > width)
  515. cnt = width - x;
  516. else
  517. cnt = runlen;
  518. draw_encoded_bitmap((ushort **)&fb,
  519. cmap[bmap[1]], cnt);
  520. }
  521. x += runlen;
  522. }
  523. bmap += 2;
  524. }
  525. }
  526. }
  527. #endif
  528. __weak void fb_put_byte(uchar **fb, uchar **from)
  529. {
  530. *(*fb)++ = *(*from)++;
  531. }
  532. #if defined(CONFIG_BMP_16BPP)
  533. __weak void fb_put_word(uchar **fb, uchar **from)
  534. {
  535. *(*fb)++ = *(*from)++;
  536. *(*fb)++ = *(*from)++;
  537. }
  538. #endif /* CONFIG_BMP_16BPP */
  539. int lcd_display_bitmap(ulong bmp_image, int x, int y)
  540. {
  541. ushort *cmap = NULL;
  542. ushort *cmap_base = NULL;
  543. ushort i, j;
  544. uchar *fb;
  545. bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
  546. uchar *bmap;
  547. ushort padded_width;
  548. unsigned long width, height, byte_width;
  549. unsigned long pwidth = panel_info.vl_col;
  550. unsigned colors, bpix, bmp_bpix;
  551. if (!bmp || !(bmp->header.signature[0] == 'B' &&
  552. bmp->header.signature[1] == 'M')) {
  553. printf("Error: no valid bmp image at %lx\n", bmp_image);
  554. return 1;
  555. }
  556. width = get_unaligned_le32(&bmp->header.width);
  557. height = get_unaligned_le32(&bmp->header.height);
  558. bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
  559. colors = 1 << bmp_bpix;
  560. bpix = NBITS(panel_info.vl_bpix);
  561. if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
  562. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  563. bpix, bmp_bpix);
  564. return 1;
  565. }
  566. /*
  567. * We support displaying 8bpp BMPs on 16bpp LCDs
  568. * and displaying 24bpp BMPs on 32bpp LCDs
  569. * */
  570. if (bpix != bmp_bpix &&
  571. !(bmp_bpix == 8 && bpix == 16) &&
  572. !(bmp_bpix == 24 && bpix == 32)) {
  573. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  574. bpix, get_unaligned_le16(&bmp->header.bit_count));
  575. return 1;
  576. }
  577. debug("Display-bmp: %d x %d with %d colors\n",
  578. (int)width, (int)height, (int)colors);
  579. if (bmp_bpix == 8) {
  580. cmap = configuration_get_cmap();
  581. cmap_base = cmap;
  582. /* Set color map */
  583. for (i = 0; i < colors; ++i) {
  584. bmp_color_table_entry_t cte = bmp->color_table[i];
  585. #if !defined(CONFIG_ATMEL_LCD)
  586. ushort colreg =
  587. ( ((cte.red) << 8) & 0xf800) |
  588. ( ((cte.green) << 3) & 0x07e0) |
  589. ( ((cte.blue) >> 3) & 0x001f) ;
  590. *cmap = colreg;
  591. #if defined(CONFIG_MPC823)
  592. cmap--;
  593. #else
  594. cmap++;
  595. #endif
  596. #else /* CONFIG_ATMEL_LCD */
  597. lcd_setcolreg(i, cte.red, cte.green, cte.blue);
  598. #endif
  599. }
  600. }
  601. padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
  602. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  603. splash_align_axis(&x, pwidth, width);
  604. splash_align_axis(&y, panel_info.vl_row, height);
  605. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  606. if ((x + width) > pwidth)
  607. width = pwidth - x;
  608. if ((y + height) > panel_info.vl_row)
  609. height = panel_info.vl_row - y;
  610. bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
  611. fb = (uchar *)(lcd_base +
  612. (y + height - 1) * lcd_line_length + x * bpix / 8);
  613. switch (bmp_bpix) {
  614. case 1: /* pass through */
  615. case 8: {
  616. #ifdef CONFIG_LCD_BMP_RLE8
  617. u32 compression = get_unaligned_le32(&bmp->header.compression);
  618. if (compression == BMP_BI_RLE8) {
  619. if (bpix != 16) {
  620. /* TODO implement render code for bpix != 16 */
  621. printf("Error: only support 16 bpix");
  622. return 1;
  623. }
  624. lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
  625. break;
  626. }
  627. #endif
  628. if (bpix != 16)
  629. byte_width = width;
  630. else
  631. byte_width = width * 2;
  632. for (i = 0; i < height; ++i) {
  633. WATCHDOG_RESET();
  634. for (j = 0; j < width; j++) {
  635. if (bpix != 16) {
  636. fb_put_byte(&fb, &bmap);
  637. } else {
  638. *(uint16_t *)fb = cmap_base[*(bmap++)];
  639. fb += sizeof(uint16_t) / sizeof(*fb);
  640. }
  641. }
  642. bmap += (padded_width - width);
  643. fb -= byte_width + lcd_line_length;
  644. }
  645. break;
  646. }
  647. #if defined(CONFIG_BMP_16BPP)
  648. case 16:
  649. for (i = 0; i < height; ++i) {
  650. WATCHDOG_RESET();
  651. for (j = 0; j < width; j++)
  652. fb_put_word(&fb, &bmap);
  653. bmap += (padded_width - width) * 2;
  654. fb -= width * 2 + lcd_line_length;
  655. }
  656. break;
  657. #endif /* CONFIG_BMP_16BPP */
  658. #if defined(CONFIG_BMP_24BMP)
  659. case 24:
  660. for (i = 0; i < height; ++i) {
  661. for (j = 0; j < width; j++) {
  662. *(fb++) = *(bmap++);
  663. *(fb++) = *(bmap++);
  664. *(fb++) = *(bmap++);
  665. *(fb++) = 0;
  666. }
  667. fb -= lcd_line_length + width * (bpix / 8);
  668. }
  669. break;
  670. #endif /* CONFIG_BMP_24BMP */
  671. #if defined(CONFIG_BMP_32BPP)
  672. case 32:
  673. for (i = 0; i < height; ++i) {
  674. for (j = 0; j < width; j++) {
  675. *(fb++) = *(bmap++);
  676. *(fb++) = *(bmap++);
  677. *(fb++) = *(bmap++);
  678. *(fb++) = *(bmap++);
  679. }
  680. fb -= lcd_line_length + width * (bpix / 8);
  681. }
  682. break;
  683. #endif /* CONFIG_BMP_32BPP */
  684. default:
  685. break;
  686. };
  687. lcd_sync();
  688. return 0;
  689. }
  690. #endif
  691. static void *lcd_logo(void)
  692. {
  693. #ifdef CONFIG_SPLASH_SCREEN
  694. char *s;
  695. ulong addr;
  696. static int do_splash = 1;
  697. if (do_splash && (s = getenv("splashimage")) != NULL) {
  698. int x = 0, y = 0;
  699. do_splash = 0;
  700. if (splash_screen_prepare())
  701. return (void *)lcd_base;
  702. addr = simple_strtoul (s, NULL, 16);
  703. splash_get_pos(&x, &y);
  704. if (bmp_display(addr, x, y) == 0)
  705. return (void *)lcd_base;
  706. }
  707. #endif /* CONFIG_SPLASH_SCREEN */
  708. bitmap_plot(0, 0);
  709. #ifdef CONFIG_LCD_INFO
  710. lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH);
  711. lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT);
  712. lcd_show_board_info();
  713. #endif /* CONFIG_LCD_INFO */
  714. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  715. return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
  716. #else
  717. return (void *)lcd_base;
  718. #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
  719. }
  720. #ifdef CONFIG_SPLASHIMAGE_GUARD
  721. static int on_splashimage(const char *name, const char *value, enum env_op op,
  722. int flags)
  723. {
  724. ulong addr;
  725. int aligned;
  726. if (op == env_op_delete)
  727. return 0;
  728. addr = simple_strtoul(value, NULL, 16);
  729. /* See README.displaying-bmps */
  730. aligned = (addr % 4 == 2);
  731. if (!aligned) {
  732. printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
  733. return -1;
  734. }
  735. return 0;
  736. }
  737. U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
  738. #endif
  739. int lcd_get_pixel_width(void)
  740. {
  741. return panel_info.vl_col;
  742. }
  743. int lcd_get_pixel_height(void)
  744. {
  745. return panel_info.vl_row;
  746. }
  747. #if defined(CONFIG_LCD_DT_SIMPLEFB)
  748. static int lcd_dt_simplefb_configure_node(void *blob, int off)
  749. {
  750. #if LCD_BPP == LCD_COLOR16
  751. return fdt_setup_simplefb_node(blob, off, gd->fb_base,
  752. panel_info.vl_col, panel_info.vl_row,
  753. panel_info.vl_col * 2, "r5g6b5");
  754. #else
  755. return -1;
  756. #endif
  757. }
  758. int lcd_dt_simplefb_add_node(void *blob)
  759. {
  760. static const char compat[] = "simple-framebuffer";
  761. static const char disabled[] = "disabled";
  762. int off, ret;
  763. off = fdt_add_subnode(blob, 0, "framebuffer");
  764. if (off < 0)
  765. return -1;
  766. ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
  767. if (ret < 0)
  768. return -1;
  769. ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
  770. if (ret < 0)
  771. return -1;
  772. return lcd_dt_simplefb_configure_node(blob, off);
  773. }
  774. int lcd_dt_simplefb_enable_existing_node(void *blob)
  775. {
  776. int off;
  777. off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
  778. if (off < 0)
  779. return -1;
  780. return lcd_dt_simplefb_configure_node(blob, off);
  781. }
  782. #endif