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