blob: 9a207b6e39f962fea8de8c9f9bd7b05ad49a923b [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),
24
Mark Whitley59ab0252001-01-23 22:30:04 +000025 CMD_FB = 1,
26 CMD_DB = 2,
27 CMD_GEOMETRY = 3,
28 CMD_TIMING = 4,
29 CMD_ACCEL = 5,
30 CMD_HSYNC = 6,
31 CMD_VSYNC = 7,
32 CMD_LACED = 8,
33 CMD_DOUBLE = 9,
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000034/* CMD_XCOMPAT = 10, */
Mark Whitley59ab0252001-01-23 22:30:04 +000035 CMD_ALL = 11,
36 CMD_INFO = 12,
37 CMD_CHANGE = 13,
Erik Andersen1c5b2581999-12-16 20:59:36 +000038
Eric Andersenbdfd0d72001-10-24 05:00:29 +000039#ifdef CONFIG_FEATURE_FBSET_FANCY
Mark Whitley59ab0252001-01-23 22:30:04 +000040 CMD_XRES = 100,
41 CMD_YRES = 101,
42 CMD_VXRES = 102,
43 CMD_VYRES = 103,
44 CMD_DEPTH = 104,
45 CMD_MATCH = 105,
46 CMD_PIXCLOCK = 106,
47 CMD_LEFT = 107,
48 CMD_RIGHT = 108,
49 CMD_UPPER = 109,
50 CMD_LOWER = 110,
51 CMD_HSLEN = 111,
52 CMD_VSLEN = 112,
53 CMD_CSYNC = 113,
54 CMD_GSYNC = 114,
55 CMD_EXTSYNC = 115,
56 CMD_BCAST = 116,
57 CMD_RGBA = 117,
58 CMD_STEP = 118,
59 CMD_MOVE = 119,
Erik Andersen1c5b2581999-12-16 20:59:36 +000060#endif
Mark Whitley59ab0252001-01-23 22:30:04 +000061};
Erik Andersen1c5b2581999-12-16 20:59:36 +000062
63static unsigned int g_options = 0;
64
Eric Andersenc873d612000-09-21 04:09:58 +000065/* Stuff stolen from the kernel's fb.h */
Rob Landleybc68cd12006-03-10 19:22:06 +000066enum {
67 FBIOGET_VSCREENINFO = 0x4600,
68 FBIOPUT_VSCREENINFO = 0x4601
69};
Eric Andersenc873d612000-09-21 04:09:58 +000070struct fb_bitfield {
Eric Andersen1eceb122003-07-14 19:32:40 +000071 uint32_t offset; /* beginning of bitfield */
72 uint32_t length; /* length of bitfield */
Eric Andersenc7bda1c2004-03-15 08:29:22 +000073 uint32_t msb_right; /* != 0 : Most significant bit is */
74 /* right */
Eric Andersenc873d612000-09-21 04:09:58 +000075};
76struct fb_var_screeninfo {
Eric Andersen1eceb122003-07-14 19:32:40 +000077 uint32_t xres; /* visible resolution */
78 uint32_t yres;
79 uint32_t xres_virtual; /* virtual resolution */
80 uint32_t yres_virtual;
81 uint32_t xoffset; /* offset from virtual to visible */
82 uint32_t yoffset; /* resolution */
Eric Andersenc873d612000-09-21 04:09:58 +000083
Eric Andersen1eceb122003-07-14 19:32:40 +000084 uint32_t bits_per_pixel; /* guess what */
85 uint32_t grayscale; /* != 0 Graylevels instead of colors */
Eric Andersenc873d612000-09-21 04:09:58 +000086
87 struct fb_bitfield red; /* bitfield in fb mem if true color, */
88 struct fb_bitfield green; /* else only length is significant */
89 struct fb_bitfield blue;
Eric Andersenc7bda1c2004-03-15 08:29:22 +000090 struct fb_bitfield transp; /* transparency */
Eric Andersenc873d612000-09-21 04:09:58 +000091
Eric Andersen1eceb122003-07-14 19:32:40 +000092 uint32_t nonstd; /* != 0 Non standard pixel format */
Eric Andersenc873d612000-09-21 04:09:58 +000093
Eric Andersen1eceb122003-07-14 19:32:40 +000094 uint32_t activate; /* see FB_ACTIVATE_* */
Eric Andersenc873d612000-09-21 04:09:58 +000095
Eric Andersen1eceb122003-07-14 19:32:40 +000096 uint32_t height; /* height of picture in mm */
97 uint32_t width; /* width of picture in mm */
Eric Andersenc873d612000-09-21 04:09:58 +000098
Eric Andersen1eceb122003-07-14 19:32:40 +000099 uint32_t accel_flags; /* acceleration flags (hints) */
Eric Andersenc873d612000-09-21 04:09:58 +0000100
101 /* Timing: All values in pixclocks, except pixclock (of course) */
Eric Andersen1eceb122003-07-14 19:32:40 +0000102 uint32_t pixclock; /* pixel clock in ps (pico seconds) */
103 uint32_t left_margin; /* time from sync to picture */
104 uint32_t right_margin; /* time from picture to sync */
105 uint32_t upper_margin; /* time from sync to picture */
106 uint32_t lower_margin;
107 uint32_t hsync_len; /* length of horizontal sync */
108 uint32_t vsync_len; /* length of vertical sync */
109 uint32_t sync; /* see FB_SYNC_* */
110 uint32_t vmode; /* see FB_VMODE_* */
111 uint32_t reserved[6]; /* Reserved for future compatibility */
Eric Andersenc873d612000-09-21 04:09:58 +0000112};
113
114
"Vladimir N. Oleynik"b399a962006-02-01 12:41:35 +0000115static const struct cmdoptions_t {
Aaron Lehmann60694412002-08-13 04:19:23 +0000116 const char *name;
117 const unsigned char param_count;
118 const unsigned char code;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000119} g_cmdoptions[] = {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000120 {
Erik Andersene49d5ec2000-02-08 19:58:47 +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}, {
Erik Andersen9cf3bfa2000-04-13 18:49:43 +0000131 "-double", 1, CMD_DOUBLE}, {
Eric Andersenc8c10c52000-07-06 17:23:23 +0000132 "-n", 0, CMD_CHANGE}, {
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000133#ifdef CONFIG_FEATURE_FBSET_FANCY
Erik Andersene49d5ec2000-02-08 19:58:47 +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}, {
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000141 "-geometry", 5, CMD_GEOMETRY}, {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000142 "-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}, {
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000149 "-timings", 7, CMD_TIMING}, {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000150 "-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}, {
Erik Andersen9cf3bfa2000-04-13 18:49:43 +0000156 "-move", 1, CMD_MOVE}, {
Erik Andersen1c5b2581999-12-16 20:59:36 +0000157#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000158 0, 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
Erik Andersen1c5b2581999-12-16 20:59:36 +0000172static int readmode(struct fb_var_screeninfo *base, const char *fn,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000173 const char *mode)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000174{
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000175#ifdef CONFIG_FEATURE_FBSET_READMODE
Erik Andersene49d5ec2000-02-08 19:58:47 +0000176 FILE *f;
177 char buf[256];
178 char *p = buf;
179
Rob Landleyd921b2e2006-08-03 15:41:12 +0000180 f = xfopen(fn, "r");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000181 while (!feof(f)) {
182 fgets(buf, sizeof(buf), f);
183 if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
184 p += 5;
185 if ((p = strstr(buf, mode))) {
186 p += strlen(mode);
187 if (!isspace(*p) && (*p != 0) && (*p != '"')
188 && (*p != '\r') && (*p != '\n'))
189 continue; /* almost, but not quite */
190 while (!feof(f)) {
191 fgets(buf, sizeof(buf), f);
Eric Andersen6f96e672000-07-12 23:01:04 +0000192
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000193 if ((p = strstr(buf, "geometry "))) {
194 p += 9;
Eric Andersen6f96e672000-07-12 23:01:04 +0000195
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000196 sscanf(p, "%d %d %d %d %d",
197 &(base->xres), &(base->yres),
198 &(base->xres_virtual), &(base->yres_virtual),
199 &(base->bits_per_pixel));
200 } else if ((p = strstr(buf, "timings "))) {
201 p += 8;
Eric Andersen6f96e672000-07-12 23:01:04 +0000202
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000203 sscanf(p, "%d %d %d %d %d %d %d",
204 &(base->pixclock),
205 &(base->left_margin), &(base->right_margin),
206 &(base->upper_margin), &(base->lower_margin),
207 &(base->hsync_len), &(base->vsync_len));
208 } else if ((p = strstr(buf, "laced "))) {
209 p += 6;
Eric Andersen6f96e672000-07-12 23:01:04 +0000210
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000211 if (strstr(buf, "false")) {
212 base->vmode &= ~FB_VMODE_INTERLACED;
213 } else {
214 base->vmode |= FB_VMODE_INTERLACED;
215 }
216 } else if ((p = strstr(buf, "double "))) {
217 p += 7;
Eric Andersen6f96e672000-07-12 23:01:04 +0000218
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000219 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;
Eric Andersen6f96e672000-07-12 23:01:04 +0000226
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000227 if (strstr(buf, "low")) {
228 base->sync &= ~FB_SYNC_VERT_HIGH_ACT;
229 } else {
230 base->sync |= FB_SYNC_VERT_HIGH_ACT;
231 }
232 } else if ((p = strstr(buf, "hsync "))) {
233 p += 6;
Eric Andersen6f96e672000-07-12 23:01:04 +0000234
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000235 if (strstr(buf, "low")) {
236 base->sync &= ~FB_SYNC_HOR_HIGH_ACT;
237 } else {
238 base->sync |= FB_SYNC_HOR_HIGH_ACT;
239 }
240 } else if ((p = strstr(buf, "csync "))) {
241 p += 6;
Eric Andersen6f96e672000-07-12 23:01:04 +0000242
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000243 if (strstr(buf, "low")) {
244 base->sync &= ~FB_SYNC_COMP_HIGH_ACT;
245 } else {
246 base->sync |= FB_SYNC_COMP_HIGH_ACT;
247 }
248 } else if ((p = strstr(buf, "extsync "))) {
249 p += 8;
250
251 if (strstr(buf, "false")) {
252 base->sync &= ~FB_SYNC_EXT;
253 } else {
254 base->sync |= FB_SYNC_EXT;
255 }
256 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000257
Eric Andersen6f96e672000-07-12 23:01:04 +0000258 if (strstr(buf, "endmode"))
Erik Andersene49d5ec2000-02-08 19:58:47 +0000259 return 1;
260 }
261 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000262 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000263 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000264#else
Manuel Novoa III cad53642003-03-19 09:13:01 +0000265 bb_error_msg( "mode reading not compiled in");
Erik Andersen1c5b2581999-12-16 20:59:36 +0000266#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000267 return 0;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000268}
269
Aaron Lehmann60694412002-08-13 04:19:23 +0000270static inline void setmode(struct fb_var_screeninfo *base,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000271 struct fb_var_screeninfo *set)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000272{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000273 if ((int) set->xres > 0)
274 base->xres = set->xres;
275 if ((int) set->yres > 0)
276 base->yres = set->yres;
277 if ((int) set->xres_virtual > 0)
278 base->xres_virtual = set->xres_virtual;
279 if ((int) set->yres_virtual > 0)
280 base->yres_virtual = set->yres_virtual;
281 if ((int) set->bits_per_pixel > 0)
282 base->bits_per_pixel = set->bits_per_pixel;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000283}
284
Aaron Lehmann60694412002-08-13 04:19:23 +0000285static inline void showmode(struct fb_var_screeninfo *v)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000286{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000287 double drate = 0, hrate = 0, vrate = 0;
288
289 if (v->pixclock) {
290 drate = 1e12 / v->pixclock;
291 hrate =
292 drate / (v->left_margin + v->xres + v->right_margin +
293 v->hsync_len);
294 vrate =
295 hrate / (v->upper_margin + v->yres + v->lower_margin +
296 v->vsync_len);
297 }
Aaron Lehmann60694412002-08-13 04:19:23 +0000298 printf("\nmode \"%ux%u-%u\"\n"
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000299#ifdef CONFIG_FEATURE_FBSET_FANCY
Aaron Lehmann60694412002-08-13 04:19:23 +0000300 "\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n"
Erik Andersen1c5b2581999-12-16 20:59:36 +0000301#endif
Aaron Lehmann60694412002-08-13 04:19:23 +0000302 "\tgeometry %u %u %u %u %u\n\ttimings %u %u %u %u %u %u %u\n\taccel %s\n\trgba %u/%u,%u/%u,%u/%u,%u/%u\nendmode\n\n",
303 v->xres, v->yres, (int) (vrate + 0.5),
304#ifdef CONFIG_FEATURE_FBSET_FANCY
305 drate / 1e6, hrate / 1e3, vrate,
306#endif
307 v->xres, v->yres, v->xres_virtual, v->yres_virtual,
308 v->bits_per_pixel, v->pixclock, v->left_margin,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000309 v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
Aaron Lehmann60694412002-08-13 04:19:23 +0000310 v->vsync_len, (v->accel_flags > 0 ? "true" : "false"), v->red.length,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000311 v->red.offset, v->green.length, v->green.offset, v->blue.length,
312 v->blue.offset, v->transp.length, v->transp.offset);
Erik Andersen1c5b2581999-12-16 20:59:36 +0000313}
314
Erik Andersen1c5b2581999-12-16 20:59:36 +0000315#ifdef STANDALONE
316int main(int argc, char **argv)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000317#else
Rob Landleydfba7412006-03-06 20:47:33 +0000318int fbset_main(int argc, char **argv)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000319#endif
320{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000321 struct fb_var_screeninfo var, varset;
322 int fh, i;
323 char *fbdev = DEFAULTFBDEV;
324 char *modefile = DEFAULTFBMODE;
325 char *thisarg, *mode = NULL;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000326
Erik Andersene49d5ec2000-02-08 19:58:47 +0000327 memset(&varset, 0xFF, sizeof(varset));
328
329 /* parse cmd args.... why do they have to make things so difficult? */
330 argv++;
331 argc--;
332 for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
333 for (i = 0; g_cmdoptions[i].name; i++) {
334 if (!strcmp(thisarg, g_cmdoptions[i].name)) {
335 if (argc - 1 < g_cmdoptions[i].param_count)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000336 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000337 switch (g_cmdoptions[i].code) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000338 case CMD_FB:
339 fbdev = argv[1];
340 break;
341 case CMD_DB:
342 modefile = argv[1];
343 break;
344 case CMD_GEOMETRY:
345 varset.xres = strtoul(argv[1], 0, 0);
346 varset.yres = strtoul(argv[2], 0, 0);
347 varset.xres_virtual = strtoul(argv[3], 0, 0);
348 varset.yres_virtual = strtoul(argv[4], 0, 0);
349 varset.bits_per_pixel = strtoul(argv[5], 0, 0);
350 break;
351 case CMD_TIMING:
352 varset.pixclock = strtoul(argv[1], 0, 0);
353 varset.left_margin = strtoul(argv[2], 0, 0);
354 varset.right_margin = strtoul(argv[3], 0, 0);
355 varset.upper_margin = strtoul(argv[4], 0, 0);
356 varset.lower_margin = strtoul(argv[5], 0, 0);
357 varset.hsync_len = strtoul(argv[6], 0, 0);
358 varset.vsync_len = strtoul(argv[7], 0, 0);
359 break;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000360 case CMD_CHANGE:
361 g_options |= OPT_CHANGE;
362 break;
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000363#ifdef CONFIG_FEATURE_FBSET_FANCY
Erik Andersene49d5ec2000-02-08 19:58:47 +0000364 case CMD_XRES:
365 varset.xres = strtoul(argv[1], 0, 0);
366 break;
367 case CMD_YRES:
368 varset.yres = strtoul(argv[1], 0, 0);
369 break;
Eric Andersen927c3bd2002-09-17 08:44:56 +0000370 case CMD_DEPTH:
371 varset.bits_per_pixel = strtoul(argv[1], 0, 0);
372 break;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000373#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000374 }
375 argc -= g_cmdoptions[i].param_count;
376 argv += g_cmdoptions[i].param_count;
377 break;
378 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000379 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000380 if (!g_cmdoptions[i].name) {
381 if (argc == 1) {
382 mode = *argv;
383 g_options |= OPT_READMODE;
384 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000385 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000386 }
387 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000388 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000389
Rob Landleyd921b2e2006-08-03 15:41:12 +0000390 fh = xopen(fbdev, O_RDONLY);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000391 if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000392 bb_perror_msg_and_die("fbset(ioctl)");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000393 if (g_options & OPT_READMODE) {
394 if (!readmode(&var, modefile, mode)) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000395 bb_error_msg("Unknown video mode `%s'", mode);
Matt Kraai3e856ce2000-12-01 02:55:13 +0000396 return EXIT_FAILURE;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000397 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000398 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000399
Erik Andersene49d5ec2000-02-08 19:58:47 +0000400 setmode(&var, &varset);
401 if (g_options & OPT_CHANGE)
402 if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000403 bb_perror_msg_and_die("fbset(ioctl)");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000404 showmode(&var);
Erik Andersen298854f2000-03-23 01:09:18 +0000405 /* Don't close the file, as exiting will take care of that */
406 /* close(fh); */
Erik Andersene49d5ec2000-02-08 19:58:47 +0000407
Matt Kraai3e856ce2000-12-01 02:55:13 +0000408 return EXIT_SUCCESS;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000409}