lcd.c 18 KB

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