All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] VGA text console support
@ 2013-04-07 15:36 Vladimir 'φ-coder/phcoder' Serbinenko
  2013-04-07 17:04 ` Wolfgang Denk
  2013-04-16  0:13 ` Simon Glass
  0 siblings, 2 replies; 4+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-04-07 15:36 UTC (permalink / raw)
  To: u-boot

Most coreboot users use just VGA text console, not graphics. Support it.
Remaining problem is that software and hardware cursor blinking superimpose.
I disabled software blinking locally but it's not part of this patch since
it's not done properly.

diff --git a/drivers/video/cfb_console.c b/drivers/video/cfb_console.c
index 61e1058..0c3c26d 100644
--- a/drivers/video/cfb_console.c
+++ b/drivers/video/cfb_console.c
@@ -180,11 +180,10 @@
 /*
  * some Macros
  */
-#define VIDEO_VISIBLE_COLS	(pGD->winSizeX)
-#define VIDEO_VISIBLE_ROWS	(pGD->winSizeY)
-#define VIDEO_PIXEL_SIZE	(pGD->gdfBytesPP)
+static int VIDEO_VISIBLE_COLS;
+static int VIDEO_VISIBLE_ROWS;
+static int VIDEO_PIXEL_SIZE;
 #define VIDEO_DATA_FORMAT	(pGD->gdfIndex)
-#define VIDEO_FB_ADRS		(pGD->frameAdrs)
 
 /*
  * Console device defines with i8042 keyboard controller
@@ -384,6 +383,7 @@ static int console_row;		/* cursor row */
 static u32 eorx, fgx, bgx;	/* color pats */
 
 static int cfb_do_flush_cache;
+static int vga_text;
 
 #ifdef CONFIG_CFB_CONSOLE_ANSI
 static char ansi_buf[10];
@@ -450,6 +450,18 @@ static void video_drawchars(int xx, int yy, unsigned char *s, int count)
 	u8 *cdat, *dest, *dest0;
 	int rows, offset, c;
 
+	if (vga_text)
+	{
+		xx /= VIDEO_FONT_WIDTH;
+		yy /= VIDEO_FONT_HEIGHT;
+		while (count--)
+		{
+			((uint16_t *)video_fb_address) [yy * 80 + xx] = 0x700 | *s++;
+			xx++;
+		}
+		return;
+	}
+
 	offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
 	dest0 = video_fb_address + offset;
 
@@ -644,6 +656,20 @@ static void video_invertchar(int xx, int yy)
 	}
 }
 
+static inline void
+cr_write (uint8_t val, uint8_t addr)
+{
+  outb (addr, 0x3d4);
+  outb (val, 0x3d5);
+}
+
+static inline uint8_t
+cr_read (uint8_t addr)
+{
+  outb (addr, 0x3d4);
+  return inb (0x3d5);
+}
+
 void console_cursor(int state)
 {
 #ifdef CONFIG_CONSOLE_TIME
@@ -667,6 +693,22 @@ void console_cursor(int state)
 	}
 #endif
 
+	if (vga_text)
+	{
+		uint8_t old;
+		unsigned int pos = console_row * 80 + console_col;
+		old = cr_read (0x0a);
+		if (state)
+			cr_write (old & ~0x20, 0x0a);
+		else
+			cr_write (old | 0x20, 0x0a);
+
+		cr_write (pos >> 8, 0x0e);
+		cr_write (pos & 0xFF, 0x0f);
+
+		return;
+	}
+
 	if (cursor_state != state) {
 		if (cursor_state) {
 			/* turn off the cursor */
@@ -704,6 +746,18 @@ static void memcpyl(int *d, int *s, int c)
 
 static void console_clear_line(int line, int begin, int end)
 {
+	if (vga_text)
+	{
+		begin /= VIDEO_FONT_WIDTH;
+		end /= VIDEO_FONT_WIDTH;
+		line /= VIDEO_FONT_HEIGHT;
+		for (; begin < end; begin++)
+		{
+			((uint16_t *)video_fb_address) [line * 80 + begin] = 0x700 | ' ';
+		}
+		return;
+	}
+
 #ifdef VIDEO_HW_RECTFILL
 	video_hw_rectfill(VIDEO_PIXEL_SIZE,		/* bytes per pixel */
 			  VIDEO_FONT_WIDTH * begin,	/* dest pos x */
@@ -742,6 +796,15 @@ static void console_clear_line(int line, int begin, int end)
 static void console_scrollup(void)
 {
 	/* copy up rows ignoring the first one */
+	if (vga_text)
+	{
+		int i;
+		memcpyl(video_fb_address, ((int32_t *)video_fb_address) + 80 / 2,
+			(80 * 24 * 2) >> 2);
+		for (i = 0; i < 80; i++)
+			((uint16_t *)video_fb_address) [24 * 80 + i] = 0x700 | ' ';
+		return;
+	}
 
 #ifdef VIDEO_HW_BITBLT
 	video_hw_bitblt(VIDEO_PIXEL_SIZE,	/* bytes per pixel */
@@ -779,6 +842,15 @@ static void console_back(void)
 
 static void console_clear(void)
 {
+	if (vga_text)
+	{
+		int i;
+		for (i = 0; i < 80 * 25; i++)
+			((uint16_t *)video_fb_address) [i] = 0x700 | ' ';
+
+		return;
+	}
+
 #ifdef VIDEO_HW_RECTFILL
 	video_hw_rectfill(VIDEO_PIXEL_SIZE,	/* bytes per pixel */
 			  0,			/* dest pos x */
@@ -1446,6 +1518,9 @@ int video_display_bitmap(ulong bmp_image, int x, int y)
 
 	WATCHDOG_RESET();
 
+	if (vga_text)
+		return 0;
+
 	if (!((bmp->header.signature[0] == 'B') &&
 	      (bmp->header.signature[1] == 'M'))) {
 
@@ -1846,6 +1921,9 @@ static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
 	unsigned char *source;
 	unsigned char *dest;
 
+	if (vga_text)
+		return;
+
 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
 	if (x == BMP_ALIGN_CENTER)
 		x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
@@ -2113,9 +2191,24 @@ static int video_init(void)
 
 	pGD = video_hw_init();
 	if (pGD == NULL)
-		return -1;
+	{
+		vga_text = 1;
+		video_fb_address = (void *) 0xb8000;
+		cfb_do_flush_cache = 0;
+		console_col = 0;
+		console_row = 0;
+		video_logo_height = 0;
+		VIDEO_VISIBLE_ROWS = 25 * VIDEO_FONT_HEIGHT;
+		VIDEO_VISIBLE_COLS = 80 * VIDEO_FONT_WIDTH;
+		VIDEO_PIXEL_SIZE = 2;
+		return 0;
+	}
+
+	video_fb_address = (void *) pGD->frameAdrs;
+	VIDEO_VISIBLE_ROWS = pGD->winSizeY;
+	VIDEO_VISIBLE_COLS = pGD->winSizeX;
+	VIDEO_PIXEL_SIZE = (pGD->gdfBytesPP);
 
-	video_fb_address = (void *) VIDEO_FB_ADRS;
 #ifdef CONFIG_VIDEO_HW_CURSOR
 	video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
 #endif
@@ -2295,6 +2388,15 @@ void video_clear(void)
 {
 	if (!video_fb_address)
 		return;
+
+	if (vga_text)
+	{
+		int i;
+		for (i = 0; i < 80 * 25; i++)
+			((uint16_t *)video_fb_address) [i] = 0x700 | ' ';
+		return;
+	}
+
 #ifdef VIDEO_HW_RECTFILL
 	video_hw_rectfill(VIDEO_PIXEL_SIZE,	/* bytes per pixel */
 			  0,			/* dest pos x */

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 294 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130407/912fe9f5/attachment.pgp>

^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [U-Boot] [PATCH] VGA text console support
@ 2013-04-07 17:07 Wolfgang Denk
  0 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Denk @ 2013-04-07 17:07 UTC (permalink / raw)
  To: u-boot

Dear Vladimir '?-coder/phcoder' Serbinenko,

I wrote:

> I cannot comment on the actual technical content of your patches, but
> here are a few formal comments; I highly recommend to study
> http://www.denx.de/wiki/U-Boot/Patches
...

Oops.  Sent to quickly.

Please ALWAYS make sure to run your patches through checkpatch - ther
are a number of issues with your coding style:

ERROR: that open brace { should be on the previous line
#147: FILE: drivers/video/cfb_console.c:453:
+	if (vga_text)
+	{

ERROR: that open brace { should be on the previous line
#151: FILE: drivers/video/cfb_console.c:457:
+		while (count--)
+		{

WARNING: line over 80 characters
#153: FILE: drivers/video/cfb_console.c:459:
+			((uint16_t *)video_fb_address) [yy * 80 + xx] = 0x700 | *s++;

ERROR: space prohibited before open square bracket '['
#153: FILE: drivers/video/cfb_console.c:459:
+			((uint16_t *)video_fb_address) [yy * 80 + xx] = 0x700 | *s++;

WARNING: space prohibited between function name and open parenthesis '('
#167: FILE: drivers/video/cfb_console.c:660:
+cr_write (uint8_t val, uint8_t addr)

WARNING: please, no spaces at the start of a line
#169: FILE: drivers/video/cfb_console.c:662:
+  outb (addr, 0x3d4);$

WARNING: space prohibited between function name and open parenthesis '('
#169: FILE: drivers/video/cfb_console.c:662:
+  outb (addr, 0x3d4);

WARNING: please, no spaces at the start of a line
#170: FILE: drivers/video/cfb_console.c:663:
+  outb (val, 0x3d5);$

WARNING: space prohibited between function name and open parenthesis '('
#170: FILE: drivers/video/cfb_console.c:663:
+  outb (val, 0x3d5);

WARNING: space prohibited between function name and open parenthesis '('
#174: FILE: drivers/video/cfb_console.c:667:
+cr_read (uint8_t addr)

WARNING: please, no spaces at the start of a line
#176: FILE: drivers/video/cfb_console.c:669:
+  outb (addr, 0x3d4);$

WARNING: space prohibited between function name and open parenthesis '('
#176: FILE: drivers/video/cfb_console.c:669:
+  outb (addr, 0x3d4);

WARNING: please, no spaces at the start of a line
#177: FILE: drivers/video/cfb_console.c:670:
+  return inb (0x3d5);$

WARNING: space prohibited between function name and open parenthesis '('
#177: FILE: drivers/video/cfb_console.c:670:
+  return inb (0x3d5);

ERROR: that open brace { should be on the previous line
#187: FILE: drivers/video/cfb_console.c:696:
+	if (vga_text)
+	{

WARNING: space prohibited between function name and open parenthesis '('
#191: FILE: drivers/video/cfb_console.c:700:
+		old = cr_read (0x0a);

WARNING: space prohibited between function name and open parenthesis '('
#193: FILE: drivers/video/cfb_console.c:702:
+			cr_write (old & ~0x20, 0x0a);

WARNING: space prohibited between function name and open parenthesis '('
#195: FILE: drivers/video/cfb_console.c:704:
+			cr_write (old | 0x20, 0x0a);

WARNING: space prohibited between function name and open parenthesis '('
#197: FILE: drivers/video/cfb_console.c:706:
+		cr_write (pos >> 8, 0x0e);

WARNING: space prohibited between function name and open parenthesis '('
#198: FILE: drivers/video/cfb_console.c:707:
+		cr_write (pos & 0xFF, 0x0f);

ERROR: that open brace { should be on the previous line
#210: FILE: drivers/video/cfb_console.c:749:
+	if (vga_text)
+	{

ERROR: that open brace { should be on the previous line
#215: FILE: drivers/video/cfb_console.c:754:
+		for (; begin < end; begin++)
+		{

WARNING: line over 80 characters
#217: FILE: drivers/video/cfb_console.c:756:
+			((uint16_t *)video_fb_address) [line * 80 + begin] = 0x700 | ' ';

ERROR: space prohibited before open square bracket '['
#217: FILE: drivers/video/cfb_console.c:756:
+			((uint16_t *)video_fb_address) [line * 80 + begin] = 0x700 | ' ';

ERROR: that open brace { should be on the previous line
#229: FILE: drivers/video/cfb_console.c:799:
+	if (vga_text)
+	{

WARNING: line over 80 characters
#232: FILE: drivers/video/cfb_console.c:802:
+		memcpyl(video_fb_address, ((int32_t *)video_fb_address) + 80 / 2,

WARNING: line over 80 characters
#235: FILE: drivers/video/cfb_console.c:805:
+			((uint16_t *)video_fb_address) [24 * 80 + i] = 0x700 | ' ';

ERROR: space prohibited before open square bracket '['
#235: FILE: drivers/video/cfb_console.c:805:
+			((uint16_t *)video_fb_address) [24 * 80 + i] = 0x700 | ' ';

ERROR: that open brace { should be on the previous line
#245: FILE: drivers/video/cfb_console.c:845:
+	if (vga_text)
+	{

ERROR: space prohibited before open square bracket '['
#249: FILE: drivers/video/cfb_console.c:849:
+			((uint16_t *)video_fb_address) [i] = 0x700 | ' ';

ERROR: that open brace { should be on the previous line
#280: FILE: drivers/video/cfb_console.c:2193:
 	if (pGD == NULL)
+	{

WARNING: Avoid CamelCase: <pGD->frameAdrs>
#295: FILE: drivers/video/cfb_console.c:2207:
+	video_fb_address = (void *) pGD->frameAdrs;

WARNING: Avoid CamelCase: <pGD->winSizeY>
#296: FILE: drivers/video/cfb_console.c:2208:
+	VIDEO_VISIBLE_ROWS = pGD->winSizeY;

WARNING: Avoid CamelCase: <pGD->winSizeX>
#297: FILE: drivers/video/cfb_console.c:2209:
+	VIDEO_VISIBLE_COLS = pGD->winSizeX;

WARNING: Avoid CamelCase: <pGD->gdfBytesPP>
#298: FILE: drivers/video/cfb_console.c:2210:
+	VIDEO_PIXEL_SIZE = (pGD->gdfBytesPP);

ERROR: that open brace { should be on the previous line
#309: FILE: drivers/video/cfb_console.c:2392:
+	if (vga_text)
+	{

ERROR: space prohibited before open square bracket '['
#313: FILE: drivers/video/cfb_console.c:2396:
+			((uint16_t *)video_fb_address) [i] = 0x700 | ' ';

ERROR: Missing Signed-off-by: line(s)

total: 15 errors, 23 warnings, 188 lines checked

/tmp/patch has style problems, please review.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It took him several minutes to understand any new idea  put  to  him,
and  this is a very valuable trait in a leader, because anything any-
one is still trying to explain to you after two minutes  is  probably
important  and anything they give up after a mere minute or so is al-
most certainly something they shouldn't have been bothering you  with
in the first place.                   - Terry Pratchett, _Reaper Man_

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-04-16  0:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-07 15:36 [U-Boot] [PATCH] VGA text console support Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-07 17:04 ` Wolfgang Denk
2013-04-16  0:13 ` Simon Glass
  -- strict thread matches above, loose matches on Subject: below --
2013-04-07 17:07 Wolfgang Denk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.