lcd.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  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. int i;
  319. ushort *cmap = configuration_get_cmap();
  320. for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i)
  321. *cmap++ = bmp_logo_palette[i];
  322. }
  323. void bitmap_plot(int x, int y)
  324. {
  325. ushort i, j;
  326. uchar *bmap;
  327. uchar *fb;
  328. ushort *fb16;
  329. unsigned bpix = NBITS(panel_info.vl_bpix);
  330. debug("Logo: width %d height %d colors %d\n",
  331. BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS);
  332. bmap = &bmp_logo_bitmap[0];
  333. fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
  334. if (bpix < 12) {
  335. WATCHDOG_RESET();
  336. lcd_logo_set_cmap();
  337. WATCHDOG_RESET();
  338. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  339. memcpy(fb, bmap, BMP_LOGO_WIDTH);
  340. bmap += BMP_LOGO_WIDTH;
  341. fb += panel_info.vl_col;
  342. }
  343. }
  344. else { /* true color mode */
  345. u16 col16;
  346. fb16 = (ushort *)fb;
  347. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  348. for (j = 0; j < BMP_LOGO_WIDTH; j++) {
  349. col16 = bmp_logo_palette[(bmap[j]-16)];
  350. fb16[j] =
  351. ((col16 & 0x000F) << 1) |
  352. ((col16 & 0x00F0) << 3) |
  353. ((col16 & 0x0F00) << 4);
  354. }
  355. bmap += BMP_LOGO_WIDTH;
  356. fb16 += panel_info.vl_col;
  357. }
  358. }
  359. WATCHDOG_RESET();
  360. lcd_sync();
  361. }
  362. #else
  363. static inline void bitmap_plot(int x, int y) {}
  364. #endif /* CONFIG_LCD_LOGO */
  365. /*----------------------------------------------------------------------*/
  366. #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  367. /*
  368. * Display the BMP file located at address bmp_image.
  369. * Only uncompressed.
  370. */
  371. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  372. #define BMP_ALIGN_CENTER 0x7FFF
  373. static void splash_align_axis(int *axis, unsigned long panel_size,
  374. unsigned long picture_size)
  375. {
  376. unsigned long panel_picture_delta = panel_size - picture_size;
  377. unsigned long axis_alignment;
  378. if (*axis == BMP_ALIGN_CENTER)
  379. axis_alignment = panel_picture_delta / 2;
  380. else if (*axis < 0)
  381. axis_alignment = panel_picture_delta + *axis + 1;
  382. else
  383. return;
  384. *axis = max(0, (int)axis_alignment);
  385. }
  386. #endif
  387. #ifdef CONFIG_LCD_BMP_RLE8
  388. #define BMP_RLE8_ESCAPE 0
  389. #define BMP_RLE8_EOL 0
  390. #define BMP_RLE8_EOBMP 1
  391. #define BMP_RLE8_DELTA 2
  392. static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
  393. int cnt)
  394. {
  395. while (cnt > 0) {
  396. *(*fbp)++ = cmap[*bmap++];
  397. cnt--;
  398. }
  399. }
  400. static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
  401. {
  402. ushort *fb = *fbp;
  403. int cnt_8copy = cnt >> 3;
  404. cnt -= cnt_8copy << 3;
  405. while (cnt_8copy > 0) {
  406. *fb++ = c;
  407. *fb++ = c;
  408. *fb++ = c;
  409. *fb++ = c;
  410. *fb++ = c;
  411. *fb++ = c;
  412. *fb++ = c;
  413. *fb++ = c;
  414. cnt_8copy--;
  415. }
  416. while (cnt > 0) {
  417. *fb++ = c;
  418. cnt--;
  419. }
  420. *fbp = fb;
  421. }
  422. /*
  423. * Do not call this function directly, must be called from lcd_display_bitmap.
  424. */
  425. static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
  426. int x_off, int y_off)
  427. {
  428. uchar *bmap;
  429. ulong width, height;
  430. ulong cnt, runlen;
  431. int x, y;
  432. int decode = 1;
  433. width = get_unaligned_le32(&bmp->header.width);
  434. height = get_unaligned_le32(&bmp->header.height);
  435. bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
  436. x = 0;
  437. y = height - 1;
  438. while (decode) {
  439. if (bmap[0] == BMP_RLE8_ESCAPE) {
  440. switch (bmap[1]) {
  441. case BMP_RLE8_EOL:
  442. /* end of line */
  443. bmap += 2;
  444. x = 0;
  445. y--;
  446. /* 16bpix, 2-byte per pixel, width should *2 */
  447. fb -= (width * 2 + lcd_line_length);
  448. break;
  449. case BMP_RLE8_EOBMP:
  450. /* end of bitmap */
  451. decode = 0;
  452. break;
  453. case BMP_RLE8_DELTA:
  454. /* delta run */
  455. x += bmap[2];
  456. y -= bmap[3];
  457. /* 16bpix, 2-byte per pixel, x should *2 */
  458. fb = (uchar *) (lcd_base + (y + y_off - 1)
  459. * lcd_line_length + (x + x_off) * 2);
  460. bmap += 4;
  461. break;
  462. default:
  463. /* unencoded run */
  464. runlen = bmap[1];
  465. bmap += 2;
  466. if (y < height) {
  467. if (x < width) {
  468. if (x + runlen > width)
  469. cnt = width - x;
  470. else
  471. cnt = runlen;
  472. draw_unencoded_bitmap(
  473. (ushort **)&fb,
  474. bmap, cmap, cnt);
  475. }
  476. x += runlen;
  477. }
  478. bmap += runlen;
  479. if (runlen & 1)
  480. bmap++;
  481. }
  482. } else {
  483. /* encoded run */
  484. if (y < height) {
  485. runlen = bmap[0];
  486. if (x < width) {
  487. /* aggregate the same code */
  488. while (bmap[0] == 0xff &&
  489. bmap[2] != BMP_RLE8_ESCAPE &&
  490. bmap[1] == bmap[3]) {
  491. runlen += bmap[2];
  492. bmap += 2;
  493. }
  494. if (x + runlen > width)
  495. cnt = width - x;
  496. else
  497. cnt = runlen;
  498. draw_encoded_bitmap((ushort **)&fb,
  499. cmap[bmap[1]], cnt);
  500. }
  501. x += runlen;
  502. }
  503. bmap += 2;
  504. }
  505. }
  506. }
  507. #endif
  508. __weak void fb_put_byte(uchar **fb, uchar **from)
  509. {
  510. *(*fb)++ = *(*from)++;
  511. }
  512. #if defined(CONFIG_BMP_16BPP)
  513. __weak void fb_put_word(uchar **fb, uchar **from)
  514. {
  515. *(*fb)++ = *(*from)++;
  516. *(*fb)++ = *(*from)++;
  517. }
  518. #endif /* CONFIG_BMP_16BPP */
  519. __weak void lcd_set_cmap(bmp_image_t *bmp, unsigned colors)
  520. {
  521. int i;
  522. bmp_color_table_entry_t cte;
  523. ushort *cmap = configuration_get_cmap();
  524. for (i = 0; i < colors; ++i) {
  525. cte = bmp->color_table[i];
  526. *cmap = (((cte.red) << 8) & 0xf800) |
  527. (((cte.green) << 3) & 0x07e0) |
  528. (((cte.blue) >> 3) & 0x001f);
  529. #if defined(CONFIG_MPC823)
  530. cmap--;
  531. #else
  532. cmap++;
  533. #endif
  534. }
  535. }
  536. int lcd_display_bitmap(ulong bmp_image, int x, int y)
  537. {
  538. ushort *cmap_base = NULL;
  539. ushort i, j;
  540. uchar *fb;
  541. bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
  542. uchar *bmap;
  543. ushort padded_width;
  544. unsigned long width, height, byte_width;
  545. unsigned long pwidth = panel_info.vl_col;
  546. unsigned colors, bpix, bmp_bpix;
  547. if (!bmp || !(bmp->header.signature[0] == 'B' &&
  548. bmp->header.signature[1] == 'M')) {
  549. printf("Error: no valid bmp image at %lx\n", bmp_image);
  550. return 1;
  551. }
  552. width = get_unaligned_le32(&bmp->header.width);
  553. height = get_unaligned_le32(&bmp->header.height);
  554. bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
  555. colors = 1 << bmp_bpix;
  556. bpix = NBITS(panel_info.vl_bpix);
  557. if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
  558. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  559. bpix, bmp_bpix);
  560. return 1;
  561. }
  562. /*
  563. * We support displaying 8bpp BMPs on 16bpp LCDs
  564. * and displaying 24bpp BMPs on 32bpp LCDs
  565. * */
  566. if (bpix != bmp_bpix &&
  567. !(bmp_bpix == 8 && bpix == 16) &&
  568. !(bmp_bpix == 24 && bpix == 32)) {
  569. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  570. bpix, get_unaligned_le16(&bmp->header.bit_count));
  571. return 1;
  572. }
  573. debug("Display-bmp: %d x %d with %d colors\n",
  574. (int)width, (int)height, (int)colors);
  575. if (bmp_bpix == 8)
  576. lcd_set_cmap(bmp, colors);
  577. padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
  578. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  579. splash_align_axis(&x, pwidth, width);
  580. splash_align_axis(&y, panel_info.vl_row, height);
  581. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  582. if ((x + width) > pwidth)
  583. width = pwidth - x;
  584. if ((y + height) > panel_info.vl_row)
  585. height = panel_info.vl_row - y;
  586. bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
  587. fb = (uchar *)(lcd_base +
  588. (y + height - 1) * lcd_line_length + x * bpix / 8);
  589. switch (bmp_bpix) {
  590. case 1: /* pass through */
  591. case 8: {
  592. cmap_base = configuration_get_cmap();
  593. #ifdef CONFIG_LCD_BMP_RLE8
  594. u32 compression = get_unaligned_le32(&bmp->header.compression);
  595. if (compression == BMP_BI_RLE8) {
  596. if (bpix != 16) {
  597. /* TODO implement render code for bpix != 16 */
  598. printf("Error: only support 16 bpix");
  599. return 1;
  600. }
  601. lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
  602. break;
  603. }
  604. #endif
  605. if (bpix != 16)
  606. byte_width = width;
  607. else
  608. byte_width = width * 2;
  609. for (i = 0; i < height; ++i) {
  610. WATCHDOG_RESET();
  611. for (j = 0; j < width; j++) {
  612. if (bpix != 16) {
  613. fb_put_byte(&fb, &bmap);
  614. } else {
  615. *(uint16_t *)fb = cmap_base[*(bmap++)];
  616. fb += sizeof(uint16_t) / sizeof(*fb);
  617. }
  618. }
  619. bmap += (padded_width - width);
  620. fb -= byte_width + lcd_line_length;
  621. }
  622. break;
  623. }
  624. #if defined(CONFIG_BMP_16BPP)
  625. case 16:
  626. for (i = 0; i < height; ++i) {
  627. WATCHDOG_RESET();
  628. for (j = 0; j < width; j++)
  629. fb_put_word(&fb, &bmap);
  630. bmap += (padded_width - width) * 2;
  631. fb -= width * 2 + lcd_line_length;
  632. }
  633. break;
  634. #endif /* CONFIG_BMP_16BPP */
  635. #if defined(CONFIG_BMP_24BMP)
  636. case 24:
  637. for (i = 0; i < height; ++i) {
  638. for (j = 0; j < width; j++) {
  639. *(fb++) = *(bmap++);
  640. *(fb++) = *(bmap++);
  641. *(fb++) = *(bmap++);
  642. *(fb++) = 0;
  643. }
  644. fb -= lcd_line_length + width * (bpix / 8);
  645. }
  646. break;
  647. #endif /* CONFIG_BMP_24BMP */
  648. #if defined(CONFIG_BMP_32BPP)
  649. case 32:
  650. for (i = 0; i < height; ++i) {
  651. for (j = 0; j < width; j++) {
  652. *(fb++) = *(bmap++);
  653. *(fb++) = *(bmap++);
  654. *(fb++) = *(bmap++);
  655. *(fb++) = *(bmap++);
  656. }
  657. fb -= lcd_line_length + width * (bpix / 8);
  658. }
  659. break;
  660. #endif /* CONFIG_BMP_32BPP */
  661. default:
  662. break;
  663. };
  664. lcd_sync();
  665. return 0;
  666. }
  667. #endif
  668. static void *lcd_logo(void)
  669. {
  670. #ifdef CONFIG_SPLASH_SCREEN
  671. char *s;
  672. ulong addr;
  673. static int do_splash = 1;
  674. if (do_splash && (s = getenv("splashimage")) != NULL) {
  675. int x = 0, y = 0;
  676. do_splash = 0;
  677. if (splash_screen_prepare())
  678. return (void *)lcd_base;
  679. addr = simple_strtoul (s, NULL, 16);
  680. splash_get_pos(&x, &y);
  681. if (bmp_display(addr, x, y) == 0)
  682. return (void *)lcd_base;
  683. }
  684. #endif /* CONFIG_SPLASH_SCREEN */
  685. bitmap_plot(0, 0);
  686. #ifdef CONFIG_LCD_INFO
  687. lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH);
  688. lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT);
  689. lcd_show_board_info();
  690. #endif /* CONFIG_LCD_INFO */
  691. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  692. return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
  693. #else
  694. return (void *)lcd_base;
  695. #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
  696. }
  697. #ifdef CONFIG_SPLASHIMAGE_GUARD
  698. static int on_splashimage(const char *name, const char *value, enum env_op op,
  699. int flags)
  700. {
  701. ulong addr;
  702. int aligned;
  703. if (op == env_op_delete)
  704. return 0;
  705. addr = simple_strtoul(value, NULL, 16);
  706. /* See README.displaying-bmps */
  707. aligned = (addr % 4 == 2);
  708. if (!aligned) {
  709. printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
  710. return -1;
  711. }
  712. return 0;
  713. }
  714. U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
  715. #endif
  716. int lcd_get_pixel_width(void)
  717. {
  718. return panel_info.vl_col;
  719. }
  720. int lcd_get_pixel_height(void)
  721. {
  722. return panel_info.vl_row;
  723. }
  724. #if defined(CONFIG_LCD_DT_SIMPLEFB)
  725. static int lcd_dt_simplefb_configure_node(void *blob, int off)
  726. {
  727. #if LCD_BPP == LCD_COLOR16
  728. return fdt_setup_simplefb_node(blob, off, gd->fb_base,
  729. panel_info.vl_col, panel_info.vl_row,
  730. panel_info.vl_col * 2, "r5g6b5");
  731. #else
  732. return -1;
  733. #endif
  734. }
  735. int lcd_dt_simplefb_add_node(void *blob)
  736. {
  737. static const char compat[] = "simple-framebuffer";
  738. static const char disabled[] = "disabled";
  739. int off, ret;
  740. off = fdt_add_subnode(blob, 0, "framebuffer");
  741. if (off < 0)
  742. return -1;
  743. ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
  744. if (ret < 0)
  745. return -1;
  746. ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
  747. if (ret < 0)
  748. return -1;
  749. return lcd_dt_simplefb_configure_node(blob, off);
  750. }
  751. int lcd_dt_simplefb_enable_existing_node(void *blob)
  752. {
  753. int off;
  754. off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
  755. if (off < 0)
  756. return -1;
  757. return lcd_dt_simplefb_configure_node(blob, off);
  758. }
  759. #endif