Debian Codegraph @

contrib/parsers/cx25821/medusaReadWrite.c

raw
1 /*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <[email protected]>, <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <fcntl.h>
26 #include <string.h>
27 #include <linux/errno.h>
28 #include <linux/ioctl.h>
29
30
31 #define MEDUSA_READ 910
32 #define MEDUSA_WRITE 911
33
34 typedef struct{
35 char *vid_stdname;
36 int pixel_format;
37 int cif_resolution_enable;
38 int cif_width;
39 int decoder_select;
40 int command;
41 int reg_address;
42 int reg_data;
43 }downstream_user_struct;
44
45
46 void print_usage()
47 {
48 printf("\n*********************************\n");
49 printf("Sample Usage: ./medusa d 1 r 0x01\n");
50 printf("Sample Usage: ./medusa d 1 w 0x0 0x2\n");
51 printf(" d device_id Device ID (1 and above) for MultiCard\n");
52 printf(" r Read Medusa register\n");
53 printf(" w Write Medusa register\n");
54 }
55
56 int main(int argc, char** argv)
57 {
58 unsigned int cmd= 0 ;
59 int fp;
60 int i = 1, j = 0, k = 0, len = 0;
61 int mode = 0;
62
63 int register_addr = 0;
64 int write_value = 0;
65
66 int device_id = 0, video_id = 11;
67 char * temp2;
68 char *device_str[4] = {"/dev/video11", "/dev/video23", "/dev/video35", "/dev/video47"};
69
70 char mode_temp = 's';
71 char *param_temp;
72
73
74 if(argc < 5 || (tolower(*(argv[1])) != 'd') )
75 {
76 print_usage();
77 return -EINVAL;
78 }
79
80 sscanf(argv[2], "%d", &device_id );
81 i += 2;
82
83 if( device_id <= 0 || device_id > 4 )
84 {
85 print_usage();
86 return -EINVAL;
87 }
88
89 printf("\n********************************* \n");
90
91 if((fp = open(device_str[device_id-1], O_RDWR)) == -1)
92 {
93 printf("Error: cannot open device file %s !\n", device_str[device_id-1]);
94 return -EINVAL;
95 }
96
97 printf("Device %s open for IOCTL successfully!\n", device_str[device_id-1]);
98
99
100 for( ; i < argc; i++)
101 {
102 temp2 = argv[i];
103 mode_temp = tolower(temp2[0]);
104 param_temp = argv[i+1];
105
106
107 switch(mode_temp)
108 {
109 case 'r':
110 {
111 downstream_user_struct arguments;
112
113 sscanf(param_temp, "%x", &register_addr );
114
115 arguments.reg_address = register_addr;
116 arguments.command = MEDUSA_READ;
117
118 printf("Read parameters: read register = 0x%x, command = %d \n", arguments.reg_address, arguments.command);
119
120 if((ioctl(fp, arguments.command, (char *) &arguments)) == -1)
121 printf("Error: ioctl FAILED!\n");
122 printf("Reg 0x%x = 0x%x\n", arguments.reg_address, arguments.reg_data);
123 }
124 break;
125
126 case 'w':
127 {
128 downstream_user_struct arguments;
129
130 sscanf(param_temp, "%x", &register_addr );
131 sscanf(argv[i+2], "%x", &write_value );
132 i++;
133
134 arguments.command = MEDUSA_WRITE;
135 arguments.reg_address = register_addr;
136 arguments.reg_data = write_value;
137
138 printf("Write parameters: write register = 0x%x, write_value = 0x%x, command = %d \n", arguments.reg_address, arguments.reg_data, arguments.command);
139
140 if((ioctl(fp, arguments.command, (char *) &arguments)) == -1)
141 printf("Error: ioctl FAILED!\n");
142 }
143 break;
144
145 default:
146 printf("Please verify the options are correct!\n");
147 break;
148 }
149
150 i++;
151 }
152
153
154 printf("********************************* \n\n");
155 close(fp);
156 return 0;
157 }
158