lcd.c 22 KB

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