lcd.c 17 KB

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