Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini fbset implementation for busybox |
| 4 | * |
| 5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
| 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 8 | * |
| 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 Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 11 | * the GPL, and is (c) 1995-1999 by: |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 12 | * Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be) |
| 13 | */ |
| 14 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 15 | #include "libbb.h" |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 16 | |
Eric Andersen | 5f28455 | 2003-11-14 03:11:29 +0000 | [diff] [blame] | 17 | #define DEFAULTFBDEV FB_0 |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 18 | #define DEFAULTFBMODE "/etc/fb.modes" |
| 19 | |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 20 | /* Stuff stolen from the kernel's fb.h */ |
Denis Vlasenko | 274b8c0 | 2006-09-30 16:22:59 +0000 | [diff] [blame] | 21 | #define FB_ACTIVATE_ALL 64 |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 22 | enum { |
| 23 | FBIOGET_VSCREENINFO = 0x4600, |
| 24 | FBIOPUT_VSCREENINFO = 0x4601 |
| 25 | }; |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 26 | |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 27 | struct fb_bitfield { |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 28 | uint32_t offset; /* beginning of bitfield */ |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame^] | 29 | uint32_t length; /* length of bitfield */ |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 30 | uint32_t msb_right; /* !=0: Most significant bit is right */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 31 | }; |
| 32 | struct fb_var_screeninfo { |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 33 | uint32_t xres; /* visible resolution */ |
Eric Andersen | 1eceb12 | 2003-07-14 19:32:40 +0000 | [diff] [blame] | 34 | uint32_t yres; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 35 | uint32_t xres_virtual; /* virtual resolution */ |
Eric Andersen | 1eceb12 | 2003-07-14 19:32:40 +0000 | [diff] [blame] | 36 | uint32_t yres_virtual; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 37 | uint32_t xoffset; /* offset from virtual to visible */ |
| 38 | uint32_t yoffset; /* resolution */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 39 | |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 40 | uint32_t bits_per_pixel; |
| 41 | uint32_t grayscale; /* !=0 Graylevels instead of colors */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 42 | |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 43 | struct fb_bitfield red; /* bitfield in fb mem if true color, */ |
| 44 | struct fb_bitfield green; /* else only length is significant */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 45 | struct fb_bitfield blue; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 46 | struct fb_bitfield transp; /* transparency */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 47 | |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 48 | uint32_t nonstd; /* !=0 Non standard pixel format */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 49 | |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 50 | uint32_t activate; /* see FB_ACTIVATE_x */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 51 | |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 52 | uint32_t height; /* height of picture in mm */ |
| 53 | uint32_t width; /* width of picture in mm */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 54 | |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame^] | 55 | uint32_t accel_flags; /* acceleration flags (hints) */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 56 | |
| 57 | /* Timing: All values in pixclocks, except pixclock (of course) */ |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 58 | uint32_t pixclock; /* pixel clock in ps (pico seconds) */ |
| 59 | uint32_t left_margin; /* time from sync to picture */ |
| 60 | uint32_t right_margin; /* time from picture to sync */ |
| 61 | uint32_t upper_margin; /* time from sync to picture */ |
Eric Andersen | 1eceb12 | 2003-07-14 19:32:40 +0000 | [diff] [blame] | 62 | uint32_t lower_margin; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 63 | uint32_t hsync_len; /* length of horizontal sync */ |
| 64 | uint32_t vsync_len; /* length of vertical sync */ |
| 65 | uint32_t sync; /* see FB_SYNC_x */ |
| 66 | uint32_t vmode; /* see FB_VMODE_x */ |
| 67 | uint32_t reserved[6]; /* Reserved for future compatibility */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 70 | static void copy_if_gt0(uint32_t *src, uint32_t *dst, unsigned cnt) |
| 71 | { |
| 72 | do { |
| 73 | if ((int32_t) *src > 0) |
| 74 | *dst = *src; |
| 75 | src++; |
| 76 | dst++; |
| 77 | } while (--cnt); |
| 78 | } |
| 79 | |
| 80 | static NOINLINE void copy_changed_values( |
| 81 | struct fb_var_screeninfo *base, |
| 82 | struct fb_var_screeninfo *set) |
| 83 | { |
| 84 | //if ((int32_t) set->xres > 0) base->xres = set->xres; |
| 85 | //if ((int32_t) set->yres > 0) base->yres = set->yres; |
| 86 | //if ((int32_t) set->xres_virtual > 0) base->xres_virtual = set->xres_virtual; |
| 87 | //if ((int32_t) set->yres_virtual > 0) base->yres_virtual = set->yres_virtual; |
| 88 | copy_if_gt0(&set->xres, &base->xres, 4); |
| 89 | |
| 90 | if ((int32_t) set->bits_per_pixel > 0) base->bits_per_pixel = set->bits_per_pixel; |
| 91 | //copy_if_gt0(&set->bits_per_pixel, &base->bits_per_pixel, 1); |
| 92 | |
| 93 | //if ((int32_t) set->pixclock > 0) base->pixclock = set->pixclock; |
| 94 | //if ((int32_t) set->left_margin > 0) base->left_margin = set->left_margin; |
| 95 | //if ((int32_t) set->right_margin > 0) base->right_margin = set->right_margin; |
| 96 | //if ((int32_t) set->upper_margin > 0) base->upper_margin = set->upper_margin; |
| 97 | //if ((int32_t) set->lower_margin > 0) base->lower_margin = set->lower_margin; |
| 98 | //if ((int32_t) set->hsync_len > 0) base->hsync_len = set->hsync_len; |
| 99 | //if ((int32_t) set->vsync_len > 0) base->vsync_len = set->vsync_len; |
| 100 | //if ((int32_t) set->sync > 0) base->sync = set->sync; |
| 101 | //if ((int32_t) set->vmode > 0) base->vmode = set->vmode; |
| 102 | copy_if_gt0(&set->pixclock, &base->pixclock, 9); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | enum { |
| 107 | CMD_FB = 1, |
| 108 | CMD_DB = 2, |
| 109 | CMD_GEOMETRY = 3, |
| 110 | CMD_TIMING = 4, |
| 111 | CMD_ACCEL = 5, |
| 112 | CMD_HSYNC = 6, |
| 113 | CMD_VSYNC = 7, |
| 114 | CMD_LACED = 8, |
| 115 | CMD_DOUBLE = 9, |
| 116 | /* CMD_XCOMPAT = 10, */ |
| 117 | CMD_ALL = 11, |
| 118 | CMD_INFO = 12, |
| 119 | CMD_SHOW = 13, |
| 120 | CMD_CHANGE = 14, |
| 121 | |
| 122 | #if ENABLE_FEATURE_FBSET_FANCY |
| 123 | CMD_XRES = 100, |
| 124 | CMD_YRES = 101, |
| 125 | CMD_VXRES = 102, |
| 126 | CMD_VYRES = 103, |
| 127 | CMD_DEPTH = 104, |
| 128 | CMD_MATCH = 105, |
| 129 | CMD_PIXCLOCK = 106, |
| 130 | CMD_LEFT = 107, |
| 131 | CMD_RIGHT = 108, |
| 132 | CMD_UPPER = 109, |
| 133 | CMD_LOWER = 110, |
| 134 | CMD_HSLEN = 111, |
| 135 | CMD_VSLEN = 112, |
| 136 | CMD_CSYNC = 113, |
| 137 | CMD_GSYNC = 114, |
| 138 | CMD_EXTSYNC = 115, |
| 139 | CMD_BCAST = 116, |
| 140 | CMD_RGBA = 117, |
| 141 | CMD_STEP = 118, |
| 142 | CMD_MOVE = 119, |
| 143 | #endif |
| 144 | }; |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 145 | |
"Vladimir N. Oleynik" | b399a96 | 2006-02-01 12:41:35 +0000 | [diff] [blame] | 146 | static const struct cmdoptions_t { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 147 | const char name[9]; |
Aaron Lehmann | 6069441 | 2002-08-13 04:19:23 +0000 | [diff] [blame] | 148 | const unsigned char param_count; |
| 149 | const unsigned char code; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 150 | } g_cmdoptions[] = { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 151 | /*"12345678" + NUL */ |
| 152 | { "fb" , 1, CMD_FB }, |
| 153 | { "db" , 1, CMD_DB }, |
| 154 | { "a" , 0, CMD_ALL }, |
| 155 | { "i" , 0, CMD_INFO }, |
| 156 | { "g" , 5, CMD_GEOMETRY }, |
| 157 | { "t" , 7, CMD_TIMING }, |
| 158 | { "accel" , 1, CMD_ACCEL }, |
| 159 | { "hsync" , 1, CMD_HSYNC }, |
| 160 | { "vsync" , 1, CMD_VSYNC }, |
| 161 | { "laced" , 1, CMD_LACED }, |
| 162 | { "double" , 1, CMD_DOUBLE }, |
Bernhard Reutner-Fischer | 7307e06 | 2009-02-18 15:28:43 +0000 | [diff] [blame] | 163 | { "show" , 0, CMD_SHOW }, |
| 164 | { "s" , 0, CMD_SHOW }, |
Denis Vlasenko | e324184 | 2007-08-13 10:36:25 +0000 | [diff] [blame] | 165 | #if ENABLE_FEATURE_FBSET_FANCY |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 166 | { "all" , 0, CMD_ALL }, |
| 167 | { "xres" , 1, CMD_XRES }, |
| 168 | { "yres" , 1, CMD_YRES }, |
| 169 | { "vxres" , 1, CMD_VXRES }, |
| 170 | { "vyres" , 1, CMD_VYRES }, |
| 171 | { "depth" , 1, CMD_DEPTH }, |
| 172 | { "match" , 0, CMD_MATCH }, |
| 173 | { "geometry", 5, CMD_GEOMETRY }, |
| 174 | { "pixclock", 1, CMD_PIXCLOCK }, |
| 175 | { "left" , 1, CMD_LEFT }, |
| 176 | { "right" , 1, CMD_RIGHT }, |
| 177 | { "upper" , 1, CMD_UPPER }, |
| 178 | { "lower" , 1, CMD_LOWER }, |
| 179 | { "hslen" , 1, CMD_HSLEN }, |
| 180 | { "vslen" , 1, CMD_VSLEN }, |
| 181 | { "timings" , 7, CMD_TIMING }, |
| 182 | { "csync" , 1, CMD_CSYNC }, |
| 183 | { "gsync" , 1, CMD_GSYNC }, |
| 184 | { "extsync" , 1, CMD_EXTSYNC }, |
| 185 | { "bcast" , 1, CMD_BCAST }, |
| 186 | { "rgba" , 1, CMD_RGBA }, |
| 187 | { "step" , 1, CMD_STEP }, |
| 188 | { "move" , 1, CMD_MOVE }, |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 189 | #endif |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 190 | }; |
| 191 | |
Matt Kraai | 269e07c | 2000-10-28 16:56:32 +0000 | [diff] [blame] | 192 | /* taken from linux/fb.h */ |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 193 | enum { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 194 | FB_SYNC_HOR_HIGH_ACT = 1, /* horizontal sync high active */ |
| 195 | FB_SYNC_VERT_HIGH_ACT = 2, /* vertical sync high active */ |
Denys Vlasenko | 6b01b71 | 2010-01-24 22:52:21 +0100 | [diff] [blame] | 196 | #if ENABLE_FEATURE_FBSET_READMODE |
| 197 | FB_VMODE_INTERLACED = 1, /* interlaced */ |
| 198 | FB_VMODE_DOUBLE = 2, /* double scan */ |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 199 | FB_SYNC_EXT = 4, /* external sync */ |
| 200 | FB_SYNC_COMP_HIGH_ACT = 8, /* composite sync high active */ |
Matt Kraai | 269e07c | 2000-10-28 16:56:32 +0000 | [diff] [blame] | 201 | #endif |
Denys Vlasenko | 6b01b71 | 2010-01-24 22:52:21 +0100 | [diff] [blame] | 202 | }; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 203 | |
Denis Vlasenko | d91afa3 | 2008-07-29 11:10:01 +0000 | [diff] [blame] | 204 | #if ENABLE_FEATURE_FBSET_READMODE |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 205 | static void ss(uint32_t *x, uint32_t flag, char *buf, const char *what) |
Denis Vlasenko | 09f5ecf | 2008-07-27 20:25:29 +0000 | [diff] [blame] | 206 | { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 207 | if (strcmp(buf, what) == 0) |
Denis Vlasenko | 09f5ecf | 2008-07-27 20:25:29 +0000 | [diff] [blame] | 208 | *x &= ~flag; |
| 209 | else |
| 210 | *x |= flag; |
| 211 | } |
| 212 | |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 213 | /* Mode db file contains mode definitions like this: |
| 214 | * mode "800x600-48-lace" |
| 215 | * # D: 36.00 MHz, H: 33.835 kHz, V: 96.39 Hz |
| 216 | * geometry 800 600 800 600 8 |
| 217 | * timings 27778 56 80 79 11 128 12 |
| 218 | * laced true |
| 219 | * hsync high |
| 220 | * vsync high |
| 221 | * endmode |
| 222 | */ |
Bernhard Reutner-Fischer | 7307e06 | 2009-02-18 15:28:43 +0000 | [diff] [blame] | 223 | static int read_mode_db(struct fb_var_screeninfo *base, const char *fn, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 224 | const char *mode) |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 225 | { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 226 | char *token[2], *p, *s; |
| 227 | parser_t *parser = config_open(fn); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 228 | |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 229 | while (config_read(parser, token, 2, 1, "# \t\r", PARSE_NORMAL)) { |
| 230 | if (strcmp(token[0], "mode") != 0 || !token[1]) |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 231 | continue; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 232 | p = strstr(token[1], mode); |
Denis Vlasenko | 6bef3d1 | 2007-11-06 03:05:54 +0000 | [diff] [blame] | 233 | if (!p) |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 234 | continue; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 235 | s = p + strlen(mode); |
| 236 | //bb_info_msg("CHECK[%s][%s][%d]", mode, p-1, *s); |
| 237 | /* exact match? */ |
| 238 | if (((!*s || isspace(*s)) && '"' != s[-1]) /* end-of-token */ |
| 239 | || ('"' == *s && '"' == p[-1]) /* ends with " but starts with " too! */ |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 240 | ) { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 241 | //bb_info_msg("FOUND[%s][%s][%s][%d]", token[1], p, mode, isspace(*s)); |
| 242 | break; |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 243 | } |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 244 | } |
Eric Andersen | 6f96e67 | 2000-07-12 23:01:04 +0000 | [diff] [blame] | 245 | |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 246 | if (!token[0]) |
| 247 | return 0; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 248 | |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 249 | while (config_read(parser, token, 2, 1, "# \t", PARSE_NORMAL)) { |
| 250 | int i; |
| 251 | |
| 252 | //bb_info_msg("???[%s][%s]", token[0], token[1]); |
| 253 | if (strcmp(token[0], "endmode") == 0) { |
| 254 | //bb_info_msg("OK[%s]", mode); |
| 255 | return 1; |
| 256 | } |
| 257 | p = token[1]; |
| 258 | i = index_in_strings( |
| 259 | "geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0", |
| 260 | token[0]); |
| 261 | switch (i) { |
| 262 | case 0: |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 263 | if (sizeof(int) == sizeof(base->xres)) { |
| 264 | sscanf(p, "%d %d %d %d %d", |
| 265 | &base->xres, &base->yres, |
| 266 | &base->xres_virtual, &base->yres_virtual, |
| 267 | &base->bits_per_pixel); |
| 268 | } else { |
| 269 | int base_xres, base_yres; |
| 270 | int base_xres_virtual, base_yres_virtual; |
| 271 | int base_bits_per_pixel; |
| 272 | sscanf(p, "%d %d %d %d %d", |
| 273 | &base_xres, &base_yres, |
| 274 | &base_xres_virtual, &base_yres_virtual, |
| 275 | &base_bits_per_pixel); |
| 276 | base->xres = base_xres; |
| 277 | base->yres = base_yres; |
| 278 | base->xres_virtual = base_xres_virtual; |
| 279 | base->yres_virtual = base_yres_virtual; |
| 280 | base->bits_per_pixel = base_bits_per_pixel; |
| 281 | } |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 282 | //bb_info_msg("GEO[%s]", p); |
| 283 | break; |
| 284 | case 1: |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 285 | if (sizeof(int) == sizeof(base->xres)) { |
| 286 | sscanf(p, "%d %d %d %d %d %d %d", |
| 287 | &base->pixclock, |
| 288 | &base->left_margin, &base->right_margin, |
| 289 | &base->upper_margin, &base->lower_margin, |
| 290 | &base->hsync_len, &base->vsync_len); |
| 291 | } else { |
| 292 | int base_pixclock; |
| 293 | int base_left_margin, base_right_margin; |
| 294 | int base_upper_margin, base_lower_margin; |
| 295 | int base_hsync_len, base_vsync_len; |
| 296 | sscanf(p, "%d %d %d %d %d %d %d", |
| 297 | &base_pixclock, |
| 298 | &base_left_margin, &base_right_margin, |
| 299 | &base_upper_margin, &base_lower_margin, |
| 300 | &base_hsync_len, &base_vsync_len); |
| 301 | base->pixclock = base_pixclock; |
| 302 | base->left_margin = base_left_margin; |
| 303 | base->right_margin = base_right_margin; |
| 304 | base->upper_margin = base_upper_margin; |
| 305 | base->lower_margin = base_lower_margin; |
| 306 | base->hsync_len = base_hsync_len; |
| 307 | base->vsync_len = base_vsync_len; |
| 308 | } |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 309 | //bb_info_msg("TIM[%s]", p); |
| 310 | break; |
| 311 | case 2: |
| 312 | case 3: { |
| 313 | static const uint32_t syncs[] = {FB_VMODE_INTERLACED, FB_VMODE_DOUBLE}; |
| 314 | ss(&base->vmode, syncs[i-2], p, "false"); |
| 315 | //bb_info_msg("VMODE[%s]", p); |
| 316 | break; |
| 317 | } |
| 318 | case 4: |
| 319 | case 5: |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame^] | 320 | case 6: { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 321 | static const uint32_t syncs[] = {FB_SYNC_VERT_HIGH_ACT, FB_SYNC_HOR_HIGH_ACT, FB_SYNC_COMP_HIGH_ACT}; |
| 322 | ss(&base->sync, syncs[i-4], p, "low"); |
| 323 | //bb_info_msg("SYNC[%s]", p); |
| 324 | break; |
| 325 | } |
| 326 | case 7: |
| 327 | ss(&base->sync, FB_SYNC_EXT, p, "false"); |
| 328 | //bb_info_msg("EXTSYNC[%s]", p); |
| 329 | break; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 330 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 331 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 332 | return 0; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 333 | } |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 334 | #endif |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 335 | |
Denys Vlasenko | ef5bc2c | 2009-10-08 14:54:18 +0200 | [diff] [blame] | 336 | static NOINLINE void showmode(struct fb_var_screeninfo *v) |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 337 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 338 | double drate = 0, hrate = 0, vrate = 0; |
| 339 | |
| 340 | if (v->pixclock) { |
| 341 | drate = 1e12 / v->pixclock; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 342 | hrate = drate / (v->left_margin + v->xres + v->right_margin + v->hsync_len); |
| 343 | vrate = hrate / (v->upper_margin + v->yres + v->lower_margin + v->vsync_len); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 344 | } |
Aaron Lehmann | 6069441 | 2002-08-13 04:19:23 +0000 | [diff] [blame] | 345 | printf("\nmode \"%ux%u-%u\"\n" |
Denis Vlasenko | e324184 | 2007-08-13 10:36:25 +0000 | [diff] [blame] | 346 | #if ENABLE_FEATURE_FBSET_FANCY |
Aaron Lehmann | 6069441 | 2002-08-13 04:19:23 +0000 | [diff] [blame] | 347 | "\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n" |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 348 | #endif |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 349 | "\tgeometry %u %u %u %u %u\n" |
| 350 | "\ttimings %u %u %u %u %u %u %u\n" |
| 351 | "\taccel %s\n" |
| 352 | "\trgba %u/%u,%u/%u,%u/%u,%u/%u\n" |
| 353 | "endmode\n\n", |
| 354 | v->xres, v->yres, (int) (vrate + 0.5), |
Denis Vlasenko | e324184 | 2007-08-13 10:36:25 +0000 | [diff] [blame] | 355 | #if ENABLE_FEATURE_FBSET_FANCY |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 356 | drate / 1e6, hrate / 1e3, vrate, |
Aaron Lehmann | 6069441 | 2002-08-13 04:19:23 +0000 | [diff] [blame] | 357 | #endif |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 358 | v->xres, v->yres, v->xres_virtual, v->yres_virtual, v->bits_per_pixel, |
| 359 | v->pixclock, v->left_margin, v->right_margin, v->upper_margin, v->lower_margin, |
| 360 | v->hsync_len, v->vsync_len, |
| 361 | (v->accel_flags > 0 ? "true" : "false"), |
| 362 | v->red.length, v->red.offset, v->green.length, v->green.offset, |
| 363 | v->blue.length, v->blue.offset, v->transp.length, v->transp.offset); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 366 | int fbset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 367 | int fbset_main(int argc, char **argv) |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 368 | { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 369 | enum { |
| 370 | OPT_CHANGE = (1 << 0), |
Bernhard Reutner-Fischer | 7307e06 | 2009-02-18 15:28:43 +0000 | [diff] [blame] | 371 | OPT_SHOW = (1 << 1), |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 372 | OPT_READMODE = (1 << 2), |
| 373 | OPT_ALL = (1 << 9), |
| 374 | }; |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 375 | struct fb_var_screeninfo var_old, var_set; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 376 | int fh, i; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 377 | unsigned options = 0; |
| 378 | |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 379 | const char *fbdev = DEFAULTFBDEV; |
| 380 | const char *modefile = DEFAULTFBMODE; |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 381 | char *thisarg; |
| 382 | char *mode = mode; /* for compiler */ |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 383 | |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 384 | memset(&var_set, 0xff, sizeof(var_set)); /* set all to -1 */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 385 | |
| 386 | /* parse cmd args.... why do they have to make things so difficult? */ |
| 387 | argv++; |
| 388 | argc--; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 389 | for (; argc > 0 && (thisarg = *argv) != NULL; argc--, argv++) { |
| 390 | if (thisarg[0] == '-') for (i = 0; i < ARRAY_SIZE(g_cmdoptions); i++) { |
| 391 | if (strcmp(thisarg + 1, g_cmdoptions[i].name) != 0) |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 392 | continue; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 393 | if (argc <= g_cmdoptions[i].param_count) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 394 | bb_show_usage(); |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 395 | |
| 396 | switch (g_cmdoptions[i].code) { |
| 397 | case CMD_FB: |
| 398 | fbdev = argv[1]; |
| 399 | break; |
| 400 | case CMD_DB: |
| 401 | modefile = argv[1]; |
| 402 | break; |
Bernhard Reutner-Fischer | 7307e06 | 2009-02-18 15:28:43 +0000 | [diff] [blame] | 403 | case CMD_ALL: |
| 404 | options |= OPT_ALL; |
| 405 | break; |
| 406 | case CMD_SHOW: |
| 407 | options |= OPT_SHOW; |
| 408 | break; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 409 | case CMD_GEOMETRY: |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 410 | var_set.xres = xatou32(argv[1]); |
| 411 | var_set.yres = xatou32(argv[2]); |
| 412 | var_set.xres_virtual = xatou32(argv[3]); |
| 413 | var_set.yres_virtual = xatou32(argv[4]); |
| 414 | var_set.bits_per_pixel = xatou32(argv[5]); |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 415 | break; |
| 416 | case CMD_TIMING: |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 417 | var_set.pixclock = xatou32(argv[1]); |
| 418 | var_set.left_margin = xatou32(argv[2]); |
| 419 | var_set.right_margin = xatou32(argv[3]); |
| 420 | var_set.upper_margin = xatou32(argv[4]); |
| 421 | var_set.lower_margin = xatou32(argv[5]); |
| 422 | var_set.hsync_len = xatou32(argv[6]); |
| 423 | var_set.vsync_len = xatou32(argv[7]); |
| 424 | break; |
| 425 | case CMD_ACCEL: |
| 426 | break; |
| 427 | case CMD_HSYNC: |
| 428 | var_set.sync |= FB_SYNC_HOR_HIGH_ACT; |
| 429 | break; |
| 430 | case CMD_VSYNC: |
| 431 | var_set.sync |= FB_SYNC_VERT_HIGH_ACT; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 432 | break; |
Denis Vlasenko | e324184 | 2007-08-13 10:36:25 +0000 | [diff] [blame] | 433 | #if ENABLE_FEATURE_FBSET_FANCY |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 434 | case CMD_XRES: |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 435 | var_set.xres = xatou32(argv[1]); |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 436 | break; |
| 437 | case CMD_YRES: |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 438 | var_set.yres = xatou32(argv[1]); |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 439 | break; |
| 440 | case CMD_DEPTH: |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 441 | var_set.bits_per_pixel = xatou32(argv[1]); |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 442 | break; |
| 443 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 444 | } |
Bernhard Reutner-Fischer | 7307e06 | 2009-02-18 15:28:43 +0000 | [diff] [blame] | 445 | switch (g_cmdoptions[i].code) { |
| 446 | case CMD_FB: |
| 447 | case CMD_DB: |
| 448 | case CMD_ALL: |
| 449 | case CMD_SHOW: |
| 450 | break; |
| 451 | default: |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 452 | /* other commands imply changes */ |
| 453 | options |= OPT_CHANGE; |
Bernhard Reutner-Fischer | 7307e06 | 2009-02-18 15:28:43 +0000 | [diff] [blame] | 454 | } |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 455 | argc -= g_cmdoptions[i].param_count; |
| 456 | argv += g_cmdoptions[i].param_count; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 457 | goto contin; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 458 | } |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 459 | if (!ENABLE_FEATURE_FBSET_READMODE || argc != 1) |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 460 | bb_show_usage(); |
| 461 | mode = *argv; |
| 462 | options |= OPT_READMODE; |
| 463 | contin: ; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 464 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 465 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 466 | fh = xopen(fbdev, O_RDONLY); |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 467 | xioctl(fh, FBIOGET_VSCREENINFO, &var_old); |
| 468 | |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 469 | if (options & OPT_READMODE) { |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 470 | #if ENABLE_FEATURE_FBSET_READMODE |
| 471 | if (!read_mode_db(&var_old, modefile, mode)) { |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 472 | bb_error_msg_and_die("unknown video mode '%s'", mode); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 473 | } |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 474 | #endif |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 475 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 476 | |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 477 | if (options & OPT_CHANGE) { |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 478 | copy_changed_values(&var_old, &var_set); |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame] | 479 | if (options & OPT_ALL) |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 480 | var_old.activate = FB_ACTIVATE_ALL; |
| 481 | xioctl(fh, FBIOPUT_VSCREENINFO, &var_old); |
Denis Vlasenko | 274b8c0 | 2006-09-30 16:22:59 +0000 | [diff] [blame] | 482 | } |
Michael Grzeschik | 24dc9ab | 2010-01-23 03:40:28 +0100 | [diff] [blame] | 483 | |
| 484 | if (options == 0 || (options & OPT_SHOW)) |
| 485 | showmode(&var_old); |
| 486 | |
| 487 | if (ENABLE_FEATURE_CLEAN_UP) |
| 488 | close(fh); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 489 | |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 490 | return EXIT_SUCCESS; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 491 | } |