lcd.c 29 KB

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