lcd.c 27 KB

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