initial checkin of fbutil.c and Makefile
[my-code/fbutil.git] / fbutil.c
1 /*
2  * fbutil.c -- get/set framebuffer values
3  *
4  * hackbard@hackdaworld.dyndns.org
5  *
6  */
7
8 #include <stdio.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <sys/ioctl.h>
12 #include <fcntl.h>
13 #include <unistd.h>
14 #include <string.h>
15
16 #include <linux/fb.h>
17
18 #define MAXDEV 32
19 #define DEVICE "/dev/fb/0"
20
21 #define FIXED_INFO (1<<0)
22 #define VAR_INFO (1<<1)
23
24 int usage() {
25         printf("usage:\n");
26         printf("-d \t specify device (default %s)\n",DEVICE);
27         printf("-f \t print out fixed framebuffer info\n");
28         printf("-v \t print out variable framebuffer info\n");
29         printf("\n");
30         return 1;
31 }
32
33 int main(int argc,char **argv) {
34
35         int i;
36         int fd;
37         char device[MAXDEV];
38         unsigned char getmodes;
39         unsigned char setmodes;
40
41         /* fb variables */
42         struct fb_fix_screeninfo fixed_info;
43         struct fb_var_screeninfo var_info;
44
45         strcpy(device,DEVICE);
46         getmodes=0;
47         setmodes=0;
48
49         for(i=1;i<argc;i++) {
50                 if(argv[i][0]=='-') {
51                         switch(argv[i][1]) {
52                                 case 'd':
53                                         strncpy(device,argv[++i],MAXDEV-1);
54                                         break;
55                                 case 'f':
56                                         getmodes|=FIXED_INFO;
57                                         break;
58                                 case 'v':
59                                         getmodes|=VAR_INFO;
60                                         break;
61                                 default:
62                                         usage();
63                                         return -1;
64                         }
65                 }
66                 else {
67                         usage();
68                         return -1;
69                 }
70         }
71
72         if((fd=open(device,O_RDWR))<0) {
73                 printf("unable to open %s\n",device);
74                 return -1;
75         }
76
77         if(getmodes&FIXED_INFO) {
78                 if(ioctl(fd,FBIOGET_FSCREENINFO,&fixed_info)<0) {
79                         printf("cannot get fixed screen info\n");
80                         return -1;
81                 }
82                 printf("fixed screen info:\n");
83                 printf("id: %s\n",fixed_info.id);
84                 printf("framebuffer memory: start=0x%x length=%u\n",
85                         fixed_info.smem_start,fixed_info.smem_len);
86                 printf("type: ");
87                 if(fixed_info.type==FB_TYPE_PACKED_PIXELS)
88                         printf("packed pixels\n");
89                 if(fixed_info.type==FB_TYPE_PLANES)
90                         printf("non interleaved planes\n");
91                 if(fixed_info.type==FB_TYPE_INTERLEAVED_PLANES)
92                         printf("interleaved planes\n");
93                 if(fixed_info.type==FB_TYPE_TEXT)
94                         printf("text attributes\n");
95                 if(fixed_info.type==FB_TYPE_VGA_PLANES)
96                         printf("ega/vga planes\n");
97                 printf("visual: ");
98                 if(fixed_info.visual==FB_VISUAL_MONO01)
99                         printf("monochrome 1=black, 0=white\n");
100                 if(fixed_info.visual==FB_VISUAL_MONO10)
101                         printf("monochrome 1=white, 0=black\n");
102                 if(fixed_info.visual==FB_VISUAL_TRUECOLOR)
103                         printf("true color\n");
104                 if(fixed_info.visual==FB_VISUAL_PSEUDOCOLOR)
105                         printf("pseudo color\n");
106                 if(fixed_info.visual==FB_VISUAL_DIRECTCOLOR)
107                         printf("direct color\n");
108                 if(fixed_info.visual==FB_VISUAL_STATIC_PSEUDOCOLOR)
109                         printf("direct pseudo color\n");
110                 printf("hardware panning x/y: %c/%c\n",
111                         fixed_info.xpanstep?'y':'n',
112                         fixed_info.ypanstep?'y':'n');
113                 printf("hardware y wrap: %c\n",fixed_info.ywrapstep?'y':'n');
114                 printf("line length: %u bytes\n",fixed_info.line_length);
115                 printf("mapped memory: start=0x%0x length=%u\n",
116                         fixed_info.mmio_start,fixed_info.mmio_len);
117                 printf("accel: %u (0 = no accel, > 0 see <linux/fb.h>)\n",
118                         fixed_info.accel);
119
120         }
121
122         if(getmodes&VAR_INFO) {
123                 if(ioctl(fd,FBIOGET_VSCREENINFO,&var_info)<0) {
124                         printf("cannot get variable screen info\n");
125                         return -1;
126                 }
127                 printf("variable screen info:\n");
128                 printf("resolution: %ux%u, virtual %ux%u\n",
129                         var_info.xres,var_info.yres,
130                         var_info.xres_virtual,var_info.yres_virtual);
131                 printf("bits per pixel: %u\n",var_info.bits_per_pixel);
132                 printf("offsets: x=%u y=%u\n",
133                         var_info.xoffset,var_info.yoffset);
134                 printf("gray scale: %c\n",var_info.grayscale?'y':'n');
135                 printf("rgb:\n");
136                 printf("red: offset=%u length=%u msb=%c\n",
137                         var_info.red.offset,var_info.red.length,
138                         var_info.red.msb_right?'r':'l');
139                 printf("green: offset=%u length=%u msb=%c\n",
140                         var_info.green.offset,var_info.green.length,
141                         var_info.green.msb_right?'r':'l');
142                 printf("blue: offset=%u length=%u msb=%c\n",
143                         var_info.blue.offset,var_info.blue.length,
144                         var_info.blue.msb_right?'r':'l');
145                 printf("transparency: offset=%u length=%u msb=%c\n",
146                         var_info.transp.offset,var_info.transp.length,
147                         var_info.transp.msb_right?'r':'l');
148                 printf("non standard pixel format: %c\n",
149                         var_info.nonstd?'y':'n');
150                 // printf("activate:
151         }
152
153         close(fd);
154
155         return 1;
156 }
157