lcd.c 17 KB

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