blob: 7ae010163a052ab1a22e228e077bac6207f4c177 [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
Eric Andersencbe31da2001-02-20 06:14:08 +000015#include "busybox.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 {
Rob Landleybc68cd12006-03-10 19:22:06 +000021 OPT_CHANGE = (1 << 0),
22 OPT_INFO = (1 << 1),
23 OPT_READMODE = (1 << 2),
Denis Vlasenko274b8c02006-09-30 16:22:59 +000024 OPT_ALL = (1 << 9),
Rob Landleybc68cd12006-03-10 19:22:06 +000025
Mark Whitley59ab0252001-01-23 22:30:04 +000026 CMD_FB = 1,
27 CMD_DB = 2,
28 CMD_GEOMETRY = 3,
29 CMD_TIMING = 4,
30 CMD_ACCEL = 5,
31 CMD_HSYNC = 6,
32 CMD_VSYNC = 7,
33 CMD_LACED = 8,
34 CMD_DOUBLE = 9,
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000035/* CMD_XCOMPAT = 10, */
Mark Whitley59ab0252001-01-23 22:30:04 +000036 CMD_ALL = 11,
37 CMD_INFO = 12,
38 CMD_CHANGE = 13,
Erik Andersen1c5b2581999-12-16 20:59:36 +000039
Eric Andersenbdfd0d72001-10-24 05:00:29 +000040#ifdef CONFIG_FEATURE_FBSET_FANCY
Mark Whitley59ab0252001-01-23 22:30:04 +000041 CMD_XRES = 100,
42 CMD_YRES = 101,
43 CMD_VXRES = 102,
44 CMD_VYRES = 103,
45 CMD_DEPTH = 104,
46 CMD_MATCH = 105,
47 CMD_PIXCLOCK = 106,
48 CMD_LEFT = 107,
49 CMD_RIGHT = 108,
50 CMD_UPPER = 109,
51 CMD_LOWER = 110,
52 CMD_HSLEN = 111,
53 CMD_VSLEN = 112,
54 CMD_CSYNC = 113,
55 CMD_GSYNC = 114,
56 CMD_EXTSYNC = 115,
57 CMD_BCAST = 116,
58 CMD_RGBA = 117,
59 CMD_STEP = 118,
60 CMD_MOVE = 119,
Erik Andersen1c5b2581999-12-16 20:59:36 +000061#endif
Mark Whitley59ab0252001-01-23 22:30:04 +000062};
Erik Andersen1c5b2581999-12-16 20:59:36 +000063
Denis Vlasenko73464ce2007-01-03 00:45:05 +000064static unsigned g_options;
Erik Andersen1c5b2581999-12-16 20:59:36 +000065
Eric Andersenc873d612000-09-21 04:09:58 +000066/* Stuff stolen from the kernel's fb.h */
Denis Vlasenko274b8c02006-09-30 16:22:59 +000067#define FB_ACTIVATE_ALL 64
Rob Landleybc68cd12006-03-10 19:22:06 +000068enum {
69 FBIOGET_VSCREENINFO = 0x4600,
70 FBIOPUT_VSCREENINFO = 0x4601
71};
Eric Andersenc873d612000-09-21 04:09:58 +000072struct fb_bitfield {
Denis Vlasenko39d551f2006-09-30 16:28:30 +000073 uint32_t offset; /* beginning of bitfield */
74 uint32_t length; /* length of bitfield */
75 uint32_t msb_right; /* !=0: Most significant bit is right */
Eric Andersenc873d612000-09-21 04:09:58 +000076};
77struct fb_var_screeninfo {
Denis Vlasenko39d551f2006-09-30 16:28:30 +000078 uint32_t xres; /* visible resolution */
Eric Andersen1eceb122003-07-14 19:32:40 +000079 uint32_t yres;
Denis Vlasenko39d551f2006-09-30 16:28:30 +000080 uint32_t xres_virtual; /* virtual resolution */
Eric Andersen1eceb122003-07-14 19:32:40 +000081 uint32_t yres_virtual;
Denis Vlasenko39d551f2006-09-30 16:28:30 +000082 uint32_t xoffset; /* offset from virtual to visible */
83 uint32_t yoffset; /* resolution */
Eric Andersenc873d612000-09-21 04:09:58 +000084
Denis Vlasenko39d551f2006-09-30 16:28:30 +000085 uint32_t bits_per_pixel;
86 uint32_t grayscale; /* !=0 Graylevels instead of colors */
Eric Andersenc873d612000-09-21 04:09:58 +000087
Denis Vlasenko39d551f2006-09-30 16:28:30 +000088 struct fb_bitfield red; /* bitfield in fb mem if true color, */
89 struct fb_bitfield green; /* else only length is significant */
Eric Andersenc873d612000-09-21 04:09:58 +000090 struct fb_bitfield blue;
Denis Vlasenko39d551f2006-09-30 16:28:30 +000091 struct fb_bitfield transp; /* transparency */
Eric Andersenc873d612000-09-21 04:09:58 +000092
Denis Vlasenko39d551f2006-09-30 16:28:30 +000093 uint32_t nonstd; /* !=0 Non standard pixel format */
Eric Andersenc873d612000-09-21 04:09:58 +000094
Denis Vlasenko39d551f2006-09-30 16:28:30 +000095 uint32_t activate; /* see FB_ACTIVATE_x */
Eric Andersenc873d612000-09-21 04:09:58 +000096
Denis Vlasenko39d551f2006-09-30 16:28:30 +000097 uint32_t height; /* height of picture in mm */
98 uint32_t width; /* width of picture in mm */
Eric Andersenc873d612000-09-21 04:09:58 +000099
Eric Andersen1eceb122003-07-14 19:32:40 +0000100 uint32_t accel_flags; /* acceleration flags (hints) */
Eric Andersenc873d612000-09-21 04:09:58 +0000101
102 /* Timing: All values in pixclocks, except pixclock (of course) */
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000103 uint32_t pixclock; /* pixel clock in ps (pico seconds) */
104 uint32_t left_margin; /* time from sync to picture */
105 uint32_t right_margin; /* time from picture to sync */
106 uint32_t upper_margin; /* time from sync to picture */
Eric Andersen1eceb122003-07-14 19:32:40 +0000107 uint32_t lower_margin;
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000108 uint32_t hsync_len; /* length of horizontal sync */
109 uint32_t vsync_len; /* length of vertical sync */
110 uint32_t sync; /* see FB_SYNC_x */
111 uint32_t vmode; /* see FB_VMODE_x */
112 uint32_t reserved[6]; /* Reserved for future compatibility */
Eric Andersenc873d612000-09-21 04:09:58 +0000113};
114
115
"Vladimir N. Oleynik"b399a962006-02-01 12:41:35 +0000116static const struct cmdoptions_t {
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000117 const char name[10];
Aaron Lehmann60694412002-08-13 04:19:23 +0000118 const unsigned char param_count;
119 const unsigned char code;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000120} g_cmdoptions[] = {
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000121 { "-fb", 1, CMD_FB },
122 { "-db", 1, CMD_DB },
123 { "-a", 0, CMD_ALL },
124 { "-i", 0, CMD_INFO },
125 { "-g", 5, CMD_GEOMETRY },
126 { "-t", 7, CMD_TIMING },
127 { "-accel", 1, CMD_ACCEL },
128 { "-hsync", 1, CMD_HSYNC },
129 { "-vsync", 1, CMD_VSYNC },
130 { "-laced", 1, CMD_LACED },
131 { "-double", 1, CMD_DOUBLE },
132 { "-n", 0, CMD_CHANGE },
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000133#ifdef CONFIG_FEATURE_FBSET_FANCY
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000134 { "-all", 0, CMD_ALL },
135 { "-xres", 1, CMD_XRES },
136 { "-yres", 1, CMD_YRES },
137 { "-vxres", 1, CMD_VXRES },
138 { "-vyres", 1, CMD_VYRES },
139 { "-depth", 1, CMD_DEPTH },
140 { "-match", 0, CMD_MATCH },
141 { "-geometry", 5, CMD_GEOMETRY },
142 { "-pixclock", 1, CMD_PIXCLOCK },
143 { "-left", 1, CMD_LEFT },
144 { "-right", 1, CMD_RIGHT },
145 { "-upper", 1, CMD_UPPER },
146 { "-lower", 1, CMD_LOWER },
147 { "-hslen", 1, CMD_HSLEN },
148 { "-vslen", 1, CMD_VSLEN },
149 { "-timings", 7, CMD_TIMING },
150 { "-csync", 1, CMD_CSYNC },
151 { "-gsync", 1, CMD_GSYNC },
152 { "-extsync", 1, CMD_EXTSYNC },
153 { "-bcast", 1, CMD_BCAST },
154 { "-rgba", 1, CMD_RGBA },
155 { "-step", 1, CMD_STEP },
156 { "-move", 1, CMD_MOVE },
Erik Andersen1c5b2581999-12-16 20:59:36 +0000157#endif
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000158 { "", 0, 0 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000159};
160
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000161#ifdef CONFIG_FEATURE_FBSET_READMODE
Matt Kraai269e07c2000-10-28 16:56:32 +0000162/* taken from linux/fb.h */
Rob Landleybc68cd12006-03-10 19:22:06 +0000163enum {
164 FB_VMODE_INTERLACED = 1, /* interlaced */
165 FB_VMODE_DOUBLE = 2, /* double scan */
166 FB_SYNC_HOR_HIGH_ACT = 1, /* horizontal sync high active */
167 FB_SYNC_VERT_HIGH_ACT = 2, /* vertical sync high active */
168 FB_SYNC_EXT = 4, /* external sync */
169 FB_SYNC_COMP_HIGH_ACT = 8 /* composite sync high active */
170};
Matt Kraai269e07c2000-10-28 16:56:32 +0000171#endif
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000172
Erik Andersen1c5b2581999-12-16 20:59:36 +0000173static int readmode(struct fb_var_screeninfo *base, const char *fn,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000174 const char *mode)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000175{
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000176#ifdef CONFIG_FEATURE_FBSET_READMODE
Erik Andersene49d5ec2000-02-08 19:58:47 +0000177 FILE *f;
178 char buf[256];
179 char *p = buf;
180
Rob Landleyd921b2e2006-08-03 15:41:12 +0000181 f = xfopen(fn, "r");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000182 while (!feof(f)) {
183 fgets(buf, sizeof(buf), f);
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000184 if (!(p = strstr(buf, "mode ")) && !(p = strstr(buf, "mode\t")))
185 continue;
186 p += 5;
187 if (!(p = strstr(buf, mode)))
188 continue;
189 p += strlen(mode);
190 if (!isspace(*p) && (*p != 0) && (*p != '"')
191 && (*p != '\r') && (*p != '\n'))
192 continue; /* almost, but not quite */
Eric Andersen6f96e672000-07-12 23:01:04 +0000193
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000194 while (!feof(f)) {
195 fgets(buf, sizeof(buf), f);
196 if ((p = strstr(buf, "geometry "))) {
197 p += 9;
198 /* FIXME: catastrophic on arches with 64bit ints */
199 sscanf(p, "%d %d %d %d %d",
200 &(base->xres), &(base->yres),
201 &(base->xres_virtual), &(base->yres_virtual),
202 &(base->bits_per_pixel));
203 } else if ((p = strstr(buf, "timings "))) {
204 p += 8;
205 sscanf(p, "%d %d %d %d %d %d %d",
206 &(base->pixclock),
207 &(base->left_margin), &(base->right_margin),
208 &(base->upper_margin), &(base->lower_margin),
209 &(base->hsync_len), &(base->vsync_len));
210 } else if ((p = strstr(buf, "laced "))) {
211 //p += 6;
212 if (strstr(buf, "false")) {
213 base->vmode &= ~FB_VMODE_INTERLACED;
214 } else {
215 base->vmode |= FB_VMODE_INTERLACED;
216 }
217 } else if ((p = strstr(buf, "double "))) {
218 //p += 7;
219 if (strstr(buf, "false")) {
220 base->vmode &= ~FB_VMODE_DOUBLE;
221 } else {
222 base->vmode |= FB_VMODE_DOUBLE;
223 }
224 } else if ((p = strstr(buf, "vsync "))) {
225 //p += 6;
226 if (strstr(buf, "low")) {
227 base->sync &= ~FB_SYNC_VERT_HIGH_ACT;
228 } else {
229 base->sync |= FB_SYNC_VERT_HIGH_ACT;
230 }
231 } else if ((p = strstr(buf, "hsync "))) {
232 //p += 6;
233 if (strstr(buf, "low")) {
234 base->sync &= ~FB_SYNC_HOR_HIGH_ACT;
235 } else {
236 base->sync |= FB_SYNC_HOR_HIGH_ACT;
237 }
238 } else if ((p = strstr(buf, "csync "))) {
239 //p += 6;
240 if (strstr(buf, "low")) {
241 base->sync &= ~FB_SYNC_COMP_HIGH_ACT;
242 } else {
243 base->sync |= FB_SYNC_COMP_HIGH_ACT;
244 }
245 } else if ((p = strstr(buf, "extsync "))) {
246 //p += 8;
247 if (strstr(buf, "false")) {
248 base->sync &= ~FB_SYNC_EXT;
249 } else {
250 base->sync |= FB_SYNC_EXT;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000251 }
252 }
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000253
254 if (strstr(buf, "endmode"))
255 return 1;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000256 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000257 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000258#else
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000259 bb_error_msg("mode reading not compiled in");
Erik Andersen1c5b2581999-12-16 20:59:36 +0000260#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000261 return 0;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000262}
263
Aaron Lehmann60694412002-08-13 04:19:23 +0000264static inline void setmode(struct fb_var_screeninfo *base,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000265 struct fb_var_screeninfo *set)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000266{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000267 if ((int) set->xres > 0)
268 base->xres = set->xres;
269 if ((int) set->yres > 0)
270 base->yres = set->yres;
271 if ((int) set->xres_virtual > 0)
272 base->xres_virtual = set->xres_virtual;
273 if ((int) set->yres_virtual > 0)
274 base->yres_virtual = set->yres_virtual;
275 if ((int) set->bits_per_pixel > 0)
276 base->bits_per_pixel = set->bits_per_pixel;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000277}
278
Aaron Lehmann60694412002-08-13 04:19:23 +0000279static inline void showmode(struct fb_var_screeninfo *v)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000280{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000281 double drate = 0, hrate = 0, vrate = 0;
282
283 if (v->pixclock) {
284 drate = 1e12 / v->pixclock;
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000285 hrate = drate / (v->left_margin + v->xres + v->right_margin + v->hsync_len);
286 vrate = hrate / (v->upper_margin + v->yres + v->lower_margin + v->vsync_len);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000287 }
Aaron Lehmann60694412002-08-13 04:19:23 +0000288 printf("\nmode \"%ux%u-%u\"\n"
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000289#ifdef CONFIG_FEATURE_FBSET_FANCY
Aaron Lehmann60694412002-08-13 04:19:23 +0000290 "\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n"
Erik Andersen1c5b2581999-12-16 20:59:36 +0000291#endif
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000292 "\tgeometry %u %u %u %u %u\n"
293 "\ttimings %u %u %u %u %u %u %u\n"
294 "\taccel %s\n"
295 "\trgba %u/%u,%u/%u,%u/%u,%u/%u\n"
296 "endmode\n\n",
297 v->xres, v->yres, (int) (vrate + 0.5),
Aaron Lehmann60694412002-08-13 04:19:23 +0000298#ifdef CONFIG_FEATURE_FBSET_FANCY
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000299 drate / 1e6, hrate / 1e3, vrate,
Aaron Lehmann60694412002-08-13 04:19:23 +0000300#endif
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000301 v->xres, v->yres, v->xres_virtual, v->yres_virtual, v->bits_per_pixel,
302 v->pixclock, v->left_margin, v->right_margin, v->upper_margin, v->lower_margin,
303 v->hsync_len, v->vsync_len,
304 (v->accel_flags > 0 ? "true" : "false"),
305 v->red.length, v->red.offset, v->green.length, v->green.offset,
306 v->blue.length, v->blue.offset, v->transp.length, v->transp.offset);
Erik Andersen1c5b2581999-12-16 20:59:36 +0000307}
308
Erik Andersen1c5b2581999-12-16 20:59:36 +0000309#ifdef STANDALONE
310int main(int argc, char **argv)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000311#else
Rob Landleydfba7412006-03-06 20:47:33 +0000312int fbset_main(int argc, char **argv)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000313#endif
314{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000315 struct fb_var_screeninfo var, varset;
316 int fh, i;
317 char *fbdev = DEFAULTFBDEV;
318 char *modefile = DEFAULTFBMODE;
319 char *thisarg, *mode = NULL;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000320
Erik Andersene49d5ec2000-02-08 19:58:47 +0000321 memset(&varset, 0xFF, sizeof(varset));
322
323 /* parse cmd args.... why do they have to make things so difficult? */
324 argv++;
325 argc--;
326 for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000327 for (i = 0; g_cmdoptions[i].name[0]; i++) {
328 if (strcmp(thisarg, g_cmdoptions[i].name))
329 continue;
330 if (argc-1 < g_cmdoptions[i].param_count)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000331 bb_show_usage();
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000332
333 switch (g_cmdoptions[i].code) {
334 case CMD_FB:
335 fbdev = argv[1];
336 break;
337 case CMD_DB:
338 modefile = argv[1];
339 break;
340 case CMD_GEOMETRY:
Denis Vlasenko13858992006-10-08 12:49:22 +0000341 varset.xres = xatou32(argv[1]);
342 varset.yres = xatou32(argv[2]);
343 varset.xres_virtual = xatou32(argv[3]);
344 varset.yres_virtual = xatou32(argv[4]);
345 varset.bits_per_pixel = xatou32(argv[5]);
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000346 break;
347 case CMD_TIMING:
Denis Vlasenko13858992006-10-08 12:49:22 +0000348 varset.pixclock = xatou32(argv[1]);
349 varset.left_margin = xatou32(argv[2]);
350 varset.right_margin = xatou32(argv[3]);
351 varset.upper_margin = xatou32(argv[4]);
352 varset.lower_margin = xatou32(argv[5]);
353 varset.hsync_len = xatou32(argv[6]);
354 varset.vsync_len = xatou32(argv[7]);
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000355 break;
356 case CMD_ALL:
357 g_options |= OPT_ALL;
358 break;
359 case CMD_CHANGE:
360 g_options |= OPT_CHANGE;
361 break;
362#ifdef CONFIG_FEATURE_FBSET_FANCY
363 case CMD_XRES:
Denis Vlasenko13858992006-10-08 12:49:22 +0000364 varset.xres = xatou32(argv[1]);
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000365 break;
366 case CMD_YRES:
Denis Vlasenko13858992006-10-08 12:49:22 +0000367 varset.yres = xatou32(argv[1]);
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000368 break;
369 case CMD_DEPTH:
Denis Vlasenko13858992006-10-08 12:49:22 +0000370 varset.bits_per_pixel = xatou32(argv[1]);
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000371 break;
372#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000373 }
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000374 argc -= g_cmdoptions[i].param_count;
375 argv += g_cmdoptions[i].param_count;
376 break;
377 }
378 if (!g_cmdoptions[i].name[0]) {
379 if (argc != 1)
380 bb_show_usage();
381 mode = *argv;
382 g_options |= OPT_READMODE;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000383 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000384 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000385
Rob Landleyd921b2e2006-08-03 15:41:12 +0000386 fh = xopen(fbdev, O_RDONLY);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000387 if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000388 bb_perror_msg_and_die("ioctl(%sT_VSCREENINFO)", "GE");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000389 if (g_options & OPT_READMODE) {
390 if (!readmode(&var, modefile, mode)) {
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000391 bb_error_msg_and_die("unknown video mode '%s'", mode);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000392 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000393 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000394
Erik Andersene49d5ec2000-02-08 19:58:47 +0000395 setmode(&var, &varset);
Denis Vlasenko274b8c02006-09-30 16:22:59 +0000396 if (g_options & OPT_CHANGE) {
397 if (g_options & OPT_ALL)
398 var.activate = FB_ACTIVATE_ALL;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000399 if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
Denis Vlasenko39d551f2006-09-30 16:28:30 +0000400 bb_perror_msg_and_die("ioctl(%sT_VSCREENINFO)", "PU");
Denis Vlasenko274b8c02006-09-30 16:22:59 +0000401 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000402 showmode(&var);
Erik Andersen298854f2000-03-23 01:09:18 +0000403 /* Don't close the file, as exiting will take care of that */
404 /* close(fh); */
Erik Andersene49d5ec2000-02-08 19:58:47 +0000405
Matt Kraai3e856ce2000-12-01 02:55:13 +0000406 return EXIT_SUCCESS;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000407}