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>
19 #include <linux/version.h>
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-device.h>
29 #include <media/v4l2-chip-ident.h>
31 #define dbgarg(cmd, fmt, arg...) \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
40 #define dbgarg2(fmt, arg...) \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
46 #define dbgarg3(fmt, arg...) \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
52 /* Zero out the end of the struct pointed to by p. Everything after, but
53 * not including, the specified field is cleared. */
54 #define CLEAR_AFTER_FIELD(p, field) \
55 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
63 static const struct std_descr standards
[] = {
64 { V4L2_STD_NTSC
, "NTSC" },
65 { V4L2_STD_NTSC_M
, "NTSC-M" },
66 { V4L2_STD_NTSC_M_JP
, "NTSC-M-JP" },
67 { V4L2_STD_NTSC_M_KR
, "NTSC-M-KR" },
68 { V4L2_STD_NTSC_443
, "NTSC-443" },
69 { V4L2_STD_PAL
, "PAL" },
70 { V4L2_STD_PAL_BG
, "PAL-BG" },
71 { V4L2_STD_PAL_B
, "PAL-B" },
72 { V4L2_STD_PAL_B1
, "PAL-B1" },
73 { V4L2_STD_PAL_G
, "PAL-G" },
74 { V4L2_STD_PAL_H
, "PAL-H" },
75 { V4L2_STD_PAL_I
, "PAL-I" },
76 { V4L2_STD_PAL_DK
, "PAL-DK" },
77 { V4L2_STD_PAL_D
, "PAL-D" },
78 { V4L2_STD_PAL_D1
, "PAL-D1" },
79 { V4L2_STD_PAL_K
, "PAL-K" },
80 { V4L2_STD_PAL_M
, "PAL-M" },
81 { V4L2_STD_PAL_N
, "PAL-N" },
82 { V4L2_STD_PAL_Nc
, "PAL-Nc" },
83 { V4L2_STD_PAL_60
, "PAL-60" },
84 { V4L2_STD_SECAM
, "SECAM" },
85 { V4L2_STD_SECAM_B
, "SECAM-B" },
86 { V4L2_STD_SECAM_G
, "SECAM-G" },
87 { V4L2_STD_SECAM_H
, "SECAM-H" },
88 { V4L2_STD_SECAM_DK
, "SECAM-DK" },
89 { V4L2_STD_SECAM_D
, "SECAM-D" },
90 { V4L2_STD_SECAM_K
, "SECAM-K" },
91 { V4L2_STD_SECAM_K1
, "SECAM-K1" },
92 { V4L2_STD_SECAM_L
, "SECAM-L" },
93 { V4L2_STD_SECAM_LC
, "SECAM-Lc" },
97 /* video4linux standard ID conversion to standard name
99 const char *v4l2_norm_to_name(v4l2_std_id id
)
104 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
105 64 bit comparations. So, on that architecture, with some gcc
106 variants, compilation fails. Currently, the max value is 30bit wide.
110 for (i
= 0; standards
[i
].std
; i
++)
111 if (myid
== standards
[i
].std
)
113 return standards
[i
].descr
;
115 EXPORT_SYMBOL(v4l2_norm_to_name
);
117 /* Returns frame period for the given standard */
118 void v4l2_video_std_frame_period(int id
, struct v4l2_fract
*frameperiod
)
120 if (id
& V4L2_STD_525_60
) {
121 frameperiod
->numerator
= 1001;
122 frameperiod
->denominator
= 30000;
124 frameperiod
->numerator
= 1;
125 frameperiod
->denominator
= 25;
128 EXPORT_SYMBOL(v4l2_video_std_frame_period
);
130 /* Fill in the fields of a v4l2_standard structure according to the
131 'id' and 'transmission' parameters. Returns negative on error. */
132 int v4l2_video_std_construct(struct v4l2_standard
*vs
,
133 int id
, const char *name
)
136 v4l2_video_std_frame_period(id
, &vs
->frameperiod
);
137 vs
->framelines
= (id
& V4L2_STD_525_60
) ? 525 : 625;
138 strlcpy(vs
->name
, name
, sizeof(vs
->name
));
141 EXPORT_SYMBOL(v4l2_video_std_construct
);
143 /* ----------------------------------------------------------------- */
144 /* some arrays for pretty-printing debug messages of enum types */
146 const char *v4l2_field_names
[] = {
147 [V4L2_FIELD_ANY
] = "any",
148 [V4L2_FIELD_NONE
] = "none",
149 [V4L2_FIELD_TOP
] = "top",
150 [V4L2_FIELD_BOTTOM
] = "bottom",
151 [V4L2_FIELD_INTERLACED
] = "interlaced",
152 [V4L2_FIELD_SEQ_TB
] = "seq-tb",
153 [V4L2_FIELD_SEQ_BT
] = "seq-bt",
154 [V4L2_FIELD_ALTERNATE
] = "alternate",
155 [V4L2_FIELD_INTERLACED_TB
] = "interlaced-tb",
156 [V4L2_FIELD_INTERLACED_BT
] = "interlaced-bt",
158 EXPORT_SYMBOL(v4l2_field_names
);
160 const char *v4l2_type_names
[] = {
161 [V4L2_BUF_TYPE_VIDEO_CAPTURE
] = "vid-cap",
162 [V4L2_BUF_TYPE_VIDEO_OVERLAY
] = "vid-overlay",
163 [V4L2_BUF_TYPE_VIDEO_OUTPUT
] = "vid-out",
164 [V4L2_BUF_TYPE_VBI_CAPTURE
] = "vbi-cap",
165 [V4L2_BUF_TYPE_VBI_OUTPUT
] = "vbi-out",
166 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
] = "sliced-vbi-cap",
167 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
] = "sliced-vbi-out",
168 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
] = "vid-out-overlay",
169 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
] = "vid-cap-mplane",
170 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
] = "vid-out-mplane",
172 EXPORT_SYMBOL(v4l2_type_names
);
174 static const char *v4l2_memory_names
[] = {
175 [V4L2_MEMORY_MMAP
] = "mmap",
176 [V4L2_MEMORY_USERPTR
] = "userptr",
177 [V4L2_MEMORY_OVERLAY
] = "overlay",
180 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
183 /* ------------------------------------------------------------------ */
184 /* debug help functions */
186 struct v4l2_ioctl_info
{
189 const char * const name
;
192 /* This control needs a priority check */
193 #define INFO_FL_PRIO (1 << 0)
194 /* This control can be valid if the filehandle passes a control handler. */
195 #define INFO_FL_CTRL (1 << 1)
197 #define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = { \
203 static struct v4l2_ioctl_info v4l2_ioctls
[] = {
204 IOCTL_INFO(VIDIOC_QUERYCAP
, 0),
205 IOCTL_INFO(VIDIOC_ENUM_FMT
, 0),
206 IOCTL_INFO(VIDIOC_G_FMT
, 0),
207 IOCTL_INFO(VIDIOC_S_FMT
, INFO_FL_PRIO
),
208 IOCTL_INFO(VIDIOC_REQBUFS
, INFO_FL_PRIO
),
209 IOCTL_INFO(VIDIOC_QUERYBUF
, 0),
210 IOCTL_INFO(VIDIOC_G_FBUF
, 0),
211 IOCTL_INFO(VIDIOC_S_FBUF
, INFO_FL_PRIO
),
212 IOCTL_INFO(VIDIOC_OVERLAY
, INFO_FL_PRIO
),
213 IOCTL_INFO(VIDIOC_QBUF
, 0),
214 IOCTL_INFO(VIDIOC_DQBUF
, 0),
215 IOCTL_INFO(VIDIOC_STREAMON
, INFO_FL_PRIO
),
216 IOCTL_INFO(VIDIOC_STREAMOFF
, INFO_FL_PRIO
),
217 IOCTL_INFO(VIDIOC_G_PARM
, 0),
218 IOCTL_INFO(VIDIOC_S_PARM
, INFO_FL_PRIO
),
219 IOCTL_INFO(VIDIOC_G_STD
, 0),
220 IOCTL_INFO(VIDIOC_S_STD
, INFO_FL_PRIO
),
221 IOCTL_INFO(VIDIOC_ENUMSTD
, 0),
222 IOCTL_INFO(VIDIOC_ENUMINPUT
, 0),
223 IOCTL_INFO(VIDIOC_G_CTRL
, INFO_FL_CTRL
),
224 IOCTL_INFO(VIDIOC_S_CTRL
, INFO_FL_PRIO
| INFO_FL_CTRL
),
225 IOCTL_INFO(VIDIOC_G_TUNER
, 0),
226 IOCTL_INFO(VIDIOC_S_TUNER
, INFO_FL_PRIO
),
227 IOCTL_INFO(VIDIOC_G_AUDIO
, 0),
228 IOCTL_INFO(VIDIOC_S_AUDIO
, INFO_FL_PRIO
),
229 IOCTL_INFO(VIDIOC_QUERYCTRL
, INFO_FL_CTRL
),
230 IOCTL_INFO(VIDIOC_QUERYMENU
, INFO_FL_CTRL
),
231 IOCTL_INFO(VIDIOC_G_INPUT
, 0),
232 IOCTL_INFO(VIDIOC_S_INPUT
, INFO_FL_PRIO
),
233 IOCTL_INFO(VIDIOC_G_OUTPUT
, 0),
234 IOCTL_INFO(VIDIOC_S_OUTPUT
, INFO_FL_PRIO
),
235 IOCTL_INFO(VIDIOC_ENUMOUTPUT
, 0),
236 IOCTL_INFO(VIDIOC_G_AUDOUT
, 0),
237 IOCTL_INFO(VIDIOC_S_AUDOUT
, INFO_FL_PRIO
),
238 IOCTL_INFO(VIDIOC_G_MODULATOR
, 0),
239 IOCTL_INFO(VIDIOC_S_MODULATOR
, INFO_FL_PRIO
),
240 IOCTL_INFO(VIDIOC_G_FREQUENCY
, 0),
241 IOCTL_INFO(VIDIOC_S_FREQUENCY
, INFO_FL_PRIO
),
242 IOCTL_INFO(VIDIOC_CROPCAP
, 0),
243 IOCTL_INFO(VIDIOC_G_CROP
, 0),
244 IOCTL_INFO(VIDIOC_S_CROP
, INFO_FL_PRIO
),
245 IOCTL_INFO(VIDIOC_G_SELECTION
, 0),
246 IOCTL_INFO(VIDIOC_S_SELECTION
, INFO_FL_PRIO
),
247 IOCTL_INFO(VIDIOC_G_JPEGCOMP
, 0),
248 IOCTL_INFO(VIDIOC_S_JPEGCOMP
, INFO_FL_PRIO
),
249 IOCTL_INFO(VIDIOC_QUERYSTD
, 0),
250 IOCTL_INFO(VIDIOC_TRY_FMT
, 0),
251 IOCTL_INFO(VIDIOC_ENUMAUDIO
, 0),
252 IOCTL_INFO(VIDIOC_ENUMAUDOUT
, 0),
253 IOCTL_INFO(VIDIOC_G_PRIORITY
, 0),
254 IOCTL_INFO(VIDIOC_S_PRIORITY
, INFO_FL_PRIO
),
255 IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP
, 0),
256 IOCTL_INFO(VIDIOC_LOG_STATUS
, 0),
257 IOCTL_INFO(VIDIOC_G_EXT_CTRLS
, INFO_FL_CTRL
),
258 IOCTL_INFO(VIDIOC_S_EXT_CTRLS
, INFO_FL_PRIO
| INFO_FL_CTRL
),
259 IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS
, 0),
260 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES
, 0),
261 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS
, 0),
262 IOCTL_INFO(VIDIOC_G_ENC_INDEX
, 0),
263 IOCTL_INFO(VIDIOC_ENCODER_CMD
, INFO_FL_PRIO
),
264 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD
, 0),
265 IOCTL_INFO(VIDIOC_DECODER_CMD
, INFO_FL_PRIO
),
266 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD
, 0),
267 #ifdef CONFIG_VIDEO_ADV_DEBUG
268 IOCTL_INFO(VIDIOC_DBG_S_REGISTER
, 0),
269 IOCTL_INFO(VIDIOC_DBG_G_REGISTER
, 0),
271 IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT
, 0),
272 IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK
, INFO_FL_PRIO
),
273 IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS
, 0),
274 IOCTL_INFO(VIDIOC_S_DV_PRESET
, INFO_FL_PRIO
),
275 IOCTL_INFO(VIDIOC_G_DV_PRESET
, 0),
276 IOCTL_INFO(VIDIOC_QUERY_DV_PRESET
, 0),
277 IOCTL_INFO(VIDIOC_S_DV_TIMINGS
, INFO_FL_PRIO
),
278 IOCTL_INFO(VIDIOC_G_DV_TIMINGS
, 0),
279 IOCTL_INFO(VIDIOC_DQEVENT
, 0),
280 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT
, 0),
281 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT
, 0),
282 IOCTL_INFO(VIDIOC_CREATE_BUFS
, INFO_FL_PRIO
),
283 IOCTL_INFO(VIDIOC_PREPARE_BUF
, 0),
284 IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS
, 0),
285 IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS
, 0),
286 IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP
, 0),
288 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
290 bool v4l2_is_known_ioctl(unsigned int cmd
)
292 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
)
294 return v4l2_ioctls
[_IOC_NR(cmd
)].ioctl
== cmd
;
297 /* Common ioctl debug function. This function can be used by
298 external ioctl messages as well as internal V4L ioctl */
299 void v4l_printk_ioctl(unsigned int cmd
)
303 switch (_IOC_TYPE(cmd
)) {
308 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
) {
312 printk("%s", v4l2_ioctls
[_IOC_NR(cmd
)].name
);
318 switch (_IOC_DIR(cmd
)) {
319 case _IOC_NONE
: dir
= "--"; break;
320 case _IOC_READ
: dir
= "r-"; break;
321 case _IOC_WRITE
: dir
= "-w"; break;
322 case _IOC_READ
| _IOC_WRITE
: dir
= "rw"; break;
323 default: dir
= "*ERR*"; break;
325 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
326 type
, _IOC_TYPE(cmd
), dir
, _IOC_NR(cmd
), cmd
);
328 EXPORT_SYMBOL(v4l_printk_ioctl
);
330 static void dbgbuf(unsigned int cmd
, struct video_device
*vfd
,
331 struct v4l2_buffer
*p
)
333 struct v4l2_timecode
*tc
= &p
->timecode
;
334 struct v4l2_plane
*plane
;
337 dbgarg(cmd
, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
338 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
339 p
->timestamp
.tv_sec
/ 3600,
340 (int)(p
->timestamp
.tv_sec
/ 60) % 60,
341 (int)(p
->timestamp
.tv_sec
% 60),
342 (long)p
->timestamp
.tv_usec
,
344 prt_names(p
->type
, v4l2_type_names
),
345 p
->flags
, p
->field
, p
->sequence
,
346 prt_names(p
->memory
, v4l2_memory_names
));
348 if (V4L2_TYPE_IS_MULTIPLANAR(p
->type
) && p
->m
.planes
) {
349 for (i
= 0; i
< p
->length
; ++i
) {
350 plane
= &p
->m
.planes
[i
];
351 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
352 "offset/userptr=0x%08lx, length=%d\n",
353 i
, plane
->bytesused
, plane
->data_offset
,
354 plane
->m
.userptr
, plane
->length
);
357 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
358 p
->bytesused
, p
->m
.userptr
, p
->length
);
361 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
362 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
363 tc
->hours
, tc
->minutes
, tc
->seconds
,
364 tc
->type
, tc
->flags
, tc
->frames
, *(__u32
*)tc
->userbits
);
367 static inline void dbgrect(struct video_device
*vfd
, char *s
,
370 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s
, r
->left
, r
->top
,
371 r
->width
, r
->height
);
374 static void dbgtimings(struct video_device
*vfd
,
375 const struct v4l2_dv_timings
*p
)
378 case V4L2_DV_BT_656_1120
:
379 dbgarg2("bt-656/1120:interlaced=%d,"
381 " width=%d, height=%d, polarities=%x,"
382 " hfrontporch=%d, hsync=%d,"
383 " hbackporch=%d, vfrontporch=%d,"
384 " vsync=%d, vbackporch=%d,"
385 " il_vfrontporch=%d, il_vsync=%d,"
386 " il_vbackporch=%d, standards=%x, flags=%x\n",
387 p
->bt
.interlaced
, p
->bt
.pixelclock
,
388 p
->bt
.width
, p
->bt
.height
,
389 p
->bt
.polarities
, p
->bt
.hfrontporch
,
390 p
->bt
.hsync
, p
->bt
.hbackporch
,
391 p
->bt
.vfrontporch
, p
->bt
.vsync
,
392 p
->bt
.vbackporch
, p
->bt
.il_vfrontporch
,
393 p
->bt
.il_vsync
, p
->bt
.il_vbackporch
,
394 p
->bt
.standards
, p
->bt
.flags
);
397 dbgarg2("Unknown type %d!\n", p
->type
);
402 static inline void v4l_print_pix_fmt(struct video_device
*vfd
,
403 struct v4l2_pix_format
*fmt
)
405 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
406 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
407 fmt
->width
, fmt
->height
,
408 (fmt
->pixelformat
& 0xff),
409 (fmt
->pixelformat
>> 8) & 0xff,
410 (fmt
->pixelformat
>> 16) & 0xff,
411 (fmt
->pixelformat
>> 24) & 0xff,
412 prt_names(fmt
->field
, v4l2_field_names
),
413 fmt
->bytesperline
, fmt
->sizeimage
, fmt
->colorspace
);
416 static inline void v4l_print_pix_fmt_mplane(struct video_device
*vfd
,
417 struct v4l2_pix_format_mplane
*fmt
)
421 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
422 "colorspace=%d, num_planes=%d\n",
423 fmt
->width
, fmt
->height
,
424 (fmt
->pixelformat
& 0xff),
425 (fmt
->pixelformat
>> 8) & 0xff,
426 (fmt
->pixelformat
>> 16) & 0xff,
427 (fmt
->pixelformat
>> 24) & 0xff,
428 prt_names(fmt
->field
, v4l2_field_names
),
429 fmt
->colorspace
, fmt
->num_planes
);
431 for (i
= 0; i
< fmt
->num_planes
; ++i
)
432 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i
,
433 fmt
->plane_fmt
[i
].bytesperline
,
434 fmt
->plane_fmt
[i
].sizeimage
);
437 static inline void v4l_print_ext_ctrls(unsigned int cmd
,
438 struct video_device
*vfd
, struct v4l2_ext_controls
*c
, int show_vals
)
442 if (!(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
))
445 printk(KERN_CONT
"class=0x%x", c
->ctrl_class
);
446 for (i
= 0; i
< c
->count
; i
++) {
447 if (show_vals
&& !c
->controls
[i
].size
)
448 printk(KERN_CONT
" id/val=0x%x/0x%x",
449 c
->controls
[i
].id
, c
->controls
[i
].value
);
451 printk(KERN_CONT
" id=0x%x,size=%u",
452 c
->controls
[i
].id
, c
->controls
[i
].size
);
454 printk(KERN_CONT
"\n");
457 static inline int check_ext_ctrls(struct v4l2_ext_controls
*c
, int allow_priv
)
461 /* zero the reserved fields */
462 c
->reserved
[0] = c
->reserved
[1] = 0;
463 for (i
= 0; i
< c
->count
; i
++)
464 c
->controls
[i
].reserved2
[0] = 0;
466 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
467 when using extended controls.
468 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
469 is it allowed for backwards compatibility.
471 if (!allow_priv
&& c
->ctrl_class
== V4L2_CID_PRIVATE_BASE
)
473 /* Check that all controls are from the same control class. */
474 for (i
= 0; i
< c
->count
; i
++) {
475 if (V4L2_CTRL_ID2CLASS(c
->controls
[i
].id
) != c
->ctrl_class
) {
483 static int check_fmt(const struct v4l2_ioctl_ops
*ops
, enum v4l2_buf_type type
)
489 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
490 if (ops
->vidioc_g_fmt_vid_cap
||
491 ops
->vidioc_g_fmt_vid_cap_mplane
)
494 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
495 if (ops
->vidioc_g_fmt_vid_cap_mplane
)
498 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
499 if (ops
->vidioc_g_fmt_vid_overlay
)
502 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
503 if (ops
->vidioc_g_fmt_vid_out
||
504 ops
->vidioc_g_fmt_vid_out_mplane
)
507 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
508 if (ops
->vidioc_g_fmt_vid_out_mplane
)
511 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
512 if (ops
->vidioc_g_fmt_vid_out_overlay
)
515 case V4L2_BUF_TYPE_VBI_CAPTURE
:
516 if (ops
->vidioc_g_fmt_vbi_cap
)
519 case V4L2_BUF_TYPE_VBI_OUTPUT
:
520 if (ops
->vidioc_g_fmt_vbi_out
)
523 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
524 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
527 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
528 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
531 case V4L2_BUF_TYPE_PRIVATE
:
532 if (ops
->vidioc_g_fmt_type_private
)
539 static long __video_do_ioctl(struct file
*file
,
540 unsigned int cmd
, void *arg
)
542 struct video_device
*vfd
= video_devdata(file
);
543 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
544 void *fh
= file
->private_data
;
545 struct v4l2_fh
*vfh
= NULL
;
550 printk(KERN_WARNING
"videodev: \"%s\" has no ioctl_ops.\n",
555 if (test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
)) {
556 vfh
= file
->private_data
;
557 use_fh_prio
= test_bit(V4L2_FL_USE_FH_PRIO
, &vfd
->flags
);
560 if (v4l2_is_known_ioctl(cmd
)) {
561 struct v4l2_ioctl_info
*info
= &v4l2_ioctls
[_IOC_NR(cmd
)];
563 if (!test_bit(_IOC_NR(cmd
), vfd
->valid_ioctls
) &&
564 !((info
->flags
& INFO_FL_CTRL
) && vfh
&& vfh
->ctrl_handler
))
567 if (use_fh_prio
&& (info
->flags
& INFO_FL_PRIO
)) {
568 ret
= v4l2_prio_check(vfd
->prio
, vfh
->prio
);
574 if ((vfd
->debug
& V4L2_DEBUG_IOCTL
) &&
575 !(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
)) {
576 v4l_print_ioctl(vfd
->name
, cmd
);
577 printk(KERN_CONT
"\n");
582 /* --- capabilities ------------------------------------------ */
583 case VIDIOC_QUERYCAP
:
585 struct v4l2_capability
*cap
= (struct v4l2_capability
*)arg
;
587 cap
->version
= LINUX_VERSION_CODE
;
588 ret
= ops
->vidioc_querycap(file
, fh
, cap
);
590 dbgarg(cmd
, "driver=%s, card=%s, bus=%s, "
592 "capabilities=0x%08x, "
593 "device_caps=0x%08x\n",
594 cap
->driver
, cap
->card
, cap
->bus_info
,
601 /* --- priority ------------------------------------------ */
602 case VIDIOC_G_PRIORITY
:
604 enum v4l2_priority
*p
= arg
;
606 if (ops
->vidioc_g_priority
) {
607 ret
= ops
->vidioc_g_priority(file
, fh
, p
);
608 } else if (use_fh_prio
) {
609 *p
= v4l2_prio_max(&vfd
->v4l2_dev
->prio
);
613 dbgarg(cmd
, "priority is %d\n", *p
);
616 case VIDIOC_S_PRIORITY
:
618 enum v4l2_priority
*p
= arg
;
620 dbgarg(cmd
, "setting priority to %d\n", *p
);
621 if (ops
->vidioc_s_priority
)
622 ret
= ops
->vidioc_s_priority(file
, fh
, *p
);
624 ret
= v4l2_prio_change(&vfd
->v4l2_dev
->prio
,
629 /* --- capture ioctls ---------------------------------------- */
630 case VIDIOC_ENUM_FMT
:
632 struct v4l2_fmtdesc
*f
= arg
;
636 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
637 if (likely(ops
->vidioc_enum_fmt_vid_cap
))
638 ret
= ops
->vidioc_enum_fmt_vid_cap(file
, fh
, f
);
640 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
641 if (likely(ops
->vidioc_enum_fmt_vid_cap_mplane
))
642 ret
= ops
->vidioc_enum_fmt_vid_cap_mplane(file
,
645 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
646 if (likely(ops
->vidioc_enum_fmt_vid_overlay
))
647 ret
= ops
->vidioc_enum_fmt_vid_overlay(file
,
650 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
651 if (likely(ops
->vidioc_enum_fmt_vid_out
))
652 ret
= ops
->vidioc_enum_fmt_vid_out(file
, fh
, f
);
654 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
655 if (likely(ops
->vidioc_enum_fmt_vid_out_mplane
))
656 ret
= ops
->vidioc_enum_fmt_vid_out_mplane(file
,
659 case V4L2_BUF_TYPE_PRIVATE
:
660 if (likely(ops
->vidioc_enum_fmt_type_private
))
661 ret
= ops
->vidioc_enum_fmt_type_private(file
,
668 dbgarg(cmd
, "index=%d, type=%d, flags=%d, "
669 "pixelformat=%c%c%c%c, description='%s'\n",
670 f
->index
, f
->type
, f
->flags
,
671 (f
->pixelformat
& 0xff),
672 (f
->pixelformat
>> 8) & 0xff,
673 (f
->pixelformat
>> 16) & 0xff,
674 (f
->pixelformat
>> 24) & 0xff,
680 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
682 /* FIXME: Should be one dump per type */
683 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
687 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
688 if (ops
->vidioc_g_fmt_vid_cap
)
689 ret
= ops
->vidioc_g_fmt_vid_cap(file
, fh
, f
);
691 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
693 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
694 if (ops
->vidioc_g_fmt_vid_cap_mplane
)
695 ret
= ops
->vidioc_g_fmt_vid_cap_mplane(file
,
698 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
700 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
701 if (likely(ops
->vidioc_g_fmt_vid_overlay
))
702 ret
= ops
->vidioc_g_fmt_vid_overlay(file
,
705 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
706 if (ops
->vidioc_g_fmt_vid_out
)
707 ret
= ops
->vidioc_g_fmt_vid_out(file
, fh
, f
);
709 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
711 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
712 if (ops
->vidioc_g_fmt_vid_out_mplane
)
713 ret
= ops
->vidioc_g_fmt_vid_out_mplane(file
,
716 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
718 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
719 if (likely(ops
->vidioc_g_fmt_vid_out_overlay
))
720 ret
= ops
->vidioc_g_fmt_vid_out_overlay(file
,
723 case V4L2_BUF_TYPE_VBI_CAPTURE
:
724 if (likely(ops
->vidioc_g_fmt_vbi_cap
))
725 ret
= ops
->vidioc_g_fmt_vbi_cap(file
, fh
, f
);
727 case V4L2_BUF_TYPE_VBI_OUTPUT
:
728 if (likely(ops
->vidioc_g_fmt_vbi_out
))
729 ret
= ops
->vidioc_g_fmt_vbi_out(file
, fh
, f
);
731 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
732 if (likely(ops
->vidioc_g_fmt_sliced_vbi_cap
))
733 ret
= ops
->vidioc_g_fmt_sliced_vbi_cap(file
,
736 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
737 if (likely(ops
->vidioc_g_fmt_sliced_vbi_out
))
738 ret
= ops
->vidioc_g_fmt_sliced_vbi_out(file
,
741 case V4L2_BUF_TYPE_PRIVATE
:
742 if (likely(ops
->vidioc_g_fmt_type_private
))
743 ret
= ops
->vidioc_g_fmt_type_private(file
,
751 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
755 /* FIXME: Should be one dump per type */
756 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
759 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
760 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
761 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
762 if (ops
->vidioc_s_fmt_vid_cap
)
763 ret
= ops
->vidioc_s_fmt_vid_cap(file
, fh
, f
);
765 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
766 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
767 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
768 if (ops
->vidioc_s_fmt_vid_cap_mplane
)
769 ret
= ops
->vidioc_s_fmt_vid_cap_mplane(file
,
772 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
773 CLEAR_AFTER_FIELD(f
, fmt
.win
);
774 if (ops
->vidioc_s_fmt_vid_overlay
)
775 ret
= ops
->vidioc_s_fmt_vid_overlay(file
,
778 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
779 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
780 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
781 if (ops
->vidioc_s_fmt_vid_out
)
782 ret
= ops
->vidioc_s_fmt_vid_out(file
, fh
, f
);
784 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
785 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
786 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
787 if (ops
->vidioc_s_fmt_vid_out_mplane
)
788 ret
= ops
->vidioc_s_fmt_vid_out_mplane(file
,
791 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
792 CLEAR_AFTER_FIELD(f
, fmt
.win
);
793 if (ops
->vidioc_s_fmt_vid_out_overlay
)
794 ret
= ops
->vidioc_s_fmt_vid_out_overlay(file
,
797 case V4L2_BUF_TYPE_VBI_CAPTURE
:
798 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
799 if (likely(ops
->vidioc_s_fmt_vbi_cap
))
800 ret
= ops
->vidioc_s_fmt_vbi_cap(file
, fh
, f
);
802 case V4L2_BUF_TYPE_VBI_OUTPUT
:
803 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
804 if (likely(ops
->vidioc_s_fmt_vbi_out
))
805 ret
= ops
->vidioc_s_fmt_vbi_out(file
, fh
, f
);
807 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
808 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
809 if (likely(ops
->vidioc_s_fmt_sliced_vbi_cap
))
810 ret
= ops
->vidioc_s_fmt_sliced_vbi_cap(file
,
813 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
814 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
815 if (likely(ops
->vidioc_s_fmt_sliced_vbi_out
))
816 ret
= ops
->vidioc_s_fmt_sliced_vbi_out(file
,
820 case V4L2_BUF_TYPE_PRIVATE
:
821 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
822 if (likely(ops
->vidioc_s_fmt_type_private
))
823 ret
= ops
->vidioc_s_fmt_type_private(file
,
831 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
833 /* FIXME: Should be one dump per type */
834 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
,
838 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
839 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
840 if (ops
->vidioc_try_fmt_vid_cap
)
841 ret
= ops
->vidioc_try_fmt_vid_cap(file
, fh
, f
);
843 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
845 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
846 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
847 if (ops
->vidioc_try_fmt_vid_cap_mplane
)
848 ret
= ops
->vidioc_try_fmt_vid_cap_mplane(file
,
851 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
853 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
854 CLEAR_AFTER_FIELD(f
, fmt
.win
);
855 if (likely(ops
->vidioc_try_fmt_vid_overlay
))
856 ret
= ops
->vidioc_try_fmt_vid_overlay(file
,
859 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
860 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
861 if (ops
->vidioc_try_fmt_vid_out
)
862 ret
= ops
->vidioc_try_fmt_vid_out(file
, fh
, f
);
864 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
866 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
867 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
868 if (ops
->vidioc_try_fmt_vid_out_mplane
)
869 ret
= ops
->vidioc_try_fmt_vid_out_mplane(file
,
872 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
874 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
875 CLEAR_AFTER_FIELD(f
, fmt
.win
);
876 if (likely(ops
->vidioc_try_fmt_vid_out_overlay
))
877 ret
= ops
->vidioc_try_fmt_vid_out_overlay(file
,
880 case V4L2_BUF_TYPE_VBI_CAPTURE
:
881 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
882 if (likely(ops
->vidioc_try_fmt_vbi_cap
))
883 ret
= ops
->vidioc_try_fmt_vbi_cap(file
, fh
, f
);
885 case V4L2_BUF_TYPE_VBI_OUTPUT
:
886 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
887 if (likely(ops
->vidioc_try_fmt_vbi_out
))
888 ret
= ops
->vidioc_try_fmt_vbi_out(file
, fh
, f
);
890 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
891 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
892 if (likely(ops
->vidioc_try_fmt_sliced_vbi_cap
))
893 ret
= ops
->vidioc_try_fmt_sliced_vbi_cap(file
,
896 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
897 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
898 if (likely(ops
->vidioc_try_fmt_sliced_vbi_out
))
899 ret
= ops
->vidioc_try_fmt_sliced_vbi_out(file
,
902 case V4L2_BUF_TYPE_PRIVATE
:
903 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
904 if (likely(ops
->vidioc_try_fmt_type_private
))
905 ret
= ops
->vidioc_try_fmt_type_private(file
,
911 /* FIXME: Those buf reqs could be handled here,
912 with some changes on videobuf to allow its header to be included at
913 videodev2.h or being merged at videodev2.
917 struct v4l2_requestbuffers
*p
= arg
;
919 ret
= check_fmt(ops
, p
->type
);
923 if (p
->type
< V4L2_BUF_TYPE_PRIVATE
)
924 CLEAR_AFTER_FIELD(p
, memory
);
926 ret
= ops
->vidioc_reqbufs(file
, fh
, p
);
927 dbgarg(cmd
, "count=%d, type=%s, memory=%s\n",
929 prt_names(p
->type
, v4l2_type_names
),
930 prt_names(p
->memory
, v4l2_memory_names
));
933 case VIDIOC_QUERYBUF
:
935 struct v4l2_buffer
*p
= arg
;
937 ret
= check_fmt(ops
, p
->type
);
941 ret
= ops
->vidioc_querybuf(file
, fh
, p
);
948 struct v4l2_buffer
*p
= arg
;
950 ret
= check_fmt(ops
, p
->type
);
954 ret
= ops
->vidioc_qbuf(file
, fh
, p
);
961 struct v4l2_buffer
*p
= arg
;
963 ret
= check_fmt(ops
, p
->type
);
967 ret
= ops
->vidioc_dqbuf(file
, fh
, p
);
976 dbgarg(cmd
, "value=%d\n", *i
);
977 ret
= ops
->vidioc_overlay(file
, fh
, *i
);
982 struct v4l2_framebuffer
*p
= arg
;
984 ret
= ops
->vidioc_g_fbuf(file
, fh
, arg
);
986 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
987 p
->capability
, p
->flags
,
988 (unsigned long)p
->base
);
989 v4l_print_pix_fmt(vfd
, &p
->fmt
);
995 struct v4l2_framebuffer
*p
= arg
;
997 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
998 p
->capability
, p
->flags
, (unsigned long)p
->base
);
999 v4l_print_pix_fmt(vfd
, &p
->fmt
);
1000 ret
= ops
->vidioc_s_fbuf(file
, fh
, arg
);
1003 case VIDIOC_STREAMON
:
1005 enum v4l2_buf_type i
= *(int *)arg
;
1007 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1008 ret
= ops
->vidioc_streamon(file
, fh
, i
);
1011 case VIDIOC_STREAMOFF
:
1013 enum v4l2_buf_type i
= *(int *)arg
;
1015 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1016 ret
= ops
->vidioc_streamoff(file
, fh
, i
);
1019 /* ---------- tv norms ---------- */
1020 case VIDIOC_ENUMSTD
:
1022 struct v4l2_standard
*p
= arg
;
1023 v4l2_std_id id
= vfd
->tvnorms
, curr_id
= 0;
1024 unsigned int index
= p
->index
, i
, j
= 0;
1025 const char *descr
= "";
1031 /* Return norm array in a canonical way */
1032 for (i
= 0; i
<= index
&& id
; i
++) {
1033 /* last std value in the standards array is 0, so this
1034 while always ends there since (id & 0) == 0. */
1035 while ((id
& standards
[j
].std
) != standards
[j
].std
)
1037 curr_id
= standards
[j
].std
;
1038 descr
= standards
[j
].descr
;
1042 if (curr_id
!= V4L2_STD_PAL
&&
1043 curr_id
!= V4L2_STD_SECAM
&&
1044 curr_id
!= V4L2_STD_NTSC
)
1050 v4l2_video_std_construct(p
, curr_id
, descr
);
1052 dbgarg(cmd
, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1053 "framelines=%d\n", p
->index
,
1054 (unsigned long long)p
->id
, p
->name
,
1055 p
->frameperiod
.numerator
,
1056 p
->frameperiod
.denominator
,
1064 v4l2_std_id
*id
= arg
;
1066 /* Calls the specific handler */
1067 if (ops
->vidioc_g_std
)
1068 ret
= ops
->vidioc_g_std(file
, fh
, id
);
1069 else if (vfd
->current_norm
) {
1071 *id
= vfd
->current_norm
;
1075 dbgarg(cmd
, "std=0x%08Lx\n", (long long unsigned)*id
);
1080 v4l2_std_id
*id
= arg
, norm
;
1082 dbgarg(cmd
, "std=%08Lx\n", (long long unsigned)*id
);
1085 norm
= (*id
) & vfd
->tvnorms
;
1086 if (vfd
->tvnorms
&& !norm
) /* Check if std is supported */
1089 /* Calls the specific handler */
1090 ret
= ops
->vidioc_s_std(file
, fh
, &norm
);
1092 /* Updates standard information */
1094 vfd
->current_norm
= norm
;
1097 case VIDIOC_QUERYSTD
:
1099 v4l2_std_id
*p
= arg
;
1102 * If nothing detected, it should return all supported
1103 * Drivers just need to mask the std argument, in order
1104 * to remove the standards that don't apply from the mask.
1105 * This means that tuners, audio and video decoders can join
1106 * their efforts to improve the standards detection
1109 ret
= ops
->vidioc_querystd(file
, fh
, arg
);
1111 dbgarg(cmd
, "detected std=%08Lx\n",
1112 (unsigned long long)*p
);
1115 /* ------ input switching ---------- */
1116 /* FIXME: Inputs can be handled inside videodev2 */
1117 case VIDIOC_ENUMINPUT
:
1119 struct v4l2_input
*p
= arg
;
1122 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1123 * CAP_STD here based on ioctl handler provided by the
1124 * driver. If the driver doesn't support these
1125 * for a specific input, it must override these flags.
1127 if (ops
->vidioc_s_std
)
1128 p
->capabilities
|= V4L2_IN_CAP_STD
;
1129 if (ops
->vidioc_s_dv_preset
)
1130 p
->capabilities
|= V4L2_IN_CAP_PRESETS
;
1131 if (ops
->vidioc_s_dv_timings
)
1132 p
->capabilities
|= V4L2_IN_CAP_CUSTOM_TIMINGS
;
1134 ret
= ops
->vidioc_enum_input(file
, fh
, p
);
1136 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1138 "tuner=%d, std=%08Lx, status=%d\n",
1139 p
->index
, p
->name
, p
->type
, p
->audioset
,
1141 (unsigned long long)p
->std
,
1145 case VIDIOC_G_INPUT
:
1147 unsigned int *i
= arg
;
1149 ret
= ops
->vidioc_g_input(file
, fh
, i
);
1151 dbgarg(cmd
, "value=%d\n", *i
);
1154 case VIDIOC_S_INPUT
:
1156 unsigned int *i
= arg
;
1158 dbgarg(cmd
, "value=%d\n", *i
);
1159 ret
= ops
->vidioc_s_input(file
, fh
, *i
);
1163 /* ------ output switching ---------- */
1164 case VIDIOC_ENUMOUTPUT
:
1166 struct v4l2_output
*p
= arg
;
1169 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1170 * CAP_STD here based on ioctl handler provided by the
1171 * driver. If the driver doesn't support these
1172 * for a specific output, it must override these flags.
1174 if (ops
->vidioc_s_std
)
1175 p
->capabilities
|= V4L2_OUT_CAP_STD
;
1176 if (ops
->vidioc_s_dv_preset
)
1177 p
->capabilities
|= V4L2_OUT_CAP_PRESETS
;
1178 if (ops
->vidioc_s_dv_timings
)
1179 p
->capabilities
|= V4L2_OUT_CAP_CUSTOM_TIMINGS
;
1181 ret
= ops
->vidioc_enum_output(file
, fh
, p
);
1183 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1185 "modulator=%d, std=0x%08Lx\n",
1186 p
->index
, p
->name
, p
->type
, p
->audioset
,
1187 p
->modulator
, (unsigned long long)p
->std
);
1190 case VIDIOC_G_OUTPUT
:
1192 unsigned int *i
= arg
;
1194 ret
= ops
->vidioc_g_output(file
, fh
, i
);
1196 dbgarg(cmd
, "value=%d\n", *i
);
1199 case VIDIOC_S_OUTPUT
:
1201 unsigned int *i
= arg
;
1203 dbgarg(cmd
, "value=%d\n", *i
);
1204 ret
= ops
->vidioc_s_output(file
, fh
, *i
);
1208 /* --- controls ---------------------------------------------- */
1209 case VIDIOC_QUERYCTRL
:
1211 struct v4l2_queryctrl
*p
= arg
;
1213 if (vfh
&& vfh
->ctrl_handler
)
1214 ret
= v4l2_queryctrl(vfh
->ctrl_handler
, p
);
1215 else if (vfd
->ctrl_handler
)
1216 ret
= v4l2_queryctrl(vfd
->ctrl_handler
, p
);
1217 else if (ops
->vidioc_queryctrl
)
1218 ret
= ops
->vidioc_queryctrl(file
, fh
, p
);
1222 dbgarg(cmd
, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1223 "step=%d, default=%d, flags=0x%08x\n",
1224 p
->id
, p
->type
, p
->name
,
1225 p
->minimum
, p
->maximum
,
1226 p
->step
, p
->default_value
, p
->flags
);
1228 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1233 struct v4l2_control
*p
= arg
;
1235 if (vfh
&& vfh
->ctrl_handler
)
1236 ret
= v4l2_g_ctrl(vfh
->ctrl_handler
, p
);
1237 else if (vfd
->ctrl_handler
)
1238 ret
= v4l2_g_ctrl(vfd
->ctrl_handler
, p
);
1239 else if (ops
->vidioc_g_ctrl
)
1240 ret
= ops
->vidioc_g_ctrl(file
, fh
, p
);
1241 else if (ops
->vidioc_g_ext_ctrls
) {
1242 struct v4l2_ext_controls ctrls
;
1243 struct v4l2_ext_control ctrl
;
1245 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1247 ctrls
.controls
= &ctrl
;
1249 ctrl
.value
= p
->value
;
1250 if (check_ext_ctrls(&ctrls
, 1)) {
1251 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, &ctrls
);
1253 p
->value
= ctrl
.value
;
1258 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1260 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1265 struct v4l2_control
*p
= arg
;
1266 struct v4l2_ext_controls ctrls
;
1267 struct v4l2_ext_control ctrl
;
1269 if (!(vfh
&& vfh
->ctrl_handler
) && !vfd
->ctrl_handler
&&
1270 !ops
->vidioc_s_ctrl
&& !ops
->vidioc_s_ext_ctrls
)
1273 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1275 if (vfh
&& vfh
->ctrl_handler
) {
1276 ret
= v4l2_s_ctrl(vfh
, vfh
->ctrl_handler
, p
);
1279 if (vfd
->ctrl_handler
) {
1280 ret
= v4l2_s_ctrl(NULL
, vfd
->ctrl_handler
, p
);
1283 if (ops
->vidioc_s_ctrl
) {
1284 ret
= ops
->vidioc_s_ctrl(file
, fh
, p
);
1287 if (!ops
->vidioc_s_ext_ctrls
)
1290 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1292 ctrls
.controls
= &ctrl
;
1294 ctrl
.value
= p
->value
;
1295 if (check_ext_ctrls(&ctrls
, 1))
1296 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, &ctrls
);
1301 case VIDIOC_G_EXT_CTRLS
:
1303 struct v4l2_ext_controls
*p
= arg
;
1305 p
->error_idx
= p
->count
;
1306 if (vfh
&& vfh
->ctrl_handler
)
1307 ret
= v4l2_g_ext_ctrls(vfh
->ctrl_handler
, p
);
1308 else if (vfd
->ctrl_handler
)
1309 ret
= v4l2_g_ext_ctrls(vfd
->ctrl_handler
, p
);
1310 else if (ops
->vidioc_g_ext_ctrls
)
1311 ret
= check_ext_ctrls(p
, 0) ?
1312 ops
->vidioc_g_ext_ctrls(file
, fh
, p
) :
1316 v4l_print_ext_ctrls(cmd
, vfd
, p
, !ret
);
1319 case VIDIOC_S_EXT_CTRLS
:
1321 struct v4l2_ext_controls
*p
= arg
;
1323 p
->error_idx
= p
->count
;
1324 if (!(vfh
&& vfh
->ctrl_handler
) && !vfd
->ctrl_handler
&&
1325 !ops
->vidioc_s_ext_ctrls
)
1327 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1328 if (vfh
&& vfh
->ctrl_handler
)
1329 ret
= v4l2_s_ext_ctrls(vfh
, vfh
->ctrl_handler
, p
);
1330 else if (vfd
->ctrl_handler
)
1331 ret
= v4l2_s_ext_ctrls(NULL
, vfd
->ctrl_handler
, p
);
1332 else if (check_ext_ctrls(p
, 0))
1333 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, p
);
1338 case VIDIOC_TRY_EXT_CTRLS
:
1340 struct v4l2_ext_controls
*p
= arg
;
1342 p
->error_idx
= p
->count
;
1343 if (!(vfh
&& vfh
->ctrl_handler
) && !vfd
->ctrl_handler
&&
1344 !ops
->vidioc_try_ext_ctrls
)
1346 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1347 if (vfh
&& vfh
->ctrl_handler
)
1348 ret
= v4l2_try_ext_ctrls(vfh
->ctrl_handler
, p
);
1349 else if (vfd
->ctrl_handler
)
1350 ret
= v4l2_try_ext_ctrls(vfd
->ctrl_handler
, p
);
1351 else if (check_ext_ctrls(p
, 0))
1352 ret
= ops
->vidioc_try_ext_ctrls(file
, fh
, p
);
1357 case VIDIOC_QUERYMENU
:
1359 struct v4l2_querymenu
*p
= arg
;
1361 if (vfh
&& vfh
->ctrl_handler
)
1362 ret
= v4l2_querymenu(vfh
->ctrl_handler
, p
);
1363 else if (vfd
->ctrl_handler
)
1364 ret
= v4l2_querymenu(vfd
->ctrl_handler
, p
);
1365 else if (ops
->vidioc_querymenu
)
1366 ret
= ops
->vidioc_querymenu(file
, fh
, p
);
1370 dbgarg(cmd
, "id=0x%x, index=%d, name=%s\n",
1371 p
->id
, p
->index
, p
->name
);
1373 dbgarg(cmd
, "id=0x%x, index=%d\n",
1377 /* --- audio ---------------------------------------------- */
1378 case VIDIOC_ENUMAUDIO
:
1380 struct v4l2_audio
*p
= arg
;
1382 ret
= ops
->vidioc_enumaudio(file
, fh
, p
);
1384 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1385 "mode=0x%x\n", p
->index
, p
->name
,
1386 p
->capability
, p
->mode
);
1388 dbgarg(cmd
, "index=%d\n", p
->index
);
1391 case VIDIOC_G_AUDIO
:
1393 struct v4l2_audio
*p
= arg
;
1395 ret
= ops
->vidioc_g_audio(file
, fh
, p
);
1397 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1398 "mode=0x%x\n", p
->index
,
1399 p
->name
, p
->capability
, p
->mode
);
1401 dbgarg(cmd
, "index=%d\n", p
->index
);
1404 case VIDIOC_S_AUDIO
:
1406 struct v4l2_audio
*p
= arg
;
1408 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1409 "mode=0x%x\n", p
->index
, p
->name
,
1410 p
->capability
, p
->mode
);
1411 ret
= ops
->vidioc_s_audio(file
, fh
, p
);
1414 case VIDIOC_ENUMAUDOUT
:
1416 struct v4l2_audioout
*p
= arg
;
1418 dbgarg(cmd
, "Enum for index=%d\n", p
->index
);
1419 ret
= ops
->vidioc_enumaudout(file
, fh
, p
);
1421 dbgarg2("index=%d, name=%s, capability=%d, "
1422 "mode=%d\n", p
->index
, p
->name
,
1423 p
->capability
, p
->mode
);
1426 case VIDIOC_G_AUDOUT
:
1428 struct v4l2_audioout
*p
= arg
;
1430 ret
= ops
->vidioc_g_audout(file
, fh
, p
);
1432 dbgarg2("index=%d, name=%s, capability=%d, "
1433 "mode=%d\n", p
->index
, p
->name
,
1434 p
->capability
, p
->mode
);
1437 case VIDIOC_S_AUDOUT
:
1439 struct v4l2_audioout
*p
= arg
;
1441 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1442 "mode=%d\n", p
->index
, p
->name
,
1443 p
->capability
, p
->mode
);
1445 ret
= ops
->vidioc_s_audout(file
, fh
, p
);
1448 case VIDIOC_G_MODULATOR
:
1450 struct v4l2_modulator
*p
= arg
;
1452 ret
= ops
->vidioc_g_modulator(file
, fh
, p
);
1454 dbgarg(cmd
, "index=%d, name=%s, "
1455 "capability=%d, rangelow=%d,"
1456 " rangehigh=%d, txsubchans=%d\n",
1457 p
->index
, p
->name
, p
->capability
,
1458 p
->rangelow
, p
->rangehigh
,
1462 case VIDIOC_S_MODULATOR
:
1464 struct v4l2_modulator
*p
= arg
;
1466 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1467 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1468 p
->index
, p
->name
, p
->capability
, p
->rangelow
,
1469 p
->rangehigh
, p
->txsubchans
);
1470 ret
= ops
->vidioc_s_modulator(file
, fh
, p
);
1475 struct v4l2_crop
*p
= arg
;
1477 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1479 if (ops
->vidioc_g_crop
) {
1480 ret
= ops
->vidioc_g_crop(file
, fh
, p
);
1482 /* simulate capture crop using selection api */
1483 struct v4l2_selection s
= {
1487 /* crop means compose for output devices */
1488 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
1489 s
.target
= V4L2_SEL_TGT_COMPOSE_ACTIVE
;
1491 s
.target
= V4L2_SEL_TGT_CROP_ACTIVE
;
1493 ret
= ops
->vidioc_g_selection(file
, fh
, &s
);
1495 /* copying results to old structure on success */
1501 dbgrect(vfd
, "", &p
->c
);
1506 struct v4l2_crop
*p
= arg
;
1508 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1509 dbgrect(vfd
, "", &p
->c
);
1511 if (ops
->vidioc_s_crop
) {
1512 ret
= ops
->vidioc_s_crop(file
, fh
, p
);
1514 /* simulate capture crop using selection api */
1515 struct v4l2_selection s
= {
1520 /* crop means compose for output devices */
1521 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
1522 s
.target
= V4L2_SEL_TGT_COMPOSE_ACTIVE
;
1524 s
.target
= V4L2_SEL_TGT_CROP_ACTIVE
;
1526 ret
= ops
->vidioc_s_selection(file
, fh
, &s
);
1530 case VIDIOC_G_SELECTION
:
1532 struct v4l2_selection
*p
= arg
;
1534 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1536 ret
= ops
->vidioc_g_selection(file
, fh
, p
);
1538 dbgrect(vfd
, "", &p
->r
);
1541 case VIDIOC_S_SELECTION
:
1543 struct v4l2_selection
*p
= arg
;
1546 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1547 dbgrect(vfd
, "", &p
->r
);
1549 ret
= ops
->vidioc_s_selection(file
, fh
, p
);
1552 case VIDIOC_CROPCAP
:
1554 struct v4l2_cropcap
*p
= arg
;
1556 /*FIXME: Should also show v4l2_fract pixelaspect */
1557 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1558 if (ops
->vidioc_cropcap
) {
1559 ret
= ops
->vidioc_cropcap(file
, fh
, p
);
1561 struct v4l2_selection s
= { .type
= p
->type
};
1563 /* obtaining bounds */
1564 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
1565 s
.target
= V4L2_SEL_TGT_COMPOSE_BOUNDS
;
1567 s
.target
= V4L2_SEL_TGT_CROP_BOUNDS
;
1569 ret
= ops
->vidioc_g_selection(file
, fh
, &s
);
1574 /* obtaining defrect */
1575 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
1576 s
.target
= V4L2_SEL_TGT_COMPOSE_DEFAULT
;
1578 s
.target
= V4L2_SEL_TGT_CROP_DEFAULT
;
1580 ret
= ops
->vidioc_g_selection(file
, fh
, &s
);
1585 /* setting trivial pixelaspect */
1586 p
->pixelaspect
.numerator
= 1;
1587 p
->pixelaspect
.denominator
= 1;
1591 dbgrect(vfd
, "bounds ", &p
->bounds
);
1592 dbgrect(vfd
, "defrect ", &p
->defrect
);
1596 case VIDIOC_G_JPEGCOMP
:
1598 struct v4l2_jpegcompression
*p
= arg
;
1600 ret
= ops
->vidioc_g_jpegcomp(file
, fh
, p
);
1602 dbgarg(cmd
, "quality=%d, APPn=%d, "
1603 "APP_len=%d, COM_len=%d, "
1604 "jpeg_markers=%d\n",
1605 p
->quality
, p
->APPn
, p
->APP_len
,
1606 p
->COM_len
, p
->jpeg_markers
);
1609 case VIDIOC_S_JPEGCOMP
:
1611 struct v4l2_jpegcompression
*p
= arg
;
1613 dbgarg(cmd
, "quality=%d, APPn=%d, APP_len=%d, "
1614 "COM_len=%d, jpeg_markers=%d\n",
1615 p
->quality
, p
->APPn
, p
->APP_len
,
1616 p
->COM_len
, p
->jpeg_markers
);
1617 ret
= ops
->vidioc_s_jpegcomp(file
, fh
, p
);
1620 case VIDIOC_G_ENC_INDEX
:
1622 struct v4l2_enc_idx
*p
= arg
;
1624 ret
= ops
->vidioc_g_enc_index(file
, fh
, p
);
1626 dbgarg(cmd
, "entries=%d, entries_cap=%d\n",
1627 p
->entries
, p
->entries_cap
);
1630 case VIDIOC_ENCODER_CMD
:
1632 struct v4l2_encoder_cmd
*p
= arg
;
1634 ret
= ops
->vidioc_encoder_cmd(file
, fh
, p
);
1636 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1639 case VIDIOC_TRY_ENCODER_CMD
:
1641 struct v4l2_encoder_cmd
*p
= arg
;
1643 ret
= ops
->vidioc_try_encoder_cmd(file
, fh
, p
);
1645 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1648 case VIDIOC_DECODER_CMD
:
1650 struct v4l2_decoder_cmd
*p
= arg
;
1652 ret
= ops
->vidioc_decoder_cmd(file
, fh
, p
);
1654 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1657 case VIDIOC_TRY_DECODER_CMD
:
1659 struct v4l2_decoder_cmd
*p
= arg
;
1661 ret
= ops
->vidioc_try_decoder_cmd(file
, fh
, p
);
1663 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1668 struct v4l2_streamparm
*p
= arg
;
1670 if (ops
->vidioc_g_parm
) {
1671 ret
= check_fmt(ops
, p
->type
);
1674 ret
= ops
->vidioc_g_parm(file
, fh
, p
);
1676 v4l2_std_id std
= vfd
->current_norm
;
1679 if (p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1683 p
->parm
.capture
.readbuffers
= 2;
1684 if (ops
->vidioc_g_std
)
1685 ret
= ops
->vidioc_g_std(file
, fh
, &std
);
1687 v4l2_video_std_frame_period(std
,
1688 &p
->parm
.capture
.timeperframe
);
1691 dbgarg(cmd
, "type=%d\n", p
->type
);
1696 struct v4l2_streamparm
*p
= arg
;
1698 ret
= check_fmt(ops
, p
->type
);
1702 dbgarg(cmd
, "type=%d\n", p
->type
);
1703 ret
= ops
->vidioc_s_parm(file
, fh
, p
);
1706 case VIDIOC_G_TUNER
:
1708 struct v4l2_tuner
*p
= arg
;
1710 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1711 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1712 ret
= ops
->vidioc_g_tuner(file
, fh
, p
);
1714 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1715 "capability=0x%x, rangelow=%d, "
1716 "rangehigh=%d, signal=%d, afc=%d, "
1717 "rxsubchans=0x%x, audmode=%d\n",
1718 p
->index
, p
->name
, p
->type
,
1719 p
->capability
, p
->rangelow
,
1720 p
->rangehigh
, p
->signal
, p
->afc
,
1721 p
->rxsubchans
, p
->audmode
);
1724 case VIDIOC_S_TUNER
:
1726 struct v4l2_tuner
*p
= arg
;
1728 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1729 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1730 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1731 "capability=0x%x, rangelow=%d, "
1732 "rangehigh=%d, signal=%d, afc=%d, "
1733 "rxsubchans=0x%x, audmode=%d\n",
1734 p
->index
, p
->name
, p
->type
,
1735 p
->capability
, p
->rangelow
,
1736 p
->rangehigh
, p
->signal
, p
->afc
,
1737 p
->rxsubchans
, p
->audmode
);
1738 ret
= ops
->vidioc_s_tuner(file
, fh
, p
);
1741 case VIDIOC_G_FREQUENCY
:
1743 struct v4l2_frequency
*p
= arg
;
1745 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1746 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1747 ret
= ops
->vidioc_g_frequency(file
, fh
, p
);
1749 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1750 p
->tuner
, p
->type
, p
->frequency
);
1753 case VIDIOC_S_FREQUENCY
:
1755 struct v4l2_frequency
*p
= arg
;
1756 enum v4l2_tuner_type type
;
1758 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1759 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1760 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1761 p
->tuner
, p
->type
, p
->frequency
);
1762 if (p
->type
!= type
)
1765 ret
= ops
->vidioc_s_frequency(file
, fh
, p
);
1768 case VIDIOC_G_SLICED_VBI_CAP
:
1770 struct v4l2_sliced_vbi_cap
*p
= arg
;
1772 /* Clear up to type, everything after type is zerod already */
1773 memset(p
, 0, offsetof(struct v4l2_sliced_vbi_cap
, type
));
1775 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1776 ret
= ops
->vidioc_g_sliced_vbi_cap(file
, fh
, p
);
1778 dbgarg2("service_set=%d\n", p
->service_set
);
1781 case VIDIOC_LOG_STATUS
:
1784 pr_info("%s: ================= START STATUS =================\n",
1785 vfd
->v4l2_dev
->name
);
1786 ret
= ops
->vidioc_log_status(file
, fh
);
1788 pr_info("%s: ================== END STATUS ==================\n",
1789 vfd
->v4l2_dev
->name
);
1792 case VIDIOC_DBG_G_REGISTER
:
1794 #ifdef CONFIG_VIDEO_ADV_DEBUG
1795 struct v4l2_dbg_register
*p
= arg
;
1797 if (!capable(CAP_SYS_ADMIN
))
1800 ret
= ops
->vidioc_g_register(file
, fh
, p
);
1804 case VIDIOC_DBG_S_REGISTER
:
1806 #ifdef CONFIG_VIDEO_ADV_DEBUG
1807 struct v4l2_dbg_register
*p
= arg
;
1809 if (!capable(CAP_SYS_ADMIN
))
1812 ret
= ops
->vidioc_s_register(file
, fh
, p
);
1816 case VIDIOC_DBG_G_CHIP_IDENT
:
1818 struct v4l2_dbg_chip_ident
*p
= arg
;
1820 p
->ident
= V4L2_IDENT_NONE
;
1822 ret
= ops
->vidioc_g_chip_ident(file
, fh
, p
);
1824 dbgarg(cmd
, "chip_ident=%u, revision=0x%x\n", p
->ident
, p
->revision
);
1827 case VIDIOC_S_HW_FREQ_SEEK
:
1829 struct v4l2_hw_freq_seek
*p
= arg
;
1830 enum v4l2_tuner_type type
;
1832 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1833 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1835 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1836 p
->tuner
, p
->type
, p
->seek_upward
, p
->wrap_around
, p
->spacing
);
1837 if (p
->type
!= type
)
1840 ret
= ops
->vidioc_s_hw_freq_seek(file
, fh
, p
);
1843 case VIDIOC_ENUM_FRAMESIZES
:
1845 struct v4l2_frmsizeenum
*p
= arg
;
1847 ret
= ops
->vidioc_enum_framesizes(file
, fh
, p
);
1849 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1851 (p
->pixel_format
& 0xff),
1852 (p
->pixel_format
>> 8) & 0xff,
1853 (p
->pixel_format
>> 16) & 0xff,
1854 (p
->pixel_format
>> 24) & 0xff,
1857 case V4L2_FRMSIZE_TYPE_DISCRETE
:
1858 dbgarg3("width = %d, height=%d\n",
1859 p
->discrete
.width
, p
->discrete
.height
);
1861 case V4L2_FRMSIZE_TYPE_STEPWISE
:
1862 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1863 p
->stepwise
.min_width
, p
->stepwise
.min_height
,
1864 p
->stepwise
.step_width
, p
->stepwise
.step_height
,
1865 p
->stepwise
.max_width
, p
->stepwise
.max_height
);
1867 case V4L2_FRMSIZE_TYPE_CONTINUOUS
:
1868 dbgarg3("continuous\n");
1871 dbgarg3("- Unknown type!\n");
1876 case VIDIOC_ENUM_FRAMEINTERVALS
:
1878 struct v4l2_frmivalenum
*p
= arg
;
1880 ret
= ops
->vidioc_enum_frameintervals(file
, fh
, p
);
1882 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1883 p
->index
, p
->pixel_format
,
1884 p
->width
, p
->height
, p
->type
);
1886 case V4L2_FRMIVAL_TYPE_DISCRETE
:
1887 dbgarg2("fps=%d/%d\n",
1888 p
->discrete
.numerator
,
1889 p
->discrete
.denominator
);
1891 case V4L2_FRMIVAL_TYPE_STEPWISE
:
1892 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1893 p
->stepwise
.min
.numerator
,
1894 p
->stepwise
.min
.denominator
,
1895 p
->stepwise
.max
.numerator
,
1896 p
->stepwise
.max
.denominator
,
1897 p
->stepwise
.step
.numerator
,
1898 p
->stepwise
.step
.denominator
);
1900 case V4L2_FRMIVAL_TYPE_CONTINUOUS
:
1901 dbgarg2("continuous\n");
1904 dbgarg2("- Unknown type!\n");
1908 case VIDIOC_ENUM_DV_PRESETS
:
1910 struct v4l2_dv_enum_preset
*p
= arg
;
1912 ret
= ops
->vidioc_enum_dv_presets(file
, fh
, p
);
1915 "index=%d, preset=%d, name=%s, width=%d,"
1917 p
->index
, p
->preset
, p
->name
, p
->width
,
1921 case VIDIOC_S_DV_PRESET
:
1923 struct v4l2_dv_preset
*p
= arg
;
1925 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1926 ret
= ops
->vidioc_s_dv_preset(file
, fh
, p
);
1929 case VIDIOC_G_DV_PRESET
:
1931 struct v4l2_dv_preset
*p
= arg
;
1933 ret
= ops
->vidioc_g_dv_preset(file
, fh
, p
);
1935 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1938 case VIDIOC_QUERY_DV_PRESET
:
1940 struct v4l2_dv_preset
*p
= arg
;
1942 ret
= ops
->vidioc_query_dv_preset(file
, fh
, p
);
1944 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1947 case VIDIOC_S_DV_TIMINGS
:
1949 struct v4l2_dv_timings
*p
= arg
;
1953 case V4L2_DV_BT_656_1120
:
1954 ret
= ops
->vidioc_s_dv_timings(file
, fh
, p
);
1962 case VIDIOC_G_DV_TIMINGS
:
1964 struct v4l2_dv_timings
*p
= arg
;
1966 ret
= ops
->vidioc_g_dv_timings(file
, fh
, p
);
1971 case VIDIOC_ENUM_DV_TIMINGS
:
1973 struct v4l2_enum_dv_timings
*p
= arg
;
1975 if (!ops
->vidioc_enum_dv_timings
)
1978 ret
= ops
->vidioc_enum_dv_timings(file
, fh
, p
);
1980 dbgarg(cmd
, "index=%d: ", p
->index
);
1981 dbgtimings(vfd
, &p
->timings
);
1985 case VIDIOC_QUERY_DV_TIMINGS
:
1987 struct v4l2_dv_timings
*p
= arg
;
1989 if (!ops
->vidioc_query_dv_timings
)
1992 ret
= ops
->vidioc_query_dv_timings(file
, fh
, p
);
1997 case VIDIOC_DV_TIMINGS_CAP
:
1999 struct v4l2_dv_timings_cap
*p
= arg
;
2001 if (!ops
->vidioc_dv_timings_cap
)
2004 ret
= ops
->vidioc_dv_timings_cap(file
, fh
, p
);
2008 case V4L2_DV_BT_656_1120
:
2010 "type=%d, width=%u-%u, height=%u-%u, "
2011 "pixelclock=%llu-%llu, standards=%x, capabilities=%x ",
2013 p
->bt
.min_width
, p
->bt
.max_width
,
2014 p
->bt
.min_height
, p
->bt
.max_height
,
2015 p
->bt
.min_pixelclock
, p
->bt
.max_pixelclock
,
2016 p
->bt
.standards
, p
->bt
.capabilities
);
2019 dbgarg(cmd
, "unknown type ");
2024 case VIDIOC_DQEVENT
:
2026 struct v4l2_event
*ev
= arg
;
2028 ret
= v4l2_event_dequeue(fh
, ev
, file
->f_flags
& O_NONBLOCK
);
2030 dbgarg(cmd
, "no pending events?");
2034 "pending=%d, type=0x%8.8x, sequence=%d, "
2035 "timestamp=%lu.%9.9lu ",
2036 ev
->pending
, ev
->type
, ev
->sequence
,
2037 ev
->timestamp
.tv_sec
, ev
->timestamp
.tv_nsec
);
2040 case VIDIOC_SUBSCRIBE_EVENT
:
2042 struct v4l2_event_subscription
*sub
= arg
;
2044 ret
= ops
->vidioc_subscribe_event(fh
, sub
);
2046 dbgarg(cmd
, "failed, ret=%ld", ret
);
2049 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
2052 case VIDIOC_UNSUBSCRIBE_EVENT
:
2054 struct v4l2_event_subscription
*sub
= arg
;
2056 ret
= ops
->vidioc_unsubscribe_event(fh
, sub
);
2058 dbgarg(cmd
, "failed, ret=%ld", ret
);
2061 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
2064 case VIDIOC_CREATE_BUFS
:
2066 struct v4l2_create_buffers
*create
= arg
;
2068 ret
= check_fmt(ops
, create
->format
.type
);
2072 ret
= ops
->vidioc_create_bufs(file
, fh
, create
);
2074 dbgarg(cmd
, "count=%d @ %d\n", create
->count
, create
->index
);
2077 case VIDIOC_PREPARE_BUF
:
2079 struct v4l2_buffer
*b
= arg
;
2081 ret
= check_fmt(ops
, b
->type
);
2085 ret
= ops
->vidioc_prepare_buf(file
, fh
, b
);
2087 dbgarg(cmd
, "index=%d", b
->index
);
2091 if (!ops
->vidioc_default
)
2093 ret
= ops
->vidioc_default(file
, fh
, use_fh_prio
?
2094 v4l2_prio_check(vfd
->prio
, vfh
->prio
) >= 0 : 0,
2099 if (vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
) {
2101 v4l_print_ioctl(vfd
->name
, cmd
);
2102 printk(KERN_CONT
" error %ld\n", ret
);
2109 /* In some cases, only a few fields are used as input, i.e. when the app sets
2110 * "index" and then the driver fills in the rest of the structure for the thing
2111 * with that index. We only need to copy up the first non-input field. */
2112 static unsigned long cmd_input_size(unsigned int cmd
)
2114 /* Size of structure up to and including 'field' */
2115 #define CMDINSIZE(cmd, type, field) \
2116 case VIDIOC_##cmd: \
2117 return offsetof(struct v4l2_##type, field) + \
2118 sizeof(((struct v4l2_##type *)0)->field);
2121 CMDINSIZE(ENUM_FMT
, fmtdesc
, type
);
2122 CMDINSIZE(G_FMT
, format
, type
);
2123 CMDINSIZE(QUERYBUF
, buffer
, length
);
2124 CMDINSIZE(G_PARM
, streamparm
, type
);
2125 CMDINSIZE(ENUMSTD
, standard
, index
);
2126 CMDINSIZE(ENUMINPUT
, input
, index
);
2127 CMDINSIZE(G_CTRL
, control
, id
);
2128 CMDINSIZE(G_TUNER
, tuner
, index
);
2129 CMDINSIZE(QUERYCTRL
, queryctrl
, id
);
2130 CMDINSIZE(QUERYMENU
, querymenu
, index
);
2131 CMDINSIZE(ENUMOUTPUT
, output
, index
);
2132 CMDINSIZE(G_MODULATOR
, modulator
, index
);
2133 CMDINSIZE(G_FREQUENCY
, frequency
, tuner
);
2134 CMDINSIZE(CROPCAP
, cropcap
, type
);
2135 CMDINSIZE(G_CROP
, crop
, type
);
2136 CMDINSIZE(ENUMAUDIO
, audio
, index
);
2137 CMDINSIZE(ENUMAUDOUT
, audioout
, index
);
2138 CMDINSIZE(ENCODER_CMD
, encoder_cmd
, flags
);
2139 CMDINSIZE(TRY_ENCODER_CMD
, encoder_cmd
, flags
);
2140 CMDINSIZE(G_SLICED_VBI_CAP
, sliced_vbi_cap
, type
);
2141 CMDINSIZE(ENUM_FRAMESIZES
, frmsizeenum
, pixel_format
);
2142 CMDINSIZE(ENUM_FRAMEINTERVALS
, frmivalenum
, height
);
2144 return _IOC_SIZE(cmd
);
2148 static int check_array_args(unsigned int cmd
, void *parg
, size_t *array_size
,
2149 void * __user
*user_ptr
, void ***kernel_ptr
)
2154 case VIDIOC_QUERYBUF
:
2156 case VIDIOC_DQBUF
: {
2157 struct v4l2_buffer
*buf
= parg
;
2159 if (V4L2_TYPE_IS_MULTIPLANAR(buf
->type
) && buf
->length
> 0) {
2160 if (buf
->length
> VIDEO_MAX_PLANES
) {
2164 *user_ptr
= (void __user
*)buf
->m
.planes
;
2165 *kernel_ptr
= (void *)&buf
->m
.planes
;
2166 *array_size
= sizeof(struct v4l2_plane
) * buf
->length
;
2172 case VIDIOC_S_EXT_CTRLS
:
2173 case VIDIOC_G_EXT_CTRLS
:
2174 case VIDIOC_TRY_EXT_CTRLS
: {
2175 struct v4l2_ext_controls
*ctrls
= parg
;
2177 if (ctrls
->count
!= 0) {
2178 if (ctrls
->count
> V4L2_CID_MAX_CTRLS
) {
2182 *user_ptr
= (void __user
*)ctrls
->controls
;
2183 *kernel_ptr
= (void *)&ctrls
->controls
;
2184 *array_size
= sizeof(struct v4l2_ext_control
)
2196 video_usercopy(struct file
*file
, unsigned int cmd
, unsigned long arg
,
2201 void *parg
= (void *)arg
;
2203 bool has_array_args
;
2204 size_t array_size
= 0;
2205 void __user
*user_ptr
= NULL
;
2206 void **kernel_ptr
= NULL
;
2208 /* Copy arguments into temp kernel buffer */
2209 if (_IOC_DIR(cmd
) != _IOC_NONE
) {
2210 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
2213 /* too big to allocate from stack */
2214 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
2221 if (_IOC_DIR(cmd
) & _IOC_WRITE
) {
2222 unsigned long n
= cmd_input_size(cmd
);
2224 if (copy_from_user(parg
, (void __user
*)arg
, n
))
2227 /* zero out anything we don't copy from userspace */
2228 if (n
< _IOC_SIZE(cmd
))
2229 memset((u8
*)parg
+ n
, 0, _IOC_SIZE(cmd
) - n
);
2231 /* read-only ioctl */
2232 memset(parg
, 0, _IOC_SIZE(cmd
));
2236 err
= check_array_args(cmd
, parg
, &array_size
, &user_ptr
, &kernel_ptr
);
2239 has_array_args
= err
;
2241 if (has_array_args
) {
2243 * When adding new types of array args, make sure that the
2244 * parent argument to ioctl (which contains the pointer to the
2245 * array) fits into sbuf (so that mbuf will still remain
2246 * unused up to here).
2248 mbuf
= kmalloc(array_size
, GFP_KERNEL
);
2251 goto out_array_args
;
2253 if (copy_from_user(mbuf
, user_ptr
, array_size
))
2254 goto out_array_args
;
2259 err
= func(file
, cmd
, parg
);
2260 if (err
== -ENOIOCTLCMD
)
2263 if (has_array_args
) {
2264 *kernel_ptr
= user_ptr
;
2265 if (copy_to_user(user_ptr
, mbuf
, array_size
))
2267 goto out_array_args
;
2269 /* VIDIOC_QUERY_DV_TIMINGS can return an error, but still have valid
2270 results that must be returned. */
2271 if (err
< 0 && cmd
!= VIDIOC_QUERY_DV_TIMINGS
)
2275 /* Copy results into user buffer */
2276 switch (_IOC_DIR(cmd
)) {
2278 case (_IOC_WRITE
| _IOC_READ
):
2279 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
2288 EXPORT_SYMBOL(video_usercopy
);
2290 long video_ioctl2(struct file
*file
,
2291 unsigned int cmd
, unsigned long arg
)
2293 return video_usercopy(file
, cmd
, arg
, __video_do_ioctl
);
2295 EXPORT_SYMBOL(video_ioctl2
);