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",
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",
289 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS
)] = "VIDIOC_ENUM_DV_PRESETS",
290 [_IOC_NR(VIDIOC_S_DV_PRESET
)] = "VIDIOC_S_DV_PRESET",
291 [_IOC_NR(VIDIOC_G_DV_PRESET
)] = "VIDIOC_G_DV_PRESET",
292 [_IOC_NR(VIDIOC_QUERY_DV_PRESET
)] = "VIDIOC_QUERY_DV_PRESET",
293 [_IOC_NR(VIDIOC_S_DV_TIMINGS
)] = "VIDIOC_S_DV_TIMINGS",
294 [_IOC_NR(VIDIOC_G_DV_TIMINGS
)] = "VIDIOC_G_DV_TIMINGS",
295 [_IOC_NR(VIDIOC_DQEVENT
)] = "VIDIOC_DQEVENT",
296 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT
)] = "VIDIOC_SUBSCRIBE_EVENT",
297 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT
)] = "VIDIOC_UNSUBSCRIBE_EVENT",
299 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
301 /* Common ioctl debug function. This function can be used by
302 external ioctl messages as well as internal V4L ioctl */
303 void v4l_printk_ioctl(unsigned int cmd
)
307 switch (_IOC_TYPE(cmd
)) {
311 #ifdef CONFIG_VIDEO_V4L1_COMPAT
313 if (_IOC_NR(cmd
) >= V4L1_IOCTLS
) {
317 printk("%s", v4l1_ioctls
[_IOC_NR(cmd
)]);
321 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
) {
325 printk("%s", v4l2_ioctls
[_IOC_NR(cmd
)]);
331 switch (_IOC_DIR(cmd
)) {
332 case _IOC_NONE
: dir
= "--"; break;
333 case _IOC_READ
: dir
= "r-"; break;
334 case _IOC_WRITE
: dir
= "-w"; break;
335 case _IOC_READ
| _IOC_WRITE
: dir
= "rw"; break;
336 default: dir
= "*ERR*"; break;
338 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
339 type
, _IOC_TYPE(cmd
), dir
, _IOC_NR(cmd
), cmd
);
341 EXPORT_SYMBOL(v4l_printk_ioctl
);
344 * helper function -- handles userspace copying for ioctl arguments
349 video_fix_command(unsigned int cmd
)
352 case VIDIOC_OVERLAY_OLD
:
353 cmd
= VIDIOC_OVERLAY
;
355 case VIDIOC_S_PARM_OLD
:
358 case VIDIOC_S_CTRL_OLD
:
361 case VIDIOC_G_AUDIO_OLD
:
362 cmd
= VIDIOC_G_AUDIO
;
364 case VIDIOC_G_AUDOUT_OLD
:
365 cmd
= VIDIOC_G_AUDOUT
;
367 case VIDIOC_CROPCAP_OLD
:
368 cmd
= VIDIOC_CROPCAP
;
376 * Obsolete usercopy function - Should be removed soon
379 video_usercopy(struct file
*file
, unsigned int cmd
, unsigned long arg
,
387 size_t ctrls_size
= 0;
388 void __user
*user_ptr
= NULL
;
391 cmd
= video_fix_command(cmd
);
393 is_ext_ctrl
= (cmd
== VIDIOC_S_EXT_CTRLS
|| cmd
== VIDIOC_G_EXT_CTRLS
||
394 cmd
== VIDIOC_TRY_EXT_CTRLS
);
396 /* Copy arguments into temp kernel buffer */
397 switch (_IOC_DIR(cmd
)) {
403 case (_IOC_WRITE
| _IOC_READ
):
404 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
407 /* too big to allocate from stack */
408 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
415 if (_IOC_DIR(cmd
) & _IOC_WRITE
)
416 if (copy_from_user(parg
, (void __user
*)arg
, _IOC_SIZE(cmd
)))
421 struct v4l2_ext_controls
*p
= parg
;
423 /* In case of an error, tell the caller that it wasn't
424 a specific control that caused it. */
425 p
->error_idx
= p
->count
;
426 user_ptr
= (void __user
*)p
->controls
;
428 ctrls_size
= sizeof(struct v4l2_ext_control
) * p
->count
;
429 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
430 mbuf
= kmalloc(ctrls_size
, GFP_KERNEL
);
435 if (copy_from_user(mbuf
, user_ptr
, ctrls_size
))
442 err
= func(file
, cmd
, parg
);
443 if (err
== -ENOIOCTLCMD
)
446 struct v4l2_ext_controls
*p
= parg
;
448 p
->controls
= (void *)user_ptr
;
449 if (p
->count
&& err
== 0 && copy_to_user(user_ptr
, mbuf
, ctrls_size
))
457 /* Copy results into user buffer */
458 switch (_IOC_DIR(cmd
)) {
460 case (_IOC_WRITE
| _IOC_READ
):
461 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
470 EXPORT_SYMBOL(video_usercopy
);
472 static void dbgbuf(unsigned int cmd
, struct video_device
*vfd
,
473 struct v4l2_buffer
*p
)
475 struct v4l2_timecode
*tc
= &p
->timecode
;
477 dbgarg(cmd
, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
478 "bytesused=%d, flags=0x%08d, "
479 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
480 p
->timestamp
.tv_sec
/ 3600,
481 (int)(p
->timestamp
.tv_sec
/ 60) % 60,
482 (int)(p
->timestamp
.tv_sec
% 60),
483 (long)p
->timestamp
.tv_usec
,
485 prt_names(p
->type
, v4l2_type_names
),
486 p
->bytesused
, p
->flags
,
487 p
->field
, p
->sequence
,
488 prt_names(p
->memory
, v4l2_memory_names
),
489 p
->m
.userptr
, p
->length
);
490 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
491 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
492 tc
->hours
, tc
->minutes
, tc
->seconds
,
493 tc
->type
, tc
->flags
, tc
->frames
, *(__u32
*)tc
->userbits
);
496 static inline void dbgrect(struct video_device
*vfd
, char *s
,
499 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s
, r
->left
, r
->top
,
500 r
->width
, r
->height
);
503 static inline void v4l_print_pix_fmt(struct video_device
*vfd
,
504 struct v4l2_pix_format
*fmt
)
506 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
507 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
508 fmt
->width
, fmt
->height
,
509 (fmt
->pixelformat
& 0xff),
510 (fmt
->pixelformat
>> 8) & 0xff,
511 (fmt
->pixelformat
>> 16) & 0xff,
512 (fmt
->pixelformat
>> 24) & 0xff,
513 prt_names(fmt
->field
, v4l2_field_names
),
514 fmt
->bytesperline
, fmt
->sizeimage
, fmt
->colorspace
);
517 static inline void v4l_print_ext_ctrls(unsigned int cmd
,
518 struct video_device
*vfd
, struct v4l2_ext_controls
*c
, int show_vals
)
522 if (!(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
))
525 printk(KERN_CONT
"class=0x%x", c
->ctrl_class
);
526 for (i
= 0; i
< c
->count
; i
++) {
527 if (show_vals
&& !c
->controls
[i
].size
)
528 printk(KERN_CONT
" id/val=0x%x/0x%x",
529 c
->controls
[i
].id
, c
->controls
[i
].value
);
531 printk(KERN_CONT
" id=0x%x,size=%u",
532 c
->controls
[i
].id
, c
->controls
[i
].size
);
534 printk(KERN_CONT
"\n");
537 static inline int check_ext_ctrls(struct v4l2_ext_controls
*c
, int allow_priv
)
541 /* zero the reserved fields */
542 c
->reserved
[0] = c
->reserved
[1] = 0;
543 for (i
= 0; i
< c
->count
; i
++)
544 c
->controls
[i
].reserved2
[0] = 0;
546 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
547 when using extended controls.
548 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
549 is it allowed for backwards compatibility.
551 if (!allow_priv
&& c
->ctrl_class
== V4L2_CID_PRIVATE_BASE
)
553 /* Check that all controls are from the same control class. */
554 for (i
= 0; i
< c
->count
; i
++) {
555 if (V4L2_CTRL_ID2CLASS(c
->controls
[i
].id
) != c
->ctrl_class
) {
563 static int check_fmt(const struct v4l2_ioctl_ops
*ops
, enum v4l2_buf_type type
)
569 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
570 if (ops
->vidioc_g_fmt_vid_cap
)
573 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
574 if (ops
->vidioc_g_fmt_vid_overlay
)
577 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
578 if (ops
->vidioc_g_fmt_vid_out
)
581 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
582 if (ops
->vidioc_g_fmt_vid_out_overlay
)
585 case V4L2_BUF_TYPE_VBI_CAPTURE
:
586 if (ops
->vidioc_g_fmt_vbi_cap
)
589 case V4L2_BUF_TYPE_VBI_OUTPUT
:
590 if (ops
->vidioc_g_fmt_vbi_out
)
593 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
594 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
597 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
598 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
601 case V4L2_BUF_TYPE_PRIVATE
:
602 if (ops
->vidioc_g_fmt_type_private
)
609 static long __video_do_ioctl(struct file
*file
,
610 unsigned int cmd
, void *arg
)
612 struct video_device
*vfd
= video_devdata(file
);
613 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
614 void *fh
= file
->private_data
;
618 printk(KERN_WARNING
"videodev: \"%s\" has no ioctl_ops.\n",
623 #ifdef CONFIG_VIDEO_V4L1_COMPAT
624 /********************************************************
625 All other V4L1 calls are handled by v4l1_compat module.
626 Those calls will be translated into V4L2 calls, and
627 __video_do_ioctl will be called again, with one or more
629 ********************************************************/
630 if (_IOC_TYPE(cmd
) == 'v' && cmd
!= VIDIOCGMBUF
&&
631 _IOC_NR(cmd
) < BASE_VIDIOCPRIVATE
) {
632 return v4l_compat_translate_ioctl(file
, cmd
, arg
,
637 if ((vfd
->debug
& V4L2_DEBUG_IOCTL
) &&
638 !(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
)) {
639 v4l_print_ioctl(vfd
->name
, cmd
);
640 printk(KERN_CONT
"\n");
645 #ifdef CONFIG_VIDEO_V4L1_COMPAT
646 /***********************************************************
647 Handles calls to the obsoleted V4L1 API
648 Due to the nature of VIDIOCGMBUF, each driver that supports
649 V4L1 should implement its own handler for this ioctl.
650 ***********************************************************/
652 /* --- streaming capture ------------------------------------- */
655 struct video_mbuf
*p
= arg
;
657 if (!ops
->vidiocgmbuf
)
659 ret
= ops
->vidiocgmbuf(file
, fh
, p
);
661 dbgarg(cmd
, "size=%d, frames=%d, offsets=0x%08lx\n",
663 (unsigned long)p
->offsets
);
668 /* --- capabilities ------------------------------------------ */
669 case VIDIOC_QUERYCAP
:
671 struct v4l2_capability
*cap
= (struct v4l2_capability
*)arg
;
673 if (!ops
->vidioc_querycap
)
676 ret
= ops
->vidioc_querycap(file
, fh
, cap
);
678 dbgarg(cmd
, "driver=%s, card=%s, bus=%s, "
680 "capabilities=0x%08x\n",
681 cap
->driver
, cap
->card
, cap
->bus_info
,
687 /* --- priority ------------------------------------------ */
688 case VIDIOC_G_PRIORITY
:
690 enum v4l2_priority
*p
= arg
;
692 if (!ops
->vidioc_g_priority
)
694 ret
= ops
->vidioc_g_priority(file
, fh
, p
);
696 dbgarg(cmd
, "priority is %d\n", *p
);
699 case VIDIOC_S_PRIORITY
:
701 enum v4l2_priority
*p
= arg
;
703 if (!ops
->vidioc_s_priority
)
705 dbgarg(cmd
, "setting priority to %d\n", *p
);
706 ret
= ops
->vidioc_s_priority(file
, fh
, *p
);
710 /* --- capture ioctls ---------------------------------------- */
711 case VIDIOC_ENUM_FMT
:
713 struct v4l2_fmtdesc
*f
= arg
;
716 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
717 if (ops
->vidioc_enum_fmt_vid_cap
)
718 ret
= ops
->vidioc_enum_fmt_vid_cap(file
, fh
, f
);
720 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
721 if (ops
->vidioc_enum_fmt_vid_overlay
)
722 ret
= ops
->vidioc_enum_fmt_vid_overlay(file
,
725 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
726 if (ops
->vidioc_enum_fmt_vid_out
)
727 ret
= ops
->vidioc_enum_fmt_vid_out(file
, fh
, f
);
729 case V4L2_BUF_TYPE_PRIVATE
:
730 if (ops
->vidioc_enum_fmt_type_private
)
731 ret
= ops
->vidioc_enum_fmt_type_private(file
,
738 dbgarg(cmd
, "index=%d, type=%d, flags=%d, "
739 "pixelformat=%c%c%c%c, description='%s'\n",
740 f
->index
, f
->type
, f
->flags
,
741 (f
->pixelformat
& 0xff),
742 (f
->pixelformat
>> 8) & 0xff,
743 (f
->pixelformat
>> 16) & 0xff,
744 (f
->pixelformat
>> 24) & 0xff,
750 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
752 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
755 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
756 if (ops
->vidioc_g_fmt_vid_cap
)
757 ret
= ops
->vidioc_g_fmt_vid_cap(file
, fh
, f
);
759 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
761 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
762 if (ops
->vidioc_g_fmt_vid_overlay
)
763 ret
= ops
->vidioc_g_fmt_vid_overlay(file
,
766 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
767 if (ops
->vidioc_g_fmt_vid_out
)
768 ret
= ops
->vidioc_g_fmt_vid_out(file
, fh
, f
);
770 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
772 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
773 if (ops
->vidioc_g_fmt_vid_out_overlay
)
774 ret
= ops
->vidioc_g_fmt_vid_out_overlay(file
,
777 case V4L2_BUF_TYPE_VBI_CAPTURE
:
778 if (ops
->vidioc_g_fmt_vbi_cap
)
779 ret
= ops
->vidioc_g_fmt_vbi_cap(file
, fh
, f
);
781 case V4L2_BUF_TYPE_VBI_OUTPUT
:
782 if (ops
->vidioc_g_fmt_vbi_out
)
783 ret
= ops
->vidioc_g_fmt_vbi_out(file
, fh
, f
);
785 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
786 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
787 ret
= ops
->vidioc_g_fmt_sliced_vbi_cap(file
,
790 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
791 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
792 ret
= ops
->vidioc_g_fmt_sliced_vbi_out(file
,
795 case V4L2_BUF_TYPE_PRIVATE
:
796 if (ops
->vidioc_g_fmt_type_private
)
797 ret
= ops
->vidioc_g_fmt_type_private(file
,
806 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
808 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
811 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
812 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
813 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
814 if (ops
->vidioc_s_fmt_vid_cap
)
815 ret
= ops
->vidioc_s_fmt_vid_cap(file
, fh
, f
);
817 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
818 CLEAR_AFTER_FIELD(f
, fmt
.win
);
819 if (ops
->vidioc_s_fmt_vid_overlay
)
820 ret
= ops
->vidioc_s_fmt_vid_overlay(file
,
823 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
824 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
825 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
826 if (ops
->vidioc_s_fmt_vid_out
)
827 ret
= ops
->vidioc_s_fmt_vid_out(file
, fh
, f
);
829 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
830 CLEAR_AFTER_FIELD(f
, fmt
.win
);
831 if (ops
->vidioc_s_fmt_vid_out_overlay
)
832 ret
= ops
->vidioc_s_fmt_vid_out_overlay(file
,
835 case V4L2_BUF_TYPE_VBI_CAPTURE
:
836 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
837 if (ops
->vidioc_s_fmt_vbi_cap
)
838 ret
= ops
->vidioc_s_fmt_vbi_cap(file
, fh
, f
);
840 case V4L2_BUF_TYPE_VBI_OUTPUT
:
841 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
842 if (ops
->vidioc_s_fmt_vbi_out
)
843 ret
= ops
->vidioc_s_fmt_vbi_out(file
, fh
, f
);
845 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
846 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
847 if (ops
->vidioc_s_fmt_sliced_vbi_cap
)
848 ret
= ops
->vidioc_s_fmt_sliced_vbi_cap(file
,
851 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
852 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
853 if (ops
->vidioc_s_fmt_sliced_vbi_out
)
854 ret
= ops
->vidioc_s_fmt_sliced_vbi_out(file
,
857 case V4L2_BUF_TYPE_PRIVATE
:
858 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
859 if (ops
->vidioc_s_fmt_type_private
)
860 ret
= ops
->vidioc_s_fmt_type_private(file
,
868 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
870 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
,
873 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
874 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
875 if (ops
->vidioc_try_fmt_vid_cap
)
876 ret
= ops
->vidioc_try_fmt_vid_cap(file
, fh
, f
);
878 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
880 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
881 CLEAR_AFTER_FIELD(f
, fmt
.win
);
882 if (ops
->vidioc_try_fmt_vid_overlay
)
883 ret
= ops
->vidioc_try_fmt_vid_overlay(file
,
886 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
887 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
888 if (ops
->vidioc_try_fmt_vid_out
)
889 ret
= ops
->vidioc_try_fmt_vid_out(file
, fh
, f
);
891 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
893 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
894 CLEAR_AFTER_FIELD(f
, fmt
.win
);
895 if (ops
->vidioc_try_fmt_vid_out_overlay
)
896 ret
= ops
->vidioc_try_fmt_vid_out_overlay(file
,
899 case V4L2_BUF_TYPE_VBI_CAPTURE
:
900 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
901 if (ops
->vidioc_try_fmt_vbi_cap
)
902 ret
= ops
->vidioc_try_fmt_vbi_cap(file
, fh
, f
);
904 case V4L2_BUF_TYPE_VBI_OUTPUT
:
905 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
906 if (ops
->vidioc_try_fmt_vbi_out
)
907 ret
= ops
->vidioc_try_fmt_vbi_out(file
, fh
, f
);
909 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
910 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
911 if (ops
->vidioc_try_fmt_sliced_vbi_cap
)
912 ret
= ops
->vidioc_try_fmt_sliced_vbi_cap(file
,
915 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
916 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
917 if (ops
->vidioc_try_fmt_sliced_vbi_out
)
918 ret
= ops
->vidioc_try_fmt_sliced_vbi_out(file
,
921 case V4L2_BUF_TYPE_PRIVATE
:
922 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
923 if (ops
->vidioc_try_fmt_type_private
)
924 ret
= ops
->vidioc_try_fmt_type_private(file
,
933 struct v4l2_requestbuffers
*p
= arg
;
935 if (!ops
->vidioc_reqbufs
)
937 ret
= check_fmt(ops
, p
->type
);
941 if (p
->type
< V4L2_BUF_TYPE_PRIVATE
)
942 CLEAR_AFTER_FIELD(p
, memory
);
944 ret
= ops
->vidioc_reqbufs(file
, fh
, p
);
945 dbgarg(cmd
, "count=%d, type=%s, memory=%s\n",
947 prt_names(p
->type
, v4l2_type_names
),
948 prt_names(p
->memory
, v4l2_memory_names
));
951 case VIDIOC_QUERYBUF
:
953 struct v4l2_buffer
*p
= arg
;
955 if (!ops
->vidioc_querybuf
)
957 ret
= check_fmt(ops
, p
->type
);
961 ret
= ops
->vidioc_querybuf(file
, fh
, p
);
968 struct v4l2_buffer
*p
= arg
;
970 if (!ops
->vidioc_qbuf
)
972 ret
= check_fmt(ops
, p
->type
);
976 ret
= ops
->vidioc_qbuf(file
, fh
, p
);
983 struct v4l2_buffer
*p
= arg
;
985 if (!ops
->vidioc_dqbuf
)
987 ret
= check_fmt(ops
, p
->type
);
991 ret
= ops
->vidioc_dqbuf(file
, fh
, p
);
1000 if (!ops
->vidioc_overlay
)
1002 dbgarg(cmd
, "value=%d\n", *i
);
1003 ret
= ops
->vidioc_overlay(file
, fh
, *i
);
1008 struct v4l2_framebuffer
*p
= arg
;
1010 if (!ops
->vidioc_g_fbuf
)
1012 ret
= ops
->vidioc_g_fbuf(file
, fh
, arg
);
1014 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
1015 p
->capability
, p
->flags
,
1016 (unsigned long)p
->base
);
1017 v4l_print_pix_fmt(vfd
, &p
->fmt
);
1023 struct v4l2_framebuffer
*p
= arg
;
1025 if (!ops
->vidioc_s_fbuf
)
1027 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
1028 p
->capability
, p
->flags
, (unsigned long)p
->base
);
1029 v4l_print_pix_fmt(vfd
, &p
->fmt
);
1030 ret
= ops
->vidioc_s_fbuf(file
, fh
, arg
);
1033 case VIDIOC_STREAMON
:
1035 enum v4l2_buf_type i
= *(int *)arg
;
1037 if (!ops
->vidioc_streamon
)
1039 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1040 ret
= ops
->vidioc_streamon(file
, fh
, i
);
1043 case VIDIOC_STREAMOFF
:
1045 enum v4l2_buf_type i
= *(int *)arg
;
1047 if (!ops
->vidioc_streamoff
)
1049 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1050 ret
= ops
->vidioc_streamoff(file
, fh
, i
);
1053 /* ---------- tv norms ---------- */
1054 case VIDIOC_ENUMSTD
:
1056 struct v4l2_standard
*p
= arg
;
1057 v4l2_std_id id
= vfd
->tvnorms
, curr_id
= 0;
1058 unsigned int index
= p
->index
, i
, j
= 0;
1059 const char *descr
= "";
1061 /* Return norm array in a canonical way */
1062 for (i
= 0; i
<= index
&& id
; i
++) {
1063 /* last std value in the standards array is 0, so this
1064 while always ends there since (id & 0) == 0. */
1065 while ((id
& standards
[j
].std
) != standards
[j
].std
)
1067 curr_id
= standards
[j
].std
;
1068 descr
= standards
[j
].descr
;
1072 if (curr_id
!= V4L2_STD_PAL
&&
1073 curr_id
!= V4L2_STD_SECAM
&&
1074 curr_id
!= V4L2_STD_NTSC
)
1080 v4l2_video_std_construct(p
, curr_id
, descr
);
1082 dbgarg(cmd
, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1083 "framelines=%d\n", p
->index
,
1084 (unsigned long long)p
->id
, p
->name
,
1085 p
->frameperiod
.numerator
,
1086 p
->frameperiod
.denominator
,
1094 v4l2_std_id
*id
= arg
;
1097 /* Calls the specific handler */
1098 if (ops
->vidioc_g_std
)
1099 ret
= ops
->vidioc_g_std(file
, fh
, id
);
1100 else if (vfd
->current_norm
)
1101 *id
= vfd
->current_norm
;
1106 dbgarg(cmd
, "std=0x%08Lx\n", (long long unsigned)*id
);
1111 v4l2_std_id
*id
= arg
, norm
;
1113 dbgarg(cmd
, "std=%08Lx\n", (long long unsigned)*id
);
1115 norm
= (*id
) & vfd
->tvnorms
;
1116 if (vfd
->tvnorms
&& !norm
) /* Check if std is supported */
1119 /* Calls the specific handler */
1120 if (ops
->vidioc_s_std
)
1121 ret
= ops
->vidioc_s_std(file
, fh
, &norm
);
1125 /* Updates standard information */
1127 vfd
->current_norm
= norm
;
1130 case VIDIOC_QUERYSTD
:
1132 v4l2_std_id
*p
= arg
;
1134 if (!ops
->vidioc_querystd
)
1136 ret
= ops
->vidioc_querystd(file
, fh
, arg
);
1138 dbgarg(cmd
, "detected std=%08Lx\n",
1139 (unsigned long long)*p
);
1142 /* ------ input switching ---------- */
1143 case VIDIOC_ENUMINPUT
:
1145 struct v4l2_input
*p
= arg
;
1148 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1149 * CAP_STD here based on ioctl handler provided by the
1150 * driver. If the driver doesn't support these
1151 * for a specific input, it must override these flags.
1153 if (ops
->vidioc_s_std
)
1154 p
->capabilities
|= V4L2_IN_CAP_STD
;
1155 if (ops
->vidioc_s_dv_preset
)
1156 p
->capabilities
|= V4L2_IN_CAP_PRESETS
;
1157 if (ops
->vidioc_s_dv_timings
)
1158 p
->capabilities
|= V4L2_IN_CAP_CUSTOM_TIMINGS
;
1160 if (!ops
->vidioc_enum_input
)
1163 ret
= ops
->vidioc_enum_input(file
, fh
, p
);
1165 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1167 "tuner=%d, std=%08Lx, status=%d\n",
1168 p
->index
, p
->name
, p
->type
, p
->audioset
,
1170 (unsigned long long)p
->std
,
1174 case VIDIOC_G_INPUT
:
1176 unsigned int *i
= arg
;
1178 if (!ops
->vidioc_g_input
)
1180 ret
= ops
->vidioc_g_input(file
, fh
, i
);
1182 dbgarg(cmd
, "value=%d\n", *i
);
1185 case VIDIOC_S_INPUT
:
1187 unsigned int *i
= arg
;
1189 if (!ops
->vidioc_s_input
)
1191 dbgarg(cmd
, "value=%d\n", *i
);
1192 ret
= ops
->vidioc_s_input(file
, fh
, *i
);
1196 /* ------ output switching ---------- */
1197 case VIDIOC_ENUMOUTPUT
:
1199 struct v4l2_output
*p
= arg
;
1201 if (!ops
->vidioc_enum_output
)
1205 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1206 * CAP_STD here based on ioctl handler provided by the
1207 * driver. If the driver doesn't support these
1208 * for a specific output, it must override these flags.
1210 if (ops
->vidioc_s_std
)
1211 p
->capabilities
|= V4L2_OUT_CAP_STD
;
1212 if (ops
->vidioc_s_dv_preset
)
1213 p
->capabilities
|= V4L2_OUT_CAP_PRESETS
;
1214 if (ops
->vidioc_s_dv_timings
)
1215 p
->capabilities
|= V4L2_OUT_CAP_CUSTOM_TIMINGS
;
1217 ret
= ops
->vidioc_enum_output(file
, fh
, p
);
1219 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1221 "modulator=%d, std=0x%08Lx\n",
1222 p
->index
, p
->name
, p
->type
, p
->audioset
,
1223 p
->modulator
, (unsigned long long)p
->std
);
1226 case VIDIOC_G_OUTPUT
:
1228 unsigned int *i
= arg
;
1230 if (!ops
->vidioc_g_output
)
1232 ret
= ops
->vidioc_g_output(file
, fh
, i
);
1234 dbgarg(cmd
, "value=%d\n", *i
);
1237 case VIDIOC_S_OUTPUT
:
1239 unsigned int *i
= arg
;
1241 if (!ops
->vidioc_s_output
)
1243 dbgarg(cmd
, "value=%d\n", *i
);
1244 ret
= ops
->vidioc_s_output(file
, fh
, *i
);
1248 /* --- controls ---------------------------------------------- */
1249 case VIDIOC_QUERYCTRL
:
1251 struct v4l2_queryctrl
*p
= arg
;
1253 if (vfd
->ctrl_handler
)
1254 ret
= v4l2_queryctrl(vfd
->ctrl_handler
, p
);
1255 else if (ops
->vidioc_queryctrl
)
1256 ret
= ops
->vidioc_queryctrl(file
, fh
, p
);
1260 dbgarg(cmd
, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1261 "step=%d, default=%d, flags=0x%08x\n",
1262 p
->id
, p
->type
, p
->name
,
1263 p
->minimum
, p
->maximum
,
1264 p
->step
, p
->default_value
, p
->flags
);
1266 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1271 struct v4l2_control
*p
= arg
;
1273 if (vfd
->ctrl_handler
)
1274 ret
= v4l2_g_ctrl(vfd
->ctrl_handler
, p
);
1275 else if (ops
->vidioc_g_ctrl
)
1276 ret
= ops
->vidioc_g_ctrl(file
, fh
, p
);
1277 else if (ops
->vidioc_g_ext_ctrls
) {
1278 struct v4l2_ext_controls ctrls
;
1279 struct v4l2_ext_control ctrl
;
1281 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1283 ctrls
.controls
= &ctrl
;
1285 ctrl
.value
= p
->value
;
1286 if (check_ext_ctrls(&ctrls
, 1)) {
1287 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, &ctrls
);
1289 p
->value
= ctrl
.value
;
1294 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1296 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1301 struct v4l2_control
*p
= arg
;
1302 struct v4l2_ext_controls ctrls
;
1303 struct v4l2_ext_control ctrl
;
1305 if (!vfd
->ctrl_handler
&&
1306 !ops
->vidioc_s_ctrl
&& !ops
->vidioc_s_ext_ctrls
)
1309 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1311 if (vfd
->ctrl_handler
) {
1312 ret
= v4l2_s_ctrl(vfd
->ctrl_handler
, p
);
1315 if (ops
->vidioc_s_ctrl
) {
1316 ret
= ops
->vidioc_s_ctrl(file
, fh
, p
);
1319 if (!ops
->vidioc_s_ext_ctrls
)
1322 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1324 ctrls
.controls
= &ctrl
;
1326 ctrl
.value
= p
->value
;
1327 if (check_ext_ctrls(&ctrls
, 1))
1328 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, &ctrls
);
1331 case VIDIOC_G_EXT_CTRLS
:
1333 struct v4l2_ext_controls
*p
= arg
;
1335 p
->error_idx
= p
->count
;
1336 if (vfd
->ctrl_handler
)
1337 ret
= v4l2_g_ext_ctrls(vfd
->ctrl_handler
, p
);
1338 else if (ops
->vidioc_g_ext_ctrls
&& check_ext_ctrls(p
, 0))
1339 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, p
);
1342 v4l_print_ext_ctrls(cmd
, vfd
, p
, !ret
);
1345 case VIDIOC_S_EXT_CTRLS
:
1347 struct v4l2_ext_controls
*p
= arg
;
1349 p
->error_idx
= p
->count
;
1350 if (!vfd
->ctrl_handler
&& !ops
->vidioc_s_ext_ctrls
)
1352 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1353 if (vfd
->ctrl_handler
)
1354 ret
= v4l2_s_ext_ctrls(vfd
->ctrl_handler
, p
);
1355 else if (check_ext_ctrls(p
, 0))
1356 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, p
);
1359 case VIDIOC_TRY_EXT_CTRLS
:
1361 struct v4l2_ext_controls
*p
= arg
;
1363 p
->error_idx
= p
->count
;
1364 if (!vfd
->ctrl_handler
&& !ops
->vidioc_try_ext_ctrls
)
1366 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1367 if (vfd
->ctrl_handler
)
1368 ret
= v4l2_try_ext_ctrls(vfd
->ctrl_handler
, p
);
1369 else if (check_ext_ctrls(p
, 0))
1370 ret
= ops
->vidioc_try_ext_ctrls(file
, fh
, p
);
1373 case VIDIOC_QUERYMENU
:
1375 struct v4l2_querymenu
*p
= arg
;
1377 if (vfd
->ctrl_handler
)
1378 ret
= v4l2_querymenu(vfd
->ctrl_handler
, p
);
1379 else if (ops
->vidioc_querymenu
)
1380 ret
= ops
->vidioc_querymenu(file
, fh
, p
);
1384 dbgarg(cmd
, "id=0x%x, index=%d, name=%s\n",
1385 p
->id
, p
->index
, p
->name
);
1387 dbgarg(cmd
, "id=0x%x, index=%d\n",
1391 /* --- audio ---------------------------------------------- */
1392 case VIDIOC_ENUMAUDIO
:
1394 struct v4l2_audio
*p
= arg
;
1396 if (!ops
->vidioc_enumaudio
)
1398 ret
= ops
->vidioc_enumaudio(file
, fh
, p
);
1400 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1401 "mode=0x%x\n", p
->index
, p
->name
,
1402 p
->capability
, p
->mode
);
1404 dbgarg(cmd
, "index=%d\n", p
->index
);
1407 case VIDIOC_G_AUDIO
:
1409 struct v4l2_audio
*p
= arg
;
1411 if (!ops
->vidioc_g_audio
)
1414 ret
= ops
->vidioc_g_audio(file
, fh
, p
);
1416 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1417 "mode=0x%x\n", p
->index
,
1418 p
->name
, p
->capability
, p
->mode
);
1420 dbgarg(cmd
, "index=%d\n", p
->index
);
1423 case VIDIOC_S_AUDIO
:
1425 struct v4l2_audio
*p
= arg
;
1427 if (!ops
->vidioc_s_audio
)
1429 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1430 "mode=0x%x\n", p
->index
, p
->name
,
1431 p
->capability
, p
->mode
);
1432 ret
= ops
->vidioc_s_audio(file
, fh
, p
);
1435 case VIDIOC_ENUMAUDOUT
:
1437 struct v4l2_audioout
*p
= arg
;
1439 if (!ops
->vidioc_enumaudout
)
1441 dbgarg(cmd
, "Enum for index=%d\n", p
->index
);
1442 ret
= ops
->vidioc_enumaudout(file
, fh
, p
);
1444 dbgarg2("index=%d, name=%s, capability=%d, "
1445 "mode=%d\n", p
->index
, p
->name
,
1446 p
->capability
, p
->mode
);
1449 case VIDIOC_G_AUDOUT
:
1451 struct v4l2_audioout
*p
= arg
;
1453 if (!ops
->vidioc_g_audout
)
1456 ret
= ops
->vidioc_g_audout(file
, fh
, p
);
1458 dbgarg2("index=%d, name=%s, capability=%d, "
1459 "mode=%d\n", p
->index
, p
->name
,
1460 p
->capability
, p
->mode
);
1463 case VIDIOC_S_AUDOUT
:
1465 struct v4l2_audioout
*p
= arg
;
1467 if (!ops
->vidioc_s_audout
)
1469 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1470 "mode=%d\n", p
->index
, p
->name
,
1471 p
->capability
, p
->mode
);
1473 ret
= ops
->vidioc_s_audout(file
, fh
, p
);
1476 case VIDIOC_G_MODULATOR
:
1478 struct v4l2_modulator
*p
= arg
;
1480 if (!ops
->vidioc_g_modulator
)
1482 ret
= ops
->vidioc_g_modulator(file
, fh
, p
);
1484 dbgarg(cmd
, "index=%d, name=%s, "
1485 "capability=%d, rangelow=%d,"
1486 " rangehigh=%d, txsubchans=%d\n",
1487 p
->index
, p
->name
, p
->capability
,
1488 p
->rangelow
, p
->rangehigh
,
1492 case VIDIOC_S_MODULATOR
:
1494 struct v4l2_modulator
*p
= arg
;
1496 if (!ops
->vidioc_s_modulator
)
1498 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1499 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1500 p
->index
, p
->name
, p
->capability
, p
->rangelow
,
1501 p
->rangehigh
, p
->txsubchans
);
1502 ret
= ops
->vidioc_s_modulator(file
, fh
, p
);
1507 struct v4l2_crop
*p
= arg
;
1509 if (!ops
->vidioc_g_crop
)
1512 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1513 ret
= ops
->vidioc_g_crop(file
, fh
, p
);
1515 dbgrect(vfd
, "", &p
->c
);
1520 struct v4l2_crop
*p
= arg
;
1522 if (!ops
->vidioc_s_crop
)
1524 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1525 dbgrect(vfd
, "", &p
->c
);
1526 ret
= ops
->vidioc_s_crop(file
, fh
, p
);
1529 case VIDIOC_CROPCAP
:
1531 struct v4l2_cropcap
*p
= arg
;
1533 if (!ops
->vidioc_cropcap
)
1536 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1537 ret
= ops
->vidioc_cropcap(file
, fh
, p
);
1539 dbgrect(vfd
, "bounds ", &p
->bounds
);
1540 dbgrect(vfd
, "defrect ", &p
->defrect
);
1544 case VIDIOC_G_JPEGCOMP
:
1546 struct v4l2_jpegcompression
*p
= arg
;
1548 if (!ops
->vidioc_g_jpegcomp
)
1551 ret
= ops
->vidioc_g_jpegcomp(file
, fh
, p
);
1553 dbgarg(cmd
, "quality=%d, APPn=%d, "
1554 "APP_len=%d, COM_len=%d, "
1555 "jpeg_markers=%d\n",
1556 p
->quality
, p
->APPn
, p
->APP_len
,
1557 p
->COM_len
, p
->jpeg_markers
);
1560 case VIDIOC_S_JPEGCOMP
:
1562 struct v4l2_jpegcompression
*p
= arg
;
1564 if (!ops
->vidioc_g_jpegcomp
)
1566 dbgarg(cmd
, "quality=%d, APPn=%d, APP_len=%d, "
1567 "COM_len=%d, jpeg_markers=%d\n",
1568 p
->quality
, p
->APPn
, p
->APP_len
,
1569 p
->COM_len
, p
->jpeg_markers
);
1570 ret
= ops
->vidioc_s_jpegcomp(file
, fh
, p
);
1573 case VIDIOC_G_ENC_INDEX
:
1575 struct v4l2_enc_idx
*p
= arg
;
1577 if (!ops
->vidioc_g_enc_index
)
1579 ret
= ops
->vidioc_g_enc_index(file
, fh
, p
);
1581 dbgarg(cmd
, "entries=%d, entries_cap=%d\n",
1582 p
->entries
, p
->entries_cap
);
1585 case VIDIOC_ENCODER_CMD
:
1587 struct v4l2_encoder_cmd
*p
= arg
;
1589 if (!ops
->vidioc_encoder_cmd
)
1591 ret
= ops
->vidioc_encoder_cmd(file
, fh
, p
);
1593 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1596 case VIDIOC_TRY_ENCODER_CMD
:
1598 struct v4l2_encoder_cmd
*p
= arg
;
1600 if (!ops
->vidioc_try_encoder_cmd
)
1602 ret
= ops
->vidioc_try_encoder_cmd(file
, fh
, p
);
1604 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1609 struct v4l2_streamparm
*p
= arg
;
1611 if (ops
->vidioc_g_parm
) {
1612 ret
= check_fmt(ops
, p
->type
);
1615 ret
= ops
->vidioc_g_parm(file
, fh
, p
);
1617 v4l2_std_id std
= vfd
->current_norm
;
1619 if (p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1623 if (ops
->vidioc_g_std
)
1624 ret
= ops
->vidioc_g_std(file
, fh
, &std
);
1628 v4l2_video_std_frame_period(std
,
1629 &p
->parm
.capture
.timeperframe
);
1632 dbgarg(cmd
, "type=%d\n", p
->type
);
1637 struct v4l2_streamparm
*p
= arg
;
1639 if (!ops
->vidioc_s_parm
)
1641 ret
= check_fmt(ops
, p
->type
);
1645 dbgarg(cmd
, "type=%d\n", p
->type
);
1646 ret
= ops
->vidioc_s_parm(file
, fh
, p
);
1649 case VIDIOC_G_TUNER
:
1651 struct v4l2_tuner
*p
= arg
;
1653 if (!ops
->vidioc_g_tuner
)
1656 ret
= ops
->vidioc_g_tuner(file
, fh
, p
);
1658 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1659 "capability=0x%x, rangelow=%d, "
1660 "rangehigh=%d, signal=%d, afc=%d, "
1661 "rxsubchans=0x%x, audmode=%d\n",
1662 p
->index
, p
->name
, p
->type
,
1663 p
->capability
, p
->rangelow
,
1664 p
->rangehigh
, p
->signal
, p
->afc
,
1665 p
->rxsubchans
, p
->audmode
);
1668 case VIDIOC_S_TUNER
:
1670 struct v4l2_tuner
*p
= arg
;
1672 if (!ops
->vidioc_s_tuner
)
1674 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1675 "capability=0x%x, rangelow=%d, "
1676 "rangehigh=%d, signal=%d, afc=%d, "
1677 "rxsubchans=0x%x, audmode=%d\n",
1678 p
->index
, p
->name
, p
->type
,
1679 p
->capability
, p
->rangelow
,
1680 p
->rangehigh
, p
->signal
, p
->afc
,
1681 p
->rxsubchans
, p
->audmode
);
1682 ret
= ops
->vidioc_s_tuner(file
, fh
, p
);
1685 case VIDIOC_G_FREQUENCY
:
1687 struct v4l2_frequency
*p
= arg
;
1689 if (!ops
->vidioc_g_frequency
)
1692 ret
= ops
->vidioc_g_frequency(file
, fh
, p
);
1694 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1695 p
->tuner
, p
->type
, p
->frequency
);
1698 case VIDIOC_S_FREQUENCY
:
1700 struct v4l2_frequency
*p
= arg
;
1702 if (!ops
->vidioc_s_frequency
)
1704 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1705 p
->tuner
, p
->type
, p
->frequency
);
1706 ret
= ops
->vidioc_s_frequency(file
, fh
, p
);
1709 case VIDIOC_G_SLICED_VBI_CAP
:
1711 struct v4l2_sliced_vbi_cap
*p
= arg
;
1713 if (!ops
->vidioc_g_sliced_vbi_cap
)
1716 /* Clear up to type, everything after type is zerod already */
1717 memset(p
, 0, offsetof(struct v4l2_sliced_vbi_cap
, type
));
1719 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1720 ret
= ops
->vidioc_g_sliced_vbi_cap(file
, fh
, p
);
1722 dbgarg2("service_set=%d\n", p
->service_set
);
1725 case VIDIOC_LOG_STATUS
:
1727 if (!ops
->vidioc_log_status
)
1729 ret
= ops
->vidioc_log_status(file
, fh
);
1732 #ifdef CONFIG_VIDEO_ADV_DEBUG
1733 case VIDIOC_DBG_G_REGISTER
:
1735 struct v4l2_dbg_register
*p
= arg
;
1737 if (!capable(CAP_SYS_ADMIN
))
1739 else if (ops
->vidioc_g_register
)
1740 ret
= ops
->vidioc_g_register(file
, fh
, p
);
1743 case VIDIOC_DBG_S_REGISTER
:
1745 struct v4l2_dbg_register
*p
= arg
;
1747 if (!capable(CAP_SYS_ADMIN
))
1749 else if (ops
->vidioc_s_register
)
1750 ret
= ops
->vidioc_s_register(file
, fh
, p
);
1754 case VIDIOC_DBG_G_CHIP_IDENT
:
1756 struct v4l2_dbg_chip_ident
*p
= arg
;
1758 if (!ops
->vidioc_g_chip_ident
)
1760 p
->ident
= V4L2_IDENT_NONE
;
1762 ret
= ops
->vidioc_g_chip_ident(file
, fh
, p
);
1764 dbgarg(cmd
, "chip_ident=%u, revision=0x%x\n", p
->ident
, p
->revision
);
1767 case VIDIOC_S_HW_FREQ_SEEK
:
1769 struct v4l2_hw_freq_seek
*p
= arg
;
1771 if (!ops
->vidioc_s_hw_freq_seek
)
1774 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1775 p
->tuner
, p
->type
, p
->seek_upward
, p
->wrap_around
);
1776 ret
= ops
->vidioc_s_hw_freq_seek(file
, fh
, p
);
1779 case VIDIOC_ENUM_FRAMESIZES
:
1781 struct v4l2_frmsizeenum
*p
= arg
;
1783 if (!ops
->vidioc_enum_framesizes
)
1786 ret
= ops
->vidioc_enum_framesizes(file
, fh
, p
);
1788 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1790 (p
->pixel_format
& 0xff),
1791 (p
->pixel_format
>> 8) & 0xff,
1792 (p
->pixel_format
>> 16) & 0xff,
1793 (p
->pixel_format
>> 24) & 0xff,
1796 case V4L2_FRMSIZE_TYPE_DISCRETE
:
1797 dbgarg3("width = %d, height=%d\n",
1798 p
->discrete
.width
, p
->discrete
.height
);
1800 case V4L2_FRMSIZE_TYPE_STEPWISE
:
1801 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1802 p
->stepwise
.min_width
, p
->stepwise
.min_height
,
1803 p
->stepwise
.step_width
, p
->stepwise
.step_height
,
1804 p
->stepwise
.max_width
, p
->stepwise
.max_height
);
1806 case V4L2_FRMSIZE_TYPE_CONTINUOUS
:
1807 dbgarg3("continuous\n");
1810 dbgarg3("- Unknown type!\n");
1815 case VIDIOC_ENUM_FRAMEINTERVALS
:
1817 struct v4l2_frmivalenum
*p
= arg
;
1819 if (!ops
->vidioc_enum_frameintervals
)
1822 ret
= ops
->vidioc_enum_frameintervals(file
, fh
, p
);
1824 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1825 p
->index
, p
->pixel_format
,
1826 p
->width
, p
->height
, p
->type
);
1828 case V4L2_FRMIVAL_TYPE_DISCRETE
:
1829 dbgarg2("fps=%d/%d\n",
1830 p
->discrete
.numerator
,
1831 p
->discrete
.denominator
);
1833 case V4L2_FRMIVAL_TYPE_STEPWISE
:
1834 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1835 p
->stepwise
.min
.numerator
,
1836 p
->stepwise
.min
.denominator
,
1837 p
->stepwise
.max
.numerator
,
1838 p
->stepwise
.max
.denominator
,
1839 p
->stepwise
.step
.numerator
,
1840 p
->stepwise
.step
.denominator
);
1842 case V4L2_FRMIVAL_TYPE_CONTINUOUS
:
1843 dbgarg2("continuous\n");
1846 dbgarg2("- Unknown type!\n");
1850 case VIDIOC_ENUM_DV_PRESETS
:
1852 struct v4l2_dv_enum_preset
*p
= arg
;
1854 if (!ops
->vidioc_enum_dv_presets
)
1857 ret
= ops
->vidioc_enum_dv_presets(file
, fh
, p
);
1860 "index=%d, preset=%d, name=%s, width=%d,"
1862 p
->index
, p
->preset
, p
->name
, p
->width
,
1866 case VIDIOC_S_DV_PRESET
:
1868 struct v4l2_dv_preset
*p
= arg
;
1870 if (!ops
->vidioc_s_dv_preset
)
1873 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1874 ret
= ops
->vidioc_s_dv_preset(file
, fh
, p
);
1877 case VIDIOC_G_DV_PRESET
:
1879 struct v4l2_dv_preset
*p
= arg
;
1881 if (!ops
->vidioc_g_dv_preset
)
1884 ret
= ops
->vidioc_g_dv_preset(file
, fh
, p
);
1886 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1889 case VIDIOC_QUERY_DV_PRESET
:
1891 struct v4l2_dv_preset
*p
= arg
;
1893 if (!ops
->vidioc_query_dv_preset
)
1896 ret
= ops
->vidioc_query_dv_preset(file
, fh
, p
);
1898 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1901 case VIDIOC_S_DV_TIMINGS
:
1903 struct v4l2_dv_timings
*p
= arg
;
1905 if (!ops
->vidioc_s_dv_timings
)
1909 case V4L2_DV_BT_656_1120
:
1910 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
1911 " width=%d, height=%d, polarities=%x,"
1912 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
1913 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
1914 " il_vfrontporch=%d, il_vsync=%d,"
1915 " il_vbackporch=%d\n",
1916 p
->bt
.interlaced
, p
->bt
.pixelclock
,
1917 p
->bt
.width
, p
->bt
.height
, p
->bt
.polarities
,
1918 p
->bt
.hfrontporch
, p
->bt
.hsync
,
1919 p
->bt
.hbackporch
, p
->bt
.vfrontporch
,
1920 p
->bt
.vsync
, p
->bt
.vbackporch
,
1921 p
->bt
.il_vfrontporch
, p
->bt
.il_vsync
,
1922 p
->bt
.il_vbackporch
);
1923 ret
= ops
->vidioc_s_dv_timings(file
, fh
, p
);
1926 dbgarg2("Unknown type %d!\n", p
->type
);
1931 case VIDIOC_G_DV_TIMINGS
:
1933 struct v4l2_dv_timings
*p
= arg
;
1935 if (!ops
->vidioc_g_dv_timings
)
1938 ret
= ops
->vidioc_g_dv_timings(file
, fh
, p
);
1941 case V4L2_DV_BT_656_1120
:
1942 dbgarg2("bt-656/1120:interlaced=%d,"
1944 " width=%d, height=%d, polarities=%x,"
1945 " hfrontporch=%d, hsync=%d,"
1946 " hbackporch=%d, vfrontporch=%d,"
1947 " vsync=%d, vbackporch=%d,"
1948 " il_vfrontporch=%d, il_vsync=%d,"
1949 " il_vbackporch=%d\n",
1950 p
->bt
.interlaced
, p
->bt
.pixelclock
,
1951 p
->bt
.width
, p
->bt
.height
,
1952 p
->bt
.polarities
, p
->bt
.hfrontporch
,
1953 p
->bt
.hsync
, p
->bt
.hbackporch
,
1954 p
->bt
.vfrontporch
, p
->bt
.vsync
,
1955 p
->bt
.vbackporch
, p
->bt
.il_vfrontporch
,
1956 p
->bt
.il_vsync
, p
->bt
.il_vbackporch
);
1959 dbgarg2("Unknown type %d!\n", p
->type
);
1965 case VIDIOC_DQEVENT
:
1967 struct v4l2_event
*ev
= arg
;
1969 if (!ops
->vidioc_subscribe_event
)
1972 ret
= v4l2_event_dequeue(fh
, ev
, file
->f_flags
& O_NONBLOCK
);
1974 dbgarg(cmd
, "no pending events?");
1978 "pending=%d, type=0x%8.8x, sequence=%d, "
1979 "timestamp=%lu.%9.9lu ",
1980 ev
->pending
, ev
->type
, ev
->sequence
,
1981 ev
->timestamp
.tv_sec
, ev
->timestamp
.tv_nsec
);
1984 case VIDIOC_SUBSCRIBE_EVENT
:
1986 struct v4l2_event_subscription
*sub
= arg
;
1988 if (!ops
->vidioc_subscribe_event
)
1991 ret
= ops
->vidioc_subscribe_event(fh
, sub
);
1993 dbgarg(cmd
, "failed, ret=%ld", ret
);
1996 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
1999 case VIDIOC_UNSUBSCRIBE_EVENT
:
2001 struct v4l2_event_subscription
*sub
= arg
;
2003 if (!ops
->vidioc_unsubscribe_event
)
2006 ret
= ops
->vidioc_unsubscribe_event(fh
, sub
);
2008 dbgarg(cmd
, "failed, ret=%ld", ret
);
2011 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
2016 if (!ops
->vidioc_default
)
2018 ret
= ops
->vidioc_default(file
, fh
, cmd
, arg
);
2023 if (vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
) {
2025 v4l_print_ioctl(vfd
->name
, cmd
);
2026 printk(KERN_CONT
" error %ld\n", ret
);
2033 /* In some cases, only a few fields are used as input, i.e. when the app sets
2034 * "index" and then the driver fills in the rest of the structure for the thing
2035 * with that index. We only need to copy up the first non-input field. */
2036 static unsigned long cmd_input_size(unsigned int cmd
)
2038 /* Size of structure up to and including 'field' */
2039 #define CMDINSIZE(cmd, type, field) \
2040 case VIDIOC_##cmd: \
2041 return offsetof(struct v4l2_##type, field) + \
2042 sizeof(((struct v4l2_##type *)0)->field);
2045 CMDINSIZE(ENUM_FMT
, fmtdesc
, type
);
2046 CMDINSIZE(G_FMT
, format
, type
);
2047 CMDINSIZE(QUERYBUF
, buffer
, type
);
2048 CMDINSIZE(G_PARM
, streamparm
, type
);
2049 CMDINSIZE(ENUMSTD
, standard
, index
);
2050 CMDINSIZE(ENUMINPUT
, input
, index
);
2051 CMDINSIZE(G_CTRL
, control
, id
);
2052 CMDINSIZE(G_TUNER
, tuner
, index
);
2053 CMDINSIZE(QUERYCTRL
, queryctrl
, id
);
2054 CMDINSIZE(QUERYMENU
, querymenu
, index
);
2055 CMDINSIZE(ENUMOUTPUT
, output
, index
);
2056 CMDINSIZE(G_MODULATOR
, modulator
, index
);
2057 CMDINSIZE(G_FREQUENCY
, frequency
, tuner
);
2058 CMDINSIZE(CROPCAP
, cropcap
, type
);
2059 CMDINSIZE(G_CROP
, crop
, type
);
2060 CMDINSIZE(ENUMAUDIO
, audio
, index
);
2061 CMDINSIZE(ENUMAUDOUT
, audioout
, index
);
2062 CMDINSIZE(ENCODER_CMD
, encoder_cmd
, flags
);
2063 CMDINSIZE(TRY_ENCODER_CMD
, encoder_cmd
, flags
);
2064 CMDINSIZE(G_SLICED_VBI_CAP
, sliced_vbi_cap
, type
);
2065 CMDINSIZE(ENUM_FRAMESIZES
, frmsizeenum
, pixel_format
);
2066 CMDINSIZE(ENUM_FRAMEINTERVALS
, frmivalenum
, height
);
2068 return _IOC_SIZE(cmd
);
2072 long video_ioctl2(struct file
*file
,
2073 unsigned int cmd
, unsigned long arg
)
2077 void *parg
= (void *)arg
;
2080 size_t ctrls_size
= 0;
2081 void __user
*user_ptr
= NULL
;
2083 #ifdef __OLD_VIDIOC_
2084 cmd
= video_fix_command(cmd
);
2086 is_ext_ctrl
= (cmd
== VIDIOC_S_EXT_CTRLS
|| cmd
== VIDIOC_G_EXT_CTRLS
||
2087 cmd
== VIDIOC_TRY_EXT_CTRLS
);
2089 /* Copy arguments into temp kernel buffer */
2090 if (_IOC_DIR(cmd
) != _IOC_NONE
) {
2091 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
2094 /* too big to allocate from stack */
2095 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
2102 if (_IOC_DIR(cmd
) & _IOC_WRITE
) {
2103 unsigned long n
= cmd_input_size(cmd
);
2105 if (copy_from_user(parg
, (void __user
*)arg
, n
))
2108 /* zero out anything we don't copy from userspace */
2109 if (n
< _IOC_SIZE(cmd
))
2110 memset((u8
*)parg
+ n
, 0, _IOC_SIZE(cmd
) - n
);
2112 /* read-only ioctl */
2113 memset(parg
, 0, _IOC_SIZE(cmd
));
2118 struct v4l2_ext_controls
*p
= parg
;
2120 /* In case of an error, tell the caller that it wasn't
2121 a specific control that caused it. */
2122 p
->error_idx
= p
->count
;
2123 user_ptr
= (void __user
*)p
->controls
;
2125 ctrls_size
= sizeof(struct v4l2_ext_control
) * p
->count
;
2126 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
2127 mbuf
= kmalloc(ctrls_size
, GFP_KERNEL
);
2132 if (copy_from_user(mbuf
, user_ptr
, ctrls_size
))
2139 err
= __video_do_ioctl(file
, cmd
, parg
);
2140 if (err
== -ENOIOCTLCMD
)
2143 struct v4l2_ext_controls
*p
= parg
;
2145 p
->controls
= (void *)user_ptr
;
2146 if (p
->count
&& err
== 0 && copy_to_user(user_ptr
, mbuf
, ctrls_size
))
2154 /* Copy results into user buffer */
2155 switch (_IOC_DIR(cmd
)) {
2157 case (_IOC_WRITE
| _IOC_READ
):
2158 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
2167 EXPORT_SYMBOL(video_ioctl2
);