lcd.c 29 KB

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