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 | |
| 27 | #include "internal.h" |
| 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> |
| 35 | #include <linux/fb.h> |
Erik Andersen | 4d1d011 | 1999-12-17 18:44:15 +0000 | [diff] [blame] | 36 | #include <linux/version.h> |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 37 | |
| 38 | #define PERROR(ctx) do { perror(ctx); exit(1); } while(0) |
| 39 | |
Erik Andersen | 4d1d011 | 1999-12-17 18:44:15 +0000 | [diff] [blame] | 40 | #ifndef KERNEL_VERSION |
| 41 | #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) |
| 42 | #endif |
| 43 | |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 44 | #define DEFAULTFBDEV "/dev/fb0" |
| 45 | #define DEFAULTFBMODE "/etc/fb.modes" |
| 46 | |
| 47 | #define OPT_CHANGE 1 |
| 48 | #define OPT_INFO (1 << 1) |
| 49 | #define OPT_READMODE (1 << 2) |
| 50 | |
| 51 | #define CMD_HELP 0 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 52 | #define CMD_FB 1 |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 53 | #define CMD_DB 2 |
| 54 | #define CMD_GEOMETRY 3 |
| 55 | #define CMD_TIMING 4 |
| 56 | #define CMD_ACCEL 5 |
| 57 | #define CMD_HSYNC 6 |
| 58 | #define CMD_VSYNC 7 |
| 59 | #define CMD_LACED 8 |
| 60 | #define CMD_DOUBLE 9 |
| 61 | /* #define CMD_XCOMPAT 10 */ |
| 62 | #define CMD_ALL 11 |
| 63 | #define CMD_INFO 12 |
Eric Andersen | c8c10c5 | 2000-07-06 17:23:23 +0000 | [diff] [blame^] | 64 | #define CMD_CHANGE 13 |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 65 | |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 66 | #ifdef BB_FEATURE_FBSET_FANCY |
Eric Andersen | c8c10c5 | 2000-07-06 17:23:23 +0000 | [diff] [blame^] | 67 | #define CMD_XRES 100 |
| 68 | #define CMD_YRES 101 |
| 69 | #define CMD_VXRES 102 |
| 70 | #define CMD_VYRES 103 |
| 71 | #define CMD_DEPTH 104 |
| 72 | #define CMD_MATCH 105 |
| 73 | #define CMD_PIXCLOCK 106 |
| 74 | #define CMD_LEFT 107 |
| 75 | #define CMD_RIGHT 108 |
| 76 | #define CMD_UPPER 109 |
| 77 | #define CMD_LOWER 110 |
| 78 | #define CMD_HSLEN 111 |
| 79 | #define CMD_VSLEN 112 |
| 80 | #define CMD_CSYNC 113 |
| 81 | #define CMD_GSYNC 114 |
| 82 | #define CMD_EXTSYNC 115 |
| 83 | #define CMD_BCAST 116 |
| 84 | #define CMD_RGBA 117 |
| 85 | #define CMD_STEP 118 |
| 86 | #define CMD_MOVE 119 |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 87 | #endif |
| 88 | |
| 89 | static unsigned int g_options = 0; |
| 90 | |
| 91 | struct cmdoptions_t { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 92 | char *name; |
| 93 | unsigned char param_count; |
| 94 | unsigned char code; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 95 | } g_cmdoptions[] = { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 96 | { |
| 97 | "-h", 0, CMD_HELP}, { |
| 98 | "-fb", 1, CMD_FB}, { |
| 99 | "-db", 1, CMD_DB}, { |
| 100 | "-a", 0, CMD_ALL}, { |
| 101 | "-i", 0, CMD_INFO}, { |
| 102 | "-g", 5, CMD_GEOMETRY}, { |
| 103 | "-t", 7, CMD_TIMING}, { |
| 104 | "-accel", 1, CMD_ACCEL}, { |
| 105 | "-hsync", 1, CMD_HSYNC}, { |
| 106 | "-vsync", 1, CMD_VSYNC}, { |
| 107 | "-laced", 1, CMD_LACED}, { |
Erik Andersen | 9cf3bfa | 2000-04-13 18:49:43 +0000 | [diff] [blame] | 108 | "-double", 1, CMD_DOUBLE}, { |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 109 | "-help", 0, CMD_HELP}, { |
Eric Andersen | c8c10c5 | 2000-07-06 17:23:23 +0000 | [diff] [blame^] | 110 | "-n", 0, CMD_CHANGE}, { |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 111 | #ifdef BB_FEATURE_FBSET_FANCY |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 112 | "-help", 0, CMD_HELP}, { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 113 | "-all", 0, CMD_ALL}, { |
| 114 | "-xres", 1, CMD_XRES}, { |
| 115 | "-yres", 1, CMD_YRES}, { |
| 116 | "-vxres", 1, CMD_VXRES}, { |
| 117 | "-vyres", 1, CMD_VYRES}, { |
| 118 | "-depth", 1, CMD_DEPTH}, { |
| 119 | "-match", 0, CMD_MATCH}, { |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 120 | "-geometry", 5, CMD_GEOMETRY}, { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 121 | "-pixclock", 1, CMD_PIXCLOCK}, { |
| 122 | "-left", 1, CMD_LEFT}, { |
| 123 | "-right", 1, CMD_RIGHT}, { |
| 124 | "-upper", 1, CMD_UPPER}, { |
| 125 | "-lower", 1, CMD_LOWER}, { |
| 126 | "-hslen", 1, CMD_HSLEN}, { |
| 127 | "-vslen", 1, CMD_VSLEN}, { |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 128 | "-timings", 7, CMD_TIMING}, { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 129 | "-csync", 1, CMD_CSYNC}, { |
| 130 | "-gsync", 1, CMD_GSYNC}, { |
| 131 | "-extsync", 1, CMD_EXTSYNC}, { |
| 132 | "-bcast", 1, CMD_BCAST}, { |
| 133 | "-rgba", 1, CMD_RGBA}, { |
| 134 | "-step", 1, CMD_STEP}, { |
Erik Andersen | 9cf3bfa | 2000-04-13 18:49:43 +0000 | [diff] [blame] | 135 | "-move", 1, CMD_MOVE}, { |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 136 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 137 | 0, 0, 0} |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static int readmode(struct fb_var_screeninfo *base, const char *fn, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 141 | const char *mode) |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 142 | { |
| 143 | #ifdef BB_FBSET_READMODE |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 144 | FILE *f; |
| 145 | char buf[256]; |
| 146 | char *p = buf; |
| 147 | |
| 148 | if ((f = fopen(fn, "r")) == NULL) |
| 149 | PERROR("readmode(fopen)"); |
| 150 | while (!feof(f)) { |
| 151 | fgets(buf, sizeof(buf), f); |
| 152 | if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { |
| 153 | p += 5; |
| 154 | if ((p = strstr(buf, mode))) { |
| 155 | p += strlen(mode); |
| 156 | if (!isspace(*p) && (*p != 0) && (*p != '"') |
| 157 | && (*p != '\r') && (*p != '\n')) |
| 158 | continue; /* almost, but not quite */ |
| 159 | while (!feof(f)) { |
| 160 | fgets(buf, sizeof(buf), f); |
| 161 | if (!strstr(buf, "endmode")) |
| 162 | return 1; |
| 163 | } |
| 164 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 165 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 166 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 167 | #else |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 168 | errorMsg( "mode reading not compiled in\n"); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 169 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 170 | return 0; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 173 | static void setmode(struct fb_var_screeninfo *base, |
| 174 | struct fb_var_screeninfo *set) |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 175 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 176 | if ((int) set->xres > 0) |
| 177 | base->xres = set->xres; |
| 178 | if ((int) set->yres > 0) |
| 179 | base->yres = set->yres; |
| 180 | if ((int) set->xres_virtual > 0) |
| 181 | base->xres_virtual = set->xres_virtual; |
| 182 | if ((int) set->yres_virtual > 0) |
| 183 | base->yres_virtual = set->yres_virtual; |
| 184 | if ((int) set->bits_per_pixel > 0) |
| 185 | base->bits_per_pixel = set->bits_per_pixel; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static void showmode(struct fb_var_screeninfo *v) |
| 189 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 190 | double drate = 0, hrate = 0, vrate = 0; |
| 191 | |
| 192 | if (v->pixclock) { |
| 193 | drate = 1e12 / v->pixclock; |
| 194 | hrate = |
| 195 | drate / (v->left_margin + v->xres + v->right_margin + |
| 196 | v->hsync_len); |
| 197 | vrate = |
| 198 | hrate / (v->upper_margin + v->yres + v->lower_margin + |
| 199 | v->vsync_len); |
| 200 | } |
| 201 | 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] | 202 | #ifdef BB_FEATURE_FBSET_FANCY |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 203 | printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate / 1e6, |
| 204 | hrate / 1e3, vrate); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 205 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 206 | printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres, |
| 207 | v->xres_virtual, v->yres_virtual, v->bits_per_pixel); |
Erik Andersen | 4d1d011 | 1999-12-17 18:44:15 +0000 | [diff] [blame] | 208 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 209 | printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin, |
| 210 | v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len, |
| 211 | v->vsync_len); |
| 212 | printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false")); |
Erik Andersen | 4d1d011 | 1999-12-17 18:44:15 +0000 | [diff] [blame] | 213 | #else |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 214 | printf("\ttimings %lu %lu %lu %lu %lu %lu %lu\n", v->pixclock, |
| 215 | v->left_margin, v->right_margin, v->upper_margin, |
| 216 | v->lower_margin, v->hsync_len, v->vsync_len); |
Erik Andersen | 4d1d011 | 1999-12-17 18:44:15 +0000 | [diff] [blame] | 217 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 218 | printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length, |
| 219 | v->red.offset, v->green.length, v->green.offset, v->blue.length, |
| 220 | v->blue.offset, v->transp.length, v->transp.offset); |
Erik Andersen | 9cf3bfa | 2000-04-13 18:49:43 +0000 | [diff] [blame] | 221 | printf("endmode\n\n"); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static void fbset_usage(void) |
| 225 | { |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 226 | #ifndef BB_FEATURE_TRIVIAL_HELP |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 227 | int i; |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 228 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 229 | |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 230 | #ifndef STANDALONE |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 231 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", |
| 232 | BB_VER, BB_BT); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 233 | #endif |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 234 | fprintf(stderr, "Usage: fbset [options] [mode]\n"); |
| 235 | #ifndef BB_FEATURE_TRIVIAL_HELP |
| 236 | fprintf(stderr, "\nShows and modifies frame buffer device settings\n\n"); |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 237 | fprintf(stderr, "The following options are recognized:\n"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 238 | for (i = 0; g_cmdoptions[i].name; i++) |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 239 | fprintf(stderr, "\t%s\n", g_cmdoptions[i].name); |
Erik Andersen | 7ab9c7e | 2000-05-12 19:41:47 +0000 | [diff] [blame] | 240 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 241 | exit(-1); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | #ifdef STANDALONE |
| 245 | int main(int argc, char **argv) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 246 | #else |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 247 | extern int fbset_main(int argc, char **argv) |
| 248 | #endif |
| 249 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 250 | struct fb_var_screeninfo var, varset; |
| 251 | int fh, i; |
| 252 | char *fbdev = DEFAULTFBDEV; |
| 253 | char *modefile = DEFAULTFBMODE; |
| 254 | char *thisarg, *mode = NULL; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 255 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 256 | memset(&varset, 0xFF, sizeof(varset)); |
| 257 | |
| 258 | /* parse cmd args.... why do they have to make things so difficult? */ |
| 259 | argv++; |
| 260 | argc--; |
| 261 | for (; argc > 0 && (thisarg = *argv); argc--, argv++) { |
| 262 | for (i = 0; g_cmdoptions[i].name; i++) { |
| 263 | if (!strcmp(thisarg, g_cmdoptions[i].name)) { |
| 264 | if (argc - 1 < g_cmdoptions[i].param_count) |
| 265 | fbset_usage(); |
| 266 | switch (g_cmdoptions[i].code) { |
| 267 | case CMD_HELP: |
| 268 | fbset_usage(); |
| 269 | case CMD_FB: |
| 270 | fbdev = argv[1]; |
| 271 | break; |
| 272 | case CMD_DB: |
| 273 | modefile = argv[1]; |
| 274 | break; |
| 275 | case CMD_GEOMETRY: |
| 276 | varset.xres = strtoul(argv[1], 0, 0); |
| 277 | varset.yres = strtoul(argv[2], 0, 0); |
| 278 | varset.xres_virtual = strtoul(argv[3], 0, 0); |
| 279 | varset.yres_virtual = strtoul(argv[4], 0, 0); |
| 280 | varset.bits_per_pixel = strtoul(argv[5], 0, 0); |
| 281 | break; |
| 282 | case CMD_TIMING: |
| 283 | varset.pixclock = strtoul(argv[1], 0, 0); |
| 284 | varset.left_margin = strtoul(argv[2], 0, 0); |
| 285 | varset.right_margin = strtoul(argv[3], 0, 0); |
| 286 | varset.upper_margin = strtoul(argv[4], 0, 0); |
| 287 | varset.lower_margin = strtoul(argv[5], 0, 0); |
| 288 | varset.hsync_len = strtoul(argv[6], 0, 0); |
| 289 | varset.vsync_len = strtoul(argv[7], 0, 0); |
| 290 | break; |
Eric Andersen | c8c10c5 | 2000-07-06 17:23:23 +0000 | [diff] [blame^] | 291 | case CMD_CHANGE: |
| 292 | g_options |= OPT_CHANGE; |
| 293 | break; |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 294 | #ifdef BB_FEATURE_FBSET_FANCY |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 295 | case CMD_XRES: |
| 296 | varset.xres = strtoul(argv[1], 0, 0); |
| 297 | break; |
| 298 | case CMD_YRES: |
| 299 | varset.yres = strtoul(argv[1], 0, 0); |
| 300 | break; |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 301 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 302 | } |
| 303 | argc -= g_cmdoptions[i].param_count; |
| 304 | argv += g_cmdoptions[i].param_count; |
| 305 | break; |
| 306 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 307 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 308 | if (!g_cmdoptions[i].name) { |
| 309 | if (argc == 1) { |
| 310 | mode = *argv; |
| 311 | g_options |= OPT_READMODE; |
| 312 | } else { |
| 313 | fbset_usage(); |
| 314 | } |
| 315 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 316 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 317 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 318 | if ((fh = open(fbdev, O_RDONLY)) < 0) |
| 319 | PERROR("fbset(open)"); |
| 320 | if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) |
| 321 | PERROR("fbset(ioctl)"); |
| 322 | if (g_options & OPT_READMODE) { |
| 323 | if (!readmode(&var, modefile, mode)) { |
| 324 | fprintf(stderr, "Unknown video mode `%s'\n", mode); |
| 325 | exit(1); |
| 326 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 327 | } |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 328 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 329 | setmode(&var, &varset); |
| 330 | if (g_options & OPT_CHANGE) |
| 331 | if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) |
| 332 | PERROR("fbset(ioctl)"); |
| 333 | showmode(&var); |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 334 | /* Don't close the file, as exiting will take care of that */ |
| 335 | /* close(fh); */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 336 | |
Eric Andersen | b610615 | 2000-06-19 17:25:40 +0000 | [diff] [blame] | 337 | return (TRUE); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 338 | } |