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/videodev2.h>
23 #include <media/v4l2-common.h>
24 #include <media/v4l2-ioctl.h>
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-fh.h>
27 #include <media/v4l2-event.h>
28 #include <media/v4l2-chip-ident.h>
30 #define dbgarg(cmd, fmt, arg...) \
32 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
33 printk(KERN_DEBUG "%s: ", vfd->name); \
34 v4l_printk_ioctl(cmd); \
35 printk(" " fmt, ## arg); \
39 #define dbgarg2(fmt, arg...) \
41 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
42 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
45 #define dbgarg3(fmt, arg...) \
47 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
48 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
51 /* Zero out the end of the struct pointed to by p. Everthing after, but
52 * not including, the specified field is cleared. */
53 #define CLEAR_AFTER_FIELD(p, field) \
54 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
55 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
62 static const struct std_descr standards
[] = {
63 { V4L2_STD_NTSC
, "NTSC" },
64 { V4L2_STD_NTSC_M
, "NTSC-M" },
65 { V4L2_STD_NTSC_M_JP
, "NTSC-M-JP" },
66 { V4L2_STD_NTSC_M_KR
, "NTSC-M-KR" },
67 { V4L2_STD_NTSC_443
, "NTSC-443" },
68 { V4L2_STD_PAL
, "PAL" },
69 { V4L2_STD_PAL_BG
, "PAL-BG" },
70 { V4L2_STD_PAL_B
, "PAL-B" },
71 { V4L2_STD_PAL_B1
, "PAL-B1" },
72 { V4L2_STD_PAL_G
, "PAL-G" },
73 { V4L2_STD_PAL_H
, "PAL-H" },
74 { V4L2_STD_PAL_I
, "PAL-I" },
75 { V4L2_STD_PAL_DK
, "PAL-DK" },
76 { V4L2_STD_PAL_D
, "PAL-D" },
77 { V4L2_STD_PAL_D1
, "PAL-D1" },
78 { V4L2_STD_PAL_K
, "PAL-K" },
79 { V4L2_STD_PAL_M
, "PAL-M" },
80 { V4L2_STD_PAL_N
, "PAL-N" },
81 { V4L2_STD_PAL_Nc
, "PAL-Nc" },
82 { V4L2_STD_PAL_60
, "PAL-60" },
83 { V4L2_STD_SECAM
, "SECAM" },
84 { V4L2_STD_SECAM_B
, "SECAM-B" },
85 { V4L2_STD_SECAM_G
, "SECAM-G" },
86 { V4L2_STD_SECAM_H
, "SECAM-H" },
87 { V4L2_STD_SECAM_DK
, "SECAM-DK" },
88 { V4L2_STD_SECAM_D
, "SECAM-D" },
89 { V4L2_STD_SECAM_K
, "SECAM-K" },
90 { V4L2_STD_SECAM_K1
, "SECAM-K1" },
91 { V4L2_STD_SECAM_L
, "SECAM-L" },
92 { V4L2_STD_SECAM_LC
, "SECAM-Lc" },
96 /* video4linux standard ID conversion to standard name
98 const char *v4l2_norm_to_name(v4l2_std_id id
)
103 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
104 64 bit comparations. So, on that architecture, with some gcc
105 variants, compilation fails. Currently, the max value is 30bit wide.
109 for (i
= 0; standards
[i
].std
; i
++)
110 if (myid
== standards
[i
].std
)
112 return standards
[i
].descr
;
114 EXPORT_SYMBOL(v4l2_norm_to_name
);
116 /* Returns frame period for the given standard */
117 void v4l2_video_std_frame_period(int id
, struct v4l2_fract
*frameperiod
)
119 if (id
& V4L2_STD_525_60
) {
120 frameperiod
->numerator
= 1001;
121 frameperiod
->denominator
= 30000;
123 frameperiod
->numerator
= 1;
124 frameperiod
->denominator
= 25;
127 EXPORT_SYMBOL(v4l2_video_std_frame_period
);
129 /* Fill in the fields of a v4l2_standard structure according to the
130 'id' and 'transmission' parameters. Returns negative on error. */
131 int v4l2_video_std_construct(struct v4l2_standard
*vs
,
132 int id
, const char *name
)
135 v4l2_video_std_frame_period(id
, &vs
->frameperiod
);
136 vs
->framelines
= (id
& V4L2_STD_525_60
) ? 525 : 625;
137 strlcpy(vs
->name
, name
, sizeof(vs
->name
));
140 EXPORT_SYMBOL(v4l2_video_std_construct
);
142 /* ----------------------------------------------------------------- */
143 /* some arrays for pretty-printing debug messages of enum types */
145 const char *v4l2_field_names
[] = {
146 [V4L2_FIELD_ANY
] = "any",
147 [V4L2_FIELD_NONE
] = "none",
148 [V4L2_FIELD_TOP
] = "top",
149 [V4L2_FIELD_BOTTOM
] = "bottom",
150 [V4L2_FIELD_INTERLACED
] = "interlaced",
151 [V4L2_FIELD_SEQ_TB
] = "seq-tb",
152 [V4L2_FIELD_SEQ_BT
] = "seq-bt",
153 [V4L2_FIELD_ALTERNATE
] = "alternate",
154 [V4L2_FIELD_INTERLACED_TB
] = "interlaced-tb",
155 [V4L2_FIELD_INTERLACED_BT
] = "interlaced-bt",
157 EXPORT_SYMBOL(v4l2_field_names
);
159 const char *v4l2_type_names
[] = {
160 [V4L2_BUF_TYPE_VIDEO_CAPTURE
] = "vid-cap",
161 [V4L2_BUF_TYPE_VIDEO_OVERLAY
] = "vid-overlay",
162 [V4L2_BUF_TYPE_VIDEO_OUTPUT
] = "vid-out",
163 [V4L2_BUF_TYPE_VBI_CAPTURE
] = "vbi-cap",
164 [V4L2_BUF_TYPE_VBI_OUTPUT
] = "vbi-out",
165 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
] = "sliced-vbi-cap",
166 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
] = "sliced-vbi-out",
167 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
] = "vid-out-overlay",
169 EXPORT_SYMBOL(v4l2_type_names
);
171 static const char *v4l2_memory_names
[] = {
172 [V4L2_MEMORY_MMAP
] = "mmap",
173 [V4L2_MEMORY_USERPTR
] = "userptr",
174 [V4L2_MEMORY_OVERLAY
] = "overlay",
177 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
180 /* ------------------------------------------------------------------ */
181 /* debug help functions */
182 static const char *v4l2_ioctls
[] = {
183 [_IOC_NR(VIDIOC_QUERYCAP
)] = "VIDIOC_QUERYCAP",
184 [_IOC_NR(VIDIOC_RESERVED
)] = "VIDIOC_RESERVED",
185 [_IOC_NR(VIDIOC_ENUM_FMT
)] = "VIDIOC_ENUM_FMT",
186 [_IOC_NR(VIDIOC_G_FMT
)] = "VIDIOC_G_FMT",
187 [_IOC_NR(VIDIOC_S_FMT
)] = "VIDIOC_S_FMT",
188 [_IOC_NR(VIDIOC_REQBUFS
)] = "VIDIOC_REQBUFS",
189 [_IOC_NR(VIDIOC_QUERYBUF
)] = "VIDIOC_QUERYBUF",
190 [_IOC_NR(VIDIOC_G_FBUF
)] = "VIDIOC_G_FBUF",
191 [_IOC_NR(VIDIOC_S_FBUF
)] = "VIDIOC_S_FBUF",
192 [_IOC_NR(VIDIOC_OVERLAY
)] = "VIDIOC_OVERLAY",
193 [_IOC_NR(VIDIOC_QBUF
)] = "VIDIOC_QBUF",
194 [_IOC_NR(VIDIOC_DQBUF
)] = "VIDIOC_DQBUF",
195 [_IOC_NR(VIDIOC_STREAMON
)] = "VIDIOC_STREAMON",
196 [_IOC_NR(VIDIOC_STREAMOFF
)] = "VIDIOC_STREAMOFF",
197 [_IOC_NR(VIDIOC_G_PARM
)] = "VIDIOC_G_PARM",
198 [_IOC_NR(VIDIOC_S_PARM
)] = "VIDIOC_S_PARM",
199 [_IOC_NR(VIDIOC_G_STD
)] = "VIDIOC_G_STD",
200 [_IOC_NR(VIDIOC_S_STD
)] = "VIDIOC_S_STD",
201 [_IOC_NR(VIDIOC_ENUMSTD
)] = "VIDIOC_ENUMSTD",
202 [_IOC_NR(VIDIOC_ENUMINPUT
)] = "VIDIOC_ENUMINPUT",
203 [_IOC_NR(VIDIOC_G_CTRL
)] = "VIDIOC_G_CTRL",
204 [_IOC_NR(VIDIOC_S_CTRL
)] = "VIDIOC_S_CTRL",
205 [_IOC_NR(VIDIOC_G_TUNER
)] = "VIDIOC_G_TUNER",
206 [_IOC_NR(VIDIOC_S_TUNER
)] = "VIDIOC_S_TUNER",
207 [_IOC_NR(VIDIOC_G_AUDIO
)] = "VIDIOC_G_AUDIO",
208 [_IOC_NR(VIDIOC_S_AUDIO
)] = "VIDIOC_S_AUDIO",
209 [_IOC_NR(VIDIOC_QUERYCTRL
)] = "VIDIOC_QUERYCTRL",
210 [_IOC_NR(VIDIOC_QUERYMENU
)] = "VIDIOC_QUERYMENU",
211 [_IOC_NR(VIDIOC_G_INPUT
)] = "VIDIOC_G_INPUT",
212 [_IOC_NR(VIDIOC_S_INPUT
)] = "VIDIOC_S_INPUT",
213 [_IOC_NR(VIDIOC_G_OUTPUT
)] = "VIDIOC_G_OUTPUT",
214 [_IOC_NR(VIDIOC_S_OUTPUT
)] = "VIDIOC_S_OUTPUT",
215 [_IOC_NR(VIDIOC_ENUMOUTPUT
)] = "VIDIOC_ENUMOUTPUT",
216 [_IOC_NR(VIDIOC_G_AUDOUT
)] = "VIDIOC_G_AUDOUT",
217 [_IOC_NR(VIDIOC_S_AUDOUT
)] = "VIDIOC_S_AUDOUT",
218 [_IOC_NR(VIDIOC_G_MODULATOR
)] = "VIDIOC_G_MODULATOR",
219 [_IOC_NR(VIDIOC_S_MODULATOR
)] = "VIDIOC_S_MODULATOR",
220 [_IOC_NR(VIDIOC_G_FREQUENCY
)] = "VIDIOC_G_FREQUENCY",
221 [_IOC_NR(VIDIOC_S_FREQUENCY
)] = "VIDIOC_S_FREQUENCY",
222 [_IOC_NR(VIDIOC_CROPCAP
)] = "VIDIOC_CROPCAP",
223 [_IOC_NR(VIDIOC_G_CROP
)] = "VIDIOC_G_CROP",
224 [_IOC_NR(VIDIOC_S_CROP
)] = "VIDIOC_S_CROP",
225 [_IOC_NR(VIDIOC_G_JPEGCOMP
)] = "VIDIOC_G_JPEGCOMP",
226 [_IOC_NR(VIDIOC_S_JPEGCOMP
)] = "VIDIOC_S_JPEGCOMP",
227 [_IOC_NR(VIDIOC_QUERYSTD
)] = "VIDIOC_QUERYSTD",
228 [_IOC_NR(VIDIOC_TRY_FMT
)] = "VIDIOC_TRY_FMT",
229 [_IOC_NR(VIDIOC_ENUMAUDIO
)] = "VIDIOC_ENUMAUDIO",
230 [_IOC_NR(VIDIOC_ENUMAUDOUT
)] = "VIDIOC_ENUMAUDOUT",
231 [_IOC_NR(VIDIOC_G_PRIORITY
)] = "VIDIOC_G_PRIORITY",
232 [_IOC_NR(VIDIOC_S_PRIORITY
)] = "VIDIOC_S_PRIORITY",
233 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP
)] = "VIDIOC_G_SLICED_VBI_CAP",
234 [_IOC_NR(VIDIOC_LOG_STATUS
)] = "VIDIOC_LOG_STATUS",
235 [_IOC_NR(VIDIOC_G_EXT_CTRLS
)] = "VIDIOC_G_EXT_CTRLS",
236 [_IOC_NR(VIDIOC_S_EXT_CTRLS
)] = "VIDIOC_S_EXT_CTRLS",
237 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS
)] = "VIDIOC_TRY_EXT_CTRLS",
239 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES
)] = "VIDIOC_ENUM_FRAMESIZES",
240 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS
)] = "VIDIOC_ENUM_FRAMEINTERVALS",
241 [_IOC_NR(VIDIOC_G_ENC_INDEX
)] = "VIDIOC_G_ENC_INDEX",
242 [_IOC_NR(VIDIOC_ENCODER_CMD
)] = "VIDIOC_ENCODER_CMD",
243 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD
)] = "VIDIOC_TRY_ENCODER_CMD",
245 [_IOC_NR(VIDIOC_DBG_S_REGISTER
)] = "VIDIOC_DBG_S_REGISTER",
246 [_IOC_NR(VIDIOC_DBG_G_REGISTER
)] = "VIDIOC_DBG_G_REGISTER",
248 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT
)] = "VIDIOC_DBG_G_CHIP_IDENT",
249 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK
)] = "VIDIOC_S_HW_FREQ_SEEK",
251 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS
)] = "VIDIOC_ENUM_DV_PRESETS",
252 [_IOC_NR(VIDIOC_S_DV_PRESET
)] = "VIDIOC_S_DV_PRESET",
253 [_IOC_NR(VIDIOC_G_DV_PRESET
)] = "VIDIOC_G_DV_PRESET",
254 [_IOC_NR(VIDIOC_QUERY_DV_PRESET
)] = "VIDIOC_QUERY_DV_PRESET",
255 [_IOC_NR(VIDIOC_S_DV_TIMINGS
)] = "VIDIOC_S_DV_TIMINGS",
256 [_IOC_NR(VIDIOC_G_DV_TIMINGS
)] = "VIDIOC_G_DV_TIMINGS",
257 [_IOC_NR(VIDIOC_DQEVENT
)] = "VIDIOC_DQEVENT",
258 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT
)] = "VIDIOC_SUBSCRIBE_EVENT",
259 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT
)] = "VIDIOC_UNSUBSCRIBE_EVENT",
261 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
263 /* Common ioctl debug function. This function can be used by
264 external ioctl messages as well as internal V4L ioctl */
265 void v4l_printk_ioctl(unsigned int cmd
)
269 switch (_IOC_TYPE(cmd
)) {
274 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
) {
278 printk("%s", v4l2_ioctls
[_IOC_NR(cmd
)]);
284 switch (_IOC_DIR(cmd
)) {
285 case _IOC_NONE
: dir
= "--"; break;
286 case _IOC_READ
: dir
= "r-"; break;
287 case _IOC_WRITE
: dir
= "-w"; break;
288 case _IOC_READ
| _IOC_WRITE
: dir
= "rw"; break;
289 default: dir
= "*ERR*"; break;
291 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
292 type
, _IOC_TYPE(cmd
), dir
, _IOC_NR(cmd
), cmd
);
294 EXPORT_SYMBOL(v4l_printk_ioctl
);
297 * helper function -- handles userspace copying for ioctl arguments
302 video_fix_command(unsigned int cmd
)
305 case VIDIOC_OVERLAY_OLD
:
306 cmd
= VIDIOC_OVERLAY
;
308 case VIDIOC_S_PARM_OLD
:
311 case VIDIOC_S_CTRL_OLD
:
314 case VIDIOC_G_AUDIO_OLD
:
315 cmd
= VIDIOC_G_AUDIO
;
317 case VIDIOC_G_AUDOUT_OLD
:
318 cmd
= VIDIOC_G_AUDOUT
;
320 case VIDIOC_CROPCAP_OLD
:
321 cmd
= VIDIOC_CROPCAP
;
329 * Obsolete usercopy function - Should be removed soon
332 video_usercopy(struct file
*file
, unsigned int cmd
, unsigned long arg
,
340 size_t ctrls_size
= 0;
341 void __user
*user_ptr
= NULL
;
344 cmd
= video_fix_command(cmd
);
346 is_ext_ctrl
= (cmd
== VIDIOC_S_EXT_CTRLS
|| cmd
== VIDIOC_G_EXT_CTRLS
||
347 cmd
== VIDIOC_TRY_EXT_CTRLS
);
349 /* Copy arguments into temp kernel buffer */
350 switch (_IOC_DIR(cmd
)) {
356 case (_IOC_WRITE
| _IOC_READ
):
357 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
360 /* too big to allocate from stack */
361 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
368 if (_IOC_DIR(cmd
) & _IOC_WRITE
)
369 if (copy_from_user(parg
, (void __user
*)arg
, _IOC_SIZE(cmd
)))
374 struct v4l2_ext_controls
*p
= parg
;
376 /* In case of an error, tell the caller that it wasn't
377 a specific control that caused it. */
378 p
->error_idx
= p
->count
;
379 user_ptr
= (void __user
*)p
->controls
;
381 ctrls_size
= sizeof(struct v4l2_ext_control
) * p
->count
;
382 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
383 mbuf
= kmalloc(ctrls_size
, GFP_KERNEL
);
388 if (copy_from_user(mbuf
, user_ptr
, ctrls_size
))
395 err
= func(file
, cmd
, parg
);
396 if (err
== -ENOIOCTLCMD
)
399 struct v4l2_ext_controls
*p
= parg
;
401 p
->controls
= (void *)user_ptr
;
402 if (p
->count
&& err
== 0 && copy_to_user(user_ptr
, mbuf
, ctrls_size
))
410 /* Copy results into user buffer */
411 switch (_IOC_DIR(cmd
)) {
413 case (_IOC_WRITE
| _IOC_READ
):
414 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
423 EXPORT_SYMBOL(video_usercopy
);
425 static void dbgbuf(unsigned int cmd
, struct video_device
*vfd
,
426 struct v4l2_buffer
*p
)
428 struct v4l2_timecode
*tc
= &p
->timecode
;
430 dbgarg(cmd
, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
431 "bytesused=%d, flags=0x%08d, "
432 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
433 p
->timestamp
.tv_sec
/ 3600,
434 (int)(p
->timestamp
.tv_sec
/ 60) % 60,
435 (int)(p
->timestamp
.tv_sec
% 60),
436 (long)p
->timestamp
.tv_usec
,
438 prt_names(p
->type
, v4l2_type_names
),
439 p
->bytesused
, p
->flags
,
440 p
->field
, p
->sequence
,
441 prt_names(p
->memory
, v4l2_memory_names
),
442 p
->m
.userptr
, p
->length
);
443 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
444 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
445 tc
->hours
, tc
->minutes
, tc
->seconds
,
446 tc
->type
, tc
->flags
, tc
->frames
, *(__u32
*)tc
->userbits
);
449 static inline void dbgrect(struct video_device
*vfd
, char *s
,
452 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s
, r
->left
, r
->top
,
453 r
->width
, r
->height
);
456 static inline void v4l_print_pix_fmt(struct video_device
*vfd
,
457 struct v4l2_pix_format
*fmt
)
459 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
460 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
461 fmt
->width
, fmt
->height
,
462 (fmt
->pixelformat
& 0xff),
463 (fmt
->pixelformat
>> 8) & 0xff,
464 (fmt
->pixelformat
>> 16) & 0xff,
465 (fmt
->pixelformat
>> 24) & 0xff,
466 prt_names(fmt
->field
, v4l2_field_names
),
467 fmt
->bytesperline
, fmt
->sizeimage
, fmt
->colorspace
);
470 static inline void v4l_print_ext_ctrls(unsigned int cmd
,
471 struct video_device
*vfd
, struct v4l2_ext_controls
*c
, int show_vals
)
475 if (!(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
))
478 printk(KERN_CONT
"class=0x%x", c
->ctrl_class
);
479 for (i
= 0; i
< c
->count
; i
++) {
480 if (show_vals
&& !c
->controls
[i
].size
)
481 printk(KERN_CONT
" id/val=0x%x/0x%x",
482 c
->controls
[i
].id
, c
->controls
[i
].value
);
484 printk(KERN_CONT
" id=0x%x,size=%u",
485 c
->controls
[i
].id
, c
->controls
[i
].size
);
487 printk(KERN_CONT
"\n");
490 static inline int check_ext_ctrls(struct v4l2_ext_controls
*c
, int allow_priv
)
494 /* zero the reserved fields */
495 c
->reserved
[0] = c
->reserved
[1] = 0;
496 for (i
= 0; i
< c
->count
; i
++)
497 c
->controls
[i
].reserved2
[0] = 0;
499 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
500 when using extended controls.
501 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
502 is it allowed for backwards compatibility.
504 if (!allow_priv
&& c
->ctrl_class
== V4L2_CID_PRIVATE_BASE
)
506 /* Check that all controls are from the same control class. */
507 for (i
= 0; i
< c
->count
; i
++) {
508 if (V4L2_CTRL_ID2CLASS(c
->controls
[i
].id
) != c
->ctrl_class
) {
516 static int check_fmt(const struct v4l2_ioctl_ops
*ops
, enum v4l2_buf_type type
)
522 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
523 if (ops
->vidioc_g_fmt_vid_cap
)
526 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
527 if (ops
->vidioc_g_fmt_vid_overlay
)
530 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
531 if (ops
->vidioc_g_fmt_vid_out
)
534 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
535 if (ops
->vidioc_g_fmt_vid_out_overlay
)
538 case V4L2_BUF_TYPE_VBI_CAPTURE
:
539 if (ops
->vidioc_g_fmt_vbi_cap
)
542 case V4L2_BUF_TYPE_VBI_OUTPUT
:
543 if (ops
->vidioc_g_fmt_vbi_out
)
546 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
547 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
550 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
551 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
554 case V4L2_BUF_TYPE_PRIVATE
:
555 if (ops
->vidioc_g_fmt_type_private
)
562 static long __video_do_ioctl(struct file
*file
,
563 unsigned int cmd
, void *arg
)
565 struct video_device
*vfd
= video_devdata(file
);
566 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
567 void *fh
= file
->private_data
;
571 printk(KERN_WARNING
"videodev: \"%s\" has no ioctl_ops.\n",
576 if ((vfd
->debug
& V4L2_DEBUG_IOCTL
) &&
577 !(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
)) {
578 v4l_print_ioctl(vfd
->name
, cmd
);
579 printk(KERN_CONT
"\n");
584 /* --- capabilities ------------------------------------------ */
585 case VIDIOC_QUERYCAP
:
587 struct v4l2_capability
*cap
= (struct v4l2_capability
*)arg
;
589 if (!ops
->vidioc_querycap
)
592 ret
= ops
->vidioc_querycap(file
, fh
, cap
);
594 dbgarg(cmd
, "driver=%s, card=%s, bus=%s, "
596 "capabilities=0x%08x\n",
597 cap
->driver
, cap
->card
, cap
->bus_info
,
603 /* --- priority ------------------------------------------ */
604 case VIDIOC_G_PRIORITY
:
606 enum v4l2_priority
*p
= arg
;
608 if (!ops
->vidioc_g_priority
)
610 ret
= ops
->vidioc_g_priority(file
, fh
, p
);
612 dbgarg(cmd
, "priority is %d\n", *p
);
615 case VIDIOC_S_PRIORITY
:
617 enum v4l2_priority
*p
= arg
;
619 if (!ops
->vidioc_s_priority
)
621 dbgarg(cmd
, "setting priority to %d\n", *p
);
622 ret
= ops
->vidioc_s_priority(file
, fh
, *p
);
626 /* --- capture ioctls ---------------------------------------- */
627 case VIDIOC_ENUM_FMT
:
629 struct v4l2_fmtdesc
*f
= arg
;
632 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
633 if (ops
->vidioc_enum_fmt_vid_cap
)
634 ret
= ops
->vidioc_enum_fmt_vid_cap(file
, fh
, f
);
636 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
637 if (ops
->vidioc_enum_fmt_vid_overlay
)
638 ret
= ops
->vidioc_enum_fmt_vid_overlay(file
,
641 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
642 if (ops
->vidioc_enum_fmt_vid_out
)
643 ret
= ops
->vidioc_enum_fmt_vid_out(file
, fh
, f
);
645 case V4L2_BUF_TYPE_PRIVATE
:
646 if (ops
->vidioc_enum_fmt_type_private
)
647 ret
= ops
->vidioc_enum_fmt_type_private(file
,
654 dbgarg(cmd
, "index=%d, type=%d, flags=%d, "
655 "pixelformat=%c%c%c%c, description='%s'\n",
656 f
->index
, f
->type
, f
->flags
,
657 (f
->pixelformat
& 0xff),
658 (f
->pixelformat
>> 8) & 0xff,
659 (f
->pixelformat
>> 16) & 0xff,
660 (f
->pixelformat
>> 24) & 0xff,
666 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
668 /* FIXME: Should be one dump per type */
669 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
672 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
673 if (ops
->vidioc_g_fmt_vid_cap
)
674 ret
= ops
->vidioc_g_fmt_vid_cap(file
, fh
, f
);
676 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
678 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
679 if (ops
->vidioc_g_fmt_vid_overlay
)
680 ret
= ops
->vidioc_g_fmt_vid_overlay(file
,
683 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
684 if (ops
->vidioc_g_fmt_vid_out
)
685 ret
= ops
->vidioc_g_fmt_vid_out(file
, fh
, f
);
687 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
689 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
690 if (ops
->vidioc_g_fmt_vid_out_overlay
)
691 ret
= ops
->vidioc_g_fmt_vid_out_overlay(file
,
694 case V4L2_BUF_TYPE_VBI_CAPTURE
:
695 if (ops
->vidioc_g_fmt_vbi_cap
)
696 ret
= ops
->vidioc_g_fmt_vbi_cap(file
, fh
, f
);
698 case V4L2_BUF_TYPE_VBI_OUTPUT
:
699 if (ops
->vidioc_g_fmt_vbi_out
)
700 ret
= ops
->vidioc_g_fmt_vbi_out(file
, fh
, f
);
702 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
703 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
704 ret
= ops
->vidioc_g_fmt_sliced_vbi_cap(file
,
707 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
708 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
709 ret
= ops
->vidioc_g_fmt_sliced_vbi_out(file
,
712 case V4L2_BUF_TYPE_PRIVATE
:
713 if (ops
->vidioc_g_fmt_type_private
)
714 ret
= ops
->vidioc_g_fmt_type_private(file
,
723 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
725 /* FIXME: Should be one dump per type */
726 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
729 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
730 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
731 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
732 if (ops
->vidioc_s_fmt_vid_cap
)
733 ret
= ops
->vidioc_s_fmt_vid_cap(file
, fh
, f
);
735 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
736 CLEAR_AFTER_FIELD(f
, fmt
.win
);
737 if (ops
->vidioc_s_fmt_vid_overlay
)
738 ret
= ops
->vidioc_s_fmt_vid_overlay(file
,
741 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
742 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
743 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
744 if (ops
->vidioc_s_fmt_vid_out
)
745 ret
= ops
->vidioc_s_fmt_vid_out(file
, fh
, f
);
747 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
748 CLEAR_AFTER_FIELD(f
, fmt
.win
);
749 if (ops
->vidioc_s_fmt_vid_out_overlay
)
750 ret
= ops
->vidioc_s_fmt_vid_out_overlay(file
,
753 case V4L2_BUF_TYPE_VBI_CAPTURE
:
754 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
755 if (ops
->vidioc_s_fmt_vbi_cap
)
756 ret
= ops
->vidioc_s_fmt_vbi_cap(file
, fh
, f
);
758 case V4L2_BUF_TYPE_VBI_OUTPUT
:
759 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
760 if (ops
->vidioc_s_fmt_vbi_out
)
761 ret
= ops
->vidioc_s_fmt_vbi_out(file
, fh
, f
);
763 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
764 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
765 if (ops
->vidioc_s_fmt_sliced_vbi_cap
)
766 ret
= ops
->vidioc_s_fmt_sliced_vbi_cap(file
,
769 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
770 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
771 if (ops
->vidioc_s_fmt_sliced_vbi_out
)
772 ret
= ops
->vidioc_s_fmt_sliced_vbi_out(file
,
775 case V4L2_BUF_TYPE_PRIVATE
:
776 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
777 if (ops
->vidioc_s_fmt_type_private
)
778 ret
= ops
->vidioc_s_fmt_type_private(file
,
786 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
788 /* FIXME: Should be one dump per type */
789 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
,
792 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
793 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
794 if (ops
->vidioc_try_fmt_vid_cap
)
795 ret
= ops
->vidioc_try_fmt_vid_cap(file
, fh
, f
);
797 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
799 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
800 CLEAR_AFTER_FIELD(f
, fmt
.win
);
801 if (ops
->vidioc_try_fmt_vid_overlay
)
802 ret
= ops
->vidioc_try_fmt_vid_overlay(file
,
805 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
806 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
807 if (ops
->vidioc_try_fmt_vid_out
)
808 ret
= ops
->vidioc_try_fmt_vid_out(file
, fh
, f
);
810 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
812 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
813 CLEAR_AFTER_FIELD(f
, fmt
.win
);
814 if (ops
->vidioc_try_fmt_vid_out_overlay
)
815 ret
= ops
->vidioc_try_fmt_vid_out_overlay(file
,
818 case V4L2_BUF_TYPE_VBI_CAPTURE
:
819 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
820 if (ops
->vidioc_try_fmt_vbi_cap
)
821 ret
= ops
->vidioc_try_fmt_vbi_cap(file
, fh
, f
);
823 case V4L2_BUF_TYPE_VBI_OUTPUT
:
824 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
825 if (ops
->vidioc_try_fmt_vbi_out
)
826 ret
= ops
->vidioc_try_fmt_vbi_out(file
, fh
, f
);
828 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
829 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
830 if (ops
->vidioc_try_fmt_sliced_vbi_cap
)
831 ret
= ops
->vidioc_try_fmt_sliced_vbi_cap(file
,
834 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
835 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
836 if (ops
->vidioc_try_fmt_sliced_vbi_out
)
837 ret
= ops
->vidioc_try_fmt_sliced_vbi_out(file
,
840 case V4L2_BUF_TYPE_PRIVATE
:
841 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
842 if (ops
->vidioc_try_fmt_type_private
)
843 ret
= ops
->vidioc_try_fmt_type_private(file
,
850 /* FIXME: Those buf reqs could be handled here,
851 with some changes on videobuf to allow its header to be included at
852 videodev2.h or being merged at videodev2.
856 struct v4l2_requestbuffers
*p
= arg
;
858 if (!ops
->vidioc_reqbufs
)
860 ret
= check_fmt(ops
, p
->type
);
864 if (p
->type
< V4L2_BUF_TYPE_PRIVATE
)
865 CLEAR_AFTER_FIELD(p
, memory
);
867 ret
= ops
->vidioc_reqbufs(file
, fh
, p
);
868 dbgarg(cmd
, "count=%d, type=%s, memory=%s\n",
870 prt_names(p
->type
, v4l2_type_names
),
871 prt_names(p
->memory
, v4l2_memory_names
));
874 case VIDIOC_QUERYBUF
:
876 struct v4l2_buffer
*p
= arg
;
878 if (!ops
->vidioc_querybuf
)
880 ret
= check_fmt(ops
, p
->type
);
884 ret
= ops
->vidioc_querybuf(file
, fh
, p
);
891 struct v4l2_buffer
*p
= arg
;
893 if (!ops
->vidioc_qbuf
)
895 ret
= check_fmt(ops
, p
->type
);
899 ret
= ops
->vidioc_qbuf(file
, fh
, p
);
906 struct v4l2_buffer
*p
= arg
;
908 if (!ops
->vidioc_dqbuf
)
910 ret
= check_fmt(ops
, p
->type
);
914 ret
= ops
->vidioc_dqbuf(file
, fh
, p
);
923 if (!ops
->vidioc_overlay
)
925 dbgarg(cmd
, "value=%d\n", *i
);
926 ret
= ops
->vidioc_overlay(file
, fh
, *i
);
931 struct v4l2_framebuffer
*p
= arg
;
933 if (!ops
->vidioc_g_fbuf
)
935 ret
= ops
->vidioc_g_fbuf(file
, fh
, arg
);
937 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
938 p
->capability
, p
->flags
,
939 (unsigned long)p
->base
);
940 v4l_print_pix_fmt(vfd
, &p
->fmt
);
946 struct v4l2_framebuffer
*p
= arg
;
948 if (!ops
->vidioc_s_fbuf
)
950 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
951 p
->capability
, p
->flags
, (unsigned long)p
->base
);
952 v4l_print_pix_fmt(vfd
, &p
->fmt
);
953 ret
= ops
->vidioc_s_fbuf(file
, fh
, arg
);
956 case VIDIOC_STREAMON
:
958 enum v4l2_buf_type i
= *(int *)arg
;
960 if (!ops
->vidioc_streamon
)
962 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
963 ret
= ops
->vidioc_streamon(file
, fh
, i
);
966 case VIDIOC_STREAMOFF
:
968 enum v4l2_buf_type i
= *(int *)arg
;
970 if (!ops
->vidioc_streamoff
)
972 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
973 ret
= ops
->vidioc_streamoff(file
, fh
, i
);
976 /* ---------- tv norms ---------- */
979 struct v4l2_standard
*p
= arg
;
980 v4l2_std_id id
= vfd
->tvnorms
, curr_id
= 0;
981 unsigned int index
= p
->index
, i
, j
= 0;
982 const char *descr
= "";
984 /* Return norm array in a canonical way */
985 for (i
= 0; i
<= index
&& id
; i
++) {
986 /* last std value in the standards array is 0, so this
987 while always ends there since (id & 0) == 0. */
988 while ((id
& standards
[j
].std
) != standards
[j
].std
)
990 curr_id
= standards
[j
].std
;
991 descr
= standards
[j
].descr
;
995 if (curr_id
!= V4L2_STD_PAL
&&
996 curr_id
!= V4L2_STD_SECAM
&&
997 curr_id
!= V4L2_STD_NTSC
)
1003 v4l2_video_std_construct(p
, curr_id
, descr
);
1005 dbgarg(cmd
, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1006 "framelines=%d\n", p
->index
,
1007 (unsigned long long)p
->id
, p
->name
,
1008 p
->frameperiod
.numerator
,
1009 p
->frameperiod
.denominator
,
1017 v4l2_std_id
*id
= arg
;
1020 /* Calls the specific handler */
1021 if (ops
->vidioc_g_std
)
1022 ret
= ops
->vidioc_g_std(file
, fh
, id
);
1023 else if (vfd
->current_norm
)
1024 *id
= vfd
->current_norm
;
1029 dbgarg(cmd
, "std=0x%08Lx\n", (long long unsigned)*id
);
1034 v4l2_std_id
*id
= arg
, norm
;
1036 dbgarg(cmd
, "std=%08Lx\n", (long long unsigned)*id
);
1038 norm
= (*id
) & vfd
->tvnorms
;
1039 if (vfd
->tvnorms
&& !norm
) /* Check if std is supported */
1042 /* Calls the specific handler */
1043 if (ops
->vidioc_s_std
)
1044 ret
= ops
->vidioc_s_std(file
, fh
, &norm
);
1048 /* Updates standard information */
1050 vfd
->current_norm
= norm
;
1053 case VIDIOC_QUERYSTD
:
1055 v4l2_std_id
*p
= arg
;
1057 if (!ops
->vidioc_querystd
)
1059 ret
= ops
->vidioc_querystd(file
, fh
, arg
);
1061 dbgarg(cmd
, "detected std=%08Lx\n",
1062 (unsigned long long)*p
);
1065 /* ------ input switching ---------- */
1066 /* FIXME: Inputs can be handled inside videodev2 */
1067 case VIDIOC_ENUMINPUT
:
1069 struct v4l2_input
*p
= arg
;
1072 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1073 * CAP_STD here based on ioctl handler provided by the
1074 * driver. If the driver doesn't support these
1075 * for a specific input, it must override these flags.
1077 if (ops
->vidioc_s_std
)
1078 p
->capabilities
|= V4L2_IN_CAP_STD
;
1079 if (ops
->vidioc_s_dv_preset
)
1080 p
->capabilities
|= V4L2_IN_CAP_PRESETS
;
1081 if (ops
->vidioc_s_dv_timings
)
1082 p
->capabilities
|= V4L2_IN_CAP_CUSTOM_TIMINGS
;
1084 if (!ops
->vidioc_enum_input
)
1087 ret
= ops
->vidioc_enum_input(file
, fh
, p
);
1089 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1091 "tuner=%d, std=%08Lx, status=%d\n",
1092 p
->index
, p
->name
, p
->type
, p
->audioset
,
1094 (unsigned long long)p
->std
,
1098 case VIDIOC_G_INPUT
:
1100 unsigned int *i
= arg
;
1102 if (!ops
->vidioc_g_input
)
1104 ret
= ops
->vidioc_g_input(file
, fh
, i
);
1106 dbgarg(cmd
, "value=%d\n", *i
);
1109 case VIDIOC_S_INPUT
:
1111 unsigned int *i
= arg
;
1113 if (!ops
->vidioc_s_input
)
1115 dbgarg(cmd
, "value=%d\n", *i
);
1116 ret
= ops
->vidioc_s_input(file
, fh
, *i
);
1120 /* ------ output switching ---------- */
1121 case VIDIOC_ENUMOUTPUT
:
1123 struct v4l2_output
*p
= arg
;
1125 if (!ops
->vidioc_enum_output
)
1129 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1130 * CAP_STD here based on ioctl handler provided by the
1131 * driver. If the driver doesn't support these
1132 * for a specific output, it must override these flags.
1134 if (ops
->vidioc_s_std
)
1135 p
->capabilities
|= V4L2_OUT_CAP_STD
;
1136 if (ops
->vidioc_s_dv_preset
)
1137 p
->capabilities
|= V4L2_OUT_CAP_PRESETS
;
1138 if (ops
->vidioc_s_dv_timings
)
1139 p
->capabilities
|= V4L2_OUT_CAP_CUSTOM_TIMINGS
;
1141 ret
= ops
->vidioc_enum_output(file
, fh
, p
);
1143 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1145 "modulator=%d, std=0x%08Lx\n",
1146 p
->index
, p
->name
, p
->type
, p
->audioset
,
1147 p
->modulator
, (unsigned long long)p
->std
);
1150 case VIDIOC_G_OUTPUT
:
1152 unsigned int *i
= arg
;
1154 if (!ops
->vidioc_g_output
)
1156 ret
= ops
->vidioc_g_output(file
, fh
, i
);
1158 dbgarg(cmd
, "value=%d\n", *i
);
1161 case VIDIOC_S_OUTPUT
:
1163 unsigned int *i
= arg
;
1165 if (!ops
->vidioc_s_output
)
1167 dbgarg(cmd
, "value=%d\n", *i
);
1168 ret
= ops
->vidioc_s_output(file
, fh
, *i
);
1172 /* --- controls ---------------------------------------------- */
1173 case VIDIOC_QUERYCTRL
:
1175 struct v4l2_queryctrl
*p
= arg
;
1177 if (vfd
->ctrl_handler
)
1178 ret
= v4l2_queryctrl(vfd
->ctrl_handler
, p
);
1179 else if (ops
->vidioc_queryctrl
)
1180 ret
= ops
->vidioc_queryctrl(file
, fh
, p
);
1184 dbgarg(cmd
, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1185 "step=%d, default=%d, flags=0x%08x\n",
1186 p
->id
, p
->type
, p
->name
,
1187 p
->minimum
, p
->maximum
,
1188 p
->step
, p
->default_value
, p
->flags
);
1190 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1195 struct v4l2_control
*p
= arg
;
1197 if (vfd
->ctrl_handler
)
1198 ret
= v4l2_g_ctrl(vfd
->ctrl_handler
, p
);
1199 else if (ops
->vidioc_g_ctrl
)
1200 ret
= ops
->vidioc_g_ctrl(file
, fh
, p
);
1201 else if (ops
->vidioc_g_ext_ctrls
) {
1202 struct v4l2_ext_controls ctrls
;
1203 struct v4l2_ext_control ctrl
;
1205 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1207 ctrls
.controls
= &ctrl
;
1209 ctrl
.value
= p
->value
;
1210 if (check_ext_ctrls(&ctrls
, 1)) {
1211 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, &ctrls
);
1213 p
->value
= ctrl
.value
;
1218 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1220 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1225 struct v4l2_control
*p
= arg
;
1226 struct v4l2_ext_controls ctrls
;
1227 struct v4l2_ext_control ctrl
;
1229 if (!vfd
->ctrl_handler
&&
1230 !ops
->vidioc_s_ctrl
&& !ops
->vidioc_s_ext_ctrls
)
1233 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1235 if (vfd
->ctrl_handler
) {
1236 ret
= v4l2_s_ctrl(vfd
->ctrl_handler
, p
);
1239 if (ops
->vidioc_s_ctrl
) {
1240 ret
= ops
->vidioc_s_ctrl(file
, fh
, p
);
1243 if (!ops
->vidioc_s_ext_ctrls
)
1246 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1248 ctrls
.controls
= &ctrl
;
1250 ctrl
.value
= p
->value
;
1251 if (check_ext_ctrls(&ctrls
, 1))
1252 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, &ctrls
);
1255 case VIDIOC_G_EXT_CTRLS
:
1257 struct v4l2_ext_controls
*p
= arg
;
1259 p
->error_idx
= p
->count
;
1260 if (vfd
->ctrl_handler
)
1261 ret
= v4l2_g_ext_ctrls(vfd
->ctrl_handler
, p
);
1262 else if (ops
->vidioc_g_ext_ctrls
&& check_ext_ctrls(p
, 0))
1263 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, p
);
1266 v4l_print_ext_ctrls(cmd
, vfd
, p
, !ret
);
1269 case VIDIOC_S_EXT_CTRLS
:
1271 struct v4l2_ext_controls
*p
= arg
;
1273 p
->error_idx
= p
->count
;
1274 if (!vfd
->ctrl_handler
&& !ops
->vidioc_s_ext_ctrls
)
1276 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1277 if (vfd
->ctrl_handler
)
1278 ret
= v4l2_s_ext_ctrls(vfd
->ctrl_handler
, p
);
1279 else if (check_ext_ctrls(p
, 0))
1280 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, p
);
1283 case VIDIOC_TRY_EXT_CTRLS
:
1285 struct v4l2_ext_controls
*p
= arg
;
1287 p
->error_idx
= p
->count
;
1288 if (!vfd
->ctrl_handler
&& !ops
->vidioc_try_ext_ctrls
)
1290 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1291 if (vfd
->ctrl_handler
)
1292 ret
= v4l2_try_ext_ctrls(vfd
->ctrl_handler
, p
);
1293 else if (check_ext_ctrls(p
, 0))
1294 ret
= ops
->vidioc_try_ext_ctrls(file
, fh
, p
);
1297 case VIDIOC_QUERYMENU
:
1299 struct v4l2_querymenu
*p
= arg
;
1301 if (vfd
->ctrl_handler
)
1302 ret
= v4l2_querymenu(vfd
->ctrl_handler
, p
);
1303 else if (ops
->vidioc_querymenu
)
1304 ret
= ops
->vidioc_querymenu(file
, fh
, p
);
1308 dbgarg(cmd
, "id=0x%x, index=%d, name=%s\n",
1309 p
->id
, p
->index
, p
->name
);
1311 dbgarg(cmd
, "id=0x%x, index=%d\n",
1315 /* --- audio ---------------------------------------------- */
1316 case VIDIOC_ENUMAUDIO
:
1318 struct v4l2_audio
*p
= arg
;
1320 if (!ops
->vidioc_enumaudio
)
1322 ret
= ops
->vidioc_enumaudio(file
, fh
, p
);
1324 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1325 "mode=0x%x\n", p
->index
, p
->name
,
1326 p
->capability
, p
->mode
);
1328 dbgarg(cmd
, "index=%d\n", p
->index
);
1331 case VIDIOC_G_AUDIO
:
1333 struct v4l2_audio
*p
= arg
;
1335 if (!ops
->vidioc_g_audio
)
1338 ret
= ops
->vidioc_g_audio(file
, fh
, p
);
1340 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1341 "mode=0x%x\n", p
->index
,
1342 p
->name
, p
->capability
, p
->mode
);
1344 dbgarg(cmd
, "index=%d\n", p
->index
);
1347 case VIDIOC_S_AUDIO
:
1349 struct v4l2_audio
*p
= arg
;
1351 if (!ops
->vidioc_s_audio
)
1353 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1354 "mode=0x%x\n", p
->index
, p
->name
,
1355 p
->capability
, p
->mode
);
1356 ret
= ops
->vidioc_s_audio(file
, fh
, p
);
1359 case VIDIOC_ENUMAUDOUT
:
1361 struct v4l2_audioout
*p
= arg
;
1363 if (!ops
->vidioc_enumaudout
)
1365 dbgarg(cmd
, "Enum for index=%d\n", p
->index
);
1366 ret
= ops
->vidioc_enumaudout(file
, fh
, p
);
1368 dbgarg2("index=%d, name=%s, capability=%d, "
1369 "mode=%d\n", p
->index
, p
->name
,
1370 p
->capability
, p
->mode
);
1373 case VIDIOC_G_AUDOUT
:
1375 struct v4l2_audioout
*p
= arg
;
1377 if (!ops
->vidioc_g_audout
)
1380 ret
= ops
->vidioc_g_audout(file
, fh
, p
);
1382 dbgarg2("index=%d, name=%s, capability=%d, "
1383 "mode=%d\n", p
->index
, p
->name
,
1384 p
->capability
, p
->mode
);
1387 case VIDIOC_S_AUDOUT
:
1389 struct v4l2_audioout
*p
= arg
;
1391 if (!ops
->vidioc_s_audout
)
1393 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1394 "mode=%d\n", p
->index
, p
->name
,
1395 p
->capability
, p
->mode
);
1397 ret
= ops
->vidioc_s_audout(file
, fh
, p
);
1400 case VIDIOC_G_MODULATOR
:
1402 struct v4l2_modulator
*p
= arg
;
1404 if (!ops
->vidioc_g_modulator
)
1406 ret
= ops
->vidioc_g_modulator(file
, fh
, p
);
1408 dbgarg(cmd
, "index=%d, name=%s, "
1409 "capability=%d, rangelow=%d,"
1410 " rangehigh=%d, txsubchans=%d\n",
1411 p
->index
, p
->name
, p
->capability
,
1412 p
->rangelow
, p
->rangehigh
,
1416 case VIDIOC_S_MODULATOR
:
1418 struct v4l2_modulator
*p
= arg
;
1420 if (!ops
->vidioc_s_modulator
)
1422 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1423 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1424 p
->index
, p
->name
, p
->capability
, p
->rangelow
,
1425 p
->rangehigh
, p
->txsubchans
);
1426 ret
= ops
->vidioc_s_modulator(file
, fh
, p
);
1431 struct v4l2_crop
*p
= arg
;
1433 if (!ops
->vidioc_g_crop
)
1436 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1437 ret
= ops
->vidioc_g_crop(file
, fh
, p
);
1439 dbgrect(vfd
, "", &p
->c
);
1444 struct v4l2_crop
*p
= arg
;
1446 if (!ops
->vidioc_s_crop
)
1448 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1449 dbgrect(vfd
, "", &p
->c
);
1450 ret
= ops
->vidioc_s_crop(file
, fh
, p
);
1453 case VIDIOC_CROPCAP
:
1455 struct v4l2_cropcap
*p
= arg
;
1457 /*FIXME: Should also show v4l2_fract pixelaspect */
1458 if (!ops
->vidioc_cropcap
)
1461 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1462 ret
= ops
->vidioc_cropcap(file
, fh
, p
);
1464 dbgrect(vfd
, "bounds ", &p
->bounds
);
1465 dbgrect(vfd
, "defrect ", &p
->defrect
);
1469 case VIDIOC_G_JPEGCOMP
:
1471 struct v4l2_jpegcompression
*p
= arg
;
1473 if (!ops
->vidioc_g_jpegcomp
)
1476 ret
= ops
->vidioc_g_jpegcomp(file
, fh
, p
);
1478 dbgarg(cmd
, "quality=%d, APPn=%d, "
1479 "APP_len=%d, COM_len=%d, "
1480 "jpeg_markers=%d\n",
1481 p
->quality
, p
->APPn
, p
->APP_len
,
1482 p
->COM_len
, p
->jpeg_markers
);
1485 case VIDIOC_S_JPEGCOMP
:
1487 struct v4l2_jpegcompression
*p
= arg
;
1489 if (!ops
->vidioc_g_jpegcomp
)
1491 dbgarg(cmd
, "quality=%d, APPn=%d, APP_len=%d, "
1492 "COM_len=%d, jpeg_markers=%d\n",
1493 p
->quality
, p
->APPn
, p
->APP_len
,
1494 p
->COM_len
, p
->jpeg_markers
);
1495 ret
= ops
->vidioc_s_jpegcomp(file
, fh
, p
);
1498 case VIDIOC_G_ENC_INDEX
:
1500 struct v4l2_enc_idx
*p
= arg
;
1502 if (!ops
->vidioc_g_enc_index
)
1504 ret
= ops
->vidioc_g_enc_index(file
, fh
, p
);
1506 dbgarg(cmd
, "entries=%d, entries_cap=%d\n",
1507 p
->entries
, p
->entries_cap
);
1510 case VIDIOC_ENCODER_CMD
:
1512 struct v4l2_encoder_cmd
*p
= arg
;
1514 if (!ops
->vidioc_encoder_cmd
)
1516 ret
= ops
->vidioc_encoder_cmd(file
, fh
, p
);
1518 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1521 case VIDIOC_TRY_ENCODER_CMD
:
1523 struct v4l2_encoder_cmd
*p
= arg
;
1525 if (!ops
->vidioc_try_encoder_cmd
)
1527 ret
= ops
->vidioc_try_encoder_cmd(file
, fh
, p
);
1529 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1534 struct v4l2_streamparm
*p
= arg
;
1536 if (ops
->vidioc_g_parm
) {
1537 ret
= check_fmt(ops
, p
->type
);
1540 ret
= ops
->vidioc_g_parm(file
, fh
, p
);
1542 v4l2_std_id std
= vfd
->current_norm
;
1544 if (p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1548 if (ops
->vidioc_g_std
)
1549 ret
= ops
->vidioc_g_std(file
, fh
, &std
);
1553 v4l2_video_std_frame_period(std
,
1554 &p
->parm
.capture
.timeperframe
);
1557 dbgarg(cmd
, "type=%d\n", p
->type
);
1562 struct v4l2_streamparm
*p
= arg
;
1564 if (!ops
->vidioc_s_parm
)
1566 ret
= check_fmt(ops
, p
->type
);
1570 dbgarg(cmd
, "type=%d\n", p
->type
);
1571 ret
= ops
->vidioc_s_parm(file
, fh
, p
);
1574 case VIDIOC_G_TUNER
:
1576 struct v4l2_tuner
*p
= arg
;
1578 if (!ops
->vidioc_g_tuner
)
1581 ret
= ops
->vidioc_g_tuner(file
, fh
, p
);
1583 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1584 "capability=0x%x, rangelow=%d, "
1585 "rangehigh=%d, signal=%d, afc=%d, "
1586 "rxsubchans=0x%x, audmode=%d\n",
1587 p
->index
, p
->name
, p
->type
,
1588 p
->capability
, p
->rangelow
,
1589 p
->rangehigh
, p
->signal
, p
->afc
,
1590 p
->rxsubchans
, p
->audmode
);
1593 case VIDIOC_S_TUNER
:
1595 struct v4l2_tuner
*p
= arg
;
1597 if (!ops
->vidioc_s_tuner
)
1599 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1600 "capability=0x%x, rangelow=%d, "
1601 "rangehigh=%d, signal=%d, afc=%d, "
1602 "rxsubchans=0x%x, audmode=%d\n",
1603 p
->index
, p
->name
, p
->type
,
1604 p
->capability
, p
->rangelow
,
1605 p
->rangehigh
, p
->signal
, p
->afc
,
1606 p
->rxsubchans
, p
->audmode
);
1607 ret
= ops
->vidioc_s_tuner(file
, fh
, p
);
1610 case VIDIOC_G_FREQUENCY
:
1612 struct v4l2_frequency
*p
= arg
;
1614 if (!ops
->vidioc_g_frequency
)
1617 ret
= ops
->vidioc_g_frequency(file
, fh
, p
);
1619 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1620 p
->tuner
, p
->type
, p
->frequency
);
1623 case VIDIOC_S_FREQUENCY
:
1625 struct v4l2_frequency
*p
= arg
;
1627 if (!ops
->vidioc_s_frequency
)
1629 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1630 p
->tuner
, p
->type
, p
->frequency
);
1631 ret
= ops
->vidioc_s_frequency(file
, fh
, p
);
1634 case VIDIOC_G_SLICED_VBI_CAP
:
1636 struct v4l2_sliced_vbi_cap
*p
= arg
;
1638 if (!ops
->vidioc_g_sliced_vbi_cap
)
1641 /* Clear up to type, everything after type is zerod already */
1642 memset(p
, 0, offsetof(struct v4l2_sliced_vbi_cap
, type
));
1644 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1645 ret
= ops
->vidioc_g_sliced_vbi_cap(file
, fh
, p
);
1647 dbgarg2("service_set=%d\n", p
->service_set
);
1650 case VIDIOC_LOG_STATUS
:
1652 if (!ops
->vidioc_log_status
)
1654 ret
= ops
->vidioc_log_status(file
, fh
);
1657 #ifdef CONFIG_VIDEO_ADV_DEBUG
1658 case VIDIOC_DBG_G_REGISTER
:
1660 struct v4l2_dbg_register
*p
= arg
;
1662 if (ops
->vidioc_g_register
) {
1663 if (!capable(CAP_SYS_ADMIN
))
1666 ret
= ops
->vidioc_g_register(file
, fh
, p
);
1670 case VIDIOC_DBG_S_REGISTER
:
1672 struct v4l2_dbg_register
*p
= arg
;
1674 if (ops
->vidioc_s_register
) {
1675 if (!capable(CAP_SYS_ADMIN
))
1678 ret
= ops
->vidioc_s_register(file
, fh
, p
);
1683 case VIDIOC_DBG_G_CHIP_IDENT
:
1685 struct v4l2_dbg_chip_ident
*p
= arg
;
1687 if (!ops
->vidioc_g_chip_ident
)
1689 p
->ident
= V4L2_IDENT_NONE
;
1691 ret
= ops
->vidioc_g_chip_ident(file
, fh
, p
);
1693 dbgarg(cmd
, "chip_ident=%u, revision=0x%x\n", p
->ident
, p
->revision
);
1696 case VIDIOC_S_HW_FREQ_SEEK
:
1698 struct v4l2_hw_freq_seek
*p
= arg
;
1700 if (!ops
->vidioc_s_hw_freq_seek
)
1703 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1704 p
->tuner
, p
->type
, p
->seek_upward
, p
->wrap_around
);
1705 ret
= ops
->vidioc_s_hw_freq_seek(file
, fh
, p
);
1708 case VIDIOC_ENUM_FRAMESIZES
:
1710 struct v4l2_frmsizeenum
*p
= arg
;
1712 if (!ops
->vidioc_enum_framesizes
)
1715 ret
= ops
->vidioc_enum_framesizes(file
, fh
, p
);
1717 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1719 (p
->pixel_format
& 0xff),
1720 (p
->pixel_format
>> 8) & 0xff,
1721 (p
->pixel_format
>> 16) & 0xff,
1722 (p
->pixel_format
>> 24) & 0xff,
1725 case V4L2_FRMSIZE_TYPE_DISCRETE
:
1726 dbgarg3("width = %d, height=%d\n",
1727 p
->discrete
.width
, p
->discrete
.height
);
1729 case V4L2_FRMSIZE_TYPE_STEPWISE
:
1730 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1731 p
->stepwise
.min_width
, p
->stepwise
.min_height
,
1732 p
->stepwise
.step_width
, p
->stepwise
.step_height
,
1733 p
->stepwise
.max_width
, p
->stepwise
.max_height
);
1735 case V4L2_FRMSIZE_TYPE_CONTINUOUS
:
1736 dbgarg3("continuous\n");
1739 dbgarg3("- Unknown type!\n");
1744 case VIDIOC_ENUM_FRAMEINTERVALS
:
1746 struct v4l2_frmivalenum
*p
= arg
;
1748 if (!ops
->vidioc_enum_frameintervals
)
1751 ret
= ops
->vidioc_enum_frameintervals(file
, fh
, p
);
1753 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1754 p
->index
, p
->pixel_format
,
1755 p
->width
, p
->height
, p
->type
);
1757 case V4L2_FRMIVAL_TYPE_DISCRETE
:
1758 dbgarg2("fps=%d/%d\n",
1759 p
->discrete
.numerator
,
1760 p
->discrete
.denominator
);
1762 case V4L2_FRMIVAL_TYPE_STEPWISE
:
1763 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1764 p
->stepwise
.min
.numerator
,
1765 p
->stepwise
.min
.denominator
,
1766 p
->stepwise
.max
.numerator
,
1767 p
->stepwise
.max
.denominator
,
1768 p
->stepwise
.step
.numerator
,
1769 p
->stepwise
.step
.denominator
);
1771 case V4L2_FRMIVAL_TYPE_CONTINUOUS
:
1772 dbgarg2("continuous\n");
1775 dbgarg2("- Unknown type!\n");
1779 case VIDIOC_ENUM_DV_PRESETS
:
1781 struct v4l2_dv_enum_preset
*p
= arg
;
1783 if (!ops
->vidioc_enum_dv_presets
)
1786 ret
= ops
->vidioc_enum_dv_presets(file
, fh
, p
);
1789 "index=%d, preset=%d, name=%s, width=%d,"
1791 p
->index
, p
->preset
, p
->name
, p
->width
,
1795 case VIDIOC_S_DV_PRESET
:
1797 struct v4l2_dv_preset
*p
= arg
;
1799 if (!ops
->vidioc_s_dv_preset
)
1802 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1803 ret
= ops
->vidioc_s_dv_preset(file
, fh
, p
);
1806 case VIDIOC_G_DV_PRESET
:
1808 struct v4l2_dv_preset
*p
= arg
;
1810 if (!ops
->vidioc_g_dv_preset
)
1813 ret
= ops
->vidioc_g_dv_preset(file
, fh
, p
);
1815 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1818 case VIDIOC_QUERY_DV_PRESET
:
1820 struct v4l2_dv_preset
*p
= arg
;
1822 if (!ops
->vidioc_query_dv_preset
)
1825 ret
= ops
->vidioc_query_dv_preset(file
, fh
, p
);
1827 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1830 case VIDIOC_S_DV_TIMINGS
:
1832 struct v4l2_dv_timings
*p
= arg
;
1834 if (!ops
->vidioc_s_dv_timings
)
1838 case V4L2_DV_BT_656_1120
:
1839 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
1840 " width=%d, height=%d, polarities=%x,"
1841 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
1842 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
1843 " il_vfrontporch=%d, il_vsync=%d,"
1844 " il_vbackporch=%d\n",
1845 p
->bt
.interlaced
, p
->bt
.pixelclock
,
1846 p
->bt
.width
, p
->bt
.height
, p
->bt
.polarities
,
1847 p
->bt
.hfrontporch
, p
->bt
.hsync
,
1848 p
->bt
.hbackporch
, p
->bt
.vfrontporch
,
1849 p
->bt
.vsync
, p
->bt
.vbackporch
,
1850 p
->bt
.il_vfrontporch
, p
->bt
.il_vsync
,
1851 p
->bt
.il_vbackporch
);
1852 ret
= ops
->vidioc_s_dv_timings(file
, fh
, p
);
1855 dbgarg2("Unknown type %d!\n", p
->type
);
1860 case VIDIOC_G_DV_TIMINGS
:
1862 struct v4l2_dv_timings
*p
= arg
;
1864 if (!ops
->vidioc_g_dv_timings
)
1867 ret
= ops
->vidioc_g_dv_timings(file
, fh
, p
);
1870 case V4L2_DV_BT_656_1120
:
1871 dbgarg2("bt-656/1120:interlaced=%d,"
1873 " width=%d, height=%d, polarities=%x,"
1874 " hfrontporch=%d, hsync=%d,"
1875 " hbackporch=%d, vfrontporch=%d,"
1876 " vsync=%d, vbackporch=%d,"
1877 " il_vfrontporch=%d, il_vsync=%d,"
1878 " il_vbackporch=%d\n",
1879 p
->bt
.interlaced
, p
->bt
.pixelclock
,
1880 p
->bt
.width
, p
->bt
.height
,
1881 p
->bt
.polarities
, p
->bt
.hfrontporch
,
1882 p
->bt
.hsync
, p
->bt
.hbackporch
,
1883 p
->bt
.vfrontporch
, p
->bt
.vsync
,
1884 p
->bt
.vbackporch
, p
->bt
.il_vfrontporch
,
1885 p
->bt
.il_vsync
, p
->bt
.il_vbackporch
);
1888 dbgarg2("Unknown type %d!\n", p
->type
);
1894 case VIDIOC_DQEVENT
:
1896 struct v4l2_event
*ev
= arg
;
1898 if (!ops
->vidioc_subscribe_event
)
1901 ret
= v4l2_event_dequeue(fh
, ev
, file
->f_flags
& O_NONBLOCK
);
1903 dbgarg(cmd
, "no pending events?");
1907 "pending=%d, type=0x%8.8x, sequence=%d, "
1908 "timestamp=%lu.%9.9lu ",
1909 ev
->pending
, ev
->type
, ev
->sequence
,
1910 ev
->timestamp
.tv_sec
, ev
->timestamp
.tv_nsec
);
1913 case VIDIOC_SUBSCRIBE_EVENT
:
1915 struct v4l2_event_subscription
*sub
= arg
;
1917 if (!ops
->vidioc_subscribe_event
)
1920 ret
= ops
->vidioc_subscribe_event(fh
, sub
);
1922 dbgarg(cmd
, "failed, ret=%ld", ret
);
1925 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
1928 case VIDIOC_UNSUBSCRIBE_EVENT
:
1930 struct v4l2_event_subscription
*sub
= arg
;
1932 if (!ops
->vidioc_unsubscribe_event
)
1935 ret
= ops
->vidioc_unsubscribe_event(fh
, sub
);
1937 dbgarg(cmd
, "failed, ret=%ld", ret
);
1940 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
1945 if (!ops
->vidioc_default
)
1947 ret
= ops
->vidioc_default(file
, fh
, cmd
, arg
);
1952 if (vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
) {
1954 v4l_print_ioctl(vfd
->name
, cmd
);
1955 printk(KERN_CONT
" error %ld\n", ret
);
1962 /* In some cases, only a few fields are used as input, i.e. when the app sets
1963 * "index" and then the driver fills in the rest of the structure for the thing
1964 * with that index. We only need to copy up the first non-input field. */
1965 static unsigned long cmd_input_size(unsigned int cmd
)
1967 /* Size of structure up to and including 'field' */
1968 #define CMDINSIZE(cmd, type, field) \
1969 case VIDIOC_##cmd: \
1970 return offsetof(struct v4l2_##type, field) + \
1971 sizeof(((struct v4l2_##type *)0)->field);
1974 CMDINSIZE(ENUM_FMT
, fmtdesc
, type
);
1975 CMDINSIZE(G_FMT
, format
, type
);
1976 CMDINSIZE(QUERYBUF
, buffer
, type
);
1977 CMDINSIZE(G_PARM
, streamparm
, type
);
1978 CMDINSIZE(ENUMSTD
, standard
, index
);
1979 CMDINSIZE(ENUMINPUT
, input
, index
);
1980 CMDINSIZE(G_CTRL
, control
, id
);
1981 CMDINSIZE(G_TUNER
, tuner
, index
);
1982 CMDINSIZE(QUERYCTRL
, queryctrl
, id
);
1983 CMDINSIZE(QUERYMENU
, querymenu
, index
);
1984 CMDINSIZE(ENUMOUTPUT
, output
, index
);
1985 CMDINSIZE(G_MODULATOR
, modulator
, index
);
1986 CMDINSIZE(G_FREQUENCY
, frequency
, tuner
);
1987 CMDINSIZE(CROPCAP
, cropcap
, type
);
1988 CMDINSIZE(G_CROP
, crop
, type
);
1989 CMDINSIZE(ENUMAUDIO
, audio
, index
);
1990 CMDINSIZE(ENUMAUDOUT
, audioout
, index
);
1991 CMDINSIZE(ENCODER_CMD
, encoder_cmd
, flags
);
1992 CMDINSIZE(TRY_ENCODER_CMD
, encoder_cmd
, flags
);
1993 CMDINSIZE(G_SLICED_VBI_CAP
, sliced_vbi_cap
, type
);
1994 CMDINSIZE(ENUM_FRAMESIZES
, frmsizeenum
, pixel_format
);
1995 CMDINSIZE(ENUM_FRAMEINTERVALS
, frmivalenum
, height
);
1997 return _IOC_SIZE(cmd
);
2001 long video_ioctl2(struct file
*file
,
2002 unsigned int cmd
, unsigned long arg
)
2006 void *parg
= (void *)arg
;
2009 size_t ctrls_size
= 0;
2010 void __user
*user_ptr
= NULL
;
2012 #ifdef __OLD_VIDIOC_
2013 cmd
= video_fix_command(cmd
);
2015 is_ext_ctrl
= (cmd
== VIDIOC_S_EXT_CTRLS
|| cmd
== VIDIOC_G_EXT_CTRLS
||
2016 cmd
== VIDIOC_TRY_EXT_CTRLS
);
2018 /* Copy arguments into temp kernel buffer */
2019 if (_IOC_DIR(cmd
) != _IOC_NONE
) {
2020 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
2023 /* too big to allocate from stack */
2024 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
2031 if (_IOC_DIR(cmd
) & _IOC_WRITE
) {
2032 unsigned long n
= cmd_input_size(cmd
);
2034 if (copy_from_user(parg
, (void __user
*)arg
, n
))
2037 /* zero out anything we don't copy from userspace */
2038 if (n
< _IOC_SIZE(cmd
))
2039 memset((u8
*)parg
+ n
, 0, _IOC_SIZE(cmd
) - n
);
2041 /* read-only ioctl */
2042 memset(parg
, 0, _IOC_SIZE(cmd
));
2047 struct v4l2_ext_controls
*p
= parg
;
2049 /* In case of an error, tell the caller that it wasn't
2050 a specific control that caused it. */
2051 p
->error_idx
= p
->count
;
2052 user_ptr
= (void __user
*)p
->controls
;
2054 ctrls_size
= sizeof(struct v4l2_ext_control
) * p
->count
;
2055 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
2056 mbuf
= kmalloc(ctrls_size
, GFP_KERNEL
);
2061 if (copy_from_user(mbuf
, user_ptr
, ctrls_size
))
2068 err
= __video_do_ioctl(file
, cmd
, parg
);
2069 if (err
== -ENOIOCTLCMD
)
2072 struct v4l2_ext_controls
*p
= parg
;
2074 p
->controls
= (void *)user_ptr
;
2075 if (p
->count
&& err
== 0 && copy_to_user(user_ptr
, mbuf
, ctrls_size
))
2083 /* Copy results into user buffer */
2084 switch (_IOC_DIR(cmd
)) {
2086 case (_IOC_WRITE
| _IOC_READ
):
2087 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
2096 EXPORT_SYMBOL(video_ioctl2
);