lcd.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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_logo(), console_rows, console_cols);
  226. lcd_sync();
  227. }
  228. static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
  229. char *const argv[])
  230. {
  231. lcd_clear();
  232. return 0;
  233. }
  234. U_BOOT_CMD(
  235. cls, 1, 1, do_lcd_clear,
  236. "clear screen",
  237. ""
  238. );
  239. /*----------------------------------------------------------------------*/
  240. static int lcd_init(void *lcdbase)
  241. {
  242. /* Initialize the lcd controller */
  243. debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
  244. lcd_ctrl_init(lcdbase);
  245. /*
  246. * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
  247. * the 'lcdbase' argument and uses custom lcd base address
  248. * by setting up gd->fb_base. Check for this condition and fixup
  249. * 'lcd_base' address.
  250. */
  251. if (map_to_sysmem(lcdbase) != gd->fb_base)
  252. lcd_base = map_sysmem(gd->fb_base, 0);
  253. debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
  254. lcd_get_size(&lcd_line_length);
  255. lcd_is_enabled = 1;
  256. lcd_clear();
  257. lcd_enable();
  258. /* Initialize the console */
  259. lcd_set_col(0);
  260. #ifdef CONFIG_LCD_INFO_BELOW_LOGO
  261. lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT);
  262. #else
  263. lcd_set_row(1); /* leave 1 blank line below logo */
  264. #endif
  265. return 0;
  266. }
  267. /************************************************************************/
  268. /* ** ROM capable initialization part - needed to reserve FB memory */
  269. /************************************************************************/
  270. /*
  271. * This is called early in the system initialization to grab memory
  272. * for the LCD controller.
  273. * Returns new address for monitor, after reserving LCD buffer memory
  274. *
  275. * Note that this is running from ROM, so no write access to global data.
  276. */
  277. ulong lcd_setmem(ulong addr)
  278. {
  279. ulong size;
  280. int line_length;
  281. debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
  282. panel_info.vl_row, NBITS(panel_info.vl_bpix));
  283. size = lcd_get_size(&line_length);
  284. /* Round up to nearest full page, or MMU section if defined */
  285. size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
  286. addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
  287. /* Allocate pages for the frame buffer. */
  288. addr -= size;
  289. debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
  290. size >> 10, addr);
  291. return addr;
  292. }
  293. /*----------------------------------------------------------------------*/
  294. static void lcd_setfgcolor(int color)
  295. {
  296. lcd_color_fg = color;
  297. }
  298. int lcd_getfgcolor(void)
  299. {
  300. return lcd_color_fg;
  301. }
  302. /*----------------------------------------------------------------------*/
  303. static void lcd_setbgcolor(int color)
  304. {
  305. lcd_color_bg = color;
  306. }
  307. int lcd_getbgcolor(void)
  308. {
  309. return lcd_color_bg;
  310. }
  311. /************************************************************************/
  312. /* ** Chipset depending Bitmap / Logo stuff... */
  313. /************************************************************************/
  314. static inline ushort *configuration_get_cmap(void)
  315. {
  316. #if defined CONFIG_CPU_PXA
  317. struct pxafb_info *fbi = &panel_info.pxa;
  318. return (ushort *)fbi->palette;
  319. #elif defined(CONFIG_MPC823)
  320. immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  321. cpm8xx_t *cp = &(immr->im_cpm);
  322. return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
  323. #elif defined(CONFIG_ATMEL_LCD)
  324. return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
  325. #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
  326. return panel_info.cmap;
  327. #elif defined(CONFIG_LCD_LOGO)
  328. return bmp_logo_palette;
  329. #else
  330. return NULL;
  331. #endif
  332. }
  333. #ifdef CONFIG_LCD_LOGO
  334. void bitmap_plot(int x, int y)
  335. {
  336. #ifdef CONFIG_ATMEL_LCD
  337. uint *cmap = (uint *)bmp_logo_palette;
  338. #else
  339. ushort *cmap = (ushort *)bmp_logo_palette;
  340. #endif
  341. ushort i, j;
  342. uchar *bmap;
  343. uchar *fb;
  344. ushort *fb16;
  345. #if defined(CONFIG_MPC823)
  346. immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  347. cpm8xx_t *cp = &(immr->im_cpm);
  348. #endif
  349. unsigned bpix = NBITS(panel_info.vl_bpix);
  350. debug("Logo: width %d height %d colors %d cmap %d\n",
  351. BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
  352. ARRAY_SIZE(bmp_logo_palette));
  353. bmap = &bmp_logo_bitmap[0];
  354. fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
  355. if (bpix < 12) {
  356. /* Leave room for default color map
  357. * default case: generic system with no cmap (most likely 16bpp)
  358. * cmap was set to the source palette, so no change is done.
  359. * This avoids even more ifdefs in the next stanza
  360. */
  361. #if defined(CONFIG_MPC823)
  362. cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
  363. #elif defined(CONFIG_ATMEL_LCD)
  364. cmap = (uint *)configuration_get_cmap();
  365. #else
  366. cmap = configuration_get_cmap();
  367. #endif
  368. WATCHDOG_RESET();
  369. /* Set color map */
  370. for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
  371. ushort colreg = bmp_logo_palette[i];
  372. #ifdef CONFIG_ATMEL_LCD
  373. uint lut_entry;
  374. #ifdef CONFIG_ATMEL_LCD_BGR555
  375. lut_entry = ((colreg & 0x000F) << 11) |
  376. ((colreg & 0x00F0) << 2) |
  377. ((colreg & 0x0F00) >> 7);
  378. #else /* CONFIG_ATMEL_LCD_RGB565 */
  379. lut_entry = ((colreg & 0x000F) << 1) |
  380. ((colreg & 0x00F0) << 3) |
  381. ((colreg & 0x0F00) << 4);
  382. #endif
  383. *(cmap + BMP_LOGO_OFFSET) = lut_entry;
  384. cmap++;
  385. #else /* !CONFIG_ATMEL_LCD */
  386. *cmap++ = colreg;
  387. #endif /* CONFIG_ATMEL_LCD */
  388. }
  389. WATCHDOG_RESET();
  390. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  391. memcpy(fb, bmap, BMP_LOGO_WIDTH);
  392. bmap += BMP_LOGO_WIDTH;
  393. fb += panel_info.vl_col;
  394. }
  395. }
  396. else { /* true color mode */
  397. u16 col16;
  398. fb16 = (ushort *)fb;
  399. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  400. for (j = 0; j < BMP_LOGO_WIDTH; j++) {
  401. col16 = bmp_logo_palette[(bmap[j]-16)];
  402. fb16[j] =
  403. ((col16 & 0x000F) << 1) |
  404. ((col16 & 0x00F0) << 3) |
  405. ((col16 & 0x0F00) << 4);
  406. }
  407. bmap += BMP_LOGO_WIDTH;
  408. fb16 += panel_info.vl_col;
  409. }
  410. }
  411. WATCHDOG_RESET();
  412. lcd_sync();
  413. }
  414. #else
  415. static inline void bitmap_plot(int x, int y) {}
  416. #endif /* CONFIG_LCD_LOGO */
  417. /*----------------------------------------------------------------------*/
  418. #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  419. /*
  420. * Display the BMP file located at address bmp_image.
  421. * Only uncompressed.
  422. */
  423. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  424. #define BMP_ALIGN_CENTER 0x7FFF
  425. static void splash_align_axis(int *axis, unsigned long panel_size,
  426. unsigned long picture_size)
  427. {
  428. unsigned long panel_picture_delta = panel_size - picture_size;
  429. unsigned long axis_alignment;
  430. if (*axis == BMP_ALIGN_CENTER)
  431. axis_alignment = panel_picture_delta / 2;
  432. else if (*axis < 0)
  433. axis_alignment = panel_picture_delta + *axis + 1;
  434. else
  435. return;
  436. *axis = max(0, (int)axis_alignment);
  437. }
  438. #endif
  439. #ifdef CONFIG_LCD_BMP_RLE8
  440. #define BMP_RLE8_ESCAPE 0
  441. #define BMP_RLE8_EOL 0
  442. #define BMP_RLE8_EOBMP 1
  443. #define BMP_RLE8_DELTA 2
  444. static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
  445. int cnt)
  446. {
  447. while (cnt > 0) {
  448. *(*fbp)++ = cmap[*bmap++];
  449. cnt--;
  450. }
  451. }
  452. static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
  453. {
  454. ushort *fb = *fbp;
  455. int cnt_8copy = cnt >> 3;
  456. cnt -= cnt_8copy << 3;
  457. while (cnt_8copy > 0) {
  458. *fb++ = c;
  459. *fb++ = c;
  460. *fb++ = c;
  461. *fb++ = c;
  462. *fb++ = c;
  463. *fb++ = c;
  464. *fb++ = c;
  465. *fb++ = c;
  466. cnt_8copy--;
  467. }
  468. while (cnt > 0) {
  469. *fb++ = c;
  470. cnt--;
  471. }
  472. *fbp = fb;
  473. }
  474. /*
  475. * Do not call this function directly, must be called from lcd_display_bitmap.
  476. */
  477. static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
  478. int x_off, int y_off)
  479. {
  480. uchar *bmap;
  481. ulong width, height;
  482. ulong cnt, runlen;
  483. int x, y;
  484. int decode = 1;
  485. width = get_unaligned_le32(&bmp->header.width);
  486. height = get_unaligned_le32(&bmp->header.height);
  487. bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
  488. x = 0;
  489. y = height - 1;
  490. while (decode) {
  491. if (bmap[0] == BMP_RLE8_ESCAPE) {
  492. switch (bmap[1]) {
  493. case BMP_RLE8_EOL:
  494. /* end of line */
  495. bmap += 2;
  496. x = 0;
  497. y--;
  498. /* 16bpix, 2-byte per pixel, width should *2 */
  499. fb -= (width * 2 + lcd_line_length);
  500. break;
  501. case BMP_RLE8_EOBMP:
  502. /* end of bitmap */
  503. decode = 0;
  504. break;
  505. case BMP_RLE8_DELTA:
  506. /* delta run */
  507. x += bmap[2];
  508. y -= bmap[3];
  509. /* 16bpix, 2-byte per pixel, x should *2 */
  510. fb = (uchar *) (lcd_base + (y + y_off - 1)
  511. * lcd_line_length + (x + x_off) * 2);
  512. bmap += 4;
  513. break;
  514. default:
  515. /* unencoded run */
  516. runlen = bmap[1];
  517. bmap += 2;
  518. if (y < height) {
  519. if (x < width) {
  520. if (x + runlen > width)
  521. cnt = width - x;
  522. else
  523. cnt = runlen;
  524. draw_unencoded_bitmap(
  525. (ushort **)&fb,
  526. bmap, cmap, cnt);
  527. }
  528. x += runlen;
  529. }
  530. bmap += runlen;
  531. if (runlen & 1)
  532. bmap++;
  533. }
  534. } else {
  535. /* encoded run */
  536. if (y < height) {
  537. runlen = bmap[0];
  538. if (x < width) {
  539. /* aggregate the same code */
  540. while (bmap[0] == 0xff &&
  541. bmap[2] != BMP_RLE8_ESCAPE &&
  542. bmap[1] == bmap[3]) {
  543. runlen += bmap[2];
  544. bmap += 2;
  545. }
  546. if (x + runlen > width)
  547. cnt = width - x;
  548. else
  549. cnt = runlen;
  550. draw_encoded_bitmap((ushort **)&fb,
  551. cmap[bmap[1]], cnt);
  552. }
  553. x += runlen;
  554. }
  555. bmap += 2;
  556. }
  557. }
  558. }
  559. #endif
  560. #if defined(CONFIG_MPC823)
  561. #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
  562. #else
  563. #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
  564. #endif
  565. #if defined(CONFIG_BMP_16BPP)
  566. #if defined(CONFIG_ATMEL_LCD_BGR555)
  567. static inline void fb_put_word(uchar **fb, uchar **from)
  568. {
  569. *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
  570. *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
  571. *from += 2;
  572. }
  573. #else
  574. static inline void fb_put_word(uchar **fb, uchar **from)
  575. {
  576. *(*fb)++ = *(*from)++;
  577. *(*fb)++ = *(*from)++;
  578. }
  579. #endif
  580. #endif /* CONFIG_BMP_16BPP */
  581. int lcd_display_bitmap(ulong bmp_image, int x, int y)
  582. {
  583. ushort *cmap = NULL;
  584. ushort *cmap_base = NULL;
  585. ushort i, j;
  586. uchar *fb;
  587. bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
  588. uchar *bmap;
  589. ushort padded_width;
  590. unsigned long width, height, byte_width;
  591. unsigned long pwidth = panel_info.vl_col;
  592. unsigned colors, bpix, bmp_bpix;
  593. if (!bmp || !(bmp->header.signature[0] == 'B' &&
  594. bmp->header.signature[1] == 'M')) {
  595. printf("Error: no valid bmp image at %lx\n", bmp_image);
  596. return 1;
  597. }
  598. width = get_unaligned_le32(&bmp->header.width);
  599. height = get_unaligned_le32(&bmp->header.height);
  600. bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
  601. colors = 1 << bmp_bpix;
  602. bpix = NBITS(panel_info.vl_bpix);
  603. if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
  604. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  605. bpix, bmp_bpix);
  606. return 1;
  607. }
  608. /*
  609. * We support displaying 8bpp BMPs on 16bpp LCDs
  610. * and displaying 24bpp BMPs on 32bpp LCDs
  611. * */
  612. if (bpix != bmp_bpix &&
  613. !(bmp_bpix == 8 && bpix == 16) &&
  614. !(bmp_bpix == 24 && bpix == 32)) {
  615. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  616. bpix, get_unaligned_le16(&bmp->header.bit_count));
  617. return 1;
  618. }
  619. debug("Display-bmp: %d x %d with %d colors\n",
  620. (int)width, (int)height, (int)colors);
  621. if (bmp_bpix == 8) {
  622. cmap = configuration_get_cmap();
  623. cmap_base = cmap;
  624. /* Set color map */
  625. for (i = 0; i < colors; ++i) {
  626. bmp_color_table_entry_t cte = bmp->color_table[i];
  627. #if !defined(CONFIG_ATMEL_LCD)
  628. ushort colreg =
  629. ( ((cte.red) << 8) & 0xf800) |
  630. ( ((cte.green) << 3) & 0x07e0) |
  631. ( ((cte.blue) >> 3) & 0x001f) ;
  632. *cmap = colreg;
  633. #if defined(CONFIG_MPC823)
  634. cmap--;
  635. #else
  636. cmap++;
  637. #endif
  638. #else /* CONFIG_ATMEL_LCD */
  639. lcd_setcolreg(i, cte.red, cte.green, cte.blue);
  640. #endif
  641. }
  642. }
  643. padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
  644. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  645. splash_align_axis(&x, pwidth, width);
  646. splash_align_axis(&y, panel_info.vl_row, height);
  647. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  648. if ((x + width) > pwidth)
  649. width = pwidth - x;
  650. if ((y + height) > panel_info.vl_row)
  651. height = panel_info.vl_row - y;
  652. bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
  653. fb = (uchar *)(lcd_base +
  654. (y + height - 1) * lcd_line_length + x * bpix / 8);
  655. switch (bmp_bpix) {
  656. case 1: /* pass through */
  657. case 8: {
  658. #ifdef CONFIG_LCD_BMP_RLE8
  659. u32 compression = get_unaligned_le32(&bmp->header.compression);
  660. if (compression == BMP_BI_RLE8) {
  661. if (bpix != 16) {
  662. /* TODO implement render code for bpix != 16 */
  663. printf("Error: only support 16 bpix");
  664. return 1;
  665. }
  666. lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
  667. break;
  668. }
  669. #endif
  670. if (bpix != 16)
  671. byte_width = width;
  672. else
  673. byte_width = width * 2;
  674. for (i = 0; i < height; ++i) {
  675. WATCHDOG_RESET();
  676. for (j = 0; j < width; j++) {
  677. if (bpix != 16) {
  678. FB_PUT_BYTE(fb, bmap);
  679. } else {
  680. *(uint16_t *)fb = cmap_base[*(bmap++)];
  681. fb += sizeof(uint16_t) / sizeof(*fb);
  682. }
  683. }
  684. bmap += (padded_width - width);
  685. fb -= byte_width + lcd_line_length;
  686. }
  687. break;
  688. }
  689. #if defined(CONFIG_BMP_16BPP)
  690. case 16:
  691. for (i = 0; i < height; ++i) {
  692. WATCHDOG_RESET();
  693. for (j = 0; j < width; j++)
  694. fb_put_word(&fb, &bmap);
  695. bmap += (padded_width - width) * 2;
  696. fb -= width * 2 + lcd_line_length;
  697. }
  698. break;
  699. #endif /* CONFIG_BMP_16BPP */
  700. #if defined(CONFIG_BMP_24BMP)
  701. case 24:
  702. for (i = 0; i < height; ++i) {
  703. for (j = 0; j < width; j++) {
  704. *(fb++) = *(bmap++);
  705. *(fb++) = *(bmap++);
  706. *(fb++) = *(bmap++);
  707. *(fb++) = 0;
  708. }
  709. fb -= lcd_line_length + width * (bpix / 8);
  710. }
  711. break;
  712. #endif /* CONFIG_BMP_24BMP */
  713. #if defined(CONFIG_BMP_32BPP)
  714. case 32:
  715. for (i = 0; i < height; ++i) {
  716. for (j = 0; j < width; j++) {
  717. *(fb++) = *(bmap++);
  718. *(fb++) = *(bmap++);
  719. *(fb++) = *(bmap++);
  720. *(fb++) = *(bmap++);
  721. }
  722. fb -= lcd_line_length + width * (bpix / 8);
  723. }
  724. break;
  725. #endif /* CONFIG_BMP_32BPP */
  726. default:
  727. break;
  728. };
  729. lcd_sync();
  730. return 0;
  731. }
  732. #endif
  733. static void *lcd_logo(void)
  734. {
  735. #ifdef CONFIG_SPLASH_SCREEN
  736. char *s;
  737. ulong addr;
  738. static int do_splash = 1;
  739. if (do_splash && (s = getenv("splashimage")) != NULL) {
  740. int x = 0, y = 0;
  741. do_splash = 0;
  742. if (splash_screen_prepare())
  743. return (void *)lcd_base;
  744. addr = simple_strtoul (s, NULL, 16);
  745. splash_get_pos(&x, &y);
  746. if (bmp_display(addr, x, y) == 0)
  747. return (void *)lcd_base;
  748. }
  749. #endif /* CONFIG_SPLASH_SCREEN */
  750. bitmap_plot(0, 0);
  751. #ifdef CONFIG_LCD_INFO
  752. lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH);
  753. lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT);
  754. lcd_show_board_info();
  755. #endif /* CONFIG_LCD_INFO */
  756. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  757. return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
  758. #else
  759. return (void *)lcd_base;
  760. #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
  761. }
  762. #ifdef CONFIG_SPLASHIMAGE_GUARD
  763. static int on_splashimage(const char *name, const char *value, enum env_op op,
  764. int flags)
  765. {
  766. ulong addr;
  767. int aligned;
  768. if (op == env_op_delete)
  769. return 0;
  770. addr = simple_strtoul(value, NULL, 16);
  771. /* See README.displaying-bmps */
  772. aligned = (addr % 4 == 2);
  773. if (!aligned) {
  774. printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
  775. return -1;
  776. }
  777. return 0;
  778. }
  779. U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
  780. #endif
  781. int lcd_get_pixel_width(void)
  782. {
  783. return panel_info.vl_col;
  784. }
  785. int lcd_get_pixel_height(void)
  786. {
  787. return panel_info.vl_row;
  788. }
  789. #if defined(CONFIG_LCD_DT_SIMPLEFB)
  790. static int lcd_dt_simplefb_configure_node(void *blob, int off)
  791. {
  792. #if LCD_BPP == LCD_COLOR16
  793. return fdt_setup_simplefb_node(blob, off, gd->fb_base,
  794. panel_info.vl_col, panel_info.vl_row,
  795. panel_info.vl_col * 2, "r5g6b5");
  796. #else
  797. return -1;
  798. #endif
  799. }
  800. int lcd_dt_simplefb_add_node(void *blob)
  801. {
  802. static const char compat[] = "simple-framebuffer";
  803. static const char disabled[] = "disabled";
  804. int off, ret;
  805. off = fdt_add_subnode(blob, 0, "framebuffer");
  806. if (off < 0)
  807. return -1;
  808. ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
  809. if (ret < 0)
  810. return -1;
  811. ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
  812. if (ret < 0)
  813. return -1;
  814. return lcd_dt_simplefb_configure_node(blob, off);
  815. }
  816. int lcd_dt_simplefb_enable_existing_node(void *blob)
  817. {
  818. int off;
  819. off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
  820. if (off < 0)
  821. return -1;
  822. return lcd_dt_simplefb_configure_node(blob, off);
  823. }
  824. #endif