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 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | * |
| 21 | * This is a from-scratch implementation of fbset; but the de facto fbset |
| 22 | * implementation was a good reference. fbset (original) is released under |
| 23 | * the GPL, and is (c) 1995-1999 by: |
| 24 | * Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be) |
| 25 | */ |
| 26 | |
Eric Andersen | 3570a34 | 2000-09-25 21:45:58 +0000 | [diff] [blame] | 27 | #include "busybox.h" |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <unistd.h> |
| 31 | #include <fcntl.h> |
| 32 | #include <errno.h> |
| 33 | #include <ctype.h> |
| 34 | #include <sys/ioctl.h> |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 35 | |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 36 | #define DEFAULTFBDEV "/dev/fb0" |
| 37 | #define DEFAULTFBMODE "/etc/fb.modes" |
| 38 | |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 39 | static const int OPT_CHANGE = (1 << 0); |
| 40 | static const int OPT_INFO = (1 << 1); |
| 41 | static const int OPT_READMODE = (1 << 2); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 42 | |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 43 | enum { |
| 44 | CMD_HELP = 0, |
| 45 | CMD_FB = 1, |
| 46 | CMD_DB = 2, |
| 47 | CMD_GEOMETRY = 3, |
| 48 | CMD_TIMING = 4, |
| 49 | CMD_ACCEL = 5, |
| 50 | CMD_HSYNC = 6, |
| 51 | CMD_VSYNC = 7, |
| 52 | CMD_LACED = 8, |
| 53 | CMD_DOUBLE = 9, |
| 54 | /* CMD_XCOMPAT = 10, */ |
| 55 | CMD_ALL = 11, |
| 56 | CMD_INFO = 12, |
| 57 | CMD_CHANGE = 13, |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 58 | |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 59 | #ifdef BB_FEATURE_FBSET_FANCY |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 60 | CMD_XRES = 100, |
| 61 | CMD_YRES = 101, |
| 62 | CMD_VXRES = 102, |
| 63 | CMD_VYRES = 103, |
| 64 | CMD_DEPTH = 104, |
| 65 | CMD_MATCH = 105, |
| 66 | CMD_PIXCLOCK = 106, |
| 67 | CMD_LEFT = 107, |
| 68 | CMD_RIGHT = 108, |
| 69 | CMD_UPPER = 109, |
| 70 | CMD_LOWER = 110, |
| 71 | CMD_HSLEN = 111, |
| 72 | CMD_VSLEN = 112, |
| 73 | CMD_CSYNC = 113, |
| 74 | CMD_GSYNC = 114, |
| 75 | CMD_EXTSYNC = 115, |
| 76 | CMD_BCAST = 116, |
| 77 | CMD_RGBA = 117, |
| 78 | CMD_STEP = 118, |
| 79 | CMD_MOVE = 119, |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 80 | #endif |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 81 | }; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 82 | |
| 83 | static unsigned int g_options = 0; |
| 84 | |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 85 | /* Stuff stolen from the kernel's fb.h */ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 86 | static const int FBIOGET_VSCREENINFO = 0x4600; |
| 87 | static const int FBIOPUT_VSCREENINFO = 0x4601; |
Eric Andersen | c873d61 | 2000-09-21 04:09:58 +0000 | [diff] [blame] | 88 | #define __u32 unsigned int |
| 89 | struct fb_bitfield { |
| 90 | __u32 offset; /* beginning of bitfield */ |
| 91 | __u32 length; /* length of bitfield */ |
| 92 | __u32 msb_right; /* != 0 : Most significant bit is */ |
| 93 | /* right */ |
| 94 | }; |
| 95 | struct fb_var_screeninfo { |
| 96 | __u32 xres; /* visible resolution */ |
| 97 | __u32 yres; |
| 98 | __u32 xres_virtual; /* virtual resolution */ |
| 99 | __u32 yres_virtual; |
| 100 | __u32 xoffset; /* offset from virtual to visible */ |
| 101 | __u32 yoffset; /* resolution */ |
| 102 | |
| 103 | __u32 bits_per_pixel; /* guess what */ |
| 104 | __u32 grayscale; /* != 0 Graylevels instead of colors */ |
| 105 | |
| 106 | struct fb_bitfield red; /* bitfield in fb mem if true color, */ |
| 107 | struct fb_bitfield green; /* else only length is significant */ |
| 108 | struct fb_bitfield blue; |
| 109 | struct fb_bitfield transp; /* transparency */ |
| 110 | |
| 111 | __u32 nonstd; /* != 0 Non standard pixel format */ |
| 112 | |
| 113 | __u32 activate; /* see FB_ACTIVATE_* */ |
| 114 | |
| 115 | __u32 height; /* height of picture in mm */ |
| 116 | __u32 width; /* width of picture in mm */ |
| 117 | |
| 118 | __u32 accel_flags; /* acceleration flags (hints) */ |
| 119 | |
| 120 | /* Timing: All values in pixclocks, except pixclock (of course) */ |
| 121 | __u32 pixclock; /* pixel clock in ps (pico seconds) */ |
| 122 | __u32 left_margin; /* time from sync to picture */ |
| 123 | __u32 right_margin; /* time from picture to sync */ |
| 124 | __u32 upper_margin; /* time from sync to picture */ |
| 125 | __u32 lower_margin; |
| 126 | __u32 hsync_len; /* length of horizontal sync */ |
| 127 | __u32 vsync_len; /* length of vertical sync */ |
| 128 | __u32 sync; /* see FB_SYNC_* */ |
| 129 | __u32 vmode; /* see FB_VMODE_* */ |
| 130 | __u32 reserved[6]; /* Reserved for future compatibility */ |
| 131 | }; |
| 132 | |
| 133 | |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 134 | struct cmdoptions_t { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 135 | char *name; |
| 136 | unsigned char param_count; |
| 137 | unsigned char code; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 138 | } g_cmdoptions[] = { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 139 | { |
| 140 | "-h", 0, CMD_HELP}, { |
| 141 | "-fb", 1, CMD_FB}, { |
| 142 | "-db", 1, CMD_DB}, { |
| 143 | "-a", 0, CMD_ALL}, { |
| 144 | "-i", 0, CMD_INFO}, { |
| 145 | "-g", 5, CMD_GEOMETRY}, { |
| 146 | "-t", 7, CMD_TIMING}, { |
| 147 | "-accel", 1, CMD_ACCEL}, { |
| 148 | "-hsync", 1, CMD_HSYNC}, { |
| 149 | "-vsync", 1, CMD_VSYNC}, { |
| 150 | "-laced", 1, CMD_LACED}, { |
Erik Andersen | 9cf3bfa | 2000-04-13 18:49:43 +0000 | [diff] [blame] | 151 | "-double", 1, CMD_DOUBLE}, { |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 152 | "-help", 0, CMD_HELP}, { |
Eric Andersen | c8c10c5 | 2000-07-06 17:23:23 +0000 | [diff] [blame] | 153 | "-n", 0, CMD_CHANGE}, { |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 154 | #ifdef BB_FEATURE_FBSET_FANCY |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 155 | "-help", 0, CMD_HELP}, { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 156 | "-all", 0, CMD_ALL}, { |
| 157 | "-xres", 1, CMD_XRES}, { |
| 158 | "-yres", 1, CMD_YRES}, { |
| 159 | "-vxres", 1, CMD_VXRES}, { |
| 160 | "-vyres", 1, CMD_VYRES}, { |
| 161 | "-depth", 1, CMD_DEPTH}, { |
| 162 | "-match", 0, CMD_MATCH}, { |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 163 | "-geometry", 5, CMD_GEOMETRY}, { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 164 | "-pixclock", 1, CMD_PIXCLOCK}, { |
| 165 | "-left", 1, CMD_LEFT}, { |
| 166 | "-right", 1, CMD_RIGHT}, { |
| 167 | "-upper", 1, CMD_UPPER}, { |
| 168 | "-lower", 1, CMD_LOWER}, { |
| 169 | "-hslen", 1, CMD_HSLEN}, { |
| 170 | "-vslen", 1, CMD_VSLEN}, { |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 171 | "-timings", 7, CMD_TIMING}, { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 172 | "-csync", 1, CMD_CSYNC}, { |
| 173 | "-gsync", 1, CMD_GSYNC}, { |
| 174 | "-extsync", 1, CMD_EXTSYNC}, { |
| 175 | "-bcast", 1, CMD_BCAST}, { |
| 176 | "-rgba", 1, CMD_RGBA}, { |
| 177 | "-step", 1, CMD_STEP}, { |
Erik Andersen | 9cf3bfa | 2000-04-13 18:49:43 +0000 | [diff] [blame] | 178 | "-move", 1, CMD_MOVE}, { |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 179 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 180 | 0, 0, 0} |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 181 | }; |
| 182 | |
Matt Kraai | 269e07c | 2000-10-28 16:56:32 +0000 | [diff] [blame] | 183 | #ifdef BB_FEATURE_FBSET_READMODE |
| 184 | /* taken from linux/fb.h */ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 185 | static const int FB_VMODE_INTERLACED = 1; /* interlaced */ |
| 186 | static const int FB_VMODE_DOUBLE = 2; /* double scan */ |
| 187 | static const int FB_SYNC_HOR_HIGH_ACT = 1; /* horizontal sync high active */ |
| 188 | static const int FB_SYNC_VERT_HIGH_ACT = 2; /* vertical sync high active */ |
| 189 | static const int FB_SYNC_EXT = 4; /* external sync */ |
| 190 | static const int FB_SYNC_COMP_HIGH_ACT = 8; /* composite sync high active */ |
Matt Kraai | 269e07c | 2000-10-28 16:56:32 +0000 | [diff] [blame] | 191 | #endif |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 192 | static int readmode(struct fb_var_screeninfo *base, const char *fn, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 193 | const char *mode) |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 194 | { |
Eric Andersen | 03f4c27 | 2000-07-06 23:10:29 +0000 | [diff] [blame] | 195 | #ifdef BB_FEATURE_FBSET_READMODE |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 196 | FILE *f; |
| 197 | char buf[256]; |
| 198 | char *p = buf; |
| 199 | |
| 200 | if ((f = fopen(fn, "r")) == NULL) |
Matt Kraai | a9819b2 | 2000-12-22 01:48:07 +0000 | [diff] [blame] | 201 | perror_msg_and_die("readmode(fopen)"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 202 | while (!feof(f)) { |
| 203 | fgets(buf, sizeof(buf), f); |
| 204 | if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { |
| 205 | p += 5; |
| 206 | if ((p = strstr(buf, mode))) { |
| 207 | p += strlen(mode); |
| 208 | if (!isspace(*p) && (*p != 0) && (*p != '"') |
| 209 | && (*p != '\r') && (*p != '\n')) |
| 210 | continue; /* almost, but not quite */ |
| 211 | while (!feof(f)) { |
| 212 | fgets(buf, sizeof(buf), f); |
Eric Andersen | 6f96e67 | 2000-07-12 23:01:04 +0000 | [diff] [blame] | 213 | |
| 214 | if ((p = strstr(buf, "geometry "))) { |
| 215 | p += 9; |
| 216 | |
| 217 | sscanf(p, "%d %d %d %d %d", |
| 218 | &(base->xres), &(base->yres), |
| 219 | &(base->xres_virtual), &(base->yres_virtual), |
| 220 | &(base->bits_per_pixel)); |
| 221 | } else if ((p = strstr(buf, "timings "))) { |
| 222 | p += 8; |
| 223 | |
| 224 | sscanf(p, "%d %d %d %d %d %d %d", |
| 225 | &(base->pixclock), |
| 226 | &(base->left_margin), &(base->right_margin), |
| 227 | &(base->upper_margin), &(base->lower_margin), |
| 228 | &(base->hsync_len), &(base->vsync_len)); |
| 229 | } else if ((p = strstr(buf, "laced "))) { |
| 230 | p += 6; |
| 231 | |
| 232 | if (strstr(buf, "false")) { |
| 233 | base->vmode &= ~FB_VMODE_INTERLACED; |
| 234 | } else { |
| 235 | base->vmode |= FB_VMODE_INTERLACED; |
| 236 | } |
| 237 | } else if ((p = strstr(buf, "double "))) { |
| 238 | p += 7; |
| 239 | |
| 240 | if (strstr(buf, "false")) { |
| 241 | base->vmode &= ~FB_VMODE_DOUBLE; |
| 242 | } else { |
| 243 | base->vmode |= FB_VMODE_DOUBLE; |
| 244 | } |
| 245 | } else if ((p = strstr(buf, "vsync "))) { |
| 246 | p += 6; |
| 247 | |
| 248 | if (strstr(buf, "low")) { |
| 249 | base->sync &= ~FB_SYNC_VERT_HIGH_ACT; |
| 250 | } else { |
| 251 | base->sync |= FB_SYNC_VERT_HIGH_ACT; |
| 252 | } |
| 253 | } else if ((p = strstr(buf, "hsync "))) { |
| 254 | p += 6; |
| 255 | |
| 256 | if (strstr(buf, "low")) { |
| 257 | base->sync &= ~FB_SYNC_HOR_HIGH_ACT; |
| 258 | } else { |
| 259 | base->sync |= FB_SYNC_HOR_HIGH_ACT; |
| 260 | } |
| 261 | } else if ((p = strstr(buf, "csync "))) { |
| 262 | p += 6; |
| 263 | |
| 264 | if (strstr(buf, "low")) { |
| 265 | base->sync &= ~FB_SYNC_COMP_HIGH_ACT; |
| 266 | } else { |
| 267 | base->sync |= FB_SYNC_COMP_HIGH_ACT; |
| 268 | } |
| 269 | } else if ((p = strstr(buf, "extsync "))) { |
| 270 | p += 8; |
| 271 | |
| 272 | if (strstr(buf, "false")) { |
| 273 | base->sync &= ~FB_SYNC_EXT; |
| 274 | } else { |
| 275 | base->sync |= FB_SYNC_EXT; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | if (strstr(buf, "endmode")) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 280 | return 1; |
| 281 | } |
| 282 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 283 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 284 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 285 | #else |
Mark Whitley | f57c944 | 2000-12-07 19:56:48 +0000 | [diff] [blame] | 286 | error_msg( "mode reading not compiled in\n"); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 287 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 288 | return 0; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 291 | static void setmode(struct fb_var_screeninfo *base, |
| 292 | struct fb_var_screeninfo *set) |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 293 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 294 | if ((int) set->xres > 0) |
| 295 | base->xres = set->xres; |
| 296 | if ((int) set->yres > 0) |
| 297 | base->yres = set->yres; |
| 298 | if ((int) set->xres_virtual > 0) |
| 299 | base->xres_virtual = set->xres_virtual; |
| 300 | if ((int) set->yres_virtual > 0) |
| 301 | base->yres_virtual = set->yres_virtual; |
| 302 | if ((int) set->bits_per_pixel > 0) |
| 303 | base->bits_per_pixel = set->bits_per_pixel; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | static void showmode(struct fb_var_screeninfo *v) |
| 307 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 308 | double drate = 0, hrate = 0, vrate = 0; |
| 309 | |
| 310 | if (v->pixclock) { |
| 311 | drate = 1e12 / v->pixclock; |
| 312 | hrate = |
| 313 | drate / (v->left_margin + v->xres + v->right_margin + |
| 314 | v->hsync_len); |
| 315 | vrate = |
| 316 | hrate / (v->upper_margin + v->yres + v->lower_margin + |
| 317 | v->vsync_len); |
| 318 | } |
| 319 | printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int) (vrate + 0.5)); |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 320 | #ifdef BB_FEATURE_FBSET_FANCY |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 321 | printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate / 1e6, |
| 322 | hrate / 1e3, vrate); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 323 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 324 | printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres, |
| 325 | v->xres_virtual, v->yres_virtual, v->bits_per_pixel); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 326 | printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin, |
| 327 | v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len, |
| 328 | v->vsync_len); |
| 329 | printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false")); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 330 | printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length, |
| 331 | v->red.offset, v->green.length, v->green.offset, v->blue.length, |
| 332 | v->blue.offset, v->transp.length, v->transp.offset); |
Erik Andersen | 9cf3bfa | 2000-04-13 18:49:43 +0000 | [diff] [blame] | 333 | printf("endmode\n\n"); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static void fbset_usage(void) |
| 337 | { |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 338 | #ifndef BB_FEATURE_TRIVIAL_HELP |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 339 | int i; |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 340 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 341 | |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 342 | #ifndef STANDALONE |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 343 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", |
| 344 | BB_VER, BB_BT); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 345 | #endif |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 346 | fprintf(stderr, "Usage: fbset [options] [mode]\n"); |
| 347 | #ifndef BB_FEATURE_TRIVIAL_HELP |
| 348 | fprintf(stderr, "\nShows and modifies frame buffer device settings\n\n"); |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 349 | fprintf(stderr, "The following options are recognized:\n"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 350 | for (i = 0; g_cmdoptions[i].name; i++) |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 351 | fprintf(stderr, "\t%s\n", g_cmdoptions[i].name); |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 352 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 353 | exit(-1); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | #ifdef STANDALONE |
| 357 | int main(int argc, char **argv) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 358 | #else |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 359 | extern int fbset_main(int argc, char **argv) |
| 360 | #endif |
| 361 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 362 | struct fb_var_screeninfo var, varset; |
| 363 | int fh, i; |
| 364 | char *fbdev = DEFAULTFBDEV; |
| 365 | char *modefile = DEFAULTFBMODE; |
| 366 | char *thisarg, *mode = NULL; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 367 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 368 | memset(&varset, 0xFF, sizeof(varset)); |
| 369 | |
| 370 | /* parse cmd args.... why do they have to make things so difficult? */ |
| 371 | argv++; |
| 372 | argc--; |
| 373 | for (; argc > 0 && (thisarg = *argv); argc--, argv++) { |
| 374 | for (i = 0; g_cmdoptions[i].name; i++) { |
| 375 | if (!strcmp(thisarg, g_cmdoptions[i].name)) { |
| 376 | if (argc - 1 < g_cmdoptions[i].param_count) |
| 377 | fbset_usage(); |
| 378 | switch (g_cmdoptions[i].code) { |
| 379 | case CMD_HELP: |
| 380 | fbset_usage(); |
| 381 | case CMD_FB: |
| 382 | fbdev = argv[1]; |
| 383 | break; |
| 384 | case CMD_DB: |
| 385 | modefile = argv[1]; |
| 386 | break; |
| 387 | case CMD_GEOMETRY: |
| 388 | varset.xres = strtoul(argv[1], 0, 0); |
| 389 | varset.yres = strtoul(argv[2], 0, 0); |
| 390 | varset.xres_virtual = strtoul(argv[3], 0, 0); |
| 391 | varset.yres_virtual = strtoul(argv[4], 0, 0); |
| 392 | varset.bits_per_pixel = strtoul(argv[5], 0, 0); |
| 393 | break; |
| 394 | case CMD_TIMING: |
| 395 | varset.pixclock = strtoul(argv[1], 0, 0); |
| 396 | varset.left_margin = strtoul(argv[2], 0, 0); |
| 397 | varset.right_margin = strtoul(argv[3], 0, 0); |
| 398 | varset.upper_margin = strtoul(argv[4], 0, 0); |
| 399 | varset.lower_margin = strtoul(argv[5], 0, 0); |
| 400 | varset.hsync_len = strtoul(argv[6], 0, 0); |
| 401 | varset.vsync_len = strtoul(argv[7], 0, 0); |
| 402 | break; |
Eric Andersen | c8c10c5 | 2000-07-06 17:23:23 +0000 | [diff] [blame] | 403 | case CMD_CHANGE: |
| 404 | g_options |= OPT_CHANGE; |
| 405 | break; |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 406 | #ifdef BB_FEATURE_FBSET_FANCY |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 407 | case CMD_XRES: |
| 408 | varset.xres = strtoul(argv[1], 0, 0); |
| 409 | break; |
| 410 | case CMD_YRES: |
| 411 | varset.yres = strtoul(argv[1], 0, 0); |
| 412 | break; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 413 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 414 | } |
| 415 | argc -= g_cmdoptions[i].param_count; |
| 416 | argv += g_cmdoptions[i].param_count; |
| 417 | break; |
| 418 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 419 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 420 | if (!g_cmdoptions[i].name) { |
| 421 | if (argc == 1) { |
| 422 | mode = *argv; |
| 423 | g_options |= OPT_READMODE; |
| 424 | } else { |
| 425 | fbset_usage(); |
| 426 | } |
| 427 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 428 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 429 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 430 | if ((fh = open(fbdev, O_RDONLY)) < 0) |
Matt Kraai | a9819b2 | 2000-12-22 01:48:07 +0000 | [diff] [blame] | 431 | perror_msg_and_die("fbset(open)"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 432 | if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) |
Matt Kraai | a9819b2 | 2000-12-22 01:48:07 +0000 | [diff] [blame] | 433 | perror_msg_and_die("fbset(ioctl)"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 434 | if (g_options & OPT_READMODE) { |
| 435 | if (!readmode(&var, modefile, mode)) { |
Mark Whitley | f57c944 | 2000-12-07 19:56:48 +0000 | [diff] [blame] | 436 | error_msg("Unknown video mode `%s'\n", mode); |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 437 | return EXIT_FAILURE; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 438 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 439 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 440 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 441 | setmode(&var, &varset); |
| 442 | if (g_options & OPT_CHANGE) |
| 443 | if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) |
Matt Kraai | a9819b2 | 2000-12-22 01:48:07 +0000 | [diff] [blame] | 444 | perror_msg_and_die("fbset(ioctl)"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 445 | showmode(&var); |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 446 | /* Don't close the file, as exiting will take care of that */ |
| 447 | /* close(fh); */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 448 | |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 449 | return EXIT_SUCCESS; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 450 | } |