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/videodev2.h>
22 #ifdef CONFIG_VIDEO_V4L1
23 #include <linux/videodev.h>
25 #include <media/v4l2-common.h>
26 #include <media/v4l2-ioctl.h>
27 #include <media/v4l2-chip-ident.h>
29 #define dbgarg(cmd, fmt, arg...) \
31 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
32 printk(KERN_DEBUG "%s: ", vfd->name); \
33 v4l_printk_ioctl(cmd); \
34 printk(" " fmt, ## arg); \
38 #define dbgarg2(fmt, arg...) \
40 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
41 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
49 static const struct std_descr standards[] = {
50 { V4L2_STD_NTSC, "NTSC" },
51 { V4L2_STD_NTSC_M, "NTSC-M" },
52 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
53 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
54 { V4L2_STD_NTSC_443, "NTSC-443" },
55 { V4L2_STD_PAL, "PAL" },
56 { V4L2_STD_PAL_BG, "PAL-BG" },
57 { V4L2_STD_PAL_B, "PAL-B" },
58 { V4L2_STD_PAL_B1, "PAL-B1" },
59 { V4L2_STD_PAL_G, "PAL-G" },
60 { V4L2_STD_PAL_H, "PAL-H" },
61 { V4L2_STD_PAL_I, "PAL-I" },
62 { V4L2_STD_PAL_DK, "PAL-DK" },
63 { V4L2_STD_PAL_D, "PAL-D" },
64 { V4L2_STD_PAL_D1, "PAL-D1" },
65 { V4L2_STD_PAL_K, "PAL-K" },
66 { V4L2_STD_PAL_M, "PAL-M" },
67 { V4L2_STD_PAL_N, "PAL-N" },
68 { V4L2_STD_PAL_Nc, "PAL-Nc" },
69 { V4L2_STD_PAL_60, "PAL-60" },
70 { V4L2_STD_SECAM, "SECAM" },
71 { V4L2_STD_SECAM_B, "SECAM-B" },
72 { V4L2_STD_SECAM_G, "SECAM-G" },
73 { V4L2_STD_SECAM_H, "SECAM-H" },
74 { V4L2_STD_SECAM_DK, "SECAM-DK" },
75 { V4L2_STD_SECAM_D, "SECAM-D" },
76 { V4L2_STD_SECAM_K, "SECAM-K" },
77 { V4L2_STD_SECAM_K1, "SECAM-K1" },
78 { V4L2_STD_SECAM_L, "SECAM-L" },
79 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
83 /* video4linux standard ID conversion to standard name
85 const char *v4l2_norm_to_name(v4l2_std_id id)
90 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
91 64 bit comparations. So, on that architecture, with some gcc
92 variants, compilation fails. Currently, the max value is 30bit wide.
96 for (i = 0; standards[i].std; i++)
97 if (myid == standards[i].std)
99 return standards[i].descr;
101 EXPORT_SYMBOL(v4l2_norm_to_name);
103 /* Returns frame period for the given standard */
104 void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
106 if (id & V4L2_STD_525_60) {
107 frameperiod->numerator = 1001;
108 frameperiod->denominator = 30000;
110 frameperiod->numerator = 1;
111 frameperiod->denominator = 25;
114 EXPORT_SYMBOL(v4l2_video_std_frame_period);
116 /* Fill in the fields of a v4l2_standard structure according to the
117 'id' and 'transmission' parameters. Returns negative on error. */
118 int v4l2_video_std_construct(struct v4l2_standard *vs,
119 int id, const char *name)
122 v4l2_video_std_frame_period(id, &vs->frameperiod);
123 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
124 strlcpy(vs->name, name, sizeof(vs->name));
127 EXPORT_SYMBOL(v4l2_video_std_construct);
129 /* ----------------------------------------------------------------- */
130 /* some arrays for pretty-printing debug messages of enum types */
132 const char *v4l2_field_names[] = {
133 [V4L2_FIELD_ANY] = "any",
134 [V4L2_FIELD_NONE] = "none",
135 [V4L2_FIELD_TOP] = "top",
136 [V4L2_FIELD_BOTTOM] = "bottom",
137 [V4L2_FIELD_INTERLACED] = "interlaced",
138 [V4L2_FIELD_SEQ_TB] = "seq-tb",
139 [V4L2_FIELD_SEQ_BT] = "seq-bt",
140 [V4L2_FIELD_ALTERNATE] = "alternate",
141 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
142 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
144 EXPORT_SYMBOL(v4l2_field_names);
146 const char *v4l2_type_names[] = {
147 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
148 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
149 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
150 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
151 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
152 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
153 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
154 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
156 EXPORT_SYMBOL(v4l2_type_names);
158 static const char *v4l2_memory_names[] = {
159 [V4L2_MEMORY_MMAP] = "mmap",
160 [V4L2_MEMORY_USERPTR] = "userptr",
161 [V4L2_MEMORY_OVERLAY] = "overlay",
164 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
167 /* ------------------------------------------------------------------ */
168 /* debug help functions */
170 #ifdef CONFIG_VIDEO_V4L1_COMPAT
171 static const char *v4l1_ioctls[] = {
172 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
173 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
174 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
175 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
176 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
177 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
178 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
179 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
180 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
181 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
182 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
183 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
184 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
185 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
186 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
187 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
188 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
189 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
190 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
191 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
192 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
193 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
194 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
195 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
196 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
197 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
198 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
199 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
200 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
202 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
205 static const char *v4l2_ioctls[] = {
206 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
207 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
208 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
209 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
210 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
211 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
212 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
213 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
214 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
215 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
216 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
217 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
218 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
219 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
220 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
221 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
222 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
223 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
224 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
225 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
226 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
227 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
228 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
229 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
230 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
231 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
232 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
233 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
234 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
235 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
236 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
237 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
238 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
239 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
240 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
241 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
242 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
243 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
244 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
245 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
246 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
247 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
248 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
249 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
250 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
251 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
252 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
253 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
254 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
255 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
256 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
257 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
258 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
259 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
260 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
262 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
263 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
264 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
265 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
266 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
268 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
269 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
271 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
272 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
275 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
277 static const char *v4l2_int_ioctls[] = {
278 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
280 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
281 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
282 [_IOC_NR(TUNER_SET_CONFIG)] = "TUNER_SET_CONFIG",
284 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
285 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
286 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
287 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
288 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
289 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
290 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
291 [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
292 [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
293 [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
294 [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
295 [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING",
296 [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)] = "VIDIOC_INT_S_CRYSTAL_FREQ",
297 [_IOC_NR(VIDIOC_INT_INIT)] = "VIDIOC_INT_INIT",
298 [_IOC_NR(VIDIOC_INT_G_STD_OUTPUT)] = "VIDIOC_INT_G_STD_OUTPUT",
299 [_IOC_NR(VIDIOC_INT_S_STD_OUTPUT)] = "VIDIOC_INT_S_STD_OUTPUT",
301 #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
303 /* Common ioctl debug function. This function can be used by
304 external ioctl messages as well as internal V4L ioctl */
305 void v4l_printk_ioctl(unsigned int cmd)
309 switch (_IOC_TYPE(cmd)) {
311 if (_IOC_NR(cmd) >= V4L2_INT_IOCTLS) {
315 printk("%s", v4l2_int_ioctls[_IOC_NR(cmd)]);
317 #ifdef CONFIG_VIDEO_V4L1_COMPAT
319 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
323 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
327 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
331 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
337 switch (_IOC_DIR(cmd)) {
338 case _IOC_NONE: dir = "--"; break;
339 case _IOC_READ: dir = "r-"; break;
340 case _IOC_WRITE: dir = "-w"; break;
341 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
342 default: dir = "*ERR*"; break;
344 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
345 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
347 EXPORT_SYMBOL(v4l_printk_ioctl);
350 * helper function -- handles userspace copying for ioctl arguments
355 video_fix_command(unsigned int cmd)
358 case VIDIOC_OVERLAY_OLD:
359 cmd = VIDIOC_OVERLAY;
361 case VIDIOC_S_PARM_OLD:
364 case VIDIOC_S_CTRL_OLD:
367 case VIDIOC_G_AUDIO_OLD:
368 cmd = VIDIOC_G_AUDIO;
370 case VIDIOC_G_AUDOUT_OLD:
371 cmd = VIDIOC_G_AUDOUT;
373 case VIDIOC_CROPCAP_OLD:
374 cmd = VIDIOC_CROPCAP;
382 * Obsolete usercopy function - Should be removed soon
385 video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
393 size_t ctrls_size = 0;
394 void __user *user_ptr = NULL;
397 cmd = video_fix_command(cmd);
399 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
400 cmd == VIDIOC_TRY_EXT_CTRLS);
402 /* Copy arguments into temp kernel buffer */
403 switch (_IOC_DIR(cmd)) {
409 case (_IOC_WRITE | _IOC_READ):
410 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
413 /* too big to allocate from stack */
414 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
421 if (_IOC_DIR(cmd) & _IOC_WRITE)
422 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
427 struct v4l2_ext_controls *p = parg;
429 /* In case of an error, tell the caller that it wasn't
430 a specific control that caused it. */
431 p->error_idx = p->count;
432 user_ptr = (void __user *)p->controls;
434 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
435 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
436 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
441 if (copy_from_user(mbuf, user_ptr, ctrls_size))
448 err = func(file, cmd, parg);
449 if (err == -ENOIOCTLCMD)
452 struct v4l2_ext_controls *p = parg;
454 p->controls = (void *)user_ptr;
455 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
463 /* Copy results into user buffer */
464 switch (_IOC_DIR(cmd)) {
466 case (_IOC_WRITE | _IOC_READ):
467 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
476 EXPORT_SYMBOL(video_usercopy);
478 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
479 struct v4l2_buffer *p)
481 struct v4l2_timecode *tc = &p->timecode;
483 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
484 "bytesused=%d, flags=0x%08d, "
485 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
486 p->timestamp.tv_sec / 3600,
487 (int)(p->timestamp.tv_sec / 60) % 60,
488 (int)(p->timestamp.tv_sec % 60),
489 (long)p->timestamp.tv_usec,
491 prt_names(p->type, v4l2_type_names),
492 p->bytesused, p->flags,
493 p->field, p->sequence,
494 prt_names(p->memory, v4l2_memory_names),
495 p->m.userptr, p->length);
496 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
497 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
498 tc->hours, tc->minutes, tc->seconds,
499 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
502 static inline void dbgrect(struct video_device *vfd, char *s,
505 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
506 r->width, r->height);
509 static inline void v4l_print_pix_fmt(struct video_device *vfd,
510 struct v4l2_pix_format *fmt)
512 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
513 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
514 fmt->width, fmt->height,
515 (fmt->pixelformat & 0xff),
516 (fmt->pixelformat >> 8) & 0xff,
517 (fmt->pixelformat >> 16) & 0xff,
518 (fmt->pixelformat >> 24) & 0xff,
519 prt_names(fmt->field, v4l2_field_names),
520 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
523 static inline void v4l_print_ext_ctrls(unsigned int cmd,
524 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
528 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
531 printk(KERN_CONT "class=0x%x", c->ctrl_class);
532 for (i = 0; i < c->count; i++) {
534 printk(KERN_CONT " id/val=0x%x/0x%x",
535 c->controls[i].id, c->controls[i].value);
537 printk(KERN_CONT " id=0x%x", c->controls[i].id);
539 printk(KERN_CONT "\n");
542 static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
546 /* zero the reserved fields */
547 c->reserved[0] = c->reserved[1] = 0;
548 for (i = 0; i < c->count; i++) {
549 c->controls[i].reserved2[0] = 0;
550 c->controls[i].reserved2[1] = 0;
552 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
553 when using extended controls.
554 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
555 is it allowed for backwards compatibility.
557 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
559 /* Check that all controls are from the same control class. */
560 for (i = 0; i < c->count; i++) {
561 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
569 static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
575 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
576 if (ops->vidioc_try_fmt_vid_cap)
579 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
580 if (ops->vidioc_try_fmt_vid_overlay)
583 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
584 if (ops->vidioc_try_fmt_vid_out)
587 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
588 if (ops->vidioc_try_fmt_vid_out_overlay)
591 case V4L2_BUF_TYPE_VBI_CAPTURE:
592 if (ops->vidioc_try_fmt_vbi_cap)
595 case V4L2_BUF_TYPE_VBI_OUTPUT:
596 if (ops->vidioc_try_fmt_vbi_out)
599 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
600 if (ops->vidioc_try_fmt_sliced_vbi_cap)
603 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
604 if (ops->vidioc_try_fmt_sliced_vbi_out)
607 case V4L2_BUF_TYPE_PRIVATE:
608 if (ops->vidioc_try_fmt_type_private)
615 static long __video_do_ioctl(struct file *file,
616 unsigned int cmd, void *arg)
618 struct video_device *vfd = video_devdata(file);
619 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
620 void *fh = file->private_data;
623 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
624 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
625 v4l_print_ioctl(vfd->name, cmd);
626 printk(KERN_CONT "\n");
630 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
635 #ifdef CONFIG_VIDEO_V4L1_COMPAT
636 /***********************************************************
637 Handles calls to the obsoleted V4L1 API
638 Due to the nature of VIDIOCGMBUF, each driver that supports
639 V4L1 should implement its own handler for this ioctl.
640 ***********************************************************/
642 /* --- streaming capture ------------------------------------- */
643 if (cmd == VIDIOCGMBUF) {
644 struct video_mbuf *p = arg;
646 if (!ops->vidiocgmbuf)
648 ret = ops->vidiocgmbuf(file, fh, p);
650 dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
652 (unsigned long)p->offsets);
656 /********************************************************
657 All other V4L1 calls are handled by v4l1_compat module.
658 Those calls will be translated into V4L2 calls, and
659 __video_do_ioctl will be called again, with one or more
661 ********************************************************/
662 if (_IOC_TYPE(cmd) == 'v' && _IOC_NR(cmd) < BASE_VIDIOCPRIVATE)
663 return v4l_compat_translate_ioctl(file, cmd, arg,
668 /* --- capabilities ------------------------------------------ */
669 case VIDIOC_QUERYCAP:
671 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
673 if (!ops->vidioc_querycap)
676 ret = ops->vidioc_querycap(file, fh, cap);
678 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
680 "capabilities=0x%08x\n",
681 cap->driver, cap->card, cap->bus_info,
687 /* --- priority ------------------------------------------ */
688 case VIDIOC_G_PRIORITY:
690 enum v4l2_priority *p = arg;
692 if (!ops->vidioc_g_priority)
694 ret = ops->vidioc_g_priority(file, fh, p);
696 dbgarg(cmd, "priority is %d\n", *p);
699 case VIDIOC_S_PRIORITY:
701 enum v4l2_priority *p = arg;
703 if (!ops->vidioc_s_priority)
705 dbgarg(cmd, "setting priority to %d\n", *p);
706 ret = ops->vidioc_s_priority(file, fh, *p);
710 /* --- capture ioctls ---------------------------------------- */
711 case VIDIOC_ENUM_FMT:
713 struct v4l2_fmtdesc *f = arg;
716 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
717 if (ops->vidioc_enum_fmt_vid_cap)
718 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
720 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
721 if (ops->vidioc_enum_fmt_vid_overlay)
722 ret = ops->vidioc_enum_fmt_vid_overlay(file,
725 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
726 if (ops->vidioc_enum_fmt_vid_out)
727 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
729 case V4L2_BUF_TYPE_PRIVATE:
730 if (ops->vidioc_enum_fmt_type_private)
731 ret = ops->vidioc_enum_fmt_type_private(file,
738 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
739 "pixelformat=%c%c%c%c, description='%s'\n",
740 f->index, f->type, f->flags,
741 (f->pixelformat & 0xff),
742 (f->pixelformat >> 8) & 0xff,
743 (f->pixelformat >> 16) & 0xff,
744 (f->pixelformat >> 24) & 0xff,
750 struct v4l2_format *f = (struct v4l2_format *)arg;
752 /* FIXME: Should be one dump per type */
753 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
756 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
757 if (ops->vidioc_g_fmt_vid_cap)
758 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
760 v4l_print_pix_fmt(vfd, &f->fmt.pix);
762 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
763 if (ops->vidioc_g_fmt_vid_overlay)
764 ret = ops->vidioc_g_fmt_vid_overlay(file,
767 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
768 if (ops->vidioc_g_fmt_vid_out)
769 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
771 v4l_print_pix_fmt(vfd, &f->fmt.pix);
773 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
774 if (ops->vidioc_g_fmt_vid_out_overlay)
775 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
778 case V4L2_BUF_TYPE_VBI_CAPTURE:
779 if (ops->vidioc_g_fmt_vbi_cap)
780 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
782 case V4L2_BUF_TYPE_VBI_OUTPUT:
783 if (ops->vidioc_g_fmt_vbi_out)
784 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
786 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
787 if (ops->vidioc_g_fmt_sliced_vbi_cap)
788 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
791 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
792 if (ops->vidioc_g_fmt_sliced_vbi_out)
793 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
796 case V4L2_BUF_TYPE_PRIVATE:
797 if (ops->vidioc_g_fmt_type_private)
798 ret = ops->vidioc_g_fmt_type_private(file,
807 struct v4l2_format *f = (struct v4l2_format *)arg;
809 /* FIXME: Should be one dump per type */
810 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
813 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
814 v4l_print_pix_fmt(vfd, &f->fmt.pix);
815 if (ops->vidioc_s_fmt_vid_cap)
816 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
818 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
819 if (ops->vidioc_s_fmt_vid_overlay)
820 ret = ops->vidioc_s_fmt_vid_overlay(file,
823 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
824 v4l_print_pix_fmt(vfd, &f->fmt.pix);
825 if (ops->vidioc_s_fmt_vid_out)
826 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
828 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
829 if (ops->vidioc_s_fmt_vid_out_overlay)
830 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
833 case V4L2_BUF_TYPE_VBI_CAPTURE:
834 if (ops->vidioc_s_fmt_vbi_cap)
835 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
837 case V4L2_BUF_TYPE_VBI_OUTPUT:
838 if (ops->vidioc_s_fmt_vbi_out)
839 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
841 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
842 if (ops->vidioc_s_fmt_sliced_vbi_cap)
843 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
846 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
847 if (ops->vidioc_s_fmt_sliced_vbi_out)
848 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
851 case V4L2_BUF_TYPE_PRIVATE:
852 if (ops->vidioc_s_fmt_type_private)
853 ret = ops->vidioc_s_fmt_type_private(file,
861 struct v4l2_format *f = (struct v4l2_format *)arg;
863 /* FIXME: Should be one dump per type */
864 dbgarg(cmd, "type=%s\n", prt_names(f->type,
867 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
868 if (ops->vidioc_try_fmt_vid_cap)
869 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
871 v4l_print_pix_fmt(vfd, &f->fmt.pix);
873 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
874 if (ops->vidioc_try_fmt_vid_overlay)
875 ret = ops->vidioc_try_fmt_vid_overlay(file,
878 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
879 if (ops->vidioc_try_fmt_vid_out)
880 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
882 v4l_print_pix_fmt(vfd, &f->fmt.pix);
884 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
885 if (ops->vidioc_try_fmt_vid_out_overlay)
886 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
889 case V4L2_BUF_TYPE_VBI_CAPTURE:
890 if (ops->vidioc_try_fmt_vbi_cap)
891 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
893 case V4L2_BUF_TYPE_VBI_OUTPUT:
894 if (ops->vidioc_try_fmt_vbi_out)
895 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
897 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
898 if (ops->vidioc_try_fmt_sliced_vbi_cap)
899 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
902 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
903 if (ops->vidioc_try_fmt_sliced_vbi_out)
904 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
907 case V4L2_BUF_TYPE_PRIVATE:
908 if (ops->vidioc_try_fmt_type_private)
909 ret = ops->vidioc_try_fmt_type_private(file,
916 /* FIXME: Those buf reqs could be handled here,
917 with some changes on videobuf to allow its header to be included at
918 videodev2.h or being merged at videodev2.
922 struct v4l2_requestbuffers *p = arg;
924 if (!ops->vidioc_reqbufs)
926 ret = check_fmt(ops, p->type);
930 ret = ops->vidioc_reqbufs(file, fh, p);
931 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
933 prt_names(p->type, v4l2_type_names),
934 prt_names(p->memory, v4l2_memory_names));
937 case VIDIOC_QUERYBUF:
939 struct v4l2_buffer *p = arg;
941 if (!ops->vidioc_querybuf)
943 ret = check_fmt(ops, p->type);
947 ret = ops->vidioc_querybuf(file, fh, p);
954 struct v4l2_buffer *p = arg;
956 if (!ops->vidioc_qbuf)
958 ret = check_fmt(ops, p->type);
962 ret = ops->vidioc_qbuf(file, fh, p);
969 struct v4l2_buffer *p = arg;
971 if (!ops->vidioc_dqbuf)
973 ret = check_fmt(ops, p->type);
977 ret = ops->vidioc_dqbuf(file, fh, p);
986 if (!ops->vidioc_overlay)
988 dbgarg(cmd, "value=%d\n", *i);
989 ret = ops->vidioc_overlay(file, fh, *i);
994 struct v4l2_framebuffer *p = arg;
996 if (!ops->vidioc_g_fbuf)
998 ret = ops->vidioc_g_fbuf(file, fh, arg);
1000 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1001 p->capability, p->flags,
1002 (unsigned long)p->base);
1003 v4l_print_pix_fmt(vfd, &p->fmt);
1009 struct v4l2_framebuffer *p = arg;
1011 if (!ops->vidioc_s_fbuf)
1013 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1014 p->capability, p->flags, (unsigned long)p->base);
1015 v4l_print_pix_fmt(vfd, &p->fmt);
1016 ret = ops->vidioc_s_fbuf(file, fh, arg);
1019 case VIDIOC_STREAMON:
1021 enum v4l2_buf_type i = *(int *)arg;
1023 if (!ops->vidioc_streamon)
1025 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1026 ret = ops->vidioc_streamon(file, fh, i);
1029 case VIDIOC_STREAMOFF:
1031 enum v4l2_buf_type i = *(int *)arg;
1033 if (!ops->vidioc_streamoff)
1035 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1036 ret = ops->vidioc_streamoff(file, fh, i);
1039 /* ---------- tv norms ---------- */
1040 case VIDIOC_ENUMSTD:
1042 struct v4l2_standard *p = arg;
1043 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1044 unsigned int index = p->index, i, j = 0;
1045 const char *descr = "";
1047 /* Return norm array in a canonical way */
1048 for (i = 0; i <= index && id; i++) {
1049 /* last std value in the standards array is 0, so this
1050 while always ends there since (id & 0) == 0. */
1051 while ((id & standards[j].std) != standards[j].std)
1053 curr_id = standards[j].std;
1054 descr = standards[j].descr;
1058 if (curr_id != V4L2_STD_PAL &&
1059 curr_id != V4L2_STD_SECAM &&
1060 curr_id != V4L2_STD_NTSC)
1066 v4l2_video_std_construct(p, curr_id, descr);
1068 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1069 "framelines=%d\n", p->index,
1070 (unsigned long long)p->id, p->name,
1071 p->frameperiod.numerator,
1072 p->frameperiod.denominator,
1080 v4l2_std_id *id = arg;
1083 /* Calls the specific handler */
1084 if (ops->vidioc_g_std)
1085 ret = ops->vidioc_g_std(file, fh, id);
1087 *id = vfd->current_norm;
1090 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1095 v4l2_std_id *id = arg, norm;
1097 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1099 norm = (*id) & vfd->tvnorms;
1100 if (vfd->tvnorms && !norm) /* Check if std is supported */
1103 /* Calls the specific handler */
1104 if (ops->vidioc_s_std)
1105 ret = ops->vidioc_s_std(file, fh, &norm);
1109 /* Updates standard information */
1111 vfd->current_norm = norm;
1114 case VIDIOC_QUERYSTD:
1116 v4l2_std_id *p = arg;
1118 if (!ops->vidioc_querystd)
1120 ret = ops->vidioc_querystd(file, fh, arg);
1122 dbgarg(cmd, "detected std=%08Lx\n",
1123 (unsigned long long)*p);
1126 /* ------ input switching ---------- */
1127 /* FIXME: Inputs can be handled inside videodev2 */
1128 case VIDIOC_ENUMINPUT:
1130 struct v4l2_input *p = arg;
1132 if (!ops->vidioc_enum_input)
1135 ret = ops->vidioc_enum_input(file, fh, p);
1137 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1139 "tuner=%d, std=%08Lx, status=%d\n",
1140 p->index, p->name, p->type, p->audioset,
1142 (unsigned long long)p->std,
1146 case VIDIOC_G_INPUT:
1148 unsigned int *i = arg;
1150 if (!ops->vidioc_g_input)
1152 ret = ops->vidioc_g_input(file, fh, i);
1154 dbgarg(cmd, "value=%d\n", *i);
1157 case VIDIOC_S_INPUT:
1159 unsigned int *i = arg;
1161 if (!ops->vidioc_s_input)
1163 dbgarg(cmd, "value=%d\n", *i);
1164 ret = ops->vidioc_s_input(file, fh, *i);
1168 /* ------ output switching ---------- */
1169 case VIDIOC_ENUMOUTPUT:
1171 struct v4l2_output *p = arg;
1173 if (!ops->vidioc_enum_output)
1176 ret = ops->vidioc_enum_output(file, fh, p);
1178 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1180 "modulator=%d, std=0x%08Lx\n",
1181 p->index, p->name, p->type, p->audioset,
1182 p->modulator, (unsigned long long)p->std);
1185 case VIDIOC_G_OUTPUT:
1187 unsigned int *i = arg;
1189 if (!ops->vidioc_g_output)
1191 ret = ops->vidioc_g_output(file, fh, i);
1193 dbgarg(cmd, "value=%d\n", *i);
1196 case VIDIOC_S_OUTPUT:
1198 unsigned int *i = arg;
1200 if (!ops->vidioc_s_output)
1202 dbgarg(cmd, "value=%d\n", *i);
1203 ret = ops->vidioc_s_output(file, fh, *i);
1207 /* --- controls ---------------------------------------------- */
1208 case VIDIOC_QUERYCTRL:
1210 struct v4l2_queryctrl *p = arg;
1212 if (!ops->vidioc_queryctrl)
1214 ret = ops->vidioc_queryctrl(file, fh, p);
1216 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1217 "step=%d, default=%d, flags=0x%08x\n",
1218 p->id, p->type, p->name,
1219 p->minimum, p->maximum,
1220 p->step, p->default_value, p->flags);
1222 dbgarg(cmd, "id=0x%x\n", p->id);
1227 struct v4l2_control *p = arg;
1229 if (ops->vidioc_g_ctrl)
1230 ret = ops->vidioc_g_ctrl(file, fh, p);
1231 else if (ops->vidioc_g_ext_ctrls) {
1232 struct v4l2_ext_controls ctrls;
1233 struct v4l2_ext_control ctrl;
1235 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1237 ctrls.controls = &ctrl;
1239 ctrl.value = p->value;
1240 if (check_ext_ctrls(&ctrls, 1)) {
1241 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1243 p->value = ctrl.value;
1248 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1250 dbgarg(cmd, "id=0x%x\n", p->id);
1255 struct v4l2_control *p = arg;
1256 struct v4l2_ext_controls ctrls;
1257 struct v4l2_ext_control ctrl;
1259 if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
1262 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1264 if (ops->vidioc_s_ctrl) {
1265 ret = ops->vidioc_s_ctrl(file, fh, p);
1268 if (!ops->vidioc_s_ext_ctrls)
1271 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1273 ctrls.controls = &ctrl;
1275 ctrl.value = p->value;
1276 if (check_ext_ctrls(&ctrls, 1))
1277 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1280 case VIDIOC_G_EXT_CTRLS:
1282 struct v4l2_ext_controls *p = arg;
1284 p->error_idx = p->count;
1285 if (!ops->vidioc_g_ext_ctrls)
1287 if (check_ext_ctrls(p, 0))
1288 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
1289 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1292 case VIDIOC_S_EXT_CTRLS:
1294 struct v4l2_ext_controls *p = arg;
1296 p->error_idx = p->count;
1297 if (!ops->vidioc_s_ext_ctrls)
1299 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1300 if (check_ext_ctrls(p, 0))
1301 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
1304 case VIDIOC_TRY_EXT_CTRLS:
1306 struct v4l2_ext_controls *p = arg;
1308 p->error_idx = p->count;
1309 if (!ops->vidioc_try_ext_ctrls)
1311 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1312 if (check_ext_ctrls(p, 0))
1313 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
1316 case VIDIOC_QUERYMENU:
1318 struct v4l2_querymenu *p = arg;
1320 if (!ops->vidioc_querymenu)
1322 ret = ops->vidioc_querymenu(file, fh, p);
1324 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1325 p->id, p->index, p->name);
1327 dbgarg(cmd, "id=0x%x, index=%d\n",
1331 /* --- audio ---------------------------------------------- */
1332 case VIDIOC_ENUMAUDIO:
1334 struct v4l2_audio *p = arg;
1336 if (!ops->vidioc_enumaudio)
1338 ret = ops->vidioc_enumaudio(file, fh, p);
1340 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1341 "mode=0x%x\n", p->index, p->name,
1342 p->capability, p->mode);
1344 dbgarg(cmd, "index=%d\n", p->index);
1347 case VIDIOC_G_AUDIO:
1349 struct v4l2_audio *p = arg;
1351 if (!ops->vidioc_g_audio)
1354 ret = ops->vidioc_g_audio(file, fh, p);
1356 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1357 "mode=0x%x\n", p->index,
1358 p->name, p->capability, p->mode);
1360 dbgarg(cmd, "index=%d\n", p->index);
1363 case VIDIOC_S_AUDIO:
1365 struct v4l2_audio *p = arg;
1367 if (!ops->vidioc_s_audio)
1369 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1370 "mode=0x%x\n", p->index, p->name,
1371 p->capability, p->mode);
1372 ret = ops->vidioc_s_audio(file, fh, p);
1375 case VIDIOC_ENUMAUDOUT:
1377 struct v4l2_audioout *p = arg;
1379 if (!ops->vidioc_enumaudout)
1381 dbgarg(cmd, "Enum for index=%d\n", p->index);
1382 ret = ops->vidioc_enumaudout(file, fh, p);
1384 dbgarg2("index=%d, name=%s, capability=%d, "
1385 "mode=%d\n", p->index, p->name,
1386 p->capability, p->mode);
1389 case VIDIOC_G_AUDOUT:
1391 struct v4l2_audioout *p = arg;
1393 if (!ops->vidioc_g_audout)
1396 ret = ops->vidioc_g_audout(file, fh, p);
1398 dbgarg2("index=%d, name=%s, capability=%d, "
1399 "mode=%d\n", p->index, p->name,
1400 p->capability, p->mode);
1403 case VIDIOC_S_AUDOUT:
1405 struct v4l2_audioout *p = arg;
1407 if (!ops->vidioc_s_audout)
1409 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1410 "mode=%d\n", p->index, p->name,
1411 p->capability, p->mode);
1413 ret = ops->vidioc_s_audout(file, fh, p);
1416 case VIDIOC_G_MODULATOR:
1418 struct v4l2_modulator *p = arg;
1420 if (!ops->vidioc_g_modulator)
1422 ret = ops->vidioc_g_modulator(file, fh, p);
1424 dbgarg(cmd, "index=%d, name=%s, "
1425 "capability=%d, rangelow=%d,"
1426 " rangehigh=%d, txsubchans=%d\n",
1427 p->index, p->name, p->capability,
1428 p->rangelow, p->rangehigh,
1432 case VIDIOC_S_MODULATOR:
1434 struct v4l2_modulator *p = arg;
1436 if (!ops->vidioc_s_modulator)
1438 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1439 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1440 p->index, p->name, p->capability, p->rangelow,
1441 p->rangehigh, p->txsubchans);
1442 ret = ops->vidioc_s_modulator(file, fh, p);
1447 struct v4l2_crop *p = arg;
1449 if (!ops->vidioc_g_crop)
1452 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1453 ret = ops->vidioc_g_crop(file, fh, p);
1455 dbgrect(vfd, "", &p->c);
1460 struct v4l2_crop *p = arg;
1462 if (!ops->vidioc_s_crop)
1464 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1465 dbgrect(vfd, "", &p->c);
1466 ret = ops->vidioc_s_crop(file, fh, p);
1469 case VIDIOC_CROPCAP:
1471 struct v4l2_cropcap *p = arg;
1473 /*FIXME: Should also show v4l2_fract pixelaspect */
1474 if (!ops->vidioc_cropcap)
1477 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1478 ret = ops->vidioc_cropcap(file, fh, p);
1480 dbgrect(vfd, "bounds ", &p->bounds);
1481 dbgrect(vfd, "defrect ", &p->defrect);
1485 case VIDIOC_G_JPEGCOMP:
1487 struct v4l2_jpegcompression *p = arg;
1489 if (!ops->vidioc_g_jpegcomp)
1492 ret = ops->vidioc_g_jpegcomp(file, fh, p);
1494 dbgarg(cmd, "quality=%d, APPn=%d, "
1495 "APP_len=%d, COM_len=%d, "
1496 "jpeg_markers=%d\n",
1497 p->quality, p->APPn, p->APP_len,
1498 p->COM_len, p->jpeg_markers);
1501 case VIDIOC_S_JPEGCOMP:
1503 struct v4l2_jpegcompression *p = arg;
1505 if (!ops->vidioc_g_jpegcomp)
1507 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1508 "COM_len=%d, jpeg_markers=%d\n",
1509 p->quality, p->APPn, p->APP_len,
1510 p->COM_len, p->jpeg_markers);
1511 ret = ops->vidioc_s_jpegcomp(file, fh, p);
1514 case VIDIOC_G_ENC_INDEX:
1516 struct v4l2_enc_idx *p = arg;
1518 if (!ops->vidioc_g_enc_index)
1520 ret = ops->vidioc_g_enc_index(file, fh, p);
1522 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1523 p->entries, p->entries_cap);
1526 case VIDIOC_ENCODER_CMD:
1528 struct v4l2_encoder_cmd *p = arg;
1530 if (!ops->vidioc_encoder_cmd)
1532 ret = ops->vidioc_encoder_cmd(file, fh, p);
1534 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1537 case VIDIOC_TRY_ENCODER_CMD:
1539 struct v4l2_encoder_cmd *p = arg;
1541 if (!ops->vidioc_try_encoder_cmd)
1543 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
1545 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1550 struct v4l2_streamparm *p = arg;
1552 if (ops->vidioc_g_parm) {
1553 ret = ops->vidioc_g_parm(file, fh, p);
1555 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1558 v4l2_video_std_frame_period(vfd->current_norm,
1559 &p->parm.capture.timeperframe);
1563 dbgarg(cmd, "type=%d\n", p->type);
1568 struct v4l2_streamparm *p = arg;
1570 if (!ops->vidioc_s_parm)
1572 dbgarg(cmd, "type=%d\n", p->type);
1573 ret = ops->vidioc_s_parm(file, fh, p);
1576 case VIDIOC_G_TUNER:
1578 struct v4l2_tuner *p = arg;
1580 if (!ops->vidioc_g_tuner)
1583 ret = ops->vidioc_g_tuner(file, fh, p);
1585 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1586 "capability=0x%x, rangelow=%d, "
1587 "rangehigh=%d, signal=%d, afc=%d, "
1588 "rxsubchans=0x%x, audmode=%d\n",
1589 p->index, p->name, p->type,
1590 p->capability, p->rangelow,
1591 p->rangehigh, p->signal, p->afc,
1592 p->rxsubchans, p->audmode);
1595 case VIDIOC_S_TUNER:
1597 struct v4l2_tuner *p = arg;
1599 if (!ops->vidioc_s_tuner)
1601 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1602 "capability=0x%x, rangelow=%d, "
1603 "rangehigh=%d, signal=%d, afc=%d, "
1604 "rxsubchans=0x%x, audmode=%d\n",
1605 p->index, p->name, p->type,
1606 p->capability, p->rangelow,
1607 p->rangehigh, p->signal, p->afc,
1608 p->rxsubchans, p->audmode);
1609 ret = ops->vidioc_s_tuner(file, fh, p);
1612 case VIDIOC_G_FREQUENCY:
1614 struct v4l2_frequency *p = arg;
1616 if (!ops->vidioc_g_frequency)
1619 ret = ops->vidioc_g_frequency(file, fh, p);
1621 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1622 p->tuner, p->type, p->frequency);
1625 case VIDIOC_S_FREQUENCY:
1627 struct v4l2_frequency *p = arg;
1629 if (!ops->vidioc_s_frequency)
1631 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1632 p->tuner, p->type, p->frequency);
1633 ret = ops->vidioc_s_frequency(file, fh, p);
1636 case VIDIOC_G_SLICED_VBI_CAP:
1638 struct v4l2_sliced_vbi_cap *p = arg;
1640 if (!ops->vidioc_g_sliced_vbi_cap)
1643 /* Clear up to type, everything after type is zerod already */
1644 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1646 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1647 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1649 dbgarg2("service_set=%d\n", p->service_set);
1652 case VIDIOC_LOG_STATUS:
1654 if (!ops->vidioc_log_status)
1656 ret = ops->vidioc_log_status(file, fh);
1659 #ifdef CONFIG_VIDEO_ADV_DEBUG
1660 case VIDIOC_DBG_G_REGISTER:
1662 struct v4l2_dbg_register *p = arg;
1664 if (!capable(CAP_SYS_ADMIN))
1666 else if (ops->vidioc_g_register)
1667 ret = ops->vidioc_g_register(file, fh, p);
1670 case VIDIOC_DBG_S_REGISTER:
1672 struct v4l2_dbg_register *p = arg;
1674 if (!capable(CAP_SYS_ADMIN))
1676 else if (ops->vidioc_s_register)
1677 ret = ops->vidioc_s_register(file, fh, p);
1681 case VIDIOC_DBG_G_CHIP_IDENT:
1683 struct v4l2_dbg_chip_ident *p = arg;
1685 if (!ops->vidioc_g_chip_ident)
1687 p->ident = V4L2_IDENT_NONE;
1689 ret = ops->vidioc_g_chip_ident(file, fh, p);
1691 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1694 case VIDIOC_G_CHIP_IDENT_OLD:
1695 printk(KERN_ERR "VIDIOC_G_CHIP_IDENT has been deprecated and will disappear in 2.6.30.\n");
1696 printk(KERN_ERR "It is a debugging ioctl and must not be used in applications!\n");
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) case _IOC_NR(VIDIOC_##cmd): return \
1804 offsetof(struct v4l2_##type, field) + \
1805 sizeof(((struct v4l2_##type *)0)->field);
1807 switch (_IOC_NR(cmd)) {
1808 CMDINSIZE(ENUM_FMT, fmtdesc, type);
1809 CMDINSIZE(G_FMT, format, type);
1810 CMDINSIZE(QUERYBUF, buffer, type);
1811 CMDINSIZE(G_PARM, streamparm, type);
1812 CMDINSIZE(ENUMSTD, standard, index);
1813 CMDINSIZE(ENUMINPUT, input, index);
1814 CMDINSIZE(G_CTRL, control, id);
1815 CMDINSIZE(G_TUNER, tuner, index);
1816 CMDINSIZE(QUERYCTRL, queryctrl, id);
1817 CMDINSIZE(QUERYMENU, querymenu, index);
1818 CMDINSIZE(ENUMOUTPUT, output, index);
1819 CMDINSIZE(G_MODULATOR, modulator, index);
1820 CMDINSIZE(G_FREQUENCY, frequency, tuner);
1821 CMDINSIZE(CROPCAP, cropcap, type);
1822 CMDINSIZE(G_CROP, crop, type);
1823 CMDINSIZE(ENUMAUDIO, audio, index);
1824 CMDINSIZE(ENUMAUDOUT, audioout, index);
1825 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
1826 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
1827 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
1828 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
1829 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
1831 return _IOC_SIZE(cmd);
1835 long video_ioctl2(struct file *file,
1836 unsigned int cmd, unsigned long arg)
1843 size_t ctrls_size = 0;
1844 void __user *user_ptr = NULL;
1846 #ifdef __OLD_VIDIOC_
1847 cmd = video_fix_command(cmd);
1849 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1850 cmd == VIDIOC_TRY_EXT_CTRLS);
1852 /* Copy arguments into temp kernel buffer */
1853 if (_IOC_DIR(cmd) != _IOC_NONE) {
1854 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1857 /* too big to allocate from stack */
1858 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
1865 if (_IOC_DIR(cmd) & _IOC_WRITE) {
1866 unsigned long n = cmd_input_size(cmd);
1868 if (copy_from_user(parg, (void __user *)arg, n))
1871 /* zero out anything we don't copy from userspace */
1872 if (n < _IOC_SIZE(cmd))
1873 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
1875 /* read-only ioctl */
1876 memset(parg, 0, _IOC_SIZE(cmd));
1881 struct v4l2_ext_controls *p = parg;
1883 /* In case of an error, tell the caller that it wasn't
1884 a specific control that caused it. */
1885 p->error_idx = p->count;
1886 user_ptr = (void __user *)p->controls;
1888 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1889 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1890 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1895 if (copy_from_user(mbuf, user_ptr, ctrls_size))
1902 err = __video_do_ioctl(file, cmd, parg);
1903 if (err == -ENOIOCTLCMD)
1906 struct v4l2_ext_controls *p = parg;
1908 p->controls = (void *)user_ptr;
1909 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1917 /* Copy results into user buffer */
1918 switch (_IOC_DIR(cmd)) {
1920 case (_IOC_WRITE | _IOC_READ):
1921 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
1930 EXPORT_SYMBOL(video_ioctl2);