diff mbox

[U-Boot,1/2] video: parse the video-mode environment variable

Message ID 1300743530-6829-1-git-send-email-timur@freescale.com
State Accepted
Commit a5dbdc81ea70daa04e49eb0004a0441131a029c6
Delegated to: Anatolij Gustschin
Headers show

Commit Message

Timur Tabi March 21, 2011, 9:38 p.m. UTC
Add function video_get_video_mode(), which parses the "video-mode" environment
variable and returns each of its components.  The format matches the video=
command-line option used for Linux:

	video-mode=<driver>:<xres>x<yres>-<depth>@<freq><,option=string>

	<driver> The video driver, ignored by U-Boot
	<xres> The X resolution (in pixels) to use.
	<yres> The Y resolution (in pixels) to use.
	<depth> The color depth (in bits) to use.
	<freq> The frequency (in Hz) to use.
	<options> A comma-separated list of device-specific options

Signed-off-by: Timur Tabi <timur@freescale.com>
---
 doc/README.video           |   19 +++++++++++++
 drivers/video/videomodes.c |   64 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/video/videomodes.h |    3 ++
 3 files changed, 86 insertions(+), 0 deletions(-)

Comments

Anatolij Gustschin April 28, 2011, 8:09 p.m. UTC | #1
On Mon, 21 Mar 2011 16:38:49 -0500
Timur Tabi <timur@freescale.com> wrote:

> Add function video_get_video_mode(), which parses the "video-mode" environment
> variable and returns each of its components.  The format matches the video=
> command-line option used for Linux:
> 
> 	video-mode=<driver>:<xres>x<yres>-<depth>@<freq><,option=string>
> 
> 	<driver> The video driver, ignored by U-Boot
> 	<xres> The X resolution (in pixels) to use.
> 	<yres> The Y resolution (in pixels) to use.
> 	<depth> The color depth (in bits) to use.
> 	<freq> The frequency (in Hz) to use.
> 	<options> A comma-separated list of device-specific options
> 
> Signed-off-by: Timur Tabi <timur@freescale.com>
> ---
>  doc/README.video           |   19 +++++++++++++
>  drivers/video/videomodes.c |   64 ++++++++++++++++++++++++++++++++++++++++++++
>  drivers/video/videomodes.h |    3 ++
>  3 files changed, 86 insertions(+), 0 deletions(-)

appied to u-boot-video/master. Thanks!

Anatolij
diff mbox

Patch

diff --git a/doc/README.video b/doc/README.video
index 34e199c..0c04bea 100644
--- a/doc/README.video
+++ b/doc/README.video
@@ -28,3 +28,22 @@  The driver has been tested with the following configurations:
 
 - MPC823FADS with AD7176 on a PAL TV (YCbYCr)	- arsenio@tin.it
 - GENIETV    with AD7177 on a PAL TV (YCbYCr)	- arsenio@tin.it
+
+
+"video-mode" environment variable
+===============================
+
+The 'video-mode' environment variable can be used to enable and configure
+some video drivers.  The format matches the video= command-line option used
+for Linux:
+
+	video-mode=<driver>:<xres>x<yres>-<depth>@<freq><,option=string>
+
+	<driver>	The video driver name, ignored by U-Boot
+	<xres>		The X resolution (in pixels) to use.
+	<yres>		The Y resolution (in pixels) to use.
+	<depth>		The color depth (in bits) to use.
+	<freq>		The frequency (in Hz) to use.
+	<options>	A comma-separated list of device-specific options
+
+Example: video-mode=fslfb:1280x1024-32@60,monitor=dvi
diff --git a/drivers/video/videomodes.c b/drivers/video/videomodes.c
index d27ce1d..6fe5811 100644
--- a/drivers/video/videomodes.c
+++ b/drivers/video/videomodes.c
@@ -1,6 +1,7 @@ 
 /*
  * (C) Copyright 2004
  * Pierre Aubert, Staubli Faverges , <p.aubert@staubli.com>
+ * Copyright 2011 Freescale Semiconductor, Inc.
  *
  * See file CREDITS for list of people who contributed to this
  * project.
@@ -73,6 +74,8 @@ 
 ****************************************************************************/
 
 #include <common.h>
+#include <linux/ctype.h>
+
 #include "videomodes.h"
 
 const struct ctfb_vesa_modes vesa_modes[VESA_MODES_COUNT] = {
@@ -206,3 +209,64 @@  int video_get_params (struct ctfb_res_modes *pPar, char *penv)
 	}
 	return bpp;
 }
+
+/*
+ * Parse the 'video-mode' environment variable
+ *
+ * Example: "video-mode=fslfb:1280x1024-32@60,monitor=dvi".  See
+ * doc/README.video for more information on how to set the variable.
+ *
+ * @xres: returned value of X-resolution
+ * @yres: returned value of Y-resolution
+ * @depth: returned value of color depth
+ * @freq: returned value of monitor frequency
+ * @options: pointer to any remaining options, or NULL
+ *
+ * Returns 1 if valid values were found, 0 otherwise
+ */
+int video_get_video_mode(unsigned int *xres, unsigned int *yres,
+	unsigned int *depth, unsigned int *freq, const char **options)
+{
+	char *p = getenv("video-mode");
+	if (!p)
+		return 0;
+
+	/* Skip over the driver name, which we don't care about. */
+	p = strchr(p, ':');
+	if (!p)
+		return 0;
+
+	/* Get the X-resolution*/
+	while (*p && !isdigit(*p))
+		p++;
+	*xres = simple_strtoul(p, &p, 10);
+	if (!*xres)
+		return 0;
+
+	/* Get the Y-resolution */
+	while (*p && !isdigit(*p))
+		p++;
+	*yres = simple_strtoul(p, &p, 10);
+	if (!*yres)
+		return 0;
+
+	/* Get the depth */
+	while (*p && !isdigit(*p))
+		p++;
+	*depth = simple_strtoul(p, &p, 10);
+	if (!*depth)
+		return 0;
+
+	/* Get the frequency */
+	while (*p && !isdigit(*p))
+		p++;
+	*freq = simple_strtoul(p, &p, 10);
+	if (!*freq)
+		return 0;
+
+	/* Find the extra options, if any */
+	p = strchr(p, ',');
+	*options = p ? p + 1 : NULL;
+
+	return 1;
+}
diff --git a/drivers/video/videomodes.h b/drivers/video/videomodes.h
index 0d7c335..e546ab4 100644
--- a/drivers/video/videomodes.h
+++ b/drivers/video/videomodes.h
@@ -86,3 +86,6 @@  extern const struct ctfb_vesa_modes vesa_modes[];
 extern const struct ctfb_res_modes res_mode_init[];
 
 int video_get_params (struct ctfb_res_modes *pPar, char *penv);
+
+int video_get_video_mode(unsigned int *xres, unsigned int *yres,
+	unsigned int *depth, unsigned int *freq, const char **options);