lcd.c 27 KB

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