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)
1555 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1556 ret = ops->vidioc_g_crop(file, fh, p);
1558 dbgrect(vfd, "", &p->c);
1563 struct v4l2_crop *p = arg;
1565 if (!ops->vidioc_s_crop)
1571 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1572 dbgrect(vfd, "", &p->c);
1573 ret = ops->vidioc_s_crop(file, fh, p);
1576 case VIDIOC_G_SELECTION:
1578 struct v4l2_selection *p = arg;
1580 if (!ops->vidioc_g_selection)
1583 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1585 ret = ops->vidioc_g_selection(file, fh, p);
1587 dbgrect(vfd, "", &p->r);
1590 case VIDIOC_S_SELECTION:
1592 struct v4l2_selection *p = arg;
1594 if (!ops->vidioc_s_selection)
1602 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1603 dbgrect(vfd, "", &p->r);
1605 ret = ops->vidioc_s_selection(file, fh, p);
1608 case VIDIOC_CROPCAP:
1610 struct v4l2_cropcap *p = arg;
1612 /*FIXME: Should also show v4l2_fract pixelaspect */
1613 if (!ops->vidioc_cropcap)
1616 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1617 ret = ops->vidioc_cropcap(file, fh, p);
1619 dbgrect(vfd, "bounds ", &p->bounds);
1620 dbgrect(vfd, "defrect ", &p->defrect);
1624 case VIDIOC_G_JPEGCOMP:
1626 struct v4l2_jpegcompression *p = arg;
1628 if (!ops->vidioc_g_jpegcomp)
1631 ret = ops->vidioc_g_jpegcomp(file, fh, p);
1633 dbgarg(cmd, "quality=%d, APPn=%d, "
1634 "APP_len=%d, COM_len=%d, "
1635 "jpeg_markers=%d\n",
1636 p->quality, p->APPn, p->APP_len,
1637 p->COM_len, p->jpeg_markers);
1640 case VIDIOC_S_JPEGCOMP:
1642 struct v4l2_jpegcompression *p = arg;
1644 if (!ops->vidioc_g_jpegcomp)
1650 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1651 "COM_len=%d, jpeg_markers=%d\n",
1652 p->quality, p->APPn, p->APP_len,
1653 p->COM_len, p->jpeg_markers);
1654 ret = ops->vidioc_s_jpegcomp(file, fh, p);
1657 case VIDIOC_G_ENC_INDEX:
1659 struct v4l2_enc_idx *p = arg;
1661 if (!ops->vidioc_g_enc_index)
1663 ret = ops->vidioc_g_enc_index(file, fh, p);
1665 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1666 p->entries, p->entries_cap);
1669 case VIDIOC_ENCODER_CMD:
1671 struct v4l2_encoder_cmd *p = arg;
1673 if (!ops->vidioc_encoder_cmd)
1679 ret = ops->vidioc_encoder_cmd(file, fh, p);
1681 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1684 case VIDIOC_TRY_ENCODER_CMD:
1686 struct v4l2_encoder_cmd *p = arg;
1688 if (!ops->vidioc_try_encoder_cmd)
1690 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
1692 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1697 struct v4l2_streamparm *p = arg;
1699 if (!ops->vidioc_g_parm && !vfd->current_norm)
1701 if (ops->vidioc_g_parm) {
1702 ret = check_fmt(ops, p->type);
1705 ret = ops->vidioc_g_parm(file, fh, p);
1707 v4l2_std_id std = vfd->current_norm;
1710 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1714 if (ops->vidioc_g_std)
1715 ret = ops->vidioc_g_std(file, fh, &std);
1717 v4l2_video_std_frame_period(std,
1718 &p->parm.capture.timeperframe);
1721 dbgarg(cmd, "type=%d\n", p->type);
1726 struct v4l2_streamparm *p = arg;
1728 if (!ops->vidioc_s_parm)
1734 ret = check_fmt(ops, p->type);
1738 dbgarg(cmd, "type=%d\n", p->type);
1739 ret = ops->vidioc_s_parm(file, fh, p);
1742 case VIDIOC_G_TUNER:
1744 struct v4l2_tuner *p = arg;
1746 if (!ops->vidioc_g_tuner)
1749 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1750 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1751 ret = ops->vidioc_g_tuner(file, fh, p);
1753 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1754 "capability=0x%x, rangelow=%d, "
1755 "rangehigh=%d, signal=%d, afc=%d, "
1756 "rxsubchans=0x%x, audmode=%d\n",
1757 p->index, p->name, p->type,
1758 p->capability, p->rangelow,
1759 p->rangehigh, p->signal, p->afc,
1760 p->rxsubchans, p->audmode);
1763 case VIDIOC_S_TUNER:
1765 struct v4l2_tuner *p = arg;
1767 if (!ops->vidioc_s_tuner)
1773 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1774 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1775 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1776 "capability=0x%x, rangelow=%d, "
1777 "rangehigh=%d, signal=%d, afc=%d, "
1778 "rxsubchans=0x%x, audmode=%d\n",
1779 p->index, p->name, p->type,
1780 p->capability, p->rangelow,
1781 p->rangehigh, p->signal, p->afc,
1782 p->rxsubchans, p->audmode);
1783 ret = ops->vidioc_s_tuner(file, fh, p);
1786 case VIDIOC_G_FREQUENCY:
1788 struct v4l2_frequency *p = arg;
1790 if (!ops->vidioc_g_frequency)
1793 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1794 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1795 ret = ops->vidioc_g_frequency(file, fh, p);
1797 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1798 p->tuner, p->type, p->frequency);
1801 case VIDIOC_S_FREQUENCY:
1803 struct v4l2_frequency *p = arg;
1805 if (!ops->vidioc_s_frequency)
1811 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1812 p->tuner, p->type, p->frequency);
1813 ret = ops->vidioc_s_frequency(file, fh, p);
1816 case VIDIOC_G_SLICED_VBI_CAP:
1818 struct v4l2_sliced_vbi_cap *p = arg;
1820 if (!ops->vidioc_g_sliced_vbi_cap)
1823 /* Clear up to type, everything after type is zerod already */
1824 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1826 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1827 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1829 dbgarg2("service_set=%d\n", p->service_set);
1832 case VIDIOC_LOG_STATUS:
1834 if (!ops->vidioc_log_status)
1836 ret = ops->vidioc_log_status(file, fh);
1839 #ifdef CONFIG_VIDEO_ADV_DEBUG
1840 case VIDIOC_DBG_G_REGISTER:
1842 struct v4l2_dbg_register *p = arg;
1844 if (ops->vidioc_g_register) {
1845 if (!capable(CAP_SYS_ADMIN))
1848 ret = ops->vidioc_g_register(file, fh, p);
1852 case VIDIOC_DBG_S_REGISTER:
1854 struct v4l2_dbg_register *p = arg;
1856 if (ops->vidioc_s_register) {
1857 if (!capable(CAP_SYS_ADMIN))
1860 ret = ops->vidioc_s_register(file, fh, p);
1865 case VIDIOC_DBG_G_CHIP_IDENT:
1867 struct v4l2_dbg_chip_ident *p = arg;
1869 if (!ops->vidioc_g_chip_ident)
1871 p->ident = V4L2_IDENT_NONE;
1873 ret = ops->vidioc_g_chip_ident(file, fh, p);
1875 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1878 case VIDIOC_S_HW_FREQ_SEEK:
1880 struct v4l2_hw_freq_seek *p = arg;
1881 enum v4l2_tuner_type type;
1883 if (!ops->vidioc_s_hw_freq_seek)
1889 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1890 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1892 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1893 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1894 if (p->type != type)
1897 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1900 case VIDIOC_ENUM_FRAMESIZES:
1902 struct v4l2_frmsizeenum *p = arg;
1904 if (!ops->vidioc_enum_framesizes)
1907 ret = ops->vidioc_enum_framesizes(file, fh, p);
1909 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1911 (p->pixel_format & 0xff),
1912 (p->pixel_format >> 8) & 0xff,
1913 (p->pixel_format >> 16) & 0xff,
1914 (p->pixel_format >> 24) & 0xff,
1917 case V4L2_FRMSIZE_TYPE_DISCRETE:
1918 dbgarg3("width = %d, height=%d\n",
1919 p->discrete.width, p->discrete.height);
1921 case V4L2_FRMSIZE_TYPE_STEPWISE:
1922 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1923 p->stepwise.min_width, p->stepwise.min_height,
1924 p->stepwise.step_width, p->stepwise.step_height,
1925 p->stepwise.max_width, p->stepwise.max_height);
1927 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1928 dbgarg3("continuous\n");
1931 dbgarg3("- Unknown type!\n");
1936 case VIDIOC_ENUM_FRAMEINTERVALS:
1938 struct v4l2_frmivalenum *p = arg;
1940 if (!ops->vidioc_enum_frameintervals)
1943 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1945 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1946 p->index, p->pixel_format,
1947 p->width, p->height, p->type);
1949 case V4L2_FRMIVAL_TYPE_DISCRETE:
1950 dbgarg2("fps=%d/%d\n",
1951 p->discrete.numerator,
1952 p->discrete.denominator);
1954 case V4L2_FRMIVAL_TYPE_STEPWISE:
1955 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1956 p->stepwise.min.numerator,
1957 p->stepwise.min.denominator,
1958 p->stepwise.max.numerator,
1959 p->stepwise.max.denominator,
1960 p->stepwise.step.numerator,
1961 p->stepwise.step.denominator);
1963 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1964 dbgarg2("continuous\n");
1967 dbgarg2("- Unknown type!\n");
1971 case VIDIOC_ENUM_DV_PRESETS:
1973 struct v4l2_dv_enum_preset *p = arg;
1975 if (!ops->vidioc_enum_dv_presets)
1978 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1981 "index=%d, preset=%d, name=%s, width=%d,"
1983 p->index, p->preset, p->name, p->width,
1987 case VIDIOC_S_DV_PRESET:
1989 struct v4l2_dv_preset *p = arg;
1991 if (!ops->vidioc_s_dv_preset)
1998 dbgarg(cmd, "preset=%d\n", p->preset);
1999 ret = ops->vidioc_s_dv_preset(file, fh, p);
2002 case VIDIOC_G_DV_PRESET:
2004 struct v4l2_dv_preset *p = arg;
2006 if (!ops->vidioc_g_dv_preset)
2009 ret = ops->vidioc_g_dv_preset(file, fh, p);
2011 dbgarg(cmd, "preset=%d\n", p->preset);
2014 case VIDIOC_QUERY_DV_PRESET:
2016 struct v4l2_dv_preset *p = arg;
2018 if (!ops->vidioc_query_dv_preset)
2021 ret = ops->vidioc_query_dv_preset(file, fh, p);
2023 dbgarg(cmd, "preset=%d\n", p->preset);
2026 case VIDIOC_S_DV_TIMINGS:
2028 struct v4l2_dv_timings *p = arg;
2030 if (!ops->vidioc_s_dv_timings)
2038 case V4L2_DV_BT_656_1120:
2039 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2040 " width=%d, height=%d, polarities=%x,"
2041 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
2042 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
2043 " il_vfrontporch=%d, il_vsync=%d,"
2044 " il_vbackporch=%d\n",
2045 p->bt.interlaced, p->bt.pixelclock,
2046 p->bt.width, p->bt.height, p->bt.polarities,
2047 p->bt.hfrontporch, p->bt.hsync,
2048 p->bt.hbackporch, p->bt.vfrontporch,
2049 p->bt.vsync, p->bt.vbackporch,
2050 p->bt.il_vfrontporch, p->bt.il_vsync,
2051 p->bt.il_vbackporch);
2052 ret = ops->vidioc_s_dv_timings(file, fh, p);
2055 dbgarg2("Unknown type %d!\n", p->type);
2060 case VIDIOC_G_DV_TIMINGS:
2062 struct v4l2_dv_timings *p = arg;
2064 if (!ops->vidioc_g_dv_timings)
2067 ret = ops->vidioc_g_dv_timings(file, fh, p);
2070 case V4L2_DV_BT_656_1120:
2071 dbgarg2("bt-656/1120:interlaced=%d,"
2073 " width=%d, height=%d, polarities=%x,"
2074 " hfrontporch=%d, hsync=%d,"
2075 " hbackporch=%d, vfrontporch=%d,"
2076 " vsync=%d, vbackporch=%d,"
2077 " il_vfrontporch=%d, il_vsync=%d,"
2078 " il_vbackporch=%d\n",
2079 p->bt.interlaced, p->bt.pixelclock,
2080 p->bt.width, p->bt.height,
2081 p->bt.polarities, p->bt.hfrontporch,
2082 p->bt.hsync, p->bt.hbackporch,
2083 p->bt.vfrontporch, p->bt.vsync,
2084 p->bt.vbackporch, p->bt.il_vfrontporch,
2085 p->bt.il_vsync, p->bt.il_vbackporch);
2088 dbgarg2("Unknown type %d!\n", p->type);
2094 case VIDIOC_DQEVENT:
2096 struct v4l2_event *ev = arg;
2098 if (!ops->vidioc_subscribe_event)
2101 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2103 dbgarg(cmd, "no pending events?");
2107 "pending=%d, type=0x%8.8x, sequence=%d, "
2108 "timestamp=%lu.%9.9lu ",
2109 ev->pending, ev->type, ev->sequence,
2110 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2113 case VIDIOC_SUBSCRIBE_EVENT:
2115 struct v4l2_event_subscription *sub = arg;
2117 if (!ops->vidioc_subscribe_event)
2120 ret = ops->vidioc_subscribe_event(fh, sub);
2122 dbgarg(cmd, "failed, ret=%ld", ret);
2125 dbgarg(cmd, "type=0x%8.8x", sub->type);
2128 case VIDIOC_UNSUBSCRIBE_EVENT:
2130 struct v4l2_event_subscription *sub = arg;
2132 if (!ops->vidioc_unsubscribe_event)
2135 ret = ops->vidioc_unsubscribe_event(fh, sub);
2137 dbgarg(cmd, "failed, ret=%ld", ret);
2140 dbgarg(cmd, "type=0x%8.8x", sub->type);
2143 case VIDIOC_CREATE_BUFS:
2145 struct v4l2_create_buffers *create = arg;
2147 if (!ops->vidioc_create_bufs)
2153 ret = check_fmt(ops, create->format.type);
2157 ret = ops->vidioc_create_bufs(file, fh, create);
2159 dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2162 case VIDIOC_PREPARE_BUF:
2164 struct v4l2_buffer *b = arg;
2166 if (!ops->vidioc_prepare_buf)
2168 ret = check_fmt(ops, b->type);
2172 ret = ops->vidioc_prepare_buf(file, fh, b);
2174 dbgarg(cmd, "index=%d", b->index);
2178 if (!ops->vidioc_default)
2180 ret = ops->vidioc_default(file, fh, ret_prio >= 0, cmd, arg);
2184 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2186 v4l_print_ioctl(vfd->name, cmd);
2187 printk(KERN_CONT " error %ld\n", ret);
2194 /* In some cases, only a few fields are used as input, i.e. when the app sets
2195 * "index" and then the driver fills in the rest of the structure for the thing
2196 * with that index. We only need to copy up the first non-input field. */
2197 static unsigned long cmd_input_size(unsigned int cmd)
2199 /* Size of structure up to and including 'field' */
2200 #define CMDINSIZE(cmd, type, field) \
2201 case VIDIOC_##cmd: \
2202 return offsetof(struct v4l2_##type, field) + \
2203 sizeof(((struct v4l2_##type *)0)->field);
2206 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2207 CMDINSIZE(G_FMT, format, type);
2208 CMDINSIZE(QUERYBUF, buffer, length);
2209 CMDINSIZE(G_PARM, streamparm, type);
2210 CMDINSIZE(ENUMSTD, standard, index);
2211 CMDINSIZE(ENUMINPUT, input, index);
2212 CMDINSIZE(G_CTRL, control, id);
2213 CMDINSIZE(G_TUNER, tuner, index);
2214 CMDINSIZE(QUERYCTRL, queryctrl, id);
2215 CMDINSIZE(QUERYMENU, querymenu, index);
2216 CMDINSIZE(ENUMOUTPUT, output, index);
2217 CMDINSIZE(G_MODULATOR, modulator, index);
2218 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2219 CMDINSIZE(CROPCAP, cropcap, type);
2220 CMDINSIZE(G_CROP, crop, type);
2221 CMDINSIZE(ENUMAUDIO, audio, index);
2222 CMDINSIZE(ENUMAUDOUT, audioout, index);
2223 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2224 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2225 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2226 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2227 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2229 return _IOC_SIZE(cmd);
2233 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2234 void * __user *user_ptr, void ***kernel_ptr)
2239 case VIDIOC_QUERYBUF:
2241 case VIDIOC_DQBUF: {
2242 struct v4l2_buffer *buf = parg;
2244 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2245 if (buf->length > VIDEO_MAX_PLANES) {
2249 *user_ptr = (void __user *)buf->m.planes;
2250 *kernel_ptr = (void *)&buf->m.planes;
2251 *array_size = sizeof(struct v4l2_plane) * buf->length;
2257 case VIDIOC_S_EXT_CTRLS:
2258 case VIDIOC_G_EXT_CTRLS:
2259 case VIDIOC_TRY_EXT_CTRLS: {
2260 struct v4l2_ext_controls *ctrls = parg;
2262 if (ctrls->count != 0) {
2263 if (ctrls->count > V4L2_CID_MAX_CTRLS) {
2267 *user_ptr = (void __user *)ctrls->controls;
2268 *kernel_ptr = (void *)&ctrls->controls;
2269 *array_size = sizeof(struct v4l2_ext_control)
2281 video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2286 void *parg = (void *)arg;
2288 bool has_array_args;
2289 size_t array_size = 0;
2290 void __user *user_ptr = NULL;
2291 void **kernel_ptr = NULL;
2293 /* Copy arguments into temp kernel buffer */
2294 if (_IOC_DIR(cmd) != _IOC_NONE) {
2295 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2298 /* too big to allocate from stack */
2299 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2306 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2307 unsigned long n = cmd_input_size(cmd);
2309 if (copy_from_user(parg, (void __user *)arg, n))
2312 /* zero out anything we don't copy from userspace */
2313 if (n < _IOC_SIZE(cmd))
2314 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
2316 /* read-only ioctl */
2317 memset(parg, 0, _IOC_SIZE(cmd));
2321 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2324 has_array_args = err;
2326 if (has_array_args) {
2328 * When adding new types of array args, make sure that the
2329 * parent argument to ioctl (which contains the pointer to the
2330 * array) fits into sbuf (so that mbuf will still remain
2331 * unused up to here).
2333 mbuf = kmalloc(array_size, GFP_KERNEL);
2336 goto out_array_args;
2338 if (copy_from_user(mbuf, user_ptr, array_size))
2339 goto out_array_args;
2344 err = func(file, cmd, parg);
2345 if (err == -ENOIOCTLCMD)
2348 if (has_array_args) {
2349 *kernel_ptr = user_ptr;
2350 if (copy_to_user(user_ptr, mbuf, array_size))
2352 goto out_array_args;
2358 /* Copy results into user buffer */
2359 switch (_IOC_DIR(cmd)) {
2361 case (_IOC_WRITE | _IOC_READ):
2362 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2371 EXPORT_SYMBOL(video_usercopy);
2373 long video_ioctl2(struct file *file,
2374 unsigned int cmd, unsigned long arg)
2376 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2378 EXPORT_SYMBOL(video_ioctl2);