lcd.c 22 KB

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