public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] drv_video_init(): simplify logic
Date: Fri, 15 May 2009 10:07:42 +0200	[thread overview]
Message-ID: <1242374863-11781-2-git-send-email-wd@denx.de> (raw)
In-Reply-To: <1242369514-24243-1-git-send-email-sr@denx.de>

Simplify nesting of drv_video_init() and use a consistent way of
indicating failure / success. Before, it took me some time to realize
which of the returns was due to an error condition and which of them
indicated success.

Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Anatolij Gustschin <agust@denx.de>
---
 drivers/video/cfb_console.c |   69 ++++++++++++++++++-------------------------
 1 files changed, 29 insertions(+), 40 deletions(-)

diff --git a/drivers/video/cfb_console.c b/drivers/video/cfb_console.c
index 5ee2314..f744d57 100644
--- a/drivers/video/cfb_console.c
+++ b/drivers/video/cfb_console.c
@@ -1335,48 +1335,37 @@ int drv_video_init (void)
 	int skip_dev_init;
 	device_t console_dev;
 
-	skip_dev_init = 0;
-
 	/* Init video chip - returns with framebuffer cleared */
-	if (video_init () == -1)
-		skip_dev_init = 1;
+	skip_dev_init = (video_init () == -1)
 
-#ifdef CONFIG_VGA_AS_SINGLE_DEVICE
-	/* Devices VGA and Keyboard will be assigned seperately */
-	/* Init vga device */
-	if (!skip_dev_init) {
-		memset (&console_dev, 0, sizeof (console_dev));
-		strcpy (console_dev.name, "vga");
-		console_dev.ext = DEV_EXT_VIDEO;	/* Video extensions */
-		console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
-		console_dev.putc = video_putc;	/* 'putc' function */
-		console_dev.puts = video_puts;	/* 'puts' function */
-		console_dev.tstc = NULL;	/* 'tstc' function */
-		console_dev.getc = NULL;	/* 'getc' function */
-
-		if (device_register (&console_dev) == 0)
-			return 1;
-	}
-#else
+#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
 	PRINTD ("KBD: Keyboard init ...\n");
-	if (VIDEO_KBD_INIT_FCT == -1)
-		skip_dev_init = 1;
-
-	/* Init console device */
-	if (!skip_dev_init) {
-		memset (&console_dev, 0, sizeof (console_dev));
-		strcpy (console_dev.name, "vga");
-		console_dev.ext = DEV_EXT_VIDEO;	/* Video extensions */
-		console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
-		console_dev.putc = video_putc;	/* 'putc' function */
-		console_dev.puts = video_puts;	/* 'puts' function */
-		console_dev.tstc = VIDEO_TSTC_FCT;	/* 'tstc' function */
-		console_dev.getc = VIDEO_GETC_FCT;	/* 'getc' function */
-
-		if (device_register (&console_dev) == 0)
-			return 1;
-	}
+	skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
+#endif
+
+	if (skip_dev_init)
+		return 0;
+
+	/* Init vga device */
+	memset (&console_dev, 0, sizeof (console_dev));
+	strcpy (console_dev.name, "vga");
+	console_dev.ext = DEV_EXT_VIDEO;	/* Video extensions */
+	console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
+	console_dev.putc = video_putc;	/* 'putc' function */
+	console_dev.puts = video_puts;	/* 'puts' function */
+	console_dev.tstc = NULL;	/* 'tstc' function */
+	console_dev.getc = NULL;	/* 'getc' function */
+
+#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
+	/* Also init console device */
+	console_dev.flags |= DEV_FLAGS_INPUT;
+	console_dev.tstc = VIDEO_TSTC_FCT;	/* 'tstc' function */
+	console_dev.getc = VIDEO_GETC_FCT;	/* 'getc' function */
 #endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
-	/* No console dev available */
-	return 0;
+
+	if (device_register (&console_dev) != 0)
+		return 0;
+
+	/* Return success */
+	return 1;
 }
-- 
1.6.0.6

  parent reply	other threads:[~2009-05-15  8:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-15  6:38 [U-Boot] [PATCH] video: Add an option to skip video initialization Stefan Roese
2009-05-15  8:07 ` [U-Boot] [PATCH 0/2] drv_video_init() cleanup / extension Wolfgang Denk
2009-05-15  8:07 ` Wolfgang Denk [this message]
2009-05-15 23:20   ` [U-Boot] [PATCH 1/2] drv_video_init(): simplify logic Anatolij Gustschin
2009-05-16  7:28     ` Wolfgang Denk
2009-05-15  8:07 ` [U-Boot] [PATCH 2/2] video: Add an option to skip video initialization Wolfgang Denk
2009-05-15  8:22   ` Jean-Christophe PLAGNIOL-VILLARD
2009-05-15 10:35     ` Anatolij Gustschin
2009-05-15 12:37       ` Jean-Christophe PLAGNIOL-VILLARD
2009-05-15 13:18         ` Anatolij Gustschin
2009-05-15 13:50           ` Wolfgang Denk
2009-05-15 13:56             ` Jean-Christophe PLAGNIOL-VILLARD
2009-05-15 15:20               ` Wolfgang Denk
2009-05-15 13:50         ` Wolfgang Denk
2009-05-15 10:41   ` Anatolij Gustschin
2009-05-15 10:48     ` Stefan Roese
2009-05-15 23:23   ` Anatolij Gustschin
2009-05-15 23:38 ` [U-Boot] [PATCH] " Anatolij Gustschin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1242374863-11781-2-git-send-email-wd@denx.de \
    --to=wd@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox