lcd.c 17 KB

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