lcd.c 28 KB

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