+/*
+ * fbutil.c -- get/set framebuffer values
+ *
+ * hackbard@hackdaworld.dyndns.org
+ *
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <linux/fb.h>
+
+#define MAXDEV 32
+#define DEVICE "/dev/fb/0"
+
+#define FIXED_INFO (1<<0)
+#define VAR_INFO (1<<1)
+
+int usage() {
+ printf("usage:\n");
+ printf("-d \t specify device (default %s)\n",DEVICE);
+ printf("-f \t print out fixed framebuffer info\n");
+ printf("-v \t print out variable framebuffer info\n");
+ printf("\n");
+ return 1;
+}
+
+int main(int argc,char **argv) {
+
+ int i;
+ int fd;
+ char device[MAXDEV];
+ unsigned char getmodes;
+ unsigned char setmodes;
+
+ /* fb variables */
+ struct fb_fix_screeninfo fixed_info;
+ struct fb_var_screeninfo var_info;
+
+ strcpy(device,DEVICE);
+ getmodes=0;
+ setmodes=0;
+
+ for(i=1;i<argc;i++) {
+ if(argv[i][0]=='-') {
+ switch(argv[i][1]) {
+ case 'd':
+ strncpy(device,argv[++i],MAXDEV-1);
+ break;
+ case 'f':
+ getmodes|=FIXED_INFO;
+ break;
+ case 'v':
+ getmodes|=VAR_INFO;
+ break;
+ default:
+ usage();
+ return -1;
+ }
+ }
+ else {
+ usage();
+ return -1;
+ }
+ }
+
+ if((fd=open(device,O_RDWR))<0) {
+ printf("unable to open %s\n",device);
+ return -1;
+ }
+
+ if(getmodes&FIXED_INFO) {
+ if(ioctl(fd,FBIOGET_FSCREENINFO,&fixed_info)<0) {
+ printf("cannot get fixed screen info\n");
+ return -1;
+ }
+ printf("fixed screen info:\n");
+ printf("id: %s\n",fixed_info.id);
+ printf("framebuffer memory: start=0x%x length=%u\n",
+ fixed_info.smem_start,fixed_info.smem_len);
+ printf("type: ");
+ if(fixed_info.type==FB_TYPE_PACKED_PIXELS)
+ printf("packed pixels\n");
+ if(fixed_info.type==FB_TYPE_PLANES)
+ printf("non interleaved planes\n");
+ if(fixed_info.type==FB_TYPE_INTERLEAVED_PLANES)
+ printf("interleaved planes\n");
+ if(fixed_info.type==FB_TYPE_TEXT)
+ printf("text attributes\n");
+ if(fixed_info.type==FB_TYPE_VGA_PLANES)
+ printf("ega/vga planes\n");
+ printf("visual: ");
+ if(fixed_info.visual==FB_VISUAL_MONO01)
+ printf("monochrome 1=black, 0=white\n");
+ if(fixed_info.visual==FB_VISUAL_MONO10)
+ printf("monochrome 1=white, 0=black\n");
+ if(fixed_info.visual==FB_VISUAL_TRUECOLOR)
+ printf("true color\n");
+ if(fixed_info.visual==FB_VISUAL_PSEUDOCOLOR)
+ printf("pseudo color\n");
+ if(fixed_info.visual==FB_VISUAL_DIRECTCOLOR)
+ printf("direct color\n");
+ if(fixed_info.visual==FB_VISUAL_STATIC_PSEUDOCOLOR)
+ printf("direct pseudo color\n");
+ printf("hardware panning x/y: %c/%c\n",
+ fixed_info.xpanstep?'y':'n',
+ fixed_info.ypanstep?'y':'n');
+ printf("hardware y wrap: %c\n",fixed_info.ywrapstep?'y':'n');
+ printf("line length: %u bytes\n",fixed_info.line_length);
+ printf("mapped memory: start=0x%0x length=%u\n",
+ fixed_info.mmio_start,fixed_info.mmio_len);
+ printf("accel: %u (0 = no accel, > 0 see <linux/fb.h>)\n",
+ fixed_info.accel);
+
+ }
+
+ if(getmodes&VAR_INFO) {
+ if(ioctl(fd,FBIOGET_VSCREENINFO,&var_info)<0) {
+ printf("cannot get variable screen info\n");
+ return -1;
+ }
+ printf("variable screen info:\n");
+ printf("resolution: %ux%u, virtual %ux%u\n",
+ var_info.xres,var_info.yres,
+ var_info.xres_virtual,var_info.yres_virtual);
+ printf("bits per pixel: %u\n",var_info.bits_per_pixel);
+ printf("offsets: x=%u y=%u\n",
+ var_info.xoffset,var_info.yoffset);
+ printf("gray scale: %c\n",var_info.grayscale?'y':'n');
+ printf("rgb:\n");
+ printf("red: offset=%u length=%u msb=%c\n",
+ var_info.red.offset,var_info.red.length,
+ var_info.red.msb_right?'r':'l');
+ printf("green: offset=%u length=%u msb=%c\n",
+ var_info.green.offset,var_info.green.length,
+ var_info.green.msb_right?'r':'l');
+ printf("blue: offset=%u length=%u msb=%c\n",
+ var_info.blue.offset,var_info.blue.length,
+ var_info.blue.msb_right?'r':'l');
+ printf("transparency: offset=%u length=%u msb=%c\n",
+ var_info.transp.offset,var_info.transp.length,
+ var_info.transp.msb_right?'r':'l');
+ printf("non standard pixel format: %c\n",
+ var_info.nonstd?'y':'n');
+ // printf("activate:
+ }
+
+ close(fd);
+
+ return 1;
+}
+