blob: 7d3cae2510a7bee1fad5e7f1393d1a2a0b35aab6 [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
Erik Andersen1c5b2581999-12-16 20:59:36 +000015#include <stdio.h>
16#include <stdlib.h>
17#include <unistd.h>
18#include <fcntl.h>
19#include <errno.h>
20#include <ctype.h>
Eric Andersened3ef502001-01-27 08:24:39 +000021#include <string.h>
Eric Andersen1eceb122003-07-14 19:32:40 +000022#include <stdint.h>
Erik Andersen1c5b2581999-12-16 20:59:36 +000023#include <sys/ioctl.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000024#include "busybox.h"
Erik Andersen1c5b2581999-12-16 20:59:36 +000025
Eric Andersen5f284552003-11-14 03:11:29 +000026#define DEFAULTFBDEV FB_0
Erik Andersen1c5b2581999-12-16 20:59:36 +000027#define DEFAULTFBMODE "/etc/fb.modes"
28
Mark Whitley59ab0252001-01-23 22:30:04 +000029enum {
Rob Landleybc68cd12006-03-10 19:22:06 +000030 OPT_CHANGE = (1 << 0),
31 OPT_INFO = (1 << 1),
32 OPT_READMODE = (1 << 2),
33
Mark Whitley59ab0252001-01-23 22:30:04 +000034 CMD_FB = 1,
35 CMD_DB = 2,
36 CMD_GEOMETRY = 3,
37 CMD_TIMING = 4,
38 CMD_ACCEL = 5,
39 CMD_HSYNC = 6,
40 CMD_VSYNC = 7,
41 CMD_LACED = 8,
42 CMD_DOUBLE = 9,
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000043/* CMD_XCOMPAT = 10, */
Mark Whitley59ab0252001-01-23 22:30:04 +000044 CMD_ALL = 11,
45 CMD_INFO = 12,
46 CMD_CHANGE = 13,
Erik Andersen1c5b2581999-12-16 20:59:36 +000047
Eric Andersenbdfd0d72001-10-24 05:00:29 +000048#ifdef CONFIG_FEATURE_FBSET_FANCY
Mark Whitley59ab0252001-01-23 22:30:04 +000049 CMD_XRES = 100,
50 CMD_YRES = 101,
51 CMD_VXRES = 102,
52 CMD_VYRES = 103,
53 CMD_DEPTH = 104,
54 CMD_MATCH = 105,
55 CMD_PIXCLOCK = 106,
56 CMD_LEFT = 107,
57 CMD_RIGHT = 108,
58 CMD_UPPER = 109,
59 CMD_LOWER = 110,
60 CMD_HSLEN = 111,
61 CMD_VSLEN = 112,
62 CMD_CSYNC = 113,
63 CMD_GSYNC = 114,
64 CMD_EXTSYNC = 115,
65 CMD_BCAST = 116,
66 CMD_RGBA = 117,
67 CMD_STEP = 118,
68 CMD_MOVE = 119,
Erik Andersen1c5b2581999-12-16 20:59:36 +000069#endif
Mark Whitley59ab0252001-01-23 22:30:04 +000070};
Erik Andersen1c5b2581999-12-16 20:59:36 +000071
72static unsigned int g_options = 0;
73
Eric Andersenc873d612000-09-21 04:09:58 +000074/* Stuff stolen from the kernel's fb.h */
Rob Landleybc68cd12006-03-10 19:22:06 +000075enum {
76 FBIOGET_VSCREENINFO = 0x4600,
77 FBIOPUT_VSCREENINFO = 0x4601
78};
Eric Andersenc873d612000-09-21 04:09:58 +000079struct fb_bitfield {
Eric Andersen1eceb122003-07-14 19:32:40 +000080 uint32_t offset; /* beginning of bitfield */
81 uint32_t length; /* length of bitfield */
Eric Andersenc7bda1c2004-03-15 08:29:22 +000082 uint32_t msb_right; /* != 0 : Most significant bit is */
83 /* right */
Eric Andersenc873d612000-09-21 04:09:58 +000084};
85struct fb_var_screeninfo {
Eric Andersen1eceb122003-07-14 19:32:40 +000086 uint32_t xres; /* visible resolution */
87 uint32_t yres;
88 uint32_t xres_virtual; /* virtual resolution */
89 uint32_t yres_virtual;
90 uint32_t xoffset; /* offset from virtual to visible */
91 uint32_t yoffset; /* resolution */
Eric Andersenc873d612000-09-21 04:09:58 +000092
Eric Andersen1eceb122003-07-14 19:32:40 +000093 uint32_t bits_per_pixel; /* guess what */
94 uint32_t grayscale; /* != 0 Graylevels instead of colors */
Eric Andersenc873d612000-09-21 04:09:58 +000095
96 struct fb_bitfield red; /* bitfield in fb mem if true color, */
97 struct fb_bitfield green; /* else only length is significant */
98 struct fb_bitfield blue;
Eric Andersenc7bda1c2004-03-15 08:29:22 +000099 struct fb_bitfield transp; /* transparency */
Eric Andersenc873d612000-09-21 04:09:58 +0000100
Eric Andersen1eceb122003-07-14 19:32:40 +0000101 uint32_t nonstd; /* != 0 Non standard pixel format */
Eric Andersenc873d612000-09-21 04:09:58 +0000102
Eric Andersen1eceb122003-07-14 19:32:40 +0000103 uint32_t activate; /* see FB_ACTIVATE_* */
Eric Andersenc873d612000-09-21 04:09:58 +0000104
Eric Andersen1eceb122003-07-14 19:32:40 +0000105 uint32_t height; /* height of picture in mm */
106 uint32_t width; /* width of picture in mm */
Eric Andersenc873d612000-09-21 04:09:58 +0000107
Eric Andersen1eceb122003-07-14 19:32:40 +0000108 uint32_t accel_flags; /* acceleration flags (hints) */
Eric Andersenc873d612000-09-21 04:09:58 +0000109
110 /* Timing: All values in pixclocks, except pixclock (of course) */
Eric Andersen1eceb122003-07-14 19:32:40 +0000111 uint32_t pixclock; /* pixel clock in ps (pico seconds) */
112 uint32_t left_margin; /* time from sync to picture */
113 uint32_t right_margin; /* time from picture to sync */
114 uint32_t upper_margin; /* time from sync to picture */
115 uint32_t lower_margin;
116 uint32_t hsync_len; /* length of horizontal sync */
117 uint32_t vsync_len; /* length of vertical sync */
118 uint32_t sync; /* see FB_SYNC_* */
119 uint32_t vmode; /* see FB_VMODE_* */
120 uint32_t reserved[6]; /* Reserved for future compatibility */
Eric Andersenc873d612000-09-21 04:09:58 +0000121};
122
123
"Vladimir N. Oleynik"b399a962006-02-01 12:41:35 +0000124static const struct cmdoptions_t {
Aaron Lehmann60694412002-08-13 04:19:23 +0000125 const char *name;
126 const unsigned char param_count;
127 const unsigned char code;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000128} g_cmdoptions[] = {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000129 {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000130 "-fb", 1, CMD_FB}, {
131 "-db", 1, CMD_DB}, {
132 "-a", 0, CMD_ALL}, {
133 "-i", 0, CMD_INFO}, {
134 "-g", 5, CMD_GEOMETRY}, {
135 "-t", 7, CMD_TIMING}, {
136 "-accel", 1, CMD_ACCEL}, {
137 "-hsync", 1, CMD_HSYNC}, {
138 "-vsync", 1, CMD_VSYNC}, {
139 "-laced", 1, CMD_LACED}, {
Erik Andersen9cf3bfa2000-04-13 18:49:43 +0000140 "-double", 1, CMD_DOUBLE}, {
Eric Andersenc8c10c52000-07-06 17:23:23 +0000141 "-n", 0, CMD_CHANGE}, {
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000142#ifdef CONFIG_FEATURE_FBSET_FANCY
Erik Andersene49d5ec2000-02-08 19:58:47 +0000143 "-all", 0, CMD_ALL}, {
144 "-xres", 1, CMD_XRES}, {
145 "-yres", 1, CMD_YRES}, {
146 "-vxres", 1, CMD_VXRES}, {
147 "-vyres", 1, CMD_VYRES}, {
148 "-depth", 1, CMD_DEPTH}, {
149 "-match", 0, CMD_MATCH}, {
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000150 "-geometry", 5, CMD_GEOMETRY}, {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000151 "-pixclock", 1, CMD_PIXCLOCK}, {
152 "-left", 1, CMD_LEFT}, {
153 "-right", 1, CMD_RIGHT}, {
154 "-upper", 1, CMD_UPPER}, {
155 "-lower", 1, CMD_LOWER}, {
156 "-hslen", 1, CMD_HSLEN}, {
157 "-vslen", 1, CMD_VSLEN}, {
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000158 "-timings", 7, CMD_TIMING}, {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000159 "-csync", 1, CMD_CSYNC}, {
160 "-gsync", 1, CMD_GSYNC}, {
161 "-extsync", 1, CMD_EXTSYNC}, {
162 "-bcast", 1, CMD_BCAST}, {
163 "-rgba", 1, CMD_RGBA}, {
164 "-step", 1, CMD_STEP}, {
Erik Andersen9cf3bfa2000-04-13 18:49:43 +0000165 "-move", 1, CMD_MOVE}, {
Erik Andersen1c5b2581999-12-16 20:59:36 +0000166#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000167 0, 0, 0}
Erik Andersen1c5b2581999-12-16 20:59:36 +0000168};
169
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000170#ifdef CONFIG_FEATURE_FBSET_READMODE
Matt Kraai269e07c2000-10-28 16:56:32 +0000171/* taken from linux/fb.h */
Rob Landleybc68cd12006-03-10 19:22:06 +0000172enum {
173 FB_VMODE_INTERLACED = 1, /* interlaced */
174 FB_VMODE_DOUBLE = 2, /* double scan */
175 FB_SYNC_HOR_HIGH_ACT = 1, /* horizontal sync high active */
176 FB_SYNC_VERT_HIGH_ACT = 2, /* vertical sync high active */
177 FB_SYNC_EXT = 4, /* external sync */
178 FB_SYNC_COMP_HIGH_ACT = 8 /* composite sync high active */
179};
Matt Kraai269e07c2000-10-28 16:56:32 +0000180#endif
Erik Andersen1c5b2581999-12-16 20:59:36 +0000181static int readmode(struct fb_var_screeninfo *base, const char *fn,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000182 const char *mode)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000183{
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000184#ifdef CONFIG_FEATURE_FBSET_READMODE
Erik Andersene49d5ec2000-02-08 19:58:47 +0000185 FILE *f;
186 char buf[256];
187 char *p = buf;
188
Manuel Novoa III cad53642003-03-19 09:13:01 +0000189 f = bb_xfopen(fn, "r");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000190 while (!feof(f)) {
191 fgets(buf, sizeof(buf), f);
192 if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
193 p += 5;
194 if ((p = strstr(buf, mode))) {
195 p += strlen(mode);
196 if (!isspace(*p) && (*p != 0) && (*p != '"')
197 && (*p != '\r') && (*p != '\n'))
198 continue; /* almost, but not quite */
199 while (!feof(f)) {
200 fgets(buf, sizeof(buf), f);
Eric Andersen6f96e672000-07-12 23:01:04 +0000201
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000202 if ((p = strstr(buf, "geometry "))) {
203 p += 9;
Eric Andersen6f96e672000-07-12 23:01:04 +0000204
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000205 sscanf(p, "%d %d %d %d %d",
206 &(base->xres), &(base->yres),
207 &(base->xres_virtual), &(base->yres_virtual),
208 &(base->bits_per_pixel));
209 } else if ((p = strstr(buf, "timings "))) {
210 p += 8;
Eric Andersen6f96e672000-07-12 23:01:04 +0000211
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000212 sscanf(p, "%d %d %d %d %d %d %d",
213 &(base->pixclock),
214 &(base->left_margin), &(base->right_margin),
215 &(base->upper_margin), &(base->lower_margin),
216 &(base->hsync_len), &(base->vsync_len));
217 } else if ((p = strstr(buf, "laced "))) {
218 p += 6;
Eric Andersen6f96e672000-07-12 23:01:04 +0000219
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000220 if (strstr(buf, "false")) {
221 base->vmode &= ~FB_VMODE_INTERLACED;
222 } else {
223 base->vmode |= FB_VMODE_INTERLACED;
224 }
225 } else if ((p = strstr(buf, "double "))) {
226 p += 7;
Eric Andersen6f96e672000-07-12 23:01:04 +0000227
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000228 if (strstr(buf, "false")) {
229 base->vmode &= ~FB_VMODE_DOUBLE;
230 } else {
231 base->vmode |= FB_VMODE_DOUBLE;
232 }
233 } else if ((p = strstr(buf, "vsync "))) {
234 p += 6;
Eric Andersen6f96e672000-07-12 23:01:04 +0000235
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000236 if (strstr(buf, "low")) {
237 base->sync &= ~FB_SYNC_VERT_HIGH_ACT;
238 } else {
239 base->sync |= FB_SYNC_VERT_HIGH_ACT;
240 }
241 } else if ((p = strstr(buf, "hsync "))) {
242 p += 6;
Eric Andersen6f96e672000-07-12 23:01:04 +0000243
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000244 if (strstr(buf, "low")) {
245 base->sync &= ~FB_SYNC_HOR_HIGH_ACT;
246 } else {
247 base->sync |= FB_SYNC_HOR_HIGH_ACT;
248 }
249 } else if ((p = strstr(buf, "csync "))) {
250 p += 6;
Eric Andersen6f96e672000-07-12 23:01:04 +0000251
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000252 if (strstr(buf, "low")) {
253 base->sync &= ~FB_SYNC_COMP_HIGH_ACT;
254 } else {
255 base->sync |= FB_SYNC_COMP_HIGH_ACT;
256 }
257 } else if ((p = strstr(buf, "extsync "))) {
258 p += 8;
259
260 if (strstr(buf, "false")) {
261 base->sync &= ~FB_SYNC_EXT;
262 } else {
263 base->sync |= FB_SYNC_EXT;
264 }
265 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000266
Eric Andersen6f96e672000-07-12 23:01:04 +0000267 if (strstr(buf, "endmode"))
Erik Andersene49d5ec2000-02-08 19:58:47 +0000268 return 1;
269 }
270 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000271 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000272 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000273#else
Manuel Novoa III cad53642003-03-19 09:13:01 +0000274 bb_error_msg( "mode reading not compiled in");
Erik Andersen1c5b2581999-12-16 20:59:36 +0000275#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000276 return 0;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000277}
278
Aaron Lehmann60694412002-08-13 04:19:23 +0000279static inline void setmode(struct fb_var_screeninfo *base,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000280 struct fb_var_screeninfo *set)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000281{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000282 if ((int) set->xres > 0)
283 base->xres = set->xres;
284 if ((int) set->yres > 0)
285 base->yres = set->yres;
286 if ((int) set->xres_virtual > 0)
287 base->xres_virtual = set->xres_virtual;
288 if ((int) set->yres_virtual > 0)
289 base->yres_virtual = set->yres_virtual;
290 if ((int) set->bits_per_pixel > 0)
291 base->bits_per_pixel = set->bits_per_pixel;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000292}
293
Aaron Lehmann60694412002-08-13 04:19:23 +0000294static inline void showmode(struct fb_var_screeninfo *v)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000295{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000296 double drate = 0, hrate = 0, vrate = 0;
297
298 if (v->pixclock) {
299 drate = 1e12 / v->pixclock;
300 hrate =
301 drate / (v->left_margin + v->xres + v->right_margin +
302 v->hsync_len);
303 vrate =
304 hrate / (v->upper_margin + v->yres + v->lower_margin +
305 v->vsync_len);
306 }
Aaron Lehmann60694412002-08-13 04:19:23 +0000307 printf("\nmode \"%ux%u-%u\"\n"
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000308#ifdef CONFIG_FEATURE_FBSET_FANCY
Aaron Lehmann60694412002-08-13 04:19:23 +0000309 "\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n"
Erik Andersen1c5b2581999-12-16 20:59:36 +0000310#endif
Aaron Lehmann60694412002-08-13 04:19:23 +0000311 "\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",
312 v->xres, v->yres, (int) (vrate + 0.5),
313#ifdef CONFIG_FEATURE_FBSET_FANCY
314 drate / 1e6, hrate / 1e3, vrate,
315#endif
316 v->xres, v->yres, v->xres_virtual, v->yres_virtual,
317 v->bits_per_pixel, v->pixclock, v->left_margin,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000318 v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
Aaron Lehmann60694412002-08-13 04:19:23 +0000319 v->vsync_len, (v->accel_flags > 0 ? "true" : "false"), v->red.length,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000320 v->red.offset, v->green.length, v->green.offset, v->blue.length,
321 v->blue.offset, v->transp.length, v->transp.offset);
Erik Andersen1c5b2581999-12-16 20:59:36 +0000322}
323
Erik Andersen1c5b2581999-12-16 20:59:36 +0000324#ifdef STANDALONE
325int main(int argc, char **argv)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000326#else
Rob Landleydfba7412006-03-06 20:47:33 +0000327int fbset_main(int argc, char **argv)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000328#endif
329{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000330 struct fb_var_screeninfo var, varset;
331 int fh, i;
332 char *fbdev = DEFAULTFBDEV;
333 char *modefile = DEFAULTFBMODE;
334 char *thisarg, *mode = NULL;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000335
Erik Andersene49d5ec2000-02-08 19:58:47 +0000336 memset(&varset, 0xFF, sizeof(varset));
337
338 /* parse cmd args.... why do they have to make things so difficult? */
339 argv++;
340 argc--;
341 for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
342 for (i = 0; g_cmdoptions[i].name; i++) {
343 if (!strcmp(thisarg, g_cmdoptions[i].name)) {
344 if (argc - 1 < g_cmdoptions[i].param_count)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000345 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000346 switch (g_cmdoptions[i].code) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000347 case CMD_FB:
348 fbdev = argv[1];
349 break;
350 case CMD_DB:
351 modefile = argv[1];
352 break;
353 case CMD_GEOMETRY:
354 varset.xres = strtoul(argv[1], 0, 0);
355 varset.yres = strtoul(argv[2], 0, 0);
356 varset.xres_virtual = strtoul(argv[3], 0, 0);
357 varset.yres_virtual = strtoul(argv[4], 0, 0);
358 varset.bits_per_pixel = strtoul(argv[5], 0, 0);
359 break;
360 case CMD_TIMING:
361 varset.pixclock = strtoul(argv[1], 0, 0);
362 varset.left_margin = strtoul(argv[2], 0, 0);
363 varset.right_margin = strtoul(argv[3], 0, 0);
364 varset.upper_margin = strtoul(argv[4], 0, 0);
365 varset.lower_margin = strtoul(argv[5], 0, 0);
366 varset.hsync_len = strtoul(argv[6], 0, 0);
367 varset.vsync_len = strtoul(argv[7], 0, 0);
368 break;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000369 case CMD_CHANGE:
370 g_options |= OPT_CHANGE;
371 break;
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000372#ifdef CONFIG_FEATURE_FBSET_FANCY
Erik Andersene49d5ec2000-02-08 19:58:47 +0000373 case CMD_XRES:
374 varset.xres = strtoul(argv[1], 0, 0);
375 break;
376 case CMD_YRES:
377 varset.yres = strtoul(argv[1], 0, 0);
378 break;
Eric Andersen927c3bd2002-09-17 08:44:56 +0000379 case CMD_DEPTH:
380 varset.bits_per_pixel = strtoul(argv[1], 0, 0);
381 break;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000382#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000383 }
384 argc -= g_cmdoptions[i].param_count;
385 argv += g_cmdoptions[i].param_count;
386 break;
387 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000388 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000389 if (!g_cmdoptions[i].name) {
390 if (argc == 1) {
391 mode = *argv;
392 g_options |= OPT_READMODE;
393 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000394 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000395 }
396 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000397 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000398
Bernhard Reutner-Fischerdac7ff12006-04-12 17:55:51 +0000399 fh = bb_xopen(fbdev, O_RDONLY);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000400 if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000401 bb_perror_msg_and_die("fbset(ioctl)");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000402 if (g_options & OPT_READMODE) {
403 if (!readmode(&var, modefile, mode)) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000404 bb_error_msg("Unknown video mode `%s'", mode);
Matt Kraai3e856ce2000-12-01 02:55:13 +0000405 return EXIT_FAILURE;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000406 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000407 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000408
Erik Andersene49d5ec2000-02-08 19:58:47 +0000409 setmode(&var, &varset);
410 if (g_options & OPT_CHANGE)
411 if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000412 bb_perror_msg_and_die("fbset(ioctl)");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000413 showmode(&var);
Erik Andersen298854f2000-03-23 01:09:18 +0000414 /* Don't close the file, as exiting will take care of that */
415 /* close(fh); */
Erik Andersene49d5ec2000-02-08 19:58:47 +0000416
Matt Kraai3e856ce2000-12-01 02:55:13 +0000417 return EXIT_SUCCESS;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000418}