lcd.c 28 KB

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