lcd.c 30 KB

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