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