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