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);\
45 /* Zero out the end of the struct pointed to by p. Everthing after, but
46 * not including, the specified field is cleared. */
47 #define CLEAR_AFTER_FIELD(p, field) \
48 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
49 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
56 static const struct std_descr standards[] = {
57 { V4L2_STD_NTSC, "NTSC" },
58 { V4L2_STD_NTSC_M, "NTSC-M" },
59 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
60 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
61 { V4L2_STD_NTSC_443, "NTSC-443" },
62 { V4L2_STD_PAL, "PAL" },
63 { V4L2_STD_PAL_BG, "PAL-BG" },
64 { V4L2_STD_PAL_B, "PAL-B" },
65 { V4L2_STD_PAL_B1, "PAL-B1" },
66 { V4L2_STD_PAL_G, "PAL-G" },
67 { V4L2_STD_PAL_H, "PAL-H" },
68 { V4L2_STD_PAL_I, "PAL-I" },
69 { V4L2_STD_PAL_DK, "PAL-DK" },
70 { V4L2_STD_PAL_D, "PAL-D" },
71 { V4L2_STD_PAL_D1, "PAL-D1" },
72 { V4L2_STD_PAL_K, "PAL-K" },
73 { V4L2_STD_PAL_M, "PAL-M" },
74 { V4L2_STD_PAL_N, "PAL-N" },
75 { V4L2_STD_PAL_Nc, "PAL-Nc" },
76 { V4L2_STD_PAL_60, "PAL-60" },
77 { V4L2_STD_SECAM, "SECAM" },
78 { V4L2_STD_SECAM_B, "SECAM-B" },
79 { V4L2_STD_SECAM_G, "SECAM-G" },
80 { V4L2_STD_SECAM_H, "SECAM-H" },
81 { V4L2_STD_SECAM_DK, "SECAM-DK" },
82 { V4L2_STD_SECAM_D, "SECAM-D" },
83 { V4L2_STD_SECAM_K, "SECAM-K" },
84 { V4L2_STD_SECAM_K1, "SECAM-K1" },
85 { V4L2_STD_SECAM_L, "SECAM-L" },
86 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
90 /* video4linux standard ID conversion to standard name
92 const char *v4l2_norm_to_name(v4l2_std_id id)
97 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
98 64 bit comparations. So, on that architecture, with some gcc
99 variants, compilation fails. Currently, the max value is 30bit wide.
103 for (i = 0; standards[i].std; i++)
104 if (myid == standards[i].std)
106 return standards[i].descr;
108 EXPORT_SYMBOL(v4l2_norm_to_name);
110 /* Returns frame period for the given standard */
111 void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
113 if (id & V4L2_STD_525_60) {
114 frameperiod->numerator = 1001;
115 frameperiod->denominator = 30000;
117 frameperiod->numerator = 1;
118 frameperiod->denominator = 25;
121 EXPORT_SYMBOL(v4l2_video_std_frame_period);
123 /* Fill in the fields of a v4l2_standard structure according to the
124 'id' and 'transmission' parameters. Returns negative on error. */
125 int v4l2_video_std_construct(struct v4l2_standard *vs,
126 int id, const char *name)
129 v4l2_video_std_frame_period(id, &vs->frameperiod);
130 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
131 strlcpy(vs->name, name, sizeof(vs->name));
134 EXPORT_SYMBOL(v4l2_video_std_construct);
136 /* ----------------------------------------------------------------- */
137 /* some arrays for pretty-printing debug messages of enum types */
139 const char *v4l2_field_names[] = {
140 [V4L2_FIELD_ANY] = "any",
141 [V4L2_FIELD_NONE] = "none",
142 [V4L2_FIELD_TOP] = "top",
143 [V4L2_FIELD_BOTTOM] = "bottom",
144 [V4L2_FIELD_INTERLACED] = "interlaced",
145 [V4L2_FIELD_SEQ_TB] = "seq-tb",
146 [V4L2_FIELD_SEQ_BT] = "seq-bt",
147 [V4L2_FIELD_ALTERNATE] = "alternate",
148 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
149 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
151 EXPORT_SYMBOL(v4l2_field_names);
153 const char *v4l2_type_names[] = {
154 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
155 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
156 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
157 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
158 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
159 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
160 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
161 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
163 EXPORT_SYMBOL(v4l2_type_names);
165 static const char *v4l2_memory_names[] = {
166 [V4L2_MEMORY_MMAP] = "mmap",
167 [V4L2_MEMORY_USERPTR] = "userptr",
168 [V4L2_MEMORY_OVERLAY] = "overlay",
171 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
174 /* ------------------------------------------------------------------ */
175 /* debug help functions */
177 #ifdef CONFIG_VIDEO_V4L1_COMPAT
178 static const char *v4l1_ioctls[] = {
179 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
180 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
181 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
182 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
183 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
184 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
185 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
186 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
187 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
188 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
189 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
190 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
191 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
192 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
193 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
194 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
195 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
196 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
197 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
198 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
199 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
200 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
201 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
202 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
203 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
204 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
205 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
206 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
207 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
209 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
212 static const char *v4l2_ioctls[] = {
213 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
214 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
215 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
216 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
217 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
218 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
219 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
220 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
221 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
222 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
223 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
224 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
225 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
226 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
227 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
228 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
229 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
230 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
231 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
232 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
233 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
234 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
235 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
236 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
237 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
238 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
239 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
240 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
241 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
242 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
243 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
244 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
245 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
246 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
247 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
248 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
249 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
250 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
251 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
252 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
253 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
254 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
255 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
256 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
257 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
258 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
259 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
260 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
261 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
262 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
263 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
264 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
265 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
266 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
267 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
269 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
270 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
271 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
272 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
273 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
275 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
276 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
278 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
279 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
282 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
284 /* Common ioctl debug function. This function can be used by
285 external ioctl messages as well as internal V4L ioctl */
286 void v4l_printk_ioctl(unsigned int cmd)
290 switch (_IOC_TYPE(cmd)) {
294 #ifdef CONFIG_VIDEO_V4L1_COMPAT
296 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
300 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
304 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
308 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
314 switch (_IOC_DIR(cmd)) {
315 case _IOC_NONE: dir = "--"; break;
316 case _IOC_READ: dir = "r-"; break;
317 case _IOC_WRITE: dir = "-w"; break;
318 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
319 default: dir = "*ERR*"; break;
321 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
322 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
324 EXPORT_SYMBOL(v4l_printk_ioctl);
327 * helper function -- handles userspace copying for ioctl arguments
332 video_fix_command(unsigned int cmd)
335 case VIDIOC_OVERLAY_OLD:
336 cmd = VIDIOC_OVERLAY;
338 case VIDIOC_S_PARM_OLD:
341 case VIDIOC_S_CTRL_OLD:
344 case VIDIOC_G_AUDIO_OLD:
345 cmd = VIDIOC_G_AUDIO;
347 case VIDIOC_G_AUDOUT_OLD:
348 cmd = VIDIOC_G_AUDOUT;
350 case VIDIOC_CROPCAP_OLD:
351 cmd = VIDIOC_CROPCAP;
359 * Obsolete usercopy function - Should be removed soon
362 video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
370 size_t ctrls_size = 0;
371 void __user *user_ptr = NULL;
374 cmd = video_fix_command(cmd);
376 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
377 cmd == VIDIOC_TRY_EXT_CTRLS);
379 /* Copy arguments into temp kernel buffer */
380 switch (_IOC_DIR(cmd)) {
386 case (_IOC_WRITE | _IOC_READ):
387 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
390 /* too big to allocate from stack */
391 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
398 if (_IOC_DIR(cmd) & _IOC_WRITE)
399 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
404 struct v4l2_ext_controls *p = parg;
406 /* In case of an error, tell the caller that it wasn't
407 a specific control that caused it. */
408 p->error_idx = p->count;
409 user_ptr = (void __user *)p->controls;
411 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
412 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
413 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
418 if (copy_from_user(mbuf, user_ptr, ctrls_size))
425 err = func(file, cmd, parg);
426 if (err == -ENOIOCTLCMD)
429 struct v4l2_ext_controls *p = parg;
431 p->controls = (void *)user_ptr;
432 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
440 /* Copy results into user buffer */
441 switch (_IOC_DIR(cmd)) {
443 case (_IOC_WRITE | _IOC_READ):
444 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
453 EXPORT_SYMBOL(video_usercopy);
455 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
456 struct v4l2_buffer *p)
458 struct v4l2_timecode *tc = &p->timecode;
460 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
461 "bytesused=%d, flags=0x%08d, "
462 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
463 p->timestamp.tv_sec / 3600,
464 (int)(p->timestamp.tv_sec / 60) % 60,
465 (int)(p->timestamp.tv_sec % 60),
466 (long)p->timestamp.tv_usec,
468 prt_names(p->type, v4l2_type_names),
469 p->bytesused, p->flags,
470 p->field, p->sequence,
471 prt_names(p->memory, v4l2_memory_names),
472 p->m.userptr, p->length);
473 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
474 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
475 tc->hours, tc->minutes, tc->seconds,
476 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
479 static inline void dbgrect(struct video_device *vfd, char *s,
482 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
483 r->width, r->height);
486 static inline void v4l_print_pix_fmt(struct video_device *vfd,
487 struct v4l2_pix_format *fmt)
489 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
490 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
491 fmt->width, fmt->height,
492 (fmt->pixelformat & 0xff),
493 (fmt->pixelformat >> 8) & 0xff,
494 (fmt->pixelformat >> 16) & 0xff,
495 (fmt->pixelformat >> 24) & 0xff,
496 prt_names(fmt->field, v4l2_field_names),
497 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
500 static inline void v4l_print_ext_ctrls(unsigned int cmd,
501 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
505 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
508 printk(KERN_CONT "class=0x%x", c->ctrl_class);
509 for (i = 0; i < c->count; i++) {
511 printk(KERN_CONT " id/val=0x%x/0x%x",
512 c->controls[i].id, c->controls[i].value);
514 printk(KERN_CONT " id=0x%x", c->controls[i].id);
516 printk(KERN_CONT "\n");
519 static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
523 /* zero the reserved fields */
524 c->reserved[0] = c->reserved[1] = 0;
525 for (i = 0; i < c->count; i++) {
526 c->controls[i].reserved2[0] = 0;
527 c->controls[i].reserved2[1] = 0;
529 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
530 when using extended controls.
531 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
532 is it allowed for backwards compatibility.
534 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
536 /* Check that all controls are from the same control class. */
537 for (i = 0; i < c->count; i++) {
538 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
546 static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
552 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
553 if (ops->vidioc_g_fmt_vid_cap)
556 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
557 if (ops->vidioc_g_fmt_vid_overlay)
560 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
561 if (ops->vidioc_g_fmt_vid_out)
564 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
565 if (ops->vidioc_g_fmt_vid_out_overlay)
568 case V4L2_BUF_TYPE_VBI_CAPTURE:
569 if (ops->vidioc_g_fmt_vbi_cap)
572 case V4L2_BUF_TYPE_VBI_OUTPUT:
573 if (ops->vidioc_g_fmt_vbi_out)
576 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
577 if (ops->vidioc_g_fmt_sliced_vbi_cap)
580 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
581 if (ops->vidioc_g_fmt_sliced_vbi_out)
584 case V4L2_BUF_TYPE_PRIVATE:
585 if (ops->vidioc_g_fmt_type_private)
592 static long __video_do_ioctl(struct file *file,
593 unsigned int cmd, void *arg)
595 struct video_device *vfd = video_devdata(file);
596 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
597 void *fh = file->private_data;
600 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
601 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
602 v4l_print_ioctl(vfd->name, cmd);
603 printk(KERN_CONT "\n");
607 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
612 #ifdef CONFIG_VIDEO_V4L1_COMPAT
613 /***********************************************************
614 Handles calls to the obsoleted V4L1 API
615 Due to the nature of VIDIOCGMBUF, each driver that supports
616 V4L1 should implement its own handler for this ioctl.
617 ***********************************************************/
619 /* --- streaming capture ------------------------------------- */
620 if (cmd == VIDIOCGMBUF) {
621 struct video_mbuf *p = arg;
623 if (!ops->vidiocgmbuf)
625 ret = ops->vidiocgmbuf(file, fh, p);
627 dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
629 (unsigned long)p->offsets);
633 /********************************************************
634 All other V4L1 calls are handled by v4l1_compat module.
635 Those calls will be translated into V4L2 calls, and
636 __video_do_ioctl will be called again, with one or more
638 ********************************************************/
639 if (_IOC_TYPE(cmd) == 'v' && _IOC_NR(cmd) < BASE_VIDIOCPRIVATE)
640 return v4l_compat_translate_ioctl(file, cmd, arg,
645 /* --- capabilities ------------------------------------------ */
646 case VIDIOC_QUERYCAP:
648 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
650 if (!ops->vidioc_querycap)
653 ret = ops->vidioc_querycap(file, fh, cap);
655 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
657 "capabilities=0x%08x\n",
658 cap->driver, cap->card, cap->bus_info,
664 /* --- priority ------------------------------------------ */
665 case VIDIOC_G_PRIORITY:
667 enum v4l2_priority *p = arg;
669 if (!ops->vidioc_g_priority)
671 ret = ops->vidioc_g_priority(file, fh, p);
673 dbgarg(cmd, "priority is %d\n", *p);
676 case VIDIOC_S_PRIORITY:
678 enum v4l2_priority *p = arg;
680 if (!ops->vidioc_s_priority)
682 dbgarg(cmd, "setting priority to %d\n", *p);
683 ret = ops->vidioc_s_priority(file, fh, *p);
687 /* --- capture ioctls ---------------------------------------- */
688 case VIDIOC_ENUM_FMT:
690 struct v4l2_fmtdesc *f = arg;
693 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
694 if (ops->vidioc_enum_fmt_vid_cap)
695 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
697 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
698 if (ops->vidioc_enum_fmt_vid_overlay)
699 ret = ops->vidioc_enum_fmt_vid_overlay(file,
702 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
703 if (ops->vidioc_enum_fmt_vid_out)
704 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
706 case V4L2_BUF_TYPE_PRIVATE:
707 if (ops->vidioc_enum_fmt_type_private)
708 ret = ops->vidioc_enum_fmt_type_private(file,
715 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
716 "pixelformat=%c%c%c%c, description='%s'\n",
717 f->index, f->type, f->flags,
718 (f->pixelformat & 0xff),
719 (f->pixelformat >> 8) & 0xff,
720 (f->pixelformat >> 16) & 0xff,
721 (f->pixelformat >> 24) & 0xff,
727 struct v4l2_format *f = (struct v4l2_format *)arg;
729 /* FIXME: Should be one dump per type */
730 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
733 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
734 if (ops->vidioc_g_fmt_vid_cap)
735 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
737 v4l_print_pix_fmt(vfd, &f->fmt.pix);
739 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
740 if (ops->vidioc_g_fmt_vid_overlay)
741 ret = ops->vidioc_g_fmt_vid_overlay(file,
744 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
745 if (ops->vidioc_g_fmt_vid_out)
746 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
748 v4l_print_pix_fmt(vfd, &f->fmt.pix);
750 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
751 if (ops->vidioc_g_fmt_vid_out_overlay)
752 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
755 case V4L2_BUF_TYPE_VBI_CAPTURE:
756 if (ops->vidioc_g_fmt_vbi_cap)
757 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
759 case V4L2_BUF_TYPE_VBI_OUTPUT:
760 if (ops->vidioc_g_fmt_vbi_out)
761 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
763 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
764 if (ops->vidioc_g_fmt_sliced_vbi_cap)
765 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
768 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
769 if (ops->vidioc_g_fmt_sliced_vbi_out)
770 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
773 case V4L2_BUF_TYPE_PRIVATE:
774 if (ops->vidioc_g_fmt_type_private)
775 ret = ops->vidioc_g_fmt_type_private(file,
784 struct v4l2_format *f = (struct v4l2_format *)arg;
786 /* FIXME: Should be one dump per type */
787 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
790 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
791 CLEAR_AFTER_FIELD(f, fmt.pix);
792 v4l_print_pix_fmt(vfd, &f->fmt.pix);
793 if (ops->vidioc_s_fmt_vid_cap)
794 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
796 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
797 CLEAR_AFTER_FIELD(f, fmt.win);
798 if (ops->vidioc_s_fmt_vid_overlay)
799 ret = ops->vidioc_s_fmt_vid_overlay(file,
802 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
803 CLEAR_AFTER_FIELD(f, fmt.pix);
804 v4l_print_pix_fmt(vfd, &f->fmt.pix);
805 if (ops->vidioc_s_fmt_vid_out)
806 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
808 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
809 CLEAR_AFTER_FIELD(f, fmt.win);
810 if (ops->vidioc_s_fmt_vid_out_overlay)
811 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
814 case V4L2_BUF_TYPE_VBI_CAPTURE:
815 CLEAR_AFTER_FIELD(f, fmt.vbi);
816 if (ops->vidioc_s_fmt_vbi_cap)
817 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
819 case V4L2_BUF_TYPE_VBI_OUTPUT:
820 CLEAR_AFTER_FIELD(f, fmt.vbi);
821 if (ops->vidioc_s_fmt_vbi_out)
822 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
824 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
825 CLEAR_AFTER_FIELD(f, fmt.sliced);
826 if (ops->vidioc_s_fmt_sliced_vbi_cap)
827 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
830 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
831 CLEAR_AFTER_FIELD(f, fmt.sliced);
832 if (ops->vidioc_s_fmt_sliced_vbi_out)
833 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
836 case V4L2_BUF_TYPE_PRIVATE:
837 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
838 if (ops->vidioc_s_fmt_type_private)
839 ret = ops->vidioc_s_fmt_type_private(file,
847 struct v4l2_format *f = (struct v4l2_format *)arg;
849 /* FIXME: Should be one dump per type */
850 dbgarg(cmd, "type=%s\n", prt_names(f->type,
853 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
854 CLEAR_AFTER_FIELD(f, fmt.pix);
855 if (ops->vidioc_try_fmt_vid_cap)
856 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
858 v4l_print_pix_fmt(vfd, &f->fmt.pix);
860 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
861 CLEAR_AFTER_FIELD(f, fmt.win);
862 if (ops->vidioc_try_fmt_vid_overlay)
863 ret = ops->vidioc_try_fmt_vid_overlay(file,
866 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
867 CLEAR_AFTER_FIELD(f, fmt.pix);
868 if (ops->vidioc_try_fmt_vid_out)
869 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
871 v4l_print_pix_fmt(vfd, &f->fmt.pix);
873 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
874 CLEAR_AFTER_FIELD(f, fmt.win);
875 if (ops->vidioc_try_fmt_vid_out_overlay)
876 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
879 case V4L2_BUF_TYPE_VBI_CAPTURE:
880 CLEAR_AFTER_FIELD(f, fmt.vbi);
881 if (ops->vidioc_try_fmt_vbi_cap)
882 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
884 case V4L2_BUF_TYPE_VBI_OUTPUT:
885 CLEAR_AFTER_FIELD(f, fmt.vbi);
886 if (ops->vidioc_try_fmt_vbi_out)
887 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
889 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
890 CLEAR_AFTER_FIELD(f, fmt.sliced);
891 if (ops->vidioc_try_fmt_sliced_vbi_cap)
892 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
895 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
896 CLEAR_AFTER_FIELD(f, fmt.sliced);
897 if (ops->vidioc_try_fmt_sliced_vbi_out)
898 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
901 case V4L2_BUF_TYPE_PRIVATE:
902 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
903 if (ops->vidioc_try_fmt_type_private)
904 ret = ops->vidioc_try_fmt_type_private(file,
911 /* FIXME: Those buf reqs could be handled here,
912 with some changes on videobuf to allow its header to be included at
913 videodev2.h or being merged at videodev2.
917 struct v4l2_requestbuffers *p = arg;
919 if (!ops->vidioc_reqbufs)
921 ret = check_fmt(ops, p->type);
925 if (p->type < V4L2_BUF_TYPE_PRIVATE)
926 CLEAR_AFTER_FIELD(p, memory);
928 ret = ops->vidioc_reqbufs(file, fh, p);
929 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
931 prt_names(p->type, v4l2_type_names),
932 prt_names(p->memory, v4l2_memory_names));
935 case VIDIOC_QUERYBUF:
937 struct v4l2_buffer *p = arg;
939 if (!ops->vidioc_querybuf)
941 ret = check_fmt(ops, p->type);
945 ret = ops->vidioc_querybuf(file, fh, p);
952 struct v4l2_buffer *p = arg;
954 if (!ops->vidioc_qbuf)
956 ret = check_fmt(ops, p->type);
960 ret = ops->vidioc_qbuf(file, fh, p);
967 struct v4l2_buffer *p = arg;
969 if (!ops->vidioc_dqbuf)
971 ret = check_fmt(ops, p->type);
975 ret = ops->vidioc_dqbuf(file, fh, p);
984 if (!ops->vidioc_overlay)
986 dbgarg(cmd, "value=%d\n", *i);
987 ret = ops->vidioc_overlay(file, fh, *i);
992 struct v4l2_framebuffer *p = arg;
994 if (!ops->vidioc_g_fbuf)
996 ret = ops->vidioc_g_fbuf(file, fh, arg);
998 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
999 p->capability, p->flags,
1000 (unsigned long)p->base);
1001 v4l_print_pix_fmt(vfd, &p->fmt);
1007 struct v4l2_framebuffer *p = arg;
1009 if (!ops->vidioc_s_fbuf)
1011 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1012 p->capability, p->flags, (unsigned long)p->base);
1013 v4l_print_pix_fmt(vfd, &p->fmt);
1014 ret = ops->vidioc_s_fbuf(file, fh, arg);
1017 case VIDIOC_STREAMON:
1019 enum v4l2_buf_type i = *(int *)arg;
1021 if (!ops->vidioc_streamon)
1023 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1024 ret = ops->vidioc_streamon(file, fh, i);
1027 case VIDIOC_STREAMOFF:
1029 enum v4l2_buf_type i = *(int *)arg;
1031 if (!ops->vidioc_streamoff)
1033 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1034 ret = ops->vidioc_streamoff(file, fh, i);
1037 /* ---------- tv norms ---------- */
1038 case VIDIOC_ENUMSTD:
1040 struct v4l2_standard *p = arg;
1041 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1042 unsigned int index = p->index, i, j = 0;
1043 const char *descr = "";
1045 /* Return norm array in a canonical way */
1046 for (i = 0; i <= index && id; i++) {
1047 /* last std value in the standards array is 0, so this
1048 while always ends there since (id & 0) == 0. */
1049 while ((id & standards[j].std) != standards[j].std)
1051 curr_id = standards[j].std;
1052 descr = standards[j].descr;
1056 if (curr_id != V4L2_STD_PAL &&
1057 curr_id != V4L2_STD_SECAM &&
1058 curr_id != V4L2_STD_NTSC)
1064 v4l2_video_std_construct(p, curr_id, descr);
1066 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1067 "framelines=%d\n", p->index,
1068 (unsigned long long)p->id, p->name,
1069 p->frameperiod.numerator,
1070 p->frameperiod.denominator,
1078 v4l2_std_id *id = arg;
1081 /* Calls the specific handler */
1082 if (ops->vidioc_g_std)
1083 ret = ops->vidioc_g_std(file, fh, id);
1085 *id = vfd->current_norm;
1088 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1093 v4l2_std_id *id = arg, norm;
1095 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1097 norm = (*id) & vfd->tvnorms;
1098 if (vfd->tvnorms && !norm) /* Check if std is supported */
1101 /* Calls the specific handler */
1102 if (ops->vidioc_s_std)
1103 ret = ops->vidioc_s_std(file, fh, &norm);
1107 /* Updates standard information */
1109 vfd->current_norm = norm;
1112 case VIDIOC_QUERYSTD:
1114 v4l2_std_id *p = arg;
1116 if (!ops->vidioc_querystd)
1118 ret = ops->vidioc_querystd(file, fh, arg);
1120 dbgarg(cmd, "detected std=%08Lx\n",
1121 (unsigned long long)*p);
1124 /* ------ input switching ---------- */
1125 /* FIXME: Inputs can be handled inside videodev2 */
1126 case VIDIOC_ENUMINPUT:
1128 struct v4l2_input *p = arg;
1130 if (!ops->vidioc_enum_input)
1133 ret = ops->vidioc_enum_input(file, fh, p);
1135 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1137 "tuner=%d, std=%08Lx, status=%d\n",
1138 p->index, p->name, p->type, p->audioset,
1140 (unsigned long long)p->std,
1144 case VIDIOC_G_INPUT:
1146 unsigned int *i = arg;
1148 if (!ops->vidioc_g_input)
1150 ret = ops->vidioc_g_input(file, fh, i);
1152 dbgarg(cmd, "value=%d\n", *i);
1155 case VIDIOC_S_INPUT:
1157 unsigned int *i = arg;
1159 if (!ops->vidioc_s_input)
1161 dbgarg(cmd, "value=%d\n", *i);
1162 ret = ops->vidioc_s_input(file, fh, *i);
1166 /* ------ output switching ---------- */
1167 case VIDIOC_ENUMOUTPUT:
1169 struct v4l2_output *p = arg;
1171 if (!ops->vidioc_enum_output)
1174 ret = ops->vidioc_enum_output(file, fh, p);
1176 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1178 "modulator=%d, std=0x%08Lx\n",
1179 p->index, p->name, p->type, p->audioset,
1180 p->modulator, (unsigned long long)p->std);
1183 case VIDIOC_G_OUTPUT:
1185 unsigned int *i = arg;
1187 if (!ops->vidioc_g_output)
1189 ret = ops->vidioc_g_output(file, fh, i);
1191 dbgarg(cmd, "value=%d\n", *i);
1194 case VIDIOC_S_OUTPUT:
1196 unsigned int *i = arg;
1198 if (!ops->vidioc_s_output)
1200 dbgarg(cmd, "value=%d\n", *i);
1201 ret = ops->vidioc_s_output(file, fh, *i);
1205 /* --- controls ---------------------------------------------- */
1206 case VIDIOC_QUERYCTRL:
1208 struct v4l2_queryctrl *p = arg;
1210 if (!ops->vidioc_queryctrl)
1212 ret = ops->vidioc_queryctrl(file, fh, p);
1214 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1215 "step=%d, default=%d, flags=0x%08x\n",
1216 p->id, p->type, p->name,
1217 p->minimum, p->maximum,
1218 p->step, p->default_value, p->flags);
1220 dbgarg(cmd, "id=0x%x\n", p->id);
1225 struct v4l2_control *p = arg;
1227 if (ops->vidioc_g_ctrl)
1228 ret = ops->vidioc_g_ctrl(file, fh, p);
1229 else if (ops->vidioc_g_ext_ctrls) {
1230 struct v4l2_ext_controls ctrls;
1231 struct v4l2_ext_control ctrl;
1233 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1235 ctrls.controls = &ctrl;
1237 ctrl.value = p->value;
1238 if (check_ext_ctrls(&ctrls, 1)) {
1239 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1241 p->value = ctrl.value;
1246 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1248 dbgarg(cmd, "id=0x%x\n", p->id);
1253 struct v4l2_control *p = arg;
1254 struct v4l2_ext_controls ctrls;
1255 struct v4l2_ext_control ctrl;
1257 if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
1260 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1262 if (ops->vidioc_s_ctrl) {
1263 ret = ops->vidioc_s_ctrl(file, fh, p);
1266 if (!ops->vidioc_s_ext_ctrls)
1269 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1271 ctrls.controls = &ctrl;
1273 ctrl.value = p->value;
1274 if (check_ext_ctrls(&ctrls, 1))
1275 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1278 case VIDIOC_G_EXT_CTRLS:
1280 struct v4l2_ext_controls *p = arg;
1282 p->error_idx = p->count;
1283 if (!ops->vidioc_g_ext_ctrls)
1285 if (check_ext_ctrls(p, 0))
1286 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
1287 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1290 case VIDIOC_S_EXT_CTRLS:
1292 struct v4l2_ext_controls *p = arg;
1294 p->error_idx = p->count;
1295 if (!ops->vidioc_s_ext_ctrls)
1297 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1298 if (check_ext_ctrls(p, 0))
1299 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
1302 case VIDIOC_TRY_EXT_CTRLS:
1304 struct v4l2_ext_controls *p = arg;
1306 p->error_idx = p->count;
1307 if (!ops->vidioc_try_ext_ctrls)
1309 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1310 if (check_ext_ctrls(p, 0))
1311 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
1314 case VIDIOC_QUERYMENU:
1316 struct v4l2_querymenu *p = arg;
1318 if (!ops->vidioc_querymenu)
1320 ret = ops->vidioc_querymenu(file, fh, p);
1322 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1323 p->id, p->index, p->name);
1325 dbgarg(cmd, "id=0x%x, index=%d\n",
1329 /* --- audio ---------------------------------------------- */
1330 case VIDIOC_ENUMAUDIO:
1332 struct v4l2_audio *p = arg;
1334 if (!ops->vidioc_enumaudio)
1336 ret = ops->vidioc_enumaudio(file, fh, p);
1338 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1339 "mode=0x%x\n", p->index, p->name,
1340 p->capability, p->mode);
1342 dbgarg(cmd, "index=%d\n", p->index);
1345 case VIDIOC_G_AUDIO:
1347 struct v4l2_audio *p = arg;
1349 if (!ops->vidioc_g_audio)
1352 ret = ops->vidioc_g_audio(file, fh, p);
1354 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1355 "mode=0x%x\n", p->index,
1356 p->name, p->capability, p->mode);
1358 dbgarg(cmd, "index=%d\n", p->index);
1361 case VIDIOC_S_AUDIO:
1363 struct v4l2_audio *p = arg;
1365 if (!ops->vidioc_s_audio)
1367 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1368 "mode=0x%x\n", p->index, p->name,
1369 p->capability, p->mode);
1370 ret = ops->vidioc_s_audio(file, fh, p);
1373 case VIDIOC_ENUMAUDOUT:
1375 struct v4l2_audioout *p = arg;
1377 if (!ops->vidioc_enumaudout)
1379 dbgarg(cmd, "Enum for index=%d\n", p->index);
1380 ret = ops->vidioc_enumaudout(file, fh, p);
1382 dbgarg2("index=%d, name=%s, capability=%d, "
1383 "mode=%d\n", p->index, p->name,
1384 p->capability, p->mode);
1387 case VIDIOC_G_AUDOUT:
1389 struct v4l2_audioout *p = arg;
1391 if (!ops->vidioc_g_audout)
1394 ret = ops->vidioc_g_audout(file, fh, p);
1396 dbgarg2("index=%d, name=%s, capability=%d, "
1397 "mode=%d\n", p->index, p->name,
1398 p->capability, p->mode);
1401 case VIDIOC_S_AUDOUT:
1403 struct v4l2_audioout *p = arg;
1405 if (!ops->vidioc_s_audout)
1407 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1408 "mode=%d\n", p->index, p->name,
1409 p->capability, p->mode);
1411 ret = ops->vidioc_s_audout(file, fh, p);
1414 case VIDIOC_G_MODULATOR:
1416 struct v4l2_modulator *p = arg;
1418 if (!ops->vidioc_g_modulator)
1420 ret = ops->vidioc_g_modulator(file, fh, p);
1422 dbgarg(cmd, "index=%d, name=%s, "
1423 "capability=%d, rangelow=%d,"
1424 " rangehigh=%d, txsubchans=%d\n",
1425 p->index, p->name, p->capability,
1426 p->rangelow, p->rangehigh,
1430 case VIDIOC_S_MODULATOR:
1432 struct v4l2_modulator *p = arg;
1434 if (!ops->vidioc_s_modulator)
1436 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1437 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1438 p->index, p->name, p->capability, p->rangelow,
1439 p->rangehigh, p->txsubchans);
1440 ret = ops->vidioc_s_modulator(file, fh, p);
1445 struct v4l2_crop *p = arg;
1447 if (!ops->vidioc_g_crop)
1450 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1451 ret = ops->vidioc_g_crop(file, fh, p);
1453 dbgrect(vfd, "", &p->c);
1458 struct v4l2_crop *p = arg;
1460 if (!ops->vidioc_s_crop)
1462 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1463 dbgrect(vfd, "", &p->c);
1464 ret = ops->vidioc_s_crop(file, fh, p);
1467 case VIDIOC_CROPCAP:
1469 struct v4l2_cropcap *p = arg;
1471 /*FIXME: Should also show v4l2_fract pixelaspect */
1472 if (!ops->vidioc_cropcap)
1475 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1476 ret = ops->vidioc_cropcap(file, fh, p);
1478 dbgrect(vfd, "bounds ", &p->bounds);
1479 dbgrect(vfd, "defrect ", &p->defrect);
1483 case VIDIOC_G_JPEGCOMP:
1485 struct v4l2_jpegcompression *p = arg;
1487 if (!ops->vidioc_g_jpegcomp)
1490 ret = ops->vidioc_g_jpegcomp(file, fh, p);
1492 dbgarg(cmd, "quality=%d, APPn=%d, "
1493 "APP_len=%d, COM_len=%d, "
1494 "jpeg_markers=%d\n",
1495 p->quality, p->APPn, p->APP_len,
1496 p->COM_len, p->jpeg_markers);
1499 case VIDIOC_S_JPEGCOMP:
1501 struct v4l2_jpegcompression *p = arg;
1503 if (!ops->vidioc_g_jpegcomp)
1505 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1506 "COM_len=%d, jpeg_markers=%d\n",
1507 p->quality, p->APPn, p->APP_len,
1508 p->COM_len, p->jpeg_markers);
1509 ret = ops->vidioc_s_jpegcomp(file, fh, p);
1512 case VIDIOC_G_ENC_INDEX:
1514 struct v4l2_enc_idx *p = arg;
1516 if (!ops->vidioc_g_enc_index)
1518 ret = ops->vidioc_g_enc_index(file, fh, p);
1520 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1521 p->entries, p->entries_cap);
1524 case VIDIOC_ENCODER_CMD:
1526 struct v4l2_encoder_cmd *p = arg;
1528 if (!ops->vidioc_encoder_cmd)
1530 ret = ops->vidioc_encoder_cmd(file, fh, p);
1532 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1535 case VIDIOC_TRY_ENCODER_CMD:
1537 struct v4l2_encoder_cmd *p = arg;
1539 if (!ops->vidioc_try_encoder_cmd)
1541 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
1543 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1548 struct v4l2_streamparm *p = arg;
1550 if (ops->vidioc_g_parm) {
1551 ret = check_fmt(ops, p->type);
1554 ret = ops->vidioc_g_parm(file, fh, p);
1556 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1559 v4l2_video_std_frame_period(vfd->current_norm,
1560 &p->parm.capture.timeperframe);
1564 dbgarg(cmd, "type=%d\n", p->type);
1569 struct v4l2_streamparm *p = arg;
1571 if (!ops->vidioc_s_parm)
1573 ret = check_fmt(ops, p->type);
1577 dbgarg(cmd, "type=%d\n", p->type);
1578 ret = ops->vidioc_s_parm(file, fh, p);
1581 case VIDIOC_G_TUNER:
1583 struct v4l2_tuner *p = arg;
1585 if (!ops->vidioc_g_tuner)
1588 ret = ops->vidioc_g_tuner(file, fh, p);
1590 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1591 "capability=0x%x, rangelow=%d, "
1592 "rangehigh=%d, signal=%d, afc=%d, "
1593 "rxsubchans=0x%x, audmode=%d\n",
1594 p->index, p->name, p->type,
1595 p->capability, p->rangelow,
1596 p->rangehigh, p->signal, p->afc,
1597 p->rxsubchans, p->audmode);
1600 case VIDIOC_S_TUNER:
1602 struct v4l2_tuner *p = arg;
1604 if (!ops->vidioc_s_tuner)
1606 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1607 "capability=0x%x, rangelow=%d, "
1608 "rangehigh=%d, signal=%d, afc=%d, "
1609 "rxsubchans=0x%x, audmode=%d\n",
1610 p->index, p->name, p->type,
1611 p->capability, p->rangelow,
1612 p->rangehigh, p->signal, p->afc,
1613 p->rxsubchans, p->audmode);
1614 ret = ops->vidioc_s_tuner(file, fh, p);
1617 case VIDIOC_G_FREQUENCY:
1619 struct v4l2_frequency *p = arg;
1621 if (!ops->vidioc_g_frequency)
1624 ret = ops->vidioc_g_frequency(file, fh, p);
1626 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1627 p->tuner, p->type, p->frequency);
1630 case VIDIOC_S_FREQUENCY:
1632 struct v4l2_frequency *p = arg;
1634 if (!ops->vidioc_s_frequency)
1636 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1637 p->tuner, p->type, p->frequency);
1638 ret = ops->vidioc_s_frequency(file, fh, p);
1641 case VIDIOC_G_SLICED_VBI_CAP:
1643 struct v4l2_sliced_vbi_cap *p = arg;
1645 if (!ops->vidioc_g_sliced_vbi_cap)
1648 /* Clear up to type, everything after type is zerod already */
1649 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1651 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1652 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1654 dbgarg2("service_set=%d\n", p->service_set);
1657 case VIDIOC_LOG_STATUS:
1659 if (!ops->vidioc_log_status)
1661 ret = ops->vidioc_log_status(file, fh);
1664 #ifdef CONFIG_VIDEO_ADV_DEBUG
1665 case VIDIOC_DBG_G_REGISTER:
1667 struct v4l2_dbg_register *p = arg;
1669 if (!capable(CAP_SYS_ADMIN))
1671 else if (ops->vidioc_g_register)
1672 ret = ops->vidioc_g_register(file, fh, p);
1675 case VIDIOC_DBG_S_REGISTER:
1677 struct v4l2_dbg_register *p = arg;
1679 if (!capable(CAP_SYS_ADMIN))
1681 else if (ops->vidioc_s_register)
1682 ret = ops->vidioc_s_register(file, fh, p);
1686 case VIDIOC_DBG_G_CHIP_IDENT:
1688 struct v4l2_dbg_chip_ident *p = arg;
1690 if (!ops->vidioc_g_chip_ident)
1692 p->ident = V4L2_IDENT_NONE;
1694 ret = ops->vidioc_g_chip_ident(file, fh, p);
1696 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1699 case VIDIOC_S_HW_FREQ_SEEK:
1701 struct v4l2_hw_freq_seek *p = arg;
1703 if (!ops->vidioc_s_hw_freq_seek)
1706 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1707 p->tuner, p->type, p->seek_upward, p->wrap_around);
1708 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1711 case VIDIOC_ENUM_FRAMESIZES:
1713 struct v4l2_frmsizeenum *p = arg;
1715 if (!ops->vidioc_enum_framesizes)
1718 ret = ops->vidioc_enum_framesizes(file, fh, p);
1720 "index=%d, pixelformat=%d, type=%d ",
1721 p->index, p->pixel_format, p->type);
1723 case V4L2_FRMSIZE_TYPE_DISCRETE:
1724 dbgarg2("width = %d, height=%d\n",
1725 p->discrete.width, p->discrete.height);
1727 case V4L2_FRMSIZE_TYPE_STEPWISE:
1728 dbgarg2("min %dx%d, max %dx%d, step %dx%d\n",
1729 p->stepwise.min_width, p->stepwise.min_height,
1730 p->stepwise.step_width, p->stepwise.step_height,
1731 p->stepwise.max_width, p->stepwise.max_height);
1733 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1734 dbgarg2("continuous\n");
1737 dbgarg2("- Unknown type!\n");
1742 case VIDIOC_ENUM_FRAMEINTERVALS:
1744 struct v4l2_frmivalenum *p = arg;
1746 if (!ops->vidioc_enum_frameintervals)
1749 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1751 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1752 p->index, p->pixel_format,
1753 p->width, p->height, p->type);
1755 case V4L2_FRMIVAL_TYPE_DISCRETE:
1756 dbgarg2("fps=%d/%d\n",
1757 p->discrete.numerator,
1758 p->discrete.denominator);
1760 case V4L2_FRMIVAL_TYPE_STEPWISE:
1761 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1762 p->stepwise.min.numerator,
1763 p->stepwise.min.denominator,
1764 p->stepwise.max.numerator,
1765 p->stepwise.max.denominator,
1766 p->stepwise.step.numerator,
1767 p->stepwise.step.denominator);
1769 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1770 dbgarg2("continuous\n");
1773 dbgarg2("- Unknown type!\n");
1780 if (!ops->vidioc_default)
1782 ret = ops->vidioc_default(file, fh, cmd, arg);
1787 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1789 v4l_print_ioctl(vfd->name, cmd);
1790 printk(KERN_CONT " error %ld\n", ret);
1797 /* In some cases, only a few fields are used as input, i.e. when the app sets
1798 * "index" and then the driver fills in the rest of the structure for the thing
1799 * with that index. We only need to copy up the first non-input field. */
1800 static unsigned long cmd_input_size(unsigned int cmd)
1802 /* Size of structure up to and including 'field' */
1803 #define CMDINSIZE(cmd, type, field) \
1804 case VIDIOC_##cmd: \
1805 return offsetof(struct v4l2_##type, field) + \
1806 sizeof(((struct v4l2_##type *)0)->field);
1809 CMDINSIZE(ENUM_FMT, fmtdesc, type);
1810 CMDINSIZE(G_FMT, format, type);
1811 CMDINSIZE(QUERYBUF, buffer, type);
1812 CMDINSIZE(G_PARM, streamparm, type);
1813 CMDINSIZE(ENUMSTD, standard, index);
1814 CMDINSIZE(ENUMINPUT, input, index);
1815 CMDINSIZE(G_CTRL, control, id);
1816 CMDINSIZE(G_TUNER, tuner, index);
1817 CMDINSIZE(QUERYCTRL, queryctrl, id);
1818 CMDINSIZE(QUERYMENU, querymenu, index);
1819 CMDINSIZE(ENUMOUTPUT, output, index);
1820 CMDINSIZE(G_MODULATOR, modulator, index);
1821 CMDINSIZE(G_FREQUENCY, frequency, tuner);
1822 CMDINSIZE(CROPCAP, cropcap, type);
1823 CMDINSIZE(G_CROP, crop, type);
1824 CMDINSIZE(ENUMAUDIO, audio, index);
1825 CMDINSIZE(ENUMAUDOUT, audioout, index);
1826 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
1827 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
1828 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
1829 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
1830 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
1832 return _IOC_SIZE(cmd);
1836 long video_ioctl2(struct file *file,
1837 unsigned int cmd, unsigned long arg)
1844 size_t ctrls_size = 0;
1845 void __user *user_ptr = NULL;
1847 #ifdef __OLD_VIDIOC_
1848 cmd = video_fix_command(cmd);
1850 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1851 cmd == VIDIOC_TRY_EXT_CTRLS);
1853 /* Copy arguments into temp kernel buffer */
1854 if (_IOC_DIR(cmd) != _IOC_NONE) {
1855 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1858 /* too big to allocate from stack */
1859 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
1866 if (_IOC_DIR(cmd) & _IOC_WRITE) {
1867 unsigned long n = cmd_input_size(cmd);
1869 if (copy_from_user(parg, (void __user *)arg, n))
1872 /* zero out anything we don't copy from userspace */
1873 if (n < _IOC_SIZE(cmd))
1874 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
1876 /* read-only ioctl */
1877 memset(parg, 0, _IOC_SIZE(cmd));
1882 struct v4l2_ext_controls *p = parg;
1884 /* In case of an error, tell the caller that it wasn't
1885 a specific control that caused it. */
1886 p->error_idx = p->count;
1887 user_ptr = (void __user *)p->controls;
1889 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1890 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1891 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1896 if (copy_from_user(mbuf, user_ptr, ctrls_size))
1903 err = __video_do_ioctl(file, cmd, parg);
1904 if (err == -ENOIOCTLCMD)
1907 struct v4l2_ext_controls *p = parg;
1909 p->controls = (void *)user_ptr;
1910 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1918 /* Copy results into user buffer */
1919 switch (_IOC_DIR(cmd)) {
1921 case (_IOC_WRITE | _IOC_READ):
1922 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
1931 EXPORT_SYMBOL(video_ioctl2);