lcd.c 22 KB

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