cfb_console.c 50.4 KB
Newer Older
wdenk's avatar
wdenk committed
1 2 3 4
/*
 * (C) Copyright 2002 ELTEC Elektronik AG
 * Frank Gottschling <fgottschling@eltec.de>
 *
5
 * SPDX-License-Identifier:	GPL-2.0+
wdenk's avatar
wdenk committed
6 7 8 9 10 11 12 13 14 15
 */

/*
 * cfb_console.c
 *
 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
 *
 * At the moment only the 8x16 font is tested and the font fore- and
 * background color is limited to black/white/gray colors. The Linux
 * logo can be placed in the upper left corner and additional board
16
 * information strings (that normally goes to serial port) can be drawn.
wdenk's avatar
wdenk committed
17
 *
18 19 20 21
 * The console driver can use a keyboard interface for character input
 * but this is deprecated. Only rk51 uses it.
 *
 * Character output goes to a memory-mapped video
wdenk's avatar
wdenk committed
22 23 24
 * framebuffer with little or big-endian organisation.
 * With environment setting 'console=serial' the console i/o can be
 * forced to serial port.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
 *
 * The driver uses graphic specific defines/parameters/functions:
 *
 * (for SMI LynxE graphic chip)
 *
 * VIDEO_FB_LITTLE_ENDIAN     - framebuffer organisation default: big endian
 * VIDEO_HW_RECTFILL	      - graphic driver supports hardware rectangle fill
 * VIDEO_HW_BITBLT	      - graphic driver supports hardware bit blt
 *
 * Console Parameters are set by graphic drivers global struct:
 *
 * VIDEO_VISIBLE_COLS	      - x resolution
 * VIDEO_VISIBLE_ROWS	      - y resolution
 * VIDEO_PIXEL_SIZE	      - storage size in byte per pixel
 * VIDEO_DATA_FORMAT	      - graphical data format GDF
 * VIDEO_FB_ADRS	      - start of video memory
 *
 * VIDEO_KBD_INIT_FCT	      - init function for keyboard
 * VIDEO_TSTC_FCT	      - keyboard_tstc function
 * VIDEO_GETC_FCT	      - keyboard_getc function
 *
46 47 48 49 50
 * CONFIG_VIDEO_LOGO	      - display Linux Logo in upper left corner.
 *				Use CONFIG_SPLASH_SCREEN_ALIGN with
 *				environment variable "splashpos" to place
 *				the logo on other position. In this case
 *				no CONSOLE_EXTRA_INFO is possible.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
 * CONFIG_VIDEO_BMP_LOGO      - use bmp_logo instead of linux_logo
 * CONFIG_CONSOLE_EXTRA_INFO  - display additional board information
 *				strings that normaly goes to serial
 *				port.  This define requires a board
 *				specific function:
 *				video_drawstring (VIDEO_INFO_X,
 *					VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
 *					info);
 *				that fills a info buffer at i=row.
 *				s.a: board/eltec/bab7xx.
 *
 * CONFIG_VIDEO_SW_CURSOR:    - Draws a cursor after the last
 *				character. No blinking is provided.
 *				Uses the macros CURSOR_SET and
 *				CURSOR_OFF.
 */
wdenk's avatar
wdenk committed
67 68

#include <common.h>
69
#include <fdtdec.h>
Andreas Bießmann's avatar
Andreas Bießmann committed
70
#include <version.h>
71
#include <malloc.h>
72
#include <video.h>
73
#include <linux/compiler.h>
74

75 76 77
/*
 * Defines for the CT69000 driver
 */
wdenk's avatar
wdenk committed
78
#ifdef	CONFIG_VIDEO_CT69000
wdenk's avatar
wdenk committed
79 80 81

#define VIDEO_FB_LITTLE_ENDIAN
#define VIDEO_HW_RECTFILL
82 83 84
#define VIDEO_HW_BITBLT
#endif

Simon Glass's avatar
Simon Glass committed
85
#if defined(CONFIG_VIDEO_MXS)
Marek Vasut's avatar
Marek Vasut committed
86 87 88
#define VIDEO_FB_16BPP_WORD_SWAP
#endif

89 90 91
/*
 * Defines for the MB862xx driver
 */
92 93 94 95 96
#ifdef CONFIG_VIDEO_MB862xx

#ifdef CONFIG_VIDEO_CORALP
#define VIDEO_FB_LITTLE_ENDIAN
#endif
97
#ifdef CONFIG_VIDEO_MB862xx_ACCEL
98 99 100
#define VIDEO_HW_RECTFILL
#define VIDEO_HW_BITBLT
#endif
101
#endif
102

103 104 105
/*
 * Defines for the i.MX31 driver (mx3fb.c)
 */
Fabio Estevam's avatar
Fabio Estevam committed
106
#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
107 108 109
#define VIDEO_FB_16BPP_WORD_SWAP
#endif

110 111 112
/*
 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
 */
wdenk's avatar
wdenk committed
113 114
#include <video_fb.h>

115 116
#include <splash.h>

117 118 119
/*
 * some Macros
 */
wdenk's avatar
wdenk committed
120 121 122 123 124
#define VIDEO_VISIBLE_COLS	(pGD->winSizeX)
#define VIDEO_VISIBLE_ROWS	(pGD->winSizeY)
#define VIDEO_PIXEL_SIZE	(pGD->gdfBytesPP)
#define VIDEO_DATA_FORMAT	(pGD->gdfIndex)
#define VIDEO_FB_ADRS		(pGD->frameAdrs)
wdenk's avatar
wdenk committed
125

126 127 128
/*
 * Console device
 */
wdenk's avatar
wdenk committed
129 130 131

#include <version.h>
#include <linux/types.h>
132
#include <stdio_dev.h>
wdenk's avatar
wdenk committed
133 134
#include <video_font.h>

135 136
#if defined(CONFIG_CMD_DATE)
#include <rtc.h>
wdenk's avatar
wdenk committed
137 138
#endif

139
#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk's avatar
wdenk committed
140 141
#include <watchdog.h>
#include <bmp_layout.h>
142
#include <splash.h>
143
#endif
wdenk's avatar
wdenk committed
144

145
#if !defined(CONFIG_VIDEO_SW_CURSOR)
wdenk's avatar
wdenk committed
146 147 148 149 150 151
/* no Cursor defined */
#define CURSOR_ON
#define CURSOR_OFF
#define CURSOR_SET
#endif

152
#if defined(CONFIG_VIDEO_SW_CURSOR)
153 154
void console_cursor(int state);

155 156
#define CURSOR_ON  console_cursor(1)
#define CURSOR_OFF console_cursor(0)
157
#define CURSOR_SET video_set_cursor()
158
#endif /* CONFIG_VIDEO_SW_CURSOR */
wdenk's avatar
wdenk committed
159

wdenk's avatar
wdenk committed
160 161
#ifdef	CONFIG_VIDEO_LOGO
#ifdef	CONFIG_VIDEO_BMP_LOGO
162
#include <bmp_logo.h>
163
#include <bmp_logo_data.h>
wdenk's avatar
wdenk committed
164 165 166 167 168
#define VIDEO_LOGO_WIDTH	BMP_LOGO_WIDTH
#define VIDEO_LOGO_HEIGHT	BMP_LOGO_HEIGHT
#define VIDEO_LOGO_LUT_OFFSET	BMP_LOGO_OFFSET
#define VIDEO_LOGO_COLORS	BMP_LOGO_COLORS

169
#else  /* CONFIG_VIDEO_BMP_LOGO */
wdenk's avatar
wdenk committed
170 171 172 173
#define LINUX_LOGO_WIDTH	80
#define LINUX_LOGO_HEIGHT	80
#define LINUX_LOGO_COLORS	214
#define LINUX_LOGO_LUT_OFFSET	0x20
wdenk's avatar
wdenk committed
174 175
#define __initdata
#include <linux_logo.h>
wdenk's avatar
wdenk committed
176 177 178 179
#define VIDEO_LOGO_WIDTH	LINUX_LOGO_WIDTH
#define VIDEO_LOGO_HEIGHT	LINUX_LOGO_HEIGHT
#define VIDEO_LOGO_LUT_OFFSET	LINUX_LOGO_LUT_OFFSET
#define VIDEO_LOGO_COLORS	LINUX_LOGO_COLORS
180
#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenk's avatar
wdenk committed
181 182
#define VIDEO_INFO_X		(VIDEO_LOGO_WIDTH)
#define VIDEO_INFO_Y		(VIDEO_FONT_HEIGHT/2)
183
#else  /* CONFIG_VIDEO_LOGO */
wdenk's avatar
wdenk committed
184 185
#define VIDEO_LOGO_WIDTH	0
#define VIDEO_LOGO_HEIGHT	0
186
#endif /* CONFIG_VIDEO_LOGO */
wdenk's avatar
wdenk committed
187 188 189

#define VIDEO_COLS		VIDEO_VISIBLE_COLS
#define VIDEO_ROWS		VIDEO_VISIBLE_ROWS
190 191 192 193
#ifndef VIDEO_LINE_LEN
#define VIDEO_LINE_LEN		(VIDEO_COLS * VIDEO_PIXEL_SIZE)
#endif
#define VIDEO_SIZE		(VIDEO_ROWS * VIDEO_LINE_LEN)
wdenk's avatar
wdenk committed
194 195 196
#define VIDEO_BURST_LEN		(VIDEO_COLS/8)

#ifdef	CONFIG_VIDEO_LOGO
197
#define CONSOLE_ROWS		((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenk's avatar
wdenk committed
198
#else
wdenk's avatar
wdenk committed
199
#define CONSOLE_ROWS		(VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenk's avatar
wdenk committed
200 201
#endif

wdenk's avatar
wdenk committed
202 203 204 205 206 207
#define CONSOLE_COLS		(VIDEO_COLS / VIDEO_FONT_WIDTH)
#define CONSOLE_ROW_SIZE	(VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
#define CONSOLE_ROW_FIRST	(video_console_address)
#define CONSOLE_ROW_SECOND	(video_console_address + CONSOLE_ROW_SIZE)
#define CONSOLE_ROW_LAST	(video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
#define CONSOLE_SIZE		(CONSOLE_ROW_SIZE * CONSOLE_ROWS)
208 209 210 211 212

/* By default we scroll by a single line */
#ifndef CONFIG_CONSOLE_SCROLL_LINES
#define CONFIG_CONSOLE_SCROLL_LINES 1
#endif
wdenk's avatar
wdenk committed
213 214

/* Macros */
wdenk's avatar
wdenk committed
215
#ifdef	VIDEO_FB_LITTLE_ENDIAN
216 217 218 219 220 221 222 223 224 225 226 227 228
#define SWAP16(x)		((((x) & 0x00ff) << 8) | \
				  ((x) >> 8) \
				)
#define SWAP32(x)		((((x) & 0x000000ff) << 24) | \
				 (((x) & 0x0000ff00) <<  8) | \
				 (((x) & 0x00ff0000) >>  8) | \
				 (((x) & 0xff000000) >> 24)   \
				)
#define SHORTSWAP32(x)		((((x) & 0x000000ff) <<  8) | \
				 (((x) & 0x0000ff00) >>  8) | \
				 (((x) & 0x00ff0000) <<  8) | \
				 (((x) & 0xff000000) >>  8)   \
				)
wdenk's avatar
wdenk committed
229
#else
230 231
#define SWAP16(x)		(x)
#define SWAP32(x)		(x)
232
#if defined(VIDEO_FB_16BPP_WORD_SWAP)
233
#define SHORTSWAP32(x)		(((x) >> 16) | ((x) << 16))
234
#else
235
#define SHORTSWAP32(x)		(x)
236
#endif
wdenk's avatar
wdenk committed
237 238
#endif

239 240
DECLARE_GLOBAL_DATA_PTR;

wdenk's avatar
wdenk committed
241 242 243
/* Locals */
static GraphicDevice *pGD;	/* Pointer to Graphic array */

244
static void *video_fb_address;	/* frame buffer address */
wdenk's avatar
wdenk committed
245
static void *video_console_address;	/* console buffer start address */
wdenk's avatar
wdenk committed
246

247 248
static int video_logo_height = VIDEO_LOGO_HEIGHT;

249 250 251
static int __maybe_unused cursor_state;
static int __maybe_unused old_col;
static int __maybe_unused old_row;
252

253 254
static int console_col;		/* cursor col */
static int console_row;		/* cursor row */
wdenk's avatar
wdenk committed
255

256
static u32 eorx, fgx, bgx;	/* color pats */
wdenk's avatar
wdenk committed
257

258 259
static int cfb_do_flush_cache;

260 261 262 263 264 265 266
#ifdef CONFIG_CFB_CONSOLE_ANSI
static char ansi_buf[10];
static int ansi_buf_size;
static int ansi_colors_need_revert;
static int ansi_cursor_hidden;
#endif

wdenk's avatar
wdenk committed
267
static const int video_font_draw_table8[] = {
268 269 270 271 272
	0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
	0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
	0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
	0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
};
wdenk's avatar
wdenk committed
273 274

static const int video_font_draw_table15[] = {
275 276
	0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
};
wdenk's avatar
wdenk committed
277 278

static const int video_font_draw_table16[] = {
279 280
	0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
};
wdenk's avatar
wdenk committed
281 282

static const int video_font_draw_table24[16][3] = {
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
	{0x00000000, 0x00000000, 0x00000000},
	{0x00000000, 0x00000000, 0x00ffffff},
	{0x00000000, 0x0000ffff, 0xff000000},
	{0x00000000, 0x0000ffff, 0xffffffff},
	{0x000000ff, 0xffff0000, 0x00000000},
	{0x000000ff, 0xffff0000, 0x00ffffff},
	{0x000000ff, 0xffffffff, 0xff000000},
	{0x000000ff, 0xffffffff, 0xffffffff},
	{0xffffff00, 0x00000000, 0x00000000},
	{0xffffff00, 0x00000000, 0x00ffffff},
	{0xffffff00, 0x0000ffff, 0xff000000},
	{0xffffff00, 0x0000ffff, 0xffffffff},
	{0xffffffff, 0xffff0000, 0x00000000},
	{0xffffffff, 0xffff0000, 0x00ffffff},
	{0xffffffff, 0xffffffff, 0xff000000},
	{0xffffffff, 0xffffffff, 0xffffffff}
};
wdenk's avatar
wdenk committed
300 301

static const int video_font_draw_table32[16][4] = {
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
	{0x00000000, 0x00000000, 0x00000000, 0x00000000},
	{0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
	{0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
	{0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
	{0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
	{0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
	{0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
	{0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
	{0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
	{0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
	{0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
	{0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
	{0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
	{0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
	{0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
	{0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
};

320 321 322 323 324 325 326 327 328 329
/*
 * Implement a weak default function for boards that optionally
 * need to skip the cfb initialization.
 */
__weak int board_cfb_skip(void)
{
	/* As default, don't skip cfb init */
	return 0;
}

330
static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenk's avatar
wdenk committed
331
{
wdenk's avatar
wdenk committed
332 333 334 335 336 337 338 339 340 341 342 343 344
	u8 *cdat, *dest, *dest0;
	int rows, offset, c;

	offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
	dest0 = video_fb_address + offset;

	switch (VIDEO_DATA_FORMAT) {
	case GDF__8BIT_INDEX:
	case GDF__8BIT_332RGB:
		while (count--) {
			c = *s;
			cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
			for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
345
			     rows--; dest += VIDEO_LINE_LEN) {
wdenk's avatar
wdenk committed
346 347
				u8 bits = *cdat++;

348 349 350
				((u32 *) dest)[0] =
					(video_font_draw_table8[bits >> 4] &
					 eorx) ^ bgx;
351 352 353 354

				if (VIDEO_FONT_WIDTH == 4)
					continue;

355 356 357
				((u32 *) dest)[1] =
					(video_font_draw_table8[bits & 15] &
					 eorx) ^ bgx;
wdenk's avatar
wdenk committed
358 359 360 361 362
			}
			dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
			s++;
		}
		break;
wdenk's avatar
wdenk committed
363

wdenk's avatar
wdenk committed
364 365 366 367 368
	case GDF_15BIT_555RGB:
		while (count--) {
			c = *s;
			cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
			for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
369
			     rows--; dest += VIDEO_LINE_LEN) {
wdenk's avatar
wdenk committed
370 371
				u8 bits = *cdat++;

372 373 374 375 376 377 378 379
				((u32 *) dest)[0] =
					SHORTSWAP32((video_font_draw_table15
						     [bits >> 6] & eorx) ^
						    bgx);
				((u32 *) dest)[1] =
					SHORTSWAP32((video_font_draw_table15
						     [bits >> 4 & 3] & eorx) ^
						    bgx);
380 381 382 383

				if (VIDEO_FONT_WIDTH == 4)
					continue;

384 385 386 387 388 389 390 391
				((u32 *) dest)[2] =
					SHORTSWAP32((video_font_draw_table15
						     [bits >> 2 & 3] & eorx) ^
						    bgx);
				((u32 *) dest)[3] =
					SHORTSWAP32((video_font_draw_table15
						     [bits & 3] & eorx) ^
						    bgx);
wdenk's avatar
wdenk committed
392 393 394 395 396
			}
			dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
			s++;
		}
		break;
wdenk's avatar
wdenk committed
397

wdenk's avatar
wdenk committed
398 399 400 401 402
	case GDF_16BIT_565RGB:
		while (count--) {
			c = *s;
			cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
			for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
403
			     rows--; dest += VIDEO_LINE_LEN) {
wdenk's avatar
wdenk committed
404 405
				u8 bits = *cdat++;

406 407 408 409 410 411 412 413
				((u32 *) dest)[0] =
					SHORTSWAP32((video_font_draw_table16
						     [bits >> 6] & eorx) ^
						    bgx);
				((u32 *) dest)[1] =
					SHORTSWAP32((video_font_draw_table16
						     [bits >> 4 & 3] & eorx) ^
						    bgx);
414 415 416 417

				if (VIDEO_FONT_WIDTH == 4)
					continue;

418 419 420 421 422 423 424 425
				((u32 *) dest)[2] =
					SHORTSWAP32((video_font_draw_table16
						     [bits >> 2 & 3] & eorx) ^
						    bgx);
				((u32 *) dest)[3] =
					SHORTSWAP32((video_font_draw_table16
						     [bits & 3] & eorx) ^
						    bgx);
wdenk's avatar
wdenk committed
426 427 428 429 430
			}
			dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
			s++;
		}
		break;
wdenk's avatar
wdenk committed
431

wdenk's avatar
wdenk committed
432 433 434 435 436
	case GDF_32BIT_X888RGB:
		while (count--) {
			c = *s;
			cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
			for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
437
			     rows--; dest += VIDEO_LINE_LEN) {
wdenk's avatar
wdenk committed
438 439
				u8 bits = *cdat++;

440 441 442 443 444 445 446 447 448 449 450 451
				((u32 *) dest)[0] =
					SWAP32((video_font_draw_table32
						[bits >> 4][0] & eorx) ^ bgx);
				((u32 *) dest)[1] =
					SWAP32((video_font_draw_table32
						[bits >> 4][1] & eorx) ^ bgx);
				((u32 *) dest)[2] =
					SWAP32((video_font_draw_table32
						[bits >> 4][2] & eorx) ^ bgx);
				((u32 *) dest)[3] =
					SWAP32((video_font_draw_table32
						[bits >> 4][3] & eorx) ^ bgx);
452 453 454 455 456


				if (VIDEO_FONT_WIDTH == 4)
					continue;

457 458 459 460 461 462 463 464 465 466 467 468
				((u32 *) dest)[4] =
					SWAP32((video_font_draw_table32
						[bits & 15][0] & eorx) ^ bgx);
				((u32 *) dest)[5] =
					SWAP32((video_font_draw_table32
						[bits & 15][1] & eorx) ^ bgx);
				((u32 *) dest)[6] =
					SWAP32((video_font_draw_table32
						[bits & 15][2] & eorx) ^ bgx);
				((u32 *) dest)[7] =
					SWAP32((video_font_draw_table32
						[bits & 15][3] & eorx) ^ bgx);
wdenk's avatar
wdenk committed
469 470 471 472 473
			}
			dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
			s++;
		}
		break;
wdenk's avatar
wdenk committed
474

wdenk's avatar
wdenk committed
475 476 477 478 479
	case GDF_24BIT_888RGB:
		while (count--) {
			c = *s;
			cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
			for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
480
			     rows--; dest += VIDEO_LINE_LEN) {
wdenk's avatar
wdenk committed
481 482
				u8 bits = *cdat++;

483 484 485 486 487 488 489 490 491
				((u32 *) dest)[0] =
					(video_font_draw_table24[bits >> 4][0]
					 & eorx) ^ bgx;
				((u32 *) dest)[1] =
					(video_font_draw_table24[bits >> 4][1]
					 & eorx) ^ bgx;
				((u32 *) dest)[2] =
					(video_font_draw_table24[bits >> 4][2]
					 & eorx) ^ bgx;
492 493 494 495

				if (VIDEO_FONT_WIDTH == 4)
					continue;

496 497 498 499 500 501 502 503 504
				((u32 *) dest)[3] =
					(video_font_draw_table24[bits & 15][0]
					 & eorx) ^ bgx;
				((u32 *) dest)[4] =
					(video_font_draw_table24[bits & 15][1]
					 & eorx) ^ bgx;
				((u32 *) dest)[5] =
					(video_font_draw_table24[bits & 15][2]
					 & eorx) ^ bgx;
wdenk's avatar
wdenk committed
505 506 507 508 509
			}
			dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
			s++;
		}
		break;
wdenk's avatar
wdenk committed
510
	}
wdenk's avatar
wdenk committed
511 512
}

513
static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenk's avatar
wdenk committed
514
{
515
	video_drawchars(xx, yy, s, strlen((char *) s));
wdenk's avatar
wdenk committed
516 517
}

518
static void video_putchar(int xx, int yy, unsigned char c)
wdenk's avatar
wdenk committed
519
{
520
	video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenk's avatar
wdenk committed
521 522
}

523
#if defined(CONFIG_VIDEO_SW_CURSOR)
524
static void video_set_cursor(void)
wdenk's avatar
wdenk committed
525
{
526 527 528
	if (cursor_state)
		console_cursor(0);
	console_cursor(1);
wdenk's avatar
wdenk committed
529
}
530

531 532 533 534 535 536 537 538 539 540 541 542 543 544
static void video_invertchar(int xx, int yy)
{
	int firstx = xx * VIDEO_PIXEL_SIZE;
	int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
	int firsty = yy * VIDEO_LINE_LEN;
	int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
	int x, y;
	for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
		for (x = firstx; x < lastx; x++) {
			u8 *dest = (u8 *)(video_fb_address) + x + y;
			*dest = ~*dest;
		}
	}
}
545

546
void console_cursor(int state)
wdenk's avatar
wdenk committed
547
{
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
	if (cursor_state != state) {
		if (cursor_state) {
			/* turn off the cursor */
			video_invertchar(old_col * VIDEO_FONT_WIDTH,
					 old_row * VIDEO_FONT_HEIGHT +
					 video_logo_height);
		} else {
			/* turn off the cursor and record where it is */
			video_invertchar(console_col * VIDEO_FONT_WIDTH,
					 console_row * VIDEO_FONT_HEIGHT +
					 video_logo_height);
			old_col = console_col;
			old_row = console_row;
		}
		cursor_state = state;
wdenk's avatar
wdenk committed
563
	}
564 565
	if (cfb_do_flush_cache)
		flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenk's avatar
wdenk committed
566 567 568 569
}
#endif

#ifndef VIDEO_HW_RECTFILL
570
static void memsetl(int *p, int c, int v)
wdenk's avatar
wdenk committed
571
{
wdenk's avatar
wdenk committed
572 573
	while (c--)
		*(p++) = v;
wdenk's avatar
wdenk committed
574 575 576 577
}
#endif

#ifndef VIDEO_HW_BITBLT
578
static void memcpyl(int *d, int *s, int c)
wdenk's avatar
wdenk committed
579
{
wdenk's avatar
wdenk committed
580 581
	while (c--)
		*(d++) = *(s++);
wdenk's avatar
wdenk committed
582 583 584
}
#endif

585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
static void console_clear_line(int line, int begin, int end)
{
#ifdef VIDEO_HW_RECTFILL
	video_hw_rectfill(VIDEO_PIXEL_SIZE,		/* bytes per pixel */
			  VIDEO_FONT_WIDTH * begin,	/* dest pos x */
			  video_logo_height +
			  VIDEO_FONT_HEIGHT * line,	/* dest pos y */
			  VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
			  VIDEO_FONT_HEIGHT,		/* frame height */
			  bgx				/* fill color */
		);
#else
	if (begin == 0 && (end + 1) == CONSOLE_COLS) {
		memsetl(CONSOLE_ROW_FIRST +
			CONSOLE_ROW_SIZE * line,	/* offset of row */
			CONSOLE_ROW_SIZE >> 2,		/* length of row */
			bgx				/* fill color */
		);
	} else {
		void *offset;
		int i, size;

		offset = CONSOLE_ROW_FIRST +
			 CONSOLE_ROW_SIZE * line +	/* offset of row */
			 VIDEO_FONT_WIDTH *
			 VIDEO_PIXEL_SIZE * begin;	/* offset of col */
		size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
		size >>= 2; /* length to end for memsetl() */
		/* fill at col offset of i'th line using bgx as fill color */
		for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
			memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
	}
#endif
}

620
static void console_scrollup(void)
wdenk's avatar
wdenk committed
621
{
622 623 624
	const int rows = CONFIG_CONSOLE_SCROLL_LINES;
	int i;

wdenk's avatar
wdenk committed
625
	/* copy up rows ignoring the first one */
wdenk's avatar
wdenk committed
626 627

#ifdef VIDEO_HW_BITBLT
628 629 630
	video_hw_bitblt(VIDEO_PIXEL_SIZE,	/* bytes per pixel */
			0,			/* source pos x */
			video_logo_height +
631
				VIDEO_FONT_HEIGHT * rows, /* source pos y */
632 633 634 635 636
			0,			/* dest pos x */
			video_logo_height,	/* dest pos y */
			VIDEO_VISIBLE_COLS,	/* frame width */
			VIDEO_VISIBLE_ROWS
			- video_logo_height
637
			- VIDEO_FONT_HEIGHT * rows	/* frame height */
wdenk's avatar
wdenk committed
638
		);
wdenk's avatar
wdenk committed
639
#else
640 641
	memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
		(CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
wdenk's avatar
wdenk committed
642
#endif
wdenk's avatar
wdenk committed
643
	/* clear the last one */
644 645 646 647 648
	for (i = 1; i <= rows; i++)
		console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);

	/* Decrement row number */
	console_row -= rows;
wdenk's avatar
wdenk committed
649 650
}

651
static void console_back(void)
wdenk's avatar
wdenk committed
652
{
653
	console_col--;
wdenk's avatar
wdenk committed
654 655 656 657 658 659 660

	if (console_col < 0) {
		console_col = CONSOLE_COLS - 1;
		console_row--;
		if (console_row < 0)
			console_row = 0;
	}
wdenk's avatar
wdenk committed
661 662
}

663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
#ifdef CONFIG_CFB_CONSOLE_ANSI

static void console_clear(void)
{
#ifdef VIDEO_HW_RECTFILL
	video_hw_rectfill(VIDEO_PIXEL_SIZE,	/* bytes per pixel */
			  0,			/* dest pos x */
			  video_logo_height,	/* dest pos y */
			  VIDEO_VISIBLE_COLS,	/* frame width */
			  VIDEO_VISIBLE_ROWS,	/* frame height */
			  bgx			/* fill color */
	);
#else
	memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
#endif
}

static void console_cursor_fix(void)
{
	if (console_row < 0)
		console_row = 0;
	if (console_row >= CONSOLE_ROWS)
		console_row = CONSOLE_ROWS - 1;
	if (console_col < 0)
		console_col = 0;
	if (console_col >= CONSOLE_COLS)
		console_col = CONSOLE_COLS - 1;
}

static void console_cursor_up(int n)
{
	console_row -= n;
	console_cursor_fix();
}

static void console_cursor_down(int n)
{
	console_row += n;
	console_cursor_fix();
}

static void console_cursor_left(int n)
{
	console_col -= n;
	console_cursor_fix();
}

static void console_cursor_right(int n)
{
	console_col += n;
	console_cursor_fix();
}

static void console_cursor_set_position(int row, int col)
{
	if (console_row != -1)
		console_row = row;
	if (console_col != -1)
		console_col = col;
	console_cursor_fix();
}

static void console_previousline(int n)
{
	/* FIXME: also scroll terminal ? */
	console_row -= n;
	console_cursor_fix();
}

static void console_swap_colors(void)
wdenk's avatar
wdenk committed
733
{
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
	eorx = fgx;
	fgx = bgx;
	bgx = eorx;
	eorx = fgx ^ bgx;
}

static inline int console_cursor_is_visible(void)
{
	return !ansi_cursor_hidden;
}
#else
static inline int console_cursor_is_visible(void)
{
	return 1;
}
#endif

static void console_newline(int n)
{
	console_row += n;
wdenk's avatar
wdenk committed
754 755 756 757 758
	console_col = 0;

	/* Check if we need to scroll the terminal */
	if (console_row >= CONSOLE_ROWS) {
		/* Scroll everything up */
759
		console_scrollup();
wdenk's avatar
wdenk committed
760
	}
wdenk's avatar
wdenk committed
761 762
}

763
static void console_cr(void)
764
{
765
	console_col = 0;
766 767
}

768
static void parse_putc(const char c)
wdenk's avatar
wdenk committed
769
{
770 771
	static int nl = 1;

772 773
	if (console_cursor_is_visible())
		CURSOR_OFF;
774

wdenk's avatar
wdenk committed
775
	switch (c) {
776
	case 13:		/* back to first column */
777
		console_cr();
wdenk's avatar
wdenk committed
778
		break;
wdenk's avatar
wdenk committed
779

wdenk's avatar
wdenk committed
780
	case '\n':		/* next line */
781
		if (console_col || (!console_col && nl))
782
			console_newline(1);
783
		nl = 1;
wdenk's avatar
wdenk committed
784 785 786
		break;

	case 9:		/* tab 8 */
787
		console_col |= 0x0008;
wdenk's avatar
wdenk committed
788
		console_col &= ~0x0007;
wdenk's avatar
wdenk committed
789

wdenk's avatar
wdenk committed
790
		if (console_col >= CONSOLE_COLS)
791
			console_newline(1);
wdenk's avatar
wdenk committed
792
		break;
wdenk's avatar
wdenk committed
793

wdenk's avatar
wdenk committed
794
	case 8:		/* backspace */
795
		console_back();
wdenk's avatar
wdenk committed
796
		break;
wdenk's avatar
wdenk committed
797

798 799 800
	case 7:		/* bell */
		break;	/* ignored */

wdenk's avatar
wdenk committed
801
	default:		/* draw the char */
802 803
		video_putchar(console_col * VIDEO_FONT_WIDTH,
			      console_row * VIDEO_FONT_HEIGHT, c);
wdenk's avatar
wdenk committed
804
		console_col++;
wdenk's avatar
wdenk committed
805

wdenk's avatar
wdenk committed
806
		/* check for newline */
807
		if (console_col >= CONSOLE_COLS) {
808
			console_newline(1);
809 810
			nl = 0;
		}
wdenk's avatar
wdenk committed
811
	}
812 813 814 815 816

	if (console_cursor_is_visible())
		CURSOR_SET;
}

817
static void cfb_video_putc(struct stdio_dev *dev, const char c)
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
{
#ifdef CONFIG_CFB_CONSOLE_ANSI
	int i;

	if (c == 27) {
		for (i = 0; i < ansi_buf_size; ++i)
			parse_putc(ansi_buf[i]);
		ansi_buf[0] = 27;
		ansi_buf_size = 1;
		return;
	}

	if (ansi_buf_size > 0) {
		/*
		 * 0 - ESC
		 * 1 - [
		 * 2 - num1
		 * 3 - ..
		 * 4 - ;
		 * 5 - num2
		 * 6 - ..
		 * - cchar
		 */
		int next = 0;

		int flush = 0;
		int fail = 0;

		int num1 = 0;
		int num2 = 0;
		int cchar = 0;

		ansi_buf[ansi_buf_size++] = c;

		if (ansi_buf_size >= sizeof(ansi_buf))
			fail = 1;

		for (i = 0; i < ansi_buf_size; ++i) {
			if (fail)
				break;

			switch (next) {
			case 0:
				if (ansi_buf[i] == 27)
					next = 1;
				else
					fail = 1;
				break;

			case 1:
				if (ansi_buf[i] == '[')
					next = 2;
				else
					fail = 1;
				break;

			case 2:
				if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
					num1 = ansi_buf[i]-'0';
					next = 3;
				} else if (ansi_buf[i] != '?') {
					--i;
					num1 = 1;
					next = 4;
				}
				break;

			case 3:
				if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
					num1 *= 10;
					num1 += ansi_buf[i]-'0';
				} else {
					--i;
					next = 4;
				}
				break;

			case 4:
				if (ansi_buf[i] != ';') {
					--i;
					next = 7;
				} else
					next = 5;
				break;

			case 5:
				if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
					num2 = ansi_buf[i]-'0';
					next = 6;
				} else
					fail = 1;
				break;

			case 6:
				if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
					num2 *= 10;
					num2 += ansi_buf[i]-'0';
				} else {
					--i;
					next = 7;
				}
				break;

			case 7:
				if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
					|| ansi_buf[i] == 'J'
					|| ansi_buf[i] == 'K'
					|| ansi_buf[i] == 'h'
					|| ansi_buf[i] == 'l'
					|| ansi_buf[i] == 'm') {
					cchar = ansi_buf[i];
					flush = 1;
				} else
					fail = 1;
				break;
			}
		}

		if (fail) {
			for (i = 0; i < ansi_buf_size; ++i)
				parse_putc(ansi_buf[i]);
			ansi_buf_size = 0;
			return;
		}

		if (flush) {
			if (!ansi_cursor_hidden)
				CURSOR_OFF;
			ansi_buf_size = 0;
			switch (cchar) {
			case 'A':
				/* move cursor num1 rows up */
				console_cursor_up(num1);
				break;
			case 'B':
				/* move cursor num1 rows down */
				console_cursor_down(num1);
				break;
			case 'C':
				/* move cursor num1 columns forward */
				console_cursor_right(num1);
				break;
			case 'D':
				/* move cursor num1 columns back */
				console_cursor_left(num1);
				break;
			case 'E':
				/* move cursor num1 rows up at begin of row */
				console_previousline(num1);
				break;
			case 'F':
				/* move cursor num1 rows down at begin of row */
				console_newline(num1);
				break;
			case 'G':
				/* move cursor to column num1 */
				console_cursor_set_position(-1, num1-1);
				break;
			case 'H':
				/* move cursor to row num1, column num2 */
				console_cursor_set_position(num1-1, num2-1);
				break;
			case 'J':
				/* clear console and move cursor to 0, 0 */
				console_clear();
				console_cursor_set_position(0, 0);
				break;
			case 'K':
				/* clear line */
				if (num1 == 0)
					console_clear_line(console_row,
							console_col,
							CONSOLE_COLS-1);
				else if (num1 == 1)
					console_clear_line(console_row,
							0, console_col);
				else
					console_clear_line(console_row,
							0, CONSOLE_COLS-1);
				break;
			case 'h':
				ansi_cursor_hidden = 0;
				break;
			case 'l':
				ansi_cursor_hidden = 1;
				break;
			case 'm':
				if (num1 == 0) { /* reset swapped colors */
					if (ansi_colors_need_revert) {
						console_swap_colors();
						ansi_colors_need_revert = 0;
					}
				} else if (num1 == 7) { /* once swap colors */
					if (!ansi_colors_need_revert) {
						console_swap_colors();
						ansi_colors_need_revert = 1;
					}
				}
				break;
			}
			if (!ansi_cursor_hidden)
				CURSOR_SET;
		}
	} else {
		parse_putc(c);
	}
#else
	parse_putc(c);
#endif
1027 1028
	if (cfb_do_flush_cache)
		flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1029
}
wdenk's avatar
wdenk committed
1030

1031
static void cfb_video_puts(struct stdio_dev *dev, const char *s)
wdenk's avatar
wdenk committed
1032
{
1033
	int flush = cfb_do_flush_cache;
1034
	int count = strlen(s);
wdenk's avatar
wdenk committed
1035

1036 1037 1038
	/* temporarily disable cache flush */
	cfb_do_flush_cache = 0;

wdenk's avatar
wdenk committed
1039
	while (count--)
1040
		cfb_video_putc(dev, *s++);
1041 1042 1043 1044 1045

	if (flush) {
		cfb_do_flush_cache = flush;
		flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
	}
wdenk's avatar
wdenk committed
1046 1047
}

1048 1049 1050 1051 1052
/*
 * Do not enforce drivers (or board code) to provide empty
 * video_set_lut() if they do not support 8 bpp format.
 * Implement weak default function instead.
 */
Jeroen Hofstee's avatar
Jeroen Hofstee committed
1053
__weak void video_set_lut(unsigned int index, unsigned char r,
1054
		     unsigned char g, unsigned char b)
1055 1056
{
}
1057

1058
#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk's avatar
wdenk committed
1059 1060 1061 1062 1063 1064 1065

#define FILL_8BIT_332RGB(r,g,b)	{			\
	*fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6);	\
	fb ++;						\
}

#define FILL_15BIT_555RGB(r,g,b) {			\
1066 1067 1068 1069
	*(unsigned short *)fb =				\
		SWAP16((unsigned short)(((r>>3)<<10) |	\
					((g>>3)<<5)  |	\
					 (b>>3)));	\
wdenk's avatar
wdenk committed
1070 1071 1072 1073
	fb += 2;					\
}

#define FILL_16BIT_565RGB(r,g,b) {			\
1074 1075 1076 1077
	*(unsigned short *)fb =				\
		SWAP16((unsigned short)((((r)>>3)<<11)| \
					(((g)>>2)<<5) | \
					 ((b)>>3)));	\
wdenk's avatar
wdenk committed
1078 1079 1080 1081
	fb += 2;					\
}

#define FILL_32BIT_X888RGB(r,g,b) {			\
1082 1083
	*(u32 *)fb =				\
		SWAP32((unsigned int)(((r<<16) |	\
1084 1085
					(g<<8)  |	\
					 b)));		\
wdenk's avatar
wdenk committed
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
	fb += 4;					\
}

#ifdef VIDEO_FB_LITTLE_ENDIAN
#define FILL_24BIT_888RGB(r,g,b) {			\
	fb[0] = b;					\
	fb[1] = g;					\
	fb[2] = r;					\
	fb += 3;					\
}
#else
#define FILL_24BIT_888RGB(r,g,b) {			\
	fb[0] = r;					\
	fb[1] = g;					\
	fb[2] = b;					\
	fb += 3;					\
}
#endif

1105
#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1106
static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1107
{
1108 1109 1110 1111
	ushort *dst = (ushort *) fb;
	ushort color = (ushort) (((r >> 3) << 10) |
				 ((g >> 3) <<  5) |
				  (b >> 3));
1112 1113 1114 1115 1116 1117
	if (x & 1)
		*(--dst) = color;
	else
		*(++dst) = color;
}
#endif
wdenk's avatar
wdenk committed
1118

1119 1120 1121 1122 1123 1124 1125 1126
/*
 * RLE8 bitmap support
 */

#ifdef CONFIG_VIDEO_BMP_RLE8
/* Pre-calculated color table entry */
struct palette {
	union {
1127 1128 1129
		unsigned short w;	/* word */
		unsigned int dw;	/* double word */
	} ce;				/* color entry */
1130 1131 1132 1133 1134
};

/*
 * Helper to draw encoded/unencoded run.
 */
1135 1136
static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
			int cnt, int enc)
1137
{
1138
	ulong addr = (ulong) *fb;
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
	int *off;
	int enc_off = 1;
	int i;

	/*
	 * Setup offset of the color index in the bitmap.
	 * Color index of encoded run is at offset 1.
	 */
	off = enc ? &enc_off : &i;

	switch (VIDEO_DATA_FORMAT) {
	case GDF__8BIT_INDEX:
		for (i = 0; i < cnt; i++)
1152
			*(unsigned char *) addr++ = bm[*off];
1153 1154 1155 1156 1157
		break;
	case GDF_15BIT_555RGB:
	case GDF_16BIT_565RGB:
		/* differences handled while pre-calculating palette */
		for (i = 0; i < cnt; i++) {
1158
			*(unsigned short *) addr = p[bm[*off]].ce.w;
1159 1160 1161 1162 1163
			addr += 2;
		}
		break;
	case GDF_32BIT_X888RGB:
		for (i = 0; i < cnt; i++) {
1164
			*(u32 *) addr = p[bm[*off]].ce.dw;
1165 1166 1167 1168
			addr += 4;
		}
		break;
	}
1169
	*fb = (uchar *) addr;	/* return modified address */
1170 1171
}

1172
static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1173
			       int width, int height)
1174 1175 1176 1177 1178 1179 1180
{
	unsigned char *bm;
	unsigned char *fbp;
	unsigned int cnt, runlen;
	int decode = 1;
	int x, y, bpp, i, ncolors;
	struct palette p[256];
1181
	struct bmp_color_table_entry cte;
1182
	int green_shift, red_off;
1183
	int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1184
	int pixels = 0;
1185 1186 1187 1188 1189

	x = 0;
	y = __le32_to_cpu(img->header.height) - 1;
	ncolors = __le32_to_cpu(img->header.colors_used);
	bpp = VIDEO_PIXEL_SIZE;