lcd.c 28 KB

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