lcd.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  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 <linux/types.h>
  34. #include <stdio_dev.h>
  35. #if defined(CONFIG_POST)
  36. #include <post.h>
  37. #endif
  38. #include <lcd.h>
  39. #include <watchdog.h>
  40. #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
  41. defined(CONFIG_CPU_MONAHANS)
  42. #define CONFIG_CPU_PXA
  43. #include <asm/byteorder.h>
  44. #endif
  45. #if defined(CONFIG_MPC823)
  46. #include <lcdvideo.h>
  47. #endif
  48. #if defined(CONFIG_ATMEL_LCD)
  49. #include <atmel_lcdc.h>
  50. #endif
  51. /************************************************************************/
  52. /* ** FONT DATA */
  53. /************************************************************************/
  54. #include <video_font.h> /* Get font data, width and height */
  55. #include <video_font_data.h>
  56. /************************************************************************/
  57. /* ** LOGO DATA */
  58. /************************************************************************/
  59. #ifdef CONFIG_LCD_LOGO
  60. # include <bmp_logo.h> /* Get logo data, width and height */
  61. # include <bmp_logo_data.h>
  62. # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
  63. # error Default Color Map overlaps with Logo Color Map
  64. # endif
  65. #endif
  66. DECLARE_GLOBAL_DATA_PTR;
  67. ulong lcd_setmem (ulong addr);
  68. static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
  69. static inline void lcd_puts_xy(ushort x, ushort y, uchar *s);
  70. static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
  71. static int lcd_init(void *lcdbase);
  72. static void *lcd_logo (void);
  73. static int lcd_getbgcolor(void);
  74. static void lcd_setfgcolor(int color);
  75. static void lcd_setbgcolor(int color);
  76. char lcd_is_enabled = 0;
  77. #ifdef NOT_USED_SO_FAR
  78. static void lcd_getcolreg(ushort regno,
  79. ushort *red, ushort *green, ushort *blue);
  80. static int lcd_getfgcolor(void);
  81. #endif /* NOT_USED_SO_FAR */
  82. /************************************************************************/
  83. /*----------------------------------------------------------------------*/
  84. static void console_scrollup(void)
  85. {
  86. /* Copy up rows ignoring the first one */
  87. memcpy(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
  88. /* Clear the last one */
  89. memset(CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
  90. }
  91. /*----------------------------------------------------------------------*/
  92. static inline void console_back(void)
  93. {
  94. if (--console_col < 0) {
  95. console_col = CONSOLE_COLS-1 ;
  96. if (--console_row < 0) {
  97. console_row = 0;
  98. }
  99. }
  100. lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
  101. console_row * VIDEO_FONT_HEIGHT, ' ');
  102. }
  103. /*----------------------------------------------------------------------*/
  104. static inline void console_newline(void)
  105. {
  106. ++console_row;
  107. console_col = 0;
  108. /* Check if we need to scroll the terminal */
  109. if (console_row >= CONSOLE_ROWS) {
  110. /* Scroll everything up */
  111. console_scrollup();
  112. --console_row;
  113. }
  114. }
  115. /*----------------------------------------------------------------------*/
  116. void lcd_putc(const char c)
  117. {
  118. if (!lcd_is_enabled) {
  119. serial_putc(c);
  120. return;
  121. }
  122. switch (c) {
  123. case '\r':
  124. console_col = 0;
  125. return;
  126. case '\n':
  127. console_newline();
  128. return;
  129. case '\t': /* Tab (8 chars alignment) */
  130. console_col += 8;
  131. console_col &= ~7;
  132. if (console_col >= CONSOLE_COLS)
  133. console_newline();
  134. return;
  135. case '\b':
  136. console_back();
  137. return;
  138. default:
  139. lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
  140. console_row * VIDEO_FONT_HEIGHT, c);
  141. if (++console_col >= CONSOLE_COLS)
  142. console_newline();
  143. }
  144. }
  145. /*----------------------------------------------------------------------*/
  146. void lcd_puts(const char *s)
  147. {
  148. if (!lcd_is_enabled) {
  149. serial_puts(s);
  150. return;
  151. }
  152. while (*s) {
  153. lcd_putc(*s++);
  154. }
  155. }
  156. /*----------------------------------------------------------------------*/
  157. void lcd_printf(const char *fmt, ...)
  158. {
  159. va_list args;
  160. char buf[CONFIG_SYS_PBSIZE];
  161. va_start(args, fmt);
  162. vsprintf(buf, fmt, args);
  163. va_end(args);
  164. lcd_puts(buf);
  165. }
  166. /************************************************************************/
  167. /* ** Low-Level Graphics Routines */
  168. /************************************************************************/
  169. static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
  170. {
  171. uchar *dest;
  172. ushort row;
  173. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  174. y += BMP_LOGO_HEIGHT;
  175. #endif
  176. #if LCD_BPP == LCD_MONOCHROME
  177. ushort off = x * (1 << LCD_BPP) % 8;
  178. #endif
  179. dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
  180. for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
  181. uchar *s = str;
  182. int i;
  183. #if LCD_BPP == LCD_COLOR16
  184. ushort *d = (ushort *)dest;
  185. #else
  186. uchar *d = dest;
  187. #endif
  188. #if LCD_BPP == LCD_MONOCHROME
  189. uchar rest = *d & -(1 << (8-off));
  190. uchar sym;
  191. #endif
  192. for (i = 0; i < count; ++i) {
  193. uchar c, bits;
  194. c = *s++;
  195. bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
  196. #if LCD_BPP == LCD_MONOCHROME
  197. sym = (COLOR_MASK(lcd_color_fg) & bits) |
  198. (COLOR_MASK(lcd_color_bg) & ~bits);
  199. *d++ = rest | (sym >> off);
  200. rest = sym << (8-off);
  201. #elif LCD_BPP == LCD_COLOR8
  202. for (c = 0; c < 8; ++c) {
  203. *d++ = (bits & 0x80) ?
  204. lcd_color_fg : lcd_color_bg;
  205. bits <<= 1;
  206. }
  207. #elif LCD_BPP == LCD_COLOR16
  208. for (c = 0; c < 8; ++c) {
  209. *d++ = (bits & 0x80) ?
  210. lcd_color_fg : lcd_color_bg;
  211. bits <<= 1;
  212. }
  213. #endif
  214. }
  215. #if LCD_BPP == LCD_MONOCHROME
  216. *d = rest | (*d & ((1 << (8-off)) - 1));
  217. #endif
  218. }
  219. }
  220. /*----------------------------------------------------------------------*/
  221. static inline void lcd_puts_xy(ushort x, ushort y, uchar *s)
  222. {
  223. lcd_drawchars(x, y, s, strlen((char *)s));
  224. }
  225. /*----------------------------------------------------------------------*/
  226. static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
  227. {
  228. lcd_drawchars(x, y, &c, 1);
  229. }
  230. /************************************************************************/
  231. /** Small utility to check that you got the colours right */
  232. /************************************************************************/
  233. #ifdef LCD_TEST_PATTERN
  234. #define N_BLK_VERT 2
  235. #define N_BLK_HOR 3
  236. static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
  237. CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
  238. CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
  239. };
  240. static void test_pattern(void)
  241. {
  242. ushort v_max = panel_info.vl_row;
  243. ushort h_max = panel_info.vl_col;
  244. ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
  245. ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
  246. ushort v, h;
  247. uchar *pix = (uchar *)lcd_base;
  248. printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
  249. h_max, v_max, h_step, v_step);
  250. /* WARNING: Code silently assumes 8bit/pixel */
  251. for (v = 0; v < v_max; ++v) {
  252. uchar iy = v / v_step;
  253. for (h = 0; h < h_max; ++h) {
  254. uchar ix = N_BLK_HOR * iy + (h/h_step);
  255. *pix++ = test_colors[ix];
  256. }
  257. }
  258. }
  259. #endif /* LCD_TEST_PATTERN */
  260. /************************************************************************/
  261. /* ** GENERIC Initialization Routines */
  262. /************************************************************************/
  263. int drv_lcd_init (void)
  264. {
  265. struct stdio_dev lcddev;
  266. int rc;
  267. lcd_base = (void *)(gd->fb_base);
  268. lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
  269. lcd_init(lcd_base); /* LCD initialization */
  270. /* Device initialization */
  271. memset(&lcddev, 0, sizeof(lcddev));
  272. strcpy(lcddev.name, "lcd");
  273. lcddev.ext = 0; /* No extensions */
  274. lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
  275. lcddev.putc = lcd_putc; /* 'putc' function */
  276. lcddev.puts = lcd_puts; /* 'puts' function */
  277. rc = stdio_register (&lcddev);
  278. return (rc == 0) ? 1 : rc;
  279. }
  280. /*----------------------------------------------------------------------*/
  281. static
  282. int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  283. {
  284. lcd_clear();
  285. return 0;
  286. }
  287. void lcd_clear(void)
  288. {
  289. #if LCD_BPP == LCD_MONOCHROME
  290. /* Setting the palette */
  291. lcd_initcolregs();
  292. #elif LCD_BPP == LCD_COLOR8
  293. /* Setting the palette */
  294. lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
  295. lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
  296. lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
  297. lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
  298. lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
  299. lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
  300. lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
  301. lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
  302. lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
  303. #endif
  304. #ifndef CONFIG_SYS_WHITE_ON_BLACK
  305. lcd_setfgcolor(CONSOLE_COLOR_BLACK);
  306. lcd_setbgcolor(CONSOLE_COLOR_WHITE);
  307. #else
  308. lcd_setfgcolor(CONSOLE_COLOR_WHITE);
  309. lcd_setbgcolor(CONSOLE_COLOR_BLACK);
  310. #endif /* CONFIG_SYS_WHITE_ON_BLACK */
  311. #ifdef LCD_TEST_PATTERN
  312. test_pattern();
  313. #else
  314. /* set framebuffer to background color */
  315. memset((char *)lcd_base,
  316. COLOR_MASK(lcd_getbgcolor()),
  317. lcd_line_length*panel_info.vl_row);
  318. #endif
  319. /* Paint the logo and retrieve LCD base address */
  320. debug("[LCD] Drawing the logo...\n");
  321. lcd_console_address = lcd_logo ();
  322. console_col = 0;
  323. console_row = 0;
  324. }
  325. U_BOOT_CMD(
  326. cls, 1, 1, do_lcd_clear,
  327. "clear screen",
  328. ""
  329. );
  330. /*----------------------------------------------------------------------*/
  331. static int lcd_init(void *lcdbase)
  332. {
  333. /* Initialize the lcd controller */
  334. debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
  335. lcd_ctrl_init(lcdbase);
  336. lcd_is_enabled = 1;
  337. lcd_clear();
  338. lcd_enable ();
  339. /* Initialize the console */
  340. console_col = 0;
  341. #ifdef CONFIG_LCD_INFO_BELOW_LOGO
  342. console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
  343. #else
  344. console_row = 1; /* leave 1 blank line below logo */
  345. #endif
  346. return 0;
  347. }
  348. /************************************************************************/
  349. /* ** ROM capable initialization part - needed to reserve FB memory */
  350. /************************************************************************/
  351. /*
  352. * This is called early in the system initialization to grab memory
  353. * for the LCD controller.
  354. * Returns new address for monitor, after reserving LCD buffer memory
  355. *
  356. * Note that this is running from ROM, so no write access to global data.
  357. */
  358. ulong lcd_setmem(ulong addr)
  359. {
  360. ulong size;
  361. int line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
  362. debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
  363. panel_info.vl_row, NBITS(panel_info.vl_bpix));
  364. size = line_length * panel_info.vl_row;
  365. /* Round up to nearest full page */
  366. size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  367. /* Allocate pages for the frame buffer. */
  368. addr -= size;
  369. debug("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
  370. return addr;
  371. }
  372. /*----------------------------------------------------------------------*/
  373. static void lcd_setfgcolor(int color)
  374. {
  375. lcd_color_fg = color;
  376. }
  377. /*----------------------------------------------------------------------*/
  378. static void lcd_setbgcolor(int color)
  379. {
  380. lcd_color_bg = color;
  381. }
  382. /*----------------------------------------------------------------------*/
  383. #ifdef NOT_USED_SO_FAR
  384. static int lcd_getfgcolor(void)
  385. {
  386. return lcd_color_fg;
  387. }
  388. #endif /* NOT_USED_SO_FAR */
  389. /*----------------------------------------------------------------------*/
  390. static int lcd_getbgcolor(void)
  391. {
  392. return lcd_color_bg;
  393. }
  394. /*----------------------------------------------------------------------*/
  395. /************************************************************************/
  396. /* ** Chipset depending Bitmap / Logo stuff... */
  397. /************************************************************************/
  398. #ifdef CONFIG_LCD_LOGO
  399. void bitmap_plot(int x, int y)
  400. {
  401. #ifdef CONFIG_ATMEL_LCD
  402. uint *cmap;
  403. #else
  404. ushort *cmap;
  405. #endif
  406. ushort i, j;
  407. uchar *bmap;
  408. uchar *fb;
  409. ushort *fb16;
  410. #if defined(CONFIG_CPU_PXA)
  411. struct pxafb_info *fbi = &panel_info.pxa;
  412. #elif defined(CONFIG_MPC823)
  413. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  414. volatile cpm8xx_t *cp = &(immr->im_cpm);
  415. #endif
  416. debug("Logo: width %d height %d colors %d cmap %d\n",
  417. BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
  418. ARRAY_SIZE(bmp_logo_palette));
  419. bmap = &bmp_logo_bitmap[0];
  420. fb = (uchar *)(lcd_base + y * lcd_line_length + x);
  421. if (NBITS(panel_info.vl_bpix) < 12) {
  422. /* Leave room for default color map */
  423. #if defined(CONFIG_CPU_PXA)
  424. cmap = (ushort *) fbi->palette;
  425. #elif defined(CONFIG_MPC823)
  426. cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
  427. #elif defined(CONFIG_ATMEL_LCD)
  428. cmap = (uint *) (panel_info.mmio + ATMEL_LCDC_LUT(0));
  429. #else
  430. /*
  431. * default case: generic system with no cmap (most likely 16bpp)
  432. * We set cmap to the source palette, so no change is done.
  433. * This avoids even more ifdef in the next stanza
  434. */
  435. cmap = bmp_logo_palette;
  436. #endif
  437. WATCHDOG_RESET();
  438. /* Set color map */
  439. for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
  440. ushort colreg = bmp_logo_palette[i];
  441. #ifdef CONFIG_ATMEL_LCD
  442. uint lut_entry;
  443. #ifdef CONFIG_ATMEL_LCD_BGR555
  444. lut_entry = ((colreg & 0x000F) << 11) |
  445. ((colreg & 0x00F0) << 2) |
  446. ((colreg & 0x0F00) >> 7);
  447. #else /* CONFIG_ATMEL_LCD_RGB565 */
  448. lut_entry = ((colreg & 0x000F) << 1) |
  449. ((colreg & 0x00F0) << 3) |
  450. ((colreg & 0x0F00) << 4);
  451. #endif
  452. *(cmap + BMP_LOGO_OFFSET) = lut_entry;
  453. cmap++;
  454. #else /* !CONFIG_ATMEL_LCD */
  455. #ifdef CONFIG_SYS_INVERT_COLORS
  456. *cmap++ = 0xffff - colreg;
  457. #else
  458. *cmap++ = colreg;
  459. #endif
  460. #endif /* CONFIG_ATMEL_LCD */
  461. }
  462. WATCHDOG_RESET();
  463. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  464. memcpy(fb, bmap, BMP_LOGO_WIDTH);
  465. bmap += BMP_LOGO_WIDTH;
  466. fb += panel_info.vl_col;
  467. }
  468. }
  469. else { /* true color mode */
  470. u16 col16;
  471. fb16 = (ushort *)(lcd_base + y * lcd_line_length + x);
  472. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  473. for (j = 0; j < BMP_LOGO_WIDTH; j++) {
  474. col16 = bmp_logo_palette[(bmap[j]-16)];
  475. fb16[j] =
  476. ((col16 & 0x000F) << 1) |
  477. ((col16 & 0x00F0) << 3) |
  478. ((col16 & 0x0F00) << 4);
  479. }
  480. bmap += BMP_LOGO_WIDTH;
  481. fb16 += panel_info.vl_col;
  482. }
  483. }
  484. WATCHDOG_RESET();
  485. }
  486. #else
  487. static inline void bitmap_plot(int x, int y) {}
  488. #endif /* CONFIG_LCD_LOGO */
  489. /*----------------------------------------------------------------------*/
  490. #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  491. /*
  492. * Display the BMP file located at address bmp_image.
  493. * Only uncompressed.
  494. */
  495. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  496. #define BMP_ALIGN_CENTER 0x7FFF
  497. #endif
  498. int lcd_display_bitmap(ulong bmp_image, int x, int y)
  499. {
  500. #if !defined(CONFIG_MCC200)
  501. ushort *cmap = NULL;
  502. #endif
  503. ushort *cmap_base = NULL;
  504. ushort i, j;
  505. uchar *fb;
  506. bmp_image_t *bmp=(bmp_image_t *)bmp_image;
  507. uchar *bmap;
  508. ushort padded_line;
  509. unsigned long width, height, byte_width;
  510. unsigned long pwidth = panel_info.vl_col;
  511. unsigned colors, bpix, bmp_bpix;
  512. #if defined(CONFIG_CPU_PXA)
  513. struct pxafb_info *fbi = &panel_info.pxa;
  514. #elif defined(CONFIG_MPC823)
  515. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  516. volatile cpm8xx_t *cp = &(immr->im_cpm);
  517. #endif
  518. if (!((bmp->header.signature[0] == 'B') &&
  519. (bmp->header.signature[1] == 'M'))) {
  520. printf("Error: no valid bmp image at %lx\n", bmp_image);
  521. return 1;
  522. }
  523. width = le32_to_cpu(bmp->header.width);
  524. height = le32_to_cpu(bmp->header.height);
  525. bmp_bpix = le16_to_cpu(bmp->header.bit_count);
  526. colors = 1 << bmp_bpix;
  527. bpix = NBITS(panel_info.vl_bpix);
  528. if ((bpix != 1) && (bpix != 8) && (bpix != 16) && (bpix != 32)) {
  529. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  530. bpix, bmp_bpix);
  531. return 1;
  532. }
  533. /* We support displaying 8bpp BMPs on 16bpp LCDs */
  534. if (bpix != bmp_bpix && (bmp_bpix != 8 || bpix != 16 || bpix != 32)) {
  535. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  536. bpix,
  537. le16_to_cpu(bmp->header.bit_count));
  538. return 1;
  539. }
  540. debug("Display-bmp: %d x %d with %d colors\n",
  541. (int)width, (int)height, (int)colors);
  542. #if !defined(CONFIG_MCC200)
  543. /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
  544. if (bmp_bpix == 8) {
  545. #if defined(CONFIG_CPU_PXA)
  546. cmap = (ushort *)fbi->palette;
  547. #elif defined(CONFIG_MPC823)
  548. cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
  549. #elif !defined(CONFIG_ATMEL_LCD) && !defined(CONFIG_EXYNOS_FB)
  550. cmap = panel_info.cmap;
  551. #endif
  552. cmap_base = cmap;
  553. /* Set color map */
  554. for (i = 0; i < colors; ++i) {
  555. bmp_color_table_entry_t cte = bmp->color_table[i];
  556. #if !defined(CONFIG_ATMEL_LCD)
  557. ushort colreg =
  558. ( ((cte.red) << 8) & 0xf800) |
  559. ( ((cte.green) << 3) & 0x07e0) |
  560. ( ((cte.blue) >> 3) & 0x001f) ;
  561. #ifdef CONFIG_SYS_INVERT_COLORS
  562. *cmap = 0xffff - colreg;
  563. #else
  564. *cmap = colreg;
  565. #endif
  566. #if defined(CONFIG_MPC823)
  567. cmap--;
  568. #else
  569. cmap++;
  570. #endif
  571. #else /* CONFIG_ATMEL_LCD */
  572. lcd_setcolreg(i, cte.red, cte.green, cte.blue);
  573. #endif
  574. }
  575. }
  576. #endif
  577. /*
  578. * BMP format for Monochrome assumes that the state of a
  579. * pixel is described on a per Bit basis, not per Byte.
  580. * So, in case of Monochrome BMP we should align widths
  581. * on a byte boundary and convert them from Bit to Byte
  582. * units.
  583. * Probably, PXA250 and MPC823 process 1bpp BMP images in
  584. * their own ways, so make the converting to be MCC200
  585. * specific.
  586. */
  587. #if defined(CONFIG_MCC200)
  588. if (bpix == 1) {
  589. width = ((width + 7) & ~7) >> 3;
  590. x = ((x + 7) & ~7) >> 3;
  591. pwidth= ((pwidth + 7) & ~7) >> 3;
  592. }
  593. #endif
  594. padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
  595. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  596. if (x == BMP_ALIGN_CENTER)
  597. x = max(0, (pwidth - width) / 2);
  598. else if (x < 0)
  599. x = max(0, pwidth - width + x + 1);
  600. if (y == BMP_ALIGN_CENTER)
  601. y = max(0, (panel_info.vl_row - height) / 2);
  602. else if (y < 0)
  603. y = max(0, panel_info.vl_row - height + y + 1);
  604. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  605. if ((x + width) > pwidth)
  606. width = pwidth - x;
  607. if ((y + height) > panel_info.vl_row)
  608. height = panel_info.vl_row - y;
  609. bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
  610. fb = (uchar *) (lcd_base +
  611. (y + height - 1) * lcd_line_length + x * bpix / 8);
  612. switch (bmp_bpix) {
  613. case 1: /* pass through */
  614. case 8:
  615. if (bpix != 16)
  616. byte_width = width;
  617. else
  618. byte_width = width * 2;
  619. for (i = 0; i < height; ++i) {
  620. WATCHDOG_RESET();
  621. for (j = 0; j < width; j++) {
  622. if (bpix != 16) {
  623. #if defined(CONFIG_CPU_PXA) || defined(CONFIG_ATMEL_LCD)
  624. *(fb++) = *(bmap++);
  625. #elif defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
  626. *(fb++) = 255 - *(bmap++);
  627. #endif
  628. } else {
  629. *(uint16_t *)fb = cmap_base[*(bmap++)];
  630. fb += sizeof(uint16_t) / sizeof(*fb);
  631. }
  632. }
  633. bmap += (width - padded_line);
  634. fb -= (byte_width + lcd_line_length);
  635. }
  636. break;
  637. #if defined(CONFIG_BMP_16BPP)
  638. case 16:
  639. for (i = 0; i < height; ++i) {
  640. WATCHDOG_RESET();
  641. for (j = 0; j < width; j++) {
  642. #if defined(CONFIG_ATMEL_LCD_BGR555)
  643. *(fb++) = ((bmap[0] & 0x1f) << 2) |
  644. (bmap[1] & 0x03);
  645. *(fb++) = (bmap[0] & 0xe0) |
  646. ((bmap[1] & 0x7c) >> 2);
  647. bmap += 2;
  648. #else
  649. *(fb++) = *(bmap++);
  650. *(fb++) = *(bmap++);
  651. #endif
  652. }
  653. bmap += (padded_line - width) * 2;
  654. fb -= (width * 2 + lcd_line_length);
  655. }
  656. break;
  657. #endif /* CONFIG_BMP_16BPP */
  658. #if defined(CONFIG_BMP_32BPP)
  659. case 32:
  660. for (i = 0; i < height; ++i) {
  661. for (j = 0; j < width; j++) {
  662. *(fb++) = *(bmap++);
  663. *(fb++) = *(bmap++);
  664. *(fb++) = *(bmap++);
  665. *(fb++) = *(bmap++);
  666. }
  667. fb -= (lcd_line_length + width * (bpix / 8));
  668. }
  669. break;
  670. #endif /* CONFIG_BMP_32BPP */
  671. default:
  672. break;
  673. };
  674. return 0;
  675. }
  676. #endif
  677. static void *lcd_logo(void)
  678. {
  679. #ifdef CONFIG_SPLASH_SCREEN
  680. char *s;
  681. ulong addr;
  682. static int do_splash = 1;
  683. if (do_splash && (s = getenv("splashimage")) != NULL) {
  684. int x = 0, y = 0;
  685. do_splash = 0;
  686. addr = simple_strtoul (s, NULL, 16);
  687. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  688. s = getenv("splashpos");
  689. if (s != NULL) {
  690. if (s[0] == 'm')
  691. x = BMP_ALIGN_CENTER;
  692. else
  693. x = simple_strtol(s, NULL, 0);
  694. s = strchr(s + 1, ',');
  695. if (s != NULL) {
  696. if (s[1] == 'm')
  697. y = BMP_ALIGN_CENTER;
  698. else
  699. y = simple_strtol (s + 1, NULL, 0);
  700. }
  701. }
  702. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  703. #ifdef CONFIG_VIDEO_BMP_GZIP
  704. bmp_image_t *bmp = (bmp_image_t *)addr;
  705. unsigned long len;
  706. if (!((bmp->header.signature[0] == 'B') &&
  707. (bmp->header.signature[1] == 'M'))) {
  708. addr = (ulong)gunzip_bmp(addr, &len);
  709. }
  710. #endif
  711. if (lcd_display_bitmap(addr, x, y) == 0)
  712. return (void *)lcd_base;
  713. }
  714. #endif /* CONFIG_SPLASH_SCREEN */
  715. bitmap_plot(0, 0);
  716. #ifdef CONFIG_LCD_INFO
  717. console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
  718. console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
  719. lcd_show_board_info();
  720. #endif /* CONFIG_LCD_INFO */
  721. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  722. return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
  723. #else
  724. return (void *)lcd_base;
  725. #endif /* CONFIG_LCD_LOGO && !CONFIG_LCD_INFO_BELOW_LOGO */
  726. }
  727. /************************************************************************/
  728. /************************************************************************/