lcd.c 28 KB

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