lcd.c 23 KB

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