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>
28 #include <linux/video_decoder.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 /* Fill in the fields of a v4l2_standard structure according to the
105 'id' and 'transmission' parameters. Returns negative on error. */
106 int v4l2_video_std_construct(struct v4l2_standard *vs,
107 int id, const char *name)
109 u32 index = vs->index;
111 memset(vs, 0, sizeof(struct v4l2_standard));
114 if (id & V4L2_STD_525_60) {
115 vs->frameperiod.numerator = 1001;
116 vs->frameperiod.denominator = 30000;
117 vs->framelines = 525;
119 vs->frameperiod.numerator = 1;
120 vs->frameperiod.denominator = 25;
121 vs->framelines = 625;
123 strlcpy(vs->name, name, sizeof(vs->name));
126 EXPORT_SYMBOL(v4l2_video_std_construct);
128 /* ----------------------------------------------------------------- */
129 /* some arrays for pretty-printing debug messages of enum types */
131 const char *v4l2_field_names[] = {
132 [V4L2_FIELD_ANY] = "any",
133 [V4L2_FIELD_NONE] = "none",
134 [V4L2_FIELD_TOP] = "top",
135 [V4L2_FIELD_BOTTOM] = "bottom",
136 [V4L2_FIELD_INTERLACED] = "interlaced",
137 [V4L2_FIELD_SEQ_TB] = "seq-tb",
138 [V4L2_FIELD_SEQ_BT] = "seq-bt",
139 [V4L2_FIELD_ALTERNATE] = "alternate",
140 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
141 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
143 EXPORT_SYMBOL(v4l2_field_names);
145 const char *v4l2_type_names[] = {
146 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
147 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
148 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
149 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
150 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
151 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
152 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
153 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
155 EXPORT_SYMBOL(v4l2_type_names);
157 static const char *v4l2_memory_names[] = {
158 [V4L2_MEMORY_MMAP] = "mmap",
159 [V4L2_MEMORY_USERPTR] = "userptr",
160 [V4L2_MEMORY_OVERLAY] = "overlay",
163 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
166 /* ------------------------------------------------------------------ */
167 /* debug help functions */
169 #ifdef CONFIG_VIDEO_V4L1_COMPAT
170 static const char *v4l1_ioctls[] = {
171 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
172 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
173 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
174 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
175 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
176 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
177 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
178 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
179 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
180 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
181 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
182 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
183 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
184 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
185 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
186 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
187 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
188 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
189 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
190 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
191 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
192 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
193 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
194 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
195 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
196 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
197 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
198 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
199 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
201 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
204 static const char *v4l2_ioctls[] = {
205 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
206 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
207 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
208 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
209 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
210 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
211 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
212 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
213 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
214 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
215 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
216 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
217 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
218 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
219 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
220 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
221 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
222 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
223 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
224 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
225 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
226 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
227 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
228 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
229 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
230 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
231 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
232 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
233 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
234 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
235 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
236 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
237 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
238 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
239 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
240 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
241 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
242 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
243 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
244 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
245 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
246 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
247 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
248 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
249 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
250 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
251 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
252 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
253 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
254 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
255 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
256 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
257 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
258 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
259 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
261 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
262 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
263 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
264 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
265 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
267 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
268 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
270 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
271 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
274 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
276 static const char *v4l2_int_ioctls[] = {
277 #ifdef CONFIG_VIDEO_V4L1_COMPAT
278 [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES",
279 [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS",
280 [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM",
281 [_IOC_NR(DECODER_SET_INPUT)] = "DECODER_SET_INPUT",
282 [_IOC_NR(DECODER_SET_OUTPUT)] = "DECODER_SET_OUTPUT",
283 [_IOC_NR(DECODER_ENABLE_OUTPUT)] = "DECODER_ENABLE_OUTPUT",
284 [_IOC_NR(DECODER_SET_PICTURE)] = "DECODER_SET_PICTURE",
285 [_IOC_NR(DECODER_SET_GPIO)] = "DECODER_SET_GPIO",
286 [_IOC_NR(DECODER_INIT)] = "DECODER_INIT",
287 [_IOC_NR(DECODER_SET_VBI_BYPASS)] = "DECODER_SET_VBI_BYPASS",
288 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP",
290 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
292 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
293 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
294 [_IOC_NR(TUNER_SET_CONFIG)] = "TUNER_SET_CONFIG",
296 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
297 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
298 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
299 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
300 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
301 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
302 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
303 [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
304 [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
305 [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
306 [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
307 [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING",
308 [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)] = "VIDIOC_INT_S_CRYSTAL_FREQ",
309 [_IOC_NR(VIDIOC_INT_INIT)] = "VIDIOC_INT_INIT",
310 [_IOC_NR(VIDIOC_INT_G_STD_OUTPUT)] = "VIDIOC_INT_G_STD_OUTPUT",
311 [_IOC_NR(VIDIOC_INT_S_STD_OUTPUT)] = "VIDIOC_INT_S_STD_OUTPUT",
313 #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
315 /* Common ioctl debug function. This function can be used by
316 external ioctl messages as well as internal V4L ioctl */
317 void v4l_printk_ioctl(unsigned int cmd)
321 switch (_IOC_TYPE(cmd)) {
323 if (_IOC_NR(cmd) >= V4L2_INT_IOCTLS) {
327 printk("%s", v4l2_int_ioctls[_IOC_NR(cmd)]);
329 #ifdef CONFIG_VIDEO_V4L1_COMPAT
331 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
335 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
339 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
343 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
349 switch (_IOC_DIR(cmd)) {
350 case _IOC_NONE: dir = "--"; break;
351 case _IOC_READ: dir = "r-"; break;
352 case _IOC_WRITE: dir = "-w"; break;
353 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
354 default: dir = "*ERR*"; break;
356 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
357 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
359 EXPORT_SYMBOL(v4l_printk_ioctl);
362 * helper function -- handles userspace copying for ioctl arguments
367 video_fix_command(unsigned int cmd)
370 case VIDIOC_OVERLAY_OLD:
371 cmd = VIDIOC_OVERLAY;
373 case VIDIOC_S_PARM_OLD:
376 case VIDIOC_S_CTRL_OLD:
379 case VIDIOC_G_AUDIO_OLD:
380 cmd = VIDIOC_G_AUDIO;
382 case VIDIOC_G_AUDOUT_OLD:
383 cmd = VIDIOC_G_AUDOUT;
385 case VIDIOC_CROPCAP_OLD:
386 cmd = VIDIOC_CROPCAP;
394 * Obsolete usercopy function - Should be removed soon
397 video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
405 size_t ctrls_size = 0;
406 void __user *user_ptr = NULL;
409 cmd = video_fix_command(cmd);
411 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
412 cmd == VIDIOC_TRY_EXT_CTRLS);
414 /* Copy arguments into temp kernel buffer */
415 switch (_IOC_DIR(cmd)) {
421 case (_IOC_WRITE | _IOC_READ):
422 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
425 /* too big to allocate from stack */
426 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
433 if (_IOC_DIR(cmd) & _IOC_WRITE)
434 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
439 struct v4l2_ext_controls *p = parg;
441 /* In case of an error, tell the caller that it wasn't
442 a specific control that caused it. */
443 p->error_idx = p->count;
444 user_ptr = (void __user *)p->controls;
446 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
447 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
448 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
453 if (copy_from_user(mbuf, user_ptr, ctrls_size))
460 err = func(file, cmd, parg);
461 if (err == -ENOIOCTLCMD)
464 struct v4l2_ext_controls *p = parg;
466 p->controls = (void *)user_ptr;
467 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
475 /* Copy results into user buffer */
476 switch (_IOC_DIR(cmd)) {
478 case (_IOC_WRITE | _IOC_READ):
479 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
488 EXPORT_SYMBOL(video_usercopy);
490 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
491 struct v4l2_buffer *p)
493 struct v4l2_timecode *tc = &p->timecode;
495 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
496 "bytesused=%d, flags=0x%08d, "
497 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
498 p->timestamp.tv_sec / 3600,
499 (int)(p->timestamp.tv_sec / 60) % 60,
500 (int)(p->timestamp.tv_sec % 60),
501 (long)p->timestamp.tv_usec,
503 prt_names(p->type, v4l2_type_names),
504 p->bytesused, p->flags,
505 p->field, p->sequence,
506 prt_names(p->memory, v4l2_memory_names),
507 p->m.userptr, p->length);
508 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
509 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
510 tc->hours, tc->minutes, tc->seconds,
511 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
514 static inline void dbgrect(struct video_device *vfd, char *s,
517 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
518 r->width, r->height);
521 static inline void v4l_print_pix_fmt(struct video_device *vfd,
522 struct v4l2_pix_format *fmt)
524 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
525 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
526 fmt->width, fmt->height,
527 (fmt->pixelformat & 0xff),
528 (fmt->pixelformat >> 8) & 0xff,
529 (fmt->pixelformat >> 16) & 0xff,
530 (fmt->pixelformat >> 24) & 0xff,
531 prt_names(fmt->field, v4l2_field_names),
532 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
535 static inline void v4l_print_ext_ctrls(unsigned int cmd,
536 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
540 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
543 printk(KERN_CONT "class=0x%x", c->ctrl_class);
544 for (i = 0; i < c->count; i++) {
546 printk(KERN_CONT " id/val=0x%x/0x%x",
547 c->controls[i].id, c->controls[i].value);
549 printk(KERN_CONT " id=0x%x", c->controls[i].id);
551 printk(KERN_CONT "\n");
554 static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
558 /* zero the reserved fields */
559 c->reserved[0] = c->reserved[1] = 0;
560 for (i = 0; i < c->count; i++) {
561 c->controls[i].reserved2[0] = 0;
562 c->controls[i].reserved2[1] = 0;
564 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
565 when using extended controls.
566 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
567 is it allowed for backwards compatibility.
569 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
571 /* Check that all controls are from the same control class. */
572 for (i = 0; i < c->count; i++) {
573 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
581 static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
587 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
588 if (ops->vidioc_try_fmt_vid_cap)
591 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
592 if (ops->vidioc_try_fmt_vid_overlay)
595 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
596 if (ops->vidioc_try_fmt_vid_out)
599 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
600 if (ops->vidioc_try_fmt_vid_out_overlay)
603 case V4L2_BUF_TYPE_VBI_CAPTURE:
604 if (ops->vidioc_try_fmt_vbi_cap)
607 case V4L2_BUF_TYPE_VBI_OUTPUT:
608 if (ops->vidioc_try_fmt_vbi_out)
611 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
612 if (ops->vidioc_try_fmt_sliced_vbi_cap)
615 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
616 if (ops->vidioc_try_fmt_sliced_vbi_out)
619 case V4L2_BUF_TYPE_PRIVATE:
620 if (ops->vidioc_try_fmt_type_private)
627 static long __video_do_ioctl(struct file *file,
628 unsigned int cmd, void *arg)
630 struct video_device *vfd = video_devdata(file);
631 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
632 void *fh = file->private_data;
635 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
636 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
637 v4l_print_ioctl(vfd->name, cmd);
638 printk(KERN_CONT "\n");
642 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
647 #ifdef CONFIG_VIDEO_V4L1_COMPAT
648 /***********************************************************
649 Handles calls to the obsoleted V4L1 API
650 Due to the nature of VIDIOCGMBUF, each driver that supports
651 V4L1 should implement its own handler for this ioctl.
652 ***********************************************************/
654 /* --- streaming capture ------------------------------------- */
655 if (cmd == VIDIOCGMBUF) {
656 struct video_mbuf *p = arg;
658 memset(p, 0, sizeof(*p));
660 if (!ops->vidiocgmbuf)
662 ret = ops->vidiocgmbuf(file, fh, p);
664 dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
666 (unsigned long)p->offsets);
670 /********************************************************
671 All other V4L1 calls are handled by v4l1_compat module.
672 Those calls will be translated into V4L2 calls, and
673 __video_do_ioctl will be called again, with one or more
675 ********************************************************/
676 if (_IOC_TYPE(cmd) == 'v' && _IOC_NR(cmd) < BASE_VIDIOCPRIVATE)
677 return v4l_compat_translate_ioctl(file, cmd, arg,
682 /* --- capabilities ------------------------------------------ */
683 case VIDIOC_QUERYCAP:
685 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
686 memset(cap, 0, sizeof(*cap));
688 if (!ops->vidioc_querycap)
691 ret = ops->vidioc_querycap(file, fh, cap);
693 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
695 "capabilities=0x%08x\n",
696 cap->driver, cap->card, cap->bus_info,
702 /* --- priority ------------------------------------------ */
703 case VIDIOC_G_PRIORITY:
705 enum v4l2_priority *p = arg;
707 if (!ops->vidioc_g_priority)
709 ret = ops->vidioc_g_priority(file, fh, p);
711 dbgarg(cmd, "priority is %d\n", *p);
714 case VIDIOC_S_PRIORITY:
716 enum v4l2_priority *p = arg;
718 if (!ops->vidioc_s_priority)
720 dbgarg(cmd, "setting priority to %d\n", *p);
721 ret = ops->vidioc_s_priority(file, fh, *p);
725 /* --- capture ioctls ---------------------------------------- */
726 case VIDIOC_ENUM_FMT:
728 struct v4l2_fmtdesc *f = arg;
729 enum v4l2_buf_type type;
734 memset(f, 0, sizeof(*f));
739 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
740 if (ops->vidioc_enum_fmt_vid_cap)
741 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
743 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
744 if (ops->vidioc_enum_fmt_vid_overlay)
745 ret = ops->vidioc_enum_fmt_vid_overlay(file,
748 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
749 if (ops->vidioc_enum_fmt_vid_out)
750 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
752 case V4L2_BUF_TYPE_PRIVATE:
753 if (ops->vidioc_enum_fmt_type_private)
754 ret = ops->vidioc_enum_fmt_type_private(file,
761 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
762 "pixelformat=%c%c%c%c, description='%s'\n",
763 f->index, f->type, f->flags,
764 (f->pixelformat & 0xff),
765 (f->pixelformat >> 8) & 0xff,
766 (f->pixelformat >> 16) & 0xff,
767 (f->pixelformat >> 24) & 0xff,
773 struct v4l2_format *f = (struct v4l2_format *)arg;
775 memset(f->fmt.raw_data, 0, sizeof(f->fmt.raw_data));
777 /* FIXME: Should be one dump per type */
778 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
781 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
782 if (ops->vidioc_g_fmt_vid_cap)
783 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
785 v4l_print_pix_fmt(vfd, &f->fmt.pix);
787 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
788 if (ops->vidioc_g_fmt_vid_overlay)
789 ret = ops->vidioc_g_fmt_vid_overlay(file,
792 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
793 if (ops->vidioc_g_fmt_vid_out)
794 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
796 v4l_print_pix_fmt(vfd, &f->fmt.pix);
798 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
799 if (ops->vidioc_g_fmt_vid_out_overlay)
800 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
803 case V4L2_BUF_TYPE_VBI_CAPTURE:
804 if (ops->vidioc_g_fmt_vbi_cap)
805 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
807 case V4L2_BUF_TYPE_VBI_OUTPUT:
808 if (ops->vidioc_g_fmt_vbi_out)
809 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
811 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
812 if (ops->vidioc_g_fmt_sliced_vbi_cap)
813 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
816 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
817 if (ops->vidioc_g_fmt_sliced_vbi_out)
818 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
821 case V4L2_BUF_TYPE_PRIVATE:
822 if (ops->vidioc_g_fmt_type_private)
823 ret = ops->vidioc_g_fmt_type_private(file,
832 struct v4l2_format *f = (struct v4l2_format *)arg;
834 /* FIXME: Should be one dump per type */
835 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
838 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
839 v4l_print_pix_fmt(vfd, &f->fmt.pix);
840 if (ops->vidioc_s_fmt_vid_cap)
841 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
843 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
844 if (ops->vidioc_s_fmt_vid_overlay)
845 ret = ops->vidioc_s_fmt_vid_overlay(file,
848 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
849 v4l_print_pix_fmt(vfd, &f->fmt.pix);
850 if (ops->vidioc_s_fmt_vid_out)
851 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
853 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
854 if (ops->vidioc_s_fmt_vid_out_overlay)
855 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
858 case V4L2_BUF_TYPE_VBI_CAPTURE:
859 if (ops->vidioc_s_fmt_vbi_cap)
860 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
862 case V4L2_BUF_TYPE_VBI_OUTPUT:
863 if (ops->vidioc_s_fmt_vbi_out)
864 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
866 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
867 if (ops->vidioc_s_fmt_sliced_vbi_cap)
868 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
871 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
872 if (ops->vidioc_s_fmt_sliced_vbi_out)
873 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
876 case V4L2_BUF_TYPE_PRIVATE:
877 if (ops->vidioc_s_fmt_type_private)
878 ret = ops->vidioc_s_fmt_type_private(file,
886 struct v4l2_format *f = (struct v4l2_format *)arg;
888 /* FIXME: Should be one dump per type */
889 dbgarg(cmd, "type=%s\n", prt_names(f->type,
892 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
893 if (ops->vidioc_try_fmt_vid_cap)
894 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
896 v4l_print_pix_fmt(vfd, &f->fmt.pix);
898 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
899 if (ops->vidioc_try_fmt_vid_overlay)
900 ret = ops->vidioc_try_fmt_vid_overlay(file,
903 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
904 if (ops->vidioc_try_fmt_vid_out)
905 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
907 v4l_print_pix_fmt(vfd, &f->fmt.pix);
909 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
910 if (ops->vidioc_try_fmt_vid_out_overlay)
911 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
914 case V4L2_BUF_TYPE_VBI_CAPTURE:
915 if (ops->vidioc_try_fmt_vbi_cap)
916 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
918 case V4L2_BUF_TYPE_VBI_OUTPUT:
919 if (ops->vidioc_try_fmt_vbi_out)
920 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
922 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
923 if (ops->vidioc_try_fmt_sliced_vbi_cap)
924 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
927 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
928 if (ops->vidioc_try_fmt_sliced_vbi_out)
929 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
932 case V4L2_BUF_TYPE_PRIVATE:
933 if (ops->vidioc_try_fmt_type_private)
934 ret = ops->vidioc_try_fmt_type_private(file,
941 /* FIXME: Those buf reqs could be handled here,
942 with some changes on videobuf to allow its header to be included at
943 videodev2.h or being merged at videodev2.
947 struct v4l2_requestbuffers *p = arg;
949 if (!ops->vidioc_reqbufs)
951 ret = check_fmt(ops, p->type);
955 ret = ops->vidioc_reqbufs(file, fh, p);
956 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
958 prt_names(p->type, v4l2_type_names),
959 prt_names(p->memory, v4l2_memory_names));
962 case VIDIOC_QUERYBUF:
964 struct v4l2_buffer *p = arg;
966 if (!ops->vidioc_querybuf)
968 ret = check_fmt(ops, p->type);
972 ret = ops->vidioc_querybuf(file, fh, p);
979 struct v4l2_buffer *p = arg;
981 if (!ops->vidioc_qbuf)
983 ret = check_fmt(ops, p->type);
987 ret = ops->vidioc_qbuf(file, fh, p);
994 struct v4l2_buffer *p = arg;
996 if (!ops->vidioc_dqbuf)
998 ret = check_fmt(ops, p->type);
1002 ret = ops->vidioc_dqbuf(file, fh, p);
1004 dbgbuf(cmd, vfd, p);
1007 case VIDIOC_OVERLAY:
1011 if (!ops->vidioc_overlay)
1013 dbgarg(cmd, "value=%d\n", *i);
1014 ret = ops->vidioc_overlay(file, fh, *i);
1019 struct v4l2_framebuffer *p = arg;
1021 if (!ops->vidioc_g_fbuf)
1023 ret = ops->vidioc_g_fbuf(file, fh, arg);
1025 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1026 p->capability, p->flags,
1027 (unsigned long)p->base);
1028 v4l_print_pix_fmt(vfd, &p->fmt);
1034 struct v4l2_framebuffer *p = arg;
1036 if (!ops->vidioc_s_fbuf)
1038 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1039 p->capability, p->flags, (unsigned long)p->base);
1040 v4l_print_pix_fmt(vfd, &p->fmt);
1041 ret = ops->vidioc_s_fbuf(file, fh, arg);
1044 case VIDIOC_STREAMON:
1046 enum v4l2_buf_type i = *(int *)arg;
1048 if (!ops->vidioc_streamon)
1050 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1051 ret = ops->vidioc_streamon(file, fh, i);
1054 case VIDIOC_STREAMOFF:
1056 enum v4l2_buf_type i = *(int *)arg;
1058 if (!ops->vidioc_streamoff)
1060 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1061 ret = ops->vidioc_streamoff(file, fh, i);
1064 /* ---------- tv norms ---------- */
1065 case VIDIOC_ENUMSTD:
1067 struct v4l2_standard *p = arg;
1068 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1069 unsigned int index = p->index, i, j = 0;
1070 const char *descr = "";
1072 /* Return norm array in a canonical way */
1073 for (i = 0; i <= index && id; i++) {
1074 /* last std value in the standards array is 0, so this
1075 while always ends there since (id & 0) == 0. */
1076 while ((id & standards[j].std) != standards[j].std)
1078 curr_id = standards[j].std;
1079 descr = standards[j].descr;
1083 if (curr_id != V4L2_STD_PAL &&
1084 curr_id != V4L2_STD_SECAM &&
1085 curr_id != V4L2_STD_NTSC)
1091 v4l2_video_std_construct(p, curr_id, descr);
1094 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1095 "framelines=%d\n", p->index,
1096 (unsigned long long)p->id, p->name,
1097 p->frameperiod.numerator,
1098 p->frameperiod.denominator,
1106 v4l2_std_id *id = arg;
1109 /* Calls the specific handler */
1110 if (ops->vidioc_g_std)
1111 ret = ops->vidioc_g_std(file, fh, id);
1113 *id = vfd->current_norm;
1116 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1121 v4l2_std_id *id = arg, norm;
1123 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1125 norm = (*id) & vfd->tvnorms;
1126 if (vfd->tvnorms && !norm) /* Check if std is supported */
1129 /* Calls the specific handler */
1130 if (ops->vidioc_s_std)
1131 ret = ops->vidioc_s_std(file, fh, &norm);
1135 /* Updates standard information */
1137 vfd->current_norm = norm;
1140 case VIDIOC_QUERYSTD:
1142 v4l2_std_id *p = arg;
1144 if (!ops->vidioc_querystd)
1146 ret = ops->vidioc_querystd(file, fh, arg);
1148 dbgarg(cmd, "detected std=%08Lx\n",
1149 (unsigned long long)*p);
1152 /* ------ input switching ---------- */
1153 /* FIXME: Inputs can be handled inside videodev2 */
1154 case VIDIOC_ENUMINPUT:
1156 struct v4l2_input *p = arg;
1159 if (!ops->vidioc_enum_input)
1161 memset(p, 0, sizeof(*p));
1164 ret = ops->vidioc_enum_input(file, fh, p);
1166 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1168 "tuner=%d, std=%08Lx, status=%d\n",
1169 p->index, p->name, p->type, p->audioset,
1171 (unsigned long long)p->std,
1175 case VIDIOC_G_INPUT:
1177 unsigned int *i = arg;
1179 if (!ops->vidioc_g_input)
1181 ret = ops->vidioc_g_input(file, fh, i);
1183 dbgarg(cmd, "value=%d\n", *i);
1186 case VIDIOC_S_INPUT:
1188 unsigned int *i = arg;
1190 if (!ops->vidioc_s_input)
1192 dbgarg(cmd, "value=%d\n", *i);
1193 ret = ops->vidioc_s_input(file, fh, *i);
1197 /* ------ output switching ---------- */
1198 case VIDIOC_ENUMOUTPUT:
1200 struct v4l2_output *p = arg;
1203 if (!ops->vidioc_enum_output)
1205 memset(p, 0, sizeof(*p));
1208 ret = ops->vidioc_enum_output(file, fh, p);
1210 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1212 "modulator=%d, std=0x%08Lx\n",
1213 p->index, p->name, p->type, p->audioset,
1214 p->modulator, (unsigned long long)p->std);
1217 case VIDIOC_G_OUTPUT:
1219 unsigned int *i = arg;
1221 if (!ops->vidioc_g_output)
1223 ret = ops->vidioc_g_output(file, fh, i);
1225 dbgarg(cmd, "value=%d\n", *i);
1228 case VIDIOC_S_OUTPUT:
1230 unsigned int *i = arg;
1232 if (!ops->vidioc_s_output)
1234 dbgarg(cmd, "value=%d\n", *i);
1235 ret = ops->vidioc_s_output(file, fh, *i);
1239 /* --- controls ---------------------------------------------- */
1240 case VIDIOC_QUERYCTRL:
1242 struct v4l2_queryctrl *p = arg;
1244 if (!ops->vidioc_queryctrl)
1246 ret = ops->vidioc_queryctrl(file, fh, p);
1248 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1249 "step=%d, default=%d, flags=0x%08x\n",
1250 p->id, p->type, p->name,
1251 p->minimum, p->maximum,
1252 p->step, p->default_value, p->flags);
1254 dbgarg(cmd, "id=0x%x\n", p->id);
1259 struct v4l2_control *p = arg;
1261 if (ops->vidioc_g_ctrl)
1262 ret = ops->vidioc_g_ctrl(file, fh, p);
1263 else if (ops->vidioc_g_ext_ctrls) {
1264 struct v4l2_ext_controls ctrls;
1265 struct v4l2_ext_control ctrl;
1267 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1269 ctrls.controls = &ctrl;
1271 ctrl.value = p->value;
1272 if (check_ext_ctrls(&ctrls, 1)) {
1273 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1275 p->value = ctrl.value;
1280 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1282 dbgarg(cmd, "id=0x%x\n", p->id);
1287 struct v4l2_control *p = arg;
1288 struct v4l2_ext_controls ctrls;
1289 struct v4l2_ext_control ctrl;
1291 if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
1294 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1296 if (ops->vidioc_s_ctrl) {
1297 ret = ops->vidioc_s_ctrl(file, fh, p);
1300 if (!ops->vidioc_s_ext_ctrls)
1303 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1305 ctrls.controls = &ctrl;
1307 ctrl.value = p->value;
1308 if (check_ext_ctrls(&ctrls, 1))
1309 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1312 case VIDIOC_G_EXT_CTRLS:
1314 struct v4l2_ext_controls *p = arg;
1316 p->error_idx = p->count;
1317 if (!ops->vidioc_g_ext_ctrls)
1319 if (check_ext_ctrls(p, 0))
1320 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
1321 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1324 case VIDIOC_S_EXT_CTRLS:
1326 struct v4l2_ext_controls *p = arg;
1328 p->error_idx = p->count;
1329 if (!ops->vidioc_s_ext_ctrls)
1331 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1332 if (check_ext_ctrls(p, 0))
1333 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
1336 case VIDIOC_TRY_EXT_CTRLS:
1338 struct v4l2_ext_controls *p = arg;
1340 p->error_idx = p->count;
1341 if (!ops->vidioc_try_ext_ctrls)
1343 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1344 if (check_ext_ctrls(p, 0))
1345 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
1348 case VIDIOC_QUERYMENU:
1350 struct v4l2_querymenu *p = arg;
1352 if (!ops->vidioc_querymenu)
1354 ret = ops->vidioc_querymenu(file, fh, p);
1356 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1357 p->id, p->index, p->name);
1359 dbgarg(cmd, "id=0x%x, index=%d\n",
1363 /* --- audio ---------------------------------------------- */
1364 case VIDIOC_ENUMAUDIO:
1366 struct v4l2_audio *p = arg;
1368 if (!ops->vidioc_enumaudio)
1370 ret = ops->vidioc_enumaudio(file, fh, p);
1372 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1373 "mode=0x%x\n", p->index, p->name,
1374 p->capability, p->mode);
1376 dbgarg(cmd, "index=%d\n", p->index);
1379 case VIDIOC_G_AUDIO:
1381 struct v4l2_audio *p = arg;
1382 __u32 index = p->index;
1384 if (!ops->vidioc_g_audio)
1387 memset(p, 0, sizeof(*p));
1389 ret = ops->vidioc_g_audio(file, fh, p);
1391 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1392 "mode=0x%x\n", p->index,
1393 p->name, p->capability, p->mode);
1395 dbgarg(cmd, "index=%d\n", p->index);
1398 case VIDIOC_S_AUDIO:
1400 struct v4l2_audio *p = arg;
1402 if (!ops->vidioc_s_audio)
1404 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1405 "mode=0x%x\n", p->index, p->name,
1406 p->capability, p->mode);
1407 ret = ops->vidioc_s_audio(file, fh, p);
1410 case VIDIOC_ENUMAUDOUT:
1412 struct v4l2_audioout *p = arg;
1414 if (!ops->vidioc_enumaudout)
1416 dbgarg(cmd, "Enum for index=%d\n", p->index);
1417 ret = ops->vidioc_enumaudout(file, fh, p);
1419 dbgarg2("index=%d, name=%s, capability=%d, "
1420 "mode=%d\n", p->index, p->name,
1421 p->capability, p->mode);
1424 case VIDIOC_G_AUDOUT:
1426 struct v4l2_audioout *p = arg;
1428 if (!ops->vidioc_g_audout)
1430 dbgarg(cmd, "Enum for index=%d\n", p->index);
1431 ret = ops->vidioc_g_audout(file, fh, p);
1433 dbgarg2("index=%d, name=%s, capability=%d, "
1434 "mode=%d\n", p->index, p->name,
1435 p->capability, p->mode);
1438 case VIDIOC_S_AUDOUT:
1440 struct v4l2_audioout *p = arg;
1442 if (!ops->vidioc_s_audout)
1444 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1445 "mode=%d\n", p->index, p->name,
1446 p->capability, p->mode);
1448 ret = ops->vidioc_s_audout(file, fh, p);
1451 case VIDIOC_G_MODULATOR:
1453 struct v4l2_modulator *p = arg;
1455 if (!ops->vidioc_g_modulator)
1457 ret = ops->vidioc_g_modulator(file, fh, p);
1459 dbgarg(cmd, "index=%d, name=%s, "
1460 "capability=%d, rangelow=%d,"
1461 " rangehigh=%d, txsubchans=%d\n",
1462 p->index, p->name, p->capability,
1463 p->rangelow, p->rangehigh,
1467 case VIDIOC_S_MODULATOR:
1469 struct v4l2_modulator *p = arg;
1471 if (!ops->vidioc_s_modulator)
1473 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1474 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1475 p->index, p->name, p->capability, p->rangelow,
1476 p->rangehigh, p->txsubchans);
1477 ret = ops->vidioc_s_modulator(file, fh, p);
1482 struct v4l2_crop *p = arg;
1485 if (!ops->vidioc_g_crop)
1489 memset(p, 0, sizeof(*p));
1492 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1493 ret = ops->vidioc_g_crop(file, fh, p);
1495 dbgrect(vfd, "", &p->c);
1500 struct v4l2_crop *p = arg;
1502 if (!ops->vidioc_s_crop)
1504 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1505 dbgrect(vfd, "", &p->c);
1506 ret = ops->vidioc_s_crop(file, fh, p);
1509 case VIDIOC_CROPCAP:
1511 struct v4l2_cropcap *p = arg;
1514 /*FIXME: Should also show v4l2_fract pixelaspect */
1515 if (!ops->vidioc_cropcap)
1519 memset(p, 0, sizeof(*p));
1522 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1523 ret = ops->vidioc_cropcap(file, fh, p);
1525 dbgrect(vfd, "bounds ", &p->bounds);
1526 dbgrect(vfd, "defrect ", &p->defrect);
1530 case VIDIOC_G_JPEGCOMP:
1532 struct v4l2_jpegcompression *p = arg;
1534 if (!ops->vidioc_g_jpegcomp)
1537 memset(p, 0, sizeof(*p));
1539 ret = ops->vidioc_g_jpegcomp(file, fh, p);
1541 dbgarg(cmd, "quality=%d, APPn=%d, "
1542 "APP_len=%d, COM_len=%d, "
1543 "jpeg_markers=%d\n",
1544 p->quality, p->APPn, p->APP_len,
1545 p->COM_len, p->jpeg_markers);
1548 case VIDIOC_S_JPEGCOMP:
1550 struct v4l2_jpegcompression *p = arg;
1552 if (!ops->vidioc_g_jpegcomp)
1554 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1555 "COM_len=%d, jpeg_markers=%d\n",
1556 p->quality, p->APPn, p->APP_len,
1557 p->COM_len, p->jpeg_markers);
1558 ret = ops->vidioc_s_jpegcomp(file, fh, p);
1561 case VIDIOC_G_ENC_INDEX:
1563 struct v4l2_enc_idx *p = arg;
1565 if (!ops->vidioc_g_enc_index)
1567 ret = ops->vidioc_g_enc_index(file, fh, p);
1569 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1570 p->entries, p->entries_cap);
1573 case VIDIOC_ENCODER_CMD:
1575 struct v4l2_encoder_cmd *p = arg;
1577 if (!ops->vidioc_encoder_cmd)
1579 memset(&p->raw, 0, sizeof(p->raw));
1580 ret = ops->vidioc_encoder_cmd(file, fh, p);
1582 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1585 case VIDIOC_TRY_ENCODER_CMD:
1587 struct v4l2_encoder_cmd *p = arg;
1589 if (!ops->vidioc_try_encoder_cmd)
1591 memset(&p->raw, 0, sizeof(p->raw));
1592 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
1594 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1599 struct v4l2_streamparm *p = arg;
1600 __u32 type = p->type;
1602 memset(p, 0, sizeof(*p));
1605 if (ops->vidioc_g_parm) {
1606 ret = ops->vidioc_g_parm(file, fh, p);
1608 struct v4l2_standard s;
1610 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1613 v4l2_video_std_construct(&s, vfd->current_norm,
1614 v4l2_norm_to_name(vfd->current_norm));
1616 p->parm.capture.timeperframe = s.frameperiod;
1620 dbgarg(cmd, "type=%d\n", p->type);
1625 struct v4l2_streamparm *p = arg;
1627 if (!ops->vidioc_s_parm)
1629 dbgarg(cmd, "type=%d\n", p->type);
1630 ret = ops->vidioc_s_parm(file, fh, p);
1633 case VIDIOC_G_TUNER:
1635 struct v4l2_tuner *p = arg;
1636 __u32 index = p->index;
1638 if (!ops->vidioc_g_tuner)
1641 memset(p, 0, sizeof(*p));
1644 ret = ops->vidioc_g_tuner(file, fh, p);
1646 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1647 "capability=0x%x, rangelow=%d, "
1648 "rangehigh=%d, signal=%d, afc=%d, "
1649 "rxsubchans=0x%x, audmode=%d\n",
1650 p->index, p->name, p->type,
1651 p->capability, p->rangelow,
1652 p->rangehigh, p->signal, p->afc,
1653 p->rxsubchans, p->audmode);
1656 case VIDIOC_S_TUNER:
1658 struct v4l2_tuner *p = arg;
1660 if (!ops->vidioc_s_tuner)
1662 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1663 "capability=0x%x, rangelow=%d, "
1664 "rangehigh=%d, signal=%d, afc=%d, "
1665 "rxsubchans=0x%x, audmode=%d\n",
1666 p->index, p->name, p->type,
1667 p->capability, p->rangelow,
1668 p->rangehigh, p->signal, p->afc,
1669 p->rxsubchans, p->audmode);
1670 ret = ops->vidioc_s_tuner(file, fh, p);
1673 case VIDIOC_G_FREQUENCY:
1675 struct v4l2_frequency *p = arg;
1677 if (!ops->vidioc_g_frequency)
1680 memset(p->reserved, 0, sizeof(p->reserved));
1682 ret = ops->vidioc_g_frequency(file, fh, p);
1684 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1685 p->tuner, p->type, p->frequency);
1688 case VIDIOC_S_FREQUENCY:
1690 struct v4l2_frequency *p = arg;
1692 if (!ops->vidioc_s_frequency)
1694 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1695 p->tuner, p->type, p->frequency);
1696 ret = ops->vidioc_s_frequency(file, fh, p);
1699 case VIDIOC_G_SLICED_VBI_CAP:
1701 struct v4l2_sliced_vbi_cap *p = arg;
1702 __u32 type = p->type;
1704 if (!ops->vidioc_g_sliced_vbi_cap)
1706 memset(p, 0, sizeof(*p));
1708 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1709 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1711 dbgarg2("service_set=%d\n", p->service_set);
1714 case VIDIOC_LOG_STATUS:
1716 if (!ops->vidioc_log_status)
1718 ret = ops->vidioc_log_status(file, fh);
1721 #ifdef CONFIG_VIDEO_ADV_DEBUG
1722 case VIDIOC_DBG_G_REGISTER:
1724 struct v4l2_dbg_register *p = arg;
1726 if (!capable(CAP_SYS_ADMIN))
1728 else if (ops->vidioc_g_register)
1729 ret = ops->vidioc_g_register(file, fh, p);
1732 case VIDIOC_DBG_S_REGISTER:
1734 struct v4l2_dbg_register *p = arg;
1736 if (!capable(CAP_SYS_ADMIN))
1738 else if (ops->vidioc_s_register)
1739 ret = ops->vidioc_s_register(file, fh, p);
1743 case VIDIOC_DBG_G_CHIP_IDENT:
1745 struct v4l2_dbg_chip_ident *p = arg;
1747 if (!ops->vidioc_g_chip_ident)
1749 p->ident = V4L2_IDENT_NONE;
1751 ret = ops->vidioc_g_chip_ident(file, fh, p);
1753 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1756 case VIDIOC_G_CHIP_IDENT_OLD:
1757 printk(KERN_ERR "VIDIOC_G_CHIP_IDENT has been deprecated and will disappear in 2.6.30.\n");
1758 printk(KERN_ERR "It is a debugging ioctl and must not be used in applications!\n");
1761 case VIDIOC_S_HW_FREQ_SEEK:
1763 struct v4l2_hw_freq_seek *p = arg;
1765 if (!ops->vidioc_s_hw_freq_seek)
1768 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1769 p->tuner, p->type, p->seek_upward, p->wrap_around);
1770 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1773 case VIDIOC_ENUM_FRAMESIZES:
1775 struct v4l2_frmsizeenum *p = arg;
1777 if (!ops->vidioc_enum_framesizes)
1780 memset(p, 0, sizeof(*p));
1782 ret = ops->vidioc_enum_framesizes(file, fh, p);
1784 "index=%d, pixelformat=%d, type=%d ",
1785 p->index, p->pixel_format, p->type);
1787 case V4L2_FRMSIZE_TYPE_DISCRETE:
1788 dbgarg2("width = %d, height=%d\n",
1789 p->discrete.width, p->discrete.height);
1791 case V4L2_FRMSIZE_TYPE_STEPWISE:
1792 dbgarg2("min %dx%d, max %dx%d, step %dx%d\n",
1793 p->stepwise.min_width, p->stepwise.min_height,
1794 p->stepwise.step_width, p->stepwise.step_height,
1795 p->stepwise.max_width, p->stepwise.max_height);
1797 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1798 dbgarg2("continuous\n");
1801 dbgarg2("- Unknown type!\n");
1806 case VIDIOC_ENUM_FRAMEINTERVALS:
1808 struct v4l2_frmivalenum *p = arg;
1810 if (!ops->vidioc_enum_frameintervals)
1813 memset(p, 0, sizeof(*p));
1815 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1817 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1818 p->index, p->pixel_format,
1819 p->width, p->height, p->type);
1821 case V4L2_FRMIVAL_TYPE_DISCRETE:
1822 dbgarg2("fps=%d/%d\n",
1823 p->discrete.numerator,
1824 p->discrete.denominator);
1826 case V4L2_FRMIVAL_TYPE_STEPWISE:
1827 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1828 p->stepwise.min.numerator,
1829 p->stepwise.min.denominator,
1830 p->stepwise.max.numerator,
1831 p->stepwise.max.denominator,
1832 p->stepwise.step.numerator,
1833 p->stepwise.step.denominator);
1835 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1836 dbgarg2("continuous\n");
1839 dbgarg2("- Unknown type!\n");
1846 if (!ops->vidioc_default)
1848 ret = ops->vidioc_default(file, fh, cmd, arg);
1853 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1855 v4l_print_ioctl(vfd->name, cmd);
1856 printk(KERN_CONT " error %ld\n", ret);
1863 long video_ioctl2(struct file *file,
1864 unsigned int cmd, unsigned long arg)
1871 size_t ctrls_size = 0;
1872 void __user *user_ptr = NULL;
1874 #ifdef __OLD_VIDIOC_
1875 cmd = video_fix_command(cmd);
1877 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1878 cmd == VIDIOC_TRY_EXT_CTRLS);
1880 /* Copy arguments into temp kernel buffer */
1881 switch (_IOC_DIR(cmd)) {
1887 case (_IOC_WRITE | _IOC_READ):
1888 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1891 /* too big to allocate from stack */
1892 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
1899 if (_IOC_DIR(cmd) & _IOC_WRITE)
1900 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
1906 struct v4l2_ext_controls *p = parg;
1908 /* In case of an error, tell the caller that it wasn't
1909 a specific control that caused it. */
1910 p->error_idx = p->count;
1911 user_ptr = (void __user *)p->controls;
1913 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1914 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1915 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1920 if (copy_from_user(mbuf, user_ptr, ctrls_size))
1927 err = __video_do_ioctl(file, cmd, parg);
1928 if (err == -ENOIOCTLCMD)
1931 struct v4l2_ext_controls *p = parg;
1933 p->controls = (void *)user_ptr;
1934 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1942 /* Copy results into user buffer */
1943 switch (_IOC_DIR(cmd)) {
1945 case (_IOC_WRITE | _IOC_READ):
1946 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
1955 EXPORT_SYMBOL(video_ioctl2);