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