lcd.c 21 KB

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