lcd.c 22 KB

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