lcd.c 29 KB

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