lcd.c 22 KB

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