annotate TVout/matroxset/matroxset.c @ 2876:12a0be665dfd

m3jpg support - ignore error
author arpi
date Tue, 13 Nov 2001 20:39:27 +0000
parents 3b5f5d1c5041
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 #include <sys/types.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 #include <unistd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 #include <sys/ioctl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 #include <errno.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 #include <fcntl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 #include "fb.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 #include "matroxfb.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 static int help(void) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 fprintf(stderr, "usage: matroxset [-f fbdev] [-o output] [-m] [value]\n"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 "\n"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 "where -f fbdev is fbdev device (default /dev/fb1)\n"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 " -o output is output number to investigate (0=primary, 1=secondary=default)\n"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 " -m says that CRTC->output mapping should be changed/retrieved\n"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 " -p print information about blanking\n"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 " value if present, value is set, if missing, value is retrieved\n"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 "\n"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 "For output mode, 128 means monitor, 1 = PAL TV, 2 = NTSC TV\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 return 98;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 int main(int argc, char* argv[]) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 char* fb = "/dev/fb1";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 int fd;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 struct matroxioc_output_mode mom;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 struct fb_vblank vbl;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 int rtn;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 int output = MATROXFB_OUTPUT_SECONDARY;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 int o_present = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 int m_present = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 int p_present = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 int act;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 u_int32_t conns;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 while ((rtn = getopt(argc, argv, "o:f:mhp")) != -1) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 switch (rtn) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 case 'o':
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 output = strtoul(optarg, NULL, 0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 o_present = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 case 'm':
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 m_present = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 case 'f':
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 fb = optarg;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 case 'p':
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 p_present = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 case 'h':
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 return help();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 default:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 fprintf(stderr, "Bad commandline\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 return 99;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 act = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 if (p_present) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 if (m_present || o_present) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 fprintf(stderr, "You cannot use -p together with -m or -o\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 return 95;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 act = 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 } else if (optind >= argc) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 if (m_present) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 if (o_present) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 fprintf(stderr, "You cannot use -m and -o together\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 return 96;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 act = 2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 mom.output = output;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 mom.mode = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 if (m_present) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 conns = strtoul(argv[optind], NULL, 0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 act = 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 mom.output = output;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 mom.mode = strtoul(argv[optind], NULL, 0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 act = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 fd = open(fb, O_RDWR);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 if (fd == -1) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 fprintf(stderr, "Cannot open %s: %s\n", fb, strerror(errno));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 return 122;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 switch (act) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 case 0:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 rtn = ioctl(fd, MATROXFB_GET_OUTPUT_MODE, &mom);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 if (rtn)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 printf("Output mode is %u\n", mom.mode);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 case 1:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 rtn = ioctl(fd, MATROXFB_SET_OUTPUT_MODE, &mom);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 case 2:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 rtn = ioctl(fd, MATROXFB_GET_OUTPUT_CONNECTION, &conns);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 if (rtn)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 printf("This framebuffer is connected to outputs %08X\n", conns);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 case 3:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 rtn = ioctl(fd, MATROXFB_SET_OUTPUT_CONNECTION, &conns);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 case 4:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 { int i; for (i = 0; i < 1000000; i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 rtn = ioctl(fd, FBIOGET_VBLANK, &vbl);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 if (rtn)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 }}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 rtn = ioctl(fd, FBIOGET_VBLANK, &vbl);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 if (rtn)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 printf("VBlank flags: %08X\n", vbl.flags);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 printf(" Symbolic: ");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 static const struct { u_int32_t mask; const char* msg; } *ptr, vals[] = {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 { FB_VBLANK_HAVE_VBLANK, "vblank" },
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 { FB_VBLANK_HAVE_HBLANK, "hblank" },
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 { FB_VBLANK_HAVE_COUNT, "field no." },
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 { FB_VBLANK_HAVE_VCOUNT, "line no." },
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 { FB_VBLANK_HAVE_HCOUNT, "column no." },
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 { FB_VBLANK_VBLANKING, "vblanking" },
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 { FB_VBLANK_HBLANKING, "hblanking" },
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 { 0, NULL }};
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 int ap = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 for (ptr = vals; ptr->msg; ptr++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 if (vbl.flags & ptr->mask) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 if (ap) printf(", ");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 printf(ptr->msg);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 ap = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 if (!ap)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 printf("none");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 printf("\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 printf("Field count: %12u\n", vbl.count);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 printf("Vertical line: %12u\n", vbl.vcount);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 printf("Horizontal column: %12u\n", vbl.hcount);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 default:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 rtn = -1; errno = EINVAL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 if (rtn) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 fprintf(stderr, "ioctl failed: %s\n", strerror(errno));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 close(fd);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162