lcd.c 27 KB

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