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