lcd.c 17 KB

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