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-fh.h>
30 #include <media/v4l2-event.h>
31 #include <media/v4l2-chip-ident.h>
33 #define dbgarg(cmd, fmt, arg...) \
35 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
36 printk(KERN_DEBUG "%s: ", vfd->name); \
37 v4l_printk_ioctl(cmd); \
38 printk(" " fmt, ## arg); \
42 #define dbgarg2(fmt, arg...) \
44 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
45 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
48 #define dbgarg3(fmt, arg...) \
50 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
51 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
54 /* Zero out the end of the struct pointed to by p. Everthing after, but
55 * not including, the specified field is cleared. */
56 #define CLEAR_AFTER_FIELD(p, field) \
57 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
58 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
65 static const struct std_descr standards
[] = {
66 { V4L2_STD_NTSC
, "NTSC" },
67 { V4L2_STD_NTSC_M
, "NTSC-M" },
68 { V4L2_STD_NTSC_M_JP
, "NTSC-M-JP" },
69 { V4L2_STD_NTSC_M_KR
, "NTSC-M-KR" },
70 { V4L2_STD_NTSC_443
, "NTSC-443" },
71 { V4L2_STD_PAL
, "PAL" },
72 { V4L2_STD_PAL_BG
, "PAL-BG" },
73 { V4L2_STD_PAL_B
, "PAL-B" },
74 { V4L2_STD_PAL_B1
, "PAL-B1" },
75 { V4L2_STD_PAL_G
, "PAL-G" },
76 { V4L2_STD_PAL_H
, "PAL-H" },
77 { V4L2_STD_PAL_I
, "PAL-I" },
78 { V4L2_STD_PAL_DK
, "PAL-DK" },
79 { V4L2_STD_PAL_D
, "PAL-D" },
80 { V4L2_STD_PAL_D1
, "PAL-D1" },
81 { V4L2_STD_PAL_K
, "PAL-K" },
82 { V4L2_STD_PAL_M
, "PAL-M" },
83 { V4L2_STD_PAL_N
, "PAL-N" },
84 { V4L2_STD_PAL_Nc
, "PAL-Nc" },
85 { V4L2_STD_PAL_60
, "PAL-60" },
86 { V4L2_STD_SECAM
, "SECAM" },
87 { V4L2_STD_SECAM_B
, "SECAM-B" },
88 { V4L2_STD_SECAM_G
, "SECAM-G" },
89 { V4L2_STD_SECAM_H
, "SECAM-H" },
90 { V4L2_STD_SECAM_DK
, "SECAM-DK" },
91 { V4L2_STD_SECAM_D
, "SECAM-D" },
92 { V4L2_STD_SECAM_K
, "SECAM-K" },
93 { V4L2_STD_SECAM_K1
, "SECAM-K1" },
94 { V4L2_STD_SECAM_L
, "SECAM-L" },
95 { V4L2_STD_SECAM_LC
, "SECAM-Lc" },
99 /* video4linux standard ID conversion to standard name
101 const char *v4l2_norm_to_name(v4l2_std_id id
)
106 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
107 64 bit comparations. So, on that architecture, with some gcc
108 variants, compilation fails. Currently, the max value is 30bit wide.
112 for (i
= 0; standards
[i
].std
; i
++)
113 if (myid
== standards
[i
].std
)
115 return standards
[i
].descr
;
117 EXPORT_SYMBOL(v4l2_norm_to_name
);
119 /* Returns frame period for the given standard */
120 void v4l2_video_std_frame_period(int id
, struct v4l2_fract
*frameperiod
)
122 if (id
& V4L2_STD_525_60
) {
123 frameperiod
->numerator
= 1001;
124 frameperiod
->denominator
= 30000;
126 frameperiod
->numerator
= 1;
127 frameperiod
->denominator
= 25;
130 EXPORT_SYMBOL(v4l2_video_std_frame_period
);
132 /* Fill in the fields of a v4l2_standard structure according to the
133 'id' and 'transmission' parameters. Returns negative on error. */
134 int v4l2_video_std_construct(struct v4l2_standard
*vs
,
135 int id
, const char *name
)
138 v4l2_video_std_frame_period(id
, &vs
->frameperiod
);
139 vs
->framelines
= (id
& V4L2_STD_525_60
) ? 525 : 625;
140 strlcpy(vs
->name
, name
, sizeof(vs
->name
));
143 EXPORT_SYMBOL(v4l2_video_std_construct
);
145 /* ----------------------------------------------------------------- */
146 /* some arrays for pretty-printing debug messages of enum types */
148 const char *v4l2_field_names
[] = {
149 [V4L2_FIELD_ANY
] = "any",
150 [V4L2_FIELD_NONE
] = "none",
151 [V4L2_FIELD_TOP
] = "top",
152 [V4L2_FIELD_BOTTOM
] = "bottom",
153 [V4L2_FIELD_INTERLACED
] = "interlaced",
154 [V4L2_FIELD_SEQ_TB
] = "seq-tb",
155 [V4L2_FIELD_SEQ_BT
] = "seq-bt",
156 [V4L2_FIELD_ALTERNATE
] = "alternate",
157 [V4L2_FIELD_INTERLACED_TB
] = "interlaced-tb",
158 [V4L2_FIELD_INTERLACED_BT
] = "interlaced-bt",
160 EXPORT_SYMBOL(v4l2_field_names
);
162 const char *v4l2_type_names
[] = {
163 [V4L2_BUF_TYPE_VIDEO_CAPTURE
] = "vid-cap",
164 [V4L2_BUF_TYPE_VIDEO_OVERLAY
] = "vid-overlay",
165 [V4L2_BUF_TYPE_VIDEO_OUTPUT
] = "vid-out",
166 [V4L2_BUF_TYPE_VBI_CAPTURE
] = "vbi-cap",
167 [V4L2_BUF_TYPE_VBI_OUTPUT
] = "vbi-out",
168 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
] = "sliced-vbi-cap",
169 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
] = "sliced-vbi-out",
170 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
] = "vid-out-overlay",
172 EXPORT_SYMBOL(v4l2_type_names
);
174 static const char *v4l2_memory_names
[] = {
175 [V4L2_MEMORY_MMAP
] = "mmap",
176 [V4L2_MEMORY_USERPTR
] = "userptr",
177 [V4L2_MEMORY_OVERLAY
] = "overlay",
180 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
183 /* ------------------------------------------------------------------ */
184 /* debug help functions */
186 #ifdef CONFIG_VIDEO_V4L1_COMPAT
187 static const char *v4l1_ioctls
[] = {
188 [_IOC_NR(VIDIOCGCAP
)] = "VIDIOCGCAP",
189 [_IOC_NR(VIDIOCGCHAN
)] = "VIDIOCGCHAN",
190 [_IOC_NR(VIDIOCSCHAN
)] = "VIDIOCSCHAN",
191 [_IOC_NR(VIDIOCGTUNER
)] = "VIDIOCGTUNER",
192 [_IOC_NR(VIDIOCSTUNER
)] = "VIDIOCSTUNER",
193 [_IOC_NR(VIDIOCGPICT
)] = "VIDIOCGPICT",
194 [_IOC_NR(VIDIOCSPICT
)] = "VIDIOCSPICT",
195 [_IOC_NR(VIDIOCCAPTURE
)] = "VIDIOCCAPTURE",
196 [_IOC_NR(VIDIOCGWIN
)] = "VIDIOCGWIN",
197 [_IOC_NR(VIDIOCSWIN
)] = "VIDIOCSWIN",
198 [_IOC_NR(VIDIOCGFBUF
)] = "VIDIOCGFBUF",
199 [_IOC_NR(VIDIOCSFBUF
)] = "VIDIOCSFBUF",
200 [_IOC_NR(VIDIOCKEY
)] = "VIDIOCKEY",
201 [_IOC_NR(VIDIOCGFREQ
)] = "VIDIOCGFREQ",
202 [_IOC_NR(VIDIOCSFREQ
)] = "VIDIOCSFREQ",
203 [_IOC_NR(VIDIOCGAUDIO
)] = "VIDIOCGAUDIO",
204 [_IOC_NR(VIDIOCSAUDIO
)] = "VIDIOCSAUDIO",
205 [_IOC_NR(VIDIOCSYNC
)] = "VIDIOCSYNC",
206 [_IOC_NR(VIDIOCMCAPTURE
)] = "VIDIOCMCAPTURE",
207 [_IOC_NR(VIDIOCGMBUF
)] = "VIDIOCGMBUF",
208 [_IOC_NR(VIDIOCGUNIT
)] = "VIDIOCGUNIT",
209 [_IOC_NR(VIDIOCGCAPTURE
)] = "VIDIOCGCAPTURE",
210 [_IOC_NR(VIDIOCSCAPTURE
)] = "VIDIOCSCAPTURE",
211 [_IOC_NR(VIDIOCSPLAYMODE
)] = "VIDIOCSPLAYMODE",
212 [_IOC_NR(VIDIOCSWRITEMODE
)] = "VIDIOCSWRITEMODE",
213 [_IOC_NR(VIDIOCGPLAYINFO
)] = "VIDIOCGPLAYINFO",
214 [_IOC_NR(VIDIOCSMICROCODE
)] = "VIDIOCSMICROCODE",
215 [_IOC_NR(VIDIOCGVBIFMT
)] = "VIDIOCGVBIFMT",
216 [_IOC_NR(VIDIOCSVBIFMT
)] = "VIDIOCSVBIFMT"
218 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
221 static const char *v4l2_ioctls
[] = {
222 [_IOC_NR(VIDIOC_QUERYCAP
)] = "VIDIOC_QUERYCAP",
223 [_IOC_NR(VIDIOC_RESERVED
)] = "VIDIOC_RESERVED",
224 [_IOC_NR(VIDIOC_ENUM_FMT
)] = "VIDIOC_ENUM_FMT",
225 [_IOC_NR(VIDIOC_G_FMT
)] = "VIDIOC_G_FMT",
226 [_IOC_NR(VIDIOC_S_FMT
)] = "VIDIOC_S_FMT",
227 [_IOC_NR(VIDIOC_REQBUFS
)] = "VIDIOC_REQBUFS",
228 [_IOC_NR(VIDIOC_QUERYBUF
)] = "VIDIOC_QUERYBUF",
229 [_IOC_NR(VIDIOC_G_FBUF
)] = "VIDIOC_G_FBUF",
230 [_IOC_NR(VIDIOC_S_FBUF
)] = "VIDIOC_S_FBUF",
231 [_IOC_NR(VIDIOC_OVERLAY
)] = "VIDIOC_OVERLAY",
232 [_IOC_NR(VIDIOC_QBUF
)] = "VIDIOC_QBUF",
233 [_IOC_NR(VIDIOC_DQBUF
)] = "VIDIOC_DQBUF",
234 [_IOC_NR(VIDIOC_STREAMON
)] = "VIDIOC_STREAMON",
235 [_IOC_NR(VIDIOC_STREAMOFF
)] = "VIDIOC_STREAMOFF",
236 [_IOC_NR(VIDIOC_G_PARM
)] = "VIDIOC_G_PARM",
237 [_IOC_NR(VIDIOC_S_PARM
)] = "VIDIOC_S_PARM",
238 [_IOC_NR(VIDIOC_G_STD
)] = "VIDIOC_G_STD",
239 [_IOC_NR(VIDIOC_S_STD
)] = "VIDIOC_S_STD",
240 [_IOC_NR(VIDIOC_ENUMSTD
)] = "VIDIOC_ENUMSTD",
241 [_IOC_NR(VIDIOC_ENUMINPUT
)] = "VIDIOC_ENUMINPUT",
242 [_IOC_NR(VIDIOC_G_CTRL
)] = "VIDIOC_G_CTRL",
243 [_IOC_NR(VIDIOC_S_CTRL
)] = "VIDIOC_S_CTRL",
244 [_IOC_NR(VIDIOC_G_TUNER
)] = "VIDIOC_G_TUNER",
245 [_IOC_NR(VIDIOC_S_TUNER
)] = "VIDIOC_S_TUNER",
246 [_IOC_NR(VIDIOC_G_AUDIO
)] = "VIDIOC_G_AUDIO",
247 [_IOC_NR(VIDIOC_S_AUDIO
)] = "VIDIOC_S_AUDIO",
248 [_IOC_NR(VIDIOC_QUERYCTRL
)] = "VIDIOC_QUERYCTRL",
249 [_IOC_NR(VIDIOC_QUERYMENU
)] = "VIDIOC_QUERYMENU",
250 [_IOC_NR(VIDIOC_G_INPUT
)] = "VIDIOC_G_INPUT",
251 [_IOC_NR(VIDIOC_S_INPUT
)] = "VIDIOC_S_INPUT",
252 [_IOC_NR(VIDIOC_G_OUTPUT
)] = "VIDIOC_G_OUTPUT",
253 [_IOC_NR(VIDIOC_S_OUTPUT
)] = "VIDIOC_S_OUTPUT",
254 [_IOC_NR(VIDIOC_ENUMOUTPUT
)] = "VIDIOC_ENUMOUTPUT",
255 [_IOC_NR(VIDIOC_G_AUDOUT
)] = "VIDIOC_G_AUDOUT",
256 [_IOC_NR(VIDIOC_S_AUDOUT
)] = "VIDIOC_S_AUDOUT",
257 [_IOC_NR(VIDIOC_G_MODULATOR
)] = "VIDIOC_G_MODULATOR",
258 [_IOC_NR(VIDIOC_S_MODULATOR
)] = "VIDIOC_S_MODULATOR",
259 [_IOC_NR(VIDIOC_G_FREQUENCY
)] = "VIDIOC_G_FREQUENCY",
260 [_IOC_NR(VIDIOC_S_FREQUENCY
)] = "VIDIOC_S_FREQUENCY",
261 [_IOC_NR(VIDIOC_CROPCAP
)] = "VIDIOC_CROPCAP",
262 [_IOC_NR(VIDIOC_G_CROP
)] = "VIDIOC_G_CROP",
263 [_IOC_NR(VIDIOC_S_CROP
)] = "VIDIOC_S_CROP",
264 [_IOC_NR(VIDIOC_G_JPEGCOMP
)] = "VIDIOC_G_JPEGCOMP",
265 [_IOC_NR(VIDIOC_S_JPEGCOMP
)] = "VIDIOC_S_JPEGCOMP",
266 [_IOC_NR(VIDIOC_QUERYSTD
)] = "VIDIOC_QUERYSTD",
267 [_IOC_NR(VIDIOC_TRY_FMT
)] = "VIDIOC_TRY_FMT",
268 [_IOC_NR(VIDIOC_ENUMAUDIO
)] = "VIDIOC_ENUMAUDIO",
269 [_IOC_NR(VIDIOC_ENUMAUDOUT
)] = "VIDIOC_ENUMAUDOUT",
270 [_IOC_NR(VIDIOC_G_PRIORITY
)] = "VIDIOC_G_PRIORITY",
271 [_IOC_NR(VIDIOC_S_PRIORITY
)] = "VIDIOC_S_PRIORITY",
272 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP
)] = "VIDIOC_G_SLICED_VBI_CAP",
273 [_IOC_NR(VIDIOC_LOG_STATUS
)] = "VIDIOC_LOG_STATUS",
274 [_IOC_NR(VIDIOC_G_EXT_CTRLS
)] = "VIDIOC_G_EXT_CTRLS",
275 [_IOC_NR(VIDIOC_S_EXT_CTRLS
)] = "VIDIOC_S_EXT_CTRLS",
276 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS
)] = "VIDIOC_TRY_EXT_CTRLS",
278 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES
)] = "VIDIOC_ENUM_FRAMESIZES",
279 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS
)] = "VIDIOC_ENUM_FRAMEINTERVALS",
280 [_IOC_NR(VIDIOC_G_ENC_INDEX
)] = "VIDIOC_G_ENC_INDEX",
281 [_IOC_NR(VIDIOC_ENCODER_CMD
)] = "VIDIOC_ENCODER_CMD",
282 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD
)] = "VIDIOC_TRY_ENCODER_CMD",
284 [_IOC_NR(VIDIOC_DBG_S_REGISTER
)] = "VIDIOC_DBG_S_REGISTER",
285 [_IOC_NR(VIDIOC_DBG_G_REGISTER
)] = "VIDIOC_DBG_G_REGISTER",
287 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT
)] = "VIDIOC_DBG_G_CHIP_IDENT",
288 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK
)] = "VIDIOC_S_HW_FREQ_SEEK",
290 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS
)] = "VIDIOC_ENUM_DV_PRESETS",
291 [_IOC_NR(VIDIOC_S_DV_PRESET
)] = "VIDIOC_S_DV_PRESET",
292 [_IOC_NR(VIDIOC_G_DV_PRESET
)] = "VIDIOC_G_DV_PRESET",
293 [_IOC_NR(VIDIOC_QUERY_DV_PRESET
)] = "VIDIOC_QUERY_DV_PRESET",
294 [_IOC_NR(VIDIOC_S_DV_TIMINGS
)] = "VIDIOC_S_DV_TIMINGS",
295 [_IOC_NR(VIDIOC_G_DV_TIMINGS
)] = "VIDIOC_G_DV_TIMINGS",
296 [_IOC_NR(VIDIOC_DQEVENT
)] = "VIDIOC_DQEVENT",
297 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT
)] = "VIDIOC_SUBSCRIBE_EVENT",
298 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT
)] = "VIDIOC_UNSUBSCRIBE_EVENT",
300 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
302 /* Common ioctl debug function. This function can be used by
303 external ioctl messages as well as internal V4L ioctl */
304 void v4l_printk_ioctl(unsigned int cmd
)
308 switch (_IOC_TYPE(cmd
)) {
312 #ifdef CONFIG_VIDEO_V4L1_COMPAT
314 if (_IOC_NR(cmd
) >= V4L1_IOCTLS
) {
318 printk("%s", v4l1_ioctls
[_IOC_NR(cmd
)]);
322 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
) {
326 printk("%s", v4l2_ioctls
[_IOC_NR(cmd
)]);
332 switch (_IOC_DIR(cmd
)) {
333 case _IOC_NONE
: dir
= "--"; break;
334 case _IOC_READ
: dir
= "r-"; break;
335 case _IOC_WRITE
: dir
= "-w"; break;
336 case _IOC_READ
| _IOC_WRITE
: dir
= "rw"; break;
337 default: dir
= "*ERR*"; break;
339 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
340 type
, _IOC_TYPE(cmd
), dir
, _IOC_NR(cmd
), cmd
);
342 EXPORT_SYMBOL(v4l_printk_ioctl
);
345 * helper function -- handles userspace copying for ioctl arguments
350 video_fix_command(unsigned int cmd
)
353 case VIDIOC_OVERLAY_OLD
:
354 cmd
= VIDIOC_OVERLAY
;
356 case VIDIOC_S_PARM_OLD
:
359 case VIDIOC_S_CTRL_OLD
:
362 case VIDIOC_G_AUDIO_OLD
:
363 cmd
= VIDIOC_G_AUDIO
;
365 case VIDIOC_G_AUDOUT_OLD
:
366 cmd
= VIDIOC_G_AUDOUT
;
368 case VIDIOC_CROPCAP_OLD
:
369 cmd
= VIDIOC_CROPCAP
;
377 * Obsolete usercopy function - Should be removed soon
380 video_usercopy(struct file
*file
, unsigned int cmd
, unsigned long arg
,
388 size_t ctrls_size
= 0;
389 void __user
*user_ptr
= NULL
;
392 cmd
= video_fix_command(cmd
);
394 is_ext_ctrl
= (cmd
== VIDIOC_S_EXT_CTRLS
|| cmd
== VIDIOC_G_EXT_CTRLS
||
395 cmd
== VIDIOC_TRY_EXT_CTRLS
);
397 /* Copy arguments into temp kernel buffer */
398 switch (_IOC_DIR(cmd
)) {
404 case (_IOC_WRITE
| _IOC_READ
):
405 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
408 /* too big to allocate from stack */
409 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
416 if (_IOC_DIR(cmd
) & _IOC_WRITE
)
417 if (copy_from_user(parg
, (void __user
*)arg
, _IOC_SIZE(cmd
)))
422 struct v4l2_ext_controls
*p
= parg
;
424 /* In case of an error, tell the caller that it wasn't
425 a specific control that caused it. */
426 p
->error_idx
= p
->count
;
427 user_ptr
= (void __user
*)p
->controls
;
429 ctrls_size
= sizeof(struct v4l2_ext_control
) * p
->count
;
430 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
431 mbuf
= kmalloc(ctrls_size
, GFP_KERNEL
);
436 if (copy_from_user(mbuf
, user_ptr
, ctrls_size
))
443 err
= func(file
, cmd
, parg
);
444 if (err
== -ENOIOCTLCMD
)
447 struct v4l2_ext_controls
*p
= parg
;
449 p
->controls
= (void *)user_ptr
;
450 if (p
->count
&& err
== 0 && copy_to_user(user_ptr
, mbuf
, ctrls_size
))
458 /* Copy results into user buffer */
459 switch (_IOC_DIR(cmd
)) {
461 case (_IOC_WRITE
| _IOC_READ
):
462 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
471 EXPORT_SYMBOL(video_usercopy
);
473 static void dbgbuf(unsigned int cmd
, struct video_device
*vfd
,
474 struct v4l2_buffer
*p
)
476 struct v4l2_timecode
*tc
= &p
->timecode
;
478 dbgarg(cmd
, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
479 "bytesused=%d, flags=0x%08d, "
480 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
481 p
->timestamp
.tv_sec
/ 3600,
482 (int)(p
->timestamp
.tv_sec
/ 60) % 60,
483 (int)(p
->timestamp
.tv_sec
% 60),
484 (long)p
->timestamp
.tv_usec
,
486 prt_names(p
->type
, v4l2_type_names
),
487 p
->bytesused
, p
->flags
,
488 p
->field
, p
->sequence
,
489 prt_names(p
->memory
, v4l2_memory_names
),
490 p
->m
.userptr
, p
->length
);
491 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
492 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
493 tc
->hours
, tc
->minutes
, tc
->seconds
,
494 tc
->type
, tc
->flags
, tc
->frames
, *(__u32
*)tc
->userbits
);
497 static inline void dbgrect(struct video_device
*vfd
, char *s
,
500 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s
, r
->left
, r
->top
,
501 r
->width
, r
->height
);
504 static inline void v4l_print_pix_fmt(struct video_device
*vfd
,
505 struct v4l2_pix_format
*fmt
)
507 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
508 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
509 fmt
->width
, fmt
->height
,
510 (fmt
->pixelformat
& 0xff),
511 (fmt
->pixelformat
>> 8) & 0xff,
512 (fmt
->pixelformat
>> 16) & 0xff,
513 (fmt
->pixelformat
>> 24) & 0xff,
514 prt_names(fmt
->field
, v4l2_field_names
),
515 fmt
->bytesperline
, fmt
->sizeimage
, fmt
->colorspace
);
518 static inline void v4l_print_ext_ctrls(unsigned int cmd
,
519 struct video_device
*vfd
, struct v4l2_ext_controls
*c
, int show_vals
)
523 if (!(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
))
526 printk(KERN_CONT
"class=0x%x", c
->ctrl_class
);
527 for (i
= 0; i
< c
->count
; i
++) {
528 if (show_vals
&& !c
->controls
[i
].size
)
529 printk(KERN_CONT
" id/val=0x%x/0x%x",
530 c
->controls
[i
].id
, c
->controls
[i
].value
);
532 printk(KERN_CONT
" id=0x%x,size=%u",
533 c
->controls
[i
].id
, c
->controls
[i
].size
);
535 printk(KERN_CONT
"\n");
538 static inline int check_ext_ctrls(struct v4l2_ext_controls
*c
, int allow_priv
)
542 /* zero the reserved fields */
543 c
->reserved
[0] = c
->reserved
[1] = 0;
544 for (i
= 0; i
< c
->count
; i
++)
545 c
->controls
[i
].reserved2
[0] = 0;
547 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
548 when using extended controls.
549 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
550 is it allowed for backwards compatibility.
552 if (!allow_priv
&& c
->ctrl_class
== V4L2_CID_PRIVATE_BASE
)
554 /* Check that all controls are from the same control class. */
555 for (i
= 0; i
< c
->count
; i
++) {
556 if (V4L2_CTRL_ID2CLASS(c
->controls
[i
].id
) != c
->ctrl_class
) {
564 static int check_fmt(const struct v4l2_ioctl_ops
*ops
, enum v4l2_buf_type type
)
570 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
571 if (ops
->vidioc_g_fmt_vid_cap
)
574 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
575 if (ops
->vidioc_g_fmt_vid_overlay
)
578 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
579 if (ops
->vidioc_g_fmt_vid_out
)
582 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
583 if (ops
->vidioc_g_fmt_vid_out_overlay
)
586 case V4L2_BUF_TYPE_VBI_CAPTURE
:
587 if (ops
->vidioc_g_fmt_vbi_cap
)
590 case V4L2_BUF_TYPE_VBI_OUTPUT
:
591 if (ops
->vidioc_g_fmt_vbi_out
)
594 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
595 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
598 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
599 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
602 case V4L2_BUF_TYPE_PRIVATE
:
603 if (ops
->vidioc_g_fmt_type_private
)
610 static long __video_do_ioctl(struct file
*file
,
611 unsigned int cmd
, void *arg
)
613 struct video_device
*vfd
= video_devdata(file
);
614 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
615 void *fh
= file
->private_data
;
619 printk(KERN_WARNING
"videodev: \"%s\" has no ioctl_ops.\n",
624 #ifdef CONFIG_VIDEO_V4L1_COMPAT
625 /********************************************************
626 All other V4L1 calls are handled by v4l1_compat module.
627 Those calls will be translated into V4L2 calls, and
628 __video_do_ioctl will be called again, with one or more
630 ********************************************************/
631 if (_IOC_TYPE(cmd
) == 'v' && cmd
!= VIDIOCGMBUF
&&
632 _IOC_NR(cmd
) < BASE_VIDIOCPRIVATE
) {
633 return v4l_compat_translate_ioctl(file
, cmd
, arg
,
638 if ((vfd
->debug
& V4L2_DEBUG_IOCTL
) &&
639 !(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
)) {
640 v4l_print_ioctl(vfd
->name
, cmd
);
641 printk(KERN_CONT
"\n");
646 #ifdef CONFIG_VIDEO_V4L1_COMPAT
647 /***********************************************************
648 Handles calls to the obsoleted V4L1 API
649 Due to the nature of VIDIOCGMBUF, each driver that supports
650 V4L1 should implement its own handler for this ioctl.
651 ***********************************************************/
653 /* --- streaming capture ------------------------------------- */
656 struct video_mbuf
*p
= arg
;
658 if (!ops
->vidiocgmbuf
)
660 ret
= ops
->vidiocgmbuf(file
, fh
, p
);
662 dbgarg(cmd
, "size=%d, frames=%d, offsets=0x%08lx\n",
664 (unsigned long)p
->offsets
);
669 /* --- capabilities ------------------------------------------ */
670 case VIDIOC_QUERYCAP
:
672 struct v4l2_capability
*cap
= (struct v4l2_capability
*)arg
;
674 if (!ops
->vidioc_querycap
)
677 ret
= ops
->vidioc_querycap(file
, fh
, cap
);
679 dbgarg(cmd
, "driver=%s, card=%s, bus=%s, "
681 "capabilities=0x%08x\n",
682 cap
->driver
, cap
->card
, cap
->bus_info
,
688 /* --- priority ------------------------------------------ */
689 case VIDIOC_G_PRIORITY
:
691 enum v4l2_priority
*p
= arg
;
693 if (!ops
->vidioc_g_priority
)
695 ret
= ops
->vidioc_g_priority(file
, fh
, p
);
697 dbgarg(cmd
, "priority is %d\n", *p
);
700 case VIDIOC_S_PRIORITY
:
702 enum v4l2_priority
*p
= arg
;
704 if (!ops
->vidioc_s_priority
)
706 dbgarg(cmd
, "setting priority to %d\n", *p
);
707 ret
= ops
->vidioc_s_priority(file
, fh
, *p
);
711 /* --- capture ioctls ---------------------------------------- */
712 case VIDIOC_ENUM_FMT
:
714 struct v4l2_fmtdesc
*f
= arg
;
717 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
718 if (ops
->vidioc_enum_fmt_vid_cap
)
719 ret
= ops
->vidioc_enum_fmt_vid_cap(file
, fh
, f
);
721 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
722 if (ops
->vidioc_enum_fmt_vid_overlay
)
723 ret
= ops
->vidioc_enum_fmt_vid_overlay(file
,
726 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
727 if (ops
->vidioc_enum_fmt_vid_out
)
728 ret
= ops
->vidioc_enum_fmt_vid_out(file
, fh
, f
);
730 case V4L2_BUF_TYPE_PRIVATE
:
731 if (ops
->vidioc_enum_fmt_type_private
)
732 ret
= ops
->vidioc_enum_fmt_type_private(file
,
739 dbgarg(cmd
, "index=%d, type=%d, flags=%d, "
740 "pixelformat=%c%c%c%c, description='%s'\n",
741 f
->index
, f
->type
, f
->flags
,
742 (f
->pixelformat
& 0xff),
743 (f
->pixelformat
>> 8) & 0xff,
744 (f
->pixelformat
>> 16) & 0xff,
745 (f
->pixelformat
>> 24) & 0xff,
751 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
753 /* FIXME: Should be one dump per type */
754 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
757 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
758 if (ops
->vidioc_g_fmt_vid_cap
)
759 ret
= ops
->vidioc_g_fmt_vid_cap(file
, fh
, f
);
761 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
763 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
764 if (ops
->vidioc_g_fmt_vid_overlay
)
765 ret
= ops
->vidioc_g_fmt_vid_overlay(file
,
768 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
769 if (ops
->vidioc_g_fmt_vid_out
)
770 ret
= ops
->vidioc_g_fmt_vid_out(file
, fh
, f
);
772 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
774 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
775 if (ops
->vidioc_g_fmt_vid_out_overlay
)
776 ret
= ops
->vidioc_g_fmt_vid_out_overlay(file
,
779 case V4L2_BUF_TYPE_VBI_CAPTURE
:
780 if (ops
->vidioc_g_fmt_vbi_cap
)
781 ret
= ops
->vidioc_g_fmt_vbi_cap(file
, fh
, f
);
783 case V4L2_BUF_TYPE_VBI_OUTPUT
:
784 if (ops
->vidioc_g_fmt_vbi_out
)
785 ret
= ops
->vidioc_g_fmt_vbi_out(file
, fh
, f
);
787 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
788 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
789 ret
= ops
->vidioc_g_fmt_sliced_vbi_cap(file
,
792 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
793 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
794 ret
= ops
->vidioc_g_fmt_sliced_vbi_out(file
,
797 case V4L2_BUF_TYPE_PRIVATE
:
798 if (ops
->vidioc_g_fmt_type_private
)
799 ret
= ops
->vidioc_g_fmt_type_private(file
,
808 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
810 /* FIXME: Should be one dump per type */
811 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
814 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
815 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
816 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
817 if (ops
->vidioc_s_fmt_vid_cap
)
818 ret
= ops
->vidioc_s_fmt_vid_cap(file
, fh
, f
);
820 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
821 CLEAR_AFTER_FIELD(f
, fmt
.win
);
822 if (ops
->vidioc_s_fmt_vid_overlay
)
823 ret
= ops
->vidioc_s_fmt_vid_overlay(file
,
826 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
827 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
828 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
829 if (ops
->vidioc_s_fmt_vid_out
)
830 ret
= ops
->vidioc_s_fmt_vid_out(file
, fh
, f
);
832 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
833 CLEAR_AFTER_FIELD(f
, fmt
.win
);
834 if (ops
->vidioc_s_fmt_vid_out_overlay
)
835 ret
= ops
->vidioc_s_fmt_vid_out_overlay(file
,
838 case V4L2_BUF_TYPE_VBI_CAPTURE
:
839 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
840 if (ops
->vidioc_s_fmt_vbi_cap
)
841 ret
= ops
->vidioc_s_fmt_vbi_cap(file
, fh
, f
);
843 case V4L2_BUF_TYPE_VBI_OUTPUT
:
844 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
845 if (ops
->vidioc_s_fmt_vbi_out
)
846 ret
= ops
->vidioc_s_fmt_vbi_out(file
, fh
, f
);
848 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
849 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
850 if (ops
->vidioc_s_fmt_sliced_vbi_cap
)
851 ret
= ops
->vidioc_s_fmt_sliced_vbi_cap(file
,
854 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
855 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
856 if (ops
->vidioc_s_fmt_sliced_vbi_out
)
857 ret
= ops
->vidioc_s_fmt_sliced_vbi_out(file
,
860 case V4L2_BUF_TYPE_PRIVATE
:
861 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
862 if (ops
->vidioc_s_fmt_type_private
)
863 ret
= ops
->vidioc_s_fmt_type_private(file
,
871 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
873 /* FIXME: Should be one dump per type */
874 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
,
877 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
878 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
879 if (ops
->vidioc_try_fmt_vid_cap
)
880 ret
= ops
->vidioc_try_fmt_vid_cap(file
, fh
, f
);
882 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
884 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
885 CLEAR_AFTER_FIELD(f
, fmt
.win
);
886 if (ops
->vidioc_try_fmt_vid_overlay
)
887 ret
= ops
->vidioc_try_fmt_vid_overlay(file
,
890 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
891 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
892 if (ops
->vidioc_try_fmt_vid_out
)
893 ret
= ops
->vidioc_try_fmt_vid_out(file
, fh
, f
);
895 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
897 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
898 CLEAR_AFTER_FIELD(f
, fmt
.win
);
899 if (ops
->vidioc_try_fmt_vid_out_overlay
)
900 ret
= ops
->vidioc_try_fmt_vid_out_overlay(file
,
903 case V4L2_BUF_TYPE_VBI_CAPTURE
:
904 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
905 if (ops
->vidioc_try_fmt_vbi_cap
)
906 ret
= ops
->vidioc_try_fmt_vbi_cap(file
, fh
, f
);
908 case V4L2_BUF_TYPE_VBI_OUTPUT
:
909 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
910 if (ops
->vidioc_try_fmt_vbi_out
)
911 ret
= ops
->vidioc_try_fmt_vbi_out(file
, fh
, f
);
913 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
914 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
915 if (ops
->vidioc_try_fmt_sliced_vbi_cap
)
916 ret
= ops
->vidioc_try_fmt_sliced_vbi_cap(file
,
919 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
920 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
921 if (ops
->vidioc_try_fmt_sliced_vbi_out
)
922 ret
= ops
->vidioc_try_fmt_sliced_vbi_out(file
,
925 case V4L2_BUF_TYPE_PRIVATE
:
926 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
927 if (ops
->vidioc_try_fmt_type_private
)
928 ret
= ops
->vidioc_try_fmt_type_private(file
,
935 /* FIXME: Those buf reqs could be handled here,
936 with some changes on videobuf to allow its header to be included at
937 videodev2.h or being merged at videodev2.
941 struct v4l2_requestbuffers
*p
= arg
;
943 if (!ops
->vidioc_reqbufs
)
945 ret
= check_fmt(ops
, p
->type
);
949 if (p
->type
< V4L2_BUF_TYPE_PRIVATE
)
950 CLEAR_AFTER_FIELD(p
, memory
);
952 ret
= ops
->vidioc_reqbufs(file
, fh
, p
);
953 dbgarg(cmd
, "count=%d, type=%s, memory=%s\n",
955 prt_names(p
->type
, v4l2_type_names
),
956 prt_names(p
->memory
, v4l2_memory_names
));
959 case VIDIOC_QUERYBUF
:
961 struct v4l2_buffer
*p
= arg
;
963 if (!ops
->vidioc_querybuf
)
965 ret
= check_fmt(ops
, p
->type
);
969 ret
= ops
->vidioc_querybuf(file
, fh
, p
);
976 struct v4l2_buffer
*p
= arg
;
978 if (!ops
->vidioc_qbuf
)
980 ret
= check_fmt(ops
, p
->type
);
984 ret
= ops
->vidioc_qbuf(file
, fh
, p
);
991 struct v4l2_buffer
*p
= arg
;
993 if (!ops
->vidioc_dqbuf
)
995 ret
= check_fmt(ops
, p
->type
);
999 ret
= ops
->vidioc_dqbuf(file
, fh
, p
);
1001 dbgbuf(cmd
, vfd
, p
);
1004 case VIDIOC_OVERLAY
:
1008 if (!ops
->vidioc_overlay
)
1010 dbgarg(cmd
, "value=%d\n", *i
);
1011 ret
= ops
->vidioc_overlay(file
, fh
, *i
);
1016 struct v4l2_framebuffer
*p
= arg
;
1018 if (!ops
->vidioc_g_fbuf
)
1020 ret
= ops
->vidioc_g_fbuf(file
, fh
, arg
);
1022 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
1023 p
->capability
, p
->flags
,
1024 (unsigned long)p
->base
);
1025 v4l_print_pix_fmt(vfd
, &p
->fmt
);
1031 struct v4l2_framebuffer
*p
= arg
;
1033 if (!ops
->vidioc_s_fbuf
)
1035 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
1036 p
->capability
, p
->flags
, (unsigned long)p
->base
);
1037 v4l_print_pix_fmt(vfd
, &p
->fmt
);
1038 ret
= ops
->vidioc_s_fbuf(file
, fh
, arg
);
1041 case VIDIOC_STREAMON
:
1043 enum v4l2_buf_type i
= *(int *)arg
;
1045 if (!ops
->vidioc_streamon
)
1047 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1048 ret
= ops
->vidioc_streamon(file
, fh
, i
);
1051 case VIDIOC_STREAMOFF
:
1053 enum v4l2_buf_type i
= *(int *)arg
;
1055 if (!ops
->vidioc_streamoff
)
1057 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1058 ret
= ops
->vidioc_streamoff(file
, fh
, i
);
1061 /* ---------- tv norms ---------- */
1062 case VIDIOC_ENUMSTD
:
1064 struct v4l2_standard
*p
= arg
;
1065 v4l2_std_id id
= vfd
->tvnorms
, curr_id
= 0;
1066 unsigned int index
= p
->index
, i
, j
= 0;
1067 const char *descr
= "";
1069 /* Return norm array in a canonical way */
1070 for (i
= 0; i
<= index
&& id
; i
++) {
1071 /* last std value in the standards array is 0, so this
1072 while always ends there since (id & 0) == 0. */
1073 while ((id
& standards
[j
].std
) != standards
[j
].std
)
1075 curr_id
= standards
[j
].std
;
1076 descr
= standards
[j
].descr
;
1080 if (curr_id
!= V4L2_STD_PAL
&&
1081 curr_id
!= V4L2_STD_SECAM
&&
1082 curr_id
!= V4L2_STD_NTSC
)
1088 v4l2_video_std_construct(p
, curr_id
, descr
);
1090 dbgarg(cmd
, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1091 "framelines=%d\n", p
->index
,
1092 (unsigned long long)p
->id
, p
->name
,
1093 p
->frameperiod
.numerator
,
1094 p
->frameperiod
.denominator
,
1102 v4l2_std_id
*id
= arg
;
1105 /* Calls the specific handler */
1106 if (ops
->vidioc_g_std
)
1107 ret
= ops
->vidioc_g_std(file
, fh
, id
);
1108 else if (vfd
->current_norm
)
1109 *id
= vfd
->current_norm
;
1114 dbgarg(cmd
, "std=0x%08Lx\n", (long long unsigned)*id
);
1119 v4l2_std_id
*id
= arg
, norm
;
1121 dbgarg(cmd
, "std=%08Lx\n", (long long unsigned)*id
);
1123 norm
= (*id
) & vfd
->tvnorms
;
1124 if (vfd
->tvnorms
&& !norm
) /* Check if std is supported */
1127 /* Calls the specific handler */
1128 if (ops
->vidioc_s_std
)
1129 ret
= ops
->vidioc_s_std(file
, fh
, &norm
);
1133 /* Updates standard information */
1135 vfd
->current_norm
= norm
;
1138 case VIDIOC_QUERYSTD
:
1140 v4l2_std_id
*p
= arg
;
1142 if (!ops
->vidioc_querystd
)
1144 ret
= ops
->vidioc_querystd(file
, fh
, arg
);
1146 dbgarg(cmd
, "detected std=%08Lx\n",
1147 (unsigned long long)*p
);
1150 /* ------ input switching ---------- */
1151 /* FIXME: Inputs can be handled inside videodev2 */
1152 case VIDIOC_ENUMINPUT
:
1154 struct v4l2_input
*p
= arg
;
1157 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1158 * CAP_STD here based on ioctl handler provided by the
1159 * driver. If the driver doesn't support these
1160 * for a specific input, it must override these flags.
1162 if (ops
->vidioc_s_std
)
1163 p
->capabilities
|= V4L2_IN_CAP_STD
;
1164 if (ops
->vidioc_s_dv_preset
)
1165 p
->capabilities
|= V4L2_IN_CAP_PRESETS
;
1166 if (ops
->vidioc_s_dv_timings
)
1167 p
->capabilities
|= V4L2_IN_CAP_CUSTOM_TIMINGS
;
1169 if (!ops
->vidioc_enum_input
)
1172 ret
= ops
->vidioc_enum_input(file
, fh
, p
);
1174 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1176 "tuner=%d, std=%08Lx, status=%d\n",
1177 p
->index
, p
->name
, p
->type
, p
->audioset
,
1179 (unsigned long long)p
->std
,
1183 case VIDIOC_G_INPUT
:
1185 unsigned int *i
= arg
;
1187 if (!ops
->vidioc_g_input
)
1189 ret
= ops
->vidioc_g_input(file
, fh
, i
);
1191 dbgarg(cmd
, "value=%d\n", *i
);
1194 case VIDIOC_S_INPUT
:
1196 unsigned int *i
= arg
;
1198 if (!ops
->vidioc_s_input
)
1200 dbgarg(cmd
, "value=%d\n", *i
);
1201 ret
= ops
->vidioc_s_input(file
, fh
, *i
);
1205 /* ------ output switching ---------- */
1206 case VIDIOC_ENUMOUTPUT
:
1208 struct v4l2_output
*p
= arg
;
1210 if (!ops
->vidioc_enum_output
)
1214 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1215 * CAP_STD here based on ioctl handler provided by the
1216 * driver. If the driver doesn't support these
1217 * for a specific output, it must override these flags.
1219 if (ops
->vidioc_s_std
)
1220 p
->capabilities
|= V4L2_OUT_CAP_STD
;
1221 if (ops
->vidioc_s_dv_preset
)
1222 p
->capabilities
|= V4L2_OUT_CAP_PRESETS
;
1223 if (ops
->vidioc_s_dv_timings
)
1224 p
->capabilities
|= V4L2_OUT_CAP_CUSTOM_TIMINGS
;
1226 ret
= ops
->vidioc_enum_output(file
, fh
, p
);
1228 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1230 "modulator=%d, std=0x%08Lx\n",
1231 p
->index
, p
->name
, p
->type
, p
->audioset
,
1232 p
->modulator
, (unsigned long long)p
->std
);
1235 case VIDIOC_G_OUTPUT
:
1237 unsigned int *i
= arg
;
1239 if (!ops
->vidioc_g_output
)
1241 ret
= ops
->vidioc_g_output(file
, fh
, i
);
1243 dbgarg(cmd
, "value=%d\n", *i
);
1246 case VIDIOC_S_OUTPUT
:
1248 unsigned int *i
= arg
;
1250 if (!ops
->vidioc_s_output
)
1252 dbgarg(cmd
, "value=%d\n", *i
);
1253 ret
= ops
->vidioc_s_output(file
, fh
, *i
);
1257 /* --- controls ---------------------------------------------- */
1258 case VIDIOC_QUERYCTRL
:
1260 struct v4l2_queryctrl
*p
= arg
;
1262 if (!ops
->vidioc_queryctrl
)
1264 ret
= ops
->vidioc_queryctrl(file
, fh
, p
);
1266 dbgarg(cmd
, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1267 "step=%d, default=%d, flags=0x%08x\n",
1268 p
->id
, p
->type
, p
->name
,
1269 p
->minimum
, p
->maximum
,
1270 p
->step
, p
->default_value
, p
->flags
);
1272 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1277 struct v4l2_control
*p
= arg
;
1279 if (ops
->vidioc_g_ctrl
)
1280 ret
= ops
->vidioc_g_ctrl(file
, fh
, p
);
1281 else if (ops
->vidioc_g_ext_ctrls
) {
1282 struct v4l2_ext_controls ctrls
;
1283 struct v4l2_ext_control ctrl
;
1285 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1287 ctrls
.controls
= &ctrl
;
1289 ctrl
.value
= p
->value
;
1290 if (check_ext_ctrls(&ctrls
, 1)) {
1291 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, &ctrls
);
1293 p
->value
= ctrl
.value
;
1298 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1300 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1305 struct v4l2_control
*p
= arg
;
1306 struct v4l2_ext_controls ctrls
;
1307 struct v4l2_ext_control ctrl
;
1309 if (!ops
->vidioc_s_ctrl
&& !ops
->vidioc_s_ext_ctrls
)
1312 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1314 if (ops
->vidioc_s_ctrl
) {
1315 ret
= ops
->vidioc_s_ctrl(file
, fh
, p
);
1318 if (!ops
->vidioc_s_ext_ctrls
)
1321 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1323 ctrls
.controls
= &ctrl
;
1325 ctrl
.value
= p
->value
;
1326 if (check_ext_ctrls(&ctrls
, 1))
1327 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, &ctrls
);
1330 case VIDIOC_G_EXT_CTRLS
:
1332 struct v4l2_ext_controls
*p
= arg
;
1334 p
->error_idx
= p
->count
;
1335 if (!ops
->vidioc_g_ext_ctrls
)
1337 if (check_ext_ctrls(p
, 0))
1338 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, p
);
1339 v4l_print_ext_ctrls(cmd
, vfd
, p
, !ret
);
1342 case VIDIOC_S_EXT_CTRLS
:
1344 struct v4l2_ext_controls
*p
= arg
;
1346 p
->error_idx
= p
->count
;
1347 if (!ops
->vidioc_s_ext_ctrls
)
1349 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1350 if (check_ext_ctrls(p
, 0))
1351 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, p
);
1354 case VIDIOC_TRY_EXT_CTRLS
:
1356 struct v4l2_ext_controls
*p
= arg
;
1358 p
->error_idx
= p
->count
;
1359 if (!ops
->vidioc_try_ext_ctrls
)
1361 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1362 if (check_ext_ctrls(p
, 0))
1363 ret
= ops
->vidioc_try_ext_ctrls(file
, fh
, p
);
1366 case VIDIOC_QUERYMENU
:
1368 struct v4l2_querymenu
*p
= arg
;
1370 if (!ops
->vidioc_querymenu
)
1372 ret
= ops
->vidioc_querymenu(file
, fh
, p
);
1374 dbgarg(cmd
, "id=0x%x, index=%d, name=%s\n",
1375 p
->id
, p
->index
, p
->name
);
1377 dbgarg(cmd
, "id=0x%x, index=%d\n",
1381 /* --- audio ---------------------------------------------- */
1382 case VIDIOC_ENUMAUDIO
:
1384 struct v4l2_audio
*p
= arg
;
1386 if (!ops
->vidioc_enumaudio
)
1388 ret
= ops
->vidioc_enumaudio(file
, fh
, p
);
1390 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1391 "mode=0x%x\n", p
->index
, p
->name
,
1392 p
->capability
, p
->mode
);
1394 dbgarg(cmd
, "index=%d\n", p
->index
);
1397 case VIDIOC_G_AUDIO
:
1399 struct v4l2_audio
*p
= arg
;
1401 if (!ops
->vidioc_g_audio
)
1404 ret
= ops
->vidioc_g_audio(file
, fh
, p
);
1406 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1407 "mode=0x%x\n", p
->index
,
1408 p
->name
, p
->capability
, p
->mode
);
1410 dbgarg(cmd
, "index=%d\n", p
->index
);
1413 case VIDIOC_S_AUDIO
:
1415 struct v4l2_audio
*p
= arg
;
1417 if (!ops
->vidioc_s_audio
)
1419 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1420 "mode=0x%x\n", p
->index
, p
->name
,
1421 p
->capability
, p
->mode
);
1422 ret
= ops
->vidioc_s_audio(file
, fh
, p
);
1425 case VIDIOC_ENUMAUDOUT
:
1427 struct v4l2_audioout
*p
= arg
;
1429 if (!ops
->vidioc_enumaudout
)
1431 dbgarg(cmd
, "Enum for index=%d\n", p
->index
);
1432 ret
= ops
->vidioc_enumaudout(file
, fh
, p
);
1434 dbgarg2("index=%d, name=%s, capability=%d, "
1435 "mode=%d\n", p
->index
, p
->name
,
1436 p
->capability
, p
->mode
);
1439 case VIDIOC_G_AUDOUT
:
1441 struct v4l2_audioout
*p
= arg
;
1443 if (!ops
->vidioc_g_audout
)
1446 ret
= ops
->vidioc_g_audout(file
, fh
, p
);
1448 dbgarg2("index=%d, name=%s, capability=%d, "
1449 "mode=%d\n", p
->index
, p
->name
,
1450 p
->capability
, p
->mode
);
1453 case VIDIOC_S_AUDOUT
:
1455 struct v4l2_audioout
*p
= arg
;
1457 if (!ops
->vidioc_s_audout
)
1459 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1460 "mode=%d\n", p
->index
, p
->name
,
1461 p
->capability
, p
->mode
);
1463 ret
= ops
->vidioc_s_audout(file
, fh
, p
);
1466 case VIDIOC_G_MODULATOR
:
1468 struct v4l2_modulator
*p
= arg
;
1470 if (!ops
->vidioc_g_modulator
)
1472 ret
= ops
->vidioc_g_modulator(file
, fh
, p
);
1474 dbgarg(cmd
, "index=%d, name=%s, "
1475 "capability=%d, rangelow=%d,"
1476 " rangehigh=%d, txsubchans=%d\n",
1477 p
->index
, p
->name
, p
->capability
,
1478 p
->rangelow
, p
->rangehigh
,
1482 case VIDIOC_S_MODULATOR
:
1484 struct v4l2_modulator
*p
= arg
;
1486 if (!ops
->vidioc_s_modulator
)
1488 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1489 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1490 p
->index
, p
->name
, p
->capability
, p
->rangelow
,
1491 p
->rangehigh
, p
->txsubchans
);
1492 ret
= ops
->vidioc_s_modulator(file
, fh
, p
);
1497 struct v4l2_crop
*p
= arg
;
1499 if (!ops
->vidioc_g_crop
)
1502 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1503 ret
= ops
->vidioc_g_crop(file
, fh
, p
);
1505 dbgrect(vfd
, "", &p
->c
);
1510 struct v4l2_crop
*p
= arg
;
1512 if (!ops
->vidioc_s_crop
)
1514 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1515 dbgrect(vfd
, "", &p
->c
);
1516 ret
= ops
->vidioc_s_crop(file
, fh
, p
);
1519 case VIDIOC_CROPCAP
:
1521 struct v4l2_cropcap
*p
= arg
;
1523 /*FIXME: Should also show v4l2_fract pixelaspect */
1524 if (!ops
->vidioc_cropcap
)
1527 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1528 ret
= ops
->vidioc_cropcap(file
, fh
, p
);
1530 dbgrect(vfd
, "bounds ", &p
->bounds
);
1531 dbgrect(vfd
, "defrect ", &p
->defrect
);
1535 case VIDIOC_G_JPEGCOMP
:
1537 struct v4l2_jpegcompression
*p
= arg
;
1539 if (!ops
->vidioc_g_jpegcomp
)
1542 ret
= ops
->vidioc_g_jpegcomp(file
, fh
, p
);
1544 dbgarg(cmd
, "quality=%d, APPn=%d, "
1545 "APP_len=%d, COM_len=%d, "
1546 "jpeg_markers=%d\n",
1547 p
->quality
, p
->APPn
, p
->APP_len
,
1548 p
->COM_len
, p
->jpeg_markers
);
1551 case VIDIOC_S_JPEGCOMP
:
1553 struct v4l2_jpegcompression
*p
= arg
;
1555 if (!ops
->vidioc_g_jpegcomp
)
1557 dbgarg(cmd
, "quality=%d, APPn=%d, APP_len=%d, "
1558 "COM_len=%d, jpeg_markers=%d\n",
1559 p
->quality
, p
->APPn
, p
->APP_len
,
1560 p
->COM_len
, p
->jpeg_markers
);
1561 ret
= ops
->vidioc_s_jpegcomp(file
, fh
, p
);
1564 case VIDIOC_G_ENC_INDEX
:
1566 struct v4l2_enc_idx
*p
= arg
;
1568 if (!ops
->vidioc_g_enc_index
)
1570 ret
= ops
->vidioc_g_enc_index(file
, fh
, p
);
1572 dbgarg(cmd
, "entries=%d, entries_cap=%d\n",
1573 p
->entries
, p
->entries_cap
);
1576 case VIDIOC_ENCODER_CMD
:
1578 struct v4l2_encoder_cmd
*p
= arg
;
1580 if (!ops
->vidioc_encoder_cmd
)
1582 ret
= ops
->vidioc_encoder_cmd(file
, fh
, p
);
1584 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1587 case VIDIOC_TRY_ENCODER_CMD
:
1589 struct v4l2_encoder_cmd
*p
= arg
;
1591 if (!ops
->vidioc_try_encoder_cmd
)
1593 ret
= ops
->vidioc_try_encoder_cmd(file
, fh
, p
);
1595 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1600 struct v4l2_streamparm
*p
= arg
;
1602 if (ops
->vidioc_g_parm
) {
1603 ret
= check_fmt(ops
, p
->type
);
1606 ret
= ops
->vidioc_g_parm(file
, fh
, p
);
1608 v4l2_std_id std
= vfd
->current_norm
;
1610 if (p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1614 if (ops
->vidioc_g_std
)
1615 ret
= ops
->vidioc_g_std(file
, fh
, &std
);
1619 v4l2_video_std_frame_period(std
,
1620 &p
->parm
.capture
.timeperframe
);
1623 dbgarg(cmd
, "type=%d\n", p
->type
);
1628 struct v4l2_streamparm
*p
= arg
;
1630 if (!ops
->vidioc_s_parm
)
1632 ret
= check_fmt(ops
, p
->type
);
1636 dbgarg(cmd
, "type=%d\n", p
->type
);
1637 ret
= ops
->vidioc_s_parm(file
, fh
, p
);
1640 case VIDIOC_G_TUNER
:
1642 struct v4l2_tuner
*p
= arg
;
1644 if (!ops
->vidioc_g_tuner
)
1647 ret
= ops
->vidioc_g_tuner(file
, fh
, p
);
1649 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1650 "capability=0x%x, rangelow=%d, "
1651 "rangehigh=%d, signal=%d, afc=%d, "
1652 "rxsubchans=0x%x, audmode=%d\n",
1653 p
->index
, p
->name
, p
->type
,
1654 p
->capability
, p
->rangelow
,
1655 p
->rangehigh
, p
->signal
, p
->afc
,
1656 p
->rxsubchans
, p
->audmode
);
1659 case VIDIOC_S_TUNER
:
1661 struct v4l2_tuner
*p
= arg
;
1663 if (!ops
->vidioc_s_tuner
)
1665 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1666 "capability=0x%x, rangelow=%d, "
1667 "rangehigh=%d, signal=%d, afc=%d, "
1668 "rxsubchans=0x%x, audmode=%d\n",
1669 p
->index
, p
->name
, p
->type
,
1670 p
->capability
, p
->rangelow
,
1671 p
->rangehigh
, p
->signal
, p
->afc
,
1672 p
->rxsubchans
, p
->audmode
);
1673 ret
= ops
->vidioc_s_tuner(file
, fh
, p
);
1676 case VIDIOC_G_FREQUENCY
:
1678 struct v4l2_frequency
*p
= arg
;
1680 if (!ops
->vidioc_g_frequency
)
1683 ret
= ops
->vidioc_g_frequency(file
, fh
, p
);
1685 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1686 p
->tuner
, p
->type
, p
->frequency
);
1689 case VIDIOC_S_FREQUENCY
:
1691 struct v4l2_frequency
*p
= arg
;
1693 if (!ops
->vidioc_s_frequency
)
1695 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1696 p
->tuner
, p
->type
, p
->frequency
);
1697 ret
= ops
->vidioc_s_frequency(file
, fh
, p
);
1700 case VIDIOC_G_SLICED_VBI_CAP
:
1702 struct v4l2_sliced_vbi_cap
*p
= arg
;
1704 if (!ops
->vidioc_g_sliced_vbi_cap
)
1707 /* Clear up to type, everything after type is zerod already */
1708 memset(p
, 0, offsetof(struct v4l2_sliced_vbi_cap
, type
));
1710 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1711 ret
= ops
->vidioc_g_sliced_vbi_cap(file
, fh
, p
);
1713 dbgarg2("service_set=%d\n", p
->service_set
);
1716 case VIDIOC_LOG_STATUS
:
1718 if (!ops
->vidioc_log_status
)
1720 ret
= ops
->vidioc_log_status(file
, fh
);
1723 #ifdef CONFIG_VIDEO_ADV_DEBUG
1724 case VIDIOC_DBG_G_REGISTER
:
1726 struct v4l2_dbg_register
*p
= arg
;
1728 if (!capable(CAP_SYS_ADMIN
))
1730 else if (ops
->vidioc_g_register
)
1731 ret
= ops
->vidioc_g_register(file
, fh
, p
);
1734 case VIDIOC_DBG_S_REGISTER
:
1736 struct v4l2_dbg_register
*p
= arg
;
1738 if (!capable(CAP_SYS_ADMIN
))
1740 else if (ops
->vidioc_s_register
)
1741 ret
= ops
->vidioc_s_register(file
, fh
, p
);
1745 case VIDIOC_DBG_G_CHIP_IDENT
:
1747 struct v4l2_dbg_chip_ident
*p
= arg
;
1749 if (!ops
->vidioc_g_chip_ident
)
1751 p
->ident
= V4L2_IDENT_NONE
;
1753 ret
= ops
->vidioc_g_chip_ident(file
, fh
, p
);
1755 dbgarg(cmd
, "chip_ident=%u, revision=0x%x\n", p
->ident
, p
->revision
);
1758 case VIDIOC_S_HW_FREQ_SEEK
:
1760 struct v4l2_hw_freq_seek
*p
= arg
;
1762 if (!ops
->vidioc_s_hw_freq_seek
)
1765 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1766 p
->tuner
, p
->type
, p
->seek_upward
, p
->wrap_around
);
1767 ret
= ops
->vidioc_s_hw_freq_seek(file
, fh
, p
);
1770 case VIDIOC_ENUM_FRAMESIZES
:
1772 struct v4l2_frmsizeenum
*p
= arg
;
1774 if (!ops
->vidioc_enum_framesizes
)
1777 ret
= ops
->vidioc_enum_framesizes(file
, fh
, p
);
1779 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1781 (p
->pixel_format
& 0xff),
1782 (p
->pixel_format
>> 8) & 0xff,
1783 (p
->pixel_format
>> 16) & 0xff,
1784 (p
->pixel_format
>> 24) & 0xff,
1787 case V4L2_FRMSIZE_TYPE_DISCRETE
:
1788 dbgarg3("width = %d, height=%d\n",
1789 p
->discrete
.width
, p
->discrete
.height
);
1791 case V4L2_FRMSIZE_TYPE_STEPWISE
:
1792 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1793 p
->stepwise
.min_width
, p
->stepwise
.min_height
,
1794 p
->stepwise
.step_width
, p
->stepwise
.step_height
,
1795 p
->stepwise
.max_width
, p
->stepwise
.max_height
);
1797 case V4L2_FRMSIZE_TYPE_CONTINUOUS
:
1798 dbgarg3("continuous\n");
1801 dbgarg3("- Unknown type!\n");
1806 case VIDIOC_ENUM_FRAMEINTERVALS
:
1808 struct v4l2_frmivalenum
*p
= arg
;
1810 if (!ops
->vidioc_enum_frameintervals
)
1813 ret
= ops
->vidioc_enum_frameintervals(file
, fh
, p
);
1815 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1816 p
->index
, p
->pixel_format
,
1817 p
->width
, p
->height
, p
->type
);
1819 case V4L2_FRMIVAL_TYPE_DISCRETE
:
1820 dbgarg2("fps=%d/%d\n",
1821 p
->discrete
.numerator
,
1822 p
->discrete
.denominator
);
1824 case V4L2_FRMIVAL_TYPE_STEPWISE
:
1825 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1826 p
->stepwise
.min
.numerator
,
1827 p
->stepwise
.min
.denominator
,
1828 p
->stepwise
.max
.numerator
,
1829 p
->stepwise
.max
.denominator
,
1830 p
->stepwise
.step
.numerator
,
1831 p
->stepwise
.step
.denominator
);
1833 case V4L2_FRMIVAL_TYPE_CONTINUOUS
:
1834 dbgarg2("continuous\n");
1837 dbgarg2("- Unknown type!\n");
1841 case VIDIOC_ENUM_DV_PRESETS
:
1843 struct v4l2_dv_enum_preset
*p
= arg
;
1845 if (!ops
->vidioc_enum_dv_presets
)
1848 ret
= ops
->vidioc_enum_dv_presets(file
, fh
, p
);
1851 "index=%d, preset=%d, name=%s, width=%d,"
1853 p
->index
, p
->preset
, p
->name
, p
->width
,
1857 case VIDIOC_S_DV_PRESET
:
1859 struct v4l2_dv_preset
*p
= arg
;
1861 if (!ops
->vidioc_s_dv_preset
)
1864 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1865 ret
= ops
->vidioc_s_dv_preset(file
, fh
, p
);
1868 case VIDIOC_G_DV_PRESET
:
1870 struct v4l2_dv_preset
*p
= arg
;
1872 if (!ops
->vidioc_g_dv_preset
)
1875 ret
= ops
->vidioc_g_dv_preset(file
, fh
, p
);
1877 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1880 case VIDIOC_QUERY_DV_PRESET
:
1882 struct v4l2_dv_preset
*p
= arg
;
1884 if (!ops
->vidioc_query_dv_preset
)
1887 ret
= ops
->vidioc_query_dv_preset(file
, fh
, p
);
1889 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1892 case VIDIOC_S_DV_TIMINGS
:
1894 struct v4l2_dv_timings
*p
= arg
;
1896 if (!ops
->vidioc_s_dv_timings
)
1900 case V4L2_DV_BT_656_1120
:
1901 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
1902 " width=%d, height=%d, polarities=%x,"
1903 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
1904 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
1905 " il_vfrontporch=%d, il_vsync=%d,"
1906 " il_vbackporch=%d\n",
1907 p
->bt
.interlaced
, p
->bt
.pixelclock
,
1908 p
->bt
.width
, p
->bt
.height
, p
->bt
.polarities
,
1909 p
->bt
.hfrontporch
, p
->bt
.hsync
,
1910 p
->bt
.hbackporch
, p
->bt
.vfrontporch
,
1911 p
->bt
.vsync
, p
->bt
.vbackporch
,
1912 p
->bt
.il_vfrontporch
, p
->bt
.il_vsync
,
1913 p
->bt
.il_vbackporch
);
1914 ret
= ops
->vidioc_s_dv_timings(file
, fh
, p
);
1917 dbgarg2("Unknown type %d!\n", p
->type
);
1922 case VIDIOC_G_DV_TIMINGS
:
1924 struct v4l2_dv_timings
*p
= arg
;
1926 if (!ops
->vidioc_g_dv_timings
)
1929 ret
= ops
->vidioc_g_dv_timings(file
, fh
, p
);
1932 case V4L2_DV_BT_656_1120
:
1933 dbgarg2("bt-656/1120:interlaced=%d,"
1935 " width=%d, height=%d, polarities=%x,"
1936 " hfrontporch=%d, hsync=%d,"
1937 " hbackporch=%d, vfrontporch=%d,"
1938 " vsync=%d, vbackporch=%d,"
1939 " il_vfrontporch=%d, il_vsync=%d,"
1940 " il_vbackporch=%d\n",
1941 p
->bt
.interlaced
, p
->bt
.pixelclock
,
1942 p
->bt
.width
, p
->bt
.height
,
1943 p
->bt
.polarities
, p
->bt
.hfrontporch
,
1944 p
->bt
.hsync
, p
->bt
.hbackporch
,
1945 p
->bt
.vfrontporch
, p
->bt
.vsync
,
1946 p
->bt
.vbackporch
, p
->bt
.il_vfrontporch
,
1947 p
->bt
.il_vsync
, p
->bt
.il_vbackporch
);
1950 dbgarg2("Unknown type %d!\n", p
->type
);
1956 case VIDIOC_DQEVENT
:
1958 struct v4l2_event
*ev
= arg
;
1960 if (!ops
->vidioc_subscribe_event
)
1963 ret
= v4l2_event_dequeue(fh
, ev
, file
->f_flags
& O_NONBLOCK
);
1965 dbgarg(cmd
, "no pending events?");
1969 "pending=%d, type=0x%8.8x, sequence=%d, "
1970 "timestamp=%lu.%9.9lu ",
1971 ev
->pending
, ev
->type
, ev
->sequence
,
1972 ev
->timestamp
.tv_sec
, ev
->timestamp
.tv_nsec
);
1975 case VIDIOC_SUBSCRIBE_EVENT
:
1977 struct v4l2_event_subscription
*sub
= arg
;
1979 if (!ops
->vidioc_subscribe_event
)
1982 ret
= ops
->vidioc_subscribe_event(fh
, sub
);
1984 dbgarg(cmd
, "failed, ret=%ld", ret
);
1987 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
1990 case VIDIOC_UNSUBSCRIBE_EVENT
:
1992 struct v4l2_event_subscription
*sub
= arg
;
1994 if (!ops
->vidioc_unsubscribe_event
)
1997 ret
= ops
->vidioc_unsubscribe_event(fh
, sub
);
1999 dbgarg(cmd
, "failed, ret=%ld", ret
);
2002 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
2007 if (!ops
->vidioc_default
)
2009 ret
= ops
->vidioc_default(file
, fh
, cmd
, arg
);
2014 if (vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
) {
2016 v4l_print_ioctl(vfd
->name
, cmd
);
2017 printk(KERN_CONT
" error %ld\n", ret
);
2024 /* In some cases, only a few fields are used as input, i.e. when the app sets
2025 * "index" and then the driver fills in the rest of the structure for the thing
2026 * with that index. We only need to copy up the first non-input field. */
2027 static unsigned long cmd_input_size(unsigned int cmd
)
2029 /* Size of structure up to and including 'field' */
2030 #define CMDINSIZE(cmd, type, field) \
2031 case VIDIOC_##cmd: \
2032 return offsetof(struct v4l2_##type, field) + \
2033 sizeof(((struct v4l2_##type *)0)->field);
2036 CMDINSIZE(ENUM_FMT
, fmtdesc
, type
);
2037 CMDINSIZE(G_FMT
, format
, type
);
2038 CMDINSIZE(QUERYBUF
, buffer
, type
);
2039 CMDINSIZE(G_PARM
, streamparm
, type
);
2040 CMDINSIZE(ENUMSTD
, standard
, index
);
2041 CMDINSIZE(ENUMINPUT
, input
, index
);
2042 CMDINSIZE(G_CTRL
, control
, id
);
2043 CMDINSIZE(G_TUNER
, tuner
, index
);
2044 CMDINSIZE(QUERYCTRL
, queryctrl
, id
);
2045 CMDINSIZE(QUERYMENU
, querymenu
, index
);
2046 CMDINSIZE(ENUMOUTPUT
, output
, index
);
2047 CMDINSIZE(G_MODULATOR
, modulator
, index
);
2048 CMDINSIZE(G_FREQUENCY
, frequency
, tuner
);
2049 CMDINSIZE(CROPCAP
, cropcap
, type
);
2050 CMDINSIZE(G_CROP
, crop
, type
);
2051 CMDINSIZE(ENUMAUDIO
, audio
, index
);
2052 CMDINSIZE(ENUMAUDOUT
, audioout
, index
);
2053 CMDINSIZE(ENCODER_CMD
, encoder_cmd
, flags
);
2054 CMDINSIZE(TRY_ENCODER_CMD
, encoder_cmd
, flags
);
2055 CMDINSIZE(G_SLICED_VBI_CAP
, sliced_vbi_cap
, type
);
2056 CMDINSIZE(ENUM_FRAMESIZES
, frmsizeenum
, pixel_format
);
2057 CMDINSIZE(ENUM_FRAMEINTERVALS
, frmivalenum
, height
);
2059 return _IOC_SIZE(cmd
);
2063 long video_ioctl2(struct file
*file
,
2064 unsigned int cmd
, unsigned long arg
)
2068 void *parg
= (void *)arg
;
2071 size_t ctrls_size
= 0;
2072 void __user
*user_ptr
= NULL
;
2074 #ifdef __OLD_VIDIOC_
2075 cmd
= video_fix_command(cmd
);
2077 is_ext_ctrl
= (cmd
== VIDIOC_S_EXT_CTRLS
|| cmd
== VIDIOC_G_EXT_CTRLS
||
2078 cmd
== VIDIOC_TRY_EXT_CTRLS
);
2080 /* Copy arguments into temp kernel buffer */
2081 if (_IOC_DIR(cmd
) != _IOC_NONE
) {
2082 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
2085 /* too big to allocate from stack */
2086 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
2093 if (_IOC_DIR(cmd
) & _IOC_WRITE
) {
2094 unsigned long n
= cmd_input_size(cmd
);
2096 if (copy_from_user(parg
, (void __user
*)arg
, n
))
2099 /* zero out anything we don't copy from userspace */
2100 if (n
< _IOC_SIZE(cmd
))
2101 memset((u8
*)parg
+ n
, 0, _IOC_SIZE(cmd
) - n
);
2103 /* read-only ioctl */
2104 memset(parg
, 0, _IOC_SIZE(cmd
));
2109 struct v4l2_ext_controls
*p
= parg
;
2111 /* In case of an error, tell the caller that it wasn't
2112 a specific control that caused it. */
2113 p
->error_idx
= p
->count
;
2114 user_ptr
= (void __user
*)p
->controls
;
2116 ctrls_size
= sizeof(struct v4l2_ext_control
) * p
->count
;
2117 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
2118 mbuf
= kmalloc(ctrls_size
, GFP_KERNEL
);
2123 if (copy_from_user(mbuf
, user_ptr
, ctrls_size
))
2130 err
= __video_do_ioctl(file
, cmd
, parg
);
2131 if (err
== -ENOIOCTLCMD
)
2134 struct v4l2_ext_controls
*p
= parg
;
2136 p
->controls
= (void *)user_ptr
;
2137 if (p
->count
&& err
== 0 && copy_to_user(user_ptr
, mbuf
, ctrls_size
))
2145 /* Copy results into user buffer */
2146 switch (_IOC_DIR(cmd
)) {
2148 case (_IOC_WRITE
| _IOC_READ
):
2149 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
2158 EXPORT_SYMBOL(video_ioctl2
);