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_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
242 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
243 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
244 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
245 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
246 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
247 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
248 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
249 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
250 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
251 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
252 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
253 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
255 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
256 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
257 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
258 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
259 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
261 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
262 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
264 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
265 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
267 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS)] = "VIDIOC_ENUM_DV_PRESETS",
268 [_IOC_NR(VIDIOC_S_DV_PRESET)] = "VIDIOC_S_DV_PRESET",
269 [_IOC_NR(VIDIOC_G_DV_PRESET)] = "VIDIOC_G_DV_PRESET",
270 [_IOC_NR(VIDIOC_QUERY_DV_PRESET)] = "VIDIOC_QUERY_DV_PRESET",
271 [_IOC_NR(VIDIOC_S_DV_TIMINGS)] = "VIDIOC_S_DV_TIMINGS",
272 [_IOC_NR(VIDIOC_G_DV_TIMINGS)] = "VIDIOC_G_DV_TIMINGS",
273 [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
274 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
275 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
277 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
279 /* Common ioctl debug function. This function can be used by
280 external ioctl messages as well as internal V4L ioctl */
281 void v4l_printk_ioctl(unsigned int cmd)
285 switch (_IOC_TYPE(cmd)) {
290 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
294 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
300 switch (_IOC_DIR(cmd)) {
301 case _IOC_NONE: dir = "--"; break;
302 case _IOC_READ: dir = "r-"; break;
303 case _IOC_WRITE: dir = "-w"; break;
304 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
305 default: dir = "*ERR*"; break;
307 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
308 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
310 EXPORT_SYMBOL(v4l_printk_ioctl);
312 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
313 struct v4l2_buffer *p)
315 struct v4l2_timecode *tc = &p->timecode;
316 struct v4l2_plane *plane;
319 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
320 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
321 p->timestamp.tv_sec / 3600,
322 (int)(p->timestamp.tv_sec / 60) % 60,
323 (int)(p->timestamp.tv_sec % 60),
324 (long)p->timestamp.tv_usec,
326 prt_names(p->type, v4l2_type_names),
327 p->flags, p->field, p->sequence,
328 prt_names(p->memory, v4l2_memory_names));
330 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
331 for (i = 0; i < p->length; ++i) {
332 plane = &p->m.planes[i];
333 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
334 "offset/userptr=0x%08lx, length=%d\n",
335 i, plane->bytesused, plane->data_offset,
336 plane->m.userptr, plane->length);
339 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
340 p->bytesused, p->m.userptr, p->length);
343 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
344 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
345 tc->hours, tc->minutes, tc->seconds,
346 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
349 static inline void dbgrect(struct video_device *vfd, char *s,
352 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
353 r->width, r->height);
356 static inline void v4l_print_pix_fmt(struct video_device *vfd,
357 struct v4l2_pix_format *fmt)
359 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
360 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
361 fmt->width, fmt->height,
362 (fmt->pixelformat & 0xff),
363 (fmt->pixelformat >> 8) & 0xff,
364 (fmt->pixelformat >> 16) & 0xff,
365 (fmt->pixelformat >> 24) & 0xff,
366 prt_names(fmt->field, v4l2_field_names),
367 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
370 static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
371 struct v4l2_pix_format_mplane *fmt)
375 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
376 "colorspace=%d, num_planes=%d\n",
377 fmt->width, fmt->height,
378 (fmt->pixelformat & 0xff),
379 (fmt->pixelformat >> 8) & 0xff,
380 (fmt->pixelformat >> 16) & 0xff,
381 (fmt->pixelformat >> 24) & 0xff,
382 prt_names(fmt->field, v4l2_field_names),
383 fmt->colorspace, fmt->num_planes);
385 for (i = 0; i < fmt->num_planes; ++i)
386 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
387 fmt->plane_fmt[i].bytesperline,
388 fmt->plane_fmt[i].sizeimage);
391 static inline void v4l_print_ext_ctrls(unsigned int cmd,
392 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
396 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
399 printk(KERN_CONT "class=0x%x", c->ctrl_class);
400 for (i = 0; i < c->count; i++) {
401 if (show_vals && !c->controls[i].size)
402 printk(KERN_CONT " id/val=0x%x/0x%x",
403 c->controls[i].id, c->controls[i].value);
405 printk(KERN_CONT " id=0x%x,size=%u",
406 c->controls[i].id, c->controls[i].size);
408 printk(KERN_CONT "\n");
411 static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
415 /* zero the reserved fields */
416 c->reserved[0] = c->reserved[1] = 0;
417 for (i = 0; i < c->count; i++)
418 c->controls[i].reserved2[0] = 0;
420 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
421 when using extended controls.
422 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
423 is it allowed for backwards compatibility.
425 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
427 /* Check that all controls are from the same control class. */
428 for (i = 0; i < c->count; i++) {
429 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
437 static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
443 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
444 if (ops->vidioc_g_fmt_vid_cap ||
445 ops->vidioc_g_fmt_vid_cap_mplane)
448 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
449 if (ops->vidioc_g_fmt_vid_cap_mplane)
452 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
453 if (ops->vidioc_g_fmt_vid_overlay)
456 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
457 if (ops->vidioc_g_fmt_vid_out ||
458 ops->vidioc_g_fmt_vid_out_mplane)
461 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
462 if (ops->vidioc_g_fmt_vid_out_mplane)
465 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
466 if (ops->vidioc_g_fmt_vid_out_overlay)
469 case V4L2_BUF_TYPE_VBI_CAPTURE:
470 if (ops->vidioc_g_fmt_vbi_cap)
473 case V4L2_BUF_TYPE_VBI_OUTPUT:
474 if (ops->vidioc_g_fmt_vbi_out)
477 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
478 if (ops->vidioc_g_fmt_sliced_vbi_cap)
481 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
482 if (ops->vidioc_g_fmt_sliced_vbi_out)
485 case V4L2_BUF_TYPE_PRIVATE:
486 if (ops->vidioc_g_fmt_type_private)
493 static long __video_do_ioctl(struct file *file,
494 unsigned int cmd, void *arg)
496 struct video_device *vfd = video_devdata(file);
497 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
498 void *fh = file->private_data;
499 struct v4l2_fh *vfh = NULL;
505 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
510 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
511 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
512 v4l_print_ioctl(vfd->name, cmd);
513 printk(KERN_CONT "\n");
516 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
517 vfh = file->private_data;
518 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
522 ret_prio = v4l2_prio_check(vfd->prio, vfh->prio);
526 /* --- capabilities ------------------------------------------ */
527 case VIDIOC_QUERYCAP:
529 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
531 if (!ops->vidioc_querycap)
534 cap->version = LINUX_VERSION_CODE;
535 ret = ops->vidioc_querycap(file, fh, cap);
537 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
539 "capabilities=0x%08x\n",
540 cap->driver, cap->card, cap->bus_info,
546 /* --- priority ------------------------------------------ */
547 case VIDIOC_G_PRIORITY:
549 enum v4l2_priority *p = arg;
551 if (ops->vidioc_g_priority) {
552 ret = ops->vidioc_g_priority(file, fh, p);
553 } else if (use_fh_prio) {
554 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
558 dbgarg(cmd, "priority is %d\n", *p);
561 case VIDIOC_S_PRIORITY:
563 enum v4l2_priority *p = arg;
565 if (!ops->vidioc_s_priority && !use_fh_prio)
567 dbgarg(cmd, "setting priority to %d\n", *p);
568 if (ops->vidioc_s_priority)
569 ret = ops->vidioc_s_priority(file, fh, *p);
571 ret = ret_prio ? ret_prio :
572 v4l2_prio_change(&vfd->v4l2_dev->prio,
577 /* --- capture ioctls ---------------------------------------- */
578 case VIDIOC_ENUM_FMT:
580 struct v4l2_fmtdesc *f = arg;
583 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
584 if (likely(ops->vidioc_enum_fmt_vid_cap))
585 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
587 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
588 if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
589 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
592 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
593 if (likely(ops->vidioc_enum_fmt_vid_overlay))
594 ret = ops->vidioc_enum_fmt_vid_overlay(file,
597 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
598 if (likely(ops->vidioc_enum_fmt_vid_out))
599 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
601 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
602 if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
603 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
606 case V4L2_BUF_TYPE_PRIVATE:
607 if (likely(ops->vidioc_enum_fmt_type_private))
608 ret = ops->vidioc_enum_fmt_type_private(file,
615 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
616 "pixelformat=%c%c%c%c, description='%s'\n",
617 f->index, f->type, f->flags,
618 (f->pixelformat & 0xff),
619 (f->pixelformat >> 8) & 0xff,
620 (f->pixelformat >> 16) & 0xff,
621 (f->pixelformat >> 24) & 0xff,
623 else if (ret == -ENOTTY &&
624 (ops->vidioc_enum_fmt_vid_cap ||
625 ops->vidioc_enum_fmt_vid_out ||
626 ops->vidioc_enum_fmt_vid_cap_mplane ||
627 ops->vidioc_enum_fmt_vid_out_mplane ||
628 ops->vidioc_enum_fmt_vid_overlay ||
629 ops->vidioc_enum_fmt_type_private))
635 struct v4l2_format *f = (struct v4l2_format *)arg;
637 /* FIXME: Should be one dump per type */
638 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
641 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
642 if (ops->vidioc_g_fmt_vid_cap)
643 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
645 v4l_print_pix_fmt(vfd, &f->fmt.pix);
647 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
648 if (ops->vidioc_g_fmt_vid_cap_mplane)
649 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
652 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
654 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
655 if (likely(ops->vidioc_g_fmt_vid_overlay))
656 ret = ops->vidioc_g_fmt_vid_overlay(file,
659 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
660 if (ops->vidioc_g_fmt_vid_out)
661 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
663 v4l_print_pix_fmt(vfd, &f->fmt.pix);
665 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
666 if (ops->vidioc_g_fmt_vid_out_mplane)
667 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
670 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
672 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
673 if (likely(ops->vidioc_g_fmt_vid_out_overlay))
674 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
677 case V4L2_BUF_TYPE_VBI_CAPTURE:
678 if (likely(ops->vidioc_g_fmt_vbi_cap))
679 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
681 case V4L2_BUF_TYPE_VBI_OUTPUT:
682 if (likely(ops->vidioc_g_fmt_vbi_out))
683 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
685 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
686 if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
687 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
690 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
691 if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
692 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
695 case V4L2_BUF_TYPE_PRIVATE:
696 if (likely(ops->vidioc_g_fmt_type_private))
697 ret = ops->vidioc_g_fmt_type_private(file,
701 if (unlikely(ret == -ENOTTY && have_fmt_ops(g)))
708 struct v4l2_format *f = (struct v4l2_format *)arg;
710 if (!have_fmt_ops(s))
718 /* FIXME: Should be one dump per type */
719 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
722 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
723 CLEAR_AFTER_FIELD(f, fmt.pix);
724 v4l_print_pix_fmt(vfd, &f->fmt.pix);
725 if (ops->vidioc_s_fmt_vid_cap)
726 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
728 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
729 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
730 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
731 if (ops->vidioc_s_fmt_vid_cap_mplane)
732 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
735 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
736 CLEAR_AFTER_FIELD(f, fmt.win);
737 if (ops->vidioc_s_fmt_vid_overlay)
738 ret = ops->vidioc_s_fmt_vid_overlay(file,
741 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
742 CLEAR_AFTER_FIELD(f, fmt.pix);
743 v4l_print_pix_fmt(vfd, &f->fmt.pix);
744 if (ops->vidioc_s_fmt_vid_out)
745 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
747 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
748 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
749 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
750 if (ops->vidioc_s_fmt_vid_out_mplane)
751 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
754 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
755 CLEAR_AFTER_FIELD(f, fmt.win);
756 if (ops->vidioc_s_fmt_vid_out_overlay)
757 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
760 case V4L2_BUF_TYPE_VBI_CAPTURE:
761 CLEAR_AFTER_FIELD(f, fmt.vbi);
762 if (likely(ops->vidioc_s_fmt_vbi_cap))
763 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
765 case V4L2_BUF_TYPE_VBI_OUTPUT:
766 CLEAR_AFTER_FIELD(f, fmt.vbi);
767 if (likely(ops->vidioc_s_fmt_vbi_out))
768 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
770 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
771 CLEAR_AFTER_FIELD(f, fmt.sliced);
772 if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
773 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
776 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
777 CLEAR_AFTER_FIELD(f, fmt.sliced);
778 if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
779 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
783 case V4L2_BUF_TYPE_PRIVATE:
784 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
785 if (likely(ops->vidioc_s_fmt_type_private))
786 ret = ops->vidioc_s_fmt_type_private(file,
794 struct v4l2_format *f = (struct v4l2_format *)arg;
796 /* FIXME: Should be one dump per type */
797 dbgarg(cmd, "type=%s\n", prt_names(f->type,
800 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
801 CLEAR_AFTER_FIELD(f, fmt.pix);
802 if (ops->vidioc_try_fmt_vid_cap)
803 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
805 v4l_print_pix_fmt(vfd, &f->fmt.pix);
807 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
808 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
809 if (ops->vidioc_try_fmt_vid_cap_mplane)
810 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
813 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
815 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
816 CLEAR_AFTER_FIELD(f, fmt.win);
817 if (likely(ops->vidioc_try_fmt_vid_overlay))
818 ret = ops->vidioc_try_fmt_vid_overlay(file,
821 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
822 CLEAR_AFTER_FIELD(f, fmt.pix);
823 if (ops->vidioc_try_fmt_vid_out)
824 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
826 v4l_print_pix_fmt(vfd, &f->fmt.pix);
828 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
829 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
830 if (ops->vidioc_try_fmt_vid_out_mplane)
831 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
834 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
836 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
837 CLEAR_AFTER_FIELD(f, fmt.win);
838 if (likely(ops->vidioc_try_fmt_vid_out_overlay))
839 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
842 case V4L2_BUF_TYPE_VBI_CAPTURE:
843 CLEAR_AFTER_FIELD(f, fmt.vbi);
844 if (likely(ops->vidioc_try_fmt_vbi_cap))
845 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
847 case V4L2_BUF_TYPE_VBI_OUTPUT:
848 CLEAR_AFTER_FIELD(f, fmt.vbi);
849 if (likely(ops->vidioc_try_fmt_vbi_out))
850 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
852 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
853 CLEAR_AFTER_FIELD(f, fmt.sliced);
854 if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
855 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
858 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
859 CLEAR_AFTER_FIELD(f, fmt.sliced);
860 if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
861 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
864 case V4L2_BUF_TYPE_PRIVATE:
865 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
866 if (likely(ops->vidioc_try_fmt_type_private))
867 ret = ops->vidioc_try_fmt_type_private(file,
871 if (unlikely(ret == -ENOTTY && have_fmt_ops(try)))
875 /* FIXME: Those buf reqs could be handled here,
876 with some changes on videobuf to allow its header to be included at
877 videodev2.h or being merged at videodev2.
881 struct v4l2_requestbuffers *p = arg;
883 if (!ops->vidioc_reqbufs)
889 ret = check_fmt(ops, p->type);
893 if (p->type < V4L2_BUF_TYPE_PRIVATE)
894 CLEAR_AFTER_FIELD(p, memory);
896 ret = ops->vidioc_reqbufs(file, fh, p);
897 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
899 prt_names(p->type, v4l2_type_names),
900 prt_names(p->memory, v4l2_memory_names));
903 case VIDIOC_QUERYBUF:
905 struct v4l2_buffer *p = arg;
907 if (!ops->vidioc_querybuf)
909 ret = check_fmt(ops, p->type);
913 ret = ops->vidioc_querybuf(file, fh, p);
920 struct v4l2_buffer *p = arg;
922 if (!ops->vidioc_qbuf)
924 ret = check_fmt(ops, p->type);
928 ret = ops->vidioc_qbuf(file, fh, p);
935 struct v4l2_buffer *p = arg;
937 if (!ops->vidioc_dqbuf)
939 ret = check_fmt(ops, p->type);
943 ret = ops->vidioc_dqbuf(file, fh, p);
952 if (!ops->vidioc_overlay)
958 dbgarg(cmd, "value=%d\n", *i);
959 ret = ops->vidioc_overlay(file, fh, *i);
964 struct v4l2_framebuffer *p = arg;
966 if (!ops->vidioc_g_fbuf)
968 ret = ops->vidioc_g_fbuf(file, fh, arg);
970 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
971 p->capability, p->flags,
972 (unsigned long)p->base);
973 v4l_print_pix_fmt(vfd, &p->fmt);
979 struct v4l2_framebuffer *p = arg;
981 if (!ops->vidioc_s_fbuf)
987 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
988 p->capability, p->flags, (unsigned long)p->base);
989 v4l_print_pix_fmt(vfd, &p->fmt);
990 ret = ops->vidioc_s_fbuf(file, fh, arg);
993 case VIDIOC_STREAMON:
995 enum v4l2_buf_type i = *(int *)arg;
997 if (!ops->vidioc_streamon)
1003 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1004 ret = ops->vidioc_streamon(file, fh, i);
1007 case VIDIOC_STREAMOFF:
1009 enum v4l2_buf_type i = *(int *)arg;
1011 if (!ops->vidioc_streamoff)
1017 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1018 ret = ops->vidioc_streamoff(file, fh, i);
1021 /* ---------- tv norms ---------- */
1022 case VIDIOC_ENUMSTD:
1024 struct v4l2_standard *p = arg;
1025 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1026 unsigned int index = p->index, i, j = 0;
1027 const char *descr = "";
1033 /* Return norm array in a canonical way */
1034 for (i = 0; i <= index && id; i++) {
1035 /* last std value in the standards array is 0, so this
1036 while always ends there since (id & 0) == 0. */
1037 while ((id & standards[j].std) != standards[j].std)
1039 curr_id = standards[j].std;
1040 descr = standards[j].descr;
1044 if (curr_id != V4L2_STD_PAL &&
1045 curr_id != V4L2_STD_SECAM &&
1046 curr_id != V4L2_STD_NTSC)
1052 v4l2_video_std_construct(p, curr_id, descr);
1054 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1055 "framelines=%d\n", p->index,
1056 (unsigned long long)p->id, p->name,
1057 p->frameperiod.numerator,
1058 p->frameperiod.denominator,
1066 v4l2_std_id *id = arg;
1068 /* Calls the specific handler */
1069 if (ops->vidioc_g_std)
1070 ret = ops->vidioc_g_std(file, fh, id);
1071 else if (vfd->current_norm) {
1073 *id = vfd->current_norm;
1077 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1082 v4l2_std_id *id = arg, norm;
1084 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1086 if (!ops->vidioc_s_std)
1094 norm = (*id) & vfd->tvnorms;
1095 if (vfd->tvnorms && !norm) /* Check if std is supported */
1098 /* Calls the specific handler */
1099 ret = ops->vidioc_s_std(file, fh, &norm);
1101 /* Updates standard information */
1103 vfd->current_norm = norm;
1106 case VIDIOC_QUERYSTD:
1108 v4l2_std_id *p = arg;
1110 if (!ops->vidioc_querystd)
1113 * If nothing detected, it should return all supported
1114 * Drivers just need to mask the std argument, in order
1115 * to remove the standards that don't apply from the mask.
1116 * This means that tuners, audio and video decoders can join
1117 * their efforts to improve the standards detection
1120 ret = ops->vidioc_querystd(file, fh, arg);
1122 dbgarg(cmd, "detected std=%08Lx\n",
1123 (unsigned long long)*p);
1126 /* ------ input switching ---------- */
1127 /* FIXME: Inputs can be handled inside videodev2 */
1128 case VIDIOC_ENUMINPUT:
1130 struct v4l2_input *p = arg;
1133 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1134 * CAP_STD here based on ioctl handler provided by the
1135 * driver. If the driver doesn't support these
1136 * for a specific input, it must override these flags.
1138 if (ops->vidioc_s_std)
1139 p->capabilities |= V4L2_IN_CAP_STD;
1140 if (ops->vidioc_s_dv_preset)
1141 p->capabilities |= V4L2_IN_CAP_PRESETS;
1142 if (ops->vidioc_s_dv_timings)
1143 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1145 if (!ops->vidioc_enum_input)
1148 ret = ops->vidioc_enum_input(file, fh, p);
1150 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1152 "tuner=%d, std=%08Lx, status=%d\n",
1153 p->index, p->name, p->type, p->audioset,
1155 (unsigned long long)p->std,
1159 case VIDIOC_G_INPUT:
1161 unsigned int *i = arg;
1163 if (!ops->vidioc_g_input)
1165 ret = ops->vidioc_g_input(file, fh, i);
1167 dbgarg(cmd, "value=%d\n", *i);
1170 case VIDIOC_S_INPUT:
1172 unsigned int *i = arg;
1174 if (!ops->vidioc_s_input)
1180 dbgarg(cmd, "value=%d\n", *i);
1181 ret = ops->vidioc_s_input(file, fh, *i);
1185 /* ------ output switching ---------- */
1186 case VIDIOC_ENUMOUTPUT:
1188 struct v4l2_output *p = arg;
1190 if (!ops->vidioc_enum_output)
1194 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1195 * CAP_STD here based on ioctl handler provided by the
1196 * driver. If the driver doesn't support these
1197 * for a specific output, it must override these flags.
1199 if (ops->vidioc_s_std)
1200 p->capabilities |= V4L2_OUT_CAP_STD;
1201 if (ops->vidioc_s_dv_preset)
1202 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1203 if (ops->vidioc_s_dv_timings)
1204 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1206 ret = ops->vidioc_enum_output(file, fh, p);
1208 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1210 "modulator=%d, std=0x%08Lx\n",
1211 p->index, p->name, p->type, p->audioset,
1212 p->modulator, (unsigned long long)p->std);
1215 case VIDIOC_G_OUTPUT:
1217 unsigned int *i = arg;
1219 if (!ops->vidioc_g_output)
1221 ret = ops->vidioc_g_output(file, fh, i);
1223 dbgarg(cmd, "value=%d\n", *i);
1226 case VIDIOC_S_OUTPUT:
1228 unsigned int *i = arg;
1230 if (!ops->vidioc_s_output)
1236 dbgarg(cmd, "value=%d\n", *i);
1237 ret = ops->vidioc_s_output(file, fh, *i);
1241 /* --- controls ---------------------------------------------- */
1242 case VIDIOC_QUERYCTRL:
1244 struct v4l2_queryctrl *p = arg;
1246 if (vfh && vfh->ctrl_handler)
1247 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1248 else if (vfd->ctrl_handler)
1249 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1250 else if (ops->vidioc_queryctrl)
1251 ret = ops->vidioc_queryctrl(file, fh, p);
1255 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1256 "step=%d, default=%d, flags=0x%08x\n",
1257 p->id, p->type, p->name,
1258 p->minimum, p->maximum,
1259 p->step, p->default_value, p->flags);
1261 dbgarg(cmd, "id=0x%x\n", p->id);
1266 struct v4l2_control *p = arg;
1268 if (vfh && vfh->ctrl_handler)
1269 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1270 else if (vfd->ctrl_handler)
1271 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1272 else if (ops->vidioc_g_ctrl)
1273 ret = ops->vidioc_g_ctrl(file, fh, p);
1274 else if (ops->vidioc_g_ext_ctrls) {
1275 struct v4l2_ext_controls ctrls;
1276 struct v4l2_ext_control ctrl;
1278 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1280 ctrls.controls = &ctrl;
1282 ctrl.value = p->value;
1283 if (check_ext_ctrls(&ctrls, 1)) {
1284 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1286 p->value = ctrl.value;
1291 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1293 dbgarg(cmd, "id=0x%x\n", p->id);
1298 struct v4l2_control *p = arg;
1299 struct v4l2_ext_controls ctrls;
1300 struct v4l2_ext_control ctrl;
1302 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1303 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
1310 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1312 if (vfh && vfh->ctrl_handler) {
1313 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
1316 if (vfd->ctrl_handler) {
1317 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
1320 if (ops->vidioc_s_ctrl) {
1321 ret = ops->vidioc_s_ctrl(file, fh, p);
1324 if (!ops->vidioc_s_ext_ctrls)
1327 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1329 ctrls.controls = &ctrl;
1331 ctrl.value = p->value;
1332 if (check_ext_ctrls(&ctrls, 1))
1333 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1338 case VIDIOC_G_EXT_CTRLS:
1340 struct v4l2_ext_controls *p = arg;
1342 p->error_idx = p->count;
1343 if (vfh && vfh->ctrl_handler)
1344 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1345 else if (vfd->ctrl_handler)
1346 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
1347 else if (ops->vidioc_g_ext_ctrls)
1348 ret = check_ext_ctrls(p, 0) ?
1349 ops->vidioc_g_ext_ctrls(file, fh, p) :
1353 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1356 case VIDIOC_S_EXT_CTRLS:
1358 struct v4l2_ext_controls *p = arg;
1360 p->error_idx = p->count;
1361 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1362 !ops->vidioc_s_ext_ctrls)
1368 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1369 if (vfh && vfh->ctrl_handler)
1370 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
1371 else if (vfd->ctrl_handler)
1372 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
1373 else if (check_ext_ctrls(p, 0))
1374 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
1379 case VIDIOC_TRY_EXT_CTRLS:
1381 struct v4l2_ext_controls *p = arg;
1383 p->error_idx = p->count;
1384 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1385 !ops->vidioc_try_ext_ctrls)
1387 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1388 if (vfh && vfh->ctrl_handler)
1389 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1390 else if (vfd->ctrl_handler)
1391 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1392 else if (check_ext_ctrls(p, 0))
1393 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
1398 case VIDIOC_QUERYMENU:
1400 struct v4l2_querymenu *p = arg;
1402 if (vfh && vfh->ctrl_handler)
1403 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1404 else if (vfd->ctrl_handler)
1405 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1406 else if (ops->vidioc_querymenu)
1407 ret = ops->vidioc_querymenu(file, fh, p);
1411 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1412 p->id, p->index, p->name);
1414 dbgarg(cmd, "id=0x%x, index=%d\n",
1418 /* --- audio ---------------------------------------------- */
1419 case VIDIOC_ENUMAUDIO:
1421 struct v4l2_audio *p = arg;
1423 if (!ops->vidioc_enumaudio)
1425 ret = ops->vidioc_enumaudio(file, fh, p);
1427 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1428 "mode=0x%x\n", p->index, p->name,
1429 p->capability, p->mode);
1431 dbgarg(cmd, "index=%d\n", p->index);
1434 case VIDIOC_G_AUDIO:
1436 struct v4l2_audio *p = arg;
1438 if (!ops->vidioc_g_audio)
1441 ret = ops->vidioc_g_audio(file, fh, p);
1443 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1444 "mode=0x%x\n", p->index,
1445 p->name, p->capability, p->mode);
1447 dbgarg(cmd, "index=%d\n", p->index);
1450 case VIDIOC_S_AUDIO:
1452 struct v4l2_audio *p = arg;
1454 if (!ops->vidioc_s_audio)
1460 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1461 "mode=0x%x\n", p->index, p->name,
1462 p->capability, p->mode);
1463 ret = ops->vidioc_s_audio(file, fh, p);
1466 case VIDIOC_ENUMAUDOUT:
1468 struct v4l2_audioout *p = arg;
1470 if (!ops->vidioc_enumaudout)
1472 dbgarg(cmd, "Enum for index=%d\n", p->index);
1473 ret = ops->vidioc_enumaudout(file, fh, p);
1475 dbgarg2("index=%d, name=%s, capability=%d, "
1476 "mode=%d\n", p->index, p->name,
1477 p->capability, p->mode);
1480 case VIDIOC_G_AUDOUT:
1482 struct v4l2_audioout *p = arg;
1484 if (!ops->vidioc_g_audout)
1487 ret = ops->vidioc_g_audout(file, fh, p);
1489 dbgarg2("index=%d, name=%s, capability=%d, "
1490 "mode=%d\n", p->index, p->name,
1491 p->capability, p->mode);
1494 case VIDIOC_S_AUDOUT:
1496 struct v4l2_audioout *p = arg;
1498 if (!ops->vidioc_s_audout)
1504 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1505 "mode=%d\n", p->index, p->name,
1506 p->capability, p->mode);
1508 ret = ops->vidioc_s_audout(file, fh, p);
1511 case VIDIOC_G_MODULATOR:
1513 struct v4l2_modulator *p = arg;
1515 if (!ops->vidioc_g_modulator)
1517 ret = ops->vidioc_g_modulator(file, fh, p);
1519 dbgarg(cmd, "index=%d, name=%s, "
1520 "capability=%d, rangelow=%d,"
1521 " rangehigh=%d, txsubchans=%d\n",
1522 p->index, p->name, p->capability,
1523 p->rangelow, p->rangehigh,
1527 case VIDIOC_S_MODULATOR:
1529 struct v4l2_modulator *p = arg;
1531 if (!ops->vidioc_s_modulator)
1537 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1538 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1539 p->index, p->name, p->capability, p->rangelow,
1540 p->rangehigh, p->txsubchans);
1541 ret = ops->vidioc_s_modulator(file, fh, p);
1546 struct v4l2_crop *p = arg;
1548 if (!ops->vidioc_g_crop)
1551 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1552 ret = ops->vidioc_g_crop(file, fh, p);
1554 dbgrect(vfd, "", &p->c);
1559 struct v4l2_crop *p = arg;
1561 if (!ops->vidioc_s_crop)
1567 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1568 dbgrect(vfd, "", &p->c);
1569 ret = ops->vidioc_s_crop(file, fh, p);
1572 case VIDIOC_CROPCAP:
1574 struct v4l2_cropcap *p = arg;
1576 /*FIXME: Should also show v4l2_fract pixelaspect */
1577 if (!ops->vidioc_cropcap)
1580 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1581 ret = ops->vidioc_cropcap(file, fh, p);
1583 dbgrect(vfd, "bounds ", &p->bounds);
1584 dbgrect(vfd, "defrect ", &p->defrect);
1588 case VIDIOC_G_JPEGCOMP:
1590 struct v4l2_jpegcompression *p = arg;
1592 if (!ops->vidioc_g_jpegcomp)
1595 ret = ops->vidioc_g_jpegcomp(file, fh, p);
1597 dbgarg(cmd, "quality=%d, APPn=%d, "
1598 "APP_len=%d, COM_len=%d, "
1599 "jpeg_markers=%d\n",
1600 p->quality, p->APPn, p->APP_len,
1601 p->COM_len, p->jpeg_markers);
1604 case VIDIOC_S_JPEGCOMP:
1606 struct v4l2_jpegcompression *p = arg;
1608 if (!ops->vidioc_g_jpegcomp)
1614 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1615 "COM_len=%d, jpeg_markers=%d\n",
1616 p->quality, p->APPn, p->APP_len,
1617 p->COM_len, p->jpeg_markers);
1618 ret = ops->vidioc_s_jpegcomp(file, fh, p);
1621 case VIDIOC_G_ENC_INDEX:
1623 struct v4l2_enc_idx *p = arg;
1625 if (!ops->vidioc_g_enc_index)
1627 ret = ops->vidioc_g_enc_index(file, fh, p);
1629 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1630 p->entries, p->entries_cap);
1633 case VIDIOC_ENCODER_CMD:
1635 struct v4l2_encoder_cmd *p = arg;
1637 if (!ops->vidioc_encoder_cmd)
1643 ret = ops->vidioc_encoder_cmd(file, fh, p);
1645 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1648 case VIDIOC_TRY_ENCODER_CMD:
1650 struct v4l2_encoder_cmd *p = arg;
1652 if (!ops->vidioc_try_encoder_cmd)
1654 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
1656 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1661 struct v4l2_streamparm *p = arg;
1663 if (!ops->vidioc_g_parm && !vfd->current_norm)
1665 if (ops->vidioc_g_parm) {
1666 ret = check_fmt(ops, p->type);
1669 ret = ops->vidioc_g_parm(file, fh, p);
1671 v4l2_std_id std = vfd->current_norm;
1674 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1678 if (ops->vidioc_g_std)
1679 ret = ops->vidioc_g_std(file, fh, &std);
1681 v4l2_video_std_frame_period(std,
1682 &p->parm.capture.timeperframe);
1685 dbgarg(cmd, "type=%d\n", p->type);
1690 struct v4l2_streamparm *p = arg;
1692 if (!ops->vidioc_s_parm)
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 if (!ops->vidioc_g_tuner)
1713 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1714 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1715 ret = ops->vidioc_g_tuner(file, fh, p);
1717 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1718 "capability=0x%x, rangelow=%d, "
1719 "rangehigh=%d, signal=%d, afc=%d, "
1720 "rxsubchans=0x%x, audmode=%d\n",
1721 p->index, p->name, p->type,
1722 p->capability, p->rangelow,
1723 p->rangehigh, p->signal, p->afc,
1724 p->rxsubchans, p->audmode);
1727 case VIDIOC_S_TUNER:
1729 struct v4l2_tuner *p = arg;
1731 if (!ops->vidioc_s_tuner)
1737 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1738 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1739 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1740 "capability=0x%x, rangelow=%d, "
1741 "rangehigh=%d, signal=%d, afc=%d, "
1742 "rxsubchans=0x%x, audmode=%d\n",
1743 p->index, p->name, p->type,
1744 p->capability, p->rangelow,
1745 p->rangehigh, p->signal, p->afc,
1746 p->rxsubchans, p->audmode);
1747 ret = ops->vidioc_s_tuner(file, fh, p);
1750 case VIDIOC_G_FREQUENCY:
1752 struct v4l2_frequency *p = arg;
1754 if (!ops->vidioc_g_frequency)
1757 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1758 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1759 ret = ops->vidioc_g_frequency(file, fh, p);
1761 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1762 p->tuner, p->type, p->frequency);
1765 case VIDIOC_S_FREQUENCY:
1767 struct v4l2_frequency *p = arg;
1769 if (!ops->vidioc_s_frequency)
1775 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1776 p->tuner, p->type, p->frequency);
1777 ret = ops->vidioc_s_frequency(file, fh, p);
1780 case VIDIOC_G_SLICED_VBI_CAP:
1782 struct v4l2_sliced_vbi_cap *p = arg;
1784 if (!ops->vidioc_g_sliced_vbi_cap)
1787 /* Clear up to type, everything after type is zerod already */
1788 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1790 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1791 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1793 dbgarg2("service_set=%d\n", p->service_set);
1796 case VIDIOC_LOG_STATUS:
1798 if (!ops->vidioc_log_status)
1800 ret = ops->vidioc_log_status(file, fh);
1803 #ifdef CONFIG_VIDEO_ADV_DEBUG
1804 case VIDIOC_DBG_G_REGISTER:
1806 struct v4l2_dbg_register *p = arg;
1808 if (ops->vidioc_g_register) {
1809 if (!capable(CAP_SYS_ADMIN))
1812 ret = ops->vidioc_g_register(file, fh, p);
1816 case VIDIOC_DBG_S_REGISTER:
1818 struct v4l2_dbg_register *p = arg;
1820 if (ops->vidioc_s_register) {
1821 if (!capable(CAP_SYS_ADMIN))
1824 ret = ops->vidioc_s_register(file, fh, p);
1829 case VIDIOC_DBG_G_CHIP_IDENT:
1831 struct v4l2_dbg_chip_ident *p = arg;
1833 if (!ops->vidioc_g_chip_ident)
1835 p->ident = V4L2_IDENT_NONE;
1837 ret = ops->vidioc_g_chip_ident(file, fh, p);
1839 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1842 case VIDIOC_S_HW_FREQ_SEEK:
1844 struct v4l2_hw_freq_seek *p = arg;
1845 enum v4l2_tuner_type type;
1847 if (!ops->vidioc_s_hw_freq_seek)
1853 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1854 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1856 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1857 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1858 if (p->type != type)
1861 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1864 case VIDIOC_ENUM_FRAMESIZES:
1866 struct v4l2_frmsizeenum *p = arg;
1868 if (!ops->vidioc_enum_framesizes)
1871 ret = ops->vidioc_enum_framesizes(file, fh, p);
1873 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1875 (p->pixel_format & 0xff),
1876 (p->pixel_format >> 8) & 0xff,
1877 (p->pixel_format >> 16) & 0xff,
1878 (p->pixel_format >> 24) & 0xff,
1881 case V4L2_FRMSIZE_TYPE_DISCRETE:
1882 dbgarg3("width = %d, height=%d\n",
1883 p->discrete.width, p->discrete.height);
1885 case V4L2_FRMSIZE_TYPE_STEPWISE:
1886 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1887 p->stepwise.min_width, p->stepwise.min_height,
1888 p->stepwise.step_width, p->stepwise.step_height,
1889 p->stepwise.max_width, p->stepwise.max_height);
1891 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1892 dbgarg3("continuous\n");
1895 dbgarg3("- Unknown type!\n");
1900 case VIDIOC_ENUM_FRAMEINTERVALS:
1902 struct v4l2_frmivalenum *p = arg;
1904 if (!ops->vidioc_enum_frameintervals)
1907 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1909 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1910 p->index, p->pixel_format,
1911 p->width, p->height, p->type);
1913 case V4L2_FRMIVAL_TYPE_DISCRETE:
1914 dbgarg2("fps=%d/%d\n",
1915 p->discrete.numerator,
1916 p->discrete.denominator);
1918 case V4L2_FRMIVAL_TYPE_STEPWISE:
1919 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1920 p->stepwise.min.numerator,
1921 p->stepwise.min.denominator,
1922 p->stepwise.max.numerator,
1923 p->stepwise.max.denominator,
1924 p->stepwise.step.numerator,
1925 p->stepwise.step.denominator);
1927 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1928 dbgarg2("continuous\n");
1931 dbgarg2("- Unknown type!\n");
1935 case VIDIOC_ENUM_DV_PRESETS:
1937 struct v4l2_dv_enum_preset *p = arg;
1939 if (!ops->vidioc_enum_dv_presets)
1942 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1945 "index=%d, preset=%d, name=%s, width=%d,"
1947 p->index, p->preset, p->name, p->width,
1951 case VIDIOC_S_DV_PRESET:
1953 struct v4l2_dv_preset *p = arg;
1955 if (!ops->vidioc_s_dv_preset)
1962 dbgarg(cmd, "preset=%d\n", p->preset);
1963 ret = ops->vidioc_s_dv_preset(file, fh, p);
1966 case VIDIOC_G_DV_PRESET:
1968 struct v4l2_dv_preset *p = arg;
1970 if (!ops->vidioc_g_dv_preset)
1973 ret = ops->vidioc_g_dv_preset(file, fh, p);
1975 dbgarg(cmd, "preset=%d\n", p->preset);
1978 case VIDIOC_QUERY_DV_PRESET:
1980 struct v4l2_dv_preset *p = arg;
1982 if (!ops->vidioc_query_dv_preset)
1985 ret = ops->vidioc_query_dv_preset(file, fh, p);
1987 dbgarg(cmd, "preset=%d\n", p->preset);
1990 case VIDIOC_S_DV_TIMINGS:
1992 struct v4l2_dv_timings *p = arg;
1994 if (!ops->vidioc_s_dv_timings)
2002 case V4L2_DV_BT_656_1120:
2003 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2004 " width=%d, height=%d, polarities=%x,"
2005 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
2006 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
2007 " il_vfrontporch=%d, il_vsync=%d,"
2008 " il_vbackporch=%d\n",
2009 p->bt.interlaced, p->bt.pixelclock,
2010 p->bt.width, p->bt.height, p->bt.polarities,
2011 p->bt.hfrontporch, p->bt.hsync,
2012 p->bt.hbackporch, p->bt.vfrontporch,
2013 p->bt.vsync, p->bt.vbackporch,
2014 p->bt.il_vfrontporch, p->bt.il_vsync,
2015 p->bt.il_vbackporch);
2016 ret = ops->vidioc_s_dv_timings(file, fh, p);
2019 dbgarg2("Unknown type %d!\n", p->type);
2024 case VIDIOC_G_DV_TIMINGS:
2026 struct v4l2_dv_timings *p = arg;
2028 if (!ops->vidioc_g_dv_timings)
2031 ret = ops->vidioc_g_dv_timings(file, fh, p);
2034 case V4L2_DV_BT_656_1120:
2035 dbgarg2("bt-656/1120:interlaced=%d,"
2037 " width=%d, height=%d, polarities=%x,"
2038 " hfrontporch=%d, hsync=%d,"
2039 " hbackporch=%d, vfrontporch=%d,"
2040 " vsync=%d, vbackporch=%d,"
2041 " il_vfrontporch=%d, il_vsync=%d,"
2042 " il_vbackporch=%d\n",
2043 p->bt.interlaced, p->bt.pixelclock,
2044 p->bt.width, p->bt.height,
2045 p->bt.polarities, p->bt.hfrontporch,
2046 p->bt.hsync, p->bt.hbackporch,
2047 p->bt.vfrontporch, p->bt.vsync,
2048 p->bt.vbackporch, p->bt.il_vfrontporch,
2049 p->bt.il_vsync, p->bt.il_vbackporch);
2052 dbgarg2("Unknown type %d!\n", p->type);
2058 case VIDIOC_DQEVENT:
2060 struct v4l2_event *ev = arg;
2062 if (!ops->vidioc_subscribe_event)
2065 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2067 dbgarg(cmd, "no pending events?");
2071 "pending=%d, type=0x%8.8x, sequence=%d, "
2072 "timestamp=%lu.%9.9lu ",
2073 ev->pending, ev->type, ev->sequence,
2074 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2077 case VIDIOC_SUBSCRIBE_EVENT:
2079 struct v4l2_event_subscription *sub = arg;
2081 if (!ops->vidioc_subscribe_event)
2084 ret = ops->vidioc_subscribe_event(fh, sub);
2086 dbgarg(cmd, "failed, ret=%ld", ret);
2089 dbgarg(cmd, "type=0x%8.8x", sub->type);
2092 case VIDIOC_UNSUBSCRIBE_EVENT:
2094 struct v4l2_event_subscription *sub = arg;
2096 if (!ops->vidioc_unsubscribe_event)
2099 ret = ops->vidioc_unsubscribe_event(fh, sub);
2101 dbgarg(cmd, "failed, ret=%ld", ret);
2104 dbgarg(cmd, "type=0x%8.8x", sub->type);
2108 if (!ops->vidioc_default)
2110 ret = ops->vidioc_default(file, fh, ret_prio >= 0, cmd, arg);
2114 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2116 v4l_print_ioctl(vfd->name, cmd);
2117 printk(KERN_CONT " error %ld\n", ret);
2124 /* In some cases, only a few fields are used as input, i.e. when the app sets
2125 * "index" and then the driver fills in the rest of the structure for the thing
2126 * with that index. We only need to copy up the first non-input field. */
2127 static unsigned long cmd_input_size(unsigned int cmd)
2129 /* Size of structure up to and including 'field' */
2130 #define CMDINSIZE(cmd, type, field) \
2131 case VIDIOC_##cmd: \
2132 return offsetof(struct v4l2_##type, field) + \
2133 sizeof(((struct v4l2_##type *)0)->field);
2136 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2137 CMDINSIZE(G_FMT, format, type);
2138 CMDINSIZE(QUERYBUF, buffer, length);
2139 CMDINSIZE(G_PARM, streamparm, type);
2140 CMDINSIZE(ENUMSTD, standard, index);
2141 CMDINSIZE(ENUMINPUT, input, index);
2142 CMDINSIZE(G_CTRL, control, id);
2143 CMDINSIZE(G_TUNER, tuner, index);
2144 CMDINSIZE(QUERYCTRL, queryctrl, id);
2145 CMDINSIZE(QUERYMENU, querymenu, index);
2146 CMDINSIZE(ENUMOUTPUT, output, index);
2147 CMDINSIZE(G_MODULATOR, modulator, index);
2148 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2149 CMDINSIZE(CROPCAP, cropcap, type);
2150 CMDINSIZE(G_CROP, crop, type);
2151 CMDINSIZE(ENUMAUDIO, audio, index);
2152 CMDINSIZE(ENUMAUDOUT, audioout, index);
2153 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2154 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2155 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2156 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2157 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2159 return _IOC_SIZE(cmd);
2163 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2164 void * __user *user_ptr, void ***kernel_ptr)
2169 case VIDIOC_QUERYBUF:
2171 case VIDIOC_DQBUF: {
2172 struct v4l2_buffer *buf = parg;
2174 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2175 if (buf->length > VIDEO_MAX_PLANES) {
2179 *user_ptr = (void __user *)buf->m.planes;
2180 *kernel_ptr = (void *)&buf->m.planes;
2181 *array_size = sizeof(struct v4l2_plane) * buf->length;
2187 case VIDIOC_S_EXT_CTRLS:
2188 case VIDIOC_G_EXT_CTRLS:
2189 case VIDIOC_TRY_EXT_CTRLS: {
2190 struct v4l2_ext_controls *ctrls = parg;
2192 if (ctrls->count != 0) {
2193 *user_ptr = (void __user *)ctrls->controls;
2194 *kernel_ptr = (void *)&ctrls->controls;
2195 *array_size = sizeof(struct v4l2_ext_control)
2207 video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2212 void *parg = (void *)arg;
2214 bool has_array_args;
2215 size_t array_size = 0;
2216 void __user *user_ptr = NULL;
2217 void **kernel_ptr = NULL;
2219 /* Copy arguments into temp kernel buffer */
2220 if (_IOC_DIR(cmd) != _IOC_NONE) {
2221 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2224 /* too big to allocate from stack */
2225 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2232 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2233 unsigned long n = cmd_input_size(cmd);
2235 if (copy_from_user(parg, (void __user *)arg, n))
2238 /* zero out anything we don't copy from userspace */
2239 if (n < _IOC_SIZE(cmd))
2240 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
2242 /* read-only ioctl */
2243 memset(parg, 0, _IOC_SIZE(cmd));
2247 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2250 has_array_args = err;
2252 if (has_array_args) {
2254 * When adding new types of array args, make sure that the
2255 * parent argument to ioctl (which contains the pointer to the
2256 * array) fits into sbuf (so that mbuf will still remain
2257 * unused up to here).
2259 mbuf = kmalloc(array_size, GFP_KERNEL);
2262 goto out_array_args;
2264 if (copy_from_user(mbuf, user_ptr, array_size))
2265 goto out_array_args;
2270 err = func(file, cmd, parg);
2271 if (err == -ENOIOCTLCMD)
2274 if (has_array_args) {
2275 *kernel_ptr = user_ptr;
2276 if (copy_to_user(user_ptr, mbuf, array_size))
2278 goto out_array_args;
2284 /* Copy results into user buffer */
2285 switch (_IOC_DIR(cmd)) {
2287 case (_IOC_WRITE | _IOC_READ):
2288 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2297 EXPORT_SYMBOL(video_usercopy);
2299 long video_ioctl2(struct file *file,
2300 unsigned int cmd, unsigned long arg)
2302 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2304 EXPORT_SYMBOL(video_ioctl2);