lcd.c 21 KB

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