lcd.c 21 KB

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