lcd.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  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. #ifdef CONFIG_LCD_BMP_RLE8
  572. #define BMP_RLE8_ESCAPE 0
  573. #define BMP_RLE8_EOL 0
  574. #define BMP_RLE8_EOBMP 1
  575. #define BMP_RLE8_DELTA 2
  576. static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
  577. int cnt)
  578. {
  579. while (cnt > 0) {
  580. *(*fbp)++ = cmap[*bmap++];
  581. cnt--;
  582. }
  583. }
  584. static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
  585. {
  586. ushort *fb = *fbp;
  587. int cnt_8copy = cnt >> 3;
  588. cnt -= cnt_8copy << 3;
  589. while (cnt_8copy > 0) {
  590. *fb++ = c;
  591. *fb++ = c;
  592. *fb++ = c;
  593. *fb++ = c;
  594. *fb++ = c;
  595. *fb++ = c;
  596. *fb++ = c;
  597. *fb++ = c;
  598. cnt_8copy--;
  599. }
  600. while (cnt > 0) {
  601. *fb++ = c;
  602. cnt--;
  603. }
  604. (*fbp) = fb;
  605. }
  606. /*
  607. * Do not call this function directly, must be called from
  608. * lcd_display_bitmap.
  609. */
  610. static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
  611. int x_off, int y_off)
  612. {
  613. uchar *bmap;
  614. ulong width, height;
  615. ulong cnt, runlen;
  616. int x, y;
  617. int decode = 1;
  618. width = le32_to_cpu(bmp->header.width);
  619. height = le32_to_cpu(bmp->header.height);
  620. bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
  621. x = 0;
  622. y = height - 1;
  623. while (decode) {
  624. if (bmap[0] == BMP_RLE8_ESCAPE) {
  625. switch (bmap[1]) {
  626. case BMP_RLE8_EOL:
  627. /* end of line */
  628. bmap += 2;
  629. x = 0;
  630. y--;
  631. /* 16bpix, 2-byte per pixel, width should *2 */
  632. fb -= (width * 2 + lcd_line_length);
  633. break;
  634. case BMP_RLE8_EOBMP:
  635. /* end of bitmap */
  636. decode = 0;
  637. break;
  638. case BMP_RLE8_DELTA:
  639. /* delta run */
  640. x += bmap[2];
  641. y -= bmap[3];
  642. /* 16bpix, 2-byte per pixel, x should *2 */
  643. fb = (uchar *) (lcd_base + (y + y_off - 1)
  644. * lcd_line_length + (x + x_off) * 2);
  645. bmap += 4;
  646. break;
  647. default:
  648. /* unencoded run */
  649. runlen = bmap[1];
  650. bmap += 2;
  651. if (y < height) {
  652. if (x < width) {
  653. if (x + runlen > width)
  654. cnt = width - x;
  655. else
  656. cnt = runlen;
  657. draw_unencoded_bitmap(
  658. (ushort **)&fb,
  659. bmap, cmap, cnt);
  660. }
  661. x += runlen;
  662. }
  663. bmap += runlen;
  664. if (runlen & 1)
  665. bmap++;
  666. }
  667. } else {
  668. /* encoded run */
  669. if (y < height) {
  670. runlen = bmap[0];
  671. if (x < width) {
  672. /* aggregate the same code */
  673. while (bmap[0] == 0xff &&
  674. bmap[2] != BMP_RLE8_ESCAPE &&
  675. bmap[1] == bmap[3]) {
  676. runlen += bmap[2];
  677. bmap += 2;
  678. }
  679. if (x + runlen > width)
  680. cnt = width - x;
  681. else
  682. cnt = runlen;
  683. draw_encoded_bitmap((ushort **)&fb,
  684. cmap[bmap[1]], cnt);
  685. }
  686. x += runlen;
  687. }
  688. bmap += 2;
  689. }
  690. }
  691. }
  692. #endif
  693. #if defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
  694. #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
  695. #else
  696. #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
  697. #endif
  698. #if defined(CONFIG_BMP_16BPP)
  699. #if defined(CONFIG_ATMEL_LCD_BGR555)
  700. static inline void fb_put_word(uchar **fb, uchar **from)
  701. {
  702. *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
  703. *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
  704. *from += 2;
  705. }
  706. #else
  707. static inline void fb_put_word(uchar **fb, uchar **from)
  708. {
  709. *(*fb)++ = *(*from)++;
  710. *(*fb)++ = *(*from)++;
  711. }
  712. #endif
  713. #endif /* CONFIG_BMP_16BPP */
  714. int lcd_display_bitmap(ulong bmp_image, int x, int y)
  715. {
  716. #if !defined(CONFIG_MCC200)
  717. ushort *cmap = NULL;
  718. #endif
  719. ushort *cmap_base = NULL;
  720. ushort i, j;
  721. uchar *fb;
  722. bmp_image_t *bmp=(bmp_image_t *)bmp_image;
  723. uchar *bmap;
  724. ushort padded_width;
  725. unsigned long width, height, byte_width;
  726. unsigned long pwidth = panel_info.vl_col;
  727. unsigned colors, bpix, bmp_bpix;
  728. if (!bmp || !((bmp->header.signature[0] == 'B') &&
  729. (bmp->header.signature[1] == 'M'))) {
  730. printf("Error: no valid bmp image at %lx\n", bmp_image);
  731. return 1;
  732. }
  733. width = le32_to_cpu(bmp->header.width);
  734. height = le32_to_cpu(bmp->header.height);
  735. bmp_bpix = le16_to_cpu(bmp->header.bit_count);
  736. colors = 1 << bmp_bpix;
  737. bpix = NBITS(panel_info.vl_bpix);
  738. if ((bpix != 1) && (bpix != 8) && (bpix != 16) && (bpix != 32)) {
  739. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  740. bpix, bmp_bpix);
  741. return 1;
  742. }
  743. /* We support displaying 8bpp BMPs on 16bpp LCDs */
  744. if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) {
  745. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  746. bpix,
  747. le16_to_cpu(bmp->header.bit_count));
  748. return 1;
  749. }
  750. debug("Display-bmp: %d x %d with %d colors\n",
  751. (int)width, (int)height, (int)colors);
  752. #if !defined(CONFIG_MCC200)
  753. /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
  754. if (bmp_bpix == 8) {
  755. cmap = configuration_get_cmap();
  756. cmap_base = cmap;
  757. /* Set color map */
  758. for (i = 0; i < colors; ++i) {
  759. bmp_color_table_entry_t cte = bmp->color_table[i];
  760. #if !defined(CONFIG_ATMEL_LCD)
  761. ushort colreg =
  762. ( ((cte.red) << 8) & 0xf800) |
  763. ( ((cte.green) << 3) & 0x07e0) |
  764. ( ((cte.blue) >> 3) & 0x001f) ;
  765. #ifdef CONFIG_SYS_INVERT_COLORS
  766. *cmap = 0xffff - colreg;
  767. #else
  768. *cmap = colreg;
  769. #endif
  770. #if defined(CONFIG_MPC823)
  771. cmap--;
  772. #else
  773. cmap++;
  774. #endif
  775. #else /* CONFIG_ATMEL_LCD */
  776. lcd_setcolreg(i, cte.red, cte.green, cte.blue);
  777. #endif
  778. }
  779. }
  780. #endif
  781. /*
  782. * BMP format for Monochrome assumes that the state of a
  783. * pixel is described on a per Bit basis, not per Byte.
  784. * So, in case of Monochrome BMP we should align widths
  785. * on a byte boundary and convert them from Bit to Byte
  786. * units.
  787. * Probably, PXA250 and MPC823 process 1bpp BMP images in
  788. * their own ways, so make the converting to be MCC200
  789. * specific.
  790. */
  791. #if defined(CONFIG_MCC200)
  792. if (bpix == 1) {
  793. width = ((width + 7) & ~7) >> 3;
  794. x = ((x + 7) & ~7) >> 3;
  795. pwidth= ((pwidth + 7) & ~7) >> 3;
  796. }
  797. #endif
  798. padded_width = (width&0x3) ? ((width&~0x3)+4) : (width);
  799. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  800. splash_align_axis(&x, pwidth, width);
  801. splash_align_axis(&y, panel_info.vl_row, height);
  802. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  803. if ((x + width) > pwidth)
  804. width = pwidth - x;
  805. if ((y + height) > panel_info.vl_row)
  806. height = panel_info.vl_row - y;
  807. bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
  808. fb = (uchar *) (lcd_base +
  809. (y + height - 1) * lcd_line_length + x * bpix / 8);
  810. switch (bmp_bpix) {
  811. case 1: /* pass through */
  812. case 8:
  813. #ifdef CONFIG_LCD_BMP_RLE8
  814. if (le32_to_cpu(bmp->header.compression) == BMP_BI_RLE8) {
  815. if (bpix != 16) {
  816. /* TODO implement render code for bpix != 16 */
  817. printf("Error: only support 16 bpix");
  818. return 1;
  819. }
  820. lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
  821. break;
  822. }
  823. #endif
  824. if (bpix != 16)
  825. byte_width = width;
  826. else
  827. byte_width = width * 2;
  828. for (i = 0; i < height; ++i) {
  829. WATCHDOG_RESET();
  830. for (j = 0; j < width; j++) {
  831. if (bpix != 16) {
  832. FB_PUT_BYTE(fb, bmap);
  833. } else {
  834. *(uint16_t *)fb = cmap_base[*(bmap++)];
  835. fb += sizeof(uint16_t) / sizeof(*fb);
  836. }
  837. }
  838. bmap += (padded_width - width);
  839. fb -= (byte_width + lcd_line_length);
  840. }
  841. break;
  842. #if defined(CONFIG_BMP_16BPP)
  843. case 16:
  844. for (i = 0; i < height; ++i) {
  845. WATCHDOG_RESET();
  846. for (j = 0; j < width; j++)
  847. fb_put_word(&fb, &bmap);
  848. bmap += (padded_width - width) * 2;
  849. fb -= (width * 2 + lcd_line_length);
  850. }
  851. break;
  852. #endif /* CONFIG_BMP_16BPP */
  853. #if defined(CONFIG_BMP_32BPP)
  854. case 32:
  855. for (i = 0; i < height; ++i) {
  856. for (j = 0; j < width; j++) {
  857. *(fb++) = *(bmap++);
  858. *(fb++) = *(bmap++);
  859. *(fb++) = *(bmap++);
  860. *(fb++) = *(bmap++);
  861. }
  862. fb -= (lcd_line_length + width * (bpix / 8));
  863. }
  864. break;
  865. #endif /* CONFIG_BMP_32BPP */
  866. default:
  867. break;
  868. };
  869. lcd_sync();
  870. return 0;
  871. }
  872. #endif
  873. static void *lcd_logo(void)
  874. {
  875. #ifdef CONFIG_SPLASH_SCREEN
  876. char *s;
  877. ulong addr;
  878. static int do_splash = 1;
  879. if (do_splash && (s = getenv("splashimage")) != NULL) {
  880. int x = 0, y = 0;
  881. do_splash = 0;
  882. addr = simple_strtoul (s, NULL, 16);
  883. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  884. s = getenv("splashpos");
  885. if (s != NULL) {
  886. if (s[0] == 'm')
  887. x = BMP_ALIGN_CENTER;
  888. else
  889. x = simple_strtol(s, NULL, 0);
  890. s = strchr(s + 1, ',');
  891. if (s != NULL) {
  892. if (s[1] == 'm')
  893. y = BMP_ALIGN_CENTER;
  894. else
  895. y = simple_strtol (s + 1, NULL, 0);
  896. }
  897. }
  898. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  899. if (bmp_display(addr, x, y) == 0)
  900. return (void *)lcd_base;
  901. }
  902. #endif /* CONFIG_SPLASH_SCREEN */
  903. bitmap_plot(0, 0);
  904. #ifdef CONFIG_LCD_INFO
  905. console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
  906. console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
  907. lcd_show_board_info();
  908. #endif /* CONFIG_LCD_INFO */
  909. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  910. return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
  911. #else
  912. return (void *)lcd_base;
  913. #endif /* CONFIG_LCD_LOGO && !CONFIG_LCD_INFO_BELOW_LOGO */
  914. }
  915. void lcd_position_cursor(unsigned col, unsigned row)
  916. {
  917. console_col = min(col, CONSOLE_COLS - 1);
  918. console_row = min(row, CONSOLE_ROWS - 1);
  919. }
  920. int lcd_get_pixel_width(void)
  921. {
  922. return panel_info.vl_col;
  923. }
  924. int lcd_get_pixel_height(void)
  925. {
  926. return panel_info.vl_row;
  927. }
  928. int lcd_get_screen_rows(void)
  929. {
  930. return CONSOLE_ROWS;
  931. }
  932. int lcd_get_screen_columns(void)
  933. {
  934. return CONSOLE_COLS;
  935. }
  936. /************************************************************************/
  937. /************************************************************************/