videomodes.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * (C) Copyright 2004
  3. * Pierre Aubert, Staubli Faverges , <p.aubert@staubli.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /************************************************************************
  24. Get Parameters for the video mode:
  25. The default video mode can be defined in CFG_DEFAULT_VIDEO_MODE.
  26. If undefined, default video mode is set to 0x301
  27. Parameters can be set via the variable "videomode" in the environment.
  28. 2 diferent ways are possible:
  29. "videomode=301" - 301 is a hexadecimal number describing the VESA
  30. mode. Following modes are implemented:
  31. Colors 640x480 800x600 1024x768 1152x864 1280x1024
  32. --------+---------------------------------------------
  33. 8 bits | 0x301 0x303 0x305 0x161 0x307
  34. 15 bits | 0x310 0x313 0x316 0x162 0x319
  35. 16 bits | 0x311 0x314 0x317 0x163 0x31A
  36. 24 bits | 0x312 0x315 0x318 ? 0x31B
  37. --------+---------------------------------------------
  38. "videomode=bootargs"
  39. - the parameters are parsed from the bootargs.
  40. The format is "NAME:VALUE,NAME:VALUE" etc.
  41. Ex.:
  42. "bootargs=video=ctfb:x:800,y:600,depth:16,pclk:25000"
  43. Parameters not included in the list will be taken from
  44. the default mode, which is one of the following:
  45. mode:0 640x480x24
  46. mode:1 800x600x16
  47. mode:2 1024x768x8
  48. mode:3 960x720x24
  49. mode:4 1152x864x16
  50. mode:5 1280x1024x8
  51. if "mode" is not provided within the parameter list,
  52. mode:0 is assumed.
  53. Following parameters are supported:
  54. x xres = visible resolution horizontal
  55. y yres = visible resolution vertical
  56. pclk pixelclocks in pico sec
  57. le left_marging time from sync to picture in pixelclocks
  58. ri right_marging time from picture to sync in pixelclocks
  59. up upper_margin time from sync to picture
  60. lo lower_margin
  61. hs hsync_len length of horizontal sync
  62. vs vsync_len length of vertical sync
  63. sync see FB_SYNC_*
  64. vmode see FB_VMODE_*
  65. depth Color depth in bits per pixel
  66. All other parameters in the variable bootargs are ignored.
  67. It is also possible to set the parameters direct in the
  68. variable "videomode", or in another variable i.e.
  69. "myvideo" and setting the variable "videomode=myvideo"..
  70. ****************************************************************************/
  71. #include <common.h>
  72. #include "videomodes.h"
  73. const struct ctfb_vesa_modes vesa_modes[VESA_MODES_COUNT] = {
  74. {0x301, RES_MODE_640x480, 8},
  75. {0x310, RES_MODE_640x480, 15},
  76. {0x311, RES_MODE_640x480, 16},
  77. {0x312, RES_MODE_640x480, 24},
  78. {0x303, RES_MODE_800x600, 8},
  79. {0x313, RES_MODE_800x600, 15},
  80. {0x314, RES_MODE_800x600, 16},
  81. {0x315, RES_MODE_800x600, 24},
  82. {0x305, RES_MODE_1024x768, 8},
  83. {0x316, RES_MODE_1024x768, 15},
  84. {0x317, RES_MODE_1024x768, 16},
  85. {0x318, RES_MODE_1024x768, 24},
  86. {0x161, RES_MODE_1152x864, 8},
  87. {0x162, RES_MODE_1152x864, 15},
  88. {0x163, RES_MODE_1152x864, 16},
  89. {0x307, RES_MODE_1280x1024, 8},
  90. {0x319, RES_MODE_1280x1024, 15},
  91. {0x31A, RES_MODE_1280x1024, 16},
  92. {0x31B, RES_MODE_1280x1024, 24},
  93. };
  94. const struct ctfb_res_modes res_mode_init[RES_MODES_COUNT] = {
  95. /* x y pixclk le ri up lo hs vs s vmode */
  96. {640, 480, 39721, 40, 24, 32, 11, 96, 2, 0, FB_VMODE_NONINTERLACED},
  97. {800, 600, 27778, 64, 24, 22, 1, 72, 2, 0, FB_VMODE_NONINTERLACED},
  98. {1024, 768, 15384, 168, 8, 29, 3, 144, 4, 0, FB_VMODE_NONINTERLACED},
  99. {960, 720, 13100, 160, 40, 32, 8, 80, 4, 0, FB_VMODE_NONINTERLACED},
  100. {1152, 864, 12004, 200, 64, 32, 16, 80, 4, 0, FB_VMODE_NONINTERLACED},
  101. {1280, 1024, 9090, 200, 48, 26, 1, 184, 3, 0, FB_VMODE_NONINTERLACED},
  102. };
  103. /************************************************************************
  104. * Get Parameters for the video mode:
  105. */
  106. /*********************************************************************
  107. * returns the length to the next seperator
  108. */
  109. static int
  110. video_get_param_len (char *start, char sep)
  111. {
  112. int i = 0;
  113. while ((*start != 0) && (*start != sep)) {
  114. start++;
  115. i++;
  116. }
  117. return i;
  118. }
  119. static int
  120. video_search_param (char *start, char *param)
  121. {
  122. int len, totallen, i;
  123. char *p = start;
  124. len = strlen (param);
  125. totallen = len + strlen (start);
  126. for (i = 0; i < totallen; i++) {
  127. if (strncmp (p++, param, len) == 0)
  128. return (i);
  129. }
  130. return -1;
  131. }
  132. /***************************************************************
  133. * Get parameter via the environment as it is done for the
  134. * linux kernel i.e:
  135. * video=ctfb:x:800,xv:1280,y:600,yv:1024,depth:16,mode:0,pclk:25000,
  136. * le:56,ri:48,up:26,lo:5,hs:152,vs:2,sync:0,vmode:0,accel:0
  137. *
  138. * penv is a pointer to the environment, containing the string, or the name of
  139. * another environment variable. It could even be the term "bootargs"
  140. */
  141. #define GET_OPTION(name,var) \
  142. if(strncmp(p,name,strlen(name))==0) { \
  143. val_s=p+strlen(name); \
  144. var=simple_strtoul(val_s, NULL, 10); \
  145. }
  146. int video_get_params (struct ctfb_res_modes *pPar, char *penv)
  147. {
  148. char *p, *s, *val_s;
  149. int i = 0, t;
  150. int bpp;
  151. int mode;
  152. /* first search for the environment containing the real param string */
  153. s = penv;
  154. if ((p = getenv (s)) != NULL) {
  155. s = p;
  156. }
  157. /* in case of the bootargs line, we have to start
  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;
  167. t = 0;
  168. mode = 0; /* default */
  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. }
  175. if (mode >= RES_MODES_COUNT)
  176. mode = 0;
  177. *pPar = res_mode_init[mode]; /* copy default values */
  178. bpp = 24 - ((mode % 3) * 8);
  179. p = s; /* restart */
  180. while ((i = video_get_param_len (p, ',')) != 0) {
  181. GET_OPTION ("x:", pPar->xres)
  182. GET_OPTION ("y:", pPar->yres)
  183. GET_OPTION ("le:", pPar->left_margin)
  184. GET_OPTION ("ri:", pPar->right_margin)
  185. GET_OPTION ("up:", pPar->upper_margin)
  186. GET_OPTION ("lo:", pPar->lower_margin)
  187. GET_OPTION ("hs:", pPar->hsync_len)
  188. GET_OPTION ("vs:", pPar->vsync_len)
  189. GET_OPTION ("sync:", pPar->sync)
  190. GET_OPTION ("vmode:", pPar->vmode)
  191. GET_OPTION ("pclk:", pPar->pixclock)
  192. GET_OPTION ("depth:", bpp)
  193. p += i;
  194. if (*p != 0)
  195. p++; /* skip ',' */
  196. }
  197. return bpp;
  198. }