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/types.h>
17 #include <linux/kernel.h>
19 #define __OLD_VIDIOC_ /* To allow fixing old calls */
20 #include <linux/videodev.h>
21 #include <linux/videodev2.h>
23 #ifdef CONFIG_VIDEO_V4L1
24 #include <linux/videodev.h>
26 #include <media/v4l2-common.h>
27 #include <media/v4l2-ioctl.h>
28 #include <media/v4l2-chip-ident.h>
30 #define dbgarg(cmd, fmt, arg...) \
32 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
33 printk(KERN_DEBUG "%s: ", vfd->name); \
34 v4l_printk_ioctl(cmd); \
35 printk(" " fmt, ## arg); \
39 #define dbgarg2(fmt, arg...) \
41 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
42 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
50 static const struct std_descr standards[] = {
51 { V4L2_STD_NTSC, "NTSC" },
52 { V4L2_STD_NTSC_M, "NTSC-M" },
53 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
54 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
55 { V4L2_STD_NTSC_443, "NTSC-443" },
56 { V4L2_STD_PAL, "PAL" },
57 { V4L2_STD_PAL_BG, "PAL-BG" },
58 { V4L2_STD_PAL_B, "PAL-B" },
59 { V4L2_STD_PAL_B1, "PAL-B1" },
60 { V4L2_STD_PAL_G, "PAL-G" },
61 { V4L2_STD_PAL_H, "PAL-H" },
62 { V4L2_STD_PAL_I, "PAL-I" },
63 { V4L2_STD_PAL_DK, "PAL-DK" },
64 { V4L2_STD_PAL_D, "PAL-D" },
65 { V4L2_STD_PAL_D1, "PAL-D1" },
66 { V4L2_STD_PAL_K, "PAL-K" },
67 { V4L2_STD_PAL_M, "PAL-M" },
68 { V4L2_STD_PAL_N, "PAL-N" },
69 { V4L2_STD_PAL_Nc, "PAL-Nc" },
70 { V4L2_STD_PAL_60, "PAL-60" },
71 { V4L2_STD_SECAM, "SECAM" },
72 { V4L2_STD_SECAM_B, "SECAM-B" },
73 { V4L2_STD_SECAM_G, "SECAM-G" },
74 { V4L2_STD_SECAM_H, "SECAM-H" },
75 { V4L2_STD_SECAM_DK, "SECAM-DK" },
76 { V4L2_STD_SECAM_D, "SECAM-D" },
77 { V4L2_STD_SECAM_K, "SECAM-K" },
78 { V4L2_STD_SECAM_K1, "SECAM-K1" },
79 { V4L2_STD_SECAM_L, "SECAM-L" },
80 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
84 /* video4linux standard ID conversion to standard name
86 const char *v4l2_norm_to_name(v4l2_std_id id)
91 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
92 64 bit comparations. So, on that architecture, with some gcc
93 variants, compilation fails. Currently, the max value is 30bit wide.
97 for (i = 0; standards[i].std; i++)
98 if (myid == standards[i].std)
100 return standards[i].descr;
102 EXPORT_SYMBOL(v4l2_norm_to_name);
104 /* Returns frame period for the given standard */
105 void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
107 if (id & V4L2_STD_525_60) {
108 frameperiod->numerator = 1001;
109 frameperiod->denominator = 30000;
111 frameperiod->numerator = 1;
112 frameperiod->denominator = 25;
115 EXPORT_SYMBOL(v4l2_video_std_frame_period);
117 /* Fill in the fields of a v4l2_standard structure according to the
118 'id' and 'transmission' parameters. Returns negative on error. */
119 int v4l2_video_std_construct(struct v4l2_standard *vs,
120 int id, const char *name)
123 v4l2_video_std_frame_period(id, &vs->frameperiod);
124 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
125 strlcpy(vs->name, name, sizeof(vs->name));
128 EXPORT_SYMBOL(v4l2_video_std_construct);
130 /* ----------------------------------------------------------------- */
131 /* some arrays for pretty-printing debug messages of enum types */
133 const char *v4l2_field_names[] = {
134 [V4L2_FIELD_ANY] = "any",
135 [V4L2_FIELD_NONE] = "none",
136 [V4L2_FIELD_TOP] = "top",
137 [V4L2_FIELD_BOTTOM] = "bottom",
138 [V4L2_FIELD_INTERLACED] = "interlaced",
139 [V4L2_FIELD_SEQ_TB] = "seq-tb",
140 [V4L2_FIELD_SEQ_BT] = "seq-bt",
141 [V4L2_FIELD_ALTERNATE] = "alternate",
142 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
143 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
145 EXPORT_SYMBOL(v4l2_field_names);
147 const char *v4l2_type_names[] = {
148 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
149 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
150 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
151 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
152 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
153 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
154 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
155 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
157 EXPORT_SYMBOL(v4l2_type_names);
159 static const char *v4l2_memory_names[] = {
160 [V4L2_MEMORY_MMAP] = "mmap",
161 [V4L2_MEMORY_USERPTR] = "userptr",
162 [V4L2_MEMORY_OVERLAY] = "overlay",
165 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
168 /* ------------------------------------------------------------------ */
169 /* debug help functions */
171 #ifdef CONFIG_VIDEO_V4L1_COMPAT
172 static const char *v4l1_ioctls[] = {
173 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
174 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
175 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
176 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
177 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
178 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
179 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
180 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
181 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
182 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
183 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
184 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
185 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
186 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
187 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
188 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
189 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
190 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
191 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
192 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
193 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
194 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
195 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
196 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
197 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
198 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
199 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
200 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
201 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
203 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
206 static const char *v4l2_ioctls[] = {
207 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
208 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
209 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
210 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
211 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
212 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
213 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
214 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
215 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
216 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
217 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
218 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
219 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
220 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
221 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
222 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
223 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
224 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
225 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
226 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
227 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
228 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
229 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
230 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
231 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
232 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
233 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
234 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
235 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
236 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
237 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
238 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
239 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
240 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
241 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
242 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
243 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
244 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
245 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
246 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
247 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
248 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
249 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
250 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
251 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
252 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
253 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
254 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
255 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
256 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
257 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
258 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
259 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
260 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
261 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
263 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
264 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
265 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
266 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
267 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
269 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
270 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
272 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
273 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
276 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
278 /* Common ioctl debug function. This function can be used by
279 external ioctl messages as well as internal V4L ioctl */
280 void v4l_printk_ioctl(unsigned int cmd)
284 switch (_IOC_TYPE(cmd)) {
288 #ifdef CONFIG_VIDEO_V4L1_COMPAT
290 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
294 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
298 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
302 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
308 switch (_IOC_DIR(cmd)) {
309 case _IOC_NONE: dir = "--"; break;
310 case _IOC_READ: dir = "r-"; break;
311 case _IOC_WRITE: dir = "-w"; break;
312 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
313 default: dir = "*ERR*"; break;
315 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
316 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
318 EXPORT_SYMBOL(v4l_printk_ioctl);
321 * helper function -- handles userspace copying for ioctl arguments
326 video_fix_command(unsigned int cmd)
329 case VIDIOC_OVERLAY_OLD:
330 cmd = VIDIOC_OVERLAY;
332 case VIDIOC_S_PARM_OLD:
335 case VIDIOC_S_CTRL_OLD:
338 case VIDIOC_G_AUDIO_OLD:
339 cmd = VIDIOC_G_AUDIO;
341 case VIDIOC_G_AUDOUT_OLD:
342 cmd = VIDIOC_G_AUDOUT;
344 case VIDIOC_CROPCAP_OLD:
345 cmd = VIDIOC_CROPCAP;
353 * Obsolete usercopy function - Should be removed soon
356 video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
364 size_t ctrls_size = 0;
365 void __user *user_ptr = NULL;
368 cmd = video_fix_command(cmd);
370 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
371 cmd == VIDIOC_TRY_EXT_CTRLS);
373 /* Copy arguments into temp kernel buffer */
374 switch (_IOC_DIR(cmd)) {
380 case (_IOC_WRITE | _IOC_READ):
381 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
384 /* too big to allocate from stack */
385 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
392 if (_IOC_DIR(cmd) & _IOC_WRITE)
393 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
398 struct v4l2_ext_controls *p = parg;
400 /* In case of an error, tell the caller that it wasn't
401 a specific control that caused it. */
402 p->error_idx = p->count;
403 user_ptr = (void __user *)p->controls;
405 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
406 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
407 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
412 if (copy_from_user(mbuf, user_ptr, ctrls_size))
419 err = func(file, cmd, parg);
420 if (err == -ENOIOCTLCMD)
423 struct v4l2_ext_controls *p = parg;
425 p->controls = (void *)user_ptr;
426 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
434 /* Copy results into user buffer */
435 switch (_IOC_DIR(cmd)) {
437 case (_IOC_WRITE | _IOC_READ):
438 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
447 EXPORT_SYMBOL(video_usercopy);
449 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
450 struct v4l2_buffer *p)
452 struct v4l2_timecode *tc = &p->timecode;
454 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
455 "bytesused=%d, flags=0x%08d, "
456 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
457 p->timestamp.tv_sec / 3600,
458 (int)(p->timestamp.tv_sec / 60) % 60,
459 (int)(p->timestamp.tv_sec % 60),
460 (long)p->timestamp.tv_usec,
462 prt_names(p->type, v4l2_type_names),
463 p->bytesused, p->flags,
464 p->field, p->sequence,
465 prt_names(p->memory, v4l2_memory_names),
466 p->m.userptr, p->length);
467 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
468 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
469 tc->hours, tc->minutes, tc->seconds,
470 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
473 static inline void dbgrect(struct video_device *vfd, char *s,
476 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
477 r->width, r->height);
480 static inline void v4l_print_pix_fmt(struct video_device *vfd,
481 struct v4l2_pix_format *fmt)
483 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
484 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
485 fmt->width, fmt->height,
486 (fmt->pixelformat & 0xff),
487 (fmt->pixelformat >> 8) & 0xff,
488 (fmt->pixelformat >> 16) & 0xff,
489 (fmt->pixelformat >> 24) & 0xff,
490 prt_names(fmt->field, v4l2_field_names),
491 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
494 static inline void v4l_print_ext_ctrls(unsigned int cmd,
495 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
499 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
502 printk(KERN_CONT "class=0x%x", c->ctrl_class);
503 for (i = 0; i < c->count; i++) {
505 printk(KERN_CONT " id/val=0x%x/0x%x",
506 c->controls[i].id, c->controls[i].value);
508 printk(KERN_CONT " id=0x%x", c->controls[i].id);
510 printk(KERN_CONT "\n");
513 static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
517 /* zero the reserved fields */
518 c->reserved[0] = c->reserved[1] = 0;
519 for (i = 0; i < c->count; i++) {
520 c->controls[i].reserved2[0] = 0;
521 c->controls[i].reserved2[1] = 0;
523 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
524 when using extended controls.
525 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
526 is it allowed for backwards compatibility.
528 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
530 /* Check that all controls are from the same control class. */
531 for (i = 0; i < c->count; i++) {
532 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
540 static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
546 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
547 if (ops->vidioc_try_fmt_vid_cap)
550 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
551 if (ops->vidioc_try_fmt_vid_overlay)
554 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
555 if (ops->vidioc_try_fmt_vid_out)
558 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
559 if (ops->vidioc_try_fmt_vid_out_overlay)
562 case V4L2_BUF_TYPE_VBI_CAPTURE:
563 if (ops->vidioc_try_fmt_vbi_cap)
566 case V4L2_BUF_TYPE_VBI_OUTPUT:
567 if (ops->vidioc_try_fmt_vbi_out)
570 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
571 if (ops->vidioc_try_fmt_sliced_vbi_cap)
574 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
575 if (ops->vidioc_try_fmt_sliced_vbi_out)
578 case V4L2_BUF_TYPE_PRIVATE:
579 if (ops->vidioc_try_fmt_type_private)
586 static long __video_do_ioctl(struct file *file,
587 unsigned int cmd, void *arg)
589 struct video_device *vfd = video_devdata(file);
590 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
591 void *fh = file->private_data;
594 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
595 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
596 v4l_print_ioctl(vfd->name, cmd);
597 printk(KERN_CONT "\n");
601 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
606 #ifdef CONFIG_VIDEO_V4L1_COMPAT
607 /***********************************************************
608 Handles calls to the obsoleted V4L1 API
609 Due to the nature of VIDIOCGMBUF, each driver that supports
610 V4L1 should implement its own handler for this ioctl.
611 ***********************************************************/
613 /* --- streaming capture ------------------------------------- */
614 if (cmd == VIDIOCGMBUF) {
615 struct video_mbuf *p = arg;
617 if (!ops->vidiocgmbuf)
619 ret = ops->vidiocgmbuf(file, fh, p);
621 dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
623 (unsigned long)p->offsets);
627 /********************************************************
628 All other V4L1 calls are handled by v4l1_compat module.
629 Those calls will be translated into V4L2 calls, and
630 __video_do_ioctl will be called again, with one or more
632 ********************************************************/
633 if (_IOC_TYPE(cmd) == 'v' && _IOC_NR(cmd) < BASE_VIDIOCPRIVATE)
634 return v4l_compat_translate_ioctl(file, cmd, arg,
639 /* --- capabilities ------------------------------------------ */
640 case VIDIOC_QUERYCAP:
642 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
644 if (!ops->vidioc_querycap)
647 ret = ops->vidioc_querycap(file, fh, cap);
649 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
651 "capabilities=0x%08x\n",
652 cap->driver, cap->card, cap->bus_info,
658 /* --- priority ------------------------------------------ */
659 case VIDIOC_G_PRIORITY:
661 enum v4l2_priority *p = arg;
663 if (!ops->vidioc_g_priority)
665 ret = ops->vidioc_g_priority(file, fh, p);
667 dbgarg(cmd, "priority is %d\n", *p);
670 case VIDIOC_S_PRIORITY:
672 enum v4l2_priority *p = arg;
674 if (!ops->vidioc_s_priority)
676 dbgarg(cmd, "setting priority to %d\n", *p);
677 ret = ops->vidioc_s_priority(file, fh, *p);
681 /* --- capture ioctls ---------------------------------------- */
682 case VIDIOC_ENUM_FMT:
684 struct v4l2_fmtdesc *f = arg;
687 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
688 if (ops->vidioc_enum_fmt_vid_cap)
689 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
691 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
692 if (ops->vidioc_enum_fmt_vid_overlay)
693 ret = ops->vidioc_enum_fmt_vid_overlay(file,
696 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
697 if (ops->vidioc_enum_fmt_vid_out)
698 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
700 case V4L2_BUF_TYPE_PRIVATE:
701 if (ops->vidioc_enum_fmt_type_private)
702 ret = ops->vidioc_enum_fmt_type_private(file,
709 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
710 "pixelformat=%c%c%c%c, description='%s'\n",
711 f->index, f->type, f->flags,
712 (f->pixelformat & 0xff),
713 (f->pixelformat >> 8) & 0xff,
714 (f->pixelformat >> 16) & 0xff,
715 (f->pixelformat >> 24) & 0xff,
721 struct v4l2_format *f = (struct v4l2_format *)arg;
723 /* FIXME: Should be one dump per type */
724 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
727 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
728 if (ops->vidioc_g_fmt_vid_cap)
729 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
731 v4l_print_pix_fmt(vfd, &f->fmt.pix);
733 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
734 if (ops->vidioc_g_fmt_vid_overlay)
735 ret = ops->vidioc_g_fmt_vid_overlay(file,
738 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
739 if (ops->vidioc_g_fmt_vid_out)
740 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
742 v4l_print_pix_fmt(vfd, &f->fmt.pix);
744 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
745 if (ops->vidioc_g_fmt_vid_out_overlay)
746 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
749 case V4L2_BUF_TYPE_VBI_CAPTURE:
750 if (ops->vidioc_g_fmt_vbi_cap)
751 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
753 case V4L2_BUF_TYPE_VBI_OUTPUT:
754 if (ops->vidioc_g_fmt_vbi_out)
755 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
757 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
758 if (ops->vidioc_g_fmt_sliced_vbi_cap)
759 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
762 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
763 if (ops->vidioc_g_fmt_sliced_vbi_out)
764 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
767 case V4L2_BUF_TYPE_PRIVATE:
768 if (ops->vidioc_g_fmt_type_private)
769 ret = ops->vidioc_g_fmt_type_private(file,
778 struct v4l2_format *f = (struct v4l2_format *)arg;
780 /* FIXME: Should be one dump per type */
781 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
784 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
785 v4l_print_pix_fmt(vfd, &f->fmt.pix);
786 if (ops->vidioc_s_fmt_vid_cap)
787 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
789 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
790 if (ops->vidioc_s_fmt_vid_overlay)
791 ret = ops->vidioc_s_fmt_vid_overlay(file,
794 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
795 v4l_print_pix_fmt(vfd, &f->fmt.pix);
796 if (ops->vidioc_s_fmt_vid_out)
797 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
799 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
800 if (ops->vidioc_s_fmt_vid_out_overlay)
801 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
804 case V4L2_BUF_TYPE_VBI_CAPTURE:
805 if (ops->vidioc_s_fmt_vbi_cap)
806 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
808 case V4L2_BUF_TYPE_VBI_OUTPUT:
809 if (ops->vidioc_s_fmt_vbi_out)
810 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
812 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
813 if (ops->vidioc_s_fmt_sliced_vbi_cap)
814 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
817 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
818 if (ops->vidioc_s_fmt_sliced_vbi_out)
819 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
822 case V4L2_BUF_TYPE_PRIVATE:
823 if (ops->vidioc_s_fmt_type_private)
824 ret = ops->vidioc_s_fmt_type_private(file,
832 struct v4l2_format *f = (struct v4l2_format *)arg;
834 /* FIXME: Should be one dump per type */
835 dbgarg(cmd, "type=%s\n", prt_names(f->type,
838 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
839 if (ops->vidioc_try_fmt_vid_cap)
840 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
842 v4l_print_pix_fmt(vfd, &f->fmt.pix);
844 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
845 if (ops->vidioc_try_fmt_vid_overlay)
846 ret = ops->vidioc_try_fmt_vid_overlay(file,
849 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
850 if (ops->vidioc_try_fmt_vid_out)
851 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
853 v4l_print_pix_fmt(vfd, &f->fmt.pix);
855 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
856 if (ops->vidioc_try_fmt_vid_out_overlay)
857 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
860 case V4L2_BUF_TYPE_VBI_CAPTURE:
861 if (ops->vidioc_try_fmt_vbi_cap)
862 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
864 case V4L2_BUF_TYPE_VBI_OUTPUT:
865 if (ops->vidioc_try_fmt_vbi_out)
866 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
868 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
869 if (ops->vidioc_try_fmt_sliced_vbi_cap)
870 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
873 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
874 if (ops->vidioc_try_fmt_sliced_vbi_out)
875 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
878 case V4L2_BUF_TYPE_PRIVATE:
879 if (ops->vidioc_try_fmt_type_private)
880 ret = ops->vidioc_try_fmt_type_private(file,
887 /* FIXME: Those buf reqs could be handled here,
888 with some changes on videobuf to allow its header to be included at
889 videodev2.h or being merged at videodev2.
893 struct v4l2_requestbuffers *p = arg;
895 if (!ops->vidioc_reqbufs)
897 ret = check_fmt(ops, p->type);
901 ret = ops->vidioc_reqbufs(file, fh, p);
902 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
904 prt_names(p->type, v4l2_type_names),
905 prt_names(p->memory, v4l2_memory_names));
908 case VIDIOC_QUERYBUF:
910 struct v4l2_buffer *p = arg;
912 if (!ops->vidioc_querybuf)
914 ret = check_fmt(ops, p->type);
918 ret = ops->vidioc_querybuf(file, fh, p);
925 struct v4l2_buffer *p = arg;
927 if (!ops->vidioc_qbuf)
929 ret = check_fmt(ops, p->type);
933 ret = ops->vidioc_qbuf(file, fh, p);
940 struct v4l2_buffer *p = arg;
942 if (!ops->vidioc_dqbuf)
944 ret = check_fmt(ops, p->type);
948 ret = ops->vidioc_dqbuf(file, fh, p);
957 if (!ops->vidioc_overlay)
959 dbgarg(cmd, "value=%d\n", *i);
960 ret = ops->vidioc_overlay(file, fh, *i);
965 struct v4l2_framebuffer *p = arg;
967 if (!ops->vidioc_g_fbuf)
969 ret = ops->vidioc_g_fbuf(file, fh, arg);
971 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
972 p->capability, p->flags,
973 (unsigned long)p->base);
974 v4l_print_pix_fmt(vfd, &p->fmt);
980 struct v4l2_framebuffer *p = arg;
982 if (!ops->vidioc_s_fbuf)
984 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
985 p->capability, p->flags, (unsigned long)p->base);
986 v4l_print_pix_fmt(vfd, &p->fmt);
987 ret = ops->vidioc_s_fbuf(file, fh, arg);
990 case VIDIOC_STREAMON:
992 enum v4l2_buf_type i = *(int *)arg;
994 if (!ops->vidioc_streamon)
996 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
997 ret = ops->vidioc_streamon(file, fh, i);
1000 case VIDIOC_STREAMOFF:
1002 enum v4l2_buf_type i = *(int *)arg;
1004 if (!ops->vidioc_streamoff)
1006 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1007 ret = ops->vidioc_streamoff(file, fh, i);
1010 /* ---------- tv norms ---------- */
1011 case VIDIOC_ENUMSTD:
1013 struct v4l2_standard *p = arg;
1014 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1015 unsigned int index = p->index, i, j = 0;
1016 const char *descr = "";
1018 /* Return norm array in a canonical way */
1019 for (i = 0; i <= index && id; i++) {
1020 /* last std value in the standards array is 0, so this
1021 while always ends there since (id & 0) == 0. */
1022 while ((id & standards[j].std) != standards[j].std)
1024 curr_id = standards[j].std;
1025 descr = standards[j].descr;
1029 if (curr_id != V4L2_STD_PAL &&
1030 curr_id != V4L2_STD_SECAM &&
1031 curr_id != V4L2_STD_NTSC)
1037 v4l2_video_std_construct(p, curr_id, descr);
1039 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1040 "framelines=%d\n", p->index,
1041 (unsigned long long)p->id, p->name,
1042 p->frameperiod.numerator,
1043 p->frameperiod.denominator,
1051 v4l2_std_id *id = arg;
1054 /* Calls the specific handler */
1055 if (ops->vidioc_g_std)
1056 ret = ops->vidioc_g_std(file, fh, id);
1058 *id = vfd->current_norm;
1061 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1066 v4l2_std_id *id = arg, norm;
1068 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1070 norm = (*id) & vfd->tvnorms;
1071 if (vfd->tvnorms && !norm) /* Check if std is supported */
1074 /* Calls the specific handler */
1075 if (ops->vidioc_s_std)
1076 ret = ops->vidioc_s_std(file, fh, &norm);
1080 /* Updates standard information */
1082 vfd->current_norm = norm;
1085 case VIDIOC_QUERYSTD:
1087 v4l2_std_id *p = arg;
1089 if (!ops->vidioc_querystd)
1091 ret = ops->vidioc_querystd(file, fh, arg);
1093 dbgarg(cmd, "detected std=%08Lx\n",
1094 (unsigned long long)*p);
1097 /* ------ input switching ---------- */
1098 /* FIXME: Inputs can be handled inside videodev2 */
1099 case VIDIOC_ENUMINPUT:
1101 struct v4l2_input *p = arg;
1103 if (!ops->vidioc_enum_input)
1106 ret = ops->vidioc_enum_input(file, fh, p);
1108 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1110 "tuner=%d, std=%08Lx, status=%d\n",
1111 p->index, p->name, p->type, p->audioset,
1113 (unsigned long long)p->std,
1117 case VIDIOC_G_INPUT:
1119 unsigned int *i = arg;
1121 if (!ops->vidioc_g_input)
1123 ret = ops->vidioc_g_input(file, fh, i);
1125 dbgarg(cmd, "value=%d\n", *i);
1128 case VIDIOC_S_INPUT:
1130 unsigned int *i = arg;
1132 if (!ops->vidioc_s_input)
1134 dbgarg(cmd, "value=%d\n", *i);
1135 ret = ops->vidioc_s_input(file, fh, *i);
1139 /* ------ output switching ---------- */
1140 case VIDIOC_ENUMOUTPUT:
1142 struct v4l2_output *p = arg;
1144 if (!ops->vidioc_enum_output)
1147 ret = ops->vidioc_enum_output(file, fh, p);
1149 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1151 "modulator=%d, std=0x%08Lx\n",
1152 p->index, p->name, p->type, p->audioset,
1153 p->modulator, (unsigned long long)p->std);
1156 case VIDIOC_G_OUTPUT:
1158 unsigned int *i = arg;
1160 if (!ops->vidioc_g_output)
1162 ret = ops->vidioc_g_output(file, fh, i);
1164 dbgarg(cmd, "value=%d\n", *i);
1167 case VIDIOC_S_OUTPUT:
1169 unsigned int *i = arg;
1171 if (!ops->vidioc_s_output)
1173 dbgarg(cmd, "value=%d\n", *i);
1174 ret = ops->vidioc_s_output(file, fh, *i);
1178 /* --- controls ---------------------------------------------- */
1179 case VIDIOC_QUERYCTRL:
1181 struct v4l2_queryctrl *p = arg;
1183 if (!ops->vidioc_queryctrl)
1185 ret = ops->vidioc_queryctrl(file, fh, p);
1187 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1188 "step=%d, default=%d, flags=0x%08x\n",
1189 p->id, p->type, p->name,
1190 p->minimum, p->maximum,
1191 p->step, p->default_value, p->flags);
1193 dbgarg(cmd, "id=0x%x\n", p->id);
1198 struct v4l2_control *p = arg;
1200 if (ops->vidioc_g_ctrl)
1201 ret = ops->vidioc_g_ctrl(file, fh, p);
1202 else if (ops->vidioc_g_ext_ctrls) {
1203 struct v4l2_ext_controls ctrls;
1204 struct v4l2_ext_control ctrl;
1206 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1208 ctrls.controls = &ctrl;
1210 ctrl.value = p->value;
1211 if (check_ext_ctrls(&ctrls, 1)) {
1212 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1214 p->value = ctrl.value;
1219 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1221 dbgarg(cmd, "id=0x%x\n", p->id);
1226 struct v4l2_control *p = arg;
1227 struct v4l2_ext_controls ctrls;
1228 struct v4l2_ext_control ctrl;
1230 if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
1233 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1235 if (ops->vidioc_s_ctrl) {
1236 ret = ops->vidioc_s_ctrl(file, fh, p);
1239 if (!ops->vidioc_s_ext_ctrls)
1242 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1244 ctrls.controls = &ctrl;
1246 ctrl.value = p->value;
1247 if (check_ext_ctrls(&ctrls, 1))
1248 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1251 case VIDIOC_G_EXT_CTRLS:
1253 struct v4l2_ext_controls *p = arg;
1255 p->error_idx = p->count;
1256 if (!ops->vidioc_g_ext_ctrls)
1258 if (check_ext_ctrls(p, 0))
1259 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
1260 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1263 case VIDIOC_S_EXT_CTRLS:
1265 struct v4l2_ext_controls *p = arg;
1267 p->error_idx = p->count;
1268 if (!ops->vidioc_s_ext_ctrls)
1270 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1271 if (check_ext_ctrls(p, 0))
1272 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
1275 case VIDIOC_TRY_EXT_CTRLS:
1277 struct v4l2_ext_controls *p = arg;
1279 p->error_idx = p->count;
1280 if (!ops->vidioc_try_ext_ctrls)
1282 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1283 if (check_ext_ctrls(p, 0))
1284 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
1287 case VIDIOC_QUERYMENU:
1289 struct v4l2_querymenu *p = arg;
1291 if (!ops->vidioc_querymenu)
1293 ret = ops->vidioc_querymenu(file, fh, p);
1295 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1296 p->id, p->index, p->name);
1298 dbgarg(cmd, "id=0x%x, index=%d\n",
1302 /* --- audio ---------------------------------------------- */
1303 case VIDIOC_ENUMAUDIO:
1305 struct v4l2_audio *p = arg;
1307 if (!ops->vidioc_enumaudio)
1309 ret = ops->vidioc_enumaudio(file, fh, p);
1311 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1312 "mode=0x%x\n", p->index, p->name,
1313 p->capability, p->mode);
1315 dbgarg(cmd, "index=%d\n", p->index);
1318 case VIDIOC_G_AUDIO:
1320 struct v4l2_audio *p = arg;
1322 if (!ops->vidioc_g_audio)
1325 ret = ops->vidioc_g_audio(file, fh, p);
1327 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1328 "mode=0x%x\n", p->index,
1329 p->name, p->capability, p->mode);
1331 dbgarg(cmd, "index=%d\n", p->index);
1334 case VIDIOC_S_AUDIO:
1336 struct v4l2_audio *p = arg;
1338 if (!ops->vidioc_s_audio)
1340 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1341 "mode=0x%x\n", p->index, p->name,
1342 p->capability, p->mode);
1343 ret = ops->vidioc_s_audio(file, fh, p);
1346 case VIDIOC_ENUMAUDOUT:
1348 struct v4l2_audioout *p = arg;
1350 if (!ops->vidioc_enumaudout)
1352 dbgarg(cmd, "Enum for index=%d\n", p->index);
1353 ret = ops->vidioc_enumaudout(file, fh, p);
1355 dbgarg2("index=%d, name=%s, capability=%d, "
1356 "mode=%d\n", p->index, p->name,
1357 p->capability, p->mode);
1360 case VIDIOC_G_AUDOUT:
1362 struct v4l2_audioout *p = arg;
1364 if (!ops->vidioc_g_audout)
1367 ret = ops->vidioc_g_audout(file, fh, p);
1369 dbgarg2("index=%d, name=%s, capability=%d, "
1370 "mode=%d\n", p->index, p->name,
1371 p->capability, p->mode);
1374 case VIDIOC_S_AUDOUT:
1376 struct v4l2_audioout *p = arg;
1378 if (!ops->vidioc_s_audout)
1380 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1381 "mode=%d\n", p->index, p->name,
1382 p->capability, p->mode);
1384 ret = ops->vidioc_s_audout(file, fh, p);
1387 case VIDIOC_G_MODULATOR:
1389 struct v4l2_modulator *p = arg;
1391 if (!ops->vidioc_g_modulator)
1393 ret = ops->vidioc_g_modulator(file, fh, p);
1395 dbgarg(cmd, "index=%d, name=%s, "
1396 "capability=%d, rangelow=%d,"
1397 " rangehigh=%d, txsubchans=%d\n",
1398 p->index, p->name, p->capability,
1399 p->rangelow, p->rangehigh,
1403 case VIDIOC_S_MODULATOR:
1405 struct v4l2_modulator *p = arg;
1407 if (!ops->vidioc_s_modulator)
1409 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1410 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1411 p->index, p->name, p->capability, p->rangelow,
1412 p->rangehigh, p->txsubchans);
1413 ret = ops->vidioc_s_modulator(file, fh, p);
1418 struct v4l2_crop *p = arg;
1420 if (!ops->vidioc_g_crop)
1423 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1424 ret = ops->vidioc_g_crop(file, fh, p);
1426 dbgrect(vfd, "", &p->c);
1431 struct v4l2_crop *p = arg;
1433 if (!ops->vidioc_s_crop)
1435 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1436 dbgrect(vfd, "", &p->c);
1437 ret = ops->vidioc_s_crop(file, fh, p);
1440 case VIDIOC_CROPCAP:
1442 struct v4l2_cropcap *p = arg;
1444 /*FIXME: Should also show v4l2_fract pixelaspect */
1445 if (!ops->vidioc_cropcap)
1448 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1449 ret = ops->vidioc_cropcap(file, fh, p);
1451 dbgrect(vfd, "bounds ", &p->bounds);
1452 dbgrect(vfd, "defrect ", &p->defrect);
1456 case VIDIOC_G_JPEGCOMP:
1458 struct v4l2_jpegcompression *p = arg;
1460 if (!ops->vidioc_g_jpegcomp)
1463 ret = ops->vidioc_g_jpegcomp(file, fh, p);
1465 dbgarg(cmd, "quality=%d, APPn=%d, "
1466 "APP_len=%d, COM_len=%d, "
1467 "jpeg_markers=%d\n",
1468 p->quality, p->APPn, p->APP_len,
1469 p->COM_len, p->jpeg_markers);
1472 case VIDIOC_S_JPEGCOMP:
1474 struct v4l2_jpegcompression *p = arg;
1476 if (!ops->vidioc_g_jpegcomp)
1478 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1479 "COM_len=%d, jpeg_markers=%d\n",
1480 p->quality, p->APPn, p->APP_len,
1481 p->COM_len, p->jpeg_markers);
1482 ret = ops->vidioc_s_jpegcomp(file, fh, p);
1485 case VIDIOC_G_ENC_INDEX:
1487 struct v4l2_enc_idx *p = arg;
1489 if (!ops->vidioc_g_enc_index)
1491 ret = ops->vidioc_g_enc_index(file, fh, p);
1493 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1494 p->entries, p->entries_cap);
1497 case VIDIOC_ENCODER_CMD:
1499 struct v4l2_encoder_cmd *p = arg;
1501 if (!ops->vidioc_encoder_cmd)
1503 ret = ops->vidioc_encoder_cmd(file, fh, p);
1505 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1508 case VIDIOC_TRY_ENCODER_CMD:
1510 struct v4l2_encoder_cmd *p = arg;
1512 if (!ops->vidioc_try_encoder_cmd)
1514 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
1516 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1521 struct v4l2_streamparm *p = arg;
1523 if (ops->vidioc_g_parm) {
1524 ret = check_fmt(ops, p->type);
1527 ret = ops->vidioc_g_parm(file, fh, p);
1529 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1532 v4l2_video_std_frame_period(vfd->current_norm,
1533 &p->parm.capture.timeperframe);
1537 dbgarg(cmd, "type=%d\n", p->type);
1542 struct v4l2_streamparm *p = arg;
1544 if (!ops->vidioc_s_parm)
1546 ret = check_fmt(ops, p->type);
1550 dbgarg(cmd, "type=%d\n", p->type);
1551 ret = ops->vidioc_s_parm(file, fh, p);
1554 case VIDIOC_G_TUNER:
1556 struct v4l2_tuner *p = arg;
1558 if (!ops->vidioc_g_tuner)
1561 ret = ops->vidioc_g_tuner(file, fh, p);
1563 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1564 "capability=0x%x, rangelow=%d, "
1565 "rangehigh=%d, signal=%d, afc=%d, "
1566 "rxsubchans=0x%x, audmode=%d\n",
1567 p->index, p->name, p->type,
1568 p->capability, p->rangelow,
1569 p->rangehigh, p->signal, p->afc,
1570 p->rxsubchans, p->audmode);
1573 case VIDIOC_S_TUNER:
1575 struct v4l2_tuner *p = arg;
1577 if (!ops->vidioc_s_tuner)
1579 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1580 "capability=0x%x, rangelow=%d, "
1581 "rangehigh=%d, signal=%d, afc=%d, "
1582 "rxsubchans=0x%x, audmode=%d\n",
1583 p->index, p->name, p->type,
1584 p->capability, p->rangelow,
1585 p->rangehigh, p->signal, p->afc,
1586 p->rxsubchans, p->audmode);
1587 ret = ops->vidioc_s_tuner(file, fh, p);
1590 case VIDIOC_G_FREQUENCY:
1592 struct v4l2_frequency *p = arg;
1594 if (!ops->vidioc_g_frequency)
1597 ret = ops->vidioc_g_frequency(file, fh, p);
1599 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1600 p->tuner, p->type, p->frequency);
1603 case VIDIOC_S_FREQUENCY:
1605 struct v4l2_frequency *p = arg;
1607 if (!ops->vidioc_s_frequency)
1609 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1610 p->tuner, p->type, p->frequency);
1611 ret = ops->vidioc_s_frequency(file, fh, p);
1614 case VIDIOC_G_SLICED_VBI_CAP:
1616 struct v4l2_sliced_vbi_cap *p = arg;
1618 if (!ops->vidioc_g_sliced_vbi_cap)
1621 /* Clear up to type, everything after type is zerod already */
1622 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1624 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1625 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1627 dbgarg2("service_set=%d\n", p->service_set);
1630 case VIDIOC_LOG_STATUS:
1632 if (!ops->vidioc_log_status)
1634 ret = ops->vidioc_log_status(file, fh);
1637 #ifdef CONFIG_VIDEO_ADV_DEBUG
1638 case VIDIOC_DBG_G_REGISTER:
1640 struct v4l2_dbg_register *p = arg;
1642 if (!capable(CAP_SYS_ADMIN))
1644 else if (ops->vidioc_g_register)
1645 ret = ops->vidioc_g_register(file, fh, p);
1648 case VIDIOC_DBG_S_REGISTER:
1650 struct v4l2_dbg_register *p = arg;
1652 if (!capable(CAP_SYS_ADMIN))
1654 else if (ops->vidioc_s_register)
1655 ret = ops->vidioc_s_register(file, fh, p);
1659 case VIDIOC_DBG_G_CHIP_IDENT:
1661 struct v4l2_dbg_chip_ident *p = arg;
1663 if (!ops->vidioc_g_chip_ident)
1665 p->ident = V4L2_IDENT_NONE;
1667 ret = ops->vidioc_g_chip_ident(file, fh, p);
1669 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1672 case VIDIOC_S_HW_FREQ_SEEK:
1674 struct v4l2_hw_freq_seek *p = arg;
1676 if (!ops->vidioc_s_hw_freq_seek)
1679 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1680 p->tuner, p->type, p->seek_upward, p->wrap_around);
1681 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1684 case VIDIOC_ENUM_FRAMESIZES:
1686 struct v4l2_frmsizeenum *p = arg;
1688 if (!ops->vidioc_enum_framesizes)
1691 ret = ops->vidioc_enum_framesizes(file, fh, p);
1693 "index=%d, pixelformat=%d, type=%d ",
1694 p->index, p->pixel_format, p->type);
1696 case V4L2_FRMSIZE_TYPE_DISCRETE:
1697 dbgarg2("width = %d, height=%d\n",
1698 p->discrete.width, p->discrete.height);
1700 case V4L2_FRMSIZE_TYPE_STEPWISE:
1701 dbgarg2("min %dx%d, max %dx%d, step %dx%d\n",
1702 p->stepwise.min_width, p->stepwise.min_height,
1703 p->stepwise.step_width, p->stepwise.step_height,
1704 p->stepwise.max_width, p->stepwise.max_height);
1706 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1707 dbgarg2("continuous\n");
1710 dbgarg2("- Unknown type!\n");
1715 case VIDIOC_ENUM_FRAMEINTERVALS:
1717 struct v4l2_frmivalenum *p = arg;
1719 if (!ops->vidioc_enum_frameintervals)
1722 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1724 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1725 p->index, p->pixel_format,
1726 p->width, p->height, p->type);
1728 case V4L2_FRMIVAL_TYPE_DISCRETE:
1729 dbgarg2("fps=%d/%d\n",
1730 p->discrete.numerator,
1731 p->discrete.denominator);
1733 case V4L2_FRMIVAL_TYPE_STEPWISE:
1734 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1735 p->stepwise.min.numerator,
1736 p->stepwise.min.denominator,
1737 p->stepwise.max.numerator,
1738 p->stepwise.max.denominator,
1739 p->stepwise.step.numerator,
1740 p->stepwise.step.denominator);
1742 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1743 dbgarg2("continuous\n");
1746 dbgarg2("- Unknown type!\n");
1753 if (!ops->vidioc_default)
1755 ret = ops->vidioc_default(file, fh, cmd, arg);
1760 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1762 v4l_print_ioctl(vfd->name, cmd);
1763 printk(KERN_CONT " error %ld\n", ret);
1770 /* In some cases, only a few fields are used as input, i.e. when the app sets
1771 * "index" and then the driver fills in the rest of the structure for the thing
1772 * with that index. We only need to copy up the first non-input field. */
1773 static unsigned long cmd_input_size(unsigned int cmd)
1775 /* Size of structure up to and including 'field' */
1776 #define CMDINSIZE(cmd, type, field) \
1777 case VIDIOC_##cmd: \
1778 return offsetof(struct v4l2_##type, field) + \
1779 sizeof(((struct v4l2_##type *)0)->field);
1782 CMDINSIZE(ENUM_FMT, fmtdesc, type);
1783 CMDINSIZE(G_FMT, format, type);
1784 CMDINSIZE(QUERYBUF, buffer, type);
1785 CMDINSIZE(G_PARM, streamparm, type);
1786 CMDINSIZE(ENUMSTD, standard, index);
1787 CMDINSIZE(ENUMINPUT, input, index);
1788 CMDINSIZE(G_CTRL, control, id);
1789 CMDINSIZE(G_TUNER, tuner, index);
1790 CMDINSIZE(QUERYCTRL, queryctrl, id);
1791 CMDINSIZE(QUERYMENU, querymenu, index);
1792 CMDINSIZE(ENUMOUTPUT, output, index);
1793 CMDINSIZE(G_MODULATOR, modulator, index);
1794 CMDINSIZE(G_FREQUENCY, frequency, tuner);
1795 CMDINSIZE(CROPCAP, cropcap, type);
1796 CMDINSIZE(G_CROP, crop, type);
1797 CMDINSIZE(ENUMAUDIO, audio, index);
1798 CMDINSIZE(ENUMAUDOUT, audioout, index);
1799 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
1800 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
1801 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
1802 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
1803 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
1805 return _IOC_SIZE(cmd);
1809 long video_ioctl2(struct file *file,
1810 unsigned int cmd, unsigned long arg)
1817 size_t ctrls_size = 0;
1818 void __user *user_ptr = NULL;
1820 #ifdef __OLD_VIDIOC_
1821 cmd = video_fix_command(cmd);
1823 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1824 cmd == VIDIOC_TRY_EXT_CTRLS);
1826 /* Copy arguments into temp kernel buffer */
1827 if (_IOC_DIR(cmd) != _IOC_NONE) {
1828 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1831 /* too big to allocate from stack */
1832 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
1839 if (_IOC_DIR(cmd) & _IOC_WRITE) {
1840 unsigned long n = cmd_input_size(cmd);
1842 if (copy_from_user(parg, (void __user *)arg, n))
1845 /* zero out anything we don't copy from userspace */
1846 if (n < _IOC_SIZE(cmd))
1847 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
1849 /* read-only ioctl */
1850 memset(parg, 0, _IOC_SIZE(cmd));
1855 struct v4l2_ext_controls *p = parg;
1857 /* In case of an error, tell the caller that it wasn't
1858 a specific control that caused it. */
1859 p->error_idx = p->count;
1860 user_ptr = (void __user *)p->controls;
1862 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1863 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1864 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1869 if (copy_from_user(mbuf, user_ptr, ctrls_size))
1876 err = __video_do_ioctl(file, cmd, parg);
1877 if (err == -ENOIOCTLCMD)
1880 struct v4l2_ext_controls *p = parg;
1882 p->controls = (void *)user_ptr;
1883 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1891 /* Copy results into user buffer */
1892 switch (_IOC_DIR(cmd)) {
1894 case (_IOC_WRITE | _IOC_READ):
1895 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
1904 EXPORT_SYMBOL(video_ioctl2);