lcd.c 20 KB

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