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 static const char *v4l2_int_ioctls[] = {
279 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
281 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
282 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
283 [_IOC_NR(TUNER_SET_CONFIG)] = "TUNER_SET_CONFIG",
285 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
286 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
287 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
288 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
289 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
290 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
291 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
292 [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
293 [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
294 [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
295 [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
296 [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING",
297 [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)] = "VIDIOC_INT_S_CRYSTAL_FREQ",
298 [_IOC_NR(VIDIOC_INT_INIT)] = "VIDIOC_INT_INIT",
299 [_IOC_NR(VIDIOC_INT_G_STD_OUTPUT)] = "VIDIOC_INT_G_STD_OUTPUT",
300 [_IOC_NR(VIDIOC_INT_S_STD_OUTPUT)] = "VIDIOC_INT_S_STD_OUTPUT",
302 #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
304 /* Common ioctl debug function. This function can be used by
305 external ioctl messages as well as internal V4L ioctl */
306 void v4l_printk_ioctl(unsigned int cmd)
310 switch (_IOC_TYPE(cmd)) {
312 if (_IOC_NR(cmd) >= V4L2_INT_IOCTLS) {
316 printk("%s", v4l2_int_ioctls[_IOC_NR(cmd)]);
318 #ifdef CONFIG_VIDEO_V4L1_COMPAT
320 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
324 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
328 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
332 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
338 switch (_IOC_DIR(cmd)) {
339 case _IOC_NONE: dir = "--"; break;
340 case _IOC_READ: dir = "r-"; break;
341 case _IOC_WRITE: dir = "-w"; break;
342 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
343 default: dir = "*ERR*"; break;
345 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
346 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
348 EXPORT_SYMBOL(v4l_printk_ioctl);
351 * helper function -- handles userspace copying for ioctl arguments
356 video_fix_command(unsigned int cmd)
359 case VIDIOC_OVERLAY_OLD:
360 cmd = VIDIOC_OVERLAY;
362 case VIDIOC_S_PARM_OLD:
365 case VIDIOC_S_CTRL_OLD:
368 case VIDIOC_G_AUDIO_OLD:
369 cmd = VIDIOC_G_AUDIO;
371 case VIDIOC_G_AUDOUT_OLD:
372 cmd = VIDIOC_G_AUDOUT;
374 case VIDIOC_CROPCAP_OLD:
375 cmd = VIDIOC_CROPCAP;
383 * Obsolete usercopy function - Should be removed soon
386 video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
394 size_t ctrls_size = 0;
395 void __user *user_ptr = NULL;
398 cmd = video_fix_command(cmd);
400 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
401 cmd == VIDIOC_TRY_EXT_CTRLS);
403 /* Copy arguments into temp kernel buffer */
404 switch (_IOC_DIR(cmd)) {
410 case (_IOC_WRITE | _IOC_READ):
411 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
414 /* too big to allocate from stack */
415 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
422 if (_IOC_DIR(cmd) & _IOC_WRITE)
423 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
428 struct v4l2_ext_controls *p = parg;
430 /* In case of an error, tell the caller that it wasn't
431 a specific control that caused it. */
432 p->error_idx = p->count;
433 user_ptr = (void __user *)p->controls;
435 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
436 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
437 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
442 if (copy_from_user(mbuf, user_ptr, ctrls_size))
449 err = func(file, cmd, parg);
450 if (err == -ENOIOCTLCMD)
453 struct v4l2_ext_controls *p = parg;
455 p->controls = (void *)user_ptr;
456 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
464 /* Copy results into user buffer */
465 switch (_IOC_DIR(cmd)) {
467 case (_IOC_WRITE | _IOC_READ):
468 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
477 EXPORT_SYMBOL(video_usercopy);
479 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
480 struct v4l2_buffer *p)
482 struct v4l2_timecode *tc = &p->timecode;
484 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
485 "bytesused=%d, flags=0x%08d, "
486 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
487 p->timestamp.tv_sec / 3600,
488 (int)(p->timestamp.tv_sec / 60) % 60,
489 (int)(p->timestamp.tv_sec % 60),
490 (long)p->timestamp.tv_usec,
492 prt_names(p->type, v4l2_type_names),
493 p->bytesused, p->flags,
494 p->field, p->sequence,
495 prt_names(p->memory, v4l2_memory_names),
496 p->m.userptr, p->length);
497 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
498 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
499 tc->hours, tc->minutes, tc->seconds,
500 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
503 static inline void dbgrect(struct video_device *vfd, char *s,
506 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
507 r->width, r->height);
510 static inline void v4l_print_pix_fmt(struct video_device *vfd,
511 struct v4l2_pix_format *fmt)
513 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
514 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
515 fmt->width, fmt->height,
516 (fmt->pixelformat & 0xff),
517 (fmt->pixelformat >> 8) & 0xff,
518 (fmt->pixelformat >> 16) & 0xff,
519 (fmt->pixelformat >> 24) & 0xff,
520 prt_names(fmt->field, v4l2_field_names),
521 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
524 static inline void v4l_print_ext_ctrls(unsigned int cmd,
525 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
529 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
532 printk(KERN_CONT "class=0x%x", c->ctrl_class);
533 for (i = 0; i < c->count; i++) {
535 printk(KERN_CONT " id/val=0x%x/0x%x",
536 c->controls[i].id, c->controls[i].value);
538 printk(KERN_CONT " id=0x%x", c->controls[i].id);
540 printk(KERN_CONT "\n");
543 static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
547 /* zero the reserved fields */
548 c->reserved[0] = c->reserved[1] = 0;
549 for (i = 0; i < c->count; i++) {
550 c->controls[i].reserved2[0] = 0;
551 c->controls[i].reserved2[1] = 0;
553 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
554 when using extended controls.
555 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
556 is it allowed for backwards compatibility.
558 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
560 /* Check that all controls are from the same control class. */
561 for (i = 0; i < c->count; i++) {
562 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
570 static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
576 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
577 if (ops->vidioc_try_fmt_vid_cap)
580 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
581 if (ops->vidioc_try_fmt_vid_overlay)
584 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
585 if (ops->vidioc_try_fmt_vid_out)
588 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
589 if (ops->vidioc_try_fmt_vid_out_overlay)
592 case V4L2_BUF_TYPE_VBI_CAPTURE:
593 if (ops->vidioc_try_fmt_vbi_cap)
596 case V4L2_BUF_TYPE_VBI_OUTPUT:
597 if (ops->vidioc_try_fmt_vbi_out)
600 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
601 if (ops->vidioc_try_fmt_sliced_vbi_cap)
604 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
605 if (ops->vidioc_try_fmt_sliced_vbi_out)
608 case V4L2_BUF_TYPE_PRIVATE:
609 if (ops->vidioc_try_fmt_type_private)
616 static long __video_do_ioctl(struct file *file,
617 unsigned int cmd, void *arg)
619 struct video_device *vfd = video_devdata(file);
620 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
621 void *fh = file->private_data;
624 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
625 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
626 v4l_print_ioctl(vfd->name, cmd);
627 printk(KERN_CONT "\n");
631 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
636 #ifdef CONFIG_VIDEO_V4L1_COMPAT
637 /***********************************************************
638 Handles calls to the obsoleted V4L1 API
639 Due to the nature of VIDIOCGMBUF, each driver that supports
640 V4L1 should implement its own handler for this ioctl.
641 ***********************************************************/
643 /* --- streaming capture ------------------------------------- */
644 if (cmd == VIDIOCGMBUF) {
645 struct video_mbuf *p = arg;
647 if (!ops->vidiocgmbuf)
649 ret = ops->vidiocgmbuf(file, fh, p);
651 dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
653 (unsigned long)p->offsets);
657 /********************************************************
658 All other V4L1 calls are handled by v4l1_compat module.
659 Those calls will be translated into V4L2 calls, and
660 __video_do_ioctl will be called again, with one or more
662 ********************************************************/
663 if (_IOC_TYPE(cmd) == 'v' && _IOC_NR(cmd) < BASE_VIDIOCPRIVATE)
664 return v4l_compat_translate_ioctl(file, cmd, arg,
669 /* --- capabilities ------------------------------------------ */
670 case VIDIOC_QUERYCAP:
672 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
674 if (!ops->vidioc_querycap)
677 ret = ops->vidioc_querycap(file, fh, cap);
679 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
681 "capabilities=0x%08x\n",
682 cap->driver, cap->card, cap->bus_info,
688 /* --- priority ------------------------------------------ */
689 case VIDIOC_G_PRIORITY:
691 enum v4l2_priority *p = arg;
693 if (!ops->vidioc_g_priority)
695 ret = ops->vidioc_g_priority(file, fh, p);
697 dbgarg(cmd, "priority is %d\n", *p);
700 case VIDIOC_S_PRIORITY:
702 enum v4l2_priority *p = arg;
704 if (!ops->vidioc_s_priority)
706 dbgarg(cmd, "setting priority to %d\n", *p);
707 ret = ops->vidioc_s_priority(file, fh, *p);
711 /* --- capture ioctls ---------------------------------------- */
712 case VIDIOC_ENUM_FMT:
714 struct v4l2_fmtdesc *f = arg;
717 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
718 if (ops->vidioc_enum_fmt_vid_cap)
719 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
721 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
722 if (ops->vidioc_enum_fmt_vid_overlay)
723 ret = ops->vidioc_enum_fmt_vid_overlay(file,
726 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
727 if (ops->vidioc_enum_fmt_vid_out)
728 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
730 case V4L2_BUF_TYPE_PRIVATE:
731 if (ops->vidioc_enum_fmt_type_private)
732 ret = ops->vidioc_enum_fmt_type_private(file,
739 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
740 "pixelformat=%c%c%c%c, description='%s'\n",
741 f->index, f->type, f->flags,
742 (f->pixelformat & 0xff),
743 (f->pixelformat >> 8) & 0xff,
744 (f->pixelformat >> 16) & 0xff,
745 (f->pixelformat >> 24) & 0xff,
751 struct v4l2_format *f = (struct v4l2_format *)arg;
753 /* FIXME: Should be one dump per type */
754 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
757 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
758 if (ops->vidioc_g_fmt_vid_cap)
759 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
761 v4l_print_pix_fmt(vfd, &f->fmt.pix);
763 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
764 if (ops->vidioc_g_fmt_vid_overlay)
765 ret = ops->vidioc_g_fmt_vid_overlay(file,
768 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
769 if (ops->vidioc_g_fmt_vid_out)
770 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
772 v4l_print_pix_fmt(vfd, &f->fmt.pix);
774 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
775 if (ops->vidioc_g_fmt_vid_out_overlay)
776 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
779 case V4L2_BUF_TYPE_VBI_CAPTURE:
780 if (ops->vidioc_g_fmt_vbi_cap)
781 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
783 case V4L2_BUF_TYPE_VBI_OUTPUT:
784 if (ops->vidioc_g_fmt_vbi_out)
785 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
787 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
788 if (ops->vidioc_g_fmt_sliced_vbi_cap)
789 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
792 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
793 if (ops->vidioc_g_fmt_sliced_vbi_out)
794 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
797 case V4L2_BUF_TYPE_PRIVATE:
798 if (ops->vidioc_g_fmt_type_private)
799 ret = ops->vidioc_g_fmt_type_private(file,
808 struct v4l2_format *f = (struct v4l2_format *)arg;
810 /* FIXME: Should be one dump per type */
811 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
814 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
815 v4l_print_pix_fmt(vfd, &f->fmt.pix);
816 if (ops->vidioc_s_fmt_vid_cap)
817 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
819 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
820 if (ops->vidioc_s_fmt_vid_overlay)
821 ret = ops->vidioc_s_fmt_vid_overlay(file,
824 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
825 v4l_print_pix_fmt(vfd, &f->fmt.pix);
826 if (ops->vidioc_s_fmt_vid_out)
827 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
829 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
830 if (ops->vidioc_s_fmt_vid_out_overlay)
831 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
834 case V4L2_BUF_TYPE_VBI_CAPTURE:
835 if (ops->vidioc_s_fmt_vbi_cap)
836 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
838 case V4L2_BUF_TYPE_VBI_OUTPUT:
839 if (ops->vidioc_s_fmt_vbi_out)
840 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
842 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
843 if (ops->vidioc_s_fmt_sliced_vbi_cap)
844 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
847 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
848 if (ops->vidioc_s_fmt_sliced_vbi_out)
849 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
852 case V4L2_BUF_TYPE_PRIVATE:
853 if (ops->vidioc_s_fmt_type_private)
854 ret = ops->vidioc_s_fmt_type_private(file,
862 struct v4l2_format *f = (struct v4l2_format *)arg;
864 /* FIXME: Should be one dump per type */
865 dbgarg(cmd, "type=%s\n", prt_names(f->type,
868 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
869 if (ops->vidioc_try_fmt_vid_cap)
870 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
872 v4l_print_pix_fmt(vfd, &f->fmt.pix);
874 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
875 if (ops->vidioc_try_fmt_vid_overlay)
876 ret = ops->vidioc_try_fmt_vid_overlay(file,
879 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
880 if (ops->vidioc_try_fmt_vid_out)
881 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
883 v4l_print_pix_fmt(vfd, &f->fmt.pix);
885 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
886 if (ops->vidioc_try_fmt_vid_out_overlay)
887 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
890 case V4L2_BUF_TYPE_VBI_CAPTURE:
891 if (ops->vidioc_try_fmt_vbi_cap)
892 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
894 case V4L2_BUF_TYPE_VBI_OUTPUT:
895 if (ops->vidioc_try_fmt_vbi_out)
896 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
898 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
899 if (ops->vidioc_try_fmt_sliced_vbi_cap)
900 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
903 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
904 if (ops->vidioc_try_fmt_sliced_vbi_out)
905 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
908 case V4L2_BUF_TYPE_PRIVATE:
909 if (ops->vidioc_try_fmt_type_private)
910 ret = ops->vidioc_try_fmt_type_private(file,
917 /* FIXME: Those buf reqs could be handled here,
918 with some changes on videobuf to allow its header to be included at
919 videodev2.h or being merged at videodev2.
923 struct v4l2_requestbuffers *p = arg;
925 if (!ops->vidioc_reqbufs)
927 ret = check_fmt(ops, p->type);
931 ret = ops->vidioc_reqbufs(file, fh, p);
932 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
934 prt_names(p->type, v4l2_type_names),
935 prt_names(p->memory, v4l2_memory_names));
938 case VIDIOC_QUERYBUF:
940 struct v4l2_buffer *p = arg;
942 if (!ops->vidioc_querybuf)
944 ret = check_fmt(ops, p->type);
948 ret = ops->vidioc_querybuf(file, fh, p);
955 struct v4l2_buffer *p = arg;
957 if (!ops->vidioc_qbuf)
959 ret = check_fmt(ops, p->type);
963 ret = ops->vidioc_qbuf(file, fh, p);
970 struct v4l2_buffer *p = arg;
972 if (!ops->vidioc_dqbuf)
974 ret = check_fmt(ops, p->type);
978 ret = ops->vidioc_dqbuf(file, fh, p);
987 if (!ops->vidioc_overlay)
989 dbgarg(cmd, "value=%d\n", *i);
990 ret = ops->vidioc_overlay(file, fh, *i);
995 struct v4l2_framebuffer *p = arg;
997 if (!ops->vidioc_g_fbuf)
999 ret = ops->vidioc_g_fbuf(file, fh, arg);
1001 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1002 p->capability, p->flags,
1003 (unsigned long)p->base);
1004 v4l_print_pix_fmt(vfd, &p->fmt);
1010 struct v4l2_framebuffer *p = arg;
1012 if (!ops->vidioc_s_fbuf)
1014 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1015 p->capability, p->flags, (unsigned long)p->base);
1016 v4l_print_pix_fmt(vfd, &p->fmt);
1017 ret = ops->vidioc_s_fbuf(file, fh, arg);
1020 case VIDIOC_STREAMON:
1022 enum v4l2_buf_type i = *(int *)arg;
1024 if (!ops->vidioc_streamon)
1026 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1027 ret = ops->vidioc_streamon(file, fh, i);
1030 case VIDIOC_STREAMOFF:
1032 enum v4l2_buf_type i = *(int *)arg;
1034 if (!ops->vidioc_streamoff)
1036 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1037 ret = ops->vidioc_streamoff(file, fh, i);
1040 /* ---------- tv norms ---------- */
1041 case VIDIOC_ENUMSTD:
1043 struct v4l2_standard *p = arg;
1044 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1045 unsigned int index = p->index, i, j = 0;
1046 const char *descr = "";
1048 /* Return norm array in a canonical way */
1049 for (i = 0; i <= index && id; i++) {
1050 /* last std value in the standards array is 0, so this
1051 while always ends there since (id & 0) == 0. */
1052 while ((id & standards[j].std) != standards[j].std)
1054 curr_id = standards[j].std;
1055 descr = standards[j].descr;
1059 if (curr_id != V4L2_STD_PAL &&
1060 curr_id != V4L2_STD_SECAM &&
1061 curr_id != V4L2_STD_NTSC)
1067 v4l2_video_std_construct(p, curr_id, descr);
1069 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1070 "framelines=%d\n", p->index,
1071 (unsigned long long)p->id, p->name,
1072 p->frameperiod.numerator,
1073 p->frameperiod.denominator,
1081 v4l2_std_id *id = arg;
1084 /* Calls the specific handler */
1085 if (ops->vidioc_g_std)
1086 ret = ops->vidioc_g_std(file, fh, id);
1088 *id = vfd->current_norm;
1091 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1096 v4l2_std_id *id = arg, norm;
1098 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1100 norm = (*id) & vfd->tvnorms;
1101 if (vfd->tvnorms && !norm) /* Check if std is supported */
1104 /* Calls the specific handler */
1105 if (ops->vidioc_s_std)
1106 ret = ops->vidioc_s_std(file, fh, &norm);
1110 /* Updates standard information */
1112 vfd->current_norm = norm;
1115 case VIDIOC_QUERYSTD:
1117 v4l2_std_id *p = arg;
1119 if (!ops->vidioc_querystd)
1121 ret = ops->vidioc_querystd(file, fh, arg);
1123 dbgarg(cmd, "detected std=%08Lx\n",
1124 (unsigned long long)*p);
1127 /* ------ input switching ---------- */
1128 /* FIXME: Inputs can be handled inside videodev2 */
1129 case VIDIOC_ENUMINPUT:
1131 struct v4l2_input *p = arg;
1133 if (!ops->vidioc_enum_input)
1136 ret = ops->vidioc_enum_input(file, fh, p);
1138 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1140 "tuner=%d, std=%08Lx, status=%d\n",
1141 p->index, p->name, p->type, p->audioset,
1143 (unsigned long long)p->std,
1147 case VIDIOC_G_INPUT:
1149 unsigned int *i = arg;
1151 if (!ops->vidioc_g_input)
1153 ret = ops->vidioc_g_input(file, fh, i);
1155 dbgarg(cmd, "value=%d\n", *i);
1158 case VIDIOC_S_INPUT:
1160 unsigned int *i = arg;
1162 if (!ops->vidioc_s_input)
1164 dbgarg(cmd, "value=%d\n", *i);
1165 ret = ops->vidioc_s_input(file, fh, *i);
1169 /* ------ output switching ---------- */
1170 case VIDIOC_ENUMOUTPUT:
1172 struct v4l2_output *p = arg;
1174 if (!ops->vidioc_enum_output)
1177 ret = ops->vidioc_enum_output(file, fh, p);
1179 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1181 "modulator=%d, std=0x%08Lx\n",
1182 p->index, p->name, p->type, p->audioset,
1183 p->modulator, (unsigned long long)p->std);
1186 case VIDIOC_G_OUTPUT:
1188 unsigned int *i = arg;
1190 if (!ops->vidioc_g_output)
1192 ret = ops->vidioc_g_output(file, fh, i);
1194 dbgarg(cmd, "value=%d\n", *i);
1197 case VIDIOC_S_OUTPUT:
1199 unsigned int *i = arg;
1201 if (!ops->vidioc_s_output)
1203 dbgarg(cmd, "value=%d\n", *i);
1204 ret = ops->vidioc_s_output(file, fh, *i);
1208 /* --- controls ---------------------------------------------- */
1209 case VIDIOC_QUERYCTRL:
1211 struct v4l2_queryctrl *p = arg;
1213 if (!ops->vidioc_queryctrl)
1215 ret = ops->vidioc_queryctrl(file, fh, p);
1217 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1218 "step=%d, default=%d, flags=0x%08x\n",
1219 p->id, p->type, p->name,
1220 p->minimum, p->maximum,
1221 p->step, p->default_value, p->flags);
1223 dbgarg(cmd, "id=0x%x\n", p->id);
1228 struct v4l2_control *p = arg;
1230 if (ops->vidioc_g_ctrl)
1231 ret = ops->vidioc_g_ctrl(file, fh, p);
1232 else if (ops->vidioc_g_ext_ctrls) {
1233 struct v4l2_ext_controls ctrls;
1234 struct v4l2_ext_control ctrl;
1236 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1238 ctrls.controls = &ctrl;
1240 ctrl.value = p->value;
1241 if (check_ext_ctrls(&ctrls, 1)) {
1242 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1244 p->value = ctrl.value;
1249 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1251 dbgarg(cmd, "id=0x%x\n", p->id);
1256 struct v4l2_control *p = arg;
1257 struct v4l2_ext_controls ctrls;
1258 struct v4l2_ext_control ctrl;
1260 if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
1263 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1265 if (ops->vidioc_s_ctrl) {
1266 ret = ops->vidioc_s_ctrl(file, fh, p);
1269 if (!ops->vidioc_s_ext_ctrls)
1272 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1274 ctrls.controls = &ctrl;
1276 ctrl.value = p->value;
1277 if (check_ext_ctrls(&ctrls, 1))
1278 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1281 case VIDIOC_G_EXT_CTRLS:
1283 struct v4l2_ext_controls *p = arg;
1285 p->error_idx = p->count;
1286 if (!ops->vidioc_g_ext_ctrls)
1288 if (check_ext_ctrls(p, 0))
1289 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
1290 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1293 case VIDIOC_S_EXT_CTRLS:
1295 struct v4l2_ext_controls *p = arg;
1297 p->error_idx = p->count;
1298 if (!ops->vidioc_s_ext_ctrls)
1300 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1301 if (check_ext_ctrls(p, 0))
1302 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
1305 case VIDIOC_TRY_EXT_CTRLS:
1307 struct v4l2_ext_controls *p = arg;
1309 p->error_idx = p->count;
1310 if (!ops->vidioc_try_ext_ctrls)
1312 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1313 if (check_ext_ctrls(p, 0))
1314 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
1317 case VIDIOC_QUERYMENU:
1319 struct v4l2_querymenu *p = arg;
1321 if (!ops->vidioc_querymenu)
1323 ret = ops->vidioc_querymenu(file, fh, p);
1325 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1326 p->id, p->index, p->name);
1328 dbgarg(cmd, "id=0x%x, index=%d\n",
1332 /* --- audio ---------------------------------------------- */
1333 case VIDIOC_ENUMAUDIO:
1335 struct v4l2_audio *p = arg;
1337 if (!ops->vidioc_enumaudio)
1339 ret = ops->vidioc_enumaudio(file, fh, p);
1341 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1342 "mode=0x%x\n", p->index, p->name,
1343 p->capability, p->mode);
1345 dbgarg(cmd, "index=%d\n", p->index);
1348 case VIDIOC_G_AUDIO:
1350 struct v4l2_audio *p = arg;
1352 if (!ops->vidioc_g_audio)
1355 ret = ops->vidioc_g_audio(file, fh, p);
1357 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1358 "mode=0x%x\n", p->index,
1359 p->name, p->capability, p->mode);
1361 dbgarg(cmd, "index=%d\n", p->index);
1364 case VIDIOC_S_AUDIO:
1366 struct v4l2_audio *p = arg;
1368 if (!ops->vidioc_s_audio)
1370 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1371 "mode=0x%x\n", p->index, p->name,
1372 p->capability, p->mode);
1373 ret = ops->vidioc_s_audio(file, fh, p);
1376 case VIDIOC_ENUMAUDOUT:
1378 struct v4l2_audioout *p = arg;
1380 if (!ops->vidioc_enumaudout)
1382 dbgarg(cmd, "Enum for index=%d\n", p->index);
1383 ret = ops->vidioc_enumaudout(file, fh, p);
1385 dbgarg2("index=%d, name=%s, capability=%d, "
1386 "mode=%d\n", p->index, p->name,
1387 p->capability, p->mode);
1390 case VIDIOC_G_AUDOUT:
1392 struct v4l2_audioout *p = arg;
1394 if (!ops->vidioc_g_audout)
1397 ret = ops->vidioc_g_audout(file, fh, p);
1399 dbgarg2("index=%d, name=%s, capability=%d, "
1400 "mode=%d\n", p->index, p->name,
1401 p->capability, p->mode);
1404 case VIDIOC_S_AUDOUT:
1406 struct v4l2_audioout *p = arg;
1408 if (!ops->vidioc_s_audout)
1410 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1411 "mode=%d\n", p->index, p->name,
1412 p->capability, p->mode);
1414 ret = ops->vidioc_s_audout(file, fh, p);
1417 case VIDIOC_G_MODULATOR:
1419 struct v4l2_modulator *p = arg;
1421 if (!ops->vidioc_g_modulator)
1423 ret = ops->vidioc_g_modulator(file, fh, p);
1425 dbgarg(cmd, "index=%d, name=%s, "
1426 "capability=%d, rangelow=%d,"
1427 " rangehigh=%d, txsubchans=%d\n",
1428 p->index, p->name, p->capability,
1429 p->rangelow, p->rangehigh,
1433 case VIDIOC_S_MODULATOR:
1435 struct v4l2_modulator *p = arg;
1437 if (!ops->vidioc_s_modulator)
1439 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1440 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1441 p->index, p->name, p->capability, p->rangelow,
1442 p->rangehigh, p->txsubchans);
1443 ret = ops->vidioc_s_modulator(file, fh, p);
1448 struct v4l2_crop *p = arg;
1450 if (!ops->vidioc_g_crop)
1453 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1454 ret = ops->vidioc_g_crop(file, fh, p);
1456 dbgrect(vfd, "", &p->c);
1461 struct v4l2_crop *p = arg;
1463 if (!ops->vidioc_s_crop)
1465 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1466 dbgrect(vfd, "", &p->c);
1467 ret = ops->vidioc_s_crop(file, fh, p);
1470 case VIDIOC_CROPCAP:
1472 struct v4l2_cropcap *p = arg;
1474 /*FIXME: Should also show v4l2_fract pixelaspect */
1475 if (!ops->vidioc_cropcap)
1478 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1479 ret = ops->vidioc_cropcap(file, fh, p);
1481 dbgrect(vfd, "bounds ", &p->bounds);
1482 dbgrect(vfd, "defrect ", &p->defrect);
1486 case VIDIOC_G_JPEGCOMP:
1488 struct v4l2_jpegcompression *p = arg;
1490 if (!ops->vidioc_g_jpegcomp)
1493 ret = ops->vidioc_g_jpegcomp(file, fh, p);
1495 dbgarg(cmd, "quality=%d, APPn=%d, "
1496 "APP_len=%d, COM_len=%d, "
1497 "jpeg_markers=%d\n",
1498 p->quality, p->APPn, p->APP_len,
1499 p->COM_len, p->jpeg_markers);
1502 case VIDIOC_S_JPEGCOMP:
1504 struct v4l2_jpegcompression *p = arg;
1506 if (!ops->vidioc_g_jpegcomp)
1508 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1509 "COM_len=%d, jpeg_markers=%d\n",
1510 p->quality, p->APPn, p->APP_len,
1511 p->COM_len, p->jpeg_markers);
1512 ret = ops->vidioc_s_jpegcomp(file, fh, p);
1515 case VIDIOC_G_ENC_INDEX:
1517 struct v4l2_enc_idx *p = arg;
1519 if (!ops->vidioc_g_enc_index)
1521 ret = ops->vidioc_g_enc_index(file, fh, p);
1523 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1524 p->entries, p->entries_cap);
1527 case VIDIOC_ENCODER_CMD:
1529 struct v4l2_encoder_cmd *p = arg;
1531 if (!ops->vidioc_encoder_cmd)
1533 ret = ops->vidioc_encoder_cmd(file, fh, p);
1535 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1538 case VIDIOC_TRY_ENCODER_CMD:
1540 struct v4l2_encoder_cmd *p = arg;
1542 if (!ops->vidioc_try_encoder_cmd)
1544 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
1546 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1551 struct v4l2_streamparm *p = arg;
1553 if (ops->vidioc_g_parm) {
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 dbgarg(cmd, "type=%d\n", p->type);
1574 ret = ops->vidioc_s_parm(file, fh, p);
1577 case VIDIOC_G_TUNER:
1579 struct v4l2_tuner *p = arg;
1581 if (!ops->vidioc_g_tuner)
1584 ret = ops->vidioc_g_tuner(file, fh, p);
1586 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1587 "capability=0x%x, rangelow=%d, "
1588 "rangehigh=%d, signal=%d, afc=%d, "
1589 "rxsubchans=0x%x, audmode=%d\n",
1590 p->index, p->name, p->type,
1591 p->capability, p->rangelow,
1592 p->rangehigh, p->signal, p->afc,
1593 p->rxsubchans, p->audmode);
1596 case VIDIOC_S_TUNER:
1598 struct v4l2_tuner *p = arg;
1600 if (!ops->vidioc_s_tuner)
1602 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1603 "capability=0x%x, rangelow=%d, "
1604 "rangehigh=%d, signal=%d, afc=%d, "
1605 "rxsubchans=0x%x, audmode=%d\n",
1606 p->index, p->name, p->type,
1607 p->capability, p->rangelow,
1608 p->rangehigh, p->signal, p->afc,
1609 p->rxsubchans, p->audmode);
1610 ret = ops->vidioc_s_tuner(file, fh, p);
1613 case VIDIOC_G_FREQUENCY:
1615 struct v4l2_frequency *p = arg;
1617 if (!ops->vidioc_g_frequency)
1620 ret = ops->vidioc_g_frequency(file, fh, p);
1622 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1623 p->tuner, p->type, p->frequency);
1626 case VIDIOC_S_FREQUENCY:
1628 struct v4l2_frequency *p = arg;
1630 if (!ops->vidioc_s_frequency)
1632 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1633 p->tuner, p->type, p->frequency);
1634 ret = ops->vidioc_s_frequency(file, fh, p);
1637 case VIDIOC_G_SLICED_VBI_CAP:
1639 struct v4l2_sliced_vbi_cap *p = arg;
1641 if (!ops->vidioc_g_sliced_vbi_cap)
1644 /* Clear up to type, everything after type is zerod already */
1645 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1647 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1648 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1650 dbgarg2("service_set=%d\n", p->service_set);
1653 case VIDIOC_LOG_STATUS:
1655 if (!ops->vidioc_log_status)
1657 ret = ops->vidioc_log_status(file, fh);
1660 #ifdef CONFIG_VIDEO_ADV_DEBUG
1661 case VIDIOC_DBG_G_REGISTER:
1663 struct v4l2_dbg_register *p = arg;
1665 if (!capable(CAP_SYS_ADMIN))
1667 else if (ops->vidioc_g_register)
1668 ret = ops->vidioc_g_register(file, fh, p);
1671 case VIDIOC_DBG_S_REGISTER:
1673 struct v4l2_dbg_register *p = arg;
1675 if (!capable(CAP_SYS_ADMIN))
1677 else if (ops->vidioc_s_register)
1678 ret = ops->vidioc_s_register(file, fh, p);
1682 case VIDIOC_DBG_G_CHIP_IDENT:
1684 struct v4l2_dbg_chip_ident *p = arg;
1686 if (!ops->vidioc_g_chip_ident)
1688 p->ident = V4L2_IDENT_NONE;
1690 ret = ops->vidioc_g_chip_ident(file, fh, p);
1692 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1695 case VIDIOC_S_HW_FREQ_SEEK:
1697 struct v4l2_hw_freq_seek *p = arg;
1699 if (!ops->vidioc_s_hw_freq_seek)
1702 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1703 p->tuner, p->type, p->seek_upward, p->wrap_around);
1704 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1707 case VIDIOC_ENUM_FRAMESIZES:
1709 struct v4l2_frmsizeenum *p = arg;
1711 if (!ops->vidioc_enum_framesizes)
1714 ret = ops->vidioc_enum_framesizes(file, fh, p);
1716 "index=%d, pixelformat=%d, type=%d ",
1717 p->index, p->pixel_format, p->type);
1719 case V4L2_FRMSIZE_TYPE_DISCRETE:
1720 dbgarg2("width = %d, height=%d\n",
1721 p->discrete.width, p->discrete.height);
1723 case V4L2_FRMSIZE_TYPE_STEPWISE:
1724 dbgarg2("min %dx%d, max %dx%d, step %dx%d\n",
1725 p->stepwise.min_width, p->stepwise.min_height,
1726 p->stepwise.step_width, p->stepwise.step_height,
1727 p->stepwise.max_width, p->stepwise.max_height);
1729 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1730 dbgarg2("continuous\n");
1733 dbgarg2("- Unknown type!\n");
1738 case VIDIOC_ENUM_FRAMEINTERVALS:
1740 struct v4l2_frmivalenum *p = arg;
1742 if (!ops->vidioc_enum_frameintervals)
1745 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1747 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1748 p->index, p->pixel_format,
1749 p->width, p->height, p->type);
1751 case V4L2_FRMIVAL_TYPE_DISCRETE:
1752 dbgarg2("fps=%d/%d\n",
1753 p->discrete.numerator,
1754 p->discrete.denominator);
1756 case V4L2_FRMIVAL_TYPE_STEPWISE:
1757 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1758 p->stepwise.min.numerator,
1759 p->stepwise.min.denominator,
1760 p->stepwise.max.numerator,
1761 p->stepwise.max.denominator,
1762 p->stepwise.step.numerator,
1763 p->stepwise.step.denominator);
1765 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1766 dbgarg2("continuous\n");
1769 dbgarg2("- Unknown type!\n");
1776 if (!ops->vidioc_default)
1778 ret = ops->vidioc_default(file, fh, cmd, arg);
1783 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1785 v4l_print_ioctl(vfd->name, cmd);
1786 printk(KERN_CONT " error %ld\n", ret);
1793 /* In some cases, only a few fields are used as input, i.e. when the app sets
1794 * "index" and then the driver fills in the rest of the structure for the thing
1795 * with that index. We only need to copy up the first non-input field. */
1796 static unsigned long cmd_input_size(unsigned int cmd)
1798 /* Size of structure up to and including 'field' */
1799 #define CMDINSIZE(cmd, type, field) case _IOC_NR(VIDIOC_##cmd): return \
1800 offsetof(struct v4l2_##type, field) + \
1801 sizeof(((struct v4l2_##type *)0)->field);
1803 switch (_IOC_NR(cmd)) {
1804 CMDINSIZE(ENUM_FMT, fmtdesc, type);
1805 CMDINSIZE(G_FMT, format, type);
1806 CMDINSIZE(QUERYBUF, buffer, type);
1807 CMDINSIZE(G_PARM, streamparm, type);
1808 CMDINSIZE(ENUMSTD, standard, index);
1809 CMDINSIZE(ENUMINPUT, input, index);
1810 CMDINSIZE(G_CTRL, control, id);
1811 CMDINSIZE(G_TUNER, tuner, index);
1812 CMDINSIZE(QUERYCTRL, queryctrl, id);
1813 CMDINSIZE(QUERYMENU, querymenu, index);
1814 CMDINSIZE(ENUMOUTPUT, output, index);
1815 CMDINSIZE(G_MODULATOR, modulator, index);
1816 CMDINSIZE(G_FREQUENCY, frequency, tuner);
1817 CMDINSIZE(CROPCAP, cropcap, type);
1818 CMDINSIZE(G_CROP, crop, type);
1819 CMDINSIZE(ENUMAUDIO, audio, index);
1820 CMDINSIZE(ENUMAUDOUT, audioout, index);
1821 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
1822 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
1823 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
1824 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
1825 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
1827 return _IOC_SIZE(cmd);
1831 long video_ioctl2(struct file *file,
1832 unsigned int cmd, unsigned long arg)
1839 size_t ctrls_size = 0;
1840 void __user *user_ptr = NULL;
1842 #ifdef __OLD_VIDIOC_
1843 cmd = video_fix_command(cmd);
1845 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1846 cmd == VIDIOC_TRY_EXT_CTRLS);
1848 /* Copy arguments into temp kernel buffer */
1849 if (_IOC_DIR(cmd) != _IOC_NONE) {
1850 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1853 /* too big to allocate from stack */
1854 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
1861 if (_IOC_DIR(cmd) & _IOC_WRITE) {
1862 unsigned long n = cmd_input_size(cmd);
1864 if (copy_from_user(parg, (void __user *)arg, n))
1867 /* zero out anything we don't copy from userspace */
1868 if (n < _IOC_SIZE(cmd))
1869 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
1871 /* read-only ioctl */
1872 memset(parg, 0, _IOC_SIZE(cmd));
1877 struct v4l2_ext_controls *p = parg;
1879 /* In case of an error, tell the caller that it wasn't
1880 a specific control that caused it. */
1881 p->error_idx = p->count;
1882 user_ptr = (void __user *)p->controls;
1884 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1885 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1886 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1891 if (copy_from_user(mbuf, user_ptr, ctrls_size))
1898 err = __video_do_ioctl(file, cmd, parg);
1899 if (err == -ENOIOCTLCMD)
1902 struct v4l2_ext_controls *p = parg;
1904 p->controls = (void *)user_ptr;
1905 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1913 /* Copy results into user buffer */
1914 switch (_IOC_DIR(cmd)) {
1916 case (_IOC_WRITE | _IOC_READ):
1917 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
1926 EXPORT_SYMBOL(video_ioctl2);