lcd.c 29 KB

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