lcd.c 27 KB

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