• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Driver for the Conexant CX25821 PCIe bridge
3  *
4  *  Copyright (C) 2009 Conexant Systems Inc.
5  *  Authors  <hiep.huynh@conexant.com>, <shu.lin@conexant.com>
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 #define VID_UPSTREAM_SRAM_CHANNEL_I     9
31 #define VID_UPSTREAM_SRAM_CHANNEL_J     10
32 #define AUDIO_UPSTREAM_SRAM_CHANNEL_B   11
33 #define PIXEL_FRMT_422                  4
34 #define PIXEL_FRMT_411                  5
35 #define UPSTREAM_START_VIDEO            700
36 #define UPSTREAM_STOP_VIDEO             701
37 #define UPSTREAM_START_AUDIO            702
38 #define UPSTREAM_STOP_AUDIO             703
39 #define UPSTREAM_DUMP_REGISTERS         702
40 
41 
42 typedef struct {
43     char *input_filename;
44     char *vid_stdname;
45     int pixel_format;
46     int channel_select;
47     int command;
48 } upstream_user_struct;
49 
print_video_usage()50 void print_video_usage()
51 {
52     printf("\n************************************************************************ \n");
53     printf("Video Sample Usage: ./upstream_app d 1 v /root/filename.yuv NTSC 422 1 start \n");
54     printf("Argument 0: ./upstream_app \n");
55     printf("Argument 1: Device ID (1 and above)\n");
56     printf("Argument 2: v for video\n");
57     printf("Argument 3: input file name \n");
58     printf("Argument 4: Video Standard \n");
59     printf("Argument 5: Pixel Format (Y422 or Y411) \n");
60     printf("Argument 6: Upstream Channel Number\n");
61     printf("Argument 7: start/stop command\n\n");
62 }
63 
print_audio_usage()64 void print_audio_usage()
65 {
66     printf("\n************************************************************************ \n");
67     printf("Audio Sample Usage: ./upstream_app d 1 a /root/audio.wav start\n");
68     printf("Argument 0: ./upstream_app \n");
69     printf("Argument 1: Device ID (1 and above)\n");
70     printf("Argument 2: a for audio \n");
71     printf("Argument 3: input file name \n");
72     printf("Argument 4: start/stop command\n\n");
73 }
74 
main(int argc,char ** argv)75 int main(int argc, char** argv)
76 {
77     int fp;
78     unsigned int cmd= 0 ;
79     int i = 1;
80     int mode = 0;
81     int pixel_format = 422;
82     int channel_select = 1;
83     int device_id = 0, video_id = 11;
84     char * temp2;
85     char *video_device_str[4][2] = {{"/dev/video8", "/dev/video9"}, {"/dev/video20", "/dev/video21"},
86                                     {"/dev/video32", "/dev/video33"}, {"/dev/video44", "/dev/video45"} };
87     char *audio_device_str[4] = {"/dev/video10", "/dev/video22", "/dev/video34", "/dev/video46"};
88     char mode_temp = 'v';
89 
90     if(argc < 2 || (tolower(*(argv[1])) != 'd') )
91     {
92         print_video_usage();
93         print_audio_usage();
94         return -EINVAL;
95     }
96     else
97     {
98         sscanf(argv[2], "%d", &device_id );
99         i += 2;
100 
101         if( device_id <= 0 || device_id > 4 )
102         {
103             print_video_usage();
104             print_audio_usage();
105             return -EINVAL;
106         }
107 
108         temp2 = argv[i];
109         mode_temp = tolower(temp2[0]);
110         switch(mode_temp)
111         {
112             case 'v':
113                 if( argc < 9 )
114                 {
115                     print_video_usage();
116                     return -EINVAL;
117                 }
118                 break;
119 
120             case 'a':
121                 if( argc < 6 )
122                 {
123                     print_audio_usage();
124                     return -EINVAL;
125                 }
126                 break;
127         }
128     }
129 
130     if( mode_temp == 'v' || mode_temp == 'a' )
131     {
132         FILE* file_ptr = fopen(argv[4], "r");
133 
134         if( !file_ptr )
135         {
136             printf("\nERROR: %s file does NOT exist!!! \n\n", argv[4]);
137             return -EINVAL;
138         }
139 
140         fclose(file_ptr);
141     }
142     else
143     {
144         print_video_usage();
145         print_audio_usage();
146         return -EINVAL;
147     }
148 
149     printf("\n*************************************************************** \n");
150 
151     switch(mode_temp)
152     {
153         case 'v':
154             {
155                 char * temp = argv[5];
156                 upstream_user_struct arguments;
157                 arguments.input_filename = argv[4];
158                 arguments.vid_stdname    = (tolower(temp[0]) == 'p') ? "PAL" : "NTSC";
159                 sscanf(argv[6], "%d", &pixel_format);
160                 sscanf(argv[7], "%d", &channel_select);
161                 arguments.pixel_format   = (pixel_format == 422) ? PIXEL_FRMT_422 : PIXEL_FRMT_411;
162                 arguments.channel_select = (channel_select==1) ? VID_UPSTREAM_SRAM_CHANNEL_I : VID_UPSTREAM_SRAM_CHANNEL_J;
163                 temp = argv[8];
164                 arguments.command        = (strcasecmp("STOP", temp) == 0) ? UPSTREAM_STOP_VIDEO : UPSTREAM_START_VIDEO;
165 
166 
167                 if( channel_select >= 1 && channel_select <= 2 )
168                 {
169                     if((fp = open(video_device_str[device_id-1][channel_select-1], O_RDWR)) == -1)
170                     {
171                         printf("Error: cannot open device file %s !\n", video_device_str[device_id-1][channel_select-1]);
172                         return -EINVAL;
173                     }
174 
175                     printf("Device %s open for IOCTL successfully!\n", video_device_str[device_id-1][channel_select-1]);
176                     printf("UPSTREAM parameters: filename = %s, channel_select(I=1) = %d \n", arguments.input_filename, channel_select);
177 
178 
179                     if((ioctl(fp, arguments.command, (char *) &arguments)) == -1)
180                     {
181                         printf("Error: ioctl FAILED!\n");
182                     }
183                 }
184             }
185             break;
186 
187         case 'a':
188             {
189                 char * temp = argv[5];
190                 upstream_user_struct arguments;
191                 arguments.input_filename = argv[4];
192                 arguments.vid_stdname    = "NTSC";
193                 arguments.pixel_format   = PIXEL_FRMT_422;
194                 arguments.channel_select = AUDIO_UPSTREAM_SRAM_CHANNEL_B;
195                 arguments.command    = (strcasecmp("STOP", temp) == 0) ? UPSTREAM_STOP_AUDIO : UPSTREAM_START_AUDIO;
196 
197 
198                 if((fp = open(audio_device_str[device_id-1], O_RDWR)) == -1)
199                 {
200                     printf("Error: cannot open device file %s !\n", audio_device_str[device_id-1]);
201                     return -EINVAL;
202                 }
203 
204                 printf("Device %s open for IOCTL successfully!\n", audio_device_str[device_id-1]);
205                 printf("UPSTREAM parameters: filename = %s, audio channel = %d \n", arguments.input_filename, arguments.channel_select);
206 
207 
208                 if((ioctl(fp, arguments.command, (char *) &arguments)) == -1)
209                     printf("Error: ioctl FAILED!\n");
210             }
211             break;
212 
213         default:
214             printf("ERROR: INVALID ioctl command!\n");
215             return -EINVAL;
216     }
217 
218     printf("*************************************************************** \n\n");
219     close(fp);
220     return 0;
221 }
222