wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004 |
| 3 | * Pierre Aubert, Staubli Faverges , <p.aubert@staubli.com> |
Timur Tabi | 5576092 | 2011-03-21 16:38:49 -0500 | [diff] [blame] | 4 | * Copyright 2011 Freescale Semiconductor, Inc. |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 5 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /************************************************************************ |
| 10 | Get Parameters for the video mode: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 11 | The default video mode can be defined in CONFIG_SYS_DEFAULT_VIDEO_MODE. |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 12 | If undefined, default video mode is set to 0x301 |
| 13 | Parameters can be set via the variable "videomode" in the environment. |
| 14 | 2 diferent ways are possible: |
| 15 | "videomode=301" - 301 is a hexadecimal number describing the VESA |
| 16 | mode. Following modes are implemented: |
| 17 | |
| 18 | Colors 640x480 800x600 1024x768 1152x864 1280x1024 |
| 19 | --------+--------------------------------------------- |
| 20 | 8 bits | 0x301 0x303 0x305 0x161 0x307 |
| 21 | 15 bits | 0x310 0x313 0x316 0x162 0x319 |
| 22 | 16 bits | 0x311 0x314 0x317 0x163 0x31A |
| 23 | 24 bits | 0x312 0x315 0x318 ? 0x31B |
| 24 | --------+--------------------------------------------- |
| 25 | "videomode=bootargs" |
| 26 | - the parameters are parsed from the bootargs. |
| 27 | The format is "NAME:VALUE,NAME:VALUE" etc. |
| 28 | Ex.: |
| 29 | "bootargs=video=ctfb:x:800,y:600,depth:16,pclk:25000" |
| 30 | Parameters not included in the list will be taken from |
| 31 | the default mode, which is one of the following: |
| 32 | mode:0 640x480x24 |
| 33 | mode:1 800x600x16 |
| 34 | mode:2 1024x768x8 |
| 35 | mode:3 960x720x24 |
| 36 | mode:4 1152x864x16 |
| 37 | mode:5 1280x1024x8 |
| 38 | |
| 39 | if "mode" is not provided within the parameter list, |
| 40 | mode:0 is assumed. |
| 41 | Following parameters are supported: |
| 42 | x xres = visible resolution horizontal |
| 43 | y yres = visible resolution vertical |
| 44 | pclk pixelclocks in pico sec |
| 45 | le left_marging time from sync to picture in pixelclocks |
| 46 | ri right_marging time from picture to sync in pixelclocks |
| 47 | up upper_margin time from sync to picture |
| 48 | lo lower_margin |
| 49 | hs hsync_len length of horizontal sync |
| 50 | vs vsync_len length of vertical sync |
| 51 | sync see FB_SYNC_* |
| 52 | vmode see FB_VMODE_* |
| 53 | depth Color depth in bits per pixel |
| 54 | All other parameters in the variable bootargs are ignored. |
| 55 | It is also possible to set the parameters direct in the |
| 56 | variable "videomode", or in another variable i.e. |
| 57 | "myvideo" and setting the variable "videomode=myvideo".. |
| 58 | ****************************************************************************/ |
| 59 | |
| 60 | #include <common.h> |
Timur Tabi | 5576092 | 2011-03-21 16:38:49 -0500 | [diff] [blame] | 61 | #include <linux/ctype.h> |
| 62 | |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 63 | #include "videomodes.h" |
| 64 | |
| 65 | const struct ctfb_vesa_modes vesa_modes[VESA_MODES_COUNT] = { |
| 66 | {0x301, RES_MODE_640x480, 8}, |
| 67 | {0x310, RES_MODE_640x480, 15}, |
| 68 | {0x311, RES_MODE_640x480, 16}, |
| 69 | {0x312, RES_MODE_640x480, 24}, |
| 70 | {0x303, RES_MODE_800x600, 8}, |
| 71 | {0x313, RES_MODE_800x600, 15}, |
| 72 | {0x314, RES_MODE_800x600, 16}, |
| 73 | {0x315, RES_MODE_800x600, 24}, |
| 74 | {0x305, RES_MODE_1024x768, 8}, |
| 75 | {0x316, RES_MODE_1024x768, 15}, |
| 76 | {0x317, RES_MODE_1024x768, 16}, |
| 77 | {0x318, RES_MODE_1024x768, 24}, |
| 78 | {0x161, RES_MODE_1152x864, 8}, |
| 79 | {0x162, RES_MODE_1152x864, 15}, |
| 80 | {0x163, RES_MODE_1152x864, 16}, |
| 81 | {0x307, RES_MODE_1280x1024, 8}, |
| 82 | {0x319, RES_MODE_1280x1024, 15}, |
| 83 | {0x31A, RES_MODE_1280x1024, 16}, |
| 84 | {0x31B, RES_MODE_1280x1024, 24}, |
| 85 | }; |
| 86 | const struct ctfb_res_modes res_mode_init[RES_MODES_COUNT] = { |
Hans de Goede | 226ac61 | 2014-12-19 10:38:49 +0100 | [diff] [blame^] | 87 | /* x y hz pixclk ps/kHz le ri up lo hs vs s vmode */ |
| 88 | { 640, 480, 60, 39721, 25180, 40, 24, 32, 11, 96, 2, 0, FB_VMODE_NONINTERLACED}, |
| 89 | { 800, 600, 60, 27778, 36000, 64, 24, 22, 1, 72, 2, 0, FB_VMODE_NONINTERLACED}, |
| 90 | {1024, 768, 60, 15384, 65000, 168, 8, 29, 3, 144, 4, 0, FB_VMODE_NONINTERLACED}, |
| 91 | { 960, 720, 80, 13100, 76335, 160, 40, 32, 8, 80, 4, 0, FB_VMODE_NONINTERLACED}, |
| 92 | {1152, 864, 60, 12004, 83300, 200, 64, 32, 16, 80, 4, 0, FB_VMODE_NONINTERLACED}, |
| 93 | {1280, 1024, 60, 9090, 110000, 200, 48, 26, 1, 184, 3, 0, FB_VMODE_NONINTERLACED}, |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | /************************************************************************ |
| 97 | * Get Parameters for the video mode: |
| 98 | */ |
| 99 | /********************************************************************* |
| 100 | * returns the length to the next seperator |
| 101 | */ |
| 102 | static int |
| 103 | video_get_param_len (char *start, char sep) |
| 104 | { |
| 105 | int i = 0; |
| 106 | while ((*start != 0) && (*start != sep)) { |
| 107 | start++; |
| 108 | i++; |
| 109 | } |
| 110 | return i; |
| 111 | } |
| 112 | |
| 113 | static int |
| 114 | video_search_param (char *start, char *param) |
| 115 | { |
| 116 | int len, totallen, i; |
| 117 | char *p = start; |
| 118 | len = strlen (param); |
| 119 | totallen = len + strlen (start); |
| 120 | for (i = 0; i < totallen; i++) { |
| 121 | if (strncmp (p++, param, len) == 0) |
| 122 | return (i); |
| 123 | } |
| 124 | return -1; |
| 125 | } |
| 126 | |
| 127 | /*************************************************************** |
| 128 | * Get parameter via the environment as it is done for the |
| 129 | * linux kernel i.e: |
| 130 | * video=ctfb:x:800,xv:1280,y:600,yv:1024,depth:16,mode:0,pclk:25000, |
| 131 | * le:56,ri:48,up:26,lo:5,hs:152,vs:2,sync:0,vmode:0,accel:0 |
| 132 | * |
| 133 | * penv is a pointer to the environment, containing the string, or the name of |
| 134 | * another environment variable. It could even be the term "bootargs" |
| 135 | */ |
| 136 | |
| 137 | #define GET_OPTION(name,var) \ |
| 138 | if(strncmp(p,name,strlen(name))==0) { \ |
| 139 | val_s=p+strlen(name); \ |
| 140 | var=simple_strtoul(val_s, NULL, 10); \ |
| 141 | } |
| 142 | |
| 143 | int video_get_params (struct ctfb_res_modes *pPar, char *penv) |
| 144 | { |
| 145 | char *p, *s, *val_s; |
Wolfgang Denk | 1b4d47f | 2011-11-04 15:55:14 +0000 | [diff] [blame] | 146 | int i = 0; |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 147 | int bpp; |
| 148 | int mode; |
Wolfgang Denk | 1b4d47f | 2011-11-04 15:55:14 +0000 | [diff] [blame] | 149 | |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 150 | /* first search for the environment containing the real param string */ |
| 151 | s = penv; |
Wolfgang Denk | 1b4d47f | 2011-11-04 15:55:14 +0000 | [diff] [blame] | 152 | |
| 153 | if ((p = getenv (s)) != NULL) |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 154 | s = p; |
Wolfgang Denk | 1b4d47f | 2011-11-04 15:55:14 +0000 | [diff] [blame] | 155 | |
| 156 | /* |
| 157 | * in case of the bootargs line, we have to start |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 158 | * after "video=ctfb:" |
| 159 | */ |
| 160 | i = video_search_param (s, "video=ctfb:"); |
| 161 | if (i >= 0) { |
| 162 | s += i; |
| 163 | s += strlen ("video=ctfb:"); |
| 164 | } |
| 165 | /* search for mode as a default value */ |
| 166 | p = s; |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 167 | mode = 0; /* default */ |
Wolfgang Denk | 1b4d47f | 2011-11-04 15:55:14 +0000 | [diff] [blame] | 168 | |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 169 | while ((i = video_get_param_len (p, ',')) != 0) { |
| 170 | GET_OPTION ("mode:", mode) |
| 171 | p += i; |
| 172 | if (*p != 0) |
| 173 | p++; /* skip ',' */ |
| 174 | } |
Wolfgang Denk | 1b4d47f | 2011-11-04 15:55:14 +0000 | [diff] [blame] | 175 | |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 176 | if (mode >= RES_MODES_COUNT) |
| 177 | mode = 0; |
Wolfgang Denk | 1b4d47f | 2011-11-04 15:55:14 +0000 | [diff] [blame] | 178 | |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 179 | *pPar = res_mode_init[mode]; /* copy default values */ |
| 180 | bpp = 24 - ((mode % 3) * 8); |
| 181 | p = s; /* restart */ |
Wolfgang Denk | 1b4d47f | 2011-11-04 15:55:14 +0000 | [diff] [blame] | 182 | |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 183 | while ((i = video_get_param_len (p, ',')) != 0) { |
| 184 | GET_OPTION ("x:", pPar->xres) |
| 185 | GET_OPTION ("y:", pPar->yres) |
Hans de Goede | 226ac61 | 2014-12-19 10:38:49 +0100 | [diff] [blame^] | 186 | GET_OPTION ("refresh:", pPar->refresh) |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 187 | GET_OPTION ("le:", pPar->left_margin) |
| 188 | GET_OPTION ("ri:", pPar->right_margin) |
| 189 | GET_OPTION ("up:", pPar->upper_margin) |
| 190 | GET_OPTION ("lo:", pPar->lower_margin) |
| 191 | GET_OPTION ("hs:", pPar->hsync_len) |
| 192 | GET_OPTION ("vs:", pPar->vsync_len) |
| 193 | GET_OPTION ("sync:", pPar->sync) |
| 194 | GET_OPTION ("vmode:", pPar->vmode) |
| 195 | GET_OPTION ("pclk:", pPar->pixclock) |
Hans de Goede | 226ac61 | 2014-12-19 10:38:49 +0100 | [diff] [blame^] | 196 | GET_OPTION ("pclk_khz:", pPar->pixclock_khz) |
wdenk | aea86e4 | 2004-03-23 22:53:55 +0000 | [diff] [blame] | 197 | GET_OPTION ("depth:", bpp) |
| 198 | p += i; |
| 199 | if (*p != 0) |
| 200 | p++; /* skip ',' */ |
| 201 | } |
| 202 | return bpp; |
| 203 | } |
Timur Tabi | 5576092 | 2011-03-21 16:38:49 -0500 | [diff] [blame] | 204 | |
| 205 | /* |
| 206 | * Parse the 'video-mode' environment variable |
| 207 | * |
| 208 | * Example: "video-mode=fslfb:1280x1024-32@60,monitor=dvi". See |
| 209 | * doc/README.video for more information on how to set the variable. |
| 210 | * |
| 211 | * @xres: returned value of X-resolution |
| 212 | * @yres: returned value of Y-resolution |
| 213 | * @depth: returned value of color depth |
| 214 | * @freq: returned value of monitor frequency |
| 215 | * @options: pointer to any remaining options, or NULL |
| 216 | * |
| 217 | * Returns 1 if valid values were found, 0 otherwise |
| 218 | */ |
| 219 | int video_get_video_mode(unsigned int *xres, unsigned int *yres, |
| 220 | unsigned int *depth, unsigned int *freq, const char **options) |
| 221 | { |
| 222 | char *p = getenv("video-mode"); |
| 223 | if (!p) |
| 224 | return 0; |
| 225 | |
| 226 | /* Skip over the driver name, which we don't care about. */ |
| 227 | p = strchr(p, ':'); |
| 228 | if (!p) |
| 229 | return 0; |
| 230 | |
| 231 | /* Get the X-resolution*/ |
| 232 | while (*p && !isdigit(*p)) |
| 233 | p++; |
| 234 | *xres = simple_strtoul(p, &p, 10); |
| 235 | if (!*xres) |
| 236 | return 0; |
| 237 | |
| 238 | /* Get the Y-resolution */ |
| 239 | while (*p && !isdigit(*p)) |
| 240 | p++; |
| 241 | *yres = simple_strtoul(p, &p, 10); |
| 242 | if (!*yres) |
| 243 | return 0; |
| 244 | |
| 245 | /* Get the depth */ |
| 246 | while (*p && !isdigit(*p)) |
| 247 | p++; |
| 248 | *depth = simple_strtoul(p, &p, 10); |
| 249 | if (!*depth) |
| 250 | return 0; |
| 251 | |
| 252 | /* Get the frequency */ |
| 253 | while (*p && !isdigit(*p)) |
| 254 | p++; |
| 255 | *freq = simple_strtoul(p, &p, 10); |
| 256 | if (!*freq) |
| 257 | return 0; |
| 258 | |
| 259 | /* Find the extra options, if any */ |
| 260 | p = strchr(p, ','); |
| 261 | *options = p ? p + 1 : NULL; |
| 262 | |
| 263 | return 1; |
| 264 | } |