lcd.c 22 KB

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