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