lcd.c 29 KB

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