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