lcd.c 22 KB

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