blob: 590918aabc9af9f2ab12ae142ec5dd5554bc42e8 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Erik Andersen1c5b2581999-12-16 20:59:36 +00002/*
3 * Mini fbset implementation for busybox
4 *
5 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
6 *
Bernhard Reutner-Fischerdac7ff12006-04-12 17:55:51 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Erik Andersen1c5b2581999-12-16 20:59:36 +00008 *
9 * This is a from-scratch implementation of fbset; but the de facto fbset
10 * implementation was a good reference. fbset (original) is released under
Eric Andersenc7bda1c2004-03-15 08:29:22 +000011 * the GPL, and is (c) 1995-1999 by:
Erik Andersen1c5b2581999-12-16 20:59:36 +000012 * Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
13 */
14
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000015#include "libbb.h"
Erik Andersen1c5b2581999-12-16 20:59:36 +000016
Eric Andersen5f284552003-11-14 03:11:29 +000017#define DEFAULTFBDEV FB_0
Erik Andersen1c5b2581999-12-16 20:59:36 +000018#define DEFAULTFBMODE "/etc/fb.modes"
19
Mark Whitley59ab0252001-01-23 22:30:04 +000020enum {
Mark Whitley59ab0252001-01-23 22:30:04 +000021 CMD_FB = 1,
22 CMD_DB = 2,
23 CMD_GEOMETRY = 3,
24 CMD_TIMING = 4,
25 CMD_ACCEL = 5,
26 CMD_HSYNC = 6,
27 CMD_VSYNC = 7,
28 CMD_LACED = 8,
29 CMD_DOUBLE = 9,
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000030/* CMD_XCOMPAT = 10, */
Mark Whitley59ab0252001-01-23 22:30:04 +000031 CMD_ALL = 11,
32 CMD_INFO = 12,
33 CMD_CHANGE = 13,
Erik Andersen1c5b2581999-12-16 20:59:36 +000034
Denis Vlasenkoe3241842007-08-13 10:36:25 +000035#if ENABLE_FEATURE_FBSET_FANCY
Mark Whitley59ab0252001-01-23 22:30:04 +000036 CMD_XRES = 100,
37 CMD_YRES = 101,
38 CMD_VXRES = 102,
39 CMD_VYRES = 103,
40 CMD_DEPTH = 104,
41 CMD_MATCH = 105,
42 CMD_PIXCLOCK = 106,
43 CMD_LEFT = 107,
44 CMD_RIGHT = 108,
45 CMD_UPPER = 109,
46 CMD_LOWER = 110,
47 CMD_HSLEN = 111,
48 CMD_VSLEN = 112,
49 CMD_CSYNC = 113,
50 CMD_GSYNC = 114,
51 CMD_EXTSYNC = 115,
52 CMD_BCAST = 116,
53 CMD_RGBA = 117,
54 CMD_STEP = 118,
55 CMD_MOVE = 119,
Erik Andersen1c5b2581999-12-16 20:59:36 +000056#endif
Mark Whitley59ab0252001-01-23 22:30:04 +000057};
Erik Andersen1c5b2581999-12-16 20:59:36 +000058
Eric Andersenc873d612000-09-21 04:09:58 +000059/* Stuff stolen from the kernel's fb.h */
Denis Vlasenko274b8c02006-09-30 16:22:59 +000060#define FB_ACTIVATE_ALL 64
Rob Landleybc68cd12006-03-10 19:22:06 +000061enum {
62 FBIOGET_VSCREENINFO = 0x4600,
63 FBIOPUT_VSCREENINFO = 0x4601
64};
Eric Andersenc873d612000-09-21 04:09:58 +000065struct fb_bitfield {
Denis Vlasenko39d551f2006-09-30 16:28:30 +000066 uint32_t offset; /* beginning of bitfield */
67 uint32_t length; /* length of bitfield */
68 uint32_t msb_right; /* !=0: Most significant bit is right */
Eric Andersenc873d612000-09-21 04:09:58 +000069};
70struct fb_var_screeninfo {
Denis Vlasenko39d551f2006-09-30 16:28:30 +000071 uint32_t xres; /* visible resolution */
Eric Andersen1eceb122003-07-14 19:32:40 +000072 uint32_t yres;
Denis Vlasenko39d551f2006-09-30 16:28:30 +000073 uint32_t xres_virtual; /* virtual resolution */
Eric Andersen1eceb122003-07-14 19:32:40 +000074 uint32_t yres_virtual;
Denis Vlasenko39d551f2006-09-30 16:28:30 +000075 uint32_t xoffset; /* offset from virtual to visible */
76 uint32_t yoffset; /* resolution */
Eric Andersenc873d612000-09-21 04:09:58 +000077
Denis Vlasenko39d551f2006-09-30 16:28:30 +000078 uint32_t bits_per_pixel;
79 uint32_t grayscale; /* !=0 Graylevels instead of colors */
Eric Andersenc873d612000-09-21 04:09:58 +000080
Denis Vlasenko39d551f2006-09-30 16:28:30 +000081 struct fb_bitfield red; /* bitfield in fb mem if true color, */
82 struct fb_bitfield green; /* else only length is significant */
Eric Andersenc873d612000-09-21 04:09:58 +000083 struct fb_bitfield blue;
Denis Vlasenko39d551f2006-09-30 16:28:30 +000084 struct fb_bitfield transp; /* transparency */
Eric Andersenc873d612000-09-21 04:09:58 +000085
Denis Vlasenko39d551f2006-09-30 16:28:30 +000086 uint32_t nonstd; /* !=0 Non standard pixel format */
Eric Andersenc873d612000-09-21 04:09:58 +000087
Denis Vlasenko39d551f2006-09-30 16:28:30 +000088 uint32_t activate; /* see FB_ACTIVATE_x */
Eric Andersenc873d612000-09-21 04:09:58 +000089
Denis Vlasenko39d551f2006-09-30 16:28:30 +000090 uint32_t height; /* height of picture in mm */
91 uint32_t width; /* width of picture in mm */
Eric Andersenc873d612000-09-21 04:09:58 +000092
Eric Andersen1eceb122003-07-14 19:32:40 +000093 uint32_t accel_flags; /* acceleration flags (hints) */
Eric Andersenc873d612000-09-21 04:09:58 +000094
95 /* Timing: All values in pixclocks, except pixclock (of course) */
Denis Vlasenko39d551f2006-09-30 16:28:30 +000096 uint32_t pixclock; /* pixel clock in ps (pico seconds) */
97 uint32_t left_margin; /* time from sync to picture */
98 uint32_t right_margin; /* time from picture to sync */
99 uint32_t upper_margin; /* time from sync to picture */
Eric Andersen1eceb122003-07-14 19:32:40 +0000100 uint32_t lower_margin;
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000101 uint32_t hsync_len; /* length of horizontal sync */
102 uint32_t vsync_len; /* length of vertical sync */
103 uint32_t sync; /* see FB_SYNC_x */
104 uint32_t vmode; /* see FB_VMODE_x */
105 uint32_t reserved[6]; /* Reserved for future compatibility */
Eric Andersenc873d612000-09-21 04:09:58 +0000106};
107
108
"Vladimir N. Oleynik"b399a962006-02-01 12:41:35 +0000109static const struct cmdoptions_t {
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000110 const char name[9];
Aaron Lehmann60694412002-08-13 04:19:23 +0000111 const unsigned char param_count;
112 const unsigned char code;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000113} g_cmdoptions[] = {
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000114 /*"12345678" + NUL */
115 { "fb" , 1, CMD_FB },
116 { "db" , 1, CMD_DB },
117 { "a" , 0, CMD_ALL },
118 { "i" , 0, CMD_INFO },
119 { "g" , 5, CMD_GEOMETRY },
120 { "t" , 7, CMD_TIMING },
121 { "accel" , 1, CMD_ACCEL },
122 { "hsync" , 1, CMD_HSYNC },
123 { "vsync" , 1, CMD_VSYNC },
124 { "laced" , 1, CMD_LACED },
125 { "double" , 1, CMD_DOUBLE },
126 { "n" , 0, CMD_CHANGE },
Denis Vlasenkoe3241842007-08-13 10:36:25 +0000127#if ENABLE_FEATURE_FBSET_FANCY
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000128 { "all" , 0, CMD_ALL },
129 { "xres" , 1, CMD_XRES },
130 { "yres" , 1, CMD_YRES },
131 { "vxres" , 1, CMD_VXRES },
132 { "vyres" , 1, CMD_VYRES },
133 { "depth" , 1, CMD_DEPTH },
134 { "match" , 0, CMD_MATCH },
135 { "geometry", 5, CMD_GEOMETRY },
136 { "pixclock", 1, CMD_PIXCLOCK },
137 { "left" , 1, CMD_LEFT },
138 { "right" , 1, CMD_RIGHT },
139 { "upper" , 1, CMD_UPPER },
140 { "lower" , 1, CMD_LOWER },
141 { "hslen" , 1, CMD_HSLEN },
142 { "vslen" , 1, CMD_VSLEN },
143 { "timings" , 7, CMD_TIMING },
144 { "csync" , 1, CMD_CSYNC },
145 { "gsync" , 1, CMD_GSYNC },
146 { "extsync" , 1, CMD_EXTSYNC },
147 { "bcast" , 1, CMD_BCAST },
148 { "rgba" , 1, CMD_RGBA },
149 { "step" , 1, CMD_STEP },
150 { "move" , 1, CMD_MOVE },
Erik Andersen1c5b2581999-12-16 20:59:36 +0000151#endif
Erik Andersen1c5b2581999-12-16 20:59:36 +0000152};
153
Denis Vlasenkoe3241842007-08-13 10:36:25 +0000154#if ENABLE_FEATURE_FBSET_READMODE
Matt Kraai269e07c2000-10-28 16:56:32 +0000155/* taken from linux/fb.h */
Rob Landleybc68cd12006-03-10 19:22:06 +0000156enum {
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000157 FB_VMODE_INTERLACED = 1, /* interlaced */
158 FB_VMODE_DOUBLE = 2, /* double scan */
159 FB_SYNC_HOR_HIGH_ACT = 1, /* horizontal sync high active */
160 FB_SYNC_VERT_HIGH_ACT = 2, /* vertical sync high active */
161 FB_SYNC_EXT = 4, /* external sync */
162 FB_SYNC_COMP_HIGH_ACT = 8, /* composite sync high active */
Rob Landleybc68cd12006-03-10 19:22:06 +0000163};
Matt Kraai269e07c2000-10-28 16:56:32 +0000164#endif
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000165
Denis Vlasenkod91afa32008-07-29 11:10:01 +0000166#if ENABLE_FEATURE_FBSET_READMODE
Denis Vlasenko8d523cb2008-07-27 21:16:30 +0000167static void ss(uint32_t *x, uint32_t flag, char *buf, const char *what)
Denis Vlasenko09f5ecf2008-07-27 20:25:29 +0000168{
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000169 if (strcmp(buf, what) == 0)
Denis Vlasenko09f5ecf2008-07-27 20:25:29 +0000170 *x &= ~flag;
171 else
172 *x |= flag;
173}
174
Erik Andersen1c5b2581999-12-16 20:59:36 +0000175static int readmode(struct fb_var_screeninfo *base, const char *fn,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000176 const char *mode)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000177{
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000178 char *token[2], *p, *s;
179 parser_t *parser = config_open(fn);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000180
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000181 while (config_read(parser, token, 2, 1, "# \t\r", PARSE_NORMAL)) {
182 if (strcmp(token[0], "mode") != 0 || !token[1])
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000183 continue;
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000184 p = strstr(token[1], mode);
Denis Vlasenko6bef3d12007-11-06 03:05:54 +0000185 if (!p)
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000186 continue;
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000187 s = p + strlen(mode);
188 //bb_info_msg("CHECK[%s][%s][%d]", mode, p-1, *s);
189 /* exact match? */
190 if (((!*s || isspace(*s)) && '"' != s[-1]) /* end-of-token */
191 || ('"' == *s && '"' == p[-1]) /* ends with " but starts with " too! */
Denis Vlasenko8d523cb2008-07-27 21:16:30 +0000192 ) {
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000193 //bb_info_msg("FOUND[%s][%s][%s][%d]", token[1], p, mode, isspace(*s));
194 break;
Denis Vlasenko8d523cb2008-07-27 21:16:30 +0000195 }
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000196 }
Eric Andersen6f96e672000-07-12 23:01:04 +0000197
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000198 if (!token[0])
199 return 0;
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000200
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000201 while (config_read(parser, token, 2, 1, "# \t", PARSE_NORMAL)) {
202 int i;
203
204//bb_info_msg("???[%s][%s]", token[0], token[1]);
205 if (strcmp(token[0], "endmode") == 0) {
206//bb_info_msg("OK[%s]", mode);
207 return 1;
208 }
209 p = token[1];
210 i = index_in_strings(
211 "geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0",
212 token[0]);
213 switch (i) {
214 case 0:
215 /* FIXME: catastrophic on arches with 64bit ints */
216 sscanf(p, "%d %d %d %d %d",
217 &(base->xres), &(base->yres),
218 &(base->xres_virtual), &(base->yres_virtual),
219 &(base->bits_per_pixel));
220//bb_info_msg("GEO[%s]", p);
221 break;
222 case 1:
223 sscanf(p, "%d %d %d %d %d %d %d",
224 &(base->pixclock),
225 &(base->left_margin), &(base->right_margin),
226 &(base->upper_margin), &(base->lower_margin),
227 &(base->hsync_len), &(base->vsync_len));
228//bb_info_msg("TIM[%s]", p);
229 break;
230 case 2:
231 case 3: {
232 static const uint32_t syncs[] = {FB_VMODE_INTERLACED, FB_VMODE_DOUBLE};
233 ss(&base->vmode, syncs[i-2], p, "false");
234//bb_info_msg("VMODE[%s]", p);
235 break;
236 }
237 case 4:
238 case 5:
239 case 6: {
240 static const uint32_t syncs[] = {FB_SYNC_VERT_HIGH_ACT, FB_SYNC_HOR_HIGH_ACT, FB_SYNC_COMP_HIGH_ACT};
241 ss(&base->sync, syncs[i-4], p, "low");
242//bb_info_msg("SYNC[%s]", p);
243 break;
244 }
245 case 7:
246 ss(&base->sync, FB_SYNC_EXT, p, "false");
247//bb_info_msg("EXTSYNC[%s]", p);
248 break;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000249 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000250 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000251 return 0;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000252}
Denis Vlasenko85c24712008-03-17 09:04:04 +0000253#endif
Erik Andersen1c5b2581999-12-16 20:59:36 +0000254
Denis Vlasenko8d523cb2008-07-27 21:16:30 +0000255static void setmode(struct fb_var_screeninfo *base,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000256 struct fb_var_screeninfo *set)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000257{
Denis Vlasenko8d523cb2008-07-27 21:16:30 +0000258 if ((int32_t) set->xres > 0)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000259 base->xres = set->xres;
Denis Vlasenko8d523cb2008-07-27 21:16:30 +0000260 if ((int32_t) set->yres > 0)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000261 base->yres = set->yres;
Denis Vlasenko8d523cb2008-07-27 21:16:30 +0000262 if ((int32_t) set->xres_virtual > 0)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000263 base->xres_virtual = set->xres_virtual;
Denis Vlasenko8d523cb2008-07-27 21:16:30 +0000264 if ((int32_t) set->yres_virtual > 0)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000265 base->yres_virtual = set->yres_virtual;
Denis Vlasenko8d523cb2008-07-27 21:16:30 +0000266 if ((int32_t) set->bits_per_pixel > 0)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000267 base->bits_per_pixel = set->bits_per_pixel;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000268}
269
Denis Vlasenko8d523cb2008-07-27 21:16:30 +0000270static void showmode(struct fb_var_screeninfo *v)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000271{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000272 double drate = 0, hrate = 0, vrate = 0;
273
274 if (v->pixclock) {
275 drate = 1e12 / v->pixclock;
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000276 hrate = drate / (v->left_margin + v->xres + v->right_margin + v->hsync_len);
277 vrate = hrate / (v->upper_margin + v->yres + v->lower_margin + v->vsync_len);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000278 }
Aaron Lehmann60694412002-08-13 04:19:23 +0000279 printf("\nmode \"%ux%u-%u\"\n"
Denis Vlasenkoe3241842007-08-13 10:36:25 +0000280#if ENABLE_FEATURE_FBSET_FANCY
Aaron Lehmann60694412002-08-13 04:19:23 +0000281 "\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n"
Erik Andersen1c5b2581999-12-16 20:59:36 +0000282#endif
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000283 "\tgeometry %u %u %u %u %u\n"
284 "\ttimings %u %u %u %u %u %u %u\n"
285 "\taccel %s\n"
286 "\trgba %u/%u,%u/%u,%u/%u,%u/%u\n"
287 "endmode\n\n",
288 v->xres, v->yres, (int) (vrate + 0.5),
Denis Vlasenkoe3241842007-08-13 10:36:25 +0000289#if ENABLE_FEATURE_FBSET_FANCY
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000290 drate / 1e6, hrate / 1e3, vrate,
Aaron Lehmann60694412002-08-13 04:19:23 +0000291#endif
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000292 v->xres, v->yres, v->xres_virtual, v->yres_virtual, v->bits_per_pixel,
293 v->pixclock, v->left_margin, v->right_margin, v->upper_margin, v->lower_margin,
294 v->hsync_len, v->vsync_len,
295 (v->accel_flags > 0 ? "true" : "false"),
296 v->red.length, v->red.offset, v->green.length, v->green.offset,
297 v->blue.length, v->blue.offset, v->transp.length, v->transp.offset);
Erik Andersen1c5b2581999-12-16 20:59:36 +0000298}
299
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000300int fbset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Rob Landleydfba7412006-03-06 20:47:33 +0000301int fbset_main(int argc, char **argv)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000302{
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000303 enum {
304 OPT_CHANGE = (1 << 0),
305 /*OPT_INFO = (1 << 1), ??*/
306 OPT_READMODE = (1 << 2),
307 OPT_ALL = (1 << 9),
308 };
Erik Andersene49d5ec2000-02-08 19:58:47 +0000309 struct fb_var_screeninfo var, varset;
310 int fh, i;
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000311 unsigned options = 0;
312
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +0000313 const char *fbdev = DEFAULTFBDEV;
314 const char *modefile = DEFAULTFBMODE;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000315 char *thisarg, *mode = NULL;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000316
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000317 memset(&varset, 0xff, sizeof(varset));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000318
319 /* parse cmd args.... why do they have to make things so difficult? */
320 argv++;
321 argc--;
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000322 for (; argc > 0 && (thisarg = *argv) != NULL; argc--, argv++) {
323 if (thisarg[0] == '-') for (i = 0; i < ARRAY_SIZE(g_cmdoptions); i++) {
324 if (strcmp(thisarg + 1, g_cmdoptions[i].name) != 0)
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000325 continue;
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000326 if (argc <= g_cmdoptions[i].param_count)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000327 bb_show_usage();
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000328
329 switch (g_cmdoptions[i].code) {
330 case CMD_FB:
331 fbdev = argv[1];
332 break;
333 case CMD_DB:
334 modefile = argv[1];
335 break;
336 case CMD_GEOMETRY:
Denis Vlasenko13858992006-10-08 12:49:22 +0000337 varset.xres = xatou32(argv[1]);
338 varset.yres = xatou32(argv[2]);
339 varset.xres_virtual = xatou32(argv[3]);
340 varset.yres_virtual = xatou32(argv[4]);
341 varset.bits_per_pixel = xatou32(argv[5]);
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000342 break;
343 case CMD_TIMING:
Denis Vlasenko13858992006-10-08 12:49:22 +0000344 varset.pixclock = xatou32(argv[1]);
345 varset.left_margin = xatou32(argv[2]);
346 varset.right_margin = xatou32(argv[3]);
347 varset.upper_margin = xatou32(argv[4]);
348 varset.lower_margin = xatou32(argv[5]);
349 varset.hsync_len = xatou32(argv[6]);
350 varset.vsync_len = xatou32(argv[7]);
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000351 break;
352 case CMD_ALL:
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000353 options |= OPT_ALL;
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000354 break;
355 case CMD_CHANGE:
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000356 options |= OPT_CHANGE;
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000357 break;
Denis Vlasenkoe3241842007-08-13 10:36:25 +0000358#if ENABLE_FEATURE_FBSET_FANCY
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000359 case CMD_XRES:
Denis Vlasenko13858992006-10-08 12:49:22 +0000360 varset.xres = xatou32(argv[1]);
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000361 break;
362 case CMD_YRES:
Denis Vlasenko13858992006-10-08 12:49:22 +0000363 varset.yres = xatou32(argv[1]);
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000364 break;
365 case CMD_DEPTH:
Denis Vlasenko13858992006-10-08 12:49:22 +0000366 varset.bits_per_pixel = xatou32(argv[1]);
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000367 break;
368#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000369 }
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000370 argc -= g_cmdoptions[i].param_count;
371 argv += g_cmdoptions[i].param_count;
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000372 goto contin;
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000373 }
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000374 if (argc != 1)
375 bb_show_usage();
376 mode = *argv;
377 options |= OPT_READMODE;
378 contin: ;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000379 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000380
Rob Landleyd921b2e2006-08-03 15:41:12 +0000381 fh = xopen(fbdev, O_RDONLY);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000382 xioctl(fh, FBIOGET_VSCREENINFO, &var);
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000383 if (options & OPT_READMODE) {
Denis Vlasenko85c24712008-03-17 09:04:04 +0000384#if !ENABLE_FEATURE_FBSET_READMODE
385 bb_show_usage();
386#else
Erik Andersene49d5ec2000-02-08 19:58:47 +0000387 if (!readmode(&var, modefile, mode)) {
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000388 bb_error_msg_and_die("unknown video mode '%s'", mode);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000389 }
Denis Vlasenko85c24712008-03-17 09:04:04 +0000390#endif
Erik Andersen1c5b2581999-12-16 20:59:36 +0000391 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000392
Erik Andersene49d5ec2000-02-08 19:58:47 +0000393 setmode(&var, &varset);
Denis Vlasenkob66d16a2008-08-24 16:25:40 +0000394 if (options & OPT_CHANGE) {
395 if (options & OPT_ALL)
Denis Vlasenko274b8c02006-09-30 16:22:59 +0000396 var.activate = FB_ACTIVATE_ALL;
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000397 xioctl(fh, FBIOPUT_VSCREENINFO, &var);
Denis Vlasenko274b8c02006-09-30 16:22:59 +0000398 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000399 showmode(&var);
Erik Andersen298854f2000-03-23 01:09:18 +0000400 /* Don't close the file, as exiting will take care of that */
401 /* close(fh); */
Erik Andersene49d5ec2000-02-08 19:58:47 +0000402
Matt Kraai3e856ce2000-12-01 02:55:13 +0000403 return EXIT_SUCCESS;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000404}