lcd.c 23 KB

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