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))
58 #define have_fmt_ops(foo) ( \
59 ops->vidioc_##foo##_fmt_vid_cap || \
60 ops->vidioc_##foo##_fmt_vid_out || \
61 ops->vidioc_##foo##_fmt_vid_cap_mplane || \
62 ops->vidioc_##foo##_fmt_vid_out_mplane || \
63 ops->vidioc_##foo##_fmt_vid_overlay || \
64 ops->vidioc_##foo##_fmt_vbi_cap || \
65 ops->vidioc_##foo##_fmt_vid_out_overlay || \
66 ops->vidioc_##foo##_fmt_vbi_out || \
67 ops->vidioc_##foo##_fmt_sliced_vbi_cap || \
68 ops->vidioc_##foo##_fmt_sliced_vbi_out || \
69 ops->vidioc_##foo##_fmt_type_private)
76 static const struct std_descr standards
[] = {
77 { V4L2_STD_NTSC
, "NTSC" },
78 { V4L2_STD_NTSC_M
, "NTSC-M" },
79 { V4L2_STD_NTSC_M_JP
, "NTSC-M-JP" },
80 { V4L2_STD_NTSC_M_KR
, "NTSC-M-KR" },
81 { V4L2_STD_NTSC_443
, "NTSC-443" },
82 { V4L2_STD_PAL
, "PAL" },
83 { V4L2_STD_PAL_BG
, "PAL-BG" },
84 { V4L2_STD_PAL_B
, "PAL-B" },
85 { V4L2_STD_PAL_B1
, "PAL-B1" },
86 { V4L2_STD_PAL_G
, "PAL-G" },
87 { V4L2_STD_PAL_H
, "PAL-H" },
88 { V4L2_STD_PAL_I
, "PAL-I" },
89 { V4L2_STD_PAL_DK
, "PAL-DK" },
90 { V4L2_STD_PAL_D
, "PAL-D" },
91 { V4L2_STD_PAL_D1
, "PAL-D1" },
92 { V4L2_STD_PAL_K
, "PAL-K" },
93 { V4L2_STD_PAL_M
, "PAL-M" },
94 { V4L2_STD_PAL_N
, "PAL-N" },
95 { V4L2_STD_PAL_Nc
, "PAL-Nc" },
96 { V4L2_STD_PAL_60
, "PAL-60" },
97 { V4L2_STD_SECAM
, "SECAM" },
98 { V4L2_STD_SECAM_B
, "SECAM-B" },
99 { V4L2_STD_SECAM_G
, "SECAM-G" },
100 { V4L2_STD_SECAM_H
, "SECAM-H" },
101 { V4L2_STD_SECAM_DK
, "SECAM-DK" },
102 { V4L2_STD_SECAM_D
, "SECAM-D" },
103 { V4L2_STD_SECAM_K
, "SECAM-K" },
104 { V4L2_STD_SECAM_K1
, "SECAM-K1" },
105 { V4L2_STD_SECAM_L
, "SECAM-L" },
106 { V4L2_STD_SECAM_LC
, "SECAM-Lc" },
110 /* video4linux standard ID conversion to standard name
112 const char *v4l2_norm_to_name(v4l2_std_id id
)
117 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
118 64 bit comparations. So, on that architecture, with some gcc
119 variants, compilation fails. Currently, the max value is 30bit wide.
123 for (i
= 0; standards
[i
].std
; i
++)
124 if (myid
== standards
[i
].std
)
126 return standards
[i
].descr
;
128 EXPORT_SYMBOL(v4l2_norm_to_name
);
130 /* Returns frame period for the given standard */
131 void v4l2_video_std_frame_period(int id
, struct v4l2_fract
*frameperiod
)
133 if (id
& V4L2_STD_525_60
) {
134 frameperiod
->numerator
= 1001;
135 frameperiod
->denominator
= 30000;
137 frameperiod
->numerator
= 1;
138 frameperiod
->denominator
= 25;
141 EXPORT_SYMBOL(v4l2_video_std_frame_period
);
143 /* Fill in the fields of a v4l2_standard structure according to the
144 'id' and 'transmission' parameters. Returns negative on error. */
145 int v4l2_video_std_construct(struct v4l2_standard
*vs
,
146 int id
, const char *name
)
149 v4l2_video_std_frame_period(id
, &vs
->frameperiod
);
150 vs
->framelines
= (id
& V4L2_STD_525_60
) ? 525 : 625;
151 strlcpy(vs
->name
, name
, sizeof(vs
->name
));
154 EXPORT_SYMBOL(v4l2_video_std_construct
);
156 /* ----------------------------------------------------------------- */
157 /* some arrays for pretty-printing debug messages of enum types */
159 const char *v4l2_field_names
[] = {
160 [V4L2_FIELD_ANY
] = "any",
161 [V4L2_FIELD_NONE
] = "none",
162 [V4L2_FIELD_TOP
] = "top",
163 [V4L2_FIELD_BOTTOM
] = "bottom",
164 [V4L2_FIELD_INTERLACED
] = "interlaced",
165 [V4L2_FIELD_SEQ_TB
] = "seq-tb",
166 [V4L2_FIELD_SEQ_BT
] = "seq-bt",
167 [V4L2_FIELD_ALTERNATE
] = "alternate",
168 [V4L2_FIELD_INTERLACED_TB
] = "interlaced-tb",
169 [V4L2_FIELD_INTERLACED_BT
] = "interlaced-bt",
171 EXPORT_SYMBOL(v4l2_field_names
);
173 const char *v4l2_type_names
[] = {
174 [V4L2_BUF_TYPE_VIDEO_CAPTURE
] = "vid-cap",
175 [V4L2_BUF_TYPE_VIDEO_OVERLAY
] = "vid-overlay",
176 [V4L2_BUF_TYPE_VIDEO_OUTPUT
] = "vid-out",
177 [V4L2_BUF_TYPE_VBI_CAPTURE
] = "vbi-cap",
178 [V4L2_BUF_TYPE_VBI_OUTPUT
] = "vbi-out",
179 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
] = "sliced-vbi-cap",
180 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
] = "sliced-vbi-out",
181 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
] = "vid-out-overlay",
182 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
] = "vid-cap-mplane",
183 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
] = "vid-out-mplane",
185 EXPORT_SYMBOL(v4l2_type_names
);
187 static const char *v4l2_memory_names
[] = {
188 [V4L2_MEMORY_MMAP
] = "mmap",
189 [V4L2_MEMORY_USERPTR
] = "userptr",
190 [V4L2_MEMORY_OVERLAY
] = "overlay",
193 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
196 /* ------------------------------------------------------------------ */
197 /* debug help functions */
198 static const char *v4l2_ioctls
[] = {
199 [_IOC_NR(VIDIOC_QUERYCAP
)] = "VIDIOC_QUERYCAP",
200 [_IOC_NR(VIDIOC_RESERVED
)] = "VIDIOC_RESERVED",
201 [_IOC_NR(VIDIOC_ENUM_FMT
)] = "VIDIOC_ENUM_FMT",
202 [_IOC_NR(VIDIOC_G_FMT
)] = "VIDIOC_G_FMT",
203 [_IOC_NR(VIDIOC_S_FMT
)] = "VIDIOC_S_FMT",
204 [_IOC_NR(VIDIOC_REQBUFS
)] = "VIDIOC_REQBUFS",
205 [_IOC_NR(VIDIOC_QUERYBUF
)] = "VIDIOC_QUERYBUF",
206 [_IOC_NR(VIDIOC_G_FBUF
)] = "VIDIOC_G_FBUF",
207 [_IOC_NR(VIDIOC_S_FBUF
)] = "VIDIOC_S_FBUF",
208 [_IOC_NR(VIDIOC_OVERLAY
)] = "VIDIOC_OVERLAY",
209 [_IOC_NR(VIDIOC_QBUF
)] = "VIDIOC_QBUF",
210 [_IOC_NR(VIDIOC_DQBUF
)] = "VIDIOC_DQBUF",
211 [_IOC_NR(VIDIOC_STREAMON
)] = "VIDIOC_STREAMON",
212 [_IOC_NR(VIDIOC_STREAMOFF
)] = "VIDIOC_STREAMOFF",
213 [_IOC_NR(VIDIOC_G_PARM
)] = "VIDIOC_G_PARM",
214 [_IOC_NR(VIDIOC_S_PARM
)] = "VIDIOC_S_PARM",
215 [_IOC_NR(VIDIOC_G_STD
)] = "VIDIOC_G_STD",
216 [_IOC_NR(VIDIOC_S_STD
)] = "VIDIOC_S_STD",
217 [_IOC_NR(VIDIOC_ENUMSTD
)] = "VIDIOC_ENUMSTD",
218 [_IOC_NR(VIDIOC_ENUMINPUT
)] = "VIDIOC_ENUMINPUT",
219 [_IOC_NR(VIDIOC_G_CTRL
)] = "VIDIOC_G_CTRL",
220 [_IOC_NR(VIDIOC_S_CTRL
)] = "VIDIOC_S_CTRL",
221 [_IOC_NR(VIDIOC_G_TUNER
)] = "VIDIOC_G_TUNER",
222 [_IOC_NR(VIDIOC_S_TUNER
)] = "VIDIOC_S_TUNER",
223 [_IOC_NR(VIDIOC_G_AUDIO
)] = "VIDIOC_G_AUDIO",
224 [_IOC_NR(VIDIOC_S_AUDIO
)] = "VIDIOC_S_AUDIO",
225 [_IOC_NR(VIDIOC_QUERYCTRL
)] = "VIDIOC_QUERYCTRL",
226 [_IOC_NR(VIDIOC_QUERYMENU
)] = "VIDIOC_QUERYMENU",
227 [_IOC_NR(VIDIOC_G_INPUT
)] = "VIDIOC_G_INPUT",
228 [_IOC_NR(VIDIOC_S_INPUT
)] = "VIDIOC_S_INPUT",
229 [_IOC_NR(VIDIOC_G_OUTPUT
)] = "VIDIOC_G_OUTPUT",
230 [_IOC_NR(VIDIOC_S_OUTPUT
)] = "VIDIOC_S_OUTPUT",
231 [_IOC_NR(VIDIOC_ENUMOUTPUT
)] = "VIDIOC_ENUMOUTPUT",
232 [_IOC_NR(VIDIOC_G_AUDOUT
)] = "VIDIOC_G_AUDOUT",
233 [_IOC_NR(VIDIOC_S_AUDOUT
)] = "VIDIOC_S_AUDOUT",
234 [_IOC_NR(VIDIOC_G_MODULATOR
)] = "VIDIOC_G_MODULATOR",
235 [_IOC_NR(VIDIOC_S_MODULATOR
)] = "VIDIOC_S_MODULATOR",
236 [_IOC_NR(VIDIOC_G_FREQUENCY
)] = "VIDIOC_G_FREQUENCY",
237 [_IOC_NR(VIDIOC_S_FREQUENCY
)] = "VIDIOC_S_FREQUENCY",
238 [_IOC_NR(VIDIOC_CROPCAP
)] = "VIDIOC_CROPCAP",
239 [_IOC_NR(VIDIOC_G_CROP
)] = "VIDIOC_G_CROP",
240 [_IOC_NR(VIDIOC_S_CROP
)] = "VIDIOC_S_CROP",
241 [_IOC_NR(VIDIOC_G_SELECTION
)] = "VIDIOC_G_SELECTION",
242 [_IOC_NR(VIDIOC_S_SELECTION
)] = "VIDIOC_S_SELECTION",
243 [_IOC_NR(VIDIOC_G_JPEGCOMP
)] = "VIDIOC_G_JPEGCOMP",
244 [_IOC_NR(VIDIOC_S_JPEGCOMP
)] = "VIDIOC_S_JPEGCOMP",
245 [_IOC_NR(VIDIOC_QUERYSTD
)] = "VIDIOC_QUERYSTD",
246 [_IOC_NR(VIDIOC_TRY_FMT
)] = "VIDIOC_TRY_FMT",
247 [_IOC_NR(VIDIOC_ENUMAUDIO
)] = "VIDIOC_ENUMAUDIO",
248 [_IOC_NR(VIDIOC_ENUMAUDOUT
)] = "VIDIOC_ENUMAUDOUT",
249 [_IOC_NR(VIDIOC_G_PRIORITY
)] = "VIDIOC_G_PRIORITY",
250 [_IOC_NR(VIDIOC_S_PRIORITY
)] = "VIDIOC_S_PRIORITY",
251 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP
)] = "VIDIOC_G_SLICED_VBI_CAP",
252 [_IOC_NR(VIDIOC_LOG_STATUS
)] = "VIDIOC_LOG_STATUS",
253 [_IOC_NR(VIDIOC_G_EXT_CTRLS
)] = "VIDIOC_G_EXT_CTRLS",
254 [_IOC_NR(VIDIOC_S_EXT_CTRLS
)] = "VIDIOC_S_EXT_CTRLS",
255 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS
)] = "VIDIOC_TRY_EXT_CTRLS",
257 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES
)] = "VIDIOC_ENUM_FRAMESIZES",
258 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS
)] = "VIDIOC_ENUM_FRAMEINTERVALS",
259 [_IOC_NR(VIDIOC_G_ENC_INDEX
)] = "VIDIOC_G_ENC_INDEX",
260 [_IOC_NR(VIDIOC_ENCODER_CMD
)] = "VIDIOC_ENCODER_CMD",
261 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD
)] = "VIDIOC_TRY_ENCODER_CMD",
263 [_IOC_NR(VIDIOC_DBG_S_REGISTER
)] = "VIDIOC_DBG_S_REGISTER",
264 [_IOC_NR(VIDIOC_DBG_G_REGISTER
)] = "VIDIOC_DBG_G_REGISTER",
266 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT
)] = "VIDIOC_DBG_G_CHIP_IDENT",
267 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK
)] = "VIDIOC_S_HW_FREQ_SEEK",
269 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS
)] = "VIDIOC_ENUM_DV_PRESETS",
270 [_IOC_NR(VIDIOC_S_DV_PRESET
)] = "VIDIOC_S_DV_PRESET",
271 [_IOC_NR(VIDIOC_G_DV_PRESET
)] = "VIDIOC_G_DV_PRESET",
272 [_IOC_NR(VIDIOC_QUERY_DV_PRESET
)] = "VIDIOC_QUERY_DV_PRESET",
273 [_IOC_NR(VIDIOC_S_DV_TIMINGS
)] = "VIDIOC_S_DV_TIMINGS",
274 [_IOC_NR(VIDIOC_G_DV_TIMINGS
)] = "VIDIOC_G_DV_TIMINGS",
275 [_IOC_NR(VIDIOC_DQEVENT
)] = "VIDIOC_DQEVENT",
276 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT
)] = "VIDIOC_SUBSCRIBE_EVENT",
277 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT
)] = "VIDIOC_UNSUBSCRIBE_EVENT",
278 [_IOC_NR(VIDIOC_CREATE_BUFS
)] = "VIDIOC_CREATE_BUFS",
279 [_IOC_NR(VIDIOC_PREPARE_BUF
)] = "VIDIOC_PREPARE_BUF",
281 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
283 /* Common ioctl debug function. This function can be used by
284 external ioctl messages as well as internal V4L ioctl */
285 void v4l_printk_ioctl(unsigned int cmd
)
289 switch (_IOC_TYPE(cmd
)) {
294 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
) {
298 printk("%s", v4l2_ioctls
[_IOC_NR(cmd
)]);
304 switch (_IOC_DIR(cmd
)) {
305 case _IOC_NONE
: dir
= "--"; break;
306 case _IOC_READ
: dir
= "r-"; break;
307 case _IOC_WRITE
: dir
= "-w"; break;
308 case _IOC_READ
| _IOC_WRITE
: dir
= "rw"; break;
309 default: dir
= "*ERR*"; break;
311 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
312 type
, _IOC_TYPE(cmd
), dir
, _IOC_NR(cmd
), cmd
);
314 EXPORT_SYMBOL(v4l_printk_ioctl
);
316 static void dbgbuf(unsigned int cmd
, struct video_device
*vfd
,
317 struct v4l2_buffer
*p
)
319 struct v4l2_timecode
*tc
= &p
->timecode
;
320 struct v4l2_plane
*plane
;
323 dbgarg(cmd
, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
324 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
325 p
->timestamp
.tv_sec
/ 3600,
326 (int)(p
->timestamp
.tv_sec
/ 60) % 60,
327 (int)(p
->timestamp
.tv_sec
% 60),
328 (long)p
->timestamp
.tv_usec
,
330 prt_names(p
->type
, v4l2_type_names
),
331 p
->flags
, p
->field
, p
->sequence
,
332 prt_names(p
->memory
, v4l2_memory_names
));
334 if (V4L2_TYPE_IS_MULTIPLANAR(p
->type
) && p
->m
.planes
) {
335 for (i
= 0; i
< p
->length
; ++i
) {
336 plane
= &p
->m
.planes
[i
];
337 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
338 "offset/userptr=0x%08lx, length=%d\n",
339 i
, plane
->bytesused
, plane
->data_offset
,
340 plane
->m
.userptr
, plane
->length
);
343 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
344 p
->bytesused
, p
->m
.userptr
, p
->length
);
347 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
348 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
349 tc
->hours
, tc
->minutes
, tc
->seconds
,
350 tc
->type
, tc
->flags
, tc
->frames
, *(__u32
*)tc
->userbits
);
353 static inline void dbgrect(struct video_device
*vfd
, char *s
,
356 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s
, r
->left
, r
->top
,
357 r
->width
, r
->height
);
360 static inline void v4l_print_pix_fmt(struct video_device
*vfd
,
361 struct v4l2_pix_format
*fmt
)
363 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
364 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
365 fmt
->width
, fmt
->height
,
366 (fmt
->pixelformat
& 0xff),
367 (fmt
->pixelformat
>> 8) & 0xff,
368 (fmt
->pixelformat
>> 16) & 0xff,
369 (fmt
->pixelformat
>> 24) & 0xff,
370 prt_names(fmt
->field
, v4l2_field_names
),
371 fmt
->bytesperline
, fmt
->sizeimage
, fmt
->colorspace
);
374 static inline void v4l_print_pix_fmt_mplane(struct video_device
*vfd
,
375 struct v4l2_pix_format_mplane
*fmt
)
379 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
380 "colorspace=%d, num_planes=%d\n",
381 fmt
->width
, fmt
->height
,
382 (fmt
->pixelformat
& 0xff),
383 (fmt
->pixelformat
>> 8) & 0xff,
384 (fmt
->pixelformat
>> 16) & 0xff,
385 (fmt
->pixelformat
>> 24) & 0xff,
386 prt_names(fmt
->field
, v4l2_field_names
),
387 fmt
->colorspace
, fmt
->num_planes
);
389 for (i
= 0; i
< fmt
->num_planes
; ++i
)
390 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i
,
391 fmt
->plane_fmt
[i
].bytesperline
,
392 fmt
->plane_fmt
[i
].sizeimage
);
395 static inline void v4l_print_ext_ctrls(unsigned int cmd
,
396 struct video_device
*vfd
, struct v4l2_ext_controls
*c
, int show_vals
)
400 if (!(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
))
403 printk(KERN_CONT
"class=0x%x", c
->ctrl_class
);
404 for (i
= 0; i
< c
->count
; i
++) {
405 if (show_vals
&& !c
->controls
[i
].size
)
406 printk(KERN_CONT
" id/val=0x%x/0x%x",
407 c
->controls
[i
].id
, c
->controls
[i
].value
);
409 printk(KERN_CONT
" id=0x%x,size=%u",
410 c
->controls
[i
].id
, c
->controls
[i
].size
);
412 printk(KERN_CONT
"\n");
415 static inline int check_ext_ctrls(struct v4l2_ext_controls
*c
, int allow_priv
)
419 /* zero the reserved fields */
420 c
->reserved
[0] = c
->reserved
[1] = 0;
421 for (i
= 0; i
< c
->count
; i
++)
422 c
->controls
[i
].reserved2
[0] = 0;
424 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
425 when using extended controls.
426 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
427 is it allowed for backwards compatibility.
429 if (!allow_priv
&& c
->ctrl_class
== V4L2_CID_PRIVATE_BASE
)
431 /* Check that all controls are from the same control class. */
432 for (i
= 0; i
< c
->count
; i
++) {
433 if (V4L2_CTRL_ID2CLASS(c
->controls
[i
].id
) != c
->ctrl_class
) {
441 static int check_fmt(const struct v4l2_ioctl_ops
*ops
, enum v4l2_buf_type type
)
447 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
448 if (ops
->vidioc_g_fmt_vid_cap
||
449 ops
->vidioc_g_fmt_vid_cap_mplane
)
452 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
453 if (ops
->vidioc_g_fmt_vid_cap_mplane
)
456 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
457 if (ops
->vidioc_g_fmt_vid_overlay
)
460 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
461 if (ops
->vidioc_g_fmt_vid_out
||
462 ops
->vidioc_g_fmt_vid_out_mplane
)
465 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
466 if (ops
->vidioc_g_fmt_vid_out_mplane
)
469 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
470 if (ops
->vidioc_g_fmt_vid_out_overlay
)
473 case V4L2_BUF_TYPE_VBI_CAPTURE
:
474 if (ops
->vidioc_g_fmt_vbi_cap
)
477 case V4L2_BUF_TYPE_VBI_OUTPUT
:
478 if (ops
->vidioc_g_fmt_vbi_out
)
481 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
482 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
485 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
486 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
489 case V4L2_BUF_TYPE_PRIVATE
:
490 if (ops
->vidioc_g_fmt_type_private
)
497 static long __video_do_ioctl(struct file
*file
,
498 unsigned int cmd
, void *arg
)
500 struct video_device
*vfd
= video_devdata(file
);
501 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
502 void *fh
= file
->private_data
;
503 struct v4l2_fh
*vfh
= NULL
;
509 printk(KERN_WARNING
"videodev: \"%s\" has no ioctl_ops.\n",
514 if ((vfd
->debug
& V4L2_DEBUG_IOCTL
) &&
515 !(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
)) {
516 v4l_print_ioctl(vfd
->name
, cmd
);
517 printk(KERN_CONT
"\n");
520 if (test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
)) {
521 vfh
= file
->private_data
;
522 use_fh_prio
= test_bit(V4L2_FL_USE_FH_PRIO
, &vfd
->flags
);
526 ret_prio
= v4l2_prio_check(vfd
->prio
, vfh
->prio
);
530 /* --- capabilities ------------------------------------------ */
531 case VIDIOC_QUERYCAP
:
533 struct v4l2_capability
*cap
= (struct v4l2_capability
*)arg
;
535 if (!ops
->vidioc_querycap
)
538 cap
->version
= LINUX_VERSION_CODE
;
539 ret
= ops
->vidioc_querycap(file
, fh
, cap
);
541 dbgarg(cmd
, "driver=%s, card=%s, bus=%s, "
543 "capabilities=0x%08x\n",
544 cap
->driver
, cap
->card
, cap
->bus_info
,
550 /* --- priority ------------------------------------------ */
551 case VIDIOC_G_PRIORITY
:
553 enum v4l2_priority
*p
= arg
;
555 if (ops
->vidioc_g_priority
) {
556 ret
= ops
->vidioc_g_priority(file
, fh
, p
);
557 } else if (use_fh_prio
) {
558 *p
= v4l2_prio_max(&vfd
->v4l2_dev
->prio
);
562 dbgarg(cmd
, "priority is %d\n", *p
);
565 case VIDIOC_S_PRIORITY
:
567 enum v4l2_priority
*p
= arg
;
569 if (!ops
->vidioc_s_priority
&& !use_fh_prio
)
571 dbgarg(cmd
, "setting priority to %d\n", *p
);
572 if (ops
->vidioc_s_priority
)
573 ret
= ops
->vidioc_s_priority(file
, fh
, *p
);
575 ret
= ret_prio
? ret_prio
:
576 v4l2_prio_change(&vfd
->v4l2_dev
->prio
,
581 /* --- capture ioctls ---------------------------------------- */
582 case VIDIOC_ENUM_FMT
:
584 struct v4l2_fmtdesc
*f
= arg
;
587 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
588 if (likely(ops
->vidioc_enum_fmt_vid_cap
))
589 ret
= ops
->vidioc_enum_fmt_vid_cap(file
, fh
, f
);
591 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
592 if (likely(ops
->vidioc_enum_fmt_vid_cap_mplane
))
593 ret
= ops
->vidioc_enum_fmt_vid_cap_mplane(file
,
596 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
597 if (likely(ops
->vidioc_enum_fmt_vid_overlay
))
598 ret
= ops
->vidioc_enum_fmt_vid_overlay(file
,
601 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
602 if (likely(ops
->vidioc_enum_fmt_vid_out
))
603 ret
= ops
->vidioc_enum_fmt_vid_out(file
, fh
, f
);
605 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
606 if (likely(ops
->vidioc_enum_fmt_vid_out_mplane
))
607 ret
= ops
->vidioc_enum_fmt_vid_out_mplane(file
,
610 case V4L2_BUF_TYPE_PRIVATE
:
611 if (likely(ops
->vidioc_enum_fmt_type_private
))
612 ret
= ops
->vidioc_enum_fmt_type_private(file
,
619 dbgarg(cmd
, "index=%d, type=%d, flags=%d, "
620 "pixelformat=%c%c%c%c, description='%s'\n",
621 f
->index
, f
->type
, f
->flags
,
622 (f
->pixelformat
& 0xff),
623 (f
->pixelformat
>> 8) & 0xff,
624 (f
->pixelformat
>> 16) & 0xff,
625 (f
->pixelformat
>> 24) & 0xff,
627 else if (ret
== -ENOTTY
&&
628 (ops
->vidioc_enum_fmt_vid_cap
||
629 ops
->vidioc_enum_fmt_vid_out
||
630 ops
->vidioc_enum_fmt_vid_cap_mplane
||
631 ops
->vidioc_enum_fmt_vid_out_mplane
||
632 ops
->vidioc_enum_fmt_vid_overlay
||
633 ops
->vidioc_enum_fmt_type_private
))
639 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
641 /* FIXME: Should be one dump per type */
642 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
645 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
646 if (ops
->vidioc_g_fmt_vid_cap
)
647 ret
= ops
->vidioc_g_fmt_vid_cap(file
, fh
, f
);
649 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
651 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
652 if (ops
->vidioc_g_fmt_vid_cap_mplane
)
653 ret
= ops
->vidioc_g_fmt_vid_cap_mplane(file
,
656 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
658 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
659 if (likely(ops
->vidioc_g_fmt_vid_overlay
))
660 ret
= ops
->vidioc_g_fmt_vid_overlay(file
,
663 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
664 if (ops
->vidioc_g_fmt_vid_out
)
665 ret
= ops
->vidioc_g_fmt_vid_out(file
, fh
, f
);
667 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
669 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
670 if (ops
->vidioc_g_fmt_vid_out_mplane
)
671 ret
= ops
->vidioc_g_fmt_vid_out_mplane(file
,
674 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
676 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
677 if (likely(ops
->vidioc_g_fmt_vid_out_overlay
))
678 ret
= ops
->vidioc_g_fmt_vid_out_overlay(file
,
681 case V4L2_BUF_TYPE_VBI_CAPTURE
:
682 if (likely(ops
->vidioc_g_fmt_vbi_cap
))
683 ret
= ops
->vidioc_g_fmt_vbi_cap(file
, fh
, f
);
685 case V4L2_BUF_TYPE_VBI_OUTPUT
:
686 if (likely(ops
->vidioc_g_fmt_vbi_out
))
687 ret
= ops
->vidioc_g_fmt_vbi_out(file
, fh
, f
);
689 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
690 if (likely(ops
->vidioc_g_fmt_sliced_vbi_cap
))
691 ret
= ops
->vidioc_g_fmt_sliced_vbi_cap(file
,
694 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
695 if (likely(ops
->vidioc_g_fmt_sliced_vbi_out
))
696 ret
= ops
->vidioc_g_fmt_sliced_vbi_out(file
,
699 case V4L2_BUF_TYPE_PRIVATE
:
700 if (likely(ops
->vidioc_g_fmt_type_private
))
701 ret
= ops
->vidioc_g_fmt_type_private(file
,
705 if (unlikely(ret
== -ENOTTY
&& have_fmt_ops(g
)))
712 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
714 if (!have_fmt_ops(s
))
722 /* FIXME: Should be one dump per type */
723 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
726 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
727 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
728 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
729 if (ops
->vidioc_s_fmt_vid_cap
)
730 ret
= ops
->vidioc_s_fmt_vid_cap(file
, fh
, f
);
732 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
733 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
734 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
735 if (ops
->vidioc_s_fmt_vid_cap_mplane
)
736 ret
= ops
->vidioc_s_fmt_vid_cap_mplane(file
,
739 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
740 CLEAR_AFTER_FIELD(f
, fmt
.win
);
741 if (ops
->vidioc_s_fmt_vid_overlay
)
742 ret
= ops
->vidioc_s_fmt_vid_overlay(file
,
745 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
746 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
747 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
748 if (ops
->vidioc_s_fmt_vid_out
)
749 ret
= ops
->vidioc_s_fmt_vid_out(file
, fh
, f
);
751 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
752 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
753 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
754 if (ops
->vidioc_s_fmt_vid_out_mplane
)
755 ret
= ops
->vidioc_s_fmt_vid_out_mplane(file
,
758 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
759 CLEAR_AFTER_FIELD(f
, fmt
.win
);
760 if (ops
->vidioc_s_fmt_vid_out_overlay
)
761 ret
= ops
->vidioc_s_fmt_vid_out_overlay(file
,
764 case V4L2_BUF_TYPE_VBI_CAPTURE
:
765 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
766 if (likely(ops
->vidioc_s_fmt_vbi_cap
))
767 ret
= ops
->vidioc_s_fmt_vbi_cap(file
, fh
, f
);
769 case V4L2_BUF_TYPE_VBI_OUTPUT
:
770 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
771 if (likely(ops
->vidioc_s_fmt_vbi_out
))
772 ret
= ops
->vidioc_s_fmt_vbi_out(file
, fh
, f
);
774 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
775 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
776 if (likely(ops
->vidioc_s_fmt_sliced_vbi_cap
))
777 ret
= ops
->vidioc_s_fmt_sliced_vbi_cap(file
,
780 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
781 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
782 if (likely(ops
->vidioc_s_fmt_sliced_vbi_out
))
783 ret
= ops
->vidioc_s_fmt_sliced_vbi_out(file
,
787 case V4L2_BUF_TYPE_PRIVATE
:
788 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
789 if (likely(ops
->vidioc_s_fmt_type_private
))
790 ret
= ops
->vidioc_s_fmt_type_private(file
,
798 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
800 /* FIXME: Should be one dump per type */
801 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
,
804 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
805 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
806 if (ops
->vidioc_try_fmt_vid_cap
)
807 ret
= ops
->vidioc_try_fmt_vid_cap(file
, fh
, f
);
809 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
811 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
812 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
813 if (ops
->vidioc_try_fmt_vid_cap_mplane
)
814 ret
= ops
->vidioc_try_fmt_vid_cap_mplane(file
,
817 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
819 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
820 CLEAR_AFTER_FIELD(f
, fmt
.win
);
821 if (likely(ops
->vidioc_try_fmt_vid_overlay
))
822 ret
= ops
->vidioc_try_fmt_vid_overlay(file
,
825 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
826 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
827 if (ops
->vidioc_try_fmt_vid_out
)
828 ret
= ops
->vidioc_try_fmt_vid_out(file
, fh
, f
);
830 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
832 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
833 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
834 if (ops
->vidioc_try_fmt_vid_out_mplane
)
835 ret
= ops
->vidioc_try_fmt_vid_out_mplane(file
,
838 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
840 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
841 CLEAR_AFTER_FIELD(f
, fmt
.win
);
842 if (likely(ops
->vidioc_try_fmt_vid_out_overlay
))
843 ret
= ops
->vidioc_try_fmt_vid_out_overlay(file
,
846 case V4L2_BUF_TYPE_VBI_CAPTURE
:
847 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
848 if (likely(ops
->vidioc_try_fmt_vbi_cap
))
849 ret
= ops
->vidioc_try_fmt_vbi_cap(file
, fh
, f
);
851 case V4L2_BUF_TYPE_VBI_OUTPUT
:
852 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
853 if (likely(ops
->vidioc_try_fmt_vbi_out
))
854 ret
= ops
->vidioc_try_fmt_vbi_out(file
, fh
, f
);
856 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
857 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
858 if (likely(ops
->vidioc_try_fmt_sliced_vbi_cap
))
859 ret
= ops
->vidioc_try_fmt_sliced_vbi_cap(file
,
862 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
863 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
864 if (likely(ops
->vidioc_try_fmt_sliced_vbi_out
))
865 ret
= ops
->vidioc_try_fmt_sliced_vbi_out(file
,
868 case V4L2_BUF_TYPE_PRIVATE
:
869 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
870 if (likely(ops
->vidioc_try_fmt_type_private
))
871 ret
= ops
->vidioc_try_fmt_type_private(file
,
875 if (unlikely(ret
== -ENOTTY
&& have_fmt_ops(try)))
879 /* FIXME: Those buf reqs could be handled here,
880 with some changes on videobuf to allow its header to be included at
881 videodev2.h or being merged at videodev2.
885 struct v4l2_requestbuffers
*p
= arg
;
887 if (!ops
->vidioc_reqbufs
)
893 ret
= check_fmt(ops
, p
->type
);
897 if (p
->type
< V4L2_BUF_TYPE_PRIVATE
)
898 CLEAR_AFTER_FIELD(p
, memory
);
900 ret
= ops
->vidioc_reqbufs(file
, fh
, p
);
901 dbgarg(cmd
, "count=%d, type=%s, memory=%s\n",
903 prt_names(p
->type
, v4l2_type_names
),
904 prt_names(p
->memory
, v4l2_memory_names
));
907 case VIDIOC_QUERYBUF
:
909 struct v4l2_buffer
*p
= arg
;
911 if (!ops
->vidioc_querybuf
)
913 ret
= check_fmt(ops
, p
->type
);
917 ret
= ops
->vidioc_querybuf(file
, fh
, p
);
924 struct v4l2_buffer
*p
= arg
;
926 if (!ops
->vidioc_qbuf
)
928 ret
= check_fmt(ops
, p
->type
);
932 ret
= ops
->vidioc_qbuf(file
, fh
, p
);
939 struct v4l2_buffer
*p
= arg
;
941 if (!ops
->vidioc_dqbuf
)
943 ret
= check_fmt(ops
, p
->type
);
947 ret
= ops
->vidioc_dqbuf(file
, fh
, p
);
956 if (!ops
->vidioc_overlay
)
962 dbgarg(cmd
, "value=%d\n", *i
);
963 ret
= ops
->vidioc_overlay(file
, fh
, *i
);
968 struct v4l2_framebuffer
*p
= arg
;
970 if (!ops
->vidioc_g_fbuf
)
972 ret
= ops
->vidioc_g_fbuf(file
, fh
, arg
);
974 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
975 p
->capability
, p
->flags
,
976 (unsigned long)p
->base
);
977 v4l_print_pix_fmt(vfd
, &p
->fmt
);
983 struct v4l2_framebuffer
*p
= arg
;
985 if (!ops
->vidioc_s_fbuf
)
991 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
992 p
->capability
, p
->flags
, (unsigned long)p
->base
);
993 v4l_print_pix_fmt(vfd
, &p
->fmt
);
994 ret
= ops
->vidioc_s_fbuf(file
, fh
, arg
);
997 case VIDIOC_STREAMON
:
999 enum v4l2_buf_type i
= *(int *)arg
;
1001 if (!ops
->vidioc_streamon
)
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 if (!ops
->vidioc_streamoff
)
1021 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1022 ret
= ops
->vidioc_streamoff(file
, fh
, i
);
1025 /* ---------- tv norms ---------- */
1026 case VIDIOC_ENUMSTD
:
1028 struct v4l2_standard
*p
= arg
;
1029 v4l2_std_id id
= vfd
->tvnorms
, curr_id
= 0;
1030 unsigned int index
= p
->index
, i
, j
= 0;
1031 const char *descr
= "";
1037 /* Return norm array in a canonical way */
1038 for (i
= 0; i
<= index
&& id
; i
++) {
1039 /* last std value in the standards array is 0, so this
1040 while always ends there since (id & 0) == 0. */
1041 while ((id
& standards
[j
].std
) != standards
[j
].std
)
1043 curr_id
= standards
[j
].std
;
1044 descr
= standards
[j
].descr
;
1048 if (curr_id
!= V4L2_STD_PAL
&&
1049 curr_id
!= V4L2_STD_SECAM
&&
1050 curr_id
!= V4L2_STD_NTSC
)
1056 v4l2_video_std_construct(p
, curr_id
, descr
);
1058 dbgarg(cmd
, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1059 "framelines=%d\n", p
->index
,
1060 (unsigned long long)p
->id
, p
->name
,
1061 p
->frameperiod
.numerator
,
1062 p
->frameperiod
.denominator
,
1070 v4l2_std_id
*id
= arg
;
1072 /* Calls the specific handler */
1073 if (ops
->vidioc_g_std
)
1074 ret
= ops
->vidioc_g_std(file
, fh
, id
);
1075 else if (vfd
->current_norm
) {
1077 *id
= vfd
->current_norm
;
1081 dbgarg(cmd
, "std=0x%08Lx\n", (long long unsigned)*id
);
1086 v4l2_std_id
*id
= arg
, norm
;
1088 dbgarg(cmd
, "std=%08Lx\n", (long long unsigned)*id
);
1090 if (!ops
->vidioc_s_std
)
1098 norm
= (*id
) & vfd
->tvnorms
;
1099 if (vfd
->tvnorms
&& !norm
) /* Check if std is supported */
1102 /* Calls the specific handler */
1103 ret
= ops
->vidioc_s_std(file
, fh
, &norm
);
1105 /* Updates standard information */
1107 vfd
->current_norm
= norm
;
1110 case VIDIOC_QUERYSTD
:
1112 v4l2_std_id
*p
= arg
;
1114 if (!ops
->vidioc_querystd
)
1117 * If nothing detected, it should return all supported
1118 * Drivers just need to mask the std argument, in order
1119 * to remove the standards that don't apply from the mask.
1120 * This means that tuners, audio and video decoders can join
1121 * their efforts to improve the standards detection
1124 ret
= ops
->vidioc_querystd(file
, fh
, arg
);
1126 dbgarg(cmd
, "detected std=%08Lx\n",
1127 (unsigned long long)*p
);
1130 /* ------ input switching ---------- */
1131 /* FIXME: Inputs can be handled inside videodev2 */
1132 case VIDIOC_ENUMINPUT
:
1134 struct v4l2_input
*p
= arg
;
1137 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1138 * CAP_STD here based on ioctl handler provided by the
1139 * driver. If the driver doesn't support these
1140 * for a specific input, it must override these flags.
1142 if (ops
->vidioc_s_std
)
1143 p
->capabilities
|= V4L2_IN_CAP_STD
;
1144 if (ops
->vidioc_s_dv_preset
)
1145 p
->capabilities
|= V4L2_IN_CAP_PRESETS
;
1146 if (ops
->vidioc_s_dv_timings
)
1147 p
->capabilities
|= V4L2_IN_CAP_CUSTOM_TIMINGS
;
1149 if (!ops
->vidioc_enum_input
)
1152 ret
= ops
->vidioc_enum_input(file
, fh
, p
);
1154 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1156 "tuner=%d, std=%08Lx, status=%d\n",
1157 p
->index
, p
->name
, p
->type
, p
->audioset
,
1159 (unsigned long long)p
->std
,
1163 case VIDIOC_G_INPUT
:
1165 unsigned int *i
= arg
;
1167 if (!ops
->vidioc_g_input
)
1169 ret
= ops
->vidioc_g_input(file
, fh
, i
);
1171 dbgarg(cmd
, "value=%d\n", *i
);
1174 case VIDIOC_S_INPUT
:
1176 unsigned int *i
= arg
;
1178 if (!ops
->vidioc_s_input
)
1184 dbgarg(cmd
, "value=%d\n", *i
);
1185 ret
= ops
->vidioc_s_input(file
, fh
, *i
);
1189 /* ------ output switching ---------- */
1190 case VIDIOC_ENUMOUTPUT
:
1192 struct v4l2_output
*p
= arg
;
1194 if (!ops
->vidioc_enum_output
)
1198 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1199 * CAP_STD here based on ioctl handler provided by the
1200 * driver. If the driver doesn't support these
1201 * for a specific output, it must override these flags.
1203 if (ops
->vidioc_s_std
)
1204 p
->capabilities
|= V4L2_OUT_CAP_STD
;
1205 if (ops
->vidioc_s_dv_preset
)
1206 p
->capabilities
|= V4L2_OUT_CAP_PRESETS
;
1207 if (ops
->vidioc_s_dv_timings
)
1208 p
->capabilities
|= V4L2_OUT_CAP_CUSTOM_TIMINGS
;
1210 ret
= ops
->vidioc_enum_output(file
, fh
, p
);
1212 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1214 "modulator=%d, std=0x%08Lx\n",
1215 p
->index
, p
->name
, p
->type
, p
->audioset
,
1216 p
->modulator
, (unsigned long long)p
->std
);
1219 case VIDIOC_G_OUTPUT
:
1221 unsigned int *i
= arg
;
1223 if (!ops
->vidioc_g_output
)
1225 ret
= ops
->vidioc_g_output(file
, fh
, i
);
1227 dbgarg(cmd
, "value=%d\n", *i
);
1230 case VIDIOC_S_OUTPUT
:
1232 unsigned int *i
= arg
;
1234 if (!ops
->vidioc_s_output
)
1240 dbgarg(cmd
, "value=%d\n", *i
);
1241 ret
= ops
->vidioc_s_output(file
, fh
, *i
);
1245 /* --- controls ---------------------------------------------- */
1246 case VIDIOC_QUERYCTRL
:
1248 struct v4l2_queryctrl
*p
= arg
;
1250 if (vfh
&& vfh
->ctrl_handler
)
1251 ret
= v4l2_queryctrl(vfh
->ctrl_handler
, p
);
1252 else if (vfd
->ctrl_handler
)
1253 ret
= v4l2_queryctrl(vfd
->ctrl_handler
, p
);
1254 else if (ops
->vidioc_queryctrl
)
1255 ret
= ops
->vidioc_queryctrl(file
, fh
, p
);
1259 dbgarg(cmd
, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1260 "step=%d, default=%d, flags=0x%08x\n",
1261 p
->id
, p
->type
, p
->name
,
1262 p
->minimum
, p
->maximum
,
1263 p
->step
, p
->default_value
, p
->flags
);
1265 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1270 struct v4l2_control
*p
= arg
;
1272 if (vfh
&& vfh
->ctrl_handler
)
1273 ret
= v4l2_g_ctrl(vfh
->ctrl_handler
, p
);
1274 else if (vfd
->ctrl_handler
)
1275 ret
= v4l2_g_ctrl(vfd
->ctrl_handler
, p
);
1276 else if (ops
->vidioc_g_ctrl
)
1277 ret
= ops
->vidioc_g_ctrl(file
, fh
, p
);
1278 else if (ops
->vidioc_g_ext_ctrls
) {
1279 struct v4l2_ext_controls ctrls
;
1280 struct v4l2_ext_control ctrl
;
1282 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1284 ctrls
.controls
= &ctrl
;
1286 ctrl
.value
= p
->value
;
1287 if (check_ext_ctrls(&ctrls
, 1)) {
1288 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, &ctrls
);
1290 p
->value
= ctrl
.value
;
1295 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1297 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1302 struct v4l2_control
*p
= arg
;
1303 struct v4l2_ext_controls ctrls
;
1304 struct v4l2_ext_control ctrl
;
1306 if (!(vfh
&& vfh
->ctrl_handler
) && !vfd
->ctrl_handler
&&
1307 !ops
->vidioc_s_ctrl
&& !ops
->vidioc_s_ext_ctrls
)
1314 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1316 if (vfh
&& vfh
->ctrl_handler
) {
1317 ret
= v4l2_s_ctrl(vfh
, vfh
->ctrl_handler
, p
);
1320 if (vfd
->ctrl_handler
) {
1321 ret
= v4l2_s_ctrl(NULL
, vfd
->ctrl_handler
, p
);
1324 if (ops
->vidioc_s_ctrl
) {
1325 ret
= ops
->vidioc_s_ctrl(file
, fh
, p
);
1328 if (!ops
->vidioc_s_ext_ctrls
)
1331 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1333 ctrls
.controls
= &ctrl
;
1335 ctrl
.value
= p
->value
;
1336 if (check_ext_ctrls(&ctrls
, 1))
1337 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, &ctrls
);
1342 case VIDIOC_G_EXT_CTRLS
:
1344 struct v4l2_ext_controls
*p
= arg
;
1346 p
->error_idx
= p
->count
;
1347 if (vfh
&& vfh
->ctrl_handler
)
1348 ret
= v4l2_g_ext_ctrls(vfh
->ctrl_handler
, p
);
1349 else if (vfd
->ctrl_handler
)
1350 ret
= v4l2_g_ext_ctrls(vfd
->ctrl_handler
, p
);
1351 else if (ops
->vidioc_g_ext_ctrls
)
1352 ret
= check_ext_ctrls(p
, 0) ?
1353 ops
->vidioc_g_ext_ctrls(file
, fh
, p
) :
1357 v4l_print_ext_ctrls(cmd
, vfd
, p
, !ret
);
1360 case VIDIOC_S_EXT_CTRLS
:
1362 struct v4l2_ext_controls
*p
= arg
;
1364 p
->error_idx
= p
->count
;
1365 if (!(vfh
&& vfh
->ctrl_handler
) && !vfd
->ctrl_handler
&&
1366 !ops
->vidioc_s_ext_ctrls
)
1372 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1373 if (vfh
&& vfh
->ctrl_handler
)
1374 ret
= v4l2_s_ext_ctrls(vfh
, vfh
->ctrl_handler
, p
);
1375 else if (vfd
->ctrl_handler
)
1376 ret
= v4l2_s_ext_ctrls(NULL
, vfd
->ctrl_handler
, p
);
1377 else if (check_ext_ctrls(p
, 0))
1378 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, p
);
1383 case VIDIOC_TRY_EXT_CTRLS
:
1385 struct v4l2_ext_controls
*p
= arg
;
1387 p
->error_idx
= p
->count
;
1388 if (!(vfh
&& vfh
->ctrl_handler
) && !vfd
->ctrl_handler
&&
1389 !ops
->vidioc_try_ext_ctrls
)
1391 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1392 if (vfh
&& vfh
->ctrl_handler
)
1393 ret
= v4l2_try_ext_ctrls(vfh
->ctrl_handler
, p
);
1394 else if (vfd
->ctrl_handler
)
1395 ret
= v4l2_try_ext_ctrls(vfd
->ctrl_handler
, p
);
1396 else if (check_ext_ctrls(p
, 0))
1397 ret
= ops
->vidioc_try_ext_ctrls(file
, fh
, p
);
1402 case VIDIOC_QUERYMENU
:
1404 struct v4l2_querymenu
*p
= arg
;
1406 if (vfh
&& vfh
->ctrl_handler
)
1407 ret
= v4l2_querymenu(vfh
->ctrl_handler
, p
);
1408 else if (vfd
->ctrl_handler
)
1409 ret
= v4l2_querymenu(vfd
->ctrl_handler
, p
);
1410 else if (ops
->vidioc_querymenu
)
1411 ret
= ops
->vidioc_querymenu(file
, fh
, p
);
1415 dbgarg(cmd
, "id=0x%x, index=%d, name=%s\n",
1416 p
->id
, p
->index
, p
->name
);
1418 dbgarg(cmd
, "id=0x%x, index=%d\n",
1422 /* --- audio ---------------------------------------------- */
1423 case VIDIOC_ENUMAUDIO
:
1425 struct v4l2_audio
*p
= arg
;
1427 if (!ops
->vidioc_enumaudio
)
1429 ret
= ops
->vidioc_enumaudio(file
, fh
, p
);
1431 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1432 "mode=0x%x\n", p
->index
, p
->name
,
1433 p
->capability
, p
->mode
);
1435 dbgarg(cmd
, "index=%d\n", p
->index
);
1438 case VIDIOC_G_AUDIO
:
1440 struct v4l2_audio
*p
= arg
;
1442 if (!ops
->vidioc_g_audio
)
1445 ret
= ops
->vidioc_g_audio(file
, fh
, p
);
1447 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1448 "mode=0x%x\n", p
->index
,
1449 p
->name
, p
->capability
, p
->mode
);
1451 dbgarg(cmd
, "index=%d\n", p
->index
);
1454 case VIDIOC_S_AUDIO
:
1456 struct v4l2_audio
*p
= arg
;
1458 if (!ops
->vidioc_s_audio
)
1464 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1465 "mode=0x%x\n", p
->index
, p
->name
,
1466 p
->capability
, p
->mode
);
1467 ret
= ops
->vidioc_s_audio(file
, fh
, p
);
1470 case VIDIOC_ENUMAUDOUT
:
1472 struct v4l2_audioout
*p
= arg
;
1474 if (!ops
->vidioc_enumaudout
)
1476 dbgarg(cmd
, "Enum for index=%d\n", p
->index
);
1477 ret
= ops
->vidioc_enumaudout(file
, fh
, p
);
1479 dbgarg2("index=%d, name=%s, capability=%d, "
1480 "mode=%d\n", p
->index
, p
->name
,
1481 p
->capability
, p
->mode
);
1484 case VIDIOC_G_AUDOUT
:
1486 struct v4l2_audioout
*p
= arg
;
1488 if (!ops
->vidioc_g_audout
)
1491 ret
= ops
->vidioc_g_audout(file
, fh
, p
);
1493 dbgarg2("index=%d, name=%s, capability=%d, "
1494 "mode=%d\n", p
->index
, p
->name
,
1495 p
->capability
, p
->mode
);
1498 case VIDIOC_S_AUDOUT
:
1500 struct v4l2_audioout
*p
= arg
;
1502 if (!ops
->vidioc_s_audout
)
1508 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1509 "mode=%d\n", p
->index
, p
->name
,
1510 p
->capability
, p
->mode
);
1512 ret
= ops
->vidioc_s_audout(file
, fh
, p
);
1515 case VIDIOC_G_MODULATOR
:
1517 struct v4l2_modulator
*p
= arg
;
1519 if (!ops
->vidioc_g_modulator
)
1521 ret
= ops
->vidioc_g_modulator(file
, fh
, p
);
1523 dbgarg(cmd
, "index=%d, name=%s, "
1524 "capability=%d, rangelow=%d,"
1525 " rangehigh=%d, txsubchans=%d\n",
1526 p
->index
, p
->name
, p
->capability
,
1527 p
->rangelow
, p
->rangehigh
,
1531 case VIDIOC_S_MODULATOR
:
1533 struct v4l2_modulator
*p
= arg
;
1535 if (!ops
->vidioc_s_modulator
)
1541 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1542 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1543 p
->index
, p
->name
, p
->capability
, p
->rangelow
,
1544 p
->rangehigh
, p
->txsubchans
);
1545 ret
= ops
->vidioc_s_modulator(file
, fh
, p
);
1550 struct v4l2_crop
*p
= arg
;
1552 if (!ops
->vidioc_g_crop
&& !ops
->vidioc_g_selection
)
1555 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1557 if (ops
->vidioc_g_crop
) {
1558 ret
= ops
->vidioc_g_crop(file
, fh
, p
);
1560 /* simulate capture crop using selection api */
1561 struct v4l2_selection s
= {
1565 /* crop means compose for output devices */
1566 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
1567 s
.target
= V4L2_SEL_TGT_COMPOSE_ACTIVE
;
1569 s
.target
= V4L2_SEL_TGT_CROP_ACTIVE
;
1571 ret
= ops
->vidioc_g_selection(file
, fh
, &s
);
1573 /* copying results to old structure on success */
1579 dbgrect(vfd
, "", &p
->c
);
1584 struct v4l2_crop
*p
= arg
;
1586 if (!ops
->vidioc_s_crop
&& !ops
->vidioc_s_selection
)
1593 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1594 dbgrect(vfd
, "", &p
->c
);
1596 if (ops
->vidioc_s_crop
) {
1597 ret
= ops
->vidioc_s_crop(file
, fh
, p
);
1599 /* simulate capture crop using selection api */
1600 struct v4l2_selection s
= {
1605 /* crop means compose for output devices */
1606 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
1607 s
.target
= V4L2_SEL_TGT_COMPOSE_ACTIVE
;
1609 s
.target
= V4L2_SEL_TGT_CROP_ACTIVE
;
1611 ret
= ops
->vidioc_s_selection(file
, fh
, &s
);
1615 case VIDIOC_G_SELECTION
:
1617 struct v4l2_selection
*p
= arg
;
1619 if (!ops
->vidioc_g_selection
)
1622 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1624 ret
= ops
->vidioc_g_selection(file
, fh
, p
);
1626 dbgrect(vfd
, "", &p
->r
);
1629 case VIDIOC_S_SELECTION
:
1631 struct v4l2_selection
*p
= arg
;
1633 if (!ops
->vidioc_s_selection
)
1641 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1642 dbgrect(vfd
, "", &p
->r
);
1644 ret
= ops
->vidioc_s_selection(file
, fh
, p
);
1647 case VIDIOC_CROPCAP
:
1649 struct v4l2_cropcap
*p
= arg
;
1651 /*FIXME: Should also show v4l2_fract pixelaspect */
1652 if (!ops
->vidioc_cropcap
&& !ops
->vidioc_g_selection
)
1655 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1656 if (ops
->vidioc_cropcap
) {
1657 ret
= ops
->vidioc_cropcap(file
, fh
, p
);
1659 struct v4l2_selection s
= { .type
= p
->type
};
1661 /* obtaining bounds */
1662 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
1663 s
.target
= V4L2_SEL_TGT_COMPOSE_BOUNDS
;
1665 s
.target
= V4L2_SEL_TGT_CROP_BOUNDS
;
1667 ret
= ops
->vidioc_g_selection(file
, fh
, &s
);
1672 /* obtaining defrect */
1673 if (V4L2_TYPE_IS_OUTPUT(p
->type
))
1674 s
.target
= V4L2_SEL_TGT_COMPOSE_DEFAULT
;
1676 s
.target
= V4L2_SEL_TGT_CROP_DEFAULT
;
1678 ret
= ops
->vidioc_g_selection(file
, fh
, &s
);
1683 /* setting trivial pixelaspect */
1684 p
->pixelaspect
.numerator
= 1;
1685 p
->pixelaspect
.denominator
= 1;
1689 dbgrect(vfd
, "bounds ", &p
->bounds
);
1690 dbgrect(vfd
, "defrect ", &p
->defrect
);
1694 case VIDIOC_G_JPEGCOMP
:
1696 struct v4l2_jpegcompression
*p
= arg
;
1698 if (!ops
->vidioc_g_jpegcomp
)
1701 ret
= ops
->vidioc_g_jpegcomp(file
, fh
, p
);
1703 dbgarg(cmd
, "quality=%d, APPn=%d, "
1704 "APP_len=%d, COM_len=%d, "
1705 "jpeg_markers=%d\n",
1706 p
->quality
, p
->APPn
, p
->APP_len
,
1707 p
->COM_len
, p
->jpeg_markers
);
1710 case VIDIOC_S_JPEGCOMP
:
1712 struct v4l2_jpegcompression
*p
= arg
;
1714 if (!ops
->vidioc_g_jpegcomp
)
1720 dbgarg(cmd
, "quality=%d, APPn=%d, APP_len=%d, "
1721 "COM_len=%d, jpeg_markers=%d\n",
1722 p
->quality
, p
->APPn
, p
->APP_len
,
1723 p
->COM_len
, p
->jpeg_markers
);
1724 ret
= ops
->vidioc_s_jpegcomp(file
, fh
, p
);
1727 case VIDIOC_G_ENC_INDEX
:
1729 struct v4l2_enc_idx
*p
= arg
;
1731 if (!ops
->vidioc_g_enc_index
)
1733 ret
= ops
->vidioc_g_enc_index(file
, fh
, p
);
1735 dbgarg(cmd
, "entries=%d, entries_cap=%d\n",
1736 p
->entries
, p
->entries_cap
);
1739 case VIDIOC_ENCODER_CMD
:
1741 struct v4l2_encoder_cmd
*p
= arg
;
1743 if (!ops
->vidioc_encoder_cmd
)
1749 ret
= ops
->vidioc_encoder_cmd(file
, fh
, p
);
1751 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1754 case VIDIOC_TRY_ENCODER_CMD
:
1756 struct v4l2_encoder_cmd
*p
= arg
;
1758 if (!ops
->vidioc_try_encoder_cmd
)
1760 ret
= ops
->vidioc_try_encoder_cmd(file
, fh
, p
);
1762 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1767 struct v4l2_streamparm
*p
= arg
;
1769 if (!ops
->vidioc_g_parm
&& !vfd
->current_norm
)
1771 if (ops
->vidioc_g_parm
) {
1772 ret
= check_fmt(ops
, p
->type
);
1775 ret
= ops
->vidioc_g_parm(file
, fh
, p
);
1777 v4l2_std_id std
= vfd
->current_norm
;
1780 if (p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1784 if (ops
->vidioc_g_std
)
1785 ret
= ops
->vidioc_g_std(file
, fh
, &std
);
1787 v4l2_video_std_frame_period(std
,
1788 &p
->parm
.capture
.timeperframe
);
1791 dbgarg(cmd
, "type=%d\n", p
->type
);
1796 struct v4l2_streamparm
*p
= arg
;
1798 if (!ops
->vidioc_s_parm
)
1804 ret
= check_fmt(ops
, p
->type
);
1808 dbgarg(cmd
, "type=%d\n", p
->type
);
1809 ret
= ops
->vidioc_s_parm(file
, fh
, p
);
1812 case VIDIOC_G_TUNER
:
1814 struct v4l2_tuner
*p
= arg
;
1816 if (!ops
->vidioc_g_tuner
)
1819 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1820 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1821 ret
= ops
->vidioc_g_tuner(file
, fh
, p
);
1823 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1824 "capability=0x%x, rangelow=%d, "
1825 "rangehigh=%d, signal=%d, afc=%d, "
1826 "rxsubchans=0x%x, audmode=%d\n",
1827 p
->index
, p
->name
, p
->type
,
1828 p
->capability
, p
->rangelow
,
1829 p
->rangehigh
, p
->signal
, p
->afc
,
1830 p
->rxsubchans
, p
->audmode
);
1833 case VIDIOC_S_TUNER
:
1835 struct v4l2_tuner
*p
= arg
;
1837 if (!ops
->vidioc_s_tuner
)
1843 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1844 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1845 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1846 "capability=0x%x, rangelow=%d, "
1847 "rangehigh=%d, signal=%d, afc=%d, "
1848 "rxsubchans=0x%x, audmode=%d\n",
1849 p
->index
, p
->name
, p
->type
,
1850 p
->capability
, p
->rangelow
,
1851 p
->rangehigh
, p
->signal
, p
->afc
,
1852 p
->rxsubchans
, p
->audmode
);
1853 ret
= ops
->vidioc_s_tuner(file
, fh
, p
);
1856 case VIDIOC_G_FREQUENCY
:
1858 struct v4l2_frequency
*p
= arg
;
1860 if (!ops
->vidioc_g_frequency
)
1863 p
->type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1864 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1865 ret
= ops
->vidioc_g_frequency(file
, fh
, p
);
1867 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1868 p
->tuner
, p
->type
, p
->frequency
);
1871 case VIDIOC_S_FREQUENCY
:
1873 struct v4l2_frequency
*p
= arg
;
1874 enum v4l2_tuner_type type
;
1876 if (!ops
->vidioc_s_frequency
)
1882 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1883 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1884 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1885 p
->tuner
, p
->type
, p
->frequency
);
1886 if (p
->type
!= type
)
1889 ret
= ops
->vidioc_s_frequency(file
, fh
, p
);
1892 case VIDIOC_G_SLICED_VBI_CAP
:
1894 struct v4l2_sliced_vbi_cap
*p
= arg
;
1896 if (!ops
->vidioc_g_sliced_vbi_cap
)
1899 /* Clear up to type, everything after type is zerod already */
1900 memset(p
, 0, offsetof(struct v4l2_sliced_vbi_cap
, type
));
1902 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1903 ret
= ops
->vidioc_g_sliced_vbi_cap(file
, fh
, p
);
1905 dbgarg2("service_set=%d\n", p
->service_set
);
1908 case VIDIOC_LOG_STATUS
:
1910 if (!ops
->vidioc_log_status
)
1912 ret
= ops
->vidioc_log_status(file
, fh
);
1915 #ifdef CONFIG_VIDEO_ADV_DEBUG
1916 case VIDIOC_DBG_G_REGISTER
:
1918 struct v4l2_dbg_register
*p
= arg
;
1920 if (ops
->vidioc_g_register
) {
1921 if (!capable(CAP_SYS_ADMIN
))
1924 ret
= ops
->vidioc_g_register(file
, fh
, p
);
1928 case VIDIOC_DBG_S_REGISTER
:
1930 struct v4l2_dbg_register
*p
= arg
;
1932 if (ops
->vidioc_s_register
) {
1933 if (!capable(CAP_SYS_ADMIN
))
1936 ret
= ops
->vidioc_s_register(file
, fh
, p
);
1941 case VIDIOC_DBG_G_CHIP_IDENT
:
1943 struct v4l2_dbg_chip_ident
*p
= arg
;
1945 if (!ops
->vidioc_g_chip_ident
)
1947 p
->ident
= V4L2_IDENT_NONE
;
1949 ret
= ops
->vidioc_g_chip_ident(file
, fh
, p
);
1951 dbgarg(cmd
, "chip_ident=%u, revision=0x%x\n", p
->ident
, p
->revision
);
1954 case VIDIOC_S_HW_FREQ_SEEK
:
1956 struct v4l2_hw_freq_seek
*p
= arg
;
1957 enum v4l2_tuner_type type
;
1959 if (!ops
->vidioc_s_hw_freq_seek
)
1965 type
= (vfd
->vfl_type
== VFL_TYPE_RADIO
) ?
1966 V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1968 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1969 p
->tuner
, p
->type
, p
->seek_upward
, p
->wrap_around
, p
->spacing
);
1970 if (p
->type
!= type
)
1973 ret
= ops
->vidioc_s_hw_freq_seek(file
, fh
, p
);
1976 case VIDIOC_ENUM_FRAMESIZES
:
1978 struct v4l2_frmsizeenum
*p
= arg
;
1980 if (!ops
->vidioc_enum_framesizes
)
1983 ret
= ops
->vidioc_enum_framesizes(file
, fh
, p
);
1985 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1987 (p
->pixel_format
& 0xff),
1988 (p
->pixel_format
>> 8) & 0xff,
1989 (p
->pixel_format
>> 16) & 0xff,
1990 (p
->pixel_format
>> 24) & 0xff,
1993 case V4L2_FRMSIZE_TYPE_DISCRETE
:
1994 dbgarg3("width = %d, height=%d\n",
1995 p
->discrete
.width
, p
->discrete
.height
);
1997 case V4L2_FRMSIZE_TYPE_STEPWISE
:
1998 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1999 p
->stepwise
.min_width
, p
->stepwise
.min_height
,
2000 p
->stepwise
.step_width
, p
->stepwise
.step_height
,
2001 p
->stepwise
.max_width
, p
->stepwise
.max_height
);
2003 case V4L2_FRMSIZE_TYPE_CONTINUOUS
:
2004 dbgarg3("continuous\n");
2007 dbgarg3("- Unknown type!\n");
2012 case VIDIOC_ENUM_FRAMEINTERVALS
:
2014 struct v4l2_frmivalenum
*p
= arg
;
2016 if (!ops
->vidioc_enum_frameintervals
)
2019 ret
= ops
->vidioc_enum_frameintervals(file
, fh
, p
);
2021 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
2022 p
->index
, p
->pixel_format
,
2023 p
->width
, p
->height
, p
->type
);
2025 case V4L2_FRMIVAL_TYPE_DISCRETE
:
2026 dbgarg2("fps=%d/%d\n",
2027 p
->discrete
.numerator
,
2028 p
->discrete
.denominator
);
2030 case V4L2_FRMIVAL_TYPE_STEPWISE
:
2031 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
2032 p
->stepwise
.min
.numerator
,
2033 p
->stepwise
.min
.denominator
,
2034 p
->stepwise
.max
.numerator
,
2035 p
->stepwise
.max
.denominator
,
2036 p
->stepwise
.step
.numerator
,
2037 p
->stepwise
.step
.denominator
);
2039 case V4L2_FRMIVAL_TYPE_CONTINUOUS
:
2040 dbgarg2("continuous\n");
2043 dbgarg2("- Unknown type!\n");
2047 case VIDIOC_ENUM_DV_PRESETS
:
2049 struct v4l2_dv_enum_preset
*p
= arg
;
2051 if (!ops
->vidioc_enum_dv_presets
)
2054 ret
= ops
->vidioc_enum_dv_presets(file
, fh
, p
);
2057 "index=%d, preset=%d, name=%s, width=%d,"
2059 p
->index
, p
->preset
, p
->name
, p
->width
,
2063 case VIDIOC_S_DV_PRESET
:
2065 struct v4l2_dv_preset
*p
= arg
;
2067 if (!ops
->vidioc_s_dv_preset
)
2074 dbgarg(cmd
, "preset=%d\n", p
->preset
);
2075 ret
= ops
->vidioc_s_dv_preset(file
, fh
, p
);
2078 case VIDIOC_G_DV_PRESET
:
2080 struct v4l2_dv_preset
*p
= arg
;
2082 if (!ops
->vidioc_g_dv_preset
)
2085 ret
= ops
->vidioc_g_dv_preset(file
, fh
, p
);
2087 dbgarg(cmd
, "preset=%d\n", p
->preset
);
2090 case VIDIOC_QUERY_DV_PRESET
:
2092 struct v4l2_dv_preset
*p
= arg
;
2094 if (!ops
->vidioc_query_dv_preset
)
2097 ret
= ops
->vidioc_query_dv_preset(file
, fh
, p
);
2099 dbgarg(cmd
, "preset=%d\n", p
->preset
);
2102 case VIDIOC_S_DV_TIMINGS
:
2104 struct v4l2_dv_timings
*p
= arg
;
2106 if (!ops
->vidioc_s_dv_timings
)
2114 case V4L2_DV_BT_656_1120
:
2115 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2116 " width=%d, height=%d, polarities=%x,"
2117 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
2118 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
2119 " il_vfrontporch=%d, il_vsync=%d,"
2120 " il_vbackporch=%d\n",
2121 p
->bt
.interlaced
, p
->bt
.pixelclock
,
2122 p
->bt
.width
, p
->bt
.height
, p
->bt
.polarities
,
2123 p
->bt
.hfrontporch
, p
->bt
.hsync
,
2124 p
->bt
.hbackporch
, p
->bt
.vfrontporch
,
2125 p
->bt
.vsync
, p
->bt
.vbackporch
,
2126 p
->bt
.il_vfrontporch
, p
->bt
.il_vsync
,
2127 p
->bt
.il_vbackporch
);
2128 ret
= ops
->vidioc_s_dv_timings(file
, fh
, p
);
2131 dbgarg2("Unknown type %d!\n", p
->type
);
2136 case VIDIOC_G_DV_TIMINGS
:
2138 struct v4l2_dv_timings
*p
= arg
;
2140 if (!ops
->vidioc_g_dv_timings
)
2143 ret
= ops
->vidioc_g_dv_timings(file
, fh
, p
);
2146 case V4L2_DV_BT_656_1120
:
2147 dbgarg2("bt-656/1120:interlaced=%d,"
2149 " width=%d, height=%d, polarities=%x,"
2150 " hfrontporch=%d, hsync=%d,"
2151 " hbackporch=%d, vfrontporch=%d,"
2152 " vsync=%d, vbackporch=%d,"
2153 " il_vfrontporch=%d, il_vsync=%d,"
2154 " il_vbackporch=%d\n",
2155 p
->bt
.interlaced
, p
->bt
.pixelclock
,
2156 p
->bt
.width
, p
->bt
.height
,
2157 p
->bt
.polarities
, p
->bt
.hfrontporch
,
2158 p
->bt
.hsync
, p
->bt
.hbackporch
,
2159 p
->bt
.vfrontporch
, p
->bt
.vsync
,
2160 p
->bt
.vbackporch
, p
->bt
.il_vfrontporch
,
2161 p
->bt
.il_vsync
, p
->bt
.il_vbackporch
);
2164 dbgarg2("Unknown type %d!\n", p
->type
);
2170 case VIDIOC_DQEVENT
:
2172 struct v4l2_event
*ev
= arg
;
2174 if (!ops
->vidioc_subscribe_event
)
2177 ret
= v4l2_event_dequeue(fh
, ev
, file
->f_flags
& O_NONBLOCK
);
2179 dbgarg(cmd
, "no pending events?");
2183 "pending=%d, type=0x%8.8x, sequence=%d, "
2184 "timestamp=%lu.%9.9lu ",
2185 ev
->pending
, ev
->type
, ev
->sequence
,
2186 ev
->timestamp
.tv_sec
, ev
->timestamp
.tv_nsec
);
2189 case VIDIOC_SUBSCRIBE_EVENT
:
2191 struct v4l2_event_subscription
*sub
= arg
;
2193 if (!ops
->vidioc_subscribe_event
)
2196 ret
= ops
->vidioc_subscribe_event(fh
, sub
);
2198 dbgarg(cmd
, "failed, ret=%ld", ret
);
2201 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
2204 case VIDIOC_UNSUBSCRIBE_EVENT
:
2206 struct v4l2_event_subscription
*sub
= arg
;
2208 if (!ops
->vidioc_unsubscribe_event
)
2211 ret
= ops
->vidioc_unsubscribe_event(fh
, sub
);
2213 dbgarg(cmd
, "failed, ret=%ld", ret
);
2216 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
2219 case VIDIOC_CREATE_BUFS
:
2221 struct v4l2_create_buffers
*create
= arg
;
2223 if (!ops
->vidioc_create_bufs
)
2229 ret
= check_fmt(ops
, create
->format
.type
);
2233 ret
= ops
->vidioc_create_bufs(file
, fh
, create
);
2235 dbgarg(cmd
, "count=%d @ %d\n", create
->count
, create
->index
);
2238 case VIDIOC_PREPARE_BUF
:
2240 struct v4l2_buffer
*b
= arg
;
2242 if (!ops
->vidioc_prepare_buf
)
2244 ret
= check_fmt(ops
, b
->type
);
2248 ret
= ops
->vidioc_prepare_buf(file
, fh
, b
);
2250 dbgarg(cmd
, "index=%d", b
->index
);
2254 if (!ops
->vidioc_default
)
2256 ret
= ops
->vidioc_default(file
, fh
, ret_prio
>= 0, cmd
, arg
);
2260 if (vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
) {
2262 v4l_print_ioctl(vfd
->name
, cmd
);
2263 printk(KERN_CONT
" error %ld\n", ret
);
2270 /* In some cases, only a few fields are used as input, i.e. when the app sets
2271 * "index" and then the driver fills in the rest of the structure for the thing
2272 * with that index. We only need to copy up the first non-input field. */
2273 static unsigned long cmd_input_size(unsigned int cmd
)
2275 /* Size of structure up to and including 'field' */
2276 #define CMDINSIZE(cmd, type, field) \
2277 case VIDIOC_##cmd: \
2278 return offsetof(struct v4l2_##type, field) + \
2279 sizeof(((struct v4l2_##type *)0)->field);
2282 CMDINSIZE(ENUM_FMT
, fmtdesc
, type
);
2283 CMDINSIZE(G_FMT
, format
, type
);
2284 CMDINSIZE(QUERYBUF
, buffer
, length
);
2285 CMDINSIZE(G_PARM
, streamparm
, type
);
2286 CMDINSIZE(ENUMSTD
, standard
, index
);
2287 CMDINSIZE(ENUMINPUT
, input
, index
);
2288 CMDINSIZE(G_CTRL
, control
, id
);
2289 CMDINSIZE(G_TUNER
, tuner
, index
);
2290 CMDINSIZE(QUERYCTRL
, queryctrl
, id
);
2291 CMDINSIZE(QUERYMENU
, querymenu
, index
);
2292 CMDINSIZE(ENUMOUTPUT
, output
, index
);
2293 CMDINSIZE(G_MODULATOR
, modulator
, index
);
2294 CMDINSIZE(G_FREQUENCY
, frequency
, tuner
);
2295 CMDINSIZE(CROPCAP
, cropcap
, type
);
2296 CMDINSIZE(G_CROP
, crop
, type
);
2297 CMDINSIZE(ENUMAUDIO
, audio
, index
);
2298 CMDINSIZE(ENUMAUDOUT
, audioout
, index
);
2299 CMDINSIZE(ENCODER_CMD
, encoder_cmd
, flags
);
2300 CMDINSIZE(TRY_ENCODER_CMD
, encoder_cmd
, flags
);
2301 CMDINSIZE(G_SLICED_VBI_CAP
, sliced_vbi_cap
, type
);
2302 CMDINSIZE(ENUM_FRAMESIZES
, frmsizeenum
, pixel_format
);
2303 CMDINSIZE(ENUM_FRAMEINTERVALS
, frmivalenum
, height
);
2305 return _IOC_SIZE(cmd
);
2309 static int check_array_args(unsigned int cmd
, void *parg
, size_t *array_size
,
2310 void * __user
*user_ptr
, void ***kernel_ptr
)
2315 case VIDIOC_QUERYBUF
:
2317 case VIDIOC_DQBUF
: {
2318 struct v4l2_buffer
*buf
= parg
;
2320 if (V4L2_TYPE_IS_MULTIPLANAR(buf
->type
) && buf
->length
> 0) {
2321 if (buf
->length
> VIDEO_MAX_PLANES
) {
2325 *user_ptr
= (void __user
*)buf
->m
.planes
;
2326 *kernel_ptr
= (void *)&buf
->m
.planes
;
2327 *array_size
= sizeof(struct v4l2_plane
) * buf
->length
;
2333 case VIDIOC_S_EXT_CTRLS
:
2334 case VIDIOC_G_EXT_CTRLS
:
2335 case VIDIOC_TRY_EXT_CTRLS
: {
2336 struct v4l2_ext_controls
*ctrls
= parg
;
2338 if (ctrls
->count
!= 0) {
2339 if (ctrls
->count
> V4L2_CID_MAX_CTRLS
) {
2343 *user_ptr
= (void __user
*)ctrls
->controls
;
2344 *kernel_ptr
= (void *)&ctrls
->controls
;
2345 *array_size
= sizeof(struct v4l2_ext_control
)
2357 video_usercopy(struct file
*file
, unsigned int cmd
, unsigned long arg
,
2362 void *parg
= (void *)arg
;
2364 bool has_array_args
;
2365 size_t array_size
= 0;
2366 void __user
*user_ptr
= NULL
;
2367 void **kernel_ptr
= NULL
;
2369 /* Copy arguments into temp kernel buffer */
2370 if (_IOC_DIR(cmd
) != _IOC_NONE
) {
2371 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
2374 /* too big to allocate from stack */
2375 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
2382 if (_IOC_DIR(cmd
) & _IOC_WRITE
) {
2383 unsigned long n
= cmd_input_size(cmd
);
2385 if (copy_from_user(parg
, (void __user
*)arg
, n
))
2388 /* zero out anything we don't copy from userspace */
2389 if (n
< _IOC_SIZE(cmd
))
2390 memset((u8
*)parg
+ n
, 0, _IOC_SIZE(cmd
) - n
);
2392 /* read-only ioctl */
2393 memset(parg
, 0, _IOC_SIZE(cmd
));
2397 err
= check_array_args(cmd
, parg
, &array_size
, &user_ptr
, &kernel_ptr
);
2400 has_array_args
= err
;
2402 if (has_array_args
) {
2404 * When adding new types of array args, make sure that the
2405 * parent argument to ioctl (which contains the pointer to the
2406 * array) fits into sbuf (so that mbuf will still remain
2407 * unused up to here).
2409 mbuf
= kmalloc(array_size
, GFP_KERNEL
);
2412 goto out_array_args
;
2414 if (copy_from_user(mbuf
, user_ptr
, array_size
))
2415 goto out_array_args
;
2420 err
= func(file
, cmd
, parg
);
2421 if (err
== -ENOIOCTLCMD
)
2424 if (has_array_args
) {
2425 *kernel_ptr
= user_ptr
;
2426 if (copy_to_user(user_ptr
, mbuf
, array_size
))
2428 goto out_array_args
;
2434 /* Copy results into user buffer */
2435 switch (_IOC_DIR(cmd
)) {
2437 case (_IOC_WRITE
| _IOC_READ
):
2438 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
2447 EXPORT_SYMBOL(video_usercopy
);
2449 long video_ioctl2(struct file
*file
,
2450 unsigned int cmd
, unsigned long arg
)
2452 return video_usercopy(file
, cmd
, arg
, __video_do_ioctl
);
2454 EXPORT_SYMBOL(video_ioctl2
);