2 * Video capture interface for Linux version 2
4 * A generic framework to process V4L2 ioctl commands.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
12 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
20 #define __OLD_VIDIOC_ /* To allow fixing old calls */
21 #include <linux/videodev.h>
22 #include <linux/videodev2.h>
24 #ifdef CONFIG_VIDEO_V4L1
25 #include <linux/videodev.h>
27 #include <media/v4l2-common.h>
28 #include <media/v4l2-ioctl.h>
29 #include <media/v4l2-ctrls.h>
30 #include <media/v4l2-fh.h>
31 #include <media/v4l2-event.h>
32 #include <media/v4l2-chip-ident.h>
34 #define dbgarg(cmd, fmt, arg...) \
36 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
37 printk(KERN_DEBUG "%s: ", vfd->name); \
38 v4l_printk_ioctl(cmd); \
39 printk(" " fmt, ## arg); \
43 #define dbgarg2(fmt, arg...) \
45 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
46 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
49 #define dbgarg3(fmt, arg...) \
51 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
52 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
55 /* Zero out the end of the struct pointed to by p. Everthing after, but
56 * not including, the specified field is cleared. */
57 #define CLEAR_AFTER_FIELD(p, field) \
58 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
59 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
66 static const struct std_descr standards
[] = {
67 { V4L2_STD_NTSC
, "NTSC" },
68 { V4L2_STD_NTSC_M
, "NTSC-M" },
69 { V4L2_STD_NTSC_M_JP
, "NTSC-M-JP" },
70 { V4L2_STD_NTSC_M_KR
, "NTSC-M-KR" },
71 { V4L2_STD_NTSC_443
, "NTSC-443" },
72 { V4L2_STD_PAL
, "PAL" },
73 { V4L2_STD_PAL_BG
, "PAL-BG" },
74 { V4L2_STD_PAL_B
, "PAL-B" },
75 { V4L2_STD_PAL_B1
, "PAL-B1" },
76 { V4L2_STD_PAL_G
, "PAL-G" },
77 { V4L2_STD_PAL_H
, "PAL-H" },
78 { V4L2_STD_PAL_I
, "PAL-I" },
79 { V4L2_STD_PAL_DK
, "PAL-DK" },
80 { V4L2_STD_PAL_D
, "PAL-D" },
81 { V4L2_STD_PAL_D1
, "PAL-D1" },
82 { V4L2_STD_PAL_K
, "PAL-K" },
83 { V4L2_STD_PAL_M
, "PAL-M" },
84 { V4L2_STD_PAL_N
, "PAL-N" },
85 { V4L2_STD_PAL_Nc
, "PAL-Nc" },
86 { V4L2_STD_PAL_60
, "PAL-60" },
87 { V4L2_STD_SECAM
, "SECAM" },
88 { V4L2_STD_SECAM_B
, "SECAM-B" },
89 { V4L2_STD_SECAM_G
, "SECAM-G" },
90 { V4L2_STD_SECAM_H
, "SECAM-H" },
91 { V4L2_STD_SECAM_DK
, "SECAM-DK" },
92 { V4L2_STD_SECAM_D
, "SECAM-D" },
93 { V4L2_STD_SECAM_K
, "SECAM-K" },
94 { V4L2_STD_SECAM_K1
, "SECAM-K1" },
95 { V4L2_STD_SECAM_L
, "SECAM-L" },
96 { V4L2_STD_SECAM_LC
, "SECAM-Lc" },
100 /* video4linux standard ID conversion to standard name
102 const char *v4l2_norm_to_name(v4l2_std_id id
)
107 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
108 64 bit comparations. So, on that architecture, with some gcc
109 variants, compilation fails. Currently, the max value is 30bit wide.
113 for (i
= 0; standards
[i
].std
; i
++)
114 if (myid
== standards
[i
].std
)
116 return standards
[i
].descr
;
118 EXPORT_SYMBOL(v4l2_norm_to_name
);
120 /* Returns frame period for the given standard */
121 void v4l2_video_std_frame_period(int id
, struct v4l2_fract
*frameperiod
)
123 if (id
& V4L2_STD_525_60
) {
124 frameperiod
->numerator
= 1001;
125 frameperiod
->denominator
= 30000;
127 frameperiod
->numerator
= 1;
128 frameperiod
->denominator
= 25;
131 EXPORT_SYMBOL(v4l2_video_std_frame_period
);
133 /* Fill in the fields of a v4l2_standard structure according to the
134 'id' and 'transmission' parameters. Returns negative on error. */
135 int v4l2_video_std_construct(struct v4l2_standard
*vs
,
136 int id
, const char *name
)
139 v4l2_video_std_frame_period(id
, &vs
->frameperiod
);
140 vs
->framelines
= (id
& V4L2_STD_525_60
) ? 525 : 625;
141 strlcpy(vs
->name
, name
, sizeof(vs
->name
));
144 EXPORT_SYMBOL(v4l2_video_std_construct
);
146 /* ----------------------------------------------------------------- */
147 /* some arrays for pretty-printing debug messages of enum types */
149 const char *v4l2_field_names
[] = {
150 [V4L2_FIELD_ANY
] = "any",
151 [V4L2_FIELD_NONE
] = "none",
152 [V4L2_FIELD_TOP
] = "top",
153 [V4L2_FIELD_BOTTOM
] = "bottom",
154 [V4L2_FIELD_INTERLACED
] = "interlaced",
155 [V4L2_FIELD_SEQ_TB
] = "seq-tb",
156 [V4L2_FIELD_SEQ_BT
] = "seq-bt",
157 [V4L2_FIELD_ALTERNATE
] = "alternate",
158 [V4L2_FIELD_INTERLACED_TB
] = "interlaced-tb",
159 [V4L2_FIELD_INTERLACED_BT
] = "interlaced-bt",
161 EXPORT_SYMBOL(v4l2_field_names
);
163 const char *v4l2_type_names
[] = {
164 [V4L2_BUF_TYPE_VIDEO_CAPTURE
] = "vid-cap",
165 [V4L2_BUF_TYPE_VIDEO_OVERLAY
] = "vid-overlay",
166 [V4L2_BUF_TYPE_VIDEO_OUTPUT
] = "vid-out",
167 [V4L2_BUF_TYPE_VBI_CAPTURE
] = "vbi-cap",
168 [V4L2_BUF_TYPE_VBI_OUTPUT
] = "vbi-out",
169 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
] = "sliced-vbi-cap",
170 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
] = "sliced-vbi-out",
171 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
] = "vid-out-overlay",
173 EXPORT_SYMBOL(v4l2_type_names
);
175 static const char *v4l2_memory_names
[] = {
176 [V4L2_MEMORY_MMAP
] = "mmap",
177 [V4L2_MEMORY_USERPTR
] = "userptr",
178 [V4L2_MEMORY_OVERLAY
] = "overlay",
181 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
184 /* ------------------------------------------------------------------ */
185 /* debug help functions */
187 #ifdef CONFIG_VIDEO_V4L1_COMPAT
188 static const char *v4l1_ioctls
[] = {
189 [_IOC_NR(VIDIOCGCAP
)] = "VIDIOCGCAP",
190 [_IOC_NR(VIDIOCGCHAN
)] = "VIDIOCGCHAN",
191 [_IOC_NR(VIDIOCSCHAN
)] = "VIDIOCSCHAN",
192 [_IOC_NR(VIDIOCGTUNER
)] = "VIDIOCGTUNER",
193 [_IOC_NR(VIDIOCSTUNER
)] = "VIDIOCSTUNER",
194 [_IOC_NR(VIDIOCGPICT
)] = "VIDIOCGPICT",
195 [_IOC_NR(VIDIOCSPICT
)] = "VIDIOCSPICT",
196 [_IOC_NR(VIDIOCCAPTURE
)] = "VIDIOCCAPTURE",
197 [_IOC_NR(VIDIOCGWIN
)] = "VIDIOCGWIN",
198 [_IOC_NR(VIDIOCSWIN
)] = "VIDIOCSWIN",
199 [_IOC_NR(VIDIOCGFBUF
)] = "VIDIOCGFBUF",
200 [_IOC_NR(VIDIOCSFBUF
)] = "VIDIOCSFBUF",
201 [_IOC_NR(VIDIOCKEY
)] = "VIDIOCKEY",
202 [_IOC_NR(VIDIOCGFREQ
)] = "VIDIOCGFREQ",
203 [_IOC_NR(VIDIOCSFREQ
)] = "VIDIOCSFREQ",
204 [_IOC_NR(VIDIOCGAUDIO
)] = "VIDIOCGAUDIO",
205 [_IOC_NR(VIDIOCSAUDIO
)] = "VIDIOCSAUDIO",
206 [_IOC_NR(VIDIOCSYNC
)] = "VIDIOCSYNC",
207 [_IOC_NR(VIDIOCMCAPTURE
)] = "VIDIOCMCAPTURE",
208 [_IOC_NR(VIDIOCGMBUF
)] = "VIDIOCGMBUF",
209 [_IOC_NR(VIDIOCGUNIT
)] = "VIDIOCGUNIT",
210 [_IOC_NR(VIDIOCGCAPTURE
)] = "VIDIOCGCAPTURE",
211 [_IOC_NR(VIDIOCSCAPTURE
)] = "VIDIOCSCAPTURE",
212 [_IOC_NR(VIDIOCSPLAYMODE
)] = "VIDIOCSPLAYMODE",
213 [_IOC_NR(VIDIOCSWRITEMODE
)] = "VIDIOCSWRITEMODE",
214 [_IOC_NR(VIDIOCGPLAYINFO
)] = "VIDIOCGPLAYINFO",
215 [_IOC_NR(VIDIOCSMICROCODE
)] = "VIDIOCSMICROCODE",
216 [_IOC_NR(VIDIOCGVBIFMT
)] = "VIDIOCGVBIFMT",
217 [_IOC_NR(VIDIOCSVBIFMT
)] = "VIDIOCSVBIFMT"
219 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
222 static const char *v4l2_ioctls
[] = {
223 [_IOC_NR(VIDIOC_QUERYCAP
)] = "VIDIOC_QUERYCAP",
224 [_IOC_NR(VIDIOC_RESERVED
)] = "VIDIOC_RESERVED",
225 [_IOC_NR(VIDIOC_ENUM_FMT
)] = "VIDIOC_ENUM_FMT",
226 [_IOC_NR(VIDIOC_G_FMT
)] = "VIDIOC_G_FMT",
227 [_IOC_NR(VIDIOC_S_FMT
)] = "VIDIOC_S_FMT",
228 [_IOC_NR(VIDIOC_REQBUFS
)] = "VIDIOC_REQBUFS",
229 [_IOC_NR(VIDIOC_QUERYBUF
)] = "VIDIOC_QUERYBUF",
230 [_IOC_NR(VIDIOC_G_FBUF
)] = "VIDIOC_G_FBUF",
231 [_IOC_NR(VIDIOC_S_FBUF
)] = "VIDIOC_S_FBUF",
232 [_IOC_NR(VIDIOC_OVERLAY
)] = "VIDIOC_OVERLAY",
233 [_IOC_NR(VIDIOC_QBUF
)] = "VIDIOC_QBUF",
234 [_IOC_NR(VIDIOC_DQBUF
)] = "VIDIOC_DQBUF",
235 [_IOC_NR(VIDIOC_STREAMON
)] = "VIDIOC_STREAMON",
236 [_IOC_NR(VIDIOC_STREAMOFF
)] = "VIDIOC_STREAMOFF",
237 [_IOC_NR(VIDIOC_G_PARM
)] = "VIDIOC_G_PARM",
238 [_IOC_NR(VIDIOC_S_PARM
)] = "VIDIOC_S_PARM",
239 [_IOC_NR(VIDIOC_G_STD
)] = "VIDIOC_G_STD",
240 [_IOC_NR(VIDIOC_S_STD
)] = "VIDIOC_S_STD",
241 [_IOC_NR(VIDIOC_ENUMSTD
)] = "VIDIOC_ENUMSTD",
242 [_IOC_NR(VIDIOC_ENUMINPUT
)] = "VIDIOC_ENUMINPUT",
243 [_IOC_NR(VIDIOC_G_CTRL
)] = "VIDIOC_G_CTRL",
244 [_IOC_NR(VIDIOC_S_CTRL
)] = "VIDIOC_S_CTRL",
245 [_IOC_NR(VIDIOC_G_TUNER
)] = "VIDIOC_G_TUNER",
246 [_IOC_NR(VIDIOC_S_TUNER
)] = "VIDIOC_S_TUNER",
247 [_IOC_NR(VIDIOC_G_AUDIO
)] = "VIDIOC_G_AUDIO",
248 [_IOC_NR(VIDIOC_S_AUDIO
)] = "VIDIOC_S_AUDIO",
249 [_IOC_NR(VIDIOC_QUERYCTRL
)] = "VIDIOC_QUERYCTRL",
250 [_IOC_NR(VIDIOC_QUERYMENU
)] = "VIDIOC_QUERYMENU",
251 [_IOC_NR(VIDIOC_G_INPUT
)] = "VIDIOC_G_INPUT",
252 [_IOC_NR(VIDIOC_S_INPUT
)] = "VIDIOC_S_INPUT",
253 [_IOC_NR(VIDIOC_G_OUTPUT
)] = "VIDIOC_G_OUTPUT",
254 [_IOC_NR(VIDIOC_S_OUTPUT
)] = "VIDIOC_S_OUTPUT",
255 [_IOC_NR(VIDIOC_ENUMOUTPUT
)] = "VIDIOC_ENUMOUTPUT",
256 [_IOC_NR(VIDIOC_G_AUDOUT
)] = "VIDIOC_G_AUDOUT",
257 [_IOC_NR(VIDIOC_S_AUDOUT
)] = "VIDIOC_S_AUDOUT",
258 [_IOC_NR(VIDIOC_G_MODULATOR
)] = "VIDIOC_G_MODULATOR",
259 [_IOC_NR(VIDIOC_S_MODULATOR
)] = "VIDIOC_S_MODULATOR",
260 [_IOC_NR(VIDIOC_G_FREQUENCY
)] = "VIDIOC_G_FREQUENCY",
261 [_IOC_NR(VIDIOC_S_FREQUENCY
)] = "VIDIOC_S_FREQUENCY",
262 [_IOC_NR(VIDIOC_CROPCAP
)] = "VIDIOC_CROPCAP",
263 [_IOC_NR(VIDIOC_G_CROP
)] = "VIDIOC_G_CROP",
264 [_IOC_NR(VIDIOC_S_CROP
)] = "VIDIOC_S_CROP",
265 [_IOC_NR(VIDIOC_G_JPEGCOMP
)] = "VIDIOC_G_JPEGCOMP",
266 [_IOC_NR(VIDIOC_S_JPEGCOMP
)] = "VIDIOC_S_JPEGCOMP",
267 [_IOC_NR(VIDIOC_QUERYSTD
)] = "VIDIOC_QUERYSTD",
268 [_IOC_NR(VIDIOC_TRY_FMT
)] = "VIDIOC_TRY_FMT",
269 [_IOC_NR(VIDIOC_ENUMAUDIO
)] = "VIDIOC_ENUMAUDIO",
270 [_IOC_NR(VIDIOC_ENUMAUDOUT
)] = "VIDIOC_ENUMAUDOUT",
271 [_IOC_NR(VIDIOC_G_PRIORITY
)] = "VIDIOC_G_PRIORITY",
272 [_IOC_NR(VIDIOC_S_PRIORITY
)] = "VIDIOC_S_PRIORITY",
273 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP
)] = "VIDIOC_G_SLICED_VBI_CAP",
274 [_IOC_NR(VIDIOC_LOG_STATUS
)] = "VIDIOC_LOG_STATUS",
275 [_IOC_NR(VIDIOC_G_EXT_CTRLS
)] = "VIDIOC_G_EXT_CTRLS",
276 [_IOC_NR(VIDIOC_S_EXT_CTRLS
)] = "VIDIOC_S_EXT_CTRLS",
277 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS
)] = "VIDIOC_TRY_EXT_CTRLS",
279 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES
)] = "VIDIOC_ENUM_FRAMESIZES",
280 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS
)] = "VIDIOC_ENUM_FRAMEINTERVALS",
281 [_IOC_NR(VIDIOC_G_ENC_INDEX
)] = "VIDIOC_G_ENC_INDEX",
282 [_IOC_NR(VIDIOC_ENCODER_CMD
)] = "VIDIOC_ENCODER_CMD",
283 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD
)] = "VIDIOC_TRY_ENCODER_CMD",
285 [_IOC_NR(VIDIOC_DBG_S_REGISTER
)] = "VIDIOC_DBG_S_REGISTER",
286 [_IOC_NR(VIDIOC_DBG_G_REGISTER
)] = "VIDIOC_DBG_G_REGISTER",
288 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT
)] = "VIDIOC_DBG_G_CHIP_IDENT",
289 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK
)] = "VIDIOC_S_HW_FREQ_SEEK",
291 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS
)] = "VIDIOC_ENUM_DV_PRESETS",
292 [_IOC_NR(VIDIOC_S_DV_PRESET
)] = "VIDIOC_S_DV_PRESET",
293 [_IOC_NR(VIDIOC_G_DV_PRESET
)] = "VIDIOC_G_DV_PRESET",
294 [_IOC_NR(VIDIOC_QUERY_DV_PRESET
)] = "VIDIOC_QUERY_DV_PRESET",
295 [_IOC_NR(VIDIOC_S_DV_TIMINGS
)] = "VIDIOC_S_DV_TIMINGS",
296 [_IOC_NR(VIDIOC_G_DV_TIMINGS
)] = "VIDIOC_G_DV_TIMINGS",
297 [_IOC_NR(VIDIOC_DQEVENT
)] = "VIDIOC_DQEVENT",
298 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT
)] = "VIDIOC_SUBSCRIBE_EVENT",
299 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT
)] = "VIDIOC_UNSUBSCRIBE_EVENT",
301 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
303 /* Common ioctl debug function. This function can be used by
304 external ioctl messages as well as internal V4L ioctl */
305 void v4l_printk_ioctl(unsigned int cmd
)
309 switch (_IOC_TYPE(cmd
)) {
313 #ifdef CONFIG_VIDEO_V4L1_COMPAT
315 if (_IOC_NR(cmd
) >= V4L1_IOCTLS
) {
319 printk("%s", v4l1_ioctls
[_IOC_NR(cmd
)]);
323 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
) {
327 printk("%s", v4l2_ioctls
[_IOC_NR(cmd
)]);
333 switch (_IOC_DIR(cmd
)) {
334 case _IOC_NONE
: dir
= "--"; break;
335 case _IOC_READ
: dir
= "r-"; break;
336 case _IOC_WRITE
: dir
= "-w"; break;
337 case _IOC_READ
| _IOC_WRITE
: dir
= "rw"; break;
338 default: dir
= "*ERR*"; break;
340 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
341 type
, _IOC_TYPE(cmd
), dir
, _IOC_NR(cmd
), cmd
);
343 EXPORT_SYMBOL(v4l_printk_ioctl
);
346 * helper function -- handles userspace copying for ioctl arguments
351 video_fix_command(unsigned int cmd
)
354 case VIDIOC_OVERLAY_OLD
:
355 cmd
= VIDIOC_OVERLAY
;
357 case VIDIOC_S_PARM_OLD
:
360 case VIDIOC_S_CTRL_OLD
:
363 case VIDIOC_G_AUDIO_OLD
:
364 cmd
= VIDIOC_G_AUDIO
;
366 case VIDIOC_G_AUDOUT_OLD
:
367 cmd
= VIDIOC_G_AUDOUT
;
369 case VIDIOC_CROPCAP_OLD
:
370 cmd
= VIDIOC_CROPCAP
;
378 * Obsolete usercopy function - Should be removed soon
381 video_usercopy(struct file
*file
, unsigned int cmd
, unsigned long arg
,
389 size_t ctrls_size
= 0;
390 void __user
*user_ptr
= NULL
;
393 cmd
= video_fix_command(cmd
);
395 is_ext_ctrl
= (cmd
== VIDIOC_S_EXT_CTRLS
|| cmd
== VIDIOC_G_EXT_CTRLS
||
396 cmd
== VIDIOC_TRY_EXT_CTRLS
);
398 /* Copy arguments into temp kernel buffer */
399 switch (_IOC_DIR(cmd
)) {
405 case (_IOC_WRITE
| _IOC_READ
):
406 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
409 /* too big to allocate from stack */
410 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
417 if (_IOC_DIR(cmd
) & _IOC_WRITE
)
418 if (copy_from_user(parg
, (void __user
*)arg
, _IOC_SIZE(cmd
)))
423 struct v4l2_ext_controls
*p
= parg
;
425 /* In case of an error, tell the caller that it wasn't
426 a specific control that caused it. */
427 p
->error_idx
= p
->count
;
428 user_ptr
= (void __user
*)p
->controls
;
430 ctrls_size
= sizeof(struct v4l2_ext_control
) * p
->count
;
431 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
432 mbuf
= kmalloc(ctrls_size
, GFP_KERNEL
);
437 if (copy_from_user(mbuf
, user_ptr
, ctrls_size
))
444 err
= func(file
, cmd
, parg
);
445 if (err
== -ENOIOCTLCMD
)
448 struct v4l2_ext_controls
*p
= parg
;
450 p
->controls
= (void *)user_ptr
;
451 if (p
->count
&& err
== 0 && copy_to_user(user_ptr
, mbuf
, ctrls_size
))
459 /* Copy results into user buffer */
460 switch (_IOC_DIR(cmd
)) {
462 case (_IOC_WRITE
| _IOC_READ
):
463 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
472 EXPORT_SYMBOL(video_usercopy
);
474 static void dbgbuf(unsigned int cmd
, struct video_device
*vfd
,
475 struct v4l2_buffer
*p
)
477 struct v4l2_timecode
*tc
= &p
->timecode
;
479 dbgarg(cmd
, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
480 "bytesused=%d, flags=0x%08d, "
481 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
482 p
->timestamp
.tv_sec
/ 3600,
483 (int)(p
->timestamp
.tv_sec
/ 60) % 60,
484 (int)(p
->timestamp
.tv_sec
% 60),
485 (long)p
->timestamp
.tv_usec
,
487 prt_names(p
->type
, v4l2_type_names
),
488 p
->bytesused
, p
->flags
,
489 p
->field
, p
->sequence
,
490 prt_names(p
->memory
, v4l2_memory_names
),
491 p
->m
.userptr
, p
->length
);
492 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
493 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
494 tc
->hours
, tc
->minutes
, tc
->seconds
,
495 tc
->type
, tc
->flags
, tc
->frames
, *(__u32
*)tc
->userbits
);
498 static inline void dbgrect(struct video_device
*vfd
, char *s
,
501 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s
, r
->left
, r
->top
,
502 r
->width
, r
->height
);
505 static inline void v4l_print_pix_fmt(struct video_device
*vfd
,
506 struct v4l2_pix_format
*fmt
)
508 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
509 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
510 fmt
->width
, fmt
->height
,
511 (fmt
->pixelformat
& 0xff),
512 (fmt
->pixelformat
>> 8) & 0xff,
513 (fmt
->pixelformat
>> 16) & 0xff,
514 (fmt
->pixelformat
>> 24) & 0xff,
515 prt_names(fmt
->field
, v4l2_field_names
),
516 fmt
->bytesperline
, fmt
->sizeimage
, fmt
->colorspace
);
519 static inline void v4l_print_ext_ctrls(unsigned int cmd
,
520 struct video_device
*vfd
, struct v4l2_ext_controls
*c
, int show_vals
)
524 if (!(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
))
527 printk(KERN_CONT
"class=0x%x", c
->ctrl_class
);
528 for (i
= 0; i
< c
->count
; i
++) {
529 if (show_vals
&& !c
->controls
[i
].size
)
530 printk(KERN_CONT
" id/val=0x%x/0x%x",
531 c
->controls
[i
].id
, c
->controls
[i
].value
);
533 printk(KERN_CONT
" id=0x%x,size=%u",
534 c
->controls
[i
].id
, c
->controls
[i
].size
);
536 printk(KERN_CONT
"\n");
539 static inline int check_ext_ctrls(struct v4l2_ext_controls
*c
, int allow_priv
)
543 /* zero the reserved fields */
544 c
->reserved
[0] = c
->reserved
[1] = 0;
545 for (i
= 0; i
< c
->count
; i
++)
546 c
->controls
[i
].reserved2
[0] = 0;
548 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
549 when using extended controls.
550 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
551 is it allowed for backwards compatibility.
553 if (!allow_priv
&& c
->ctrl_class
== V4L2_CID_PRIVATE_BASE
)
555 /* Check that all controls are from the same control class. */
556 for (i
= 0; i
< c
->count
; i
++) {
557 if (V4L2_CTRL_ID2CLASS(c
->controls
[i
].id
) != c
->ctrl_class
) {
565 static int check_fmt(const struct v4l2_ioctl_ops
*ops
, enum v4l2_buf_type type
)
571 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
572 if (ops
->vidioc_g_fmt_vid_cap
)
575 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
576 if (ops
->vidioc_g_fmt_vid_overlay
)
579 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
580 if (ops
->vidioc_g_fmt_vid_out
)
583 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
584 if (ops
->vidioc_g_fmt_vid_out_overlay
)
587 case V4L2_BUF_TYPE_VBI_CAPTURE
:
588 if (ops
->vidioc_g_fmt_vbi_cap
)
591 case V4L2_BUF_TYPE_VBI_OUTPUT
:
592 if (ops
->vidioc_g_fmt_vbi_out
)
595 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
596 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
599 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
600 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
603 case V4L2_BUF_TYPE_PRIVATE
:
604 if (ops
->vidioc_g_fmt_type_private
)
611 static long __video_do_ioctl(struct file
*file
,
612 unsigned int cmd
, void *arg
)
614 struct video_device
*vfd
= video_devdata(file
);
615 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
616 void *fh
= file
->private_data
;
620 printk(KERN_WARNING
"videodev: \"%s\" has no ioctl_ops.\n",
625 #ifdef CONFIG_VIDEO_V4L1_COMPAT
626 /********************************************************
627 All other V4L1 calls are handled by v4l1_compat module.
628 Those calls will be translated into V4L2 calls, and
629 __video_do_ioctl will be called again, with one or more
631 ********************************************************/
632 if (_IOC_TYPE(cmd
) == 'v' && cmd
!= VIDIOCGMBUF
&&
633 _IOC_NR(cmd
) < BASE_VIDIOCPRIVATE
) {
634 return v4l_compat_translate_ioctl(file
, cmd
, arg
,
639 if ((vfd
->debug
& V4L2_DEBUG_IOCTL
) &&
640 !(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
)) {
641 v4l_print_ioctl(vfd
->name
, cmd
);
642 printk(KERN_CONT
"\n");
647 #ifdef CONFIG_VIDEO_V4L1_COMPAT
648 /***********************************************************
649 Handles calls to the obsoleted V4L1 API
650 Due to the nature of VIDIOCGMBUF, each driver that supports
651 V4L1 should implement its own handler for this ioctl.
652 ***********************************************************/
654 /* --- streaming capture ------------------------------------- */
657 struct video_mbuf
*p
= arg
;
659 if (!ops
->vidiocgmbuf
)
661 ret
= ops
->vidiocgmbuf(file
, fh
, p
);
663 dbgarg(cmd
, "size=%d, frames=%d, offsets=0x%08lx\n",
665 (unsigned long)p
->offsets
);
670 /* --- capabilities ------------------------------------------ */
671 case VIDIOC_QUERYCAP
:
673 struct v4l2_capability
*cap
= (struct v4l2_capability
*)arg
;
675 if (!ops
->vidioc_querycap
)
678 ret
= ops
->vidioc_querycap(file
, fh
, cap
);
680 dbgarg(cmd
, "driver=%s, card=%s, bus=%s, "
682 "capabilities=0x%08x\n",
683 cap
->driver
, cap
->card
, cap
->bus_info
,
689 /* --- priority ------------------------------------------ */
690 case VIDIOC_G_PRIORITY
:
692 enum v4l2_priority
*p
= arg
;
694 if (!ops
->vidioc_g_priority
)
696 ret
= ops
->vidioc_g_priority(file
, fh
, p
);
698 dbgarg(cmd
, "priority is %d\n", *p
);
701 case VIDIOC_S_PRIORITY
:
703 enum v4l2_priority
*p
= arg
;
705 if (!ops
->vidioc_s_priority
)
707 dbgarg(cmd
, "setting priority to %d\n", *p
);
708 ret
= ops
->vidioc_s_priority(file
, fh
, *p
);
712 /* --- capture ioctls ---------------------------------------- */
713 case VIDIOC_ENUM_FMT
:
715 struct v4l2_fmtdesc
*f
= arg
;
718 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
719 if (ops
->vidioc_enum_fmt_vid_cap
)
720 ret
= ops
->vidioc_enum_fmt_vid_cap(file
, fh
, f
);
722 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
723 if (ops
->vidioc_enum_fmt_vid_overlay
)
724 ret
= ops
->vidioc_enum_fmt_vid_overlay(file
,
727 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
728 if (ops
->vidioc_enum_fmt_vid_out
)
729 ret
= ops
->vidioc_enum_fmt_vid_out(file
, fh
, f
);
731 case V4L2_BUF_TYPE_PRIVATE
:
732 if (ops
->vidioc_enum_fmt_type_private
)
733 ret
= ops
->vidioc_enum_fmt_type_private(file
,
740 dbgarg(cmd
, "index=%d, type=%d, flags=%d, "
741 "pixelformat=%c%c%c%c, description='%s'\n",
742 f
->index
, f
->type
, f
->flags
,
743 (f
->pixelformat
& 0xff),
744 (f
->pixelformat
>> 8) & 0xff,
745 (f
->pixelformat
>> 16) & 0xff,
746 (f
->pixelformat
>> 24) & 0xff,
752 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
754 /* FIXME: Should be one dump per type */
755 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
758 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
759 if (ops
->vidioc_g_fmt_vid_cap
)
760 ret
= ops
->vidioc_g_fmt_vid_cap(file
, fh
, f
);
762 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
764 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
765 if (ops
->vidioc_g_fmt_vid_overlay
)
766 ret
= ops
->vidioc_g_fmt_vid_overlay(file
,
769 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
770 if (ops
->vidioc_g_fmt_vid_out
)
771 ret
= ops
->vidioc_g_fmt_vid_out(file
, fh
, f
);
773 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
775 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
776 if (ops
->vidioc_g_fmt_vid_out_overlay
)
777 ret
= ops
->vidioc_g_fmt_vid_out_overlay(file
,
780 case V4L2_BUF_TYPE_VBI_CAPTURE
:
781 if (ops
->vidioc_g_fmt_vbi_cap
)
782 ret
= ops
->vidioc_g_fmt_vbi_cap(file
, fh
, f
);
784 case V4L2_BUF_TYPE_VBI_OUTPUT
:
785 if (ops
->vidioc_g_fmt_vbi_out
)
786 ret
= ops
->vidioc_g_fmt_vbi_out(file
, fh
, f
);
788 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
789 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
790 ret
= ops
->vidioc_g_fmt_sliced_vbi_cap(file
,
793 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
794 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
795 ret
= ops
->vidioc_g_fmt_sliced_vbi_out(file
,
798 case V4L2_BUF_TYPE_PRIVATE
:
799 if (ops
->vidioc_g_fmt_type_private
)
800 ret
= ops
->vidioc_g_fmt_type_private(file
,
809 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
811 /* FIXME: Should be one dump per type */
812 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
815 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
816 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
817 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
818 if (ops
->vidioc_s_fmt_vid_cap
)
819 ret
= ops
->vidioc_s_fmt_vid_cap(file
, fh
, f
);
821 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
822 CLEAR_AFTER_FIELD(f
, fmt
.win
);
823 if (ops
->vidioc_s_fmt_vid_overlay
)
824 ret
= ops
->vidioc_s_fmt_vid_overlay(file
,
827 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
828 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
829 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
830 if (ops
->vidioc_s_fmt_vid_out
)
831 ret
= ops
->vidioc_s_fmt_vid_out(file
, fh
, f
);
833 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
834 CLEAR_AFTER_FIELD(f
, fmt
.win
);
835 if (ops
->vidioc_s_fmt_vid_out_overlay
)
836 ret
= ops
->vidioc_s_fmt_vid_out_overlay(file
,
839 case V4L2_BUF_TYPE_VBI_CAPTURE
:
840 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
841 if (ops
->vidioc_s_fmt_vbi_cap
)
842 ret
= ops
->vidioc_s_fmt_vbi_cap(file
, fh
, f
);
844 case V4L2_BUF_TYPE_VBI_OUTPUT
:
845 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
846 if (ops
->vidioc_s_fmt_vbi_out
)
847 ret
= ops
->vidioc_s_fmt_vbi_out(file
, fh
, f
);
849 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
850 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
851 if (ops
->vidioc_s_fmt_sliced_vbi_cap
)
852 ret
= ops
->vidioc_s_fmt_sliced_vbi_cap(file
,
855 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
856 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
857 if (ops
->vidioc_s_fmt_sliced_vbi_out
)
858 ret
= ops
->vidioc_s_fmt_sliced_vbi_out(file
,
861 case V4L2_BUF_TYPE_PRIVATE
:
862 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
863 if (ops
->vidioc_s_fmt_type_private
)
864 ret
= ops
->vidioc_s_fmt_type_private(file
,
872 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
874 /* FIXME: Should be one dump per type */
875 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
,
878 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
879 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
880 if (ops
->vidioc_try_fmt_vid_cap
)
881 ret
= ops
->vidioc_try_fmt_vid_cap(file
, fh
, f
);
883 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
885 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
886 CLEAR_AFTER_FIELD(f
, fmt
.win
);
887 if (ops
->vidioc_try_fmt_vid_overlay
)
888 ret
= ops
->vidioc_try_fmt_vid_overlay(file
,
891 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
892 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
893 if (ops
->vidioc_try_fmt_vid_out
)
894 ret
= ops
->vidioc_try_fmt_vid_out(file
, fh
, f
);
896 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
898 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
899 CLEAR_AFTER_FIELD(f
, fmt
.win
);
900 if (ops
->vidioc_try_fmt_vid_out_overlay
)
901 ret
= ops
->vidioc_try_fmt_vid_out_overlay(file
,
904 case V4L2_BUF_TYPE_VBI_CAPTURE
:
905 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
906 if (ops
->vidioc_try_fmt_vbi_cap
)
907 ret
= ops
->vidioc_try_fmt_vbi_cap(file
, fh
, f
);
909 case V4L2_BUF_TYPE_VBI_OUTPUT
:
910 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
911 if (ops
->vidioc_try_fmt_vbi_out
)
912 ret
= ops
->vidioc_try_fmt_vbi_out(file
, fh
, f
);
914 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
915 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
916 if (ops
->vidioc_try_fmt_sliced_vbi_cap
)
917 ret
= ops
->vidioc_try_fmt_sliced_vbi_cap(file
,
920 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
921 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
922 if (ops
->vidioc_try_fmt_sliced_vbi_out
)
923 ret
= ops
->vidioc_try_fmt_sliced_vbi_out(file
,
926 case V4L2_BUF_TYPE_PRIVATE
:
927 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
928 if (ops
->vidioc_try_fmt_type_private
)
929 ret
= ops
->vidioc_try_fmt_type_private(file
,
936 /* FIXME: Those buf reqs could be handled here,
937 with some changes on videobuf to allow its header to be included at
938 videodev2.h or being merged at videodev2.
942 struct v4l2_requestbuffers
*p
= arg
;
944 if (!ops
->vidioc_reqbufs
)
946 ret
= check_fmt(ops
, p
->type
);
950 if (p
->type
< V4L2_BUF_TYPE_PRIVATE
)
951 CLEAR_AFTER_FIELD(p
, memory
);
953 ret
= ops
->vidioc_reqbufs(file
, fh
, p
);
954 dbgarg(cmd
, "count=%d, type=%s, memory=%s\n",
956 prt_names(p
->type
, v4l2_type_names
),
957 prt_names(p
->memory
, v4l2_memory_names
));
960 case VIDIOC_QUERYBUF
:
962 struct v4l2_buffer
*p
= arg
;
964 if (!ops
->vidioc_querybuf
)
966 ret
= check_fmt(ops
, p
->type
);
970 ret
= ops
->vidioc_querybuf(file
, fh
, p
);
977 struct v4l2_buffer
*p
= arg
;
979 if (!ops
->vidioc_qbuf
)
981 ret
= check_fmt(ops
, p
->type
);
985 ret
= ops
->vidioc_qbuf(file
, fh
, p
);
992 struct v4l2_buffer
*p
= arg
;
994 if (!ops
->vidioc_dqbuf
)
996 ret
= check_fmt(ops
, p
->type
);
1000 ret
= ops
->vidioc_dqbuf(file
, fh
, p
);
1002 dbgbuf(cmd
, vfd
, p
);
1005 case VIDIOC_OVERLAY
:
1009 if (!ops
->vidioc_overlay
)
1011 dbgarg(cmd
, "value=%d\n", *i
);
1012 ret
= ops
->vidioc_overlay(file
, fh
, *i
);
1017 struct v4l2_framebuffer
*p
= arg
;
1019 if (!ops
->vidioc_g_fbuf
)
1021 ret
= ops
->vidioc_g_fbuf(file
, fh
, arg
);
1023 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
1024 p
->capability
, p
->flags
,
1025 (unsigned long)p
->base
);
1026 v4l_print_pix_fmt(vfd
, &p
->fmt
);
1032 struct v4l2_framebuffer
*p
= arg
;
1034 if (!ops
->vidioc_s_fbuf
)
1036 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
1037 p
->capability
, p
->flags
, (unsigned long)p
->base
);
1038 v4l_print_pix_fmt(vfd
, &p
->fmt
);
1039 ret
= ops
->vidioc_s_fbuf(file
, fh
, arg
);
1042 case VIDIOC_STREAMON
:
1044 enum v4l2_buf_type i
= *(int *)arg
;
1046 if (!ops
->vidioc_streamon
)
1048 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1049 ret
= ops
->vidioc_streamon(file
, fh
, i
);
1052 case VIDIOC_STREAMOFF
:
1054 enum v4l2_buf_type i
= *(int *)arg
;
1056 if (!ops
->vidioc_streamoff
)
1058 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1059 ret
= ops
->vidioc_streamoff(file
, fh
, i
);
1062 /* ---------- tv norms ---------- */
1063 case VIDIOC_ENUMSTD
:
1065 struct v4l2_standard
*p
= arg
;
1066 v4l2_std_id id
= vfd
->tvnorms
, curr_id
= 0;
1067 unsigned int index
= p
->index
, i
, j
= 0;
1068 const char *descr
= "";
1070 /* Return norm array in a canonical way */
1071 for (i
= 0; i
<= index
&& id
; i
++) {
1072 /* last std value in the standards array is 0, so this
1073 while always ends there since (id & 0) == 0. */
1074 while ((id
& standards
[j
].std
) != standards
[j
].std
)
1076 curr_id
= standards
[j
].std
;
1077 descr
= standards
[j
].descr
;
1081 if (curr_id
!= V4L2_STD_PAL
&&
1082 curr_id
!= V4L2_STD_SECAM
&&
1083 curr_id
!= V4L2_STD_NTSC
)
1089 v4l2_video_std_construct(p
, curr_id
, descr
);
1091 dbgarg(cmd
, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1092 "framelines=%d\n", p
->index
,
1093 (unsigned long long)p
->id
, p
->name
,
1094 p
->frameperiod
.numerator
,
1095 p
->frameperiod
.denominator
,
1103 v4l2_std_id
*id
= arg
;
1106 /* Calls the specific handler */
1107 if (ops
->vidioc_g_std
)
1108 ret
= ops
->vidioc_g_std(file
, fh
, id
);
1109 else if (vfd
->current_norm
)
1110 *id
= vfd
->current_norm
;
1115 dbgarg(cmd
, "std=0x%08Lx\n", (long long unsigned)*id
);
1120 v4l2_std_id
*id
= arg
, norm
;
1122 dbgarg(cmd
, "std=%08Lx\n", (long long unsigned)*id
);
1124 norm
= (*id
) & vfd
->tvnorms
;
1125 if (vfd
->tvnorms
&& !norm
) /* Check if std is supported */
1128 /* Calls the specific handler */
1129 if (ops
->vidioc_s_std
)
1130 ret
= ops
->vidioc_s_std(file
, fh
, &norm
);
1134 /* Updates standard information */
1136 vfd
->current_norm
= norm
;
1139 case VIDIOC_QUERYSTD
:
1141 v4l2_std_id
*p
= arg
;
1143 if (!ops
->vidioc_querystd
)
1145 ret
= ops
->vidioc_querystd(file
, fh
, arg
);
1147 dbgarg(cmd
, "detected std=%08Lx\n",
1148 (unsigned long long)*p
);
1151 /* ------ input switching ---------- */
1152 /* FIXME: Inputs can be handled inside videodev2 */
1153 case VIDIOC_ENUMINPUT
:
1155 struct v4l2_input
*p
= arg
;
1158 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1159 * CAP_STD here based on ioctl handler provided by the
1160 * driver. If the driver doesn't support these
1161 * for a specific input, it must override these flags.
1163 if (ops
->vidioc_s_std
)
1164 p
->capabilities
|= V4L2_IN_CAP_STD
;
1165 if (ops
->vidioc_s_dv_preset
)
1166 p
->capabilities
|= V4L2_IN_CAP_PRESETS
;
1167 if (ops
->vidioc_s_dv_timings
)
1168 p
->capabilities
|= V4L2_IN_CAP_CUSTOM_TIMINGS
;
1170 if (!ops
->vidioc_enum_input
)
1173 ret
= ops
->vidioc_enum_input(file
, fh
, p
);
1175 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1177 "tuner=%d, std=%08Lx, status=%d\n",
1178 p
->index
, p
->name
, p
->type
, p
->audioset
,
1180 (unsigned long long)p
->std
,
1184 case VIDIOC_G_INPUT
:
1186 unsigned int *i
= arg
;
1188 if (!ops
->vidioc_g_input
)
1190 ret
= ops
->vidioc_g_input(file
, fh
, i
);
1192 dbgarg(cmd
, "value=%d\n", *i
);
1195 case VIDIOC_S_INPUT
:
1197 unsigned int *i
= arg
;
1199 if (!ops
->vidioc_s_input
)
1201 dbgarg(cmd
, "value=%d\n", *i
);
1202 ret
= ops
->vidioc_s_input(file
, fh
, *i
);
1206 /* ------ output switching ---------- */
1207 case VIDIOC_ENUMOUTPUT
:
1209 struct v4l2_output
*p
= arg
;
1211 if (!ops
->vidioc_enum_output
)
1215 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1216 * CAP_STD here based on ioctl handler provided by the
1217 * driver. If the driver doesn't support these
1218 * for a specific output, it must override these flags.
1220 if (ops
->vidioc_s_std
)
1221 p
->capabilities
|= V4L2_OUT_CAP_STD
;
1222 if (ops
->vidioc_s_dv_preset
)
1223 p
->capabilities
|= V4L2_OUT_CAP_PRESETS
;
1224 if (ops
->vidioc_s_dv_timings
)
1225 p
->capabilities
|= V4L2_OUT_CAP_CUSTOM_TIMINGS
;
1227 ret
= ops
->vidioc_enum_output(file
, fh
, p
);
1229 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1231 "modulator=%d, std=0x%08Lx\n",
1232 p
->index
, p
->name
, p
->type
, p
->audioset
,
1233 p
->modulator
, (unsigned long long)p
->std
);
1236 case VIDIOC_G_OUTPUT
:
1238 unsigned int *i
= arg
;
1240 if (!ops
->vidioc_g_output
)
1242 ret
= ops
->vidioc_g_output(file
, fh
, i
);
1244 dbgarg(cmd
, "value=%d\n", *i
);
1247 case VIDIOC_S_OUTPUT
:
1249 unsigned int *i
= arg
;
1251 if (!ops
->vidioc_s_output
)
1253 dbgarg(cmd
, "value=%d\n", *i
);
1254 ret
= ops
->vidioc_s_output(file
, fh
, *i
);
1258 /* --- controls ---------------------------------------------- */
1259 case VIDIOC_QUERYCTRL
:
1261 struct v4l2_queryctrl
*p
= arg
;
1263 if (vfd
->ctrl_handler
)
1264 ret
= v4l2_queryctrl(vfd
->ctrl_handler
, p
);
1265 else if (ops
->vidioc_queryctrl
)
1266 ret
= ops
->vidioc_queryctrl(file
, fh
, p
);
1270 dbgarg(cmd
, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1271 "step=%d, default=%d, flags=0x%08x\n",
1272 p
->id
, p
->type
, p
->name
,
1273 p
->minimum
, p
->maximum
,
1274 p
->step
, p
->default_value
, p
->flags
);
1276 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1281 struct v4l2_control
*p
= arg
;
1283 if (vfd
->ctrl_handler
)
1284 ret
= v4l2_g_ctrl(vfd
->ctrl_handler
, p
);
1285 else if (ops
->vidioc_g_ctrl
)
1286 ret
= ops
->vidioc_g_ctrl(file
, fh
, p
);
1287 else if (ops
->vidioc_g_ext_ctrls
) {
1288 struct v4l2_ext_controls ctrls
;
1289 struct v4l2_ext_control ctrl
;
1291 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1293 ctrls
.controls
= &ctrl
;
1295 ctrl
.value
= p
->value
;
1296 if (check_ext_ctrls(&ctrls
, 1)) {
1297 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, &ctrls
);
1299 p
->value
= ctrl
.value
;
1304 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1306 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1311 struct v4l2_control
*p
= arg
;
1312 struct v4l2_ext_controls ctrls
;
1313 struct v4l2_ext_control ctrl
;
1315 if (!vfd
->ctrl_handler
&&
1316 !ops
->vidioc_s_ctrl
&& !ops
->vidioc_s_ext_ctrls
)
1319 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1321 if (vfd
->ctrl_handler
) {
1322 ret
= v4l2_s_ctrl(vfd
->ctrl_handler
, p
);
1325 if (ops
->vidioc_s_ctrl
) {
1326 ret
= ops
->vidioc_s_ctrl(file
, fh
, p
);
1329 if (!ops
->vidioc_s_ext_ctrls
)
1332 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1334 ctrls
.controls
= &ctrl
;
1336 ctrl
.value
= p
->value
;
1337 if (check_ext_ctrls(&ctrls
, 1))
1338 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, &ctrls
);
1341 case VIDIOC_G_EXT_CTRLS
:
1343 struct v4l2_ext_controls
*p
= arg
;
1345 p
->error_idx
= p
->count
;
1346 if (vfd
->ctrl_handler
)
1347 ret
= v4l2_g_ext_ctrls(vfd
->ctrl_handler
, p
);
1348 else if (ops
->vidioc_g_ext_ctrls
&& check_ext_ctrls(p
, 0))
1349 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, p
);
1352 v4l_print_ext_ctrls(cmd
, vfd
, p
, !ret
);
1355 case VIDIOC_S_EXT_CTRLS
:
1357 struct v4l2_ext_controls
*p
= arg
;
1359 p
->error_idx
= p
->count
;
1360 if (!vfd
->ctrl_handler
&& !ops
->vidioc_s_ext_ctrls
)
1362 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1363 if (vfd
->ctrl_handler
)
1364 ret
= v4l2_s_ext_ctrls(vfd
->ctrl_handler
, p
);
1365 else if (check_ext_ctrls(p
, 0))
1366 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, p
);
1369 case VIDIOC_TRY_EXT_CTRLS
:
1371 struct v4l2_ext_controls
*p
= arg
;
1373 p
->error_idx
= p
->count
;
1374 if (!vfd
->ctrl_handler
&& !ops
->vidioc_try_ext_ctrls
)
1376 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1377 if (vfd
->ctrl_handler
)
1378 ret
= v4l2_try_ext_ctrls(vfd
->ctrl_handler
, p
);
1379 else if (check_ext_ctrls(p
, 0))
1380 ret
= ops
->vidioc_try_ext_ctrls(file
, fh
, p
);
1383 case VIDIOC_QUERYMENU
:
1385 struct v4l2_querymenu
*p
= arg
;
1387 if (vfd
->ctrl_handler
)
1388 ret
= v4l2_querymenu(vfd
->ctrl_handler
, p
);
1389 else if (ops
->vidioc_querymenu
)
1390 ret
= ops
->vidioc_querymenu(file
, fh
, p
);
1394 dbgarg(cmd
, "id=0x%x, index=%d, name=%s\n",
1395 p
->id
, p
->index
, p
->name
);
1397 dbgarg(cmd
, "id=0x%x, index=%d\n",
1401 /* --- audio ---------------------------------------------- */
1402 case VIDIOC_ENUMAUDIO
:
1404 struct v4l2_audio
*p
= arg
;
1406 if (!ops
->vidioc_enumaudio
)
1408 ret
= ops
->vidioc_enumaudio(file
, fh
, p
);
1410 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1411 "mode=0x%x\n", p
->index
, p
->name
,
1412 p
->capability
, p
->mode
);
1414 dbgarg(cmd
, "index=%d\n", p
->index
);
1417 case VIDIOC_G_AUDIO
:
1419 struct v4l2_audio
*p
= arg
;
1421 if (!ops
->vidioc_g_audio
)
1424 ret
= ops
->vidioc_g_audio(file
, fh
, p
);
1426 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1427 "mode=0x%x\n", p
->index
,
1428 p
->name
, p
->capability
, p
->mode
);
1430 dbgarg(cmd
, "index=%d\n", p
->index
);
1433 case VIDIOC_S_AUDIO
:
1435 struct v4l2_audio
*p
= arg
;
1437 if (!ops
->vidioc_s_audio
)
1439 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1440 "mode=0x%x\n", p
->index
, p
->name
,
1441 p
->capability
, p
->mode
);
1442 ret
= ops
->vidioc_s_audio(file
, fh
, p
);
1445 case VIDIOC_ENUMAUDOUT
:
1447 struct v4l2_audioout
*p
= arg
;
1449 if (!ops
->vidioc_enumaudout
)
1451 dbgarg(cmd
, "Enum for index=%d\n", p
->index
);
1452 ret
= ops
->vidioc_enumaudout(file
, fh
, p
);
1454 dbgarg2("index=%d, name=%s, capability=%d, "
1455 "mode=%d\n", p
->index
, p
->name
,
1456 p
->capability
, p
->mode
);
1459 case VIDIOC_G_AUDOUT
:
1461 struct v4l2_audioout
*p
= arg
;
1463 if (!ops
->vidioc_g_audout
)
1466 ret
= ops
->vidioc_g_audout(file
, fh
, p
);
1468 dbgarg2("index=%d, name=%s, capability=%d, "
1469 "mode=%d\n", p
->index
, p
->name
,
1470 p
->capability
, p
->mode
);
1473 case VIDIOC_S_AUDOUT
:
1475 struct v4l2_audioout
*p
= arg
;
1477 if (!ops
->vidioc_s_audout
)
1479 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1480 "mode=%d\n", p
->index
, p
->name
,
1481 p
->capability
, p
->mode
);
1483 ret
= ops
->vidioc_s_audout(file
, fh
, p
);
1486 case VIDIOC_G_MODULATOR
:
1488 struct v4l2_modulator
*p
= arg
;
1490 if (!ops
->vidioc_g_modulator
)
1492 ret
= ops
->vidioc_g_modulator(file
, fh
, p
);
1494 dbgarg(cmd
, "index=%d, name=%s, "
1495 "capability=%d, rangelow=%d,"
1496 " rangehigh=%d, txsubchans=%d\n",
1497 p
->index
, p
->name
, p
->capability
,
1498 p
->rangelow
, p
->rangehigh
,
1502 case VIDIOC_S_MODULATOR
:
1504 struct v4l2_modulator
*p
= arg
;
1506 if (!ops
->vidioc_s_modulator
)
1508 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1509 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1510 p
->index
, p
->name
, p
->capability
, p
->rangelow
,
1511 p
->rangehigh
, p
->txsubchans
);
1512 ret
= ops
->vidioc_s_modulator(file
, fh
, p
);
1517 struct v4l2_crop
*p
= arg
;
1519 if (!ops
->vidioc_g_crop
)
1522 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1523 ret
= ops
->vidioc_g_crop(file
, fh
, p
);
1525 dbgrect(vfd
, "", &p
->c
);
1530 struct v4l2_crop
*p
= arg
;
1532 if (!ops
->vidioc_s_crop
)
1534 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1535 dbgrect(vfd
, "", &p
->c
);
1536 ret
= ops
->vidioc_s_crop(file
, fh
, p
);
1539 case VIDIOC_CROPCAP
:
1541 struct v4l2_cropcap
*p
= arg
;
1543 /*FIXME: Should also show v4l2_fract pixelaspect */
1544 if (!ops
->vidioc_cropcap
)
1547 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1548 ret
= ops
->vidioc_cropcap(file
, fh
, p
);
1550 dbgrect(vfd
, "bounds ", &p
->bounds
);
1551 dbgrect(vfd
, "defrect ", &p
->defrect
);
1555 case VIDIOC_G_JPEGCOMP
:
1557 struct v4l2_jpegcompression
*p
= arg
;
1559 if (!ops
->vidioc_g_jpegcomp
)
1562 ret
= ops
->vidioc_g_jpegcomp(file
, fh
, p
);
1564 dbgarg(cmd
, "quality=%d, APPn=%d, "
1565 "APP_len=%d, COM_len=%d, "
1566 "jpeg_markers=%d\n",
1567 p
->quality
, p
->APPn
, p
->APP_len
,
1568 p
->COM_len
, p
->jpeg_markers
);
1571 case VIDIOC_S_JPEGCOMP
:
1573 struct v4l2_jpegcompression
*p
= arg
;
1575 if (!ops
->vidioc_g_jpegcomp
)
1577 dbgarg(cmd
, "quality=%d, APPn=%d, APP_len=%d, "
1578 "COM_len=%d, jpeg_markers=%d\n",
1579 p
->quality
, p
->APPn
, p
->APP_len
,
1580 p
->COM_len
, p
->jpeg_markers
);
1581 ret
= ops
->vidioc_s_jpegcomp(file
, fh
, p
);
1584 case VIDIOC_G_ENC_INDEX
:
1586 struct v4l2_enc_idx
*p
= arg
;
1588 if (!ops
->vidioc_g_enc_index
)
1590 ret
= ops
->vidioc_g_enc_index(file
, fh
, p
);
1592 dbgarg(cmd
, "entries=%d, entries_cap=%d\n",
1593 p
->entries
, p
->entries_cap
);
1596 case VIDIOC_ENCODER_CMD
:
1598 struct v4l2_encoder_cmd
*p
= arg
;
1600 if (!ops
->vidioc_encoder_cmd
)
1602 ret
= ops
->vidioc_encoder_cmd(file
, fh
, p
);
1604 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1607 case VIDIOC_TRY_ENCODER_CMD
:
1609 struct v4l2_encoder_cmd
*p
= arg
;
1611 if (!ops
->vidioc_try_encoder_cmd
)
1613 ret
= ops
->vidioc_try_encoder_cmd(file
, fh
, p
);
1615 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1620 struct v4l2_streamparm
*p
= arg
;
1622 if (ops
->vidioc_g_parm
) {
1623 ret
= check_fmt(ops
, p
->type
);
1626 ret
= ops
->vidioc_g_parm(file
, fh
, p
);
1628 v4l2_std_id std
= vfd
->current_norm
;
1630 if (p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1634 if (ops
->vidioc_g_std
)
1635 ret
= ops
->vidioc_g_std(file
, fh
, &std
);
1639 v4l2_video_std_frame_period(std
,
1640 &p
->parm
.capture
.timeperframe
);
1643 dbgarg(cmd
, "type=%d\n", p
->type
);
1648 struct v4l2_streamparm
*p
= arg
;
1650 if (!ops
->vidioc_s_parm
)
1652 ret
= check_fmt(ops
, p
->type
);
1656 dbgarg(cmd
, "type=%d\n", p
->type
);
1657 ret
= ops
->vidioc_s_parm(file
, fh
, p
);
1660 case VIDIOC_G_TUNER
:
1662 struct v4l2_tuner
*p
= arg
;
1664 if (!ops
->vidioc_g_tuner
)
1667 ret
= ops
->vidioc_g_tuner(file
, fh
, p
);
1669 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1670 "capability=0x%x, rangelow=%d, "
1671 "rangehigh=%d, signal=%d, afc=%d, "
1672 "rxsubchans=0x%x, audmode=%d\n",
1673 p
->index
, p
->name
, p
->type
,
1674 p
->capability
, p
->rangelow
,
1675 p
->rangehigh
, p
->signal
, p
->afc
,
1676 p
->rxsubchans
, p
->audmode
);
1679 case VIDIOC_S_TUNER
:
1681 struct v4l2_tuner
*p
= arg
;
1683 if (!ops
->vidioc_s_tuner
)
1685 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1686 "capability=0x%x, rangelow=%d, "
1687 "rangehigh=%d, signal=%d, afc=%d, "
1688 "rxsubchans=0x%x, audmode=%d\n",
1689 p
->index
, p
->name
, p
->type
,
1690 p
->capability
, p
->rangelow
,
1691 p
->rangehigh
, p
->signal
, p
->afc
,
1692 p
->rxsubchans
, p
->audmode
);
1693 ret
= ops
->vidioc_s_tuner(file
, fh
, p
);
1696 case VIDIOC_G_FREQUENCY
:
1698 struct v4l2_frequency
*p
= arg
;
1700 if (!ops
->vidioc_g_frequency
)
1703 ret
= ops
->vidioc_g_frequency(file
, fh
, p
);
1705 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1706 p
->tuner
, p
->type
, p
->frequency
);
1709 case VIDIOC_S_FREQUENCY
:
1711 struct v4l2_frequency
*p
= arg
;
1713 if (!ops
->vidioc_s_frequency
)
1715 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1716 p
->tuner
, p
->type
, p
->frequency
);
1717 ret
= ops
->vidioc_s_frequency(file
, fh
, p
);
1720 case VIDIOC_G_SLICED_VBI_CAP
:
1722 struct v4l2_sliced_vbi_cap
*p
= arg
;
1724 if (!ops
->vidioc_g_sliced_vbi_cap
)
1727 /* Clear up to type, everything after type is zerod already */
1728 memset(p
, 0, offsetof(struct v4l2_sliced_vbi_cap
, type
));
1730 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1731 ret
= ops
->vidioc_g_sliced_vbi_cap(file
, fh
, p
);
1733 dbgarg2("service_set=%d\n", p
->service_set
);
1736 case VIDIOC_LOG_STATUS
:
1738 if (!ops
->vidioc_log_status
)
1740 ret
= ops
->vidioc_log_status(file
, fh
);
1743 #ifdef CONFIG_VIDEO_ADV_DEBUG
1744 case VIDIOC_DBG_G_REGISTER
:
1746 struct v4l2_dbg_register
*p
= arg
;
1748 if (!capable(CAP_SYS_ADMIN
))
1750 else if (ops
->vidioc_g_register
)
1751 ret
= ops
->vidioc_g_register(file
, fh
, p
);
1754 case VIDIOC_DBG_S_REGISTER
:
1756 struct v4l2_dbg_register
*p
= arg
;
1758 if (!capable(CAP_SYS_ADMIN
))
1760 else if (ops
->vidioc_s_register
)
1761 ret
= ops
->vidioc_s_register(file
, fh
, p
);
1765 case VIDIOC_DBG_G_CHIP_IDENT
:
1767 struct v4l2_dbg_chip_ident
*p
= arg
;
1769 if (!ops
->vidioc_g_chip_ident
)
1771 p
->ident
= V4L2_IDENT_NONE
;
1773 ret
= ops
->vidioc_g_chip_ident(file
, fh
, p
);
1775 dbgarg(cmd
, "chip_ident=%u, revision=0x%x\n", p
->ident
, p
->revision
);
1778 case VIDIOC_S_HW_FREQ_SEEK
:
1780 struct v4l2_hw_freq_seek
*p
= arg
;
1782 if (!ops
->vidioc_s_hw_freq_seek
)
1785 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1786 p
->tuner
, p
->type
, p
->seek_upward
, p
->wrap_around
);
1787 ret
= ops
->vidioc_s_hw_freq_seek(file
, fh
, p
);
1790 case VIDIOC_ENUM_FRAMESIZES
:
1792 struct v4l2_frmsizeenum
*p
= arg
;
1794 if (!ops
->vidioc_enum_framesizes
)
1797 ret
= ops
->vidioc_enum_framesizes(file
, fh
, p
);
1799 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1801 (p
->pixel_format
& 0xff),
1802 (p
->pixel_format
>> 8) & 0xff,
1803 (p
->pixel_format
>> 16) & 0xff,
1804 (p
->pixel_format
>> 24) & 0xff,
1807 case V4L2_FRMSIZE_TYPE_DISCRETE
:
1808 dbgarg3("width = %d, height=%d\n",
1809 p
->discrete
.width
, p
->discrete
.height
);
1811 case V4L2_FRMSIZE_TYPE_STEPWISE
:
1812 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1813 p
->stepwise
.min_width
, p
->stepwise
.min_height
,
1814 p
->stepwise
.step_width
, p
->stepwise
.step_height
,
1815 p
->stepwise
.max_width
, p
->stepwise
.max_height
);
1817 case V4L2_FRMSIZE_TYPE_CONTINUOUS
:
1818 dbgarg3("continuous\n");
1821 dbgarg3("- Unknown type!\n");
1826 case VIDIOC_ENUM_FRAMEINTERVALS
:
1828 struct v4l2_frmivalenum
*p
= arg
;
1830 if (!ops
->vidioc_enum_frameintervals
)
1833 ret
= ops
->vidioc_enum_frameintervals(file
, fh
, p
);
1835 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1836 p
->index
, p
->pixel_format
,
1837 p
->width
, p
->height
, p
->type
);
1839 case V4L2_FRMIVAL_TYPE_DISCRETE
:
1840 dbgarg2("fps=%d/%d\n",
1841 p
->discrete
.numerator
,
1842 p
->discrete
.denominator
);
1844 case V4L2_FRMIVAL_TYPE_STEPWISE
:
1845 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1846 p
->stepwise
.min
.numerator
,
1847 p
->stepwise
.min
.denominator
,
1848 p
->stepwise
.max
.numerator
,
1849 p
->stepwise
.max
.denominator
,
1850 p
->stepwise
.step
.numerator
,
1851 p
->stepwise
.step
.denominator
);
1853 case V4L2_FRMIVAL_TYPE_CONTINUOUS
:
1854 dbgarg2("continuous\n");
1857 dbgarg2("- Unknown type!\n");
1861 case VIDIOC_ENUM_DV_PRESETS
:
1863 struct v4l2_dv_enum_preset
*p
= arg
;
1865 if (!ops
->vidioc_enum_dv_presets
)
1868 ret
= ops
->vidioc_enum_dv_presets(file
, fh
, p
);
1871 "index=%d, preset=%d, name=%s, width=%d,"
1873 p
->index
, p
->preset
, p
->name
, p
->width
,
1877 case VIDIOC_S_DV_PRESET
:
1879 struct v4l2_dv_preset
*p
= arg
;
1881 if (!ops
->vidioc_s_dv_preset
)
1884 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1885 ret
= ops
->vidioc_s_dv_preset(file
, fh
, p
);
1888 case VIDIOC_G_DV_PRESET
:
1890 struct v4l2_dv_preset
*p
= arg
;
1892 if (!ops
->vidioc_g_dv_preset
)
1895 ret
= ops
->vidioc_g_dv_preset(file
, fh
, p
);
1897 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1900 case VIDIOC_QUERY_DV_PRESET
:
1902 struct v4l2_dv_preset
*p
= arg
;
1904 if (!ops
->vidioc_query_dv_preset
)
1907 ret
= ops
->vidioc_query_dv_preset(file
, fh
, p
);
1909 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1912 case VIDIOC_S_DV_TIMINGS
:
1914 struct v4l2_dv_timings
*p
= arg
;
1916 if (!ops
->vidioc_s_dv_timings
)
1920 case V4L2_DV_BT_656_1120
:
1921 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
1922 " width=%d, height=%d, polarities=%x,"
1923 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
1924 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
1925 " il_vfrontporch=%d, il_vsync=%d,"
1926 " il_vbackporch=%d\n",
1927 p
->bt
.interlaced
, p
->bt
.pixelclock
,
1928 p
->bt
.width
, p
->bt
.height
, p
->bt
.polarities
,
1929 p
->bt
.hfrontporch
, p
->bt
.hsync
,
1930 p
->bt
.hbackporch
, p
->bt
.vfrontporch
,
1931 p
->bt
.vsync
, p
->bt
.vbackporch
,
1932 p
->bt
.il_vfrontporch
, p
->bt
.il_vsync
,
1933 p
->bt
.il_vbackporch
);
1934 ret
= ops
->vidioc_s_dv_timings(file
, fh
, p
);
1937 dbgarg2("Unknown type %d!\n", p
->type
);
1942 case VIDIOC_G_DV_TIMINGS
:
1944 struct v4l2_dv_timings
*p
= arg
;
1946 if (!ops
->vidioc_g_dv_timings
)
1949 ret
= ops
->vidioc_g_dv_timings(file
, fh
, p
);
1952 case V4L2_DV_BT_656_1120
:
1953 dbgarg2("bt-656/1120:interlaced=%d,"
1955 " width=%d, height=%d, polarities=%x,"
1956 " hfrontporch=%d, hsync=%d,"
1957 " hbackporch=%d, vfrontporch=%d,"
1958 " vsync=%d, vbackporch=%d,"
1959 " il_vfrontporch=%d, il_vsync=%d,"
1960 " il_vbackporch=%d\n",
1961 p
->bt
.interlaced
, p
->bt
.pixelclock
,
1962 p
->bt
.width
, p
->bt
.height
,
1963 p
->bt
.polarities
, p
->bt
.hfrontporch
,
1964 p
->bt
.hsync
, p
->bt
.hbackporch
,
1965 p
->bt
.vfrontporch
, p
->bt
.vsync
,
1966 p
->bt
.vbackporch
, p
->bt
.il_vfrontporch
,
1967 p
->bt
.il_vsync
, p
->bt
.il_vbackporch
);
1970 dbgarg2("Unknown type %d!\n", p
->type
);
1976 case VIDIOC_DQEVENT
:
1978 struct v4l2_event
*ev
= arg
;
1980 if (!ops
->vidioc_subscribe_event
)
1983 ret
= v4l2_event_dequeue(fh
, ev
, file
->f_flags
& O_NONBLOCK
);
1985 dbgarg(cmd
, "no pending events?");
1989 "pending=%d, type=0x%8.8x, sequence=%d, "
1990 "timestamp=%lu.%9.9lu ",
1991 ev
->pending
, ev
->type
, ev
->sequence
,
1992 ev
->timestamp
.tv_sec
, ev
->timestamp
.tv_nsec
);
1995 case VIDIOC_SUBSCRIBE_EVENT
:
1997 struct v4l2_event_subscription
*sub
= arg
;
1999 if (!ops
->vidioc_subscribe_event
)
2002 ret
= ops
->vidioc_subscribe_event(fh
, sub
);
2004 dbgarg(cmd
, "failed, ret=%ld", ret
);
2007 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
2010 case VIDIOC_UNSUBSCRIBE_EVENT
:
2012 struct v4l2_event_subscription
*sub
= arg
;
2014 if (!ops
->vidioc_unsubscribe_event
)
2017 ret
= ops
->vidioc_unsubscribe_event(fh
, sub
);
2019 dbgarg(cmd
, "failed, ret=%ld", ret
);
2022 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
2027 if (!ops
->vidioc_default
)
2029 ret
= ops
->vidioc_default(file
, fh
, cmd
, arg
);
2034 if (vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
) {
2036 v4l_print_ioctl(vfd
->name
, cmd
);
2037 printk(KERN_CONT
" error %ld\n", ret
);
2044 /* In some cases, only a few fields are used as input, i.e. when the app sets
2045 * "index" and then the driver fills in the rest of the structure for the thing
2046 * with that index. We only need to copy up the first non-input field. */
2047 static unsigned long cmd_input_size(unsigned int cmd
)
2049 /* Size of structure up to and including 'field' */
2050 #define CMDINSIZE(cmd, type, field) \
2051 case VIDIOC_##cmd: \
2052 return offsetof(struct v4l2_##type, field) + \
2053 sizeof(((struct v4l2_##type *)0)->field);
2056 CMDINSIZE(ENUM_FMT
, fmtdesc
, type
);
2057 CMDINSIZE(G_FMT
, format
, type
);
2058 CMDINSIZE(QUERYBUF
, buffer
, type
);
2059 CMDINSIZE(G_PARM
, streamparm
, type
);
2060 CMDINSIZE(ENUMSTD
, standard
, index
);
2061 CMDINSIZE(ENUMINPUT
, input
, index
);
2062 CMDINSIZE(G_CTRL
, control
, id
);
2063 CMDINSIZE(G_TUNER
, tuner
, index
);
2064 CMDINSIZE(QUERYCTRL
, queryctrl
, id
);
2065 CMDINSIZE(QUERYMENU
, querymenu
, index
);
2066 CMDINSIZE(ENUMOUTPUT
, output
, index
);
2067 CMDINSIZE(G_MODULATOR
, modulator
, index
);
2068 CMDINSIZE(G_FREQUENCY
, frequency
, tuner
);
2069 CMDINSIZE(CROPCAP
, cropcap
, type
);
2070 CMDINSIZE(G_CROP
, crop
, type
);
2071 CMDINSIZE(ENUMAUDIO
, audio
, index
);
2072 CMDINSIZE(ENUMAUDOUT
, audioout
, index
);
2073 CMDINSIZE(ENCODER_CMD
, encoder_cmd
, flags
);
2074 CMDINSIZE(TRY_ENCODER_CMD
, encoder_cmd
, flags
);
2075 CMDINSIZE(G_SLICED_VBI_CAP
, sliced_vbi_cap
, type
);
2076 CMDINSIZE(ENUM_FRAMESIZES
, frmsizeenum
, pixel_format
);
2077 CMDINSIZE(ENUM_FRAMEINTERVALS
, frmivalenum
, height
);
2079 return _IOC_SIZE(cmd
);
2083 long video_ioctl2(struct file
*file
,
2084 unsigned int cmd
, unsigned long arg
)
2088 void *parg
= (void *)arg
;
2091 size_t ctrls_size
= 0;
2092 void __user
*user_ptr
= NULL
;
2094 #ifdef __OLD_VIDIOC_
2095 cmd
= video_fix_command(cmd
);
2097 is_ext_ctrl
= (cmd
== VIDIOC_S_EXT_CTRLS
|| cmd
== VIDIOC_G_EXT_CTRLS
||
2098 cmd
== VIDIOC_TRY_EXT_CTRLS
);
2100 /* Copy arguments into temp kernel buffer */
2101 if (_IOC_DIR(cmd
) != _IOC_NONE
) {
2102 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
2105 /* too big to allocate from stack */
2106 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
2113 if (_IOC_DIR(cmd
) & _IOC_WRITE
) {
2114 unsigned long n
= cmd_input_size(cmd
);
2116 if (copy_from_user(parg
, (void __user
*)arg
, n
))
2119 /* zero out anything we don't copy from userspace */
2120 if (n
< _IOC_SIZE(cmd
))
2121 memset((u8
*)parg
+ n
, 0, _IOC_SIZE(cmd
) - n
);
2123 /* read-only ioctl */
2124 memset(parg
, 0, _IOC_SIZE(cmd
));
2129 struct v4l2_ext_controls
*p
= parg
;
2131 /* In case of an error, tell the caller that it wasn't
2132 a specific control that caused it. */
2133 p
->error_idx
= p
->count
;
2134 user_ptr
= (void __user
*)p
->controls
;
2136 ctrls_size
= sizeof(struct v4l2_ext_control
) * p
->count
;
2137 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
2138 mbuf
= kmalloc(ctrls_size
, GFP_KERNEL
);
2143 if (copy_from_user(mbuf
, user_ptr
, ctrls_size
))
2150 err
= __video_do_ioctl(file
, cmd
, parg
);
2151 if (err
== -ENOIOCTLCMD
)
2154 struct v4l2_ext_controls
*p
= parg
;
2156 p
->controls
= (void *)user_ptr
;
2157 if (p
->count
&& err
== 0 && copy_to_user(user_ptr
, mbuf
, ctrls_size
))
2165 /* Copy results into user buffer */
2166 switch (_IOC_DIR(cmd
)) {
2168 case (_IOC_WRITE
| _IOC_READ
):
2169 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
2178 EXPORT_SYMBOL(video_ioctl2
);