]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/video/videomodes.c
cfb_console: flush FB cache at end of public functions
[karo-tx-uboot.git] / drivers / video / videomodes.c
index d27ce1d2cd2a45c400df753233be499583c92774..ef9bc4c08284c1d3e3d2d23e4a585ccbbac677b2 100644 (file)
@@ -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] = {
@@ -156,15 +159,18 @@ video_search_param (char *start, char *param)
 int video_get_params (struct ctfb_res_modes *pPar, char *penv)
 {
        char *p, *s, *val_s;
-       int i = 0, t;
+       int i = 0;
        int bpp;
        int mode;
+
        /* first search for the environment containing the real param string */
        s = penv;
-       if ((p = getenv (s)) != NULL) {
+
+       if ((p = getenv (s)) != NULL)
                s = p;
-       }
-       /* in case of the bootargs line, we have to start
+
+       /*
+        * in case of the bootargs line, we have to start
         * after "video=ctfb:"
         */
        i = video_search_param (s, "video=ctfb:");
@@ -174,19 +180,22 @@ int video_get_params (struct ctfb_res_modes *pPar, char *penv)
        }
        /* search for mode as a default value */
        p = s;
-       t = 0;
        mode = 0;               /* default */
+
        while ((i = video_get_param_len (p, ',')) != 0) {
                GET_OPTION ("mode:", mode)
                        p += i;
                if (*p != 0)
                        p++;    /* skip ',' */
        }
+
        if (mode >= RES_MODES_COUNT)
                mode = 0;
+
        *pPar = res_mode_init[mode];    /* copy default values */
        bpp = 24 - ((mode % 3) * 8);
        p = s;                  /* restart */
+
        while ((i = video_get_param_len (p, ',')) != 0) {
                GET_OPTION ("x:", pPar->xres)
                        GET_OPTION ("y:", pPar->yres)
@@ -206,3 +215,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;
+}