Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / media / video / videodev.c
blob40e228ff2320c0ed5c3ba88411825e237f379965
1 /*
2 * Video capture interface for Linux version 2
4 * A generic video device interface for the LINUX operating system
5 * using a set of device structures/vectors for low level operations.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * Authors: Alan Cox, <alan@redhat.com> (version 1)
13 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
15 * Fixes: 20000516 Claudio Matsuoka <claudio@conectiva.com>
16 * - Added procfs support
19 #define dbgarg(cmd, fmt, arg...) \
20 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
21 printk (KERN_DEBUG "%s: ", vfd->name); \
22 v4l_printk_ioctl(cmd); \
23 printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg); \
26 #define dbgarg2(fmt, arg...) \
27 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
28 printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg);
30 #include <linux/module.h>
31 #include <linux/types.h>
32 #include <linux/kernel.h>
33 #include <linux/mm.h>
34 #include <linux/string.h>
35 #include <linux/errno.h>
36 #include <linux/init.h>
37 #include <linux/kmod.h>
38 #include <linux/slab.h>
39 #include <asm/uaccess.h>
40 #include <asm/system.h>
42 #define __OLD_VIDIOC_ /* To allow fixing old calls*/
43 #include <linux/videodev2.h>
45 #ifdef CONFIG_VIDEO_V4L1
46 #include <linux/videodev.h>
47 #endif
48 #include <media/v4l2-common.h>
49 <<<<<<< HEAD:drivers/media/video/videodev.c
50 =======
51 #include <linux/video_decoder.h>
52 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
54 #define VIDEO_NUM_DEVICES 256
55 #define VIDEO_NAME "video4linux"
57 <<<<<<< HEAD:drivers/media/video/videodev.c
58 =======
59 /* video4linux standard ID conversion to standard name
61 char *v4l2_norm_to_name(v4l2_std_id id)
63 char *name;
64 u32 myid = id;
66 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
67 64 bit comparations. So, on that architecture, with some gcc
68 variants, compilation fails. Currently, the max value is 30bit wide.
70 BUG_ON(myid != id);
72 switch (myid) {
73 case V4L2_STD_PAL:
74 name = "PAL";
75 break;
76 case V4L2_STD_PAL_BG:
77 name = "PAL-BG";
78 break;
79 case V4L2_STD_PAL_DK:
80 name = "PAL-DK";
81 break;
82 case V4L2_STD_PAL_B:
83 name = "PAL-B";
84 break;
85 case V4L2_STD_PAL_B1:
86 name = "PAL-B1";
87 break;
88 case V4L2_STD_PAL_G:
89 name = "PAL-G";
90 break;
91 case V4L2_STD_PAL_H:
92 name = "PAL-H";
93 break;
94 case V4L2_STD_PAL_I:
95 name = "PAL-I";
96 break;
97 case V4L2_STD_PAL_D:
98 name = "PAL-D";
99 break;
100 case V4L2_STD_PAL_D1:
101 name = "PAL-D1";
102 break;
103 case V4L2_STD_PAL_K:
104 name = "PAL-K";
105 break;
106 case V4L2_STD_PAL_M:
107 name = "PAL-M";
108 break;
109 case V4L2_STD_PAL_N:
110 name = "PAL-N";
111 break;
112 case V4L2_STD_PAL_Nc:
113 name = "PAL-Nc";
114 break;
115 case V4L2_STD_PAL_60:
116 name = "PAL-60";
117 break;
118 case V4L2_STD_NTSC:
119 name = "NTSC";
120 break;
121 case V4L2_STD_NTSC_M:
122 name = "NTSC-M";
123 break;
124 case V4L2_STD_NTSC_M_JP:
125 name = "NTSC-M-JP";
126 break;
127 case V4L2_STD_NTSC_443:
128 name = "NTSC-443";
129 break;
130 case V4L2_STD_NTSC_M_KR:
131 name = "NTSC-M-KR";
132 break;
133 case V4L2_STD_SECAM:
134 name = "SECAM";
135 break;
136 case V4L2_STD_SECAM_DK:
137 name = "SECAM-DK";
138 break;
139 case V4L2_STD_SECAM_B:
140 name = "SECAM-B";
141 break;
142 case V4L2_STD_SECAM_D:
143 name = "SECAM-D";
144 break;
145 case V4L2_STD_SECAM_G:
146 name = "SECAM-G";
147 break;
148 case V4L2_STD_SECAM_H:
149 name = "SECAM-H";
150 break;
151 case V4L2_STD_SECAM_K:
152 name = "SECAM-K";
153 break;
154 case V4L2_STD_SECAM_K1:
155 name = "SECAM-K1";
156 break;
157 case V4L2_STD_SECAM_L:
158 name = "SECAM-L";
159 break;
160 case V4L2_STD_SECAM_LC:
161 name = "SECAM-LC";
162 break;
163 default:
164 name = "Unknown";
165 break;
168 return name;
170 EXPORT_SYMBOL(v4l2_norm_to_name);
172 /* Fill in the fields of a v4l2_standard structure according to the
173 'id' and 'transmission' parameters. Returns negative on error. */
174 int v4l2_video_std_construct(struct v4l2_standard *vs,
175 int id, char *name)
177 u32 index = vs->index;
179 memset(vs, 0, sizeof(struct v4l2_standard));
180 vs->index = index;
181 vs->id = id;
182 if (id & V4L2_STD_525_60) {
183 vs->frameperiod.numerator = 1001;
184 vs->frameperiod.denominator = 30000;
185 vs->framelines = 525;
186 } else {
187 vs->frameperiod.numerator = 1;
188 vs->frameperiod.denominator = 25;
189 vs->framelines = 625;
191 strlcpy(vs->name, name, sizeof(vs->name));
192 return 0;
194 EXPORT_SYMBOL(v4l2_video_std_construct);
196 /* ----------------------------------------------------------------- */
197 /* some arrays for pretty-printing debug messages of enum types */
199 char *v4l2_field_names[] = {
200 [V4L2_FIELD_ANY] = "any",
201 [V4L2_FIELD_NONE] = "none",
202 [V4L2_FIELD_TOP] = "top",
203 [V4L2_FIELD_BOTTOM] = "bottom",
204 [V4L2_FIELD_INTERLACED] = "interlaced",
205 [V4L2_FIELD_SEQ_TB] = "seq-tb",
206 [V4L2_FIELD_SEQ_BT] = "seq-bt",
207 [V4L2_FIELD_ALTERNATE] = "alternate",
208 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
209 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
211 EXPORT_SYMBOL(v4l2_field_names);
213 char *v4l2_type_names[] = {
214 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
215 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
216 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
217 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
218 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
219 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
220 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
221 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "video-out-over",
223 EXPORT_SYMBOL(v4l2_type_names);
225 static char *v4l2_memory_names[] = {
226 [V4L2_MEMORY_MMAP] = "mmap",
227 [V4L2_MEMORY_USERPTR] = "userptr",
228 [V4L2_MEMORY_OVERLAY] = "overlay",
231 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
232 arr[a] : "unknown")
234 /* ------------------------------------------------------------------ */
235 /* debug help functions */
237 #ifdef CONFIG_VIDEO_V4L1_COMPAT
238 static const char *v4l1_ioctls[] = {
239 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
240 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
241 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
242 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
243 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
244 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
245 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
246 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
247 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
248 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
249 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
250 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
251 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
252 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
253 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
254 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
255 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
256 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
257 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
258 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
259 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
260 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
261 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
262 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
263 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
264 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
265 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
266 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
267 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
269 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
270 #endif
272 static const char *v4l2_ioctls[] = {
273 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
274 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
275 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
276 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
277 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
278 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
279 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
280 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
281 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
282 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
283 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
284 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
285 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
286 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
287 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
288 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
289 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
290 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
291 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
292 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
293 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
294 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
295 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
296 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
297 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
298 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
299 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
300 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
301 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
302 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
303 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
304 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
305 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
306 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
307 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
308 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
309 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
310 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
311 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
312 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
313 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
314 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
315 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
316 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
317 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
318 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
319 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
320 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
321 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
322 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
323 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
324 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
325 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
326 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
327 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
328 #if 1
329 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
330 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
331 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
332 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
333 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
335 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
336 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
338 [_IOC_NR(VIDIOC_G_CHIP_IDENT)] = "VIDIOC_G_CHIP_IDENT",
339 #endif
341 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
343 static const char *v4l2_int_ioctls[] = {
344 #ifdef CONFIG_VIDEO_V4L1_COMPAT
345 [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES",
346 [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS",
347 [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM",
348 [_IOC_NR(DECODER_SET_INPUT)] = "DECODER_SET_INPUT",
349 [_IOC_NR(DECODER_SET_OUTPUT)] = "DECODER_SET_OUTPUT",
350 [_IOC_NR(DECODER_ENABLE_OUTPUT)] = "DECODER_ENABLE_OUTPUT",
351 [_IOC_NR(DECODER_SET_PICTURE)] = "DECODER_SET_PICTURE",
352 [_IOC_NR(DECODER_SET_GPIO)] = "DECODER_SET_GPIO",
353 [_IOC_NR(DECODER_INIT)] = "DECODER_INIT",
354 [_IOC_NR(DECODER_SET_VBI_BYPASS)] = "DECODER_SET_VBI_BYPASS",
355 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP",
356 #endif
357 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
359 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
360 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
361 [_IOC_NR(TUNER_SET_CONFIG)] = "TUNER_SET_CONFIG",
363 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
364 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
365 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
366 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
367 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
368 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
369 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
370 [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
371 [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
372 [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
373 [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
374 [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING",
375 [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)] = "VIDIOC_INT_S_CRYSTAL_FREQ",
376 [_IOC_NR(VIDIOC_INT_INIT)] = "VIDIOC_INT_INIT",
377 [_IOC_NR(VIDIOC_INT_G_STD_OUTPUT)] = "VIDIOC_INT_G_STD_OUTPUT",
378 [_IOC_NR(VIDIOC_INT_S_STD_OUTPUT)] = "VIDIOC_INT_S_STD_OUTPUT",
380 #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
382 /* Common ioctl debug function. This function can be used by
383 external ioctl messages as well as internal V4L ioctl */
384 void v4l_printk_ioctl(unsigned int cmd)
386 char *dir;
388 switch (_IOC_DIR(cmd)) {
389 case _IOC_NONE: dir = "--"; break;
390 case _IOC_READ: dir = "r-"; break;
391 case _IOC_WRITE: dir = "-w"; break;
392 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
393 default: dir = "*ERR*"; break;
395 switch (_IOC_TYPE(cmd)) {
396 case 'd':
397 printk("v4l2_int ioctl %s, dir=%s (0x%08x)\n",
398 (_IOC_NR(cmd) < V4L2_INT_IOCTLS) ?
399 v4l2_int_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
400 break;
401 #ifdef CONFIG_VIDEO_V4L1_COMPAT
402 case 'v':
403 printk("v4l1 ioctl %s, dir=%s (0x%08x)\n",
404 (_IOC_NR(cmd) < V4L1_IOCTLS) ?
405 v4l1_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
406 break;
407 #endif
408 case 'V':
409 printk("v4l2 ioctl %s, dir=%s (0x%08x)\n",
410 (_IOC_NR(cmd) < V4L2_IOCTLS) ?
411 v4l2_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
412 break;
414 default:
415 printk("unknown ioctl '%c', dir=%s, #%d (0x%08x)\n",
416 _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
419 EXPORT_SYMBOL(v4l_printk_ioctl);
421 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
423 * sysfs stuff
426 static ssize_t show_name(struct device *cd,
427 struct device_attribute *attr, char *buf)
429 struct video_device *vfd = container_of(cd, struct video_device,
430 class_dev);
431 return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
434 struct video_device *video_device_alloc(void)
436 struct video_device *vfd;
438 vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
439 return vfd;
441 <<<<<<< HEAD:drivers/media/video/videodev.c
442 =======
443 EXPORT_SYMBOL(video_device_alloc);
444 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
446 void video_device_release(struct video_device *vfd)
448 kfree(vfd);
450 <<<<<<< HEAD:drivers/media/video/videodev.c
451 =======
452 EXPORT_SYMBOL(video_device_release);
453 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
455 static void video_release(struct device *cd)
457 struct video_device *vfd = container_of(cd, struct video_device,
458 class_dev);
460 #if 1
461 /* needed until all drivers are fixed */
462 if (!vfd->release)
463 return;
464 #endif
465 vfd->release(vfd);
468 static struct device_attribute video_device_attrs[] = {
469 __ATTR(name, S_IRUGO, show_name, NULL),
470 __ATTR_NULL
473 static struct class video_class = {
474 .name = VIDEO_NAME,
475 .dev_attrs = video_device_attrs,
476 .dev_release = video_release,
480 * Active devices
483 static struct video_device *video_device[VIDEO_NUM_DEVICES];
484 static DEFINE_MUTEX(videodev_lock);
486 struct video_device* video_devdata(struct file *file)
488 return video_device[iminor(file->f_path.dentry->d_inode)];
490 <<<<<<< HEAD:drivers/media/video/videodev.c
491 =======
492 EXPORT_SYMBOL(video_devdata);
493 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
496 * Open a video device - FIXME: Obsoleted
498 static int video_open(struct inode *inode, struct file *file)
500 unsigned int minor = iminor(inode);
501 int err = 0;
502 struct video_device *vfl;
503 const struct file_operations *old_fops;
505 if(minor>=VIDEO_NUM_DEVICES)
506 return -ENODEV;
507 mutex_lock(&videodev_lock);
508 vfl=video_device[minor];
509 if(vfl==NULL) {
510 mutex_unlock(&videodev_lock);
511 request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
512 mutex_lock(&videodev_lock);
513 vfl=video_device[minor];
514 if (vfl==NULL) {
515 mutex_unlock(&videodev_lock);
516 return -ENODEV;
519 old_fops = file->f_op;
520 file->f_op = fops_get(vfl->fops);
521 if(file->f_op->open)
522 err = file->f_op->open(inode,file);
523 if (err) {
524 fops_put(file->f_op);
525 file->f_op = fops_get(old_fops);
527 fops_put(old_fops);
528 mutex_unlock(&videodev_lock);
529 return err;
533 * helper function -- handles userspace copying for ioctl arguments
536 #ifdef __OLD_VIDIOC_
537 static unsigned int
538 video_fix_command(unsigned int cmd)
540 switch (cmd) {
541 case VIDIOC_OVERLAY_OLD:
542 cmd = VIDIOC_OVERLAY;
543 break;
544 case VIDIOC_S_PARM_OLD:
545 cmd = VIDIOC_S_PARM;
546 break;
547 case VIDIOC_S_CTRL_OLD:
548 cmd = VIDIOC_S_CTRL;
549 break;
550 case VIDIOC_G_AUDIO_OLD:
551 cmd = VIDIOC_G_AUDIO;
552 break;
553 case VIDIOC_G_AUDOUT_OLD:
554 cmd = VIDIOC_G_AUDOUT;
555 break;
556 case VIDIOC_CROPCAP_OLD:
557 cmd = VIDIOC_CROPCAP;
558 break;
560 return cmd;
562 #endif
565 * Obsolete usercopy function - Should be removed soon
568 video_usercopy(struct inode *inode, struct file *file,
569 unsigned int cmd, unsigned long arg,
570 int (*func)(struct inode *inode, struct file *file,
571 unsigned int cmd, void *arg))
573 char sbuf[128];
574 void *mbuf = NULL;
575 void *parg = NULL;
576 int err = -EINVAL;
577 int is_ext_ctrl;
578 size_t ctrls_size = 0;
579 void __user *user_ptr = NULL;
581 #ifdef __OLD_VIDIOC_
582 cmd = video_fix_command(cmd);
583 #endif
584 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
585 cmd == VIDIOC_TRY_EXT_CTRLS);
587 /* Copy arguments into temp kernel buffer */
588 switch (_IOC_DIR(cmd)) {
589 case _IOC_NONE:
590 parg = NULL;
591 break;
592 case _IOC_READ:
593 case _IOC_WRITE:
594 case (_IOC_WRITE | _IOC_READ):
595 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
596 parg = sbuf;
597 } else {
598 /* too big to allocate from stack */
599 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
600 if (NULL == mbuf)
601 return -ENOMEM;
602 parg = mbuf;
605 err = -EFAULT;
606 if (_IOC_DIR(cmd) & _IOC_WRITE)
607 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
608 goto out;
609 break;
611 if (is_ext_ctrl) {
612 struct v4l2_ext_controls *p = parg;
614 /* In case of an error, tell the caller that it wasn't
615 a specific control that caused it. */
616 p->error_idx = p->count;
617 user_ptr = (void __user *)p->controls;
618 if (p->count) {
619 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
620 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
621 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
622 err = -ENOMEM;
623 if (NULL == mbuf)
624 goto out_ext_ctrl;
625 err = -EFAULT;
626 if (copy_from_user(mbuf, user_ptr, ctrls_size))
627 goto out_ext_ctrl;
628 p->controls = mbuf;
632 /* call driver */
633 err = func(inode, file, cmd, parg);
634 if (err == -ENOIOCTLCMD)
635 err = -EINVAL;
636 if (is_ext_ctrl) {
637 struct v4l2_ext_controls *p = parg;
639 p->controls = (void *)user_ptr;
640 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
641 err = -EFAULT;
642 goto out_ext_ctrl;
644 if (err < 0)
645 goto out;
647 out_ext_ctrl:
648 /* Copy results into user buffer */
649 switch (_IOC_DIR(cmd))
651 case _IOC_READ:
652 case (_IOC_WRITE | _IOC_READ):
653 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
654 err = -EFAULT;
655 break;
658 out:
659 kfree(mbuf);
660 return err;
662 <<<<<<< HEAD:drivers/media/video/videodev.c
663 =======
664 EXPORT_SYMBOL(video_usercopy);
665 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
668 * open/release helper functions -- handle exclusive opens
669 * Should be removed soon
671 int video_exclusive_open(struct inode *inode, struct file *file)
673 struct video_device *vfl = video_devdata(file);
674 int retval = 0;
676 mutex_lock(&vfl->lock);
677 if (vfl->users) {
678 retval = -EBUSY;
679 } else {
680 vfl->users++;
682 mutex_unlock(&vfl->lock);
683 return retval;
685 <<<<<<< HEAD:drivers/media/video/videodev.c
686 =======
687 EXPORT_SYMBOL(video_exclusive_open);
688 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
690 int video_exclusive_release(struct inode *inode, struct file *file)
692 struct video_device *vfl = video_devdata(file);
694 vfl->users--;
695 return 0;
697 <<<<<<< HEAD:drivers/media/video/videodev.c
699 static char *v4l2_memory_names[] = {
700 [V4L2_MEMORY_MMAP] = "mmap",
701 [V4L2_MEMORY_USERPTR] = "userptr",
702 [V4L2_MEMORY_OVERLAY] = "overlay",
706 /* FIXME: Those stuff are replicated also on v4l2-common.c */
707 static char *v4l2_type_names_FIXME[] = {
708 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
709 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
710 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
711 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
712 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
713 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
714 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-capture",
715 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "video-out-over",
716 [V4L2_BUF_TYPE_PRIVATE] = "private",
719 static char *v4l2_field_names_FIXME[] = {
720 [V4L2_FIELD_ANY] = "any",
721 [V4L2_FIELD_NONE] = "none",
722 [V4L2_FIELD_TOP] = "top",
723 [V4L2_FIELD_BOTTOM] = "bottom",
724 [V4L2_FIELD_INTERLACED] = "interlaced",
725 [V4L2_FIELD_SEQ_TB] = "seq-tb",
726 [V4L2_FIELD_SEQ_BT] = "seq-bt",
727 [V4L2_FIELD_ALTERNATE] = "alternate",
728 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
729 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
732 #define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
733 =======
734 EXPORT_SYMBOL(video_exclusive_release);
735 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
737 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
738 struct v4l2_buffer *p)
740 struct v4l2_timecode *tc=&p->timecode;
742 dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
743 "bytesused=%d, flags=0x%08d, "
744 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
745 (p->timestamp.tv_sec/3600),
746 (int)(p->timestamp.tv_sec/60)%60,
747 (int)(p->timestamp.tv_sec%60),
748 p->timestamp.tv_usec,
749 p->index,
750 <<<<<<< HEAD:drivers/media/video/videodev.c
751 prt_names(p->type,v4l2_type_names_FIXME),
752 p->bytesused,p->flags,
753 p->field,p->sequence,
754 prt_names(p->memory,v4l2_memory_names),
755 =======
756 prt_names(p->type, v4l2_type_names),
757 p->bytesused, p->flags,
758 p->field, p->sequence,
759 prt_names(p->memory, v4l2_memory_names),
760 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
761 p->m.userptr, p->length);
762 dbgarg2 ("timecode= %02d:%02d:%02d type=%d, "
763 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
764 tc->hours,tc->minutes,tc->seconds,
765 tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
768 static inline void dbgrect(struct video_device *vfd, char *s,
769 struct v4l2_rect *r)
771 dbgarg2 ("%sRect start at %dx%d, size= %dx%d\n", s, r->left, r->top,
772 r->width, r->height);
775 static inline void v4l_print_pix_fmt (struct video_device *vfd,
776 struct v4l2_pix_format *fmt)
778 dbgarg2 ("width=%d, height=%d, format=%c%c%c%c, field=%s, "
779 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
780 fmt->width,fmt->height,
781 (fmt->pixelformat & 0xff),
782 (fmt->pixelformat >> 8) & 0xff,
783 (fmt->pixelformat >> 16) & 0xff,
784 (fmt->pixelformat >> 24) & 0xff,
785 <<<<<<< HEAD:drivers/media/video/videodev.c
786 prt_names(fmt->field,v4l2_field_names_FIXME),
787 fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
788 =======
789 prt_names(fmt->field, v4l2_field_names),
790 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
791 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
795 static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
797 switch (type) {
798 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
799 if (vfd->vidioc_try_fmt_cap)
800 return (0);
801 break;
802 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
803 if (vfd->vidioc_try_fmt_overlay)
804 return (0);
805 break;
806 case V4L2_BUF_TYPE_VBI_CAPTURE:
807 if (vfd->vidioc_try_fmt_vbi)
808 return (0);
809 break;
810 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
811 if (vfd->vidioc_try_fmt_vbi_output)
812 return (0);
813 break;
814 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
815 if (vfd->vidioc_try_fmt_vbi_capture)
816 return (0);
817 break;
818 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
819 if (vfd->vidioc_try_fmt_video_output)
820 return (0);
821 break;
822 case V4L2_BUF_TYPE_VBI_OUTPUT:
823 if (vfd->vidioc_try_fmt_vbi_output)
824 return (0);
825 break;
826 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
827 if (vfd->vidioc_try_fmt_output_overlay)
828 return (0);
829 break;
830 case V4L2_BUF_TYPE_PRIVATE:
831 if (vfd->vidioc_try_fmt_type_private)
832 return (0);
833 break;
835 return (-EINVAL);
838 static int __video_do_ioctl(struct inode *inode, struct file *file,
839 unsigned int cmd, void *arg)
841 struct video_device *vfd = video_devdata(file);
842 void *fh = file->private_data;
843 int ret = -EINVAL;
845 if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
846 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
847 v4l_print_ioctl(vfd->name, cmd);
850 #ifdef CONFIG_VIDEO_V4L1_COMPAT
851 /***********************************************************
852 Handles calls to the obsoleted V4L1 API
853 Due to the nature of VIDIOCGMBUF, each driver that supports
854 V4L1 should implement its own handler for this ioctl.
855 ***********************************************************/
857 /* --- streaming capture ------------------------------------- */
858 if (cmd == VIDIOCGMBUF) {
859 struct video_mbuf *p=arg;
861 memset(p, 0, sizeof(*p));
863 if (!vfd->vidiocgmbuf)
864 return ret;
865 ret=vfd->vidiocgmbuf(file, fh, p);
866 if (!ret)
867 dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
868 p->size, p->frames,
869 (unsigned long)p->offsets);
870 return ret;
873 /********************************************************
874 All other V4L1 calls are handled by v4l1_compat module.
875 Those calls will be translated into V4L2 calls, and
876 __video_do_ioctl will be called again, with one or more
877 V4L2 ioctls.
878 ********************************************************/
879 if (_IOC_TYPE(cmd)=='v')
880 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
881 __video_do_ioctl);
882 #endif
884 switch(cmd) {
885 /* --- capabilities ------------------------------------------ */
886 case VIDIOC_QUERYCAP:
888 struct v4l2_capability *cap = (struct v4l2_capability*)arg;
889 memset(cap, 0, sizeof(*cap));
891 if (!vfd->vidioc_querycap)
892 break;
894 ret=vfd->vidioc_querycap(file, fh, cap);
895 if (!ret)
896 dbgarg (cmd, "driver=%s, card=%s, bus=%s, "
897 "version=0x%08x, "
898 "capabilities=0x%08x\n",
899 cap->driver,cap->card,cap->bus_info,
900 cap->version,
901 cap->capabilities);
902 break;
905 /* --- priority ------------------------------------------ */
906 case VIDIOC_G_PRIORITY:
908 enum v4l2_priority *p=arg;
910 if (!vfd->vidioc_g_priority)
911 break;
912 ret=vfd->vidioc_g_priority(file, fh, p);
913 if (!ret)
914 dbgarg(cmd, "priority is %d\n", *p);
915 break;
917 case VIDIOC_S_PRIORITY:
919 enum v4l2_priority *p=arg;
921 if (!vfd->vidioc_s_priority)
922 break;
923 dbgarg(cmd, "setting priority to %d\n", *p);
924 ret=vfd->vidioc_s_priority(file, fh, *p);
925 break;
928 /* --- capture ioctls ---------------------------------------- */
929 case VIDIOC_ENUM_FMT:
931 struct v4l2_fmtdesc *f = arg;
932 enum v4l2_buf_type type;
933 unsigned int index;
935 index = f->index;
936 type = f->type;
937 memset(f,0,sizeof(*f));
938 f->index = index;
939 f->type = type;
941 switch (type) {
942 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
943 if (vfd->vidioc_enum_fmt_cap)
944 ret=vfd->vidioc_enum_fmt_cap(file, fh, f);
945 break;
946 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
947 if (vfd->vidioc_enum_fmt_overlay)
948 ret=vfd->vidioc_enum_fmt_overlay(file, fh, f);
949 break;
950 case V4L2_BUF_TYPE_VBI_CAPTURE:
951 if (vfd->vidioc_enum_fmt_vbi)
952 ret=vfd->vidioc_enum_fmt_vbi(file, fh, f);
953 break;
954 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
955 if (vfd->vidioc_enum_fmt_vbi_output)
956 ret=vfd->vidioc_enum_fmt_vbi_output(file,
957 fh, f);
958 break;
959 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
960 if (vfd->vidioc_enum_fmt_vbi_capture)
961 ret=vfd->vidioc_enum_fmt_vbi_capture(file,
962 fh, f);
963 break;
964 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
965 if (vfd->vidioc_enum_fmt_video_output)
966 ret=vfd->vidioc_enum_fmt_video_output(file,
967 fh, f);
968 break;
969 case V4L2_BUF_TYPE_VBI_OUTPUT:
970 if (vfd->vidioc_enum_fmt_vbi_output)
971 ret=vfd->vidioc_enum_fmt_vbi_output(file,
972 fh, f);
973 break;
974 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
975 if (vfd->vidioc_enum_fmt_output_overlay)
976 ret=vfd->vidioc_enum_fmt_output_overlay(file, fh, f);
977 break;
978 case V4L2_BUF_TYPE_PRIVATE:
979 if (vfd->vidioc_enum_fmt_type_private)
980 ret=vfd->vidioc_enum_fmt_type_private(file,
981 fh, f);
982 break;
984 if (!ret)
985 dbgarg (cmd, "index=%d, type=%d, flags=%d, "
986 "pixelformat=%c%c%c%c, description='%s'\n",
987 f->index, f->type, f->flags,
988 (f->pixelformat & 0xff),
989 (f->pixelformat >> 8) & 0xff,
990 (f->pixelformat >> 16) & 0xff,
991 (f->pixelformat >> 24) & 0xff,
992 f->description);
993 break;
995 case VIDIOC_G_FMT:
997 struct v4l2_format *f = (struct v4l2_format *)arg;
998 enum v4l2_buf_type type=f->type;
1000 memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
1001 f->type=type;
1003 /* FIXME: Should be one dump per type */
1004 dbgarg (cmd, "type=%s\n", prt_names(type,
1005 <<<<<<< HEAD:drivers/media/video/videodev.c
1006 v4l2_type_names_FIXME));
1007 =======
1008 v4l2_type_names));
1009 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
1011 switch (type) {
1012 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1013 if (vfd->vidioc_g_fmt_cap)
1014 ret=vfd->vidioc_g_fmt_cap(file, fh, f);
1015 if (!ret)
1016 v4l_print_pix_fmt(vfd,&f->fmt.pix);
1017 break;
1018 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1019 if (vfd->vidioc_g_fmt_overlay)
1020 ret=vfd->vidioc_g_fmt_overlay(file, fh, f);
1021 break;
1022 case V4L2_BUF_TYPE_VBI_CAPTURE:
1023 if (vfd->vidioc_g_fmt_vbi)
1024 ret=vfd->vidioc_g_fmt_vbi(file, fh, f);
1025 break;
1026 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1027 if (vfd->vidioc_g_fmt_vbi_output)
1028 ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
1029 break;
1030 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1031 if (vfd->vidioc_g_fmt_vbi_capture)
1032 ret=vfd->vidioc_g_fmt_vbi_capture(file, fh, f);
1033 break;
1034 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1035 if (vfd->vidioc_g_fmt_video_output)
1036 ret=vfd->vidioc_g_fmt_video_output(file,
1037 fh, f);
1038 break;
1039 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1040 if (vfd->vidioc_g_fmt_output_overlay)
1041 ret=vfd->vidioc_g_fmt_output_overlay(file, fh, f);
1042 break;
1043 case V4L2_BUF_TYPE_VBI_OUTPUT:
1044 if (vfd->vidioc_g_fmt_vbi_output)
1045 ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
1046 break;
1047 case V4L2_BUF_TYPE_PRIVATE:
1048 if (vfd->vidioc_g_fmt_type_private)
1049 ret=vfd->vidioc_g_fmt_type_private(file,
1050 fh, f);
1051 break;
1054 break;
1056 case VIDIOC_S_FMT:
1058 struct v4l2_format *f = (struct v4l2_format *)arg;
1060 /* FIXME: Should be one dump per type */
1061 dbgarg (cmd, "type=%s\n", prt_names(f->type,
1062 <<<<<<< HEAD:drivers/media/video/videodev.c
1063 v4l2_type_names_FIXME));
1064 =======
1065 v4l2_type_names));
1066 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
1068 switch (f->type) {
1069 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1070 v4l_print_pix_fmt(vfd,&f->fmt.pix);
1071 if (vfd->vidioc_s_fmt_cap)
1072 ret=vfd->vidioc_s_fmt_cap(file, fh, f);
1073 break;
1074 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1075 if (vfd->vidioc_s_fmt_overlay)
1076 ret=vfd->vidioc_s_fmt_overlay(file, fh, f);
1077 break;
1078 case V4L2_BUF_TYPE_VBI_CAPTURE:
1079 if (vfd->vidioc_s_fmt_vbi)
1080 ret=vfd->vidioc_s_fmt_vbi(file, fh, f);
1081 break;
1082 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1083 if (vfd->vidioc_s_fmt_vbi_output)
1084 ret=vfd->vidioc_s_fmt_vbi_output(file, fh, f);
1085 break;
1086 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1087 if (vfd->vidioc_s_fmt_vbi_capture)
1088 ret=vfd->vidioc_s_fmt_vbi_capture(file, fh, f);
1089 break;
1090 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1091 if (vfd->vidioc_s_fmt_video_output)
1092 ret=vfd->vidioc_s_fmt_video_output(file,
1093 fh, f);
1094 break;
1095 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1096 if (vfd->vidioc_s_fmt_output_overlay)
1097 ret=vfd->vidioc_s_fmt_output_overlay(file, fh, f);
1098 break;
1099 case V4L2_BUF_TYPE_VBI_OUTPUT:
1100 if (vfd->vidioc_s_fmt_vbi_output)
1101 ret=vfd->vidioc_s_fmt_vbi_output(file,
1102 fh, f);
1103 break;
1104 case V4L2_BUF_TYPE_PRIVATE:
1105 if (vfd->vidioc_s_fmt_type_private)
1106 ret=vfd->vidioc_s_fmt_type_private(file,
1107 fh, f);
1108 break;
1110 break;
1112 case VIDIOC_TRY_FMT:
1114 struct v4l2_format *f = (struct v4l2_format *)arg;
1116 /* FIXME: Should be one dump per type */
1117 dbgarg (cmd, "type=%s\n", prt_names(f->type,
1118 <<<<<<< HEAD:drivers/media/video/videodev.c
1119 v4l2_type_names_FIXME));
1120 =======
1121 v4l2_type_names));
1122 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
1123 switch (f->type) {
1124 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1125 if (vfd->vidioc_try_fmt_cap)
1126 ret=vfd->vidioc_try_fmt_cap(file, fh, f);
1127 if (!ret)
1128 v4l_print_pix_fmt(vfd,&f->fmt.pix);
1129 break;
1130 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1131 if (vfd->vidioc_try_fmt_overlay)
1132 ret=vfd->vidioc_try_fmt_overlay(file, fh, f);
1133 break;
1134 case V4L2_BUF_TYPE_VBI_CAPTURE:
1135 if (vfd->vidioc_try_fmt_vbi)
1136 ret=vfd->vidioc_try_fmt_vbi(file, fh, f);
1137 break;
1138 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1139 if (vfd->vidioc_try_fmt_vbi_output)
1140 ret=vfd->vidioc_try_fmt_vbi_output(file,
1141 fh, f);
1142 break;
1143 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1144 if (vfd->vidioc_try_fmt_vbi_capture)
1145 ret=vfd->vidioc_try_fmt_vbi_capture(file,
1146 fh, f);
1147 break;
1148 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1149 if (vfd->vidioc_try_fmt_video_output)
1150 ret=vfd->vidioc_try_fmt_video_output(file,
1151 fh, f);
1152 break;
1153 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1154 if (vfd->vidioc_try_fmt_output_overlay)
1155 ret=vfd->vidioc_try_fmt_output_overlay(file, fh, f);
1156 break;
1157 case V4L2_BUF_TYPE_VBI_OUTPUT:
1158 if (vfd->vidioc_try_fmt_vbi_output)
1159 ret=vfd->vidioc_try_fmt_vbi_output(file,
1160 fh, f);
1161 break;
1162 case V4L2_BUF_TYPE_PRIVATE:
1163 if (vfd->vidioc_try_fmt_type_private)
1164 ret=vfd->vidioc_try_fmt_type_private(file,
1165 fh, f);
1166 break;
1169 break;
1171 /* FIXME: Those buf reqs could be handled here,
1172 with some changes on videobuf to allow its header to be included at
1173 videodev2.h or being merged at videodev2.
1175 case VIDIOC_REQBUFS:
1177 struct v4l2_requestbuffers *p=arg;
1179 if (!vfd->vidioc_reqbufs)
1180 break;
1181 ret = check_fmt (vfd, p->type);
1182 if (ret)
1183 break;
1185 ret=vfd->vidioc_reqbufs(file, fh, p);
1186 dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
1187 p->count,
1188 <<<<<<< HEAD:drivers/media/video/videodev.c
1189 prt_names(p->type,v4l2_type_names_FIXME),
1190 prt_names(p->memory,v4l2_memory_names));
1191 =======
1192 prt_names(p->type, v4l2_type_names),
1193 prt_names(p->memory, v4l2_memory_names));
1194 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
1195 break;
1197 case VIDIOC_QUERYBUF:
1199 struct v4l2_buffer *p=arg;
1201 if (!vfd->vidioc_querybuf)
1202 break;
1203 ret = check_fmt (vfd, p->type);
1204 if (ret)
1205 break;
1207 ret=vfd->vidioc_querybuf(file, fh, p);
1208 if (!ret)
1209 dbgbuf(cmd,vfd,p);
1210 break;
1212 case VIDIOC_QBUF:
1214 struct v4l2_buffer *p=arg;
1216 if (!vfd->vidioc_qbuf)
1217 break;
1218 ret = check_fmt (vfd, p->type);
1219 if (ret)
1220 break;
1222 ret=vfd->vidioc_qbuf(file, fh, p);
1223 if (!ret)
1224 dbgbuf(cmd,vfd,p);
1225 break;
1227 case VIDIOC_DQBUF:
1229 struct v4l2_buffer *p=arg;
1230 if (!vfd->vidioc_dqbuf)
1231 break;
1232 ret = check_fmt (vfd, p->type);
1233 if (ret)
1234 break;
1236 ret=vfd->vidioc_dqbuf(file, fh, p);
1237 if (!ret)
1238 dbgbuf(cmd,vfd,p);
1239 break;
1241 case VIDIOC_OVERLAY:
1243 int *i = arg;
1245 if (!vfd->vidioc_overlay)
1246 break;
1247 dbgarg (cmd, "value=%d\n",*i);
1248 ret=vfd->vidioc_overlay(file, fh, *i);
1249 break;
1251 case VIDIOC_G_FBUF:
1253 struct v4l2_framebuffer *p=arg;
1254 if (!vfd->vidioc_g_fbuf)
1255 break;
1256 ret=vfd->vidioc_g_fbuf(file, fh, arg);
1257 if (!ret) {
1258 dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
1259 p->capability,p->flags,
1260 (unsigned long)p->base);
1261 v4l_print_pix_fmt (vfd, &p->fmt);
1263 break;
1265 case VIDIOC_S_FBUF:
1267 struct v4l2_framebuffer *p=arg;
1268 if (!vfd->vidioc_s_fbuf)
1269 break;
1271 dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
1272 p->capability,p->flags,(unsigned long)p->base);
1273 v4l_print_pix_fmt (vfd, &p->fmt);
1274 ret=vfd->vidioc_s_fbuf(file, fh, arg);
1276 break;
1278 case VIDIOC_STREAMON:
1280 enum v4l2_buf_type i = *(int *)arg;
1281 if (!vfd->vidioc_streamon)
1282 break;
1283 <<<<<<< HEAD:drivers/media/video/videodev.c
1284 dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
1285 =======
1286 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1287 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
1288 ret=vfd->vidioc_streamon(file, fh,i);
1289 break;
1291 case VIDIOC_STREAMOFF:
1293 enum v4l2_buf_type i = *(int *)arg;
1295 if (!vfd->vidioc_streamoff)
1296 break;
1297 <<<<<<< HEAD:drivers/media/video/videodev.c
1298 dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
1299 =======
1300 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1301 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
1302 ret=vfd->vidioc_streamoff(file, fh, i);
1303 break;
1305 /* ---------- tv norms ---------- */
1306 case VIDIOC_ENUMSTD:
1308 struct v4l2_standard *p = arg;
1309 v4l2_std_id id = vfd->tvnorms,curr_id=0;
1310 unsigned int index = p->index,i;
1312 if (index<0) {
1313 ret=-EINVAL;
1314 break;
1317 /* Return norm array on a canonical way */
1318 for (i=0;i<= index && id; i++) {
1319 if ( (id & V4L2_STD_PAL) == V4L2_STD_PAL) {
1320 curr_id = V4L2_STD_PAL;
1321 } else if ( (id & V4L2_STD_PAL_BG) == V4L2_STD_PAL_BG) {
1322 curr_id = V4L2_STD_PAL_BG;
1323 } else if ( (id & V4L2_STD_PAL_DK) == V4L2_STD_PAL_DK) {
1324 curr_id = V4L2_STD_PAL_DK;
1325 } else if ( (id & V4L2_STD_PAL_B) == V4L2_STD_PAL_B) {
1326 curr_id = V4L2_STD_PAL_B;
1327 } else if ( (id & V4L2_STD_PAL_B1) == V4L2_STD_PAL_B1) {
1328 curr_id = V4L2_STD_PAL_B1;
1329 } else if ( (id & V4L2_STD_PAL_G) == V4L2_STD_PAL_G) {
1330 curr_id = V4L2_STD_PAL_G;
1331 } else if ( (id & V4L2_STD_PAL_H) == V4L2_STD_PAL_H) {
1332 curr_id = V4L2_STD_PAL_H;
1333 } else if ( (id & V4L2_STD_PAL_I) == V4L2_STD_PAL_I) {
1334 curr_id = V4L2_STD_PAL_I;
1335 } else if ( (id & V4L2_STD_PAL_D) == V4L2_STD_PAL_D) {
1336 curr_id = V4L2_STD_PAL_D;
1337 } else if ( (id & V4L2_STD_PAL_D1) == V4L2_STD_PAL_D1) {
1338 curr_id = V4L2_STD_PAL_D1;
1339 } else if ( (id & V4L2_STD_PAL_K) == V4L2_STD_PAL_K) {
1340 curr_id = V4L2_STD_PAL_K;
1341 } else if ( (id & V4L2_STD_PAL_M) == V4L2_STD_PAL_M) {
1342 curr_id = V4L2_STD_PAL_M;
1343 } else if ( (id & V4L2_STD_PAL_N) == V4L2_STD_PAL_N) {
1344 curr_id = V4L2_STD_PAL_N;
1345 } else if ( (id & V4L2_STD_PAL_Nc) == V4L2_STD_PAL_Nc) {
1346 curr_id = V4L2_STD_PAL_Nc;
1347 } else if ( (id & V4L2_STD_PAL_60) == V4L2_STD_PAL_60) {
1348 curr_id = V4L2_STD_PAL_60;
1349 } else if ( (id & V4L2_STD_NTSC) == V4L2_STD_NTSC) {
1350 curr_id = V4L2_STD_NTSC;
1351 } else if ( (id & V4L2_STD_NTSC_M) == V4L2_STD_NTSC_M) {
1352 curr_id = V4L2_STD_NTSC_M;
1353 } else if ( (id & V4L2_STD_NTSC_M_JP) == V4L2_STD_NTSC_M_JP) {
1354 curr_id = V4L2_STD_NTSC_M_JP;
1355 } else if ( (id & V4L2_STD_NTSC_443) == V4L2_STD_NTSC_443) {
1356 curr_id = V4L2_STD_NTSC_443;
1357 } else if ( (id & V4L2_STD_NTSC_M_KR) == V4L2_STD_NTSC_M_KR) {
1358 curr_id = V4L2_STD_NTSC_M_KR;
1359 } else if ( (id & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
1360 curr_id = V4L2_STD_SECAM;
1361 } else if ( (id & V4L2_STD_SECAM_DK) == V4L2_STD_SECAM_DK) {
1362 curr_id = V4L2_STD_SECAM_DK;
1363 } else if ( (id & V4L2_STD_SECAM_B) == V4L2_STD_SECAM_B) {
1364 curr_id = V4L2_STD_SECAM_B;
1365 } else if ( (id & V4L2_STD_SECAM_D) == V4L2_STD_SECAM_D) {
1366 curr_id = V4L2_STD_SECAM_D;
1367 } else if ( (id & V4L2_STD_SECAM_G) == V4L2_STD_SECAM_G) {
1368 curr_id = V4L2_STD_SECAM_G;
1369 } else if ( (id & V4L2_STD_SECAM_H) == V4L2_STD_SECAM_H) {
1370 curr_id = V4L2_STD_SECAM_H;
1371 } else if ( (id & V4L2_STD_SECAM_K) == V4L2_STD_SECAM_K) {
1372 curr_id = V4L2_STD_SECAM_K;
1373 } else if ( (id & V4L2_STD_SECAM_K1) == V4L2_STD_SECAM_K1) {
1374 curr_id = V4L2_STD_SECAM_K1;
1375 } else if ( (id & V4L2_STD_SECAM_L) == V4L2_STD_SECAM_L) {
1376 curr_id = V4L2_STD_SECAM_L;
1377 } else if ( (id & V4L2_STD_SECAM_LC) == V4L2_STD_SECAM_LC) {
1378 curr_id = V4L2_STD_SECAM_LC;
1379 } else {
1380 break;
1382 id &= ~curr_id;
1384 if (i<=index)
1385 return -EINVAL;
1387 v4l2_video_std_construct(p, curr_id,v4l2_norm_to_name(curr_id));
1388 p->index = index;
1390 dbgarg (cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
1391 "framelines=%d\n", p->index,
1392 (unsigned long long)p->id, p->name,
1393 p->frameperiod.numerator,
1394 p->frameperiod.denominator,
1395 p->framelines);
1397 ret=0;
1398 break;
1400 case VIDIOC_G_STD:
1402 v4l2_std_id *id = arg;
1404 *id = vfd->current_norm;
1406 dbgarg (cmd, "value=%08Lx\n", (long long unsigned) *id);
1408 ret=0;
1409 break;
1411 case VIDIOC_S_STD:
1413 v4l2_std_id *id = arg,norm;
1415 dbgarg (cmd, "value=%08Lx\n", (long long unsigned) *id);
1417 norm = (*id) & vfd->tvnorms;
1418 if ( vfd->tvnorms && !norm) /* Check if std is supported */
1419 break;
1421 /* Calls the specific handler */
1422 if (vfd->vidioc_s_std)
1423 ret=vfd->vidioc_s_std(file, fh, &norm);
1424 else
1425 ret=-EINVAL;
1427 /* Updates standard information */
1428 if (ret>=0)
1429 vfd->current_norm=norm;
1431 break;
1433 case VIDIOC_QUERYSTD:
1435 v4l2_std_id *p=arg;
1437 if (!vfd->vidioc_querystd)
1438 break;
1439 ret=vfd->vidioc_querystd(file, fh, arg);
1440 if (!ret)
1441 dbgarg (cmd, "detected std=%08Lx\n",
1442 (unsigned long long)*p);
1443 break;
1445 /* ------ input switching ---------- */
1446 /* FIXME: Inputs can be handled inside videodev2 */
1447 case VIDIOC_ENUMINPUT:
1449 struct v4l2_input *p=arg;
1450 int i=p->index;
1452 if (!vfd->vidioc_enum_input)
1453 break;
1454 memset(p, 0, sizeof(*p));
1455 p->index=i;
1457 ret=vfd->vidioc_enum_input(file, fh, p);
1458 if (!ret)
1459 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1460 "audioset=%d, "
1461 "tuner=%d, std=%08Lx, status=%d\n",
1462 p->index,p->name,p->type,p->audioset,
1463 p->tuner,
1464 (unsigned long long)p->std,
1465 p->status);
1466 break;
1468 case VIDIOC_G_INPUT:
1470 unsigned int *i = arg;
1472 if (!vfd->vidioc_g_input)
1473 break;
1474 ret=vfd->vidioc_g_input(file, fh, i);
1475 if (!ret)
1476 dbgarg (cmd, "value=%d\n",*i);
1477 break;
1479 case VIDIOC_S_INPUT:
1481 unsigned int *i = arg;
1483 if (!vfd->vidioc_s_input)
1484 break;
1485 dbgarg (cmd, "value=%d\n",*i);
1486 ret=vfd->vidioc_s_input(file, fh, *i);
1487 break;
1490 /* ------ output switching ---------- */
1491 case VIDIOC_G_OUTPUT:
1493 unsigned int *i = arg;
1495 if (!vfd->vidioc_g_output)
1496 break;
1497 ret=vfd->vidioc_g_output(file, fh, i);
1498 if (!ret)
1499 dbgarg (cmd, "value=%d\n",*i);
1500 break;
1502 case VIDIOC_S_OUTPUT:
1504 unsigned int *i = arg;
1506 if (!vfd->vidioc_s_output)
1507 break;
1508 dbgarg (cmd, "value=%d\n",*i);
1509 ret=vfd->vidioc_s_output(file, fh, *i);
1510 break;
1513 /* --- controls ---------------------------------------------- */
1514 case VIDIOC_QUERYCTRL:
1516 struct v4l2_queryctrl *p=arg;
1518 if (!vfd->vidioc_queryctrl)
1519 break;
1520 ret=vfd->vidioc_queryctrl(file, fh, p);
1522 if (!ret)
1523 dbgarg (cmd, "id=%d, type=%d, name=%s, "
1524 "min/max=%d/%d,"
1525 " step=%d, default=%d, flags=0x%08x\n",
1526 p->id,p->type,p->name,p->minimum,
1527 p->maximum,p->step,p->default_value,
1528 p->flags);
1529 break;
1531 case VIDIOC_G_CTRL:
1533 struct v4l2_control *p = arg;
1535 if (!vfd->vidioc_g_ctrl)
1536 break;
1537 dbgarg(cmd, "Enum for index=%d\n", p->id);
1539 ret=vfd->vidioc_g_ctrl(file, fh, p);
1540 if (!ret)
1541 dbgarg2 ( "id=%d, value=%d\n", p->id, p->value);
1542 break;
1544 case VIDIOC_S_CTRL:
1546 struct v4l2_control *p = arg;
1548 if (!vfd->vidioc_s_ctrl)
1549 break;
1550 dbgarg (cmd, "id=%d, value=%d\n", p->id, p->value);
1552 ret=vfd->vidioc_s_ctrl(file, fh, p);
1553 break;
1555 case VIDIOC_G_EXT_CTRLS:
1557 struct v4l2_ext_controls *p = arg;
1559 if (vfd->vidioc_g_ext_ctrls) {
1560 dbgarg(cmd, "count=%d\n", p->count);
1562 ret=vfd->vidioc_g_ext_ctrls(file, fh, p);
1564 break;
1566 case VIDIOC_S_EXT_CTRLS:
1568 struct v4l2_ext_controls *p = arg;
1570 if (vfd->vidioc_s_ext_ctrls) {
1571 dbgarg(cmd, "count=%d\n", p->count);
1573 ret=vfd->vidioc_s_ext_ctrls(file, fh, p);
1575 break;
1577 case VIDIOC_TRY_EXT_CTRLS:
1579 struct v4l2_ext_controls *p = arg;
1581 if (vfd->vidioc_try_ext_ctrls) {
1582 dbgarg(cmd, "count=%d\n", p->count);
1584 ret=vfd->vidioc_try_ext_ctrls(file, fh, p);
1586 break;
1588 case VIDIOC_QUERYMENU:
1590 struct v4l2_querymenu *p=arg;
1591 if (!vfd->vidioc_querymenu)
1592 break;
1593 ret=vfd->vidioc_querymenu(file, fh, p);
1594 if (!ret)
1595 dbgarg (cmd, "id=%d, index=%d, name=%s\n",
1596 p->id,p->index,p->name);
1597 break;
1599 /* --- audio ---------------------------------------------- */
1600 case VIDIOC_ENUMAUDIO:
1602 struct v4l2_audio *p=arg;
1604 if (!vfd->vidioc_enumaudio)
1605 break;
1606 dbgarg(cmd, "Enum for index=%d\n", p->index);
1607 ret=vfd->vidioc_enumaudio(file, fh, p);
1608 if (!ret)
1609 dbgarg2("index=%d, name=%s, capability=%d, "
1610 "mode=%d\n",p->index,p->name,
1611 p->capability, p->mode);
1612 break;
1614 case VIDIOC_G_AUDIO:
1616 struct v4l2_audio *p=arg;
1617 __u32 index=p->index;
1619 if (!vfd->vidioc_g_audio)
1620 break;
1622 memset(p,0,sizeof(*p));
1623 p->index=index;
1624 dbgarg(cmd, "Get for index=%d\n", p->index);
1625 ret=vfd->vidioc_g_audio(file, fh, p);
1626 if (!ret)
1627 dbgarg2("index=%d, name=%s, capability=%d, "
1628 "mode=%d\n",p->index,
1629 p->name,p->capability, p->mode);
1630 break;
1632 case VIDIOC_S_AUDIO:
1634 struct v4l2_audio *p=arg;
1636 if (!vfd->vidioc_s_audio)
1637 break;
1638 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1639 "mode=%d\n", p->index, p->name,
1640 p->capability, p->mode);
1641 ret=vfd->vidioc_s_audio(file, fh, p);
1642 break;
1644 case VIDIOC_ENUMAUDOUT:
1646 struct v4l2_audioout *p=arg;
1648 if (!vfd->vidioc_enumaudout)
1649 break;
1650 dbgarg(cmd, "Enum for index=%d\n", p->index);
1651 ret=vfd->vidioc_enumaudout(file, fh, p);
1652 if (!ret)
1653 dbgarg2("index=%d, name=%s, capability=%d, "
1654 "mode=%d\n", p->index, p->name,
1655 p->capability,p->mode);
1656 break;
1658 case VIDIOC_G_AUDOUT:
1660 struct v4l2_audioout *p=arg;
1662 if (!vfd->vidioc_g_audout)
1663 break;
1664 dbgarg(cmd, "Enum for index=%d\n", p->index);
1665 ret=vfd->vidioc_g_audout(file, fh, p);
1666 if (!ret)
1667 dbgarg2("index=%d, name=%s, capability=%d, "
1668 "mode=%d\n", p->index, p->name,
1669 p->capability,p->mode);
1670 break;
1672 case VIDIOC_S_AUDOUT:
1674 struct v4l2_audioout *p=arg;
1676 if (!vfd->vidioc_s_audout)
1677 break;
1678 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1679 "mode=%d\n", p->index, p->name,
1680 p->capability,p->mode);
1682 ret=vfd->vidioc_s_audout(file, fh, p);
1683 break;
1685 case VIDIOC_G_MODULATOR:
1687 struct v4l2_modulator *p=arg;
1688 if (!vfd->vidioc_g_modulator)
1689 break;
1690 ret=vfd->vidioc_g_modulator(file, fh, p);
1691 if (!ret)
1692 dbgarg(cmd, "index=%d, name=%s, "
1693 "capability=%d, rangelow=%d,"
1694 " rangehigh=%d, txsubchans=%d\n",
1695 p->index, p->name,p->capability,
1696 p->rangelow, p->rangehigh,
1697 p->txsubchans);
1698 break;
1700 case VIDIOC_S_MODULATOR:
1702 struct v4l2_modulator *p=arg;
1703 if (!vfd->vidioc_s_modulator)
1704 break;
1705 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1706 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1707 p->index, p->name,p->capability,p->rangelow,
1708 p->rangehigh,p->txsubchans);
1709 ret=vfd->vidioc_s_modulator(file, fh, p);
1710 break;
1712 case VIDIOC_G_CROP:
1714 struct v4l2_crop *p=arg;
1715 if (!vfd->vidioc_g_crop)
1716 break;
1717 ret=vfd->vidioc_g_crop(file, fh, p);
1718 if (!ret) {
1719 dbgarg(cmd, "type=%d\n", p->type);
1720 dbgrect(vfd, "", &p->c);
1722 break;
1724 case VIDIOC_S_CROP:
1726 struct v4l2_crop *p=arg;
1727 if (!vfd->vidioc_s_crop)
1728 break;
1729 dbgarg(cmd, "type=%d\n", p->type);
1730 dbgrect(vfd, "", &p->c);
1731 ret=vfd->vidioc_s_crop(file, fh, p);
1732 break;
1734 case VIDIOC_CROPCAP:
1736 struct v4l2_cropcap *p=arg;
1737 /*FIXME: Should also show v4l2_fract pixelaspect */
1738 if (!vfd->vidioc_cropcap)
1739 break;
1740 dbgarg(cmd, "type=%d\n", p->type);
1741 dbgrect(vfd, "bounds ", &p->bounds);
1742 dbgrect(vfd, "defrect ", &p->defrect);
1743 ret=vfd->vidioc_cropcap(file, fh, p);
1744 break;
1746 case VIDIOC_G_JPEGCOMP:
1748 struct v4l2_jpegcompression *p=arg;
1749 if (!vfd->vidioc_g_jpegcomp)
1750 break;
1751 ret=vfd->vidioc_g_jpegcomp(file, fh, p);
1752 if (!ret)
1753 dbgarg (cmd, "quality=%d, APPn=%d, "
1754 "APP_len=%d, COM_len=%d, "
1755 "jpeg_markers=%d\n",
1756 p->quality,p->APPn,p->APP_len,
1757 p->COM_len,p->jpeg_markers);
1758 break;
1760 case VIDIOC_S_JPEGCOMP:
1762 struct v4l2_jpegcompression *p=arg;
1763 if (!vfd->vidioc_g_jpegcomp)
1764 break;
1765 dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
1766 "COM_len=%d, jpeg_markers=%d\n",
1767 p->quality,p->APPn,p->APP_len,
1768 p->COM_len,p->jpeg_markers);
1769 ret=vfd->vidioc_s_jpegcomp(file, fh, p);
1770 break;
1772 case VIDIOC_G_ENC_INDEX:
1774 struct v4l2_enc_idx *p=arg;
1776 if (!vfd->vidioc_g_enc_index)
1777 break;
1778 ret=vfd->vidioc_g_enc_index(file, fh, p);
1779 if (!ret)
1780 dbgarg (cmd, "entries=%d, entries_cap=%d\n",
1781 p->entries,p->entries_cap);
1782 break;
1784 case VIDIOC_ENCODER_CMD:
1786 struct v4l2_encoder_cmd *p=arg;
1788 if (!vfd->vidioc_encoder_cmd)
1789 break;
1790 ret=vfd->vidioc_encoder_cmd(file, fh, p);
1791 if (!ret)
1792 dbgarg (cmd, "cmd=%d, flags=%d\n",
1793 p->cmd,p->flags);
1794 break;
1796 case VIDIOC_TRY_ENCODER_CMD:
1798 struct v4l2_encoder_cmd *p=arg;
1800 if (!vfd->vidioc_try_encoder_cmd)
1801 break;
1802 ret=vfd->vidioc_try_encoder_cmd(file, fh, p);
1803 if (!ret)
1804 dbgarg (cmd, "cmd=%d, flags=%d\n",
1805 p->cmd,p->flags);
1806 break;
1808 case VIDIOC_G_PARM:
1810 struct v4l2_streamparm *p=arg;
1811 __u32 type=p->type;
1813 memset(p,0,sizeof(*p));
1814 p->type=type;
1816 if (vfd->vidioc_g_parm) {
1817 ret=vfd->vidioc_g_parm(file, fh, p);
1818 } else {
1819 struct v4l2_standard s;
1821 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1822 return -EINVAL;
1824 v4l2_video_std_construct(&s, vfd->current_norm,
1825 v4l2_norm_to_name(vfd->current_norm));
1827 p->parm.capture.timeperframe = s.frameperiod;
1828 ret=0;
1831 dbgarg (cmd, "type=%d\n", p->type);
1832 break;
1834 case VIDIOC_S_PARM:
1836 struct v4l2_streamparm *p=arg;
1837 if (!vfd->vidioc_s_parm)
1838 break;
1839 dbgarg (cmd, "type=%d\n", p->type);
1840 ret=vfd->vidioc_s_parm(file, fh, p);
1841 break;
1843 case VIDIOC_G_TUNER:
1845 struct v4l2_tuner *p=arg;
1846 __u32 index=p->index;
1848 if (!vfd->vidioc_g_tuner)
1849 break;
1851 memset(p,0,sizeof(*p));
1852 p->index=index;
1854 ret=vfd->vidioc_g_tuner(file, fh, p);
1855 if (!ret)
1856 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1857 "capability=%d, rangelow=%d, "
1858 "rangehigh=%d, signal=%d, afc=%d, "
1859 "rxsubchans=%d, audmode=%d\n",
1860 p->index, p->name, p->type,
1861 p->capability, p->rangelow,
1862 p->rangehigh, p->rxsubchans,
1863 p->audmode, p->signal, p->afc);
1864 break;
1866 case VIDIOC_S_TUNER:
1868 struct v4l2_tuner *p=arg;
1869 if (!vfd->vidioc_s_tuner)
1870 break;
1871 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1872 "capability=%d, rangelow=%d, rangehigh=%d, "
1873 "signal=%d, afc=%d, rxsubchans=%d, "
1874 "audmode=%d\n",p->index, p->name, p->type,
1875 p->capability, p->rangelow,p->rangehigh,
1876 p->rxsubchans, p->audmode, p->signal,
1877 p->afc);
1878 ret=vfd->vidioc_s_tuner(file, fh, p);
1879 break;
1881 case VIDIOC_G_FREQUENCY:
1883 struct v4l2_frequency *p=arg;
1884 if (!vfd->vidioc_g_frequency)
1885 break;
1887 memset(p,0,sizeof(*p));
1889 ret=vfd->vidioc_g_frequency(file, fh, p);
1890 if (!ret)
1891 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1892 p->tuner,p->type,p->frequency);
1893 break;
1895 case VIDIOC_S_FREQUENCY:
1897 struct v4l2_frequency *p=arg;
1898 if (!vfd->vidioc_s_frequency)
1899 break;
1900 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1901 p->tuner,p->type,p->frequency);
1902 ret=vfd->vidioc_s_frequency(file, fh, p);
1903 break;
1905 case VIDIOC_G_SLICED_VBI_CAP:
1907 struct v4l2_sliced_vbi_cap *p=arg;
1908 if (!vfd->vidioc_g_sliced_vbi_cap)
1909 break;
1910 ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
1911 if (!ret)
1912 dbgarg (cmd, "service_set=%d\n", p->service_set);
1913 break;
1915 case VIDIOC_LOG_STATUS:
1917 if (!vfd->vidioc_log_status)
1918 break;
1919 ret=vfd->vidioc_log_status(file, fh);
1920 break;
1922 #ifdef CONFIG_VIDEO_ADV_DEBUG
1923 case VIDIOC_DBG_G_REGISTER:
1925 struct v4l2_register *p=arg;
1926 if (!capable(CAP_SYS_ADMIN))
1927 ret=-EPERM;
1928 else if (vfd->vidioc_g_register)
1929 ret=vfd->vidioc_g_register(file, fh, p);
1930 break;
1932 case VIDIOC_DBG_S_REGISTER:
1934 struct v4l2_register *p=arg;
1935 if (!capable(CAP_SYS_ADMIN))
1936 ret=-EPERM;
1937 else if (vfd->vidioc_s_register)
1938 ret=vfd->vidioc_s_register(file, fh, p);
1939 break;
1941 #endif
1942 case VIDIOC_G_CHIP_IDENT:
1944 struct v4l2_chip_ident *p=arg;
1945 if (!vfd->vidioc_g_chip_ident)
1946 break;
1947 ret=vfd->vidioc_g_chip_ident(file, fh, p);
1948 if (!ret)
1949 dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1950 break;
1952 } /* switch */
1954 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1955 if (ret<0) {
1956 printk ("%s: err:\n", vfd->name);
1957 v4l_print_ioctl(vfd->name, cmd);
1961 return ret;
1964 int video_ioctl2 (struct inode *inode, struct file *file,
1965 unsigned int cmd, unsigned long arg)
1967 char sbuf[128];
1968 void *mbuf = NULL;
1969 void *parg = NULL;
1970 int err = -EINVAL;
1971 int is_ext_ctrl;
1972 size_t ctrls_size = 0;
1973 void __user *user_ptr = NULL;
1975 #ifdef __OLD_VIDIOC_
1976 cmd = video_fix_command(cmd);
1977 #endif
1978 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1979 cmd == VIDIOC_TRY_EXT_CTRLS);
1981 /* Copy arguments into temp kernel buffer */
1982 switch (_IOC_DIR(cmd)) {
1983 case _IOC_NONE:
1984 parg = NULL;
1985 break;
1986 case _IOC_READ:
1987 case _IOC_WRITE:
1988 case (_IOC_WRITE | _IOC_READ):
1989 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1990 parg = sbuf;
1991 } else {
1992 /* too big to allocate from stack */
1993 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
1994 if (NULL == mbuf)
1995 return -ENOMEM;
1996 parg = mbuf;
1999 err = -EFAULT;
2000 if (_IOC_DIR(cmd) & _IOC_WRITE)
2001 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
2002 goto out;
2003 break;
2006 if (is_ext_ctrl) {
2007 struct v4l2_ext_controls *p = parg;
2009 /* In case of an error, tell the caller that it wasn't
2010 a specific control that caused it. */
2011 p->error_idx = p->count;
2012 user_ptr = (void __user *)p->controls;
2013 if (p->count) {
2014 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
2015 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
2016 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
2017 err = -ENOMEM;
2018 if (NULL == mbuf)
2019 goto out_ext_ctrl;
2020 err = -EFAULT;
2021 if (copy_from_user(mbuf, user_ptr, ctrls_size))
2022 goto out_ext_ctrl;
2023 p->controls = mbuf;
2027 /* Handles IOCTL */
2028 err = __video_do_ioctl(inode, file, cmd, parg);
2029 if (err == -ENOIOCTLCMD)
2030 err = -EINVAL;
2031 if (is_ext_ctrl) {
2032 struct v4l2_ext_controls *p = parg;
2034 p->controls = (void *)user_ptr;
2035 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
2036 err = -EFAULT;
2037 goto out_ext_ctrl;
2039 if (err < 0)
2040 goto out;
2042 out_ext_ctrl:
2043 /* Copy results into user buffer */
2044 switch (_IOC_DIR(cmd))
2046 case _IOC_READ:
2047 case (_IOC_WRITE | _IOC_READ):
2048 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2049 err = -EFAULT;
2050 break;
2053 out:
2054 kfree(mbuf);
2055 return err;
2057 <<<<<<< HEAD:drivers/media/video/videodev.c
2059 =======
2060 EXPORT_SYMBOL(video_ioctl2);
2061 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
2063 static const struct file_operations video_fops;
2066 * video_register_device - register video4linux devices
2067 * @vfd: video device structure we want to register
2068 * @type: type of device to register
2069 * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
2070 * -1 == first free)
2072 * The registration code assigns minor numbers based on the type
2073 * requested. -ENFILE is returned in all the device slots for this
2074 * category are full. If not then the minor field is set and the
2075 * driver initialize function is called (if non %NULL).
2077 * Zero is returned on success.
2079 * Valid types are
2081 * %VFL_TYPE_GRABBER - A frame grabber
2083 * %VFL_TYPE_VTX - A teletext device
2085 * %VFL_TYPE_VBI - Vertical blank data (undecoded)
2087 * %VFL_TYPE_RADIO - A radio card
2090 int video_register_device(struct video_device *vfd, int type, int nr)
2092 int i=0;
2093 int base;
2094 int end;
2095 int ret;
2096 char *name_base;
2098 switch(type)
2100 case VFL_TYPE_GRABBER:
2101 base=MINOR_VFL_TYPE_GRABBER_MIN;
2102 end=MINOR_VFL_TYPE_GRABBER_MAX+1;
2103 name_base = "video";
2104 break;
2105 case VFL_TYPE_VTX:
2106 base=MINOR_VFL_TYPE_VTX_MIN;
2107 end=MINOR_VFL_TYPE_VTX_MAX+1;
2108 name_base = "vtx";
2109 break;
2110 case VFL_TYPE_VBI:
2111 base=MINOR_VFL_TYPE_VBI_MIN;
2112 end=MINOR_VFL_TYPE_VBI_MAX+1;
2113 name_base = "vbi";
2114 break;
2115 case VFL_TYPE_RADIO:
2116 base=MINOR_VFL_TYPE_RADIO_MIN;
2117 end=MINOR_VFL_TYPE_RADIO_MAX+1;
2118 name_base = "radio";
2119 break;
2120 default:
2121 printk(KERN_ERR "%s called with unknown type: %d\n",
2122 __FUNCTION__, type);
2123 return -1;
2126 /* pick a minor number */
2127 mutex_lock(&videodev_lock);
2128 if (nr >= 0 && nr < end-base) {
2129 /* use the one the driver asked for */
2130 i = base+nr;
2131 if (NULL != video_device[i]) {
2132 mutex_unlock(&videodev_lock);
2133 return -ENFILE;
2135 } else {
2136 /* use first free */
2137 for(i=base;i<end;i++)
2138 if (NULL == video_device[i])
2139 break;
2140 if (i == end) {
2141 mutex_unlock(&videodev_lock);
2142 return -ENFILE;
2145 video_device[i]=vfd;
2146 vfd->minor=i;
2147 mutex_unlock(&videodev_lock);
2148 mutex_init(&vfd->lock);
2150 /* sysfs class */
2151 memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
2152 if (vfd->dev)
2153 vfd->class_dev.parent = vfd->dev;
2154 vfd->class_dev.class = &video_class;
2155 vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
2156 sprintf(vfd->class_dev.bus_id, "%s%d", name_base, i - base);
2157 ret = device_register(&vfd->class_dev);
2158 if (ret < 0) {
2159 printk(KERN_ERR "%s: device_register failed\n",
2160 __FUNCTION__);
2161 goto fail_minor;
2164 #if 1
2165 /* needed until all drivers are fixed */
2166 if (!vfd->release)
2167 printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
2168 "Please fix your driver for proper sysfs support, see "
2169 "http://lwn.net/Articles/36850/\n", vfd->name);
2170 #endif
2171 return 0;
2173 fail_minor:
2174 mutex_lock(&videodev_lock);
2175 video_device[vfd->minor] = NULL;
2176 vfd->minor = -1;
2177 mutex_unlock(&videodev_lock);
2178 return ret;
2180 <<<<<<< HEAD:drivers/media/video/videodev.c
2181 =======
2182 EXPORT_SYMBOL(video_register_device);
2183 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
2186 * video_unregister_device - unregister a video4linux device
2187 * @vfd: the device to unregister
2189 * This unregisters the passed device and deassigns the minor
2190 * number. Future open calls will be met with errors.
2193 void video_unregister_device(struct video_device *vfd)
2195 mutex_lock(&videodev_lock);
2196 if(video_device[vfd->minor]!=vfd)
2197 panic("videodev: bad unregister");
2199 video_device[vfd->minor]=NULL;
2200 device_unregister(&vfd->class_dev);
2201 mutex_unlock(&videodev_lock);
2203 <<<<<<< HEAD:drivers/media/video/videodev.c
2204 =======
2205 EXPORT_SYMBOL(video_unregister_device);
2206 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
2209 * Video fs operations
2211 static const struct file_operations video_fops=
2213 .owner = THIS_MODULE,
2214 .llseek = no_llseek,
2215 .open = video_open,
2219 * Initialise video for linux
2222 static int __init videodev_init(void)
2224 int ret;
2226 printk(KERN_INFO "Linux video capture interface: v2.00\n");
2227 if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
2228 printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
2229 return -EIO;
2232 ret = class_register(&video_class);
2233 if (ret < 0) {
2234 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
2235 printk(KERN_WARNING "video_dev: class_register failed\n");
2236 return -EIO;
2239 return 0;
2242 static void __exit videodev_exit(void)
2244 class_unregister(&video_class);
2245 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
2248 module_init(videodev_init)
2249 module_exit(videodev_exit)
2251 <<<<<<< HEAD:drivers/media/video/videodev.c
2252 EXPORT_SYMBOL(video_register_device);
2253 EXPORT_SYMBOL(video_unregister_device);
2254 EXPORT_SYMBOL(video_devdata);
2255 EXPORT_SYMBOL(video_usercopy);
2256 EXPORT_SYMBOL(video_exclusive_open);
2257 EXPORT_SYMBOL(video_exclusive_release);
2258 EXPORT_SYMBOL(video_ioctl2);
2259 EXPORT_SYMBOL(video_device_alloc);
2260 EXPORT_SYMBOL(video_device_release);
2262 =======
2263 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/media/video/videodev.c
2264 MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
2265 MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
2266 MODULE_LICENSE("GPL");
2270 * Local variables:
2271 * c-basic-offset: 8
2272 * End: