2000-02-09 01:28:47 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
1999-12-17 02:29:36 +05:30
|
|
|
/*
|
|
|
|
* Mini fbset implementation for busybox
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
1999-12-17 02:29:36 +05:30
|
|
|
*
|
|
|
|
* This is a from-scratch implementation of fbset; but the de facto fbset
|
|
|
|
* implementation was a good reference. fbset (original) is released under
|
2004-03-15 13:59:22 +05:30
|
|
|
* the GPL, and is (c) 1995-1999 by:
|
1999-12-17 02:29:36 +05:30
|
|
|
* Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
|
|
|
|
*/
|
|
|
|
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.h"
|
1999-12-17 02:29:36 +05:30
|
|
|
|
2003-11-14 08:41:29 +05:30
|
|
|
#define DEFAULTFBDEV FB_0
|
1999-12-17 02:29:36 +05:30
|
|
|
#define DEFAULTFBMODE "/etc/fb.modes"
|
|
|
|
|
2000-09-21 09:39:58 +05:30
|
|
|
/* Stuff stolen from the kernel's fb.h */
|
2006-09-30 21:52:59 +05:30
|
|
|
#define FB_ACTIVATE_ALL 64
|
2006-03-11 00:52:06 +05:30
|
|
|
enum {
|
|
|
|
FBIOGET_VSCREENINFO = 0x4600,
|
|
|
|
FBIOPUT_VSCREENINFO = 0x4601
|
|
|
|
};
|
2010-01-23 08:10:28 +05:30
|
|
|
|
2000-09-21 09:39:58 +05:30
|
|
|
struct fb_bitfield {
|
2006-09-30 21:58:30 +05:30
|
|
|
uint32_t offset; /* beginning of bitfield */
|
|
|
|
uint32_t length; /* length of bitfield */
|
|
|
|
uint32_t msb_right; /* !=0: Most significant bit is right */
|
2000-09-21 09:39:58 +05:30
|
|
|
};
|
|
|
|
struct fb_var_screeninfo {
|
2006-09-30 21:58:30 +05:30
|
|
|
uint32_t xres; /* visible resolution */
|
2003-07-15 01:02:40 +05:30
|
|
|
uint32_t yres;
|
2006-09-30 21:58:30 +05:30
|
|
|
uint32_t xres_virtual; /* virtual resolution */
|
2003-07-15 01:02:40 +05:30
|
|
|
uint32_t yres_virtual;
|
2006-09-30 21:58:30 +05:30
|
|
|
uint32_t xoffset; /* offset from virtual to visible */
|
|
|
|
uint32_t yoffset; /* resolution */
|
2000-09-21 09:39:58 +05:30
|
|
|
|
2006-09-30 21:58:30 +05:30
|
|
|
uint32_t bits_per_pixel;
|
|
|
|
uint32_t grayscale; /* !=0 Graylevels instead of colors */
|
2000-09-21 09:39:58 +05:30
|
|
|
|
2006-09-30 21:58:30 +05:30
|
|
|
struct fb_bitfield red; /* bitfield in fb mem if true color, */
|
|
|
|
struct fb_bitfield green; /* else only length is significant */
|
2000-09-21 09:39:58 +05:30
|
|
|
struct fb_bitfield blue;
|
2006-09-30 21:58:30 +05:30
|
|
|
struct fb_bitfield transp; /* transparency */
|
2000-09-21 09:39:58 +05:30
|
|
|
|
2006-09-30 21:58:30 +05:30
|
|
|
uint32_t nonstd; /* !=0 Non standard pixel format */
|
2000-09-21 09:39:58 +05:30
|
|
|
|
2006-09-30 21:58:30 +05:30
|
|
|
uint32_t activate; /* see FB_ACTIVATE_x */
|
2000-09-21 09:39:58 +05:30
|
|
|
|
2006-09-30 21:58:30 +05:30
|
|
|
uint32_t height; /* height of picture in mm */
|
|
|
|
uint32_t width; /* width of picture in mm */
|
2000-09-21 09:39:58 +05:30
|
|
|
|
2009-04-02 01:18:05 +05:30
|
|
|
uint32_t accel_flags; /* acceleration flags (hints) */
|
2000-09-21 09:39:58 +05:30
|
|
|
|
|
|
|
/* Timing: All values in pixclocks, except pixclock (of course) */
|
2006-09-30 21:58:30 +05:30
|
|
|
uint32_t pixclock; /* pixel clock in ps (pico seconds) */
|
|
|
|
uint32_t left_margin; /* time from sync to picture */
|
|
|
|
uint32_t right_margin; /* time from picture to sync */
|
|
|
|
uint32_t upper_margin; /* time from sync to picture */
|
2003-07-15 01:02:40 +05:30
|
|
|
uint32_t lower_margin;
|
2006-09-30 21:58:30 +05:30
|
|
|
uint32_t hsync_len; /* length of horizontal sync */
|
|
|
|
uint32_t vsync_len; /* length of vertical sync */
|
|
|
|
uint32_t sync; /* see FB_SYNC_x */
|
|
|
|
uint32_t vmode; /* see FB_VMODE_x */
|
|
|
|
uint32_t reserved[6]; /* Reserved for future compatibility */
|
2000-09-21 09:39:58 +05:30
|
|
|
};
|
|
|
|
|
2010-01-23 08:10:28 +05:30
|
|
|
static void copy_if_gt0(uint32_t *src, uint32_t *dst, unsigned cnt)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
if ((int32_t) *src > 0)
|
|
|
|
*dst = *src;
|
|
|
|
src++;
|
|
|
|
dst++;
|
|
|
|
} while (--cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NOINLINE void copy_changed_values(
|
|
|
|
struct fb_var_screeninfo *base,
|
|
|
|
struct fb_var_screeninfo *set)
|
|
|
|
{
|
|
|
|
//if ((int32_t) set->xres > 0) base->xres = set->xres;
|
|
|
|
//if ((int32_t) set->yres > 0) base->yres = set->yres;
|
|
|
|
//if ((int32_t) set->xres_virtual > 0) base->xres_virtual = set->xres_virtual;
|
|
|
|
//if ((int32_t) set->yres_virtual > 0) base->yres_virtual = set->yres_virtual;
|
|
|
|
copy_if_gt0(&set->xres, &base->xres, 4);
|
|
|
|
|
|
|
|
if ((int32_t) set->bits_per_pixel > 0) base->bits_per_pixel = set->bits_per_pixel;
|
|
|
|
//copy_if_gt0(&set->bits_per_pixel, &base->bits_per_pixel, 1);
|
|
|
|
|
|
|
|
//if ((int32_t) set->pixclock > 0) base->pixclock = set->pixclock;
|
|
|
|
//if ((int32_t) set->left_margin > 0) base->left_margin = set->left_margin;
|
|
|
|
//if ((int32_t) set->right_margin > 0) base->right_margin = set->right_margin;
|
|
|
|
//if ((int32_t) set->upper_margin > 0) base->upper_margin = set->upper_margin;
|
|
|
|
//if ((int32_t) set->lower_margin > 0) base->lower_margin = set->lower_margin;
|
|
|
|
//if ((int32_t) set->hsync_len > 0) base->hsync_len = set->hsync_len;
|
|
|
|
//if ((int32_t) set->vsync_len > 0) base->vsync_len = set->vsync_len;
|
|
|
|
//if ((int32_t) set->sync > 0) base->sync = set->sync;
|
|
|
|
//if ((int32_t) set->vmode > 0) base->vmode = set->vmode;
|
|
|
|
copy_if_gt0(&set->pixclock, &base->pixclock, 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CMD_FB = 1,
|
|
|
|
CMD_DB = 2,
|
|
|
|
CMD_GEOMETRY = 3,
|
|
|
|
CMD_TIMING = 4,
|
|
|
|
CMD_ACCEL = 5,
|
|
|
|
CMD_HSYNC = 6,
|
|
|
|
CMD_VSYNC = 7,
|
|
|
|
CMD_LACED = 8,
|
|
|
|
CMD_DOUBLE = 9,
|
|
|
|
/* CMD_XCOMPAT = 10, */
|
|
|
|
CMD_ALL = 11,
|
|
|
|
CMD_INFO = 12,
|
|
|
|
CMD_SHOW = 13,
|
|
|
|
CMD_CHANGE = 14,
|
|
|
|
|
|
|
|
#if ENABLE_FEATURE_FBSET_FANCY
|
|
|
|
CMD_XRES = 100,
|
|
|
|
CMD_YRES = 101,
|
|
|
|
CMD_VXRES = 102,
|
|
|
|
CMD_VYRES = 103,
|
|
|
|
CMD_DEPTH = 104,
|
|
|
|
CMD_MATCH = 105,
|
|
|
|
CMD_PIXCLOCK = 106,
|
|
|
|
CMD_LEFT = 107,
|
|
|
|
CMD_RIGHT = 108,
|
|
|
|
CMD_UPPER = 109,
|
|
|
|
CMD_LOWER = 110,
|
|
|
|
CMD_HSLEN = 111,
|
|
|
|
CMD_VSLEN = 112,
|
|
|
|
CMD_CSYNC = 113,
|
|
|
|
CMD_GSYNC = 114,
|
|
|
|
CMD_EXTSYNC = 115,
|
|
|
|
CMD_BCAST = 116,
|
|
|
|
CMD_RGBA = 117,
|
|
|
|
CMD_STEP = 118,
|
|
|
|
CMD_MOVE = 119,
|
|
|
|
#endif
|
|
|
|
};
|
2000-09-21 09:39:58 +05:30
|
|
|
|
2006-02-01 18:11:35 +05:30
|
|
|
static const struct cmdoptions_t {
|
2008-08-24 21:55:40 +05:30
|
|
|
const char name[9];
|
minor fixes for fbset bloat
<mjn3> printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres,
<mjn3> v->xres_virtual, v->yres_virtual, v->bits_per_pixel);
<mjn3> printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin,
<mjn3> v->right_margin, v->upper_margin, v->lower_margin, v->hsync_l
<mjn3> en,
<mjn3> v->vsync_len);
<mjn3> printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false"));
<mjn3> printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length,
<mjn3> v->red.offset, v->green.length, v->green.offset, v->blue.leng
<mjn3> th,
<mjn3> v->blue.offset, v->transp.length, v->transp.offset);
<mjn3> printf("endmode\n\n");
<mjn3> whay have multiple printf calls when one would do?
<mjn3> and this:
<mjn3> static struct cmdoptions_t {
<mjn3> char *name;
<mjn3> unsigned char param_count;
<mjn3> unsigned char code;
<mjn3> } g_cmdoptions[] = {
<mjn3> {
<mjn3> "-fb", 1, CMD_FB}, {
<mjn3> (repeated entries)
<mjn3> why isn't this constant? what about struct packing?
inline the helper functions that are only referenced once.
2002-08-13 09:49:23 +05:30
|
|
|
const unsigned char param_count;
|
|
|
|
const unsigned char code;
|
1999-12-17 02:29:36 +05:30
|
|
|
} g_cmdoptions[] = {
|
2008-08-24 21:55:40 +05:30
|
|
|
/*"12345678" + NUL */
|
|
|
|
{ "fb" , 1, CMD_FB },
|
|
|
|
{ "db" , 1, CMD_DB },
|
|
|
|
{ "a" , 0, CMD_ALL },
|
|
|
|
{ "i" , 0, CMD_INFO },
|
|
|
|
{ "g" , 5, CMD_GEOMETRY },
|
|
|
|
{ "t" , 7, CMD_TIMING },
|
|
|
|
{ "accel" , 1, CMD_ACCEL },
|
|
|
|
{ "hsync" , 1, CMD_HSYNC },
|
|
|
|
{ "vsync" , 1, CMD_VSYNC },
|
|
|
|
{ "laced" , 1, CMD_LACED },
|
|
|
|
{ "double" , 1, CMD_DOUBLE },
|
2009-02-18 20:58:43 +05:30
|
|
|
{ "show" , 0, CMD_SHOW },
|
|
|
|
{ "s" , 0, CMD_SHOW },
|
2007-08-13 16:06:25 +05:30
|
|
|
#if ENABLE_FEATURE_FBSET_FANCY
|
2008-08-24 21:55:40 +05:30
|
|
|
{ "all" , 0, CMD_ALL },
|
|
|
|
{ "xres" , 1, CMD_XRES },
|
|
|
|
{ "yres" , 1, CMD_YRES },
|
|
|
|
{ "vxres" , 1, CMD_VXRES },
|
|
|
|
{ "vyres" , 1, CMD_VYRES },
|
|
|
|
{ "depth" , 1, CMD_DEPTH },
|
|
|
|
{ "match" , 0, CMD_MATCH },
|
|
|
|
{ "geometry", 5, CMD_GEOMETRY },
|
|
|
|
{ "pixclock", 1, CMD_PIXCLOCK },
|
|
|
|
{ "left" , 1, CMD_LEFT },
|
|
|
|
{ "right" , 1, CMD_RIGHT },
|
|
|
|
{ "upper" , 1, CMD_UPPER },
|
|
|
|
{ "lower" , 1, CMD_LOWER },
|
|
|
|
{ "hslen" , 1, CMD_HSLEN },
|
|
|
|
{ "vslen" , 1, CMD_VSLEN },
|
|
|
|
{ "timings" , 7, CMD_TIMING },
|
|
|
|
{ "csync" , 1, CMD_CSYNC },
|
|
|
|
{ "gsync" , 1, CMD_GSYNC },
|
|
|
|
{ "extsync" , 1, CMD_EXTSYNC },
|
|
|
|
{ "bcast" , 1, CMD_BCAST },
|
|
|
|
{ "rgba" , 1, CMD_RGBA },
|
|
|
|
{ "step" , 1, CMD_STEP },
|
|
|
|
{ "move" , 1, CMD_MOVE },
|
1999-12-17 02:29:36 +05:30
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2000-10-28 22:26:32 +05:30
|
|
|
/* taken from linux/fb.h */
|
2006-03-11 00:52:06 +05:30
|
|
|
enum {
|
2008-08-24 21:55:40 +05:30
|
|
|
FB_SYNC_HOR_HIGH_ACT = 1, /* horizontal sync high active */
|
|
|
|
FB_SYNC_VERT_HIGH_ACT = 2, /* vertical sync high active */
|
2010-01-25 03:22:21 +05:30
|
|
|
#if ENABLE_FEATURE_FBSET_READMODE
|
|
|
|
FB_VMODE_INTERLACED = 1, /* interlaced */
|
|
|
|
FB_VMODE_DOUBLE = 2, /* double scan */
|
2008-08-24 21:55:40 +05:30
|
|
|
FB_SYNC_EXT = 4, /* external sync */
|
|
|
|
FB_SYNC_COMP_HIGH_ACT = 8, /* composite sync high active */
|
2000-10-28 22:26:32 +05:30
|
|
|
#endif
|
2010-01-25 03:22:21 +05:30
|
|
|
};
|
2006-09-30 21:58:30 +05:30
|
|
|
|
2008-07-29 16:40:01 +05:30
|
|
|
#if ENABLE_FEATURE_FBSET_READMODE
|
2008-07-28 02:46:30 +05:30
|
|
|
static void ss(uint32_t *x, uint32_t flag, char *buf, const char *what)
|
2008-07-28 01:55:29 +05:30
|
|
|
{
|
2008-08-24 21:55:40 +05:30
|
|
|
if (strcmp(buf, what) == 0)
|
2008-07-28 01:55:29 +05:30
|
|
|
*x &= ~flag;
|
|
|
|
else
|
|
|
|
*x |= flag;
|
|
|
|
}
|
|
|
|
|
2010-01-23 08:10:28 +05:30
|
|
|
/* Mode db file contains mode definitions like this:
|
|
|
|
* mode "800x600-48-lace"
|
|
|
|
* # D: 36.00 MHz, H: 33.835 kHz, V: 96.39 Hz
|
|
|
|
* geometry 800 600 800 600 8
|
|
|
|
* timings 27778 56 80 79 11 128 12
|
|
|
|
* laced true
|
|
|
|
* hsync high
|
|
|
|
* vsync high
|
|
|
|
* endmode
|
|
|
|
*/
|
2009-02-18 20:58:43 +05:30
|
|
|
static int read_mode_db(struct fb_var_screeninfo *base, const char *fn,
|
2000-02-09 01:28:47 +05:30
|
|
|
const char *mode)
|
1999-12-17 02:29:36 +05:30
|
|
|
{
|
2008-08-24 21:55:40 +05:30
|
|
|
char *token[2], *p, *s;
|
|
|
|
parser_t *parser = config_open(fn);
|
|
|
|
|
|
|
|
while (config_read(parser, token, 2, 1, "# \t\r", PARSE_NORMAL)) {
|
|
|
|
if (strcmp(token[0], "mode") != 0 || !token[1])
|
2006-09-30 21:58:30 +05:30
|
|
|
continue;
|
2008-08-24 21:55:40 +05:30
|
|
|
p = strstr(token[1], mode);
|
2007-11-06 08:35:54 +05:30
|
|
|
if (!p)
|
2006-09-30 21:58:30 +05:30
|
|
|
continue;
|
2008-08-24 21:55:40 +05:30
|
|
|
s = p + strlen(mode);
|
|
|
|
//bb_info_msg("CHECK[%s][%s][%d]", mode, p-1, *s);
|
|
|
|
/* exact match? */
|
|
|
|
if (((!*s || isspace(*s)) && '"' != s[-1]) /* end-of-token */
|
|
|
|
|| ('"' == *s && '"' == p[-1]) /* ends with " but starts with " too! */
|
2008-07-28 02:46:30 +05:30
|
|
|
) {
|
2008-08-24 21:55:40 +05:30
|
|
|
//bb_info_msg("FOUND[%s][%s][%s][%d]", token[1], p, mode, isspace(*s));
|
|
|
|
break;
|
2008-07-28 02:46:30 +05:30
|
|
|
}
|
2008-08-24 21:55:40 +05:30
|
|
|
}
|
2006-09-30 21:58:30 +05:30
|
|
|
|
2008-08-24 21:55:40 +05:30
|
|
|
if (!token[0])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (config_read(parser, token, 2, 1, "# \t", PARSE_NORMAL)) {
|
|
|
|
int i;
|
2006-09-30 21:58:30 +05:30
|
|
|
|
2008-08-24 21:55:40 +05:30
|
|
|
//bb_info_msg("???[%s][%s]", token[0], token[1]);
|
|
|
|
if (strcmp(token[0], "endmode") == 0) {
|
|
|
|
//bb_info_msg("OK[%s]", mode);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
p = token[1];
|
|
|
|
i = index_in_strings(
|
|
|
|
"geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0",
|
|
|
|
token[0]);
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
2010-01-23 08:10:28 +05:30
|
|
|
if (sizeof(int) == sizeof(base->xres)) {
|
|
|
|
sscanf(p, "%d %d %d %d %d",
|
|
|
|
&base->xres, &base->yres,
|
|
|
|
&base->xres_virtual, &base->yres_virtual,
|
|
|
|
&base->bits_per_pixel);
|
|
|
|
} else {
|
|
|
|
int base_xres, base_yres;
|
|
|
|
int base_xres_virtual, base_yres_virtual;
|
|
|
|
int base_bits_per_pixel;
|
|
|
|
sscanf(p, "%d %d %d %d %d",
|
|
|
|
&base_xres, &base_yres,
|
|
|
|
&base_xres_virtual, &base_yres_virtual,
|
|
|
|
&base_bits_per_pixel);
|
|
|
|
base->xres = base_xres;
|
|
|
|
base->yres = base_yres;
|
|
|
|
base->xres_virtual = base_xres_virtual;
|
|
|
|
base->yres_virtual = base_yres_virtual;
|
|
|
|
base->bits_per_pixel = base_bits_per_pixel;
|
|
|
|
}
|
2008-08-24 21:55:40 +05:30
|
|
|
//bb_info_msg("GEO[%s]", p);
|
|
|
|
break;
|
|
|
|
case 1:
|
2010-01-23 08:10:28 +05:30
|
|
|
if (sizeof(int) == sizeof(base->xres)) {
|
|
|
|
sscanf(p, "%d %d %d %d %d %d %d",
|
|
|
|
&base->pixclock,
|
|
|
|
&base->left_margin, &base->right_margin,
|
|
|
|
&base->upper_margin, &base->lower_margin,
|
|
|
|
&base->hsync_len, &base->vsync_len);
|
|
|
|
} else {
|
|
|
|
int base_pixclock;
|
|
|
|
int base_left_margin, base_right_margin;
|
|
|
|
int base_upper_margin, base_lower_margin;
|
|
|
|
int base_hsync_len, base_vsync_len;
|
|
|
|
sscanf(p, "%d %d %d %d %d %d %d",
|
|
|
|
&base_pixclock,
|
|
|
|
&base_left_margin, &base_right_margin,
|
|
|
|
&base_upper_margin, &base_lower_margin,
|
|
|
|
&base_hsync_len, &base_vsync_len);
|
|
|
|
base->pixclock = base_pixclock;
|
|
|
|
base->left_margin = base_left_margin;
|
|
|
|
base->right_margin = base_right_margin;
|
|
|
|
base->upper_margin = base_upper_margin;
|
|
|
|
base->lower_margin = base_lower_margin;
|
|
|
|
base->hsync_len = base_hsync_len;
|
|
|
|
base->vsync_len = base_vsync_len;
|
|
|
|
}
|
2008-08-24 21:55:40 +05:30
|
|
|
//bb_info_msg("TIM[%s]", p);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3: {
|
|
|
|
static const uint32_t syncs[] = {FB_VMODE_INTERLACED, FB_VMODE_DOUBLE};
|
|
|
|
ss(&base->vmode, syncs[i-2], p, "false");
|
|
|
|
//bb_info_msg("VMODE[%s]", p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
case 6: {
|
|
|
|
static const uint32_t syncs[] = {FB_SYNC_VERT_HIGH_ACT, FB_SYNC_HOR_HIGH_ACT, FB_SYNC_COMP_HIGH_ACT};
|
|
|
|
ss(&base->sync, syncs[i-4], p, "low");
|
|
|
|
//bb_info_msg("SYNC[%s]", p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
ss(&base->sync, FB_SYNC_EXT, p, "false");
|
|
|
|
//bb_info_msg("EXTSYNC[%s]", p);
|
|
|
|
break;
|
1999-12-17 02:29:36 +05:30
|
|
|
}
|
|
|
|
}
|
2000-02-09 01:28:47 +05:30
|
|
|
return 0;
|
1999-12-17 02:29:36 +05:30
|
|
|
}
|
2008-03-17 14:34:04 +05:30
|
|
|
#endif
|
1999-12-17 02:29:36 +05:30
|
|
|
|
2009-10-08 18:24:18 +05:30
|
|
|
static NOINLINE void showmode(struct fb_var_screeninfo *v)
|
1999-12-17 02:29:36 +05:30
|
|
|
{
|
2000-02-09 01:28:47 +05:30
|
|
|
double drate = 0, hrate = 0, vrate = 0;
|
|
|
|
|
|
|
|
if (v->pixclock) {
|
|
|
|
drate = 1e12 / v->pixclock;
|
2006-09-30 21:58:30 +05:30
|
|
|
hrate = drate / (v->left_margin + v->xres + v->right_margin + v->hsync_len);
|
|
|
|
vrate = hrate / (v->upper_margin + v->yres + v->lower_margin + v->vsync_len);
|
2000-02-09 01:28:47 +05:30
|
|
|
}
|
minor fixes for fbset bloat
<mjn3> printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres,
<mjn3> v->xres_virtual, v->yres_virtual, v->bits_per_pixel);
<mjn3> printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin,
<mjn3> v->right_margin, v->upper_margin, v->lower_margin, v->hsync_l
<mjn3> en,
<mjn3> v->vsync_len);
<mjn3> printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false"));
<mjn3> printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length,
<mjn3> v->red.offset, v->green.length, v->green.offset, v->blue.leng
<mjn3> th,
<mjn3> v->blue.offset, v->transp.length, v->transp.offset);
<mjn3> printf("endmode\n\n");
<mjn3> whay have multiple printf calls when one would do?
<mjn3> and this:
<mjn3> static struct cmdoptions_t {
<mjn3> char *name;
<mjn3> unsigned char param_count;
<mjn3> unsigned char code;
<mjn3> } g_cmdoptions[] = {
<mjn3> {
<mjn3> "-fb", 1, CMD_FB}, {
<mjn3> (repeated entries)
<mjn3> why isn't this constant? what about struct packing?
inline the helper functions that are only referenced once.
2002-08-13 09:49:23 +05:30
|
|
|
printf("\nmode \"%ux%u-%u\"\n"
|
2007-08-13 16:06:25 +05:30
|
|
|
#if ENABLE_FEATURE_FBSET_FANCY
|
minor fixes for fbset bloat
<mjn3> printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres,
<mjn3> v->xres_virtual, v->yres_virtual, v->bits_per_pixel);
<mjn3> printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin,
<mjn3> v->right_margin, v->upper_margin, v->lower_margin, v->hsync_l
<mjn3> en,
<mjn3> v->vsync_len);
<mjn3> printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false"));
<mjn3> printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length,
<mjn3> v->red.offset, v->green.length, v->green.offset, v->blue.leng
<mjn3> th,
<mjn3> v->blue.offset, v->transp.length, v->transp.offset);
<mjn3> printf("endmode\n\n");
<mjn3> whay have multiple printf calls when one would do?
<mjn3> and this:
<mjn3> static struct cmdoptions_t {
<mjn3> char *name;
<mjn3> unsigned char param_count;
<mjn3> unsigned char code;
<mjn3> } g_cmdoptions[] = {
<mjn3> {
<mjn3> "-fb", 1, CMD_FB}, {
<mjn3> (repeated entries)
<mjn3> why isn't this constant? what about struct packing?
inline the helper functions that are only referenced once.
2002-08-13 09:49:23 +05:30
|
|
|
"\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n"
|
1999-12-17 02:29:36 +05:30
|
|
|
#endif
|
2006-09-30 21:58:30 +05:30
|
|
|
"\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\n"
|
|
|
|
"endmode\n\n",
|
|
|
|
v->xres, v->yres, (int) (vrate + 0.5),
|
2007-08-13 16:06:25 +05:30
|
|
|
#if ENABLE_FEATURE_FBSET_FANCY
|
2006-09-30 21:58:30 +05:30
|
|
|
drate / 1e6, hrate / 1e3, vrate,
|
minor fixes for fbset bloat
<mjn3> printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres,
<mjn3> v->xres_virtual, v->yres_virtual, v->bits_per_pixel);
<mjn3> printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin,
<mjn3> v->right_margin, v->upper_margin, v->lower_margin, v->hsync_l
<mjn3> en,
<mjn3> v->vsync_len);
<mjn3> printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false"));
<mjn3> printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length,
<mjn3> v->red.offset, v->green.length, v->green.offset, v->blue.leng
<mjn3> th,
<mjn3> v->blue.offset, v->transp.length, v->transp.offset);
<mjn3> printf("endmode\n\n");
<mjn3> whay have multiple printf calls when one would do?
<mjn3> and this:
<mjn3> static struct cmdoptions_t {
<mjn3> char *name;
<mjn3> unsigned char param_count;
<mjn3> unsigned char code;
<mjn3> } g_cmdoptions[] = {
<mjn3> {
<mjn3> "-fb", 1, CMD_FB}, {
<mjn3> (repeated entries)
<mjn3> why isn't this constant? what about struct packing?
inline the helper functions that are only referenced once.
2002-08-13 09:49:23 +05:30
|
|
|
#endif
|
2006-09-30 21:58:30 +05:30
|
|
|
v->xres, v->yres, v->xres_virtual, v->yres_virtual, v->bits_per_pixel,
|
|
|
|
v->pixclock, v->left_margin, v->right_margin, v->upper_margin, v->lower_margin,
|
|
|
|
v->hsync_len, v->vsync_len,
|
|
|
|
(v->accel_flags > 0 ? "true" : "false"),
|
|
|
|
v->red.length, v->red.offset, v->green.length, v->green.offset,
|
|
|
|
v->blue.length, v->blue.offset, v->transp.length, v->transp.offset);
|
1999-12-17 02:29:36 +05:30
|
|
|
}
|
|
|
|
|
2007-10-11 15:35:36 +05:30
|
|
|
int fbset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2006-03-07 02:17:33 +05:30
|
|
|
int fbset_main(int argc, char **argv)
|
1999-12-17 02:29:36 +05:30
|
|
|
{
|
2008-08-24 21:55:40 +05:30
|
|
|
enum {
|
|
|
|
OPT_CHANGE = (1 << 0),
|
2009-02-18 20:58:43 +05:30
|
|
|
OPT_SHOW = (1 << 1),
|
2008-08-24 21:55:40 +05:30
|
|
|
OPT_READMODE = (1 << 2),
|
|
|
|
OPT_ALL = (1 << 9),
|
|
|
|
};
|
2010-01-23 08:10:28 +05:30
|
|
|
struct fb_var_screeninfo var_old, var_set;
|
2000-02-09 01:28:47 +05:30
|
|
|
int fh, i;
|
2008-08-24 21:55:40 +05:30
|
|
|
unsigned options = 0;
|
|
|
|
|
2007-01-30 04:21:25 +05:30
|
|
|
const char *fbdev = DEFAULTFBDEV;
|
|
|
|
const char *modefile = DEFAULTFBMODE;
|
2010-01-23 08:10:28 +05:30
|
|
|
char *thisarg;
|
|
|
|
char *mode = mode; /* for compiler */
|
2000-02-09 01:28:47 +05:30
|
|
|
|
2010-01-23 08:10:28 +05:30
|
|
|
memset(&var_set, 0xff, sizeof(var_set)); /* set all to -1 */
|
1999-12-17 02:29:36 +05:30
|
|
|
|
2000-02-09 01:28:47 +05:30
|
|
|
/* parse cmd args.... why do they have to make things so difficult? */
|
|
|
|
argv++;
|
|
|
|
argc--;
|
2008-08-24 21:55:40 +05:30
|
|
|
for (; argc > 0 && (thisarg = *argv) != NULL; argc--, argv++) {
|
|
|
|
if (thisarg[0] == '-') for (i = 0; i < ARRAY_SIZE(g_cmdoptions); i++) {
|
|
|
|
if (strcmp(thisarg + 1, g_cmdoptions[i].name) != 0)
|
2006-09-30 21:58:30 +05:30
|
|
|
continue;
|
2008-08-24 21:55:40 +05:30
|
|
|
if (argc <= g_cmdoptions[i].param_count)
|
2006-09-30 21:58:30 +05:30
|
|
|
bb_show_usage();
|
|
|
|
|
|
|
|
switch (g_cmdoptions[i].code) {
|
|
|
|
case CMD_FB:
|
|
|
|
fbdev = argv[1];
|
|
|
|
break;
|
|
|
|
case CMD_DB:
|
|
|
|
modefile = argv[1];
|
|
|
|
break;
|
2009-02-18 20:58:43 +05:30
|
|
|
case CMD_ALL:
|
|
|
|
options |= OPT_ALL;
|
|
|
|
break;
|
|
|
|
case CMD_SHOW:
|
|
|
|
options |= OPT_SHOW;
|
|
|
|
break;
|
2006-09-30 21:58:30 +05:30
|
|
|
case CMD_GEOMETRY:
|
2010-01-23 08:10:28 +05:30
|
|
|
var_set.xres = xatou32(argv[1]);
|
|
|
|
var_set.yres = xatou32(argv[2]);
|
|
|
|
var_set.xres_virtual = xatou32(argv[3]);
|
|
|
|
var_set.yres_virtual = xatou32(argv[4]);
|
|
|
|
var_set.bits_per_pixel = xatou32(argv[5]);
|
2006-09-30 21:58:30 +05:30
|
|
|
break;
|
|
|
|
case CMD_TIMING:
|
2010-01-23 08:10:28 +05:30
|
|
|
var_set.pixclock = xatou32(argv[1]);
|
|
|
|
var_set.left_margin = xatou32(argv[2]);
|
|
|
|
var_set.right_margin = xatou32(argv[3]);
|
|
|
|
var_set.upper_margin = xatou32(argv[4]);
|
|
|
|
var_set.lower_margin = xatou32(argv[5]);
|
|
|
|
var_set.hsync_len = xatou32(argv[6]);
|
|
|
|
var_set.vsync_len = xatou32(argv[7]);
|
|
|
|
break;
|
|
|
|
case CMD_ACCEL:
|
|
|
|
break;
|
|
|
|
case CMD_HSYNC:
|
|
|
|
var_set.sync |= FB_SYNC_HOR_HIGH_ACT;
|
|
|
|
break;
|
|
|
|
case CMD_VSYNC:
|
|
|
|
var_set.sync |= FB_SYNC_VERT_HIGH_ACT;
|
2006-09-30 21:58:30 +05:30
|
|
|
break;
|
2007-08-13 16:06:25 +05:30
|
|
|
#if ENABLE_FEATURE_FBSET_FANCY
|
2006-09-30 21:58:30 +05:30
|
|
|
case CMD_XRES:
|
2010-01-23 08:10:28 +05:30
|
|
|
var_set.xres = xatou32(argv[1]);
|
2000-02-09 01:28:47 +05:30
|
|
|
break;
|
2006-09-30 21:58:30 +05:30
|
|
|
case CMD_YRES:
|
2010-01-23 08:10:28 +05:30
|
|
|
var_set.yres = xatou32(argv[1]);
|
2006-09-30 21:58:30 +05:30
|
|
|
break;
|
|
|
|
case CMD_DEPTH:
|
2010-01-23 08:10:28 +05:30
|
|
|
var_set.bits_per_pixel = xatou32(argv[1]);
|
2006-09-30 21:58:30 +05:30
|
|
|
break;
|
|
|
|
#endif
|
2000-02-09 01:28:47 +05:30
|
|
|
}
|
2009-02-18 20:58:43 +05:30
|
|
|
switch (g_cmdoptions[i].code) {
|
|
|
|
case CMD_FB:
|
|
|
|
case CMD_DB:
|
|
|
|
case CMD_ALL:
|
|
|
|
case CMD_SHOW:
|
|
|
|
break;
|
|
|
|
default:
|
2010-01-23 08:10:28 +05:30
|
|
|
/* other commands imply changes */
|
|
|
|
options |= OPT_CHANGE;
|
2009-02-18 20:58:43 +05:30
|
|
|
}
|
2006-09-30 21:58:30 +05:30
|
|
|
argc -= g_cmdoptions[i].param_count;
|
|
|
|
argv += g_cmdoptions[i].param_count;
|
2008-08-24 21:55:40 +05:30
|
|
|
goto contin;
|
1999-12-17 02:29:36 +05:30
|
|
|
}
|
2010-01-23 08:10:28 +05:30
|
|
|
if (!ENABLE_FEATURE_FBSET_READMODE || argc != 1)
|
2008-08-24 21:55:40 +05:30
|
|
|
bb_show_usage();
|
|
|
|
mode = *argv;
|
|
|
|
options |= OPT_READMODE;
|
|
|
|
contin: ;
|
1999-12-17 02:29:36 +05:30
|
|
|
}
|
|
|
|
|
2006-08-03 21:11:12 +05:30
|
|
|
fh = xopen(fbdev, O_RDONLY);
|
2010-01-23 08:10:28 +05:30
|
|
|
xioctl(fh, FBIOGET_VSCREENINFO, &var_old);
|
|
|
|
|
2008-08-24 21:55:40 +05:30
|
|
|
if (options & OPT_READMODE) {
|
2010-01-23 08:10:28 +05:30
|
|
|
#if ENABLE_FEATURE_FBSET_READMODE
|
|
|
|
if (!read_mode_db(&var_old, modefile, mode)) {
|
2006-09-30 21:58:30 +05:30
|
|
|
bb_error_msg_and_die("unknown video mode '%s'", mode);
|
2000-02-09 01:28:47 +05:30
|
|
|
}
|
2008-03-17 14:34:04 +05:30
|
|
|
#endif
|
1999-12-17 02:29:36 +05:30
|
|
|
}
|
|
|
|
|
2008-08-24 21:55:40 +05:30
|
|
|
if (options & OPT_CHANGE) {
|
2010-01-23 08:10:28 +05:30
|
|
|
copy_changed_values(&var_old, &var_set);
|
2008-08-24 21:55:40 +05:30
|
|
|
if (options & OPT_ALL)
|
2010-01-23 08:10:28 +05:30
|
|
|
var_old.activate = FB_ACTIVATE_ALL;
|
|
|
|
xioctl(fh, FBIOPUT_VSCREENINFO, &var_old);
|
2006-09-30 21:52:59 +05:30
|
|
|
}
|
2010-01-23 08:10:28 +05:30
|
|
|
|
|
|
|
if (options == 0 || (options & OPT_SHOW))
|
|
|
|
showmode(&var_old);
|
|
|
|
|
|
|
|
if (ENABLE_FEATURE_CLEAN_UP)
|
|
|
|
close(fh);
|
1999-12-17 02:29:36 +05:30
|
|
|
|
2000-12-01 08:25:13 +05:30
|
|
|
return EXIT_SUCCESS;
|
2000-02-09 01:28:47 +05:30
|
|
|
}
|