lcd.c 22 KB

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