lcd.c 22 KB

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