lcd.c 22 KB

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