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_init(lcd_base); /* LCD initialization */
  312. /* Device initialization */
  313. memset(&lcddev, 0, sizeof(lcddev));
  314. strcpy(lcddev.name, "lcd");
  315. lcddev.ext = 0; /* No extensions */
  316. lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
  317. lcddev.putc = lcd_putc; /* 'putc' function */
  318. lcddev.puts = lcd_puts; /* 'puts' function */
  319. rc = stdio_register (&lcddev);
  320. return (rc == 0) ? 1 : rc;
  321. }
  322. /*----------------------------------------------------------------------*/
  323. void lcd_clear(void)
  324. {
  325. #if LCD_BPP == LCD_MONOCHROME
  326. /* Setting the palette */
  327. lcd_initcolregs();
  328. #elif LCD_BPP == LCD_COLOR8
  329. /* Setting the palette */
  330. lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
  331. lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
  332. lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
  333. lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
  334. lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
  335. lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
  336. lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
  337. lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
  338. lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
  339. #endif
  340. #ifndef CONFIG_SYS_WHITE_ON_BLACK
  341. lcd_setfgcolor(CONSOLE_COLOR_BLACK);
  342. lcd_setbgcolor(CONSOLE_COLOR_WHITE);
  343. #else
  344. lcd_setfgcolor(CONSOLE_COLOR_WHITE);
  345. lcd_setbgcolor(CONSOLE_COLOR_BLACK);
  346. #endif /* CONFIG_SYS_WHITE_ON_BLACK */
  347. #ifdef LCD_TEST_PATTERN
  348. test_pattern();
  349. #else
  350. /* set framebuffer to background color */
  351. memset((char *)lcd_base,
  352. COLOR_MASK(lcd_getbgcolor()),
  353. lcd_line_length*panel_info.vl_row);
  354. #endif
  355. /* Paint the logo and retrieve LCD base address */
  356. debug("[LCD] Drawing the logo...\n");
  357. lcd_console_address = lcd_logo ();
  358. console_col = 0;
  359. console_row = 0;
  360. lcd_sync();
  361. }
  362. static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
  363. char *const argv[])
  364. {
  365. lcd_clear();
  366. return 0;
  367. }
  368. U_BOOT_CMD(
  369. cls, 1, 1, do_lcd_clear,
  370. "clear screen",
  371. ""
  372. );
  373. /*----------------------------------------------------------------------*/
  374. static int lcd_init(void *lcdbase)
  375. {
  376. /* Initialize the lcd controller */
  377. debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
  378. lcd_ctrl_init(lcdbase);
  379. lcd_get_size(&lcd_line_length);
  380. lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
  381. lcd_is_enabled = 1;
  382. lcd_clear();
  383. lcd_enable ();
  384. /* Initialize the console */
  385. console_col = 0;
  386. #ifdef CONFIG_LCD_INFO_BELOW_LOGO
  387. console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
  388. #else
  389. console_row = 1; /* leave 1 blank line below logo */
  390. #endif
  391. return 0;
  392. }
  393. /************************************************************************/
  394. /* ** ROM capable initialization part - needed to reserve FB memory */
  395. /************************************************************************/
  396. /*
  397. * This is called early in the system initialization to grab memory
  398. * for the LCD controller.
  399. * Returns new address for monitor, after reserving LCD buffer memory
  400. *
  401. * Note that this is running from ROM, so no write access to global data.
  402. */
  403. ulong lcd_setmem(ulong addr)
  404. {
  405. ulong size;
  406. int line_length;
  407. debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
  408. panel_info.vl_row, NBITS(panel_info.vl_bpix));
  409. size = lcd_get_size(&line_length);
  410. /* Round up to nearest full page, or MMU section if defined */
  411. size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
  412. addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
  413. /* Allocate pages for the frame buffer. */
  414. addr -= size;
  415. debug("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
  416. return addr;
  417. }
  418. /*----------------------------------------------------------------------*/
  419. static void lcd_setfgcolor(int color)
  420. {
  421. lcd_color_fg = color;
  422. }
  423. /*----------------------------------------------------------------------*/
  424. static void lcd_setbgcolor(int color)
  425. {
  426. lcd_color_bg = color;
  427. }
  428. /*----------------------------------------------------------------------*/
  429. #ifdef NOT_USED_SO_FAR
  430. static int lcd_getfgcolor(void)
  431. {
  432. return lcd_color_fg;
  433. }
  434. #endif /* NOT_USED_SO_FAR */
  435. /*----------------------------------------------------------------------*/
  436. static int lcd_getbgcolor(void)
  437. {
  438. return lcd_color_bg;
  439. }
  440. /*----------------------------------------------------------------------*/
  441. /************************************************************************/
  442. /* ** Chipset depending Bitmap / Logo stuff... */
  443. /************************************************************************/
  444. static inline ushort *configuration_get_cmap(void)
  445. {
  446. #if defined CONFIG_CPU_PXA
  447. struct pxafb_info *fbi = &panel_info.pxa;
  448. return (ushort *)fbi->palette;
  449. #elif defined(CONFIG_MPC823)
  450. immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  451. cpm8xx_t *cp = &(immr->im_cpm);
  452. return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
  453. #elif defined(CONFIG_ATMEL_LCD)
  454. return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
  455. #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
  456. return panel_info.cmap;
  457. #else
  458. #if defined(CONFIG_LCD_LOGO)
  459. return bmp_logo_palette;
  460. #else
  461. return NULL;
  462. #endif
  463. #endif
  464. }
  465. #ifdef CONFIG_LCD_LOGO
  466. void bitmap_plot(int x, int y)
  467. {
  468. #ifdef CONFIG_ATMEL_LCD
  469. uint *cmap = (uint *)bmp_logo_palette;
  470. #else
  471. ushort *cmap = (ushort *)bmp_logo_palette;
  472. #endif
  473. ushort i, j;
  474. uchar *bmap;
  475. uchar *fb;
  476. ushort *fb16;
  477. #if defined(CONFIG_MPC823)
  478. immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  479. cpm8xx_t *cp = &(immr->im_cpm);
  480. #endif
  481. debug("Logo: width %d height %d colors %d cmap %d\n",
  482. BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
  483. ARRAY_SIZE(bmp_logo_palette));
  484. bmap = &bmp_logo_bitmap[0];
  485. fb = (uchar *)(lcd_base + y * lcd_line_length + x);
  486. if (NBITS(panel_info.vl_bpix) < 12) {
  487. /* Leave room for default color map
  488. * default case: generic system with no cmap (most likely 16bpp)
  489. * cmap was set to the source palette, so no change is done.
  490. * This avoids even more ifdefs in the next stanza
  491. */
  492. #if defined(CONFIG_MPC823)
  493. cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
  494. #elif defined(CONFIG_ATMEL_LCD)
  495. cmap = (uint *)configuration_get_cmap();
  496. #else
  497. cmap = configuration_get_cmap();
  498. #endif
  499. WATCHDOG_RESET();
  500. /* Set color map */
  501. for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
  502. ushort colreg = bmp_logo_palette[i];
  503. #ifdef CONFIG_ATMEL_LCD
  504. uint lut_entry;
  505. #ifdef CONFIG_ATMEL_LCD_BGR555
  506. lut_entry = ((colreg & 0x000F) << 11) |
  507. ((colreg & 0x00F0) << 2) |
  508. ((colreg & 0x0F00) >> 7);
  509. #else /* CONFIG_ATMEL_LCD_RGB565 */
  510. lut_entry = ((colreg & 0x000F) << 1) |
  511. ((colreg & 0x00F0) << 3) |
  512. ((colreg & 0x0F00) << 4);
  513. #endif
  514. *(cmap + BMP_LOGO_OFFSET) = lut_entry;
  515. cmap++;
  516. #else /* !CONFIG_ATMEL_LCD */
  517. #ifdef CONFIG_SYS_INVERT_COLORS
  518. *cmap++ = 0xffff - colreg;
  519. #else
  520. *cmap++ = colreg;
  521. #endif
  522. #endif /* CONFIG_ATMEL_LCD */
  523. }
  524. WATCHDOG_RESET();
  525. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  526. memcpy(fb, bmap, BMP_LOGO_WIDTH);
  527. bmap += BMP_LOGO_WIDTH;
  528. fb += panel_info.vl_col;
  529. }
  530. }
  531. else { /* true color mode */
  532. u16 col16;
  533. fb16 = (ushort *)(lcd_base + y * lcd_line_length + x);
  534. for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
  535. for (j = 0; j < BMP_LOGO_WIDTH; j++) {
  536. col16 = bmp_logo_palette[(bmap[j]-16)];
  537. fb16[j] =
  538. ((col16 & 0x000F) << 1) |
  539. ((col16 & 0x00F0) << 3) |
  540. ((col16 & 0x0F00) << 4);
  541. }
  542. bmap += BMP_LOGO_WIDTH;
  543. fb16 += panel_info.vl_col;
  544. }
  545. }
  546. WATCHDOG_RESET();
  547. lcd_sync();
  548. }
  549. #else
  550. static inline void bitmap_plot(int x, int y) {}
  551. #endif /* CONFIG_LCD_LOGO */
  552. /*----------------------------------------------------------------------*/
  553. #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  554. /*
  555. * Display the BMP file located at address bmp_image.
  556. * Only uncompressed.
  557. */
  558. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  559. #define BMP_ALIGN_CENTER 0x7FFF
  560. static void splash_align_axis(int *axis, unsigned long panel_size,
  561. unsigned long picture_size)
  562. {
  563. unsigned long panel_picture_delta = panel_size - picture_size;
  564. unsigned long axis_alignment;
  565. if (*axis == BMP_ALIGN_CENTER)
  566. axis_alignment = panel_picture_delta / 2;
  567. else if (*axis < 0)
  568. axis_alignment = panel_picture_delta + *axis + 1;
  569. else
  570. return;
  571. *axis = max(0, axis_alignment);
  572. }
  573. #endif
  574. #ifdef CONFIG_LCD_BMP_RLE8
  575. #define BMP_RLE8_ESCAPE 0
  576. #define BMP_RLE8_EOL 0
  577. #define BMP_RLE8_EOBMP 1
  578. #define BMP_RLE8_DELTA 2
  579. static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
  580. int cnt)
  581. {
  582. while (cnt > 0) {
  583. *(*fbp)++ = cmap[*bmap++];
  584. cnt--;
  585. }
  586. }
  587. static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
  588. {
  589. ushort *fb = *fbp;
  590. int cnt_8copy = cnt >> 3;
  591. cnt -= cnt_8copy << 3;
  592. while (cnt_8copy > 0) {
  593. *fb++ = c;
  594. *fb++ = c;
  595. *fb++ = c;
  596. *fb++ = c;
  597. *fb++ = c;
  598. *fb++ = c;
  599. *fb++ = c;
  600. *fb++ = c;
  601. cnt_8copy--;
  602. }
  603. while (cnt > 0) {
  604. *fb++ = c;
  605. cnt--;
  606. }
  607. (*fbp) = fb;
  608. }
  609. /*
  610. * Do not call this function directly, must be called from
  611. * lcd_display_bitmap.
  612. */
  613. static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
  614. int x_off, int y_off)
  615. {
  616. uchar *bmap;
  617. ulong width, height;
  618. ulong cnt, runlen;
  619. int x, y;
  620. int decode = 1;
  621. width = le32_to_cpu(bmp->header.width);
  622. height = le32_to_cpu(bmp->header.height);
  623. bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
  624. x = 0;
  625. y = height - 1;
  626. while (decode) {
  627. if (bmap[0] == BMP_RLE8_ESCAPE) {
  628. switch (bmap[1]) {
  629. case BMP_RLE8_EOL:
  630. /* end of line */
  631. bmap += 2;
  632. x = 0;
  633. y--;
  634. /* 16bpix, 2-byte per pixel, width should *2 */
  635. fb -= (width * 2 + lcd_line_length);
  636. break;
  637. case BMP_RLE8_EOBMP:
  638. /* end of bitmap */
  639. decode = 0;
  640. break;
  641. case BMP_RLE8_DELTA:
  642. /* delta run */
  643. x += bmap[2];
  644. y -= bmap[3];
  645. /* 16bpix, 2-byte per pixel, x should *2 */
  646. fb = (uchar *) (lcd_base + (y + y_off - 1)
  647. * lcd_line_length + (x + x_off) * 2);
  648. bmap += 4;
  649. break;
  650. default:
  651. /* unencoded run */
  652. runlen = bmap[1];
  653. bmap += 2;
  654. if (y < height) {
  655. if (x < width) {
  656. if (x + runlen > width)
  657. cnt = width - x;
  658. else
  659. cnt = runlen;
  660. draw_unencoded_bitmap(
  661. (ushort **)&fb,
  662. bmap, cmap, cnt);
  663. }
  664. x += runlen;
  665. }
  666. bmap += runlen;
  667. if (runlen & 1)
  668. bmap++;
  669. }
  670. } else {
  671. /* encoded run */
  672. if (y < height) {
  673. runlen = bmap[0];
  674. if (x < width) {
  675. /* aggregate the same code */
  676. while (bmap[0] == 0xff &&
  677. bmap[2] != BMP_RLE8_ESCAPE &&
  678. bmap[1] == bmap[3]) {
  679. runlen += bmap[2];
  680. bmap += 2;
  681. }
  682. if (x + runlen > width)
  683. cnt = width - x;
  684. else
  685. cnt = runlen;
  686. draw_encoded_bitmap((ushort **)&fb,
  687. cmap[bmap[1]], cnt);
  688. }
  689. x += runlen;
  690. }
  691. bmap += 2;
  692. }
  693. }
  694. }
  695. #endif
  696. #if defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
  697. #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
  698. #else
  699. #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
  700. #endif
  701. #if defined(CONFIG_BMP_16BPP)
  702. #if defined(CONFIG_ATMEL_LCD_BGR555)
  703. static inline void fb_put_word(uchar **fb, uchar **from)
  704. {
  705. *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
  706. *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
  707. *from += 2;
  708. }
  709. #else
  710. static inline void fb_put_word(uchar **fb, uchar **from)
  711. {
  712. *(*fb)++ = *(*from)++;
  713. *(*fb)++ = *(*from)++;
  714. }
  715. #endif
  716. #endif /* CONFIG_BMP_16BPP */
  717. int lcd_display_bitmap(ulong bmp_image, int x, int y)
  718. {
  719. #if !defined(CONFIG_MCC200)
  720. ushort *cmap = NULL;
  721. #endif
  722. ushort *cmap_base = NULL;
  723. ushort i, j;
  724. uchar *fb;
  725. bmp_image_t *bmp=(bmp_image_t *)bmp_image;
  726. uchar *bmap;
  727. ushort padded_width;
  728. unsigned long width, height, byte_width;
  729. unsigned long pwidth = panel_info.vl_col;
  730. unsigned colors, bpix, bmp_bpix;
  731. if (!bmp || !((bmp->header.signature[0] == 'B') &&
  732. (bmp->header.signature[1] == 'M'))) {
  733. printf("Error: no valid bmp image at %lx\n", bmp_image);
  734. return 1;
  735. }
  736. width = le32_to_cpu(bmp->header.width);
  737. height = le32_to_cpu(bmp->header.height);
  738. bmp_bpix = le16_to_cpu(bmp->header.bit_count);
  739. colors = 1 << bmp_bpix;
  740. bpix = NBITS(panel_info.vl_bpix);
  741. if ((bpix != 1) && (bpix != 8) && (bpix != 16) && (bpix != 32)) {
  742. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  743. bpix, bmp_bpix);
  744. return 1;
  745. }
  746. /* We support displaying 8bpp BMPs on 16bpp LCDs */
  747. if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) {
  748. printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
  749. bpix,
  750. le16_to_cpu(bmp->header.bit_count));
  751. return 1;
  752. }
  753. debug("Display-bmp: %d x %d with %d colors\n",
  754. (int)width, (int)height, (int)colors);
  755. #if !defined(CONFIG_MCC200)
  756. /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
  757. if (bmp_bpix == 8) {
  758. cmap = configuration_get_cmap();
  759. cmap_base = cmap;
  760. /* Set color map */
  761. for (i = 0; i < colors; ++i) {
  762. bmp_color_table_entry_t cte = bmp->color_table[i];
  763. #if !defined(CONFIG_ATMEL_LCD)
  764. ushort colreg =
  765. ( ((cte.red) << 8) & 0xf800) |
  766. ( ((cte.green) << 3) & 0x07e0) |
  767. ( ((cte.blue) >> 3) & 0x001f) ;
  768. #ifdef CONFIG_SYS_INVERT_COLORS
  769. *cmap = 0xffff - colreg;
  770. #else
  771. *cmap = colreg;
  772. #endif
  773. #if defined(CONFIG_MPC823)
  774. cmap--;
  775. #else
  776. cmap++;
  777. #endif
  778. #else /* CONFIG_ATMEL_LCD */
  779. lcd_setcolreg(i, cte.red, cte.green, cte.blue);
  780. #endif
  781. }
  782. }
  783. #endif
  784. /*
  785. * BMP format for Monochrome assumes that the state of a
  786. * pixel is described on a per Bit basis, not per Byte.
  787. * So, in case of Monochrome BMP we should align widths
  788. * on a byte boundary and convert them from Bit to Byte
  789. * units.
  790. * Probably, PXA250 and MPC823 process 1bpp BMP images in
  791. * their own ways, so make the converting to be MCC200
  792. * specific.
  793. */
  794. #if defined(CONFIG_MCC200)
  795. if (bpix == 1) {
  796. width = ((width + 7) & ~7) >> 3;
  797. x = ((x + 7) & ~7) >> 3;
  798. pwidth= ((pwidth + 7) & ~7) >> 3;
  799. }
  800. #endif
  801. padded_width = (width&0x3) ? ((width&~0x3)+4) : (width);
  802. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  803. splash_align_axis(&x, pwidth, width);
  804. splash_align_axis(&y, panel_info.vl_row, height);
  805. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  806. if ((x + width) > pwidth)
  807. width = pwidth - x;
  808. if ((y + height) > panel_info.vl_row)
  809. height = panel_info.vl_row - y;
  810. bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
  811. fb = (uchar *) (lcd_base +
  812. (y + height - 1) * lcd_line_length + x * bpix / 8);
  813. switch (bmp_bpix) {
  814. case 1: /* pass through */
  815. case 8:
  816. #ifdef CONFIG_LCD_BMP_RLE8
  817. if (le32_to_cpu(bmp->header.compression) == BMP_BI_RLE8) {
  818. if (bpix != 16) {
  819. /* TODO implement render code for bpix != 16 */
  820. printf("Error: only support 16 bpix");
  821. return 1;
  822. }
  823. lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
  824. break;
  825. }
  826. #endif
  827. if (bpix != 16)
  828. byte_width = width;
  829. else
  830. byte_width = width * 2;
  831. for (i = 0; i < height; ++i) {
  832. WATCHDOG_RESET();
  833. for (j = 0; j < width; j++) {
  834. if (bpix != 16) {
  835. FB_PUT_BYTE(fb, bmap);
  836. } else {
  837. *(uint16_t *)fb = cmap_base[*(bmap++)];
  838. fb += sizeof(uint16_t) / sizeof(*fb);
  839. }
  840. }
  841. bmap += (padded_width - width);
  842. fb -= (byte_width + lcd_line_length);
  843. }
  844. break;
  845. #if defined(CONFIG_BMP_16BPP)
  846. case 16:
  847. for (i = 0; i < height; ++i) {
  848. WATCHDOG_RESET();
  849. for (j = 0; j < width; j++)
  850. fb_put_word(&fb, &bmap);
  851. bmap += (padded_width - width) * 2;
  852. fb -= (width * 2 + lcd_line_length);
  853. }
  854. break;
  855. #endif /* CONFIG_BMP_16BPP */
  856. #if defined(CONFIG_BMP_32BPP)
  857. case 32:
  858. for (i = 0; i < height; ++i) {
  859. for (j = 0; j < width; j++) {
  860. *(fb++) = *(bmap++);
  861. *(fb++) = *(bmap++);
  862. *(fb++) = *(bmap++);
  863. *(fb++) = *(bmap++);
  864. }
  865. fb -= (lcd_line_length + width * (bpix / 8));
  866. }
  867. break;
  868. #endif /* CONFIG_BMP_32BPP */
  869. default:
  870. break;
  871. };
  872. lcd_sync();
  873. return 0;
  874. }
  875. #endif
  876. #ifdef CONFIG_SPLASH_SCREEN_PREPARE
  877. static inline int splash_screen_prepare(void)
  878. {
  879. return board_splash_screen_prepare();
  880. }
  881. #else
  882. static inline int splash_screen_prepare(void)
  883. {
  884. return 0;
  885. }
  886. #endif
  887. static void *lcd_logo(void)
  888. {
  889. #ifdef CONFIG_SPLASH_SCREEN
  890. char *s;
  891. ulong addr;
  892. static int do_splash = 1;
  893. if (do_splash && (s = getenv("splashimage")) != NULL) {
  894. int x = 0, y = 0;
  895. do_splash = 0;
  896. if (splash_screen_prepare())
  897. return (void *)gd->fb_base;
  898. addr = simple_strtoul (s, NULL, 16);
  899. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  900. s = getenv("splashpos");
  901. if (s != NULL) {
  902. if (s[0] == 'm')
  903. x = BMP_ALIGN_CENTER;
  904. else
  905. x = simple_strtol(s, NULL, 0);
  906. s = strchr(s + 1, ',');
  907. if (s != NULL) {
  908. if (s[1] == 'm')
  909. y = BMP_ALIGN_CENTER;
  910. else
  911. y = simple_strtol (s + 1, NULL, 0);
  912. }
  913. }
  914. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  915. if (bmp_display(addr, x, y) == 0)
  916. return (void *)lcd_base;
  917. }
  918. #endif /* CONFIG_SPLASH_SCREEN */
  919. bitmap_plot(0, 0);
  920. #ifdef CONFIG_LCD_INFO
  921. console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
  922. console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
  923. lcd_show_board_info();
  924. #endif /* CONFIG_LCD_INFO */
  925. #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  926. return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
  927. #else
  928. return (void *)lcd_base;
  929. #endif /* CONFIG_LCD_LOGO && !CONFIG_LCD_INFO_BELOW_LOGO */
  930. }
  931. #ifdef CONFIG_SPLASHIMAGE_GUARD
  932. static int on_splashimage(const char *name, const char *value, enum env_op op,
  933. int flags)
  934. {
  935. ulong addr;
  936. int aligned;
  937. if (op == env_op_delete)
  938. return 0;
  939. addr = simple_strtoul(value, NULL, 16);
  940. /* See README.displaying-bmps */
  941. aligned = (addr % 4 == 2);
  942. if (!aligned) {
  943. printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
  944. return -1;
  945. }
  946. return 0;
  947. }
  948. U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
  949. #endif
  950. void lcd_position_cursor(unsigned col, unsigned row)
  951. {
  952. console_col = min(col, CONSOLE_COLS - 1);
  953. console_row = min(row, CONSOLE_ROWS - 1);
  954. }
  955. int lcd_get_pixel_width(void)
  956. {
  957. return panel_info.vl_col;
  958. }
  959. int lcd_get_pixel_height(void)
  960. {
  961. return panel_info.vl_row;
  962. }
  963. int lcd_get_screen_rows(void)
  964. {
  965. return CONSOLE_ROWS;
  966. }
  967. int lcd_get_screen_columns(void)
  968. {
  969. return CONSOLE_COLS;
  970. }
  971. /************************************************************************/
  972. /************************************************************************/