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 | * |
Bernhard Reutner-Fischer | dac7ff1 | 2006-04-12 17:55:51 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
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 | |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 20 | enum { |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 21 | CMD_FB = 1, |
| 22 | CMD_DB = 2, |
| 23 | CMD_GEOMETRY = 3, |
| 24 | CMD_TIMING = 4, |
| 25 | CMD_ACCEL = 5, |
| 26 | CMD_HSYNC = 6, |
| 27 | CMD_VSYNC = 7, |
| 28 | CMD_LACED = 8, |
| 29 | CMD_DOUBLE = 9, |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 30 | /* CMD_XCOMPAT = 10, */ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 31 | CMD_ALL = 11, |
| 32 | CMD_INFO = 12, |
| 33 | CMD_CHANGE = 13, |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 34 | |
Denis Vlasenko | e324184 | 2007-08-13 10:36:25 +0000 | [diff] [blame] | 35 | #if ENABLE_FEATURE_FBSET_FANCY |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 36 | CMD_XRES = 100, |
| 37 | CMD_YRES = 101, |
| 38 | CMD_VXRES = 102, |
| 39 | CMD_VYRES = 103, |
| 40 | CMD_DEPTH = 104, |
| 41 | CMD_MATCH = 105, |
| 42 | CMD_PIXCLOCK = 106, |
| 43 | CMD_LEFT = 107, |
| 44 | CMD_RIGHT = 108, |
| 45 | CMD_UPPER = 109, |
| 46 | CMD_LOWER = 110, |
| 47 | CMD_HSLEN = 111, |
| 48 | CMD_VSLEN = 112, |
| 49 | CMD_CSYNC = 113, |
| 50 | CMD_GSYNC = 114, |
| 51 | CMD_EXTSYNC = 115, |
| 52 | CMD_BCAST = 116, |
| 53 | CMD_RGBA = 117, |
| 54 | CMD_STEP = 118, |
| 55 | CMD_MOVE = 119, |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 56 | #endif |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 57 | }; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 58 | |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 59 | /* Stuff stolen from the kernel's fb.h */ |
Denis Vlasenko | 274b8c0 | 2006-09-30 16:22:59 +0000 | [diff] [blame] | 60 | #define FB_ACTIVATE_ALL 64 |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 61 | enum { |
| 62 | FBIOGET_VSCREENINFO = 0x4600, |
| 63 | FBIOPUT_VSCREENINFO = 0x4601 |
| 64 | }; |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 65 | struct fb_bitfield { |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 66 | uint32_t offset; /* beginning of bitfield */ |
| 67 | uint32_t length; /* length of bitfield */ |
| 68 | uint32_t msb_right; /* !=0: Most significant bit is right */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 69 | }; |
| 70 | struct fb_var_screeninfo { |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 71 | uint32_t xres; /* visible resolution */ |
Eric Andersen | 1eceb12 | 2003-07-14 19:32:40 +0000 | [diff] [blame] | 72 | uint32_t yres; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 73 | uint32_t xres_virtual; /* virtual resolution */ |
Eric Andersen | 1eceb12 | 2003-07-14 19:32:40 +0000 | [diff] [blame] | 74 | uint32_t yres_virtual; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 75 | uint32_t xoffset; /* offset from virtual to visible */ |
| 76 | uint32_t yoffset; /* resolution */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 77 | |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 78 | uint32_t bits_per_pixel; |
| 79 | uint32_t grayscale; /* !=0 Graylevels instead of colors */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 80 | |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 81 | struct fb_bitfield red; /* bitfield in fb mem if true color, */ |
| 82 | struct fb_bitfield green; /* else only length is significant */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 83 | struct fb_bitfield blue; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 84 | struct fb_bitfield transp; /* transparency */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 85 | |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 86 | uint32_t nonstd; /* !=0 Non standard pixel format */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 87 | |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 88 | uint32_t activate; /* see FB_ACTIVATE_x */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 89 | |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 90 | uint32_t height; /* height of picture in mm */ |
| 91 | uint32_t width; /* width of picture in mm */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 92 | |
Eric Andersen | 1eceb12 | 2003-07-14 19:32:40 +0000 | [diff] [blame] | 93 | uint32_t accel_flags; /* acceleration flags (hints) */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 94 | |
| 95 | /* Timing: All values in pixclocks, except pixclock (of course) */ |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 96 | uint32_t pixclock; /* pixel clock in ps (pico seconds) */ |
| 97 | uint32_t left_margin; /* time from sync to picture */ |
| 98 | uint32_t right_margin; /* time from picture to sync */ |
| 99 | uint32_t upper_margin; /* time from sync to picture */ |
Eric Andersen | 1eceb12 | 2003-07-14 19:32:40 +0000 | [diff] [blame] | 100 | uint32_t lower_margin; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 101 | uint32_t hsync_len; /* length of horizontal sync */ |
| 102 | uint32_t vsync_len; /* length of vertical sync */ |
| 103 | uint32_t sync; /* see FB_SYNC_x */ |
| 104 | uint32_t vmode; /* see FB_VMODE_x */ |
| 105 | uint32_t reserved[6]; /* Reserved for future compatibility */ |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | |
"Vladimir N. Oleynik" | b399a96 | 2006-02-01 12:41:35 +0000 | [diff] [blame] | 109 | static const struct cmdoptions_t { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 110 | const char name[9]; |
Aaron Lehmann | 6069441 | 2002-08-13 04:19:23 +0000 | [diff] [blame] | 111 | const unsigned char param_count; |
| 112 | const unsigned char code; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 113 | } g_cmdoptions[] = { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 114 | /*"12345678" + NUL */ |
| 115 | { "fb" , 1, CMD_FB }, |
| 116 | { "db" , 1, CMD_DB }, |
| 117 | { "a" , 0, CMD_ALL }, |
| 118 | { "i" , 0, CMD_INFO }, |
| 119 | { "g" , 5, CMD_GEOMETRY }, |
| 120 | { "t" , 7, CMD_TIMING }, |
| 121 | { "accel" , 1, CMD_ACCEL }, |
| 122 | { "hsync" , 1, CMD_HSYNC }, |
| 123 | { "vsync" , 1, CMD_VSYNC }, |
| 124 | { "laced" , 1, CMD_LACED }, |
| 125 | { "double" , 1, CMD_DOUBLE }, |
| 126 | { "n" , 0, CMD_CHANGE }, |
Denis Vlasenko | e324184 | 2007-08-13 10:36:25 +0000 | [diff] [blame] | 127 | #if ENABLE_FEATURE_FBSET_FANCY |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 128 | { "all" , 0, CMD_ALL }, |
| 129 | { "xres" , 1, CMD_XRES }, |
| 130 | { "yres" , 1, CMD_YRES }, |
| 131 | { "vxres" , 1, CMD_VXRES }, |
| 132 | { "vyres" , 1, CMD_VYRES }, |
| 133 | { "depth" , 1, CMD_DEPTH }, |
| 134 | { "match" , 0, CMD_MATCH }, |
| 135 | { "geometry", 5, CMD_GEOMETRY }, |
| 136 | { "pixclock", 1, CMD_PIXCLOCK }, |
| 137 | { "left" , 1, CMD_LEFT }, |
| 138 | { "right" , 1, CMD_RIGHT }, |
| 139 | { "upper" , 1, CMD_UPPER }, |
| 140 | { "lower" , 1, CMD_LOWER }, |
| 141 | { "hslen" , 1, CMD_HSLEN }, |
| 142 | { "vslen" , 1, CMD_VSLEN }, |
| 143 | { "timings" , 7, CMD_TIMING }, |
| 144 | { "csync" , 1, CMD_CSYNC }, |
| 145 | { "gsync" , 1, CMD_GSYNC }, |
| 146 | { "extsync" , 1, CMD_EXTSYNC }, |
| 147 | { "bcast" , 1, CMD_BCAST }, |
| 148 | { "rgba" , 1, CMD_RGBA }, |
| 149 | { "step" , 1, CMD_STEP }, |
| 150 | { "move" , 1, CMD_MOVE }, |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 151 | #endif |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
Denis Vlasenko | e324184 | 2007-08-13 10:36:25 +0000 | [diff] [blame] | 154 | #if ENABLE_FEATURE_FBSET_READMODE |
Matt Kraai | 269e07c | 2000-10-28 16:56:32 +0000 | [diff] [blame] | 155 | /* taken from linux/fb.h */ |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 156 | enum { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 157 | FB_VMODE_INTERLACED = 1, /* interlaced */ |
| 158 | FB_VMODE_DOUBLE = 2, /* double scan */ |
| 159 | FB_SYNC_HOR_HIGH_ACT = 1, /* horizontal sync high active */ |
| 160 | FB_SYNC_VERT_HIGH_ACT = 2, /* vertical sync high active */ |
| 161 | FB_SYNC_EXT = 4, /* external sync */ |
| 162 | FB_SYNC_COMP_HIGH_ACT = 8, /* composite sync high active */ |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 163 | }; |
Matt Kraai | 269e07c | 2000-10-28 16:56:32 +0000 | [diff] [blame] | 164 | #endif |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 165 | |
Denis Vlasenko | d91afa3 | 2008-07-29 11:10:01 +0000 | [diff] [blame] | 166 | #if ENABLE_FEATURE_FBSET_READMODE |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 167 | 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] | 168 | { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 169 | if (strcmp(buf, what) == 0) |
Denis Vlasenko | 09f5ecf | 2008-07-27 20:25:29 +0000 | [diff] [blame] | 170 | *x &= ~flag; |
| 171 | else |
| 172 | *x |= flag; |
| 173 | } |
| 174 | |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 175 | static int readmode(struct fb_var_screeninfo *base, const char *fn, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 176 | const char *mode) |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 177 | { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 178 | char *token[2], *p, *s; |
| 179 | parser_t *parser = config_open(fn); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 180 | |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 181 | while (config_read(parser, token, 2, 1, "# \t\r", PARSE_NORMAL)) { |
| 182 | if (strcmp(token[0], "mode") != 0 || !token[1]) |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 183 | continue; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 184 | p = strstr(token[1], mode); |
Denis Vlasenko | 6bef3d1 | 2007-11-06 03:05:54 +0000 | [diff] [blame] | 185 | if (!p) |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 186 | continue; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 187 | s = p + strlen(mode); |
| 188 | //bb_info_msg("CHECK[%s][%s][%d]", mode, p-1, *s); |
| 189 | /* exact match? */ |
| 190 | if (((!*s || isspace(*s)) && '"' != s[-1]) /* end-of-token */ |
| 191 | || ('"' == *s && '"' == p[-1]) /* ends with " but starts with " too! */ |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 192 | ) { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 193 | //bb_info_msg("FOUND[%s][%s][%s][%d]", token[1], p, mode, isspace(*s)); |
| 194 | break; |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 195 | } |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 196 | } |
Eric Andersen | 6f96e67 | 2000-07-12 23:01:04 +0000 | [diff] [blame] | 197 | |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 198 | if (!token[0]) |
| 199 | return 0; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 200 | |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 201 | while (config_read(parser, token, 2, 1, "# \t", PARSE_NORMAL)) { |
| 202 | int i; |
| 203 | |
| 204 | //bb_info_msg("???[%s][%s]", token[0], token[1]); |
| 205 | if (strcmp(token[0], "endmode") == 0) { |
| 206 | //bb_info_msg("OK[%s]", mode); |
| 207 | return 1; |
| 208 | } |
| 209 | p = token[1]; |
| 210 | i = index_in_strings( |
| 211 | "geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0", |
| 212 | token[0]); |
| 213 | switch (i) { |
| 214 | case 0: |
| 215 | /* FIXME: catastrophic on arches with 64bit ints */ |
| 216 | sscanf(p, "%d %d %d %d %d", |
| 217 | &(base->xres), &(base->yres), |
| 218 | &(base->xres_virtual), &(base->yres_virtual), |
| 219 | &(base->bits_per_pixel)); |
| 220 | //bb_info_msg("GEO[%s]", p); |
| 221 | break; |
| 222 | case 1: |
| 223 | sscanf(p, "%d %d %d %d %d %d %d", |
| 224 | &(base->pixclock), |
| 225 | &(base->left_margin), &(base->right_margin), |
| 226 | &(base->upper_margin), &(base->lower_margin), |
| 227 | &(base->hsync_len), &(base->vsync_len)); |
| 228 | //bb_info_msg("TIM[%s]", p); |
| 229 | break; |
| 230 | case 2: |
| 231 | case 3: { |
| 232 | static const uint32_t syncs[] = {FB_VMODE_INTERLACED, FB_VMODE_DOUBLE}; |
| 233 | ss(&base->vmode, syncs[i-2], p, "false"); |
| 234 | //bb_info_msg("VMODE[%s]", p); |
| 235 | break; |
| 236 | } |
| 237 | case 4: |
| 238 | case 5: |
| 239 | case 6: { |
| 240 | static const uint32_t syncs[] = {FB_SYNC_VERT_HIGH_ACT, FB_SYNC_HOR_HIGH_ACT, FB_SYNC_COMP_HIGH_ACT}; |
| 241 | ss(&base->sync, syncs[i-4], p, "low"); |
| 242 | //bb_info_msg("SYNC[%s]", p); |
| 243 | break; |
| 244 | } |
| 245 | case 7: |
| 246 | ss(&base->sync, FB_SYNC_EXT, p, "false"); |
| 247 | //bb_info_msg("EXTSYNC[%s]", p); |
| 248 | break; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 249 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 250 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 251 | return 0; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 252 | } |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 253 | #endif |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 254 | |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 255 | static void setmode(struct fb_var_screeninfo *base, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 256 | struct fb_var_screeninfo *set) |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 257 | { |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 258 | if ((int32_t) set->xres > 0) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 259 | base->xres = set->xres; |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 260 | if ((int32_t) set->yres > 0) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 261 | base->yres = set->yres; |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 262 | if ((int32_t) set->xres_virtual > 0) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 263 | base->xres_virtual = set->xres_virtual; |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 264 | if ((int32_t) set->yres_virtual > 0) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 265 | base->yres_virtual = set->yres_virtual; |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 266 | if ((int32_t) set->bits_per_pixel > 0) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 267 | base->bits_per_pixel = set->bits_per_pixel; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Denis Vlasenko | 8d523cb | 2008-07-27 21:16:30 +0000 | [diff] [blame] | 270 | static void showmode(struct fb_var_screeninfo *v) |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 271 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 272 | double drate = 0, hrate = 0, vrate = 0; |
| 273 | |
| 274 | if (v->pixclock) { |
| 275 | drate = 1e12 / v->pixclock; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 276 | hrate = drate / (v->left_margin + v->xres + v->right_margin + v->hsync_len); |
| 277 | 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] | 278 | } |
Aaron Lehmann | 6069441 | 2002-08-13 04:19:23 +0000 | [diff] [blame] | 279 | printf("\nmode \"%ux%u-%u\"\n" |
Denis Vlasenko | e324184 | 2007-08-13 10:36:25 +0000 | [diff] [blame] | 280 | #if ENABLE_FEATURE_FBSET_FANCY |
Aaron Lehmann | 6069441 | 2002-08-13 04:19:23 +0000 | [diff] [blame] | 281 | "\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n" |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 282 | #endif |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 283 | "\tgeometry %u %u %u %u %u\n" |
| 284 | "\ttimings %u %u %u %u %u %u %u\n" |
| 285 | "\taccel %s\n" |
| 286 | "\trgba %u/%u,%u/%u,%u/%u,%u/%u\n" |
| 287 | "endmode\n\n", |
| 288 | v->xres, v->yres, (int) (vrate + 0.5), |
Denis Vlasenko | e324184 | 2007-08-13 10:36:25 +0000 | [diff] [blame] | 289 | #if ENABLE_FEATURE_FBSET_FANCY |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 290 | drate / 1e6, hrate / 1e3, vrate, |
Aaron Lehmann | 6069441 | 2002-08-13 04:19:23 +0000 | [diff] [blame] | 291 | #endif |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 292 | v->xres, v->yres, v->xres_virtual, v->yres_virtual, v->bits_per_pixel, |
| 293 | v->pixclock, v->left_margin, v->right_margin, v->upper_margin, v->lower_margin, |
| 294 | v->hsync_len, v->vsync_len, |
| 295 | (v->accel_flags > 0 ? "true" : "false"), |
| 296 | v->red.length, v->red.offset, v->green.length, v->green.offset, |
| 297 | v->blue.length, v->blue.offset, v->transp.length, v->transp.offset); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 300 | int fbset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 301 | int fbset_main(int argc, char **argv) |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 302 | { |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 303 | enum { |
| 304 | OPT_CHANGE = (1 << 0), |
| 305 | /*OPT_INFO = (1 << 1), ??*/ |
| 306 | OPT_READMODE = (1 << 2), |
| 307 | OPT_ALL = (1 << 9), |
| 308 | }; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 309 | struct fb_var_screeninfo var, varset; |
| 310 | int fh, i; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 311 | unsigned options = 0; |
| 312 | |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 313 | const char *fbdev = DEFAULTFBDEV; |
| 314 | const char *modefile = DEFAULTFBMODE; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 315 | char *thisarg, *mode = NULL; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 316 | |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 317 | memset(&varset, 0xff, sizeof(varset)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 318 | |
| 319 | /* parse cmd args.... why do they have to make things so difficult? */ |
| 320 | argv++; |
| 321 | argc--; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 322 | for (; argc > 0 && (thisarg = *argv) != NULL; argc--, argv++) { |
| 323 | if (thisarg[0] == '-') for (i = 0; i < ARRAY_SIZE(g_cmdoptions); i++) { |
| 324 | if (strcmp(thisarg + 1, g_cmdoptions[i].name) != 0) |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 325 | continue; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 326 | if (argc <= g_cmdoptions[i].param_count) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 327 | bb_show_usage(); |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 328 | |
| 329 | switch (g_cmdoptions[i].code) { |
| 330 | case CMD_FB: |
| 331 | fbdev = argv[1]; |
| 332 | break; |
| 333 | case CMD_DB: |
| 334 | modefile = argv[1]; |
| 335 | break; |
| 336 | case CMD_GEOMETRY: |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 337 | varset.xres = xatou32(argv[1]); |
| 338 | varset.yres = xatou32(argv[2]); |
| 339 | varset.xres_virtual = xatou32(argv[3]); |
| 340 | varset.yres_virtual = xatou32(argv[4]); |
| 341 | varset.bits_per_pixel = xatou32(argv[5]); |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 342 | break; |
| 343 | case CMD_TIMING: |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 344 | varset.pixclock = xatou32(argv[1]); |
| 345 | varset.left_margin = xatou32(argv[2]); |
| 346 | varset.right_margin = xatou32(argv[3]); |
| 347 | varset.upper_margin = xatou32(argv[4]); |
| 348 | varset.lower_margin = xatou32(argv[5]); |
| 349 | varset.hsync_len = xatou32(argv[6]); |
| 350 | varset.vsync_len = xatou32(argv[7]); |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 351 | break; |
| 352 | case CMD_ALL: |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 353 | options |= OPT_ALL; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 354 | break; |
| 355 | case CMD_CHANGE: |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 356 | options |= OPT_CHANGE; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 357 | break; |
Denis Vlasenko | e324184 | 2007-08-13 10:36:25 +0000 | [diff] [blame] | 358 | #if ENABLE_FEATURE_FBSET_FANCY |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 359 | case CMD_XRES: |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 360 | varset.xres = xatou32(argv[1]); |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 361 | break; |
| 362 | case CMD_YRES: |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 363 | varset.yres = xatou32(argv[1]); |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 364 | break; |
| 365 | case CMD_DEPTH: |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 366 | varset.bits_per_pixel = xatou32(argv[1]); |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 367 | break; |
| 368 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 369 | } |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 370 | argc -= g_cmdoptions[i].param_count; |
| 371 | argv += g_cmdoptions[i].param_count; |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 372 | goto contin; |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 373 | } |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 374 | if (argc != 1) |
| 375 | bb_show_usage(); |
| 376 | mode = *argv; |
| 377 | options |= OPT_READMODE; |
| 378 | contin: ; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 379 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 380 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 381 | fh = xopen(fbdev, O_RDONLY); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 382 | xioctl(fh, FBIOGET_VSCREENINFO, &var); |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 383 | if (options & OPT_READMODE) { |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 384 | #if !ENABLE_FEATURE_FBSET_READMODE |
| 385 | bb_show_usage(); |
| 386 | #else |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 387 | if (!readmode(&var, modefile, mode)) { |
Denis Vlasenko | 39d551f | 2006-09-30 16:28:30 +0000 | [diff] [blame] | 388 | bb_error_msg_and_die("unknown video mode '%s'", mode); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 389 | } |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 390 | #endif |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 391 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 392 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 393 | setmode(&var, &varset); |
Denis Vlasenko | b66d16a | 2008-08-24 16:25:40 +0000 | [diff] [blame^] | 394 | if (options & OPT_CHANGE) { |
| 395 | if (options & OPT_ALL) |
Denis Vlasenko | 274b8c0 | 2006-09-30 16:22:59 +0000 | [diff] [blame] | 396 | var.activate = FB_ACTIVATE_ALL; |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 397 | xioctl(fh, FBIOPUT_VSCREENINFO, &var); |
Denis Vlasenko | 274b8c0 | 2006-09-30 16:22:59 +0000 | [diff] [blame] | 398 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 399 | showmode(&var); |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 400 | /* Don't close the file, as exiting will take care of that */ |
| 401 | /* close(fh); */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 402 | |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 403 | return EXIT_SUCCESS; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 404 | } |