lcd.c 28 KB

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