lcd.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  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. /* By default we scroll by a single line */
  65. #ifndef CONFIG_CONSOLE_SCROLL_LINES
  66. #define CONFIG_CONSOLE_SCROLL_LINES 1
  67. #endif
  68. /************************************************************************/
  69. /* ** CONSOLE DEFINITIONS & FUNCTIONS */
  70. /************************************************************************/
  71. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  72. # define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
  73. / VIDEO_FONT_HEIGHT)
  74. #else
  75. # define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
  76. #endif
  77. #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
  78. #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
  79. #define CONSOLE_ROW_FIRST lcd_console_address
  80. #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
  81. #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
  82. - CONSOLE_ROW_SIZE)
  83. #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
  84. #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
  85. #if (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \
  86. (LCD_BPP == LCD_COLOR32)
  87. # define COLOR_MASK(c) (c)
  88. #else
  89. # error Unsupported LCD BPP.
  90. #endif
  91. DECLARE_GLOBAL_DATA_PTR;
  92. static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
  93. static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
  94. static int lcd_init(void *lcdbase);
  95. static void *lcd_logo(void);
  96. static void lcd_setfgcolor(int color);
  97. static void lcd_setbgcolor(int color);
  98. static int lcd_color_fg;
  99. static int lcd_color_bg;
  100. int lcd_line_length;
  101. char lcd_is_enabled = 0;
  102. static short console_col;
  103. static short console_row;
  104. static void *lcd_console_address;
  105. static void *lcd_base; /* Start of framebuffer memory */
  106. static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
  107. /************************************************************************/
  108. /* Flush LCD activity to the caches */
  109. void lcd_sync(void)
  110. {
  111. /*
  112. * flush_dcache_range() is declared in common.h but it seems that some
  113. * architectures do not actually implement it. Is there a way to find
  114. * out whether it exists? For now, ARM is safe.
  115. */
  116. #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
  117. int line_length;
  118. if (lcd_flush_dcache)
  119. flush_dcache_range((u32)lcd_base,
  120. (u32)(lcd_base + lcd_get_size(&line_length)));
  121. #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
  122. static ulong last_sync;
  123. if (get_timer(last_sync) > 10) {
  124. sandbox_sdl_sync(lcd_base);
  125. last_sync = get_timer(0);
  126. }
  127. #endif
  128. }
  129. void lcd_set_flush_dcache(int flush)
  130. {
  131. lcd_flush_dcache = (flush != 0);
  132. }
  133. /*----------------------------------------------------------------------*/
  134. static void console_scrollup(void)
  135. {
  136. const int rows = CONFIG_CONSOLE_SCROLL_LINES;
  137. /* Copy up rows ignoring those that will be overwritten */
  138. memcpy(CONSOLE_ROW_FIRST,
  139. lcd_console_address + CONSOLE_ROW_SIZE * rows,
  140. CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
  141. /* Clear the last rows */
  142. #if (LCD_BPP != LCD_COLOR32)
  143. memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
  144. COLOR_MASK(lcd_color_bg),
  145. CONSOLE_ROW_SIZE * rows);
  146. #else
  147. u32 *ppix = lcd_console_address +
  148. CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
  149. u32 i;
  150. for (i = 0;
  151. i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
  152. i++) {
  153. *ppix++ = COLOR_MASK(lcd_color_bg);
  154. }
  155. #endif
  156. lcd_sync();
  157. console_row -= rows;
  158. }
  159. /*----------------------------------------------------------------------*/
  160. static inline void console_back(void)
  161. {
  162. if (--console_col < 0) {
  163. console_col = CONSOLE_COLS-1 ;
  164. if (--console_row < 0)
  165. console_row = 0;
  166. }
  167. lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
  168. console_row * VIDEO_FONT_HEIGHT, ' ');
  169. }
  170. /*----------------------------------------------------------------------*/
  171. static inline void console_newline(void)
  172. {
  173. console_col = 0;
  174. /* Check if we need to scroll the terminal */
  175. if (++console_row >= CONSOLE_ROWS)
  176. console_scrollup();
  177. else
  178. lcd_sync();
  179. }
  180. /*----------------------------------------------------------------------*/
  181. static void lcd_stub_putc(struct stdio_dev *dev, const char c)
  182. {
  183. lcd_putc(c);
  184. }
  185. void lcd_putc(const char c)
  186. {
  187. if (!lcd_is_enabled) {
  188. serial_putc(c);
  189. return;
  190. }
  191. switch (c) {
  192. case '\r':
  193. console_col = 0;
  194. return;
  195. case '\n':
  196. console_newline();
  197. return;
  198. case '\t': /* Tab (8 chars alignment) */
  199. console_col += 8;
  200. console_col &= ~7;
  201. if (console_col >= CONSOLE_COLS)
  202. console_newline();
  203. return;
  204. case '\b':
  205. console_back();
  206. return;
  207. default:
  208. lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
  209. console_row * VIDEO_FONT_HEIGHT, c);
  210. if (++console_col >= CONSOLE_COLS)
  211. console_newline();
  212. }
  213. }
  214. /*----------------------------------------------------------------------*/
  215. static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
  216. {
  217. lcd_puts(s);
  218. }
  219. void lcd_puts(const char *s)
  220. {
  221. if (!lcd_is_enabled) {
  222. serial_puts(s);
  223. return;
  224. }
  225. while (*s)
  226. lcd_putc(*s++);
  227. lcd_sync();
  228. }
  229. /*----------------------------------------------------------------------*/
  230. void lcd_printf(const char *fmt, ...)
  231. {
  232. va_list args;
  233. char buf[CONFIG_SYS_PBSIZE];
  234. va_start(args, fmt);
  235. vsprintf(buf, fmt, args);
  236. va_end(args);
  237. lcd_puts(buf);
  238. }
  239. /************************************************************************/
  240. /* ** Low-Level Graphics Routines */
  241. /************************************************************************/
  242. static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
  243. {
  244. uchar *dest;
  245. ushort row;
  246. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  247. y += BMP_LOGO_HEIGHT;
  248. #endif
  249. dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8);
  250. for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
  251. uchar *s = str;
  252. int i;
  253. #if LCD_BPP == LCD_COLOR16
  254. ushort *d = (ushort *)dest;
  255. #elif LCD_BPP == LCD_COLOR32
  256. u32 *d = (u32 *)dest;
  257. #else
  258. uchar *d = dest;
  259. #endif
  260. for (i = 0; i < count; ++i) {
  261. uchar c, bits;
  262. c = *s++;
  263. bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
  264. for (c = 0; c < 8; ++c) {
  265. *d++ = (bits & 0x80) ?
  266. lcd_color_fg : lcd_color_bg;
  267. bits <<= 1;
  268. }
  269. }
  270. }
  271. }
  272. static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
  273. {
  274. lcd_drawchars(x, y, &c, 1);
  275. }
  276. /************************************************************************/
  277. /** Small utility to check that you got the colours right */
  278. /************************************************************************/
  279. #ifdef LCD_TEST_PATTERN
  280. #define N_BLK_VERT 2
  281. #define N_BLK_HOR 3
  282. static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
  283. CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
  284. CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
  285. };
  286. static void test_pattern(void)
  287. {
  288. ushort v_max = panel_info.vl_row;
  289. ushort h_max = panel_info.vl_col;
  290. ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
  291. ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
  292. ushort v, h;
  293. uchar *pix = (uchar *)lcd_base;
  294. printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
  295. h_max, v_max, h_step, v_step);
  296. /* WARNING: Code silently assumes 8bit/pixel */
  297. for (v = 0; v < v_max; ++v) {
  298. uchar iy = v / v_step;
  299. for (h = 0; h < h_max; ++h) {
  300. uchar ix = N_BLK_HOR * iy + h / h_step;
  301. *pix++ = test_colors[ix];
  302. }
  303. }
  304. }
  305. #endif /* LCD_TEST_PATTERN */
  306. /************************************************************************/
  307. /* ** GENERIC Initialization Routines */
  308. /************************************************************************/
  309. /*
  310. * With most lcd drivers the line length is set up
  311. * by calculating it from panel_info parameters. Some
  312. * drivers need to calculate the line length differently,
  313. * so make the function weak to allow overriding it.
  314. */
  315. __weak int lcd_get_size(int *line_length)
  316. {
  317. *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
  318. return *line_length * panel_info.vl_row;
  319. }
  320. int drv_lcd_init(void)
  321. {
  322. struct stdio_dev lcddev;
  323. int rc;
  324. lcd_base = map_sysmem(gd->fb_base, 0);
  325. lcd_init(lcd_base); /* LCD initialization */
  326. /* Device initialization */
  327. memset(&lcddev, 0, sizeof(lcddev));
  328. strcpy(lcddev.name, "lcd");
  329. lcddev.ext = 0; /* No extensions */
  330. lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
  331. lcddev.putc = lcd_stub_putc; /* 'putc' function */
  332. lcddev.puts = lcd_stub_puts; /* 'puts' function */
  333. rc = stdio_register(&lcddev);
  334. return (rc == 0) ? 1 : rc;
  335. }
  336. /*----------------------------------------------------------------------*/
  337. void lcd_clear(void)
  338. {
  339. #if LCD_BPP == LCD_COLOR8
  340. /* Setting the palette */
  341. lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
  342. lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
  343. lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
  344. lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
  345. lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
  346. lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
  347. lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
  348. lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
  349. lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
  350. #endif
  351. #ifndef CONFIG_SYS_WHITE_ON_BLACK
  352. lcd_setfgcolor(CONSOLE_COLOR_BLACK);
  353. lcd_setbgcolor(CONSOLE_COLOR_WHITE);
  354. #else
  355. lcd_setfgcolor(CONSOLE_COLOR_WHITE);
  356. lcd_setbgcolor(CONSOLE_COLOR_BLACK);
  357. #endif /* CONFIG_SYS_WHITE_ON_BLACK */
  358. #ifdef LCD_TEST_PATTERN
  359. test_pattern();
  360. #else
  361. /* set framebuffer to background color */
  362. #if (LCD_BPP != LCD_COLOR32)
  363. memset((char *)lcd_base,
  364. COLOR_MASK(lcd_color_bg),
  365. lcd_line_length * panel_info.vl_row);
  366. #else
  367. u32 *ppix = lcd_base;
  368. u32 i;
  369. for (i = 0;
  370. i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
  371. i++) {
  372. *ppix++ = COLOR_MASK(lcd_color_bg);
  373. }
  374. #endif
  375. #endif
  376. /* Paint the logo and retrieve LCD base address */
  377. debug("[LCD] Drawing the logo...\n");
  378. lcd_console_address = lcd_logo();
  379. console_col = 0;
  380. console_row = 0;
  381. lcd_sync();
  382. }
  383. static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
  384. char *const argv[])
  385. {
  386. lcd_clear();
  387. return 0;
  388. }
  389. U_BOOT_CMD(
  390. cls, 1, 1, do_lcd_clear,
  391. "clear screen",
  392. ""
  393. );
  394. /*----------------------------------------------------------------------*/
  395. static int lcd_init(void *lcdbase)
  396. {
  397. /* Initialize the lcd controller */
  398. debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
  399. lcd_ctrl_init(lcdbase);
  400. /*
  401. * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
  402. * the 'lcdbase' argument and uses custom lcd base address
  403. * by setting up gd->fb_base. Check for this condition and fixup
  404. * 'lcd_base' address.
  405. */
  406. if (map_to_sysmem(lcdbase) != gd->fb_base)
  407. lcd_base = map_sysmem(gd->fb_base, 0);
  408. debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
  409. lcd_get_size(&lcd_line_length);
  410. lcd_is_enabled = 1;
  411. lcd_clear();
  412. lcd_enable();
  413. /* Initialize the console */
  414. console_col = 0;
  415. #ifdef CONFIG_LCD_INFO_BELOW_LOGO
  416. console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
  417. #else
  418. console_row = 1; /* leave 1 blank line below logo */
  419. #endif
  420. return 0;
  421. }
  422. /************************************************************************/
  423. /* ** ROM capable initialization part - needed to reserve FB memory */
  424. /************************************************************************/
  425. /*
  426. * This is called early in the system initialization to grab memory
  427. * for the LCD controller.
  428. * Returns new address for monitor, after reserving LCD buffer memory
  429. *
  430. * Note that this is running from ROM, so no write access to global data.
  431. */
  432. ulong lcd_setmem(ulong addr)
  433. {
  434. ulong size;
  435. int line_length;
  436. debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
  437. panel_info.vl_row, NBITS(panel_info.vl_bpix));
  438. size = lcd_get_size(&line_length);
  439. /* Round up to nearest full page, or MMU section if defined */
  440. size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
  441. addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
  442. /* Allocate pages for the frame buffer. */
  443. addr -= size;
  444. debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
  445. size >> 10, addr);
  446. return addr;
  447. }
  448. /*----------------------------------------------------------------------*/
  449. static void lcd_setfgcolor(int color)
  450. {
  451. lcd_color_fg = color;
  452. }
  453. /*----------------------------------------------------------------------*/
  454. static void lcd_setbgcolor(int color)
  455. {
  456. lcd_color_bg = color;
  457. }
  458. /************************************************************************/
  459. /* ** Chipset depending Bitmap / Logo stuff... */
  460. /************************************************************************/
  461. static inline ushort *configuration_get_cmap(void)
  462. {
  463. #if defined CONFIG_CPU_PXA
  464. struct pxafb_info *fbi = &panel_info.pxa;
  465. return (ushort *)fbi->palette;
  466. #elif defined(CONFIG_MPC823)
  467. immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  468. cpm8xx_t *cp = &(immr->im_cpm);
  469. return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
  470. #elif defined(CONFIG_ATMEL_LCD)
  471. return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
  472. #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
  473. return panel_info.cmap;
  474. #elif defined(CONFIG_LCD_LOGO)
  475. return bmp_logo_palette;
  476. #else
  477. return NULL;
  478. #endif
  479. }
  480. #ifdef CONFIG_LCD_LOGO
  481. void bitmap_plot(int x, int y)
  482. {
  483. #ifdef CONFIG_ATMEL_LCD
  484. uint *cmap = (uint *)bmp_logo_palette;
  485. #else
  486. ushort *cmap = (ushort *)bmp_logo_palette;
  487. #endif
  488. ushort i, j;
  489. uchar *bmap;
  490. uchar *fb;
  491. ushort *fb16;
  492. #if defined(CONFIG_MPC823)
  493. immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  494. cpm8xx_t *cp = &(immr->im_cpm);
  495. #endif
  496. unsigned bpix = NBITS(panel_info.vl_bpix);
  497. debug("Logo: width %d height %d colors %d cmap %d\n",
  498. BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
  499. ARRAY_SIZE(bmp_logo_palette));
  500. bmap = &bmp_logo_bitmap[0];
  501. fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
  502. if (bpix < 12) {
  503. /* Leave room for default color map
  504. * default case: generic system with no cmap (most likely 16bpp)
  505. * cmap was set to the source palette, so no change is done.
  506. * This avoids even more ifdefs in the next stanza
  507. */
  508. #if defined(CONFIG_MPC823)
  509. cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
  510. #elif defined(CONFIG_ATMEL_LCD)
  511. cmap = (uint *)configuration_get_cmap();
  512. #else
  513. cmap = configuration_get_cmap();
  514. #endif
  515. WATCHDOG_RESET();
  516. /* Set color map */
  517. for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
  518. ushort colreg = bmp_logo_palette[i];
  519. #ifdef CONFIG_ATMEL_LCD
  520. uint lut_entry;
  521. #ifdef CONFIG_ATMEL_LCD_BGR555
  522. lut_entry = ((colreg & 0x000F) << 11) |
  523. ((colreg & 0x00F0) << 2) |
  524. ((colreg & 0x0F00) >> 7);
  525. #else /* CONFIG_ATMEL_LCD_RGB565 */
  526. lut_entry = ((colreg & 0x000F) << 1) |
  527. ((colreg & 0x00F0) << 3) |
  528. ((colreg & 0x0F00) << 4);
  529. #endif
  530. *(cmap + BMP_LOGO_OFFSET) = lut_entry;
  531. cmap++;
  532. #else /* !CONFIG_ATMEL_LCD */
  533. *cmap++ = colreg;
  534. #endif /* CONFIG_ATMEL_LCD */
  535. }
  536. WATCHDOG_RESET();
  537. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  538. memcpy(fb, bmap, BMP_LOGO_WIDTH);
  539. bmap += BMP_LOGO_WIDTH;
  540. fb += panel_info.vl_col;
  541. }
  542. }
  543. else { /* true color mode */
  544. u16 col16;
  545. fb16 = (ushort *)fb;
  546. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  547. for (j = 0; j < BMP_LOGO_WIDTH; j++) {
  548. col16 = bmp_logo_palette[(bmap[j]-16)];
  549. fb16[j] =
  550. ((col16 & 0x000F) << 1) |
  551. ((col16 & 0x00F0) << 3) |
  552. ((col16 & 0x0F00) << 4);
  553. }
  554. bmap += BMP_LOGO_WIDTH;
  555. fb16 += panel_info.vl_col;
  556. }
  557. }
  558. WATCHDOG_RESET();
  559. lcd_sync();
  560. }
  561. #else
  562. static inline void bitmap_plot(int x, int y) {}
  563. #endif /* CONFIG_LCD_LOGO */
  564. /*----------------------------------------------------------------------*/
  565. #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  566. /*
  567. * Display the BMP file located at address bmp_image.
  568. * Only uncompressed.
  569. */
  570. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  571. #define BMP_ALIGN_CENTER 0x7FFF
  572. static void splash_align_axis(int *axis, unsigned long panel_size,
  573. unsigned long picture_size)
  574. {
  575. unsigned long panel_picture_delta = panel_size - picture_size;
  576. unsigned long axis_alignment;
  577. if (*axis == BMP_ALIGN_CENTER)
  578. axis_alignment = panel_picture_delta / 2;
  579. else if (*axis < 0)
  580. axis_alignment = panel_picture_delta + *axis + 1;
  581. else
  582. return;
  583. *axis = max(0, (int)axis_alignment);
  584. }
  585. #endif
  586. #ifdef CONFIG_LCD_BMP_RLE8
  587. #define BMP_RLE8_ESCAPE 0
  588. #define BMP_RLE8_EOL 0
  589. #define BMP_RLE8_EOBMP 1
  590. #define BMP_RLE8_DELTA 2
  591. static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
  592. int cnt)
  593. {
  594. while (cnt > 0) {
  595. *(*fbp)++ = cmap[*bmap++];
  596. cnt--;
  597. }
  598. }
  599. static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
  600. {
  601. ushort *fb = *fbp;
  602. int cnt_8copy = cnt >> 3;
  603. cnt -= cnt_8copy << 3;
  604. while (cnt_8copy > 0) {
  605. *fb++ = c;
  606. *fb++ = c;
  607. *fb++ = c;
  608. *fb++ = c;
  609. *fb++ = c;
  610. *fb++ = c;
  611. *fb++ = c;
  612. *fb++ = c;
  613. cnt_8copy--;
  614. }
  615. while (cnt > 0) {
  616. *fb++ = c;
  617. cnt--;
  618. }
  619. *fbp = fb;
  620. }
  621. /*
  622. * Do not call this function directly, must be called from lcd_display_bitmap.
  623. */
  624. static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
  625. int x_off, int y_off)
  626. {
  627. uchar *bmap;
  628. ulong width, height;
  629. ulong cnt, runlen;
  630. int x, y;
  631. int decode = 1;
  632. width = get_unaligned_le32(&bmp->header.width);
  633. height = get_unaligned_le32(&bmp->header.height);
  634. bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
  635. x = 0;
  636. y = height - 1;
  637. while (decode) {
  638. if (bmap[0] == BMP_RLE8_ESCAPE) {
  639. switch (bmap[1]) {
  640. case BMP_RLE8_EOL:
  641. /* end of line */
  642. bmap += 2;
  643. x = 0;
  644. y--;
  645. /* 16bpix, 2-byte per pixel, width should *2 */
  646. fb -= (width * 2 + lcd_line_length);
  647. break;
  648. case BMP_RLE8_EOBMP:
  649. /* end of bitmap */
  650. decode = 0;
  651. break;
  652. case BMP_RLE8_DELTA:
  653. /* delta run */
  654. x += bmap[2];
  655. y -= bmap[3];
  656. /* 16bpix, 2-byte per pixel, x should *2 */
  657. fb = (uchar *) (lcd_base + (y + y_off - 1)
  658. * lcd_line_length + (x + x_off) * 2);
  659. bmap += 4;
  660. break;
  661. default:
  662. /* unencoded run */
  663. runlen = bmap[1];
  664. bmap += 2;
  665. if (y < height) {
  666. if (x < width) {
  667. if (x + runlen > width)
  668. cnt = width - x;
  669. else
  670. cnt = runlen;
  671. draw_unencoded_bitmap(
  672. (ushort **)&fb,
  673. bmap, cmap, cnt);
  674. }
  675. x += runlen;
  676. }
  677. bmap += runlen;
  678. if (runlen & 1)
  679. bmap++;
  680. }
  681. } else {
  682. /* encoded run */
  683. if (y < height) {
  684. runlen = bmap[0];
  685. if (x < width) {
  686. /* aggregate the same code */
  687. while (bmap[0] == 0xff &&
  688. bmap[2] != BMP_RLE8_ESCAPE &&
  689. bmap[1] == bmap[3]) {
  690. runlen += bmap[2];
  691. bmap += 2;
  692. }
  693. if (x + runlen > width)
  694. cnt = width - x;
  695. else
  696. cnt = runlen;
  697. draw_encoded_bitmap((ushort **)&fb,
  698. cmap[bmap[1]], cnt);
  699. }
  700. x += runlen;
  701. }
  702. bmap += 2;
  703. }
  704. }
  705. }
  706. #endif
  707. #if defined(CONFIG_MPC823)
  708. #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
  709. #else
  710. #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
  711. #endif
  712. #if defined(CONFIG_BMP_16BPP)
  713. #if defined(CONFIG_ATMEL_LCD_BGR555)
  714. static inline void fb_put_word(uchar **fb, uchar **from)
  715. {
  716. *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
  717. *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
  718. *from += 2;
  719. }
  720. #else
  721. static inline void fb_put_word(uchar **fb, uchar **from)
  722. {
  723. *(*fb)++ = *(*from)++;
  724. *(*fb)++ = *(*from)++;
  725. }
  726. #endif
  727. #endif /* CONFIG_BMP_16BPP */
  728. int lcd_display_bitmap(ulong bmp_image, int x, int y)
  729. {
  730. ushort *cmap = NULL;
  731. ushort *cmap_base = NULL;
  732. ushort i, j;
  733. uchar *fb;
  734. bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
  735. uchar *bmap;
  736. ushort padded_width;
  737. unsigned long width, height, byte_width;
  738. unsigned long pwidth = panel_info.vl_col;
  739. unsigned colors, bpix, bmp_bpix;
  740. if (!bmp || !(bmp->header.signature[0] == 'B' &&
  741. bmp->header.signature[1] == 'M')) {
  742. printf("Error: no valid bmp image at %lx\n", bmp_image);
  743. return 1;
  744. }
  745. width = get_unaligned_le32(&bmp->header.width);
  746. height = get_unaligned_le32(&bmp->header.height);
  747. bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
  748. colors = 1 << bmp_bpix;
  749. bpix = NBITS(panel_info.vl_bpix);
  750. if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
  751. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  752. bpix, bmp_bpix);
  753. return 1;
  754. }
  755. /*
  756. * We support displaying 8bpp BMPs on 16bpp LCDs
  757. * and displaying 24bpp BMPs on 32bpp LCDs
  758. * */
  759. if (bpix != bmp_bpix &&
  760. !(bmp_bpix == 8 && bpix == 16) &&
  761. !(bmp_bpix == 24 && bpix == 32)) {
  762. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  763. bpix, get_unaligned_le16(&bmp->header.bit_count));
  764. return 1;
  765. }
  766. debug("Display-bmp: %d x %d with %d colors\n",
  767. (int)width, (int)height, (int)colors);
  768. if (bmp_bpix == 8) {
  769. cmap = configuration_get_cmap();
  770. cmap_base = cmap;
  771. /* Set color map */
  772. for (i = 0; i < colors; ++i) {
  773. bmp_color_table_entry_t cte = bmp->color_table[i];
  774. #if !defined(CONFIG_ATMEL_LCD)
  775. ushort colreg =
  776. ( ((cte.red) << 8) & 0xf800) |
  777. ( ((cte.green) << 3) & 0x07e0) |
  778. ( ((cte.blue) >> 3) & 0x001f) ;
  779. *cmap = colreg;
  780. #if defined(CONFIG_MPC823)
  781. cmap--;
  782. #else
  783. cmap++;
  784. #endif
  785. #else /* CONFIG_ATMEL_LCD */
  786. lcd_setcolreg(i, cte.red, cte.green, cte.blue);
  787. #endif
  788. }
  789. }
  790. padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
  791. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  792. splash_align_axis(&x, pwidth, width);
  793. splash_align_axis(&y, panel_info.vl_row, height);
  794. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  795. if ((x + width) > pwidth)
  796. width = pwidth - x;
  797. if ((y + height) > panel_info.vl_row)
  798. height = panel_info.vl_row - y;
  799. bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
  800. fb = (uchar *)(lcd_base +
  801. (y + height - 1) * lcd_line_length + x * bpix / 8);
  802. switch (bmp_bpix) {
  803. case 1: /* pass through */
  804. case 8: {
  805. #ifdef CONFIG_LCD_BMP_RLE8
  806. u32 compression = get_unaligned_le32(&bmp->header.compression);
  807. if (compression == BMP_BI_RLE8) {
  808. if (bpix != 16) {
  809. /* TODO implement render code for bpix != 16 */
  810. printf("Error: only support 16 bpix");
  811. return 1;
  812. }
  813. lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
  814. break;
  815. }
  816. #endif
  817. if (bpix != 16)
  818. byte_width = width;
  819. else
  820. byte_width = width * 2;
  821. for (i = 0; i < height; ++i) {
  822. WATCHDOG_RESET();
  823. for (j = 0; j < width; j++) {
  824. if (bpix != 16) {
  825. FB_PUT_BYTE(fb, bmap);
  826. } else {
  827. *(uint16_t *)fb = cmap_base[*(bmap++)];
  828. fb += sizeof(uint16_t) / sizeof(*fb);
  829. }
  830. }
  831. bmap += (padded_width - width);
  832. fb -= byte_width + lcd_line_length;
  833. }
  834. break;
  835. }
  836. #if defined(CONFIG_BMP_16BPP)
  837. case 16:
  838. for (i = 0; i < height; ++i) {
  839. WATCHDOG_RESET();
  840. for (j = 0; j < width; j++)
  841. fb_put_word(&fb, &bmap);
  842. bmap += (padded_width - width) * 2;
  843. fb -= width * 2 + lcd_line_length;
  844. }
  845. break;
  846. #endif /* CONFIG_BMP_16BPP */
  847. #if defined(CONFIG_BMP_24BMP)
  848. case 24:
  849. for (i = 0; i < height; ++i) {
  850. for (j = 0; j < width; j++) {
  851. *(fb++) = *(bmap++);
  852. *(fb++) = *(bmap++);
  853. *(fb++) = *(bmap++);
  854. *(fb++) = 0;
  855. }
  856. fb -= lcd_line_length + width * (bpix / 8);
  857. }
  858. break;
  859. #endif /* CONFIG_BMP_24BMP */
  860. #if defined(CONFIG_BMP_32BPP)
  861. case 32:
  862. for (i = 0; i < height; ++i) {
  863. for (j = 0; j < width; j++) {
  864. *(fb++) = *(bmap++);
  865. *(fb++) = *(bmap++);
  866. *(fb++) = *(bmap++);
  867. *(fb++) = *(bmap++);
  868. }
  869. fb -= lcd_line_length + width * (bpix / 8);
  870. }
  871. break;
  872. #endif /* CONFIG_BMP_32BPP */
  873. default:
  874. break;
  875. };
  876. lcd_sync();
  877. return 0;
  878. }
  879. #endif
  880. static void *lcd_logo(void)
  881. {
  882. #ifdef CONFIG_SPLASH_SCREEN
  883. char *s;
  884. ulong addr;
  885. static int do_splash = 1;
  886. if (do_splash && (s = getenv("splashimage")) != NULL) {
  887. int x = 0, y = 0;
  888. do_splash = 0;
  889. if (splash_screen_prepare())
  890. return (void *)lcd_base;
  891. addr = simple_strtoul (s, NULL, 16);
  892. splash_get_pos(&x, &y);
  893. if (bmp_display(addr, x, y) == 0)
  894. return (void *)lcd_base;
  895. }
  896. #endif /* CONFIG_SPLASH_SCREEN */
  897. bitmap_plot(0, 0);
  898. #ifdef CONFIG_LCD_INFO
  899. console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
  900. console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
  901. lcd_show_board_info();
  902. #endif /* CONFIG_LCD_INFO */
  903. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  904. return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
  905. #else
  906. return (void *)lcd_base;
  907. #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
  908. }
  909. #ifdef CONFIG_SPLASHIMAGE_GUARD
  910. static int on_splashimage(const char *name, const char *value, enum env_op op,
  911. int flags)
  912. {
  913. ulong addr;
  914. int aligned;
  915. if (op == env_op_delete)
  916. return 0;
  917. addr = simple_strtoul(value, NULL, 16);
  918. /* See README.displaying-bmps */
  919. aligned = (addr % 4 == 2);
  920. if (!aligned) {
  921. printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
  922. return -1;
  923. }
  924. return 0;
  925. }
  926. U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
  927. #endif
  928. void lcd_position_cursor(unsigned col, unsigned row)
  929. {
  930. console_col = min_t(short, col, CONSOLE_COLS - 1);
  931. console_row = min_t(short, row, CONSOLE_ROWS - 1);
  932. }
  933. int lcd_get_pixel_width(void)
  934. {
  935. return panel_info.vl_col;
  936. }
  937. int lcd_get_pixel_height(void)
  938. {
  939. return panel_info.vl_row;
  940. }
  941. int lcd_get_screen_rows(void)
  942. {
  943. return CONSOLE_ROWS;
  944. }
  945. int lcd_get_screen_columns(void)
  946. {
  947. return CONSOLE_COLS;
  948. }
  949. #if defined(CONFIG_LCD_DT_SIMPLEFB)
  950. static int lcd_dt_simplefb_configure_node(void *blob, int off)
  951. {
  952. #if LCD_BPP == LCD_COLOR16
  953. return fdt_setup_simplefb_node(blob, off, gd->fb_base,
  954. panel_info.vl_col, panel_info.vl_row,
  955. panel_info.vl_col * 2, "r5g6b5");
  956. #else
  957. return -1;
  958. #endif
  959. }
  960. int lcd_dt_simplefb_add_node(void *blob)
  961. {
  962. static const char compat[] = "simple-framebuffer";
  963. static const char disabled[] = "disabled";
  964. int off, ret;
  965. off = fdt_add_subnode(blob, 0, "framebuffer");
  966. if (off < 0)
  967. return -1;
  968. ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
  969. if (ret < 0)
  970. return -1;
  971. ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
  972. if (ret < 0)
  973. return -1;
  974. return lcd_dt_simplefb_configure_node(blob, off);
  975. }
  976. int lcd_dt_simplefb_enable_existing_node(void *blob)
  977. {
  978. int off;
  979. off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
  980. if (off < 0)
  981. return -1;
  982. return lcd_dt_simplefb_configure_node(blob, off);
  983. }
  984. #endif