2 * Video capture interface for Linux version 2
4 * A generic framework to process V4L2 ioctl commands.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
12 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
19 #define __OLD_VIDIOC_ /* To allow fixing old calls */
20 #include <linux/videodev.h>
21 #include <linux/videodev2.h>
23 #ifdef CONFIG_VIDEO_V4L1
24 #include <linux/videodev.h>
26 #include <media/v4l2-common.h>
27 #include <media/v4l2-ioctl.h>
28 #include <media/v4l2-chip-ident.h>
30 #define dbgarg(cmd, fmt, arg...) \
32 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
33 printk(KERN_DEBUG "%s: ", vfd->name); \
34 v4l_printk_ioctl(cmd); \
35 printk(" " fmt, ## arg); \
39 #define dbgarg2(fmt, arg...) \
41 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
42 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
45 #define dbgarg3(fmt, arg...) \
47 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
48 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
51 /* Zero out the end of the struct pointed to by p. Everthing after, but
52 * not including, the specified field is cleared. */
53 #define CLEAR_AFTER_FIELD(p, field) \
54 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
55 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
62 static const struct std_descr standards
[] = {
63 { V4L2_STD_NTSC
, "NTSC" },
64 { V4L2_STD_NTSC_M
, "NTSC-M" },
65 { V4L2_STD_NTSC_M_JP
, "NTSC-M-JP" },
66 { V4L2_STD_NTSC_M_KR
, "NTSC-M-KR" },
67 { V4L2_STD_NTSC_443
, "NTSC-443" },
68 { V4L2_STD_PAL
, "PAL" },
69 { V4L2_STD_PAL_BG
, "PAL-BG" },
70 { V4L2_STD_PAL_B
, "PAL-B" },
71 { V4L2_STD_PAL_B1
, "PAL-B1" },
72 { V4L2_STD_PAL_G
, "PAL-G" },
73 { V4L2_STD_PAL_H
, "PAL-H" },
74 { V4L2_STD_PAL_I
, "PAL-I" },
75 { V4L2_STD_PAL_DK
, "PAL-DK" },
76 { V4L2_STD_PAL_D
, "PAL-D" },
77 { V4L2_STD_PAL_D1
, "PAL-D1" },
78 { V4L2_STD_PAL_K
, "PAL-K" },
79 { V4L2_STD_PAL_M
, "PAL-M" },
80 { V4L2_STD_PAL_N
, "PAL-N" },
81 { V4L2_STD_PAL_Nc
, "PAL-Nc" },
82 { V4L2_STD_PAL_60
, "PAL-60" },
83 { V4L2_STD_SECAM
, "SECAM" },
84 { V4L2_STD_SECAM_B
, "SECAM-B" },
85 { V4L2_STD_SECAM_G
, "SECAM-G" },
86 { V4L2_STD_SECAM_H
, "SECAM-H" },
87 { V4L2_STD_SECAM_DK
, "SECAM-DK" },
88 { V4L2_STD_SECAM_D
, "SECAM-D" },
89 { V4L2_STD_SECAM_K
, "SECAM-K" },
90 { V4L2_STD_SECAM_K1
, "SECAM-K1" },
91 { V4L2_STD_SECAM_L
, "SECAM-L" },
92 { V4L2_STD_SECAM_LC
, "SECAM-Lc" },
96 /* video4linux standard ID conversion to standard name
98 const char *v4l2_norm_to_name(v4l2_std_id id
)
103 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
104 64 bit comparations. So, on that architecture, with some gcc
105 variants, compilation fails. Currently, the max value is 30bit wide.
109 for (i
= 0; standards
[i
].std
; i
++)
110 if (myid
== standards
[i
].std
)
112 return standards
[i
].descr
;
114 EXPORT_SYMBOL(v4l2_norm_to_name
);
116 /* Returns frame period for the given standard */
117 void v4l2_video_std_frame_period(int id
, struct v4l2_fract
*frameperiod
)
119 if (id
& V4L2_STD_525_60
) {
120 frameperiod
->numerator
= 1001;
121 frameperiod
->denominator
= 30000;
123 frameperiod
->numerator
= 1;
124 frameperiod
->denominator
= 25;
127 EXPORT_SYMBOL(v4l2_video_std_frame_period
);
129 /* Fill in the fields of a v4l2_standard structure according to the
130 'id' and 'transmission' parameters. Returns negative on error. */
131 int v4l2_video_std_construct(struct v4l2_standard
*vs
,
132 int id
, const char *name
)
135 v4l2_video_std_frame_period(id
, &vs
->frameperiod
);
136 vs
->framelines
= (id
& V4L2_STD_525_60
) ? 525 : 625;
137 strlcpy(vs
->name
, name
, sizeof(vs
->name
));
140 EXPORT_SYMBOL(v4l2_video_std_construct
);
142 /* ----------------------------------------------------------------- */
143 /* some arrays for pretty-printing debug messages of enum types */
145 const char *v4l2_field_names
[] = {
146 [V4L2_FIELD_ANY
] = "any",
147 [V4L2_FIELD_NONE
] = "none",
148 [V4L2_FIELD_TOP
] = "top",
149 [V4L2_FIELD_BOTTOM
] = "bottom",
150 [V4L2_FIELD_INTERLACED
] = "interlaced",
151 [V4L2_FIELD_SEQ_TB
] = "seq-tb",
152 [V4L2_FIELD_SEQ_BT
] = "seq-bt",
153 [V4L2_FIELD_ALTERNATE
] = "alternate",
154 [V4L2_FIELD_INTERLACED_TB
] = "interlaced-tb",
155 [V4L2_FIELD_INTERLACED_BT
] = "interlaced-bt",
157 EXPORT_SYMBOL(v4l2_field_names
);
159 const char *v4l2_type_names
[] = {
160 [V4L2_BUF_TYPE_VIDEO_CAPTURE
] = "vid-cap",
161 [V4L2_BUF_TYPE_VIDEO_OVERLAY
] = "vid-overlay",
162 [V4L2_BUF_TYPE_VIDEO_OUTPUT
] = "vid-out",
163 [V4L2_BUF_TYPE_VBI_CAPTURE
] = "vbi-cap",
164 [V4L2_BUF_TYPE_VBI_OUTPUT
] = "vbi-out",
165 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
] = "sliced-vbi-cap",
166 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
] = "sliced-vbi-out",
167 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
] = "vid-out-overlay",
169 EXPORT_SYMBOL(v4l2_type_names
);
171 static const char *v4l2_memory_names
[] = {
172 [V4L2_MEMORY_MMAP
] = "mmap",
173 [V4L2_MEMORY_USERPTR
] = "userptr",
174 [V4L2_MEMORY_OVERLAY
] = "overlay",
177 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
180 /* ------------------------------------------------------------------ */
181 /* debug help functions */
183 #ifdef CONFIG_VIDEO_V4L1_COMPAT
184 static const char *v4l1_ioctls
[] = {
185 [_IOC_NR(VIDIOCGCAP
)] = "VIDIOCGCAP",
186 [_IOC_NR(VIDIOCGCHAN
)] = "VIDIOCGCHAN",
187 [_IOC_NR(VIDIOCSCHAN
)] = "VIDIOCSCHAN",
188 [_IOC_NR(VIDIOCGTUNER
)] = "VIDIOCGTUNER",
189 [_IOC_NR(VIDIOCSTUNER
)] = "VIDIOCSTUNER",
190 [_IOC_NR(VIDIOCGPICT
)] = "VIDIOCGPICT",
191 [_IOC_NR(VIDIOCSPICT
)] = "VIDIOCSPICT",
192 [_IOC_NR(VIDIOCCAPTURE
)] = "VIDIOCCAPTURE",
193 [_IOC_NR(VIDIOCGWIN
)] = "VIDIOCGWIN",
194 [_IOC_NR(VIDIOCSWIN
)] = "VIDIOCSWIN",
195 [_IOC_NR(VIDIOCGFBUF
)] = "VIDIOCGFBUF",
196 [_IOC_NR(VIDIOCSFBUF
)] = "VIDIOCSFBUF",
197 [_IOC_NR(VIDIOCKEY
)] = "VIDIOCKEY",
198 [_IOC_NR(VIDIOCGFREQ
)] = "VIDIOCGFREQ",
199 [_IOC_NR(VIDIOCSFREQ
)] = "VIDIOCSFREQ",
200 [_IOC_NR(VIDIOCGAUDIO
)] = "VIDIOCGAUDIO",
201 [_IOC_NR(VIDIOCSAUDIO
)] = "VIDIOCSAUDIO",
202 [_IOC_NR(VIDIOCSYNC
)] = "VIDIOCSYNC",
203 [_IOC_NR(VIDIOCMCAPTURE
)] = "VIDIOCMCAPTURE",
204 [_IOC_NR(VIDIOCGMBUF
)] = "VIDIOCGMBUF",
205 [_IOC_NR(VIDIOCGUNIT
)] = "VIDIOCGUNIT",
206 [_IOC_NR(VIDIOCGCAPTURE
)] = "VIDIOCGCAPTURE",
207 [_IOC_NR(VIDIOCSCAPTURE
)] = "VIDIOCSCAPTURE",
208 [_IOC_NR(VIDIOCSPLAYMODE
)] = "VIDIOCSPLAYMODE",
209 [_IOC_NR(VIDIOCSWRITEMODE
)] = "VIDIOCSWRITEMODE",
210 [_IOC_NR(VIDIOCGPLAYINFO
)] = "VIDIOCGPLAYINFO",
211 [_IOC_NR(VIDIOCSMICROCODE
)] = "VIDIOCSMICROCODE",
212 [_IOC_NR(VIDIOCGVBIFMT
)] = "VIDIOCGVBIFMT",
213 [_IOC_NR(VIDIOCSVBIFMT
)] = "VIDIOCSVBIFMT"
215 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
218 static const char *v4l2_ioctls
[] = {
219 [_IOC_NR(VIDIOC_QUERYCAP
)] = "VIDIOC_QUERYCAP",
220 [_IOC_NR(VIDIOC_RESERVED
)] = "VIDIOC_RESERVED",
221 [_IOC_NR(VIDIOC_ENUM_FMT
)] = "VIDIOC_ENUM_FMT",
222 [_IOC_NR(VIDIOC_G_FMT
)] = "VIDIOC_G_FMT",
223 [_IOC_NR(VIDIOC_S_FMT
)] = "VIDIOC_S_FMT",
224 [_IOC_NR(VIDIOC_REQBUFS
)] = "VIDIOC_REQBUFS",
225 [_IOC_NR(VIDIOC_QUERYBUF
)] = "VIDIOC_QUERYBUF",
226 [_IOC_NR(VIDIOC_G_FBUF
)] = "VIDIOC_G_FBUF",
227 [_IOC_NR(VIDIOC_S_FBUF
)] = "VIDIOC_S_FBUF",
228 [_IOC_NR(VIDIOC_OVERLAY
)] = "VIDIOC_OVERLAY",
229 [_IOC_NR(VIDIOC_QBUF
)] = "VIDIOC_QBUF",
230 [_IOC_NR(VIDIOC_DQBUF
)] = "VIDIOC_DQBUF",
231 [_IOC_NR(VIDIOC_STREAMON
)] = "VIDIOC_STREAMON",
232 [_IOC_NR(VIDIOC_STREAMOFF
)] = "VIDIOC_STREAMOFF",
233 [_IOC_NR(VIDIOC_G_PARM
)] = "VIDIOC_G_PARM",
234 [_IOC_NR(VIDIOC_S_PARM
)] = "VIDIOC_S_PARM",
235 [_IOC_NR(VIDIOC_G_STD
)] = "VIDIOC_G_STD",
236 [_IOC_NR(VIDIOC_S_STD
)] = "VIDIOC_S_STD",
237 [_IOC_NR(VIDIOC_ENUMSTD
)] = "VIDIOC_ENUMSTD",
238 [_IOC_NR(VIDIOC_ENUMINPUT
)] = "VIDIOC_ENUMINPUT",
239 [_IOC_NR(VIDIOC_G_CTRL
)] = "VIDIOC_G_CTRL",
240 [_IOC_NR(VIDIOC_S_CTRL
)] = "VIDIOC_S_CTRL",
241 [_IOC_NR(VIDIOC_G_TUNER
)] = "VIDIOC_G_TUNER",
242 [_IOC_NR(VIDIOC_S_TUNER
)] = "VIDIOC_S_TUNER",
243 [_IOC_NR(VIDIOC_G_AUDIO
)] = "VIDIOC_G_AUDIO",
244 [_IOC_NR(VIDIOC_S_AUDIO
)] = "VIDIOC_S_AUDIO",
245 [_IOC_NR(VIDIOC_QUERYCTRL
)] = "VIDIOC_QUERYCTRL",
246 [_IOC_NR(VIDIOC_QUERYMENU
)] = "VIDIOC_QUERYMENU",
247 [_IOC_NR(VIDIOC_G_INPUT
)] = "VIDIOC_G_INPUT",
248 [_IOC_NR(VIDIOC_S_INPUT
)] = "VIDIOC_S_INPUT",
249 [_IOC_NR(VIDIOC_G_OUTPUT
)] = "VIDIOC_G_OUTPUT",
250 [_IOC_NR(VIDIOC_S_OUTPUT
)] = "VIDIOC_S_OUTPUT",
251 [_IOC_NR(VIDIOC_ENUMOUTPUT
)] = "VIDIOC_ENUMOUTPUT",
252 [_IOC_NR(VIDIOC_G_AUDOUT
)] = "VIDIOC_G_AUDOUT",
253 [_IOC_NR(VIDIOC_S_AUDOUT
)] = "VIDIOC_S_AUDOUT",
254 [_IOC_NR(VIDIOC_G_MODULATOR
)] = "VIDIOC_G_MODULATOR",
255 [_IOC_NR(VIDIOC_S_MODULATOR
)] = "VIDIOC_S_MODULATOR",
256 [_IOC_NR(VIDIOC_G_FREQUENCY
)] = "VIDIOC_G_FREQUENCY",
257 [_IOC_NR(VIDIOC_S_FREQUENCY
)] = "VIDIOC_S_FREQUENCY",
258 [_IOC_NR(VIDIOC_CROPCAP
)] = "VIDIOC_CROPCAP",
259 [_IOC_NR(VIDIOC_G_CROP
)] = "VIDIOC_G_CROP",
260 [_IOC_NR(VIDIOC_S_CROP
)] = "VIDIOC_S_CROP",
261 [_IOC_NR(VIDIOC_G_JPEGCOMP
)] = "VIDIOC_G_JPEGCOMP",
262 [_IOC_NR(VIDIOC_S_JPEGCOMP
)] = "VIDIOC_S_JPEGCOMP",
263 [_IOC_NR(VIDIOC_QUERYSTD
)] = "VIDIOC_QUERYSTD",
264 [_IOC_NR(VIDIOC_TRY_FMT
)] = "VIDIOC_TRY_FMT",
265 [_IOC_NR(VIDIOC_ENUMAUDIO
)] = "VIDIOC_ENUMAUDIO",
266 [_IOC_NR(VIDIOC_ENUMAUDOUT
)] = "VIDIOC_ENUMAUDOUT",
267 [_IOC_NR(VIDIOC_G_PRIORITY
)] = "VIDIOC_G_PRIORITY",
268 [_IOC_NR(VIDIOC_S_PRIORITY
)] = "VIDIOC_S_PRIORITY",
269 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP
)] = "VIDIOC_G_SLICED_VBI_CAP",
270 [_IOC_NR(VIDIOC_LOG_STATUS
)] = "VIDIOC_LOG_STATUS",
271 [_IOC_NR(VIDIOC_G_EXT_CTRLS
)] = "VIDIOC_G_EXT_CTRLS",
272 [_IOC_NR(VIDIOC_S_EXT_CTRLS
)] = "VIDIOC_S_EXT_CTRLS",
273 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS
)] = "VIDIOC_TRY_EXT_CTRLS",
275 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES
)] = "VIDIOC_ENUM_FRAMESIZES",
276 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS
)] = "VIDIOC_ENUM_FRAMEINTERVALS",
277 [_IOC_NR(VIDIOC_G_ENC_INDEX
)] = "VIDIOC_G_ENC_INDEX",
278 [_IOC_NR(VIDIOC_ENCODER_CMD
)] = "VIDIOC_ENCODER_CMD",
279 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD
)] = "VIDIOC_TRY_ENCODER_CMD",
281 [_IOC_NR(VIDIOC_DBG_S_REGISTER
)] = "VIDIOC_DBG_S_REGISTER",
282 [_IOC_NR(VIDIOC_DBG_G_REGISTER
)] = "VIDIOC_DBG_G_REGISTER",
284 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT
)] = "VIDIOC_DBG_G_CHIP_IDENT",
285 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK
)] = "VIDIOC_S_HW_FREQ_SEEK",
287 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS
)] = "VIDIOC_ENUM_DV_PRESETS",
288 [_IOC_NR(VIDIOC_S_DV_PRESET
)] = "VIDIOC_S_DV_PRESET",
289 [_IOC_NR(VIDIOC_G_DV_PRESET
)] = "VIDIOC_G_DV_PRESET",
290 [_IOC_NR(VIDIOC_QUERY_DV_PRESET
)] = "VIDIOC_QUERY_DV_PRESET",
291 [_IOC_NR(VIDIOC_S_DV_TIMINGS
)] = "VIDIOC_S_DV_TIMINGS",
292 [_IOC_NR(VIDIOC_G_DV_TIMINGS
)] = "VIDIOC_G_DV_TIMINGS",
294 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
296 /* Common ioctl debug function. This function can be used by
297 external ioctl messages as well as internal V4L ioctl */
298 void v4l_printk_ioctl(unsigned int cmd
)
302 switch (_IOC_TYPE(cmd
)) {
306 #ifdef CONFIG_VIDEO_V4L1_COMPAT
308 if (_IOC_NR(cmd
) >= V4L1_IOCTLS
) {
312 printk("%s", v4l1_ioctls
[_IOC_NR(cmd
)]);
316 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
) {
320 printk("%s", v4l2_ioctls
[_IOC_NR(cmd
)]);
326 switch (_IOC_DIR(cmd
)) {
327 case _IOC_NONE
: dir
= "--"; break;
328 case _IOC_READ
: dir
= "r-"; break;
329 case _IOC_WRITE
: dir
= "-w"; break;
330 case _IOC_READ
| _IOC_WRITE
: dir
= "rw"; break;
331 default: dir
= "*ERR*"; break;
333 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
334 type
, _IOC_TYPE(cmd
), dir
, _IOC_NR(cmd
), cmd
);
336 EXPORT_SYMBOL(v4l_printk_ioctl
);
339 * helper function -- handles userspace copying for ioctl arguments
344 video_fix_command(unsigned int cmd
)
347 case VIDIOC_OVERLAY_OLD
:
348 cmd
= VIDIOC_OVERLAY
;
350 case VIDIOC_S_PARM_OLD
:
353 case VIDIOC_S_CTRL_OLD
:
356 case VIDIOC_G_AUDIO_OLD
:
357 cmd
= VIDIOC_G_AUDIO
;
359 case VIDIOC_G_AUDOUT_OLD
:
360 cmd
= VIDIOC_G_AUDOUT
;
362 case VIDIOC_CROPCAP_OLD
:
363 cmd
= VIDIOC_CROPCAP
;
371 * Obsolete usercopy function - Should be removed soon
374 video_usercopy(struct file
*file
, unsigned int cmd
, unsigned long arg
,
382 size_t ctrls_size
= 0;
383 void __user
*user_ptr
= NULL
;
386 cmd
= video_fix_command(cmd
);
388 is_ext_ctrl
= (cmd
== VIDIOC_S_EXT_CTRLS
|| cmd
== VIDIOC_G_EXT_CTRLS
||
389 cmd
== VIDIOC_TRY_EXT_CTRLS
);
391 /* Copy arguments into temp kernel buffer */
392 switch (_IOC_DIR(cmd
)) {
398 case (_IOC_WRITE
| _IOC_READ
):
399 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
402 /* too big to allocate from stack */
403 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
410 if (_IOC_DIR(cmd
) & _IOC_WRITE
)
411 if (copy_from_user(parg
, (void __user
*)arg
, _IOC_SIZE(cmd
)))
416 struct v4l2_ext_controls
*p
= parg
;
418 /* In case of an error, tell the caller that it wasn't
419 a specific control that caused it. */
420 p
->error_idx
= p
->count
;
421 user_ptr
= (void __user
*)p
->controls
;
423 ctrls_size
= sizeof(struct v4l2_ext_control
) * p
->count
;
424 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
425 mbuf
= kmalloc(ctrls_size
, GFP_KERNEL
);
430 if (copy_from_user(mbuf
, user_ptr
, ctrls_size
))
437 err
= func(file
, cmd
, parg
);
438 if (err
== -ENOIOCTLCMD
)
441 struct v4l2_ext_controls
*p
= parg
;
443 p
->controls
= (void *)user_ptr
;
444 if (p
->count
&& err
== 0 && copy_to_user(user_ptr
, mbuf
, ctrls_size
))
452 /* Copy results into user buffer */
453 switch (_IOC_DIR(cmd
)) {
455 case (_IOC_WRITE
| _IOC_READ
):
456 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
465 EXPORT_SYMBOL(video_usercopy
);
467 static void dbgbuf(unsigned int cmd
, struct video_device
*vfd
,
468 struct v4l2_buffer
*p
)
470 struct v4l2_timecode
*tc
= &p
->timecode
;
472 dbgarg(cmd
, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
473 "bytesused=%d, flags=0x%08d, "
474 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
475 p
->timestamp
.tv_sec
/ 3600,
476 (int)(p
->timestamp
.tv_sec
/ 60) % 60,
477 (int)(p
->timestamp
.tv_sec
% 60),
478 (long)p
->timestamp
.tv_usec
,
480 prt_names(p
->type
, v4l2_type_names
),
481 p
->bytesused
, p
->flags
,
482 p
->field
, p
->sequence
,
483 prt_names(p
->memory
, v4l2_memory_names
),
484 p
->m
.userptr
, p
->length
);
485 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
486 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
487 tc
->hours
, tc
->minutes
, tc
->seconds
,
488 tc
->type
, tc
->flags
, tc
->frames
, *(__u32
*)tc
->userbits
);
491 static inline void dbgrect(struct video_device
*vfd
, char *s
,
494 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s
, r
->left
, r
->top
,
495 r
->width
, r
->height
);
498 static inline void v4l_print_pix_fmt(struct video_device
*vfd
,
499 struct v4l2_pix_format
*fmt
)
501 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
502 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
503 fmt
->width
, fmt
->height
,
504 (fmt
->pixelformat
& 0xff),
505 (fmt
->pixelformat
>> 8) & 0xff,
506 (fmt
->pixelformat
>> 16) & 0xff,
507 (fmt
->pixelformat
>> 24) & 0xff,
508 prt_names(fmt
->field
, v4l2_field_names
),
509 fmt
->bytesperline
, fmt
->sizeimage
, fmt
->colorspace
);
512 static inline void v4l_print_ext_ctrls(unsigned int cmd
,
513 struct video_device
*vfd
, struct v4l2_ext_controls
*c
, int show_vals
)
517 if (!(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
))
520 printk(KERN_CONT
"class=0x%x", c
->ctrl_class
);
521 for (i
= 0; i
< c
->count
; i
++) {
522 if (show_vals
&& !c
->controls
[i
].size
)
523 printk(KERN_CONT
" id/val=0x%x/0x%x",
524 c
->controls
[i
].id
, c
->controls
[i
].value
);
526 printk(KERN_CONT
" id=0x%x,size=%u",
527 c
->controls
[i
].id
, c
->controls
[i
].size
);
529 printk(KERN_CONT
"\n");
532 static inline int check_ext_ctrls(struct v4l2_ext_controls
*c
, int allow_priv
)
536 /* zero the reserved fields */
537 c
->reserved
[0] = c
->reserved
[1] = 0;
538 for (i
= 0; i
< c
->count
; i
++)
539 c
->controls
[i
].reserved2
[0] = 0;
541 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
542 when using extended controls.
543 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
544 is it allowed for backwards compatibility.
546 if (!allow_priv
&& c
->ctrl_class
== V4L2_CID_PRIVATE_BASE
)
548 /* Check that all controls are from the same control class. */
549 for (i
= 0; i
< c
->count
; i
++) {
550 if (V4L2_CTRL_ID2CLASS(c
->controls
[i
].id
) != c
->ctrl_class
) {
558 static int check_fmt(const struct v4l2_ioctl_ops
*ops
, enum v4l2_buf_type type
)
564 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
565 if (ops
->vidioc_g_fmt_vid_cap
)
568 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
569 if (ops
->vidioc_g_fmt_vid_overlay
)
572 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
573 if (ops
->vidioc_g_fmt_vid_out
)
576 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
577 if (ops
->vidioc_g_fmt_vid_out_overlay
)
580 case V4L2_BUF_TYPE_VBI_CAPTURE
:
581 if (ops
->vidioc_g_fmt_vbi_cap
)
584 case V4L2_BUF_TYPE_VBI_OUTPUT
:
585 if (ops
->vidioc_g_fmt_vbi_out
)
588 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
589 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
592 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
593 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
596 case V4L2_BUF_TYPE_PRIVATE
:
597 if (ops
->vidioc_g_fmt_type_private
)
604 static long __video_do_ioctl(struct file
*file
,
605 unsigned int cmd
, void *arg
)
607 struct video_device
*vfd
= video_devdata(file
);
608 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
609 void *fh
= file
->private_data
;
612 if ((vfd
->debug
& V4L2_DEBUG_IOCTL
) &&
613 !(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
)) {
614 v4l_print_ioctl(vfd
->name
, cmd
);
615 printk(KERN_CONT
"\n");
619 printk(KERN_WARNING
"videodev: \"%s\" has no ioctl_ops.\n",
624 #ifdef CONFIG_VIDEO_V4L1_COMPAT
625 /***********************************************************
626 Handles calls to the obsoleted V4L1 API
627 Due to the nature of VIDIOCGMBUF, each driver that supports
628 V4L1 should implement its own handler for this ioctl.
629 ***********************************************************/
631 /* --- streaming capture ------------------------------------- */
632 if (cmd
== VIDIOCGMBUF
) {
633 struct video_mbuf
*p
= arg
;
635 if (!ops
->vidiocgmbuf
)
637 ret
= ops
->vidiocgmbuf(file
, fh
, p
);
639 dbgarg(cmd
, "size=%d, frames=%d, offsets=0x%08lx\n",
641 (unsigned long)p
->offsets
);
645 /********************************************************
646 All other V4L1 calls are handled by v4l1_compat module.
647 Those calls will be translated into V4L2 calls, and
648 __video_do_ioctl will be called again, with one or more
650 ********************************************************/
651 if (_IOC_TYPE(cmd
) == 'v' && _IOC_NR(cmd
) < BASE_VIDIOCPRIVATE
)
652 return v4l_compat_translate_ioctl(file
, cmd
, arg
,
657 /* --- capabilities ------------------------------------------ */
658 case VIDIOC_QUERYCAP
:
660 struct v4l2_capability
*cap
= (struct v4l2_capability
*)arg
;
662 if (!ops
->vidioc_querycap
)
665 ret
= ops
->vidioc_querycap(file
, fh
, cap
);
667 dbgarg(cmd
, "driver=%s, card=%s, bus=%s, "
669 "capabilities=0x%08x\n",
670 cap
->driver
, cap
->card
, cap
->bus_info
,
676 /* --- priority ------------------------------------------ */
677 case VIDIOC_G_PRIORITY
:
679 enum v4l2_priority
*p
= arg
;
681 if (!ops
->vidioc_g_priority
)
683 ret
= ops
->vidioc_g_priority(file
, fh
, p
);
685 dbgarg(cmd
, "priority is %d\n", *p
);
688 case VIDIOC_S_PRIORITY
:
690 enum v4l2_priority
*p
= arg
;
692 if (!ops
->vidioc_s_priority
)
694 dbgarg(cmd
, "setting priority to %d\n", *p
);
695 ret
= ops
->vidioc_s_priority(file
, fh
, *p
);
699 /* --- capture ioctls ---------------------------------------- */
700 case VIDIOC_ENUM_FMT
:
702 struct v4l2_fmtdesc
*f
= arg
;
705 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
706 if (ops
->vidioc_enum_fmt_vid_cap
)
707 ret
= ops
->vidioc_enum_fmt_vid_cap(file
, fh
, f
);
709 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
710 if (ops
->vidioc_enum_fmt_vid_overlay
)
711 ret
= ops
->vidioc_enum_fmt_vid_overlay(file
,
714 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
715 if (ops
->vidioc_enum_fmt_vid_out
)
716 ret
= ops
->vidioc_enum_fmt_vid_out(file
, fh
, f
);
718 case V4L2_BUF_TYPE_PRIVATE
:
719 if (ops
->vidioc_enum_fmt_type_private
)
720 ret
= ops
->vidioc_enum_fmt_type_private(file
,
727 dbgarg(cmd
, "index=%d, type=%d, flags=%d, "
728 "pixelformat=%c%c%c%c, description='%s'\n",
729 f
->index
, f
->type
, f
->flags
,
730 (f
->pixelformat
& 0xff),
731 (f
->pixelformat
>> 8) & 0xff,
732 (f
->pixelformat
>> 16) & 0xff,
733 (f
->pixelformat
>> 24) & 0xff,
739 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
741 /* FIXME: Should be one dump per type */
742 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
745 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
746 if (ops
->vidioc_g_fmt_vid_cap
)
747 ret
= ops
->vidioc_g_fmt_vid_cap(file
, fh
, f
);
749 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
751 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
752 if (ops
->vidioc_g_fmt_vid_overlay
)
753 ret
= ops
->vidioc_g_fmt_vid_overlay(file
,
756 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
757 if (ops
->vidioc_g_fmt_vid_out
)
758 ret
= ops
->vidioc_g_fmt_vid_out(file
, fh
, f
);
760 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
762 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
763 if (ops
->vidioc_g_fmt_vid_out_overlay
)
764 ret
= ops
->vidioc_g_fmt_vid_out_overlay(file
,
767 case V4L2_BUF_TYPE_VBI_CAPTURE
:
768 if (ops
->vidioc_g_fmt_vbi_cap
)
769 ret
= ops
->vidioc_g_fmt_vbi_cap(file
, fh
, f
);
771 case V4L2_BUF_TYPE_VBI_OUTPUT
:
772 if (ops
->vidioc_g_fmt_vbi_out
)
773 ret
= ops
->vidioc_g_fmt_vbi_out(file
, fh
, f
);
775 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
776 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
777 ret
= ops
->vidioc_g_fmt_sliced_vbi_cap(file
,
780 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
781 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
782 ret
= ops
->vidioc_g_fmt_sliced_vbi_out(file
,
785 case V4L2_BUF_TYPE_PRIVATE
:
786 if (ops
->vidioc_g_fmt_type_private
)
787 ret
= ops
->vidioc_g_fmt_type_private(file
,
796 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
798 /* FIXME: Should be one dump per type */
799 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
802 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
803 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
804 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
805 if (ops
->vidioc_s_fmt_vid_cap
)
806 ret
= ops
->vidioc_s_fmt_vid_cap(file
, fh
, f
);
808 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
809 CLEAR_AFTER_FIELD(f
, fmt
.win
);
810 if (ops
->vidioc_s_fmt_vid_overlay
)
811 ret
= ops
->vidioc_s_fmt_vid_overlay(file
,
814 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
815 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
816 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
817 if (ops
->vidioc_s_fmt_vid_out
)
818 ret
= ops
->vidioc_s_fmt_vid_out(file
, fh
, f
);
820 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
821 CLEAR_AFTER_FIELD(f
, fmt
.win
);
822 if (ops
->vidioc_s_fmt_vid_out_overlay
)
823 ret
= ops
->vidioc_s_fmt_vid_out_overlay(file
,
826 case V4L2_BUF_TYPE_VBI_CAPTURE
:
827 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
828 if (ops
->vidioc_s_fmt_vbi_cap
)
829 ret
= ops
->vidioc_s_fmt_vbi_cap(file
, fh
, f
);
831 case V4L2_BUF_TYPE_VBI_OUTPUT
:
832 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
833 if (ops
->vidioc_s_fmt_vbi_out
)
834 ret
= ops
->vidioc_s_fmt_vbi_out(file
, fh
, f
);
836 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
837 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
838 if (ops
->vidioc_s_fmt_sliced_vbi_cap
)
839 ret
= ops
->vidioc_s_fmt_sliced_vbi_cap(file
,
842 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
843 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
844 if (ops
->vidioc_s_fmt_sliced_vbi_out
)
845 ret
= ops
->vidioc_s_fmt_sliced_vbi_out(file
,
848 case V4L2_BUF_TYPE_PRIVATE
:
849 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
850 if (ops
->vidioc_s_fmt_type_private
)
851 ret
= ops
->vidioc_s_fmt_type_private(file
,
859 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
861 /* FIXME: Should be one dump per type */
862 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
,
865 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
866 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
867 if (ops
->vidioc_try_fmt_vid_cap
)
868 ret
= ops
->vidioc_try_fmt_vid_cap(file
, fh
, f
);
870 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
872 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
873 CLEAR_AFTER_FIELD(f
, fmt
.win
);
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 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
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 CLEAR_AFTER_FIELD(f
, fmt
.win
);
887 if (ops
->vidioc_try_fmt_vid_out_overlay
)
888 ret
= ops
->vidioc_try_fmt_vid_out_overlay(file
,
891 case V4L2_BUF_TYPE_VBI_CAPTURE
:
892 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
893 if (ops
->vidioc_try_fmt_vbi_cap
)
894 ret
= ops
->vidioc_try_fmt_vbi_cap(file
, fh
, f
);
896 case V4L2_BUF_TYPE_VBI_OUTPUT
:
897 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
898 if (ops
->vidioc_try_fmt_vbi_out
)
899 ret
= ops
->vidioc_try_fmt_vbi_out(file
, fh
, f
);
901 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
902 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
903 if (ops
->vidioc_try_fmt_sliced_vbi_cap
)
904 ret
= ops
->vidioc_try_fmt_sliced_vbi_cap(file
,
907 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
908 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
909 if (ops
->vidioc_try_fmt_sliced_vbi_out
)
910 ret
= ops
->vidioc_try_fmt_sliced_vbi_out(file
,
913 case V4L2_BUF_TYPE_PRIVATE
:
914 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
915 if (ops
->vidioc_try_fmt_type_private
)
916 ret
= ops
->vidioc_try_fmt_type_private(file
,
923 /* FIXME: Those buf reqs could be handled here,
924 with some changes on videobuf to allow its header to be included at
925 videodev2.h or being merged at videodev2.
929 struct v4l2_requestbuffers
*p
= arg
;
931 if (!ops
->vidioc_reqbufs
)
933 ret
= check_fmt(ops
, p
->type
);
937 if (p
->type
< V4L2_BUF_TYPE_PRIVATE
)
938 CLEAR_AFTER_FIELD(p
, memory
);
940 ret
= ops
->vidioc_reqbufs(file
, fh
, p
);
941 dbgarg(cmd
, "count=%d, type=%s, memory=%s\n",
943 prt_names(p
->type
, v4l2_type_names
),
944 prt_names(p
->memory
, v4l2_memory_names
));
947 case VIDIOC_QUERYBUF
:
949 struct v4l2_buffer
*p
= arg
;
951 if (!ops
->vidioc_querybuf
)
953 ret
= check_fmt(ops
, p
->type
);
957 ret
= ops
->vidioc_querybuf(file
, fh
, p
);
964 struct v4l2_buffer
*p
= arg
;
966 if (!ops
->vidioc_qbuf
)
968 ret
= check_fmt(ops
, p
->type
);
972 ret
= ops
->vidioc_qbuf(file
, fh
, p
);
979 struct v4l2_buffer
*p
= arg
;
981 if (!ops
->vidioc_dqbuf
)
983 ret
= check_fmt(ops
, p
->type
);
987 ret
= ops
->vidioc_dqbuf(file
, fh
, p
);
996 if (!ops
->vidioc_overlay
)
998 dbgarg(cmd
, "value=%d\n", *i
);
999 ret
= ops
->vidioc_overlay(file
, fh
, *i
);
1004 struct v4l2_framebuffer
*p
= arg
;
1006 if (!ops
->vidioc_g_fbuf
)
1008 ret
= ops
->vidioc_g_fbuf(file
, fh
, arg
);
1010 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
1011 p
->capability
, p
->flags
,
1012 (unsigned long)p
->base
);
1013 v4l_print_pix_fmt(vfd
, &p
->fmt
);
1019 struct v4l2_framebuffer
*p
= arg
;
1021 if (!ops
->vidioc_s_fbuf
)
1023 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
1024 p
->capability
, p
->flags
, (unsigned long)p
->base
);
1025 v4l_print_pix_fmt(vfd
, &p
->fmt
);
1026 ret
= ops
->vidioc_s_fbuf(file
, fh
, arg
);
1029 case VIDIOC_STREAMON
:
1031 enum v4l2_buf_type i
= *(int *)arg
;
1033 if (!ops
->vidioc_streamon
)
1035 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1036 ret
= ops
->vidioc_streamon(file
, fh
, i
);
1039 case VIDIOC_STREAMOFF
:
1041 enum v4l2_buf_type i
= *(int *)arg
;
1043 if (!ops
->vidioc_streamoff
)
1045 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1046 ret
= ops
->vidioc_streamoff(file
, fh
, i
);
1049 /* ---------- tv norms ---------- */
1050 case VIDIOC_ENUMSTD
:
1052 struct v4l2_standard
*p
= arg
;
1053 v4l2_std_id id
= vfd
->tvnorms
, curr_id
= 0;
1054 unsigned int index
= p
->index
, i
, j
= 0;
1055 const char *descr
= "";
1057 /* Return norm array in a canonical way */
1058 for (i
= 0; i
<= index
&& id
; i
++) {
1059 /* last std value in the standards array is 0, so this
1060 while always ends there since (id & 0) == 0. */
1061 while ((id
& standards
[j
].std
) != standards
[j
].std
)
1063 curr_id
= standards
[j
].std
;
1064 descr
= standards
[j
].descr
;
1068 if (curr_id
!= V4L2_STD_PAL
&&
1069 curr_id
!= V4L2_STD_SECAM
&&
1070 curr_id
!= V4L2_STD_NTSC
)
1076 v4l2_video_std_construct(p
, curr_id
, descr
);
1078 dbgarg(cmd
, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1079 "framelines=%d\n", p
->index
,
1080 (unsigned long long)p
->id
, p
->name
,
1081 p
->frameperiod
.numerator
,
1082 p
->frameperiod
.denominator
,
1090 v4l2_std_id
*id
= arg
;
1093 /* Calls the specific handler */
1094 if (ops
->vidioc_g_std
)
1095 ret
= ops
->vidioc_g_std(file
, fh
, id
);
1096 else if (vfd
->current_norm
)
1097 *id
= vfd
->current_norm
;
1102 dbgarg(cmd
, "std=0x%08Lx\n", (long long unsigned)*id
);
1107 v4l2_std_id
*id
= arg
, norm
;
1109 dbgarg(cmd
, "std=%08Lx\n", (long long unsigned)*id
);
1111 norm
= (*id
) & vfd
->tvnorms
;
1112 if (vfd
->tvnorms
&& !norm
) /* Check if std is supported */
1115 /* Calls the specific handler */
1116 if (ops
->vidioc_s_std
)
1117 ret
= ops
->vidioc_s_std(file
, fh
, &norm
);
1121 /* Updates standard information */
1123 vfd
->current_norm
= norm
;
1126 case VIDIOC_QUERYSTD
:
1128 v4l2_std_id
*p
= arg
;
1130 if (!ops
->vidioc_querystd
)
1132 ret
= ops
->vidioc_querystd(file
, fh
, arg
);
1134 dbgarg(cmd
, "detected std=%08Lx\n",
1135 (unsigned long long)*p
);
1138 /* ------ input switching ---------- */
1139 /* FIXME: Inputs can be handled inside videodev2 */
1140 case VIDIOC_ENUMINPUT
:
1142 struct v4l2_input
*p
= arg
;
1145 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1146 * CAP_STD here based on ioctl handler provided by the
1147 * driver. If the driver doesn't support these
1148 * for a specific input, it must override these flags.
1150 if (ops
->vidioc_s_std
)
1151 p
->capabilities
|= V4L2_IN_CAP_STD
;
1152 if (ops
->vidioc_s_dv_preset
)
1153 p
->capabilities
|= V4L2_IN_CAP_PRESETS
;
1154 if (ops
->vidioc_s_dv_timings
)
1155 p
->capabilities
|= V4L2_IN_CAP_CUSTOM_TIMINGS
;
1157 if (!ops
->vidioc_enum_input
)
1160 ret
= ops
->vidioc_enum_input(file
, fh
, p
);
1162 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1164 "tuner=%d, std=%08Lx, status=%d\n",
1165 p
->index
, p
->name
, p
->type
, p
->audioset
,
1167 (unsigned long long)p
->std
,
1171 case VIDIOC_G_INPUT
:
1173 unsigned int *i
= arg
;
1175 if (!ops
->vidioc_g_input
)
1177 ret
= ops
->vidioc_g_input(file
, fh
, i
);
1179 dbgarg(cmd
, "value=%d\n", *i
);
1182 case VIDIOC_S_INPUT
:
1184 unsigned int *i
= arg
;
1186 if (!ops
->vidioc_s_input
)
1188 dbgarg(cmd
, "value=%d\n", *i
);
1189 ret
= ops
->vidioc_s_input(file
, fh
, *i
);
1193 /* ------ output switching ---------- */
1194 case VIDIOC_ENUMOUTPUT
:
1196 struct v4l2_output
*p
= arg
;
1198 if (!ops
->vidioc_enum_output
)
1202 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1203 * CAP_STD here based on ioctl handler provided by the
1204 * driver. If the driver doesn't support these
1205 * for a specific output, it must override these flags.
1207 if (ops
->vidioc_s_std
)
1208 p
->capabilities
|= V4L2_OUT_CAP_STD
;
1209 if (ops
->vidioc_s_dv_preset
)
1210 p
->capabilities
|= V4L2_OUT_CAP_PRESETS
;
1211 if (ops
->vidioc_s_dv_timings
)
1212 p
->capabilities
|= V4L2_OUT_CAP_CUSTOM_TIMINGS
;
1214 ret
= ops
->vidioc_enum_output(file
, fh
, p
);
1216 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1218 "modulator=%d, std=0x%08Lx\n",
1219 p
->index
, p
->name
, p
->type
, p
->audioset
,
1220 p
->modulator
, (unsigned long long)p
->std
);
1223 case VIDIOC_G_OUTPUT
:
1225 unsigned int *i
= arg
;
1227 if (!ops
->vidioc_g_output
)
1229 ret
= ops
->vidioc_g_output(file
, fh
, i
);
1231 dbgarg(cmd
, "value=%d\n", *i
);
1234 case VIDIOC_S_OUTPUT
:
1236 unsigned int *i
= arg
;
1238 if (!ops
->vidioc_s_output
)
1240 dbgarg(cmd
, "value=%d\n", *i
);
1241 ret
= ops
->vidioc_s_output(file
, fh
, *i
);
1245 /* --- controls ---------------------------------------------- */
1246 case VIDIOC_QUERYCTRL
:
1248 struct v4l2_queryctrl
*p
= arg
;
1250 if (!ops
->vidioc_queryctrl
)
1252 ret
= ops
->vidioc_queryctrl(file
, fh
, p
);
1254 dbgarg(cmd
, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1255 "step=%d, default=%d, flags=0x%08x\n",
1256 p
->id
, p
->type
, p
->name
,
1257 p
->minimum
, p
->maximum
,
1258 p
->step
, p
->default_value
, p
->flags
);
1260 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1265 struct v4l2_control
*p
= arg
;
1267 if (ops
->vidioc_g_ctrl
)
1268 ret
= ops
->vidioc_g_ctrl(file
, fh
, p
);
1269 else if (ops
->vidioc_g_ext_ctrls
) {
1270 struct v4l2_ext_controls ctrls
;
1271 struct v4l2_ext_control ctrl
;
1273 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1275 ctrls
.controls
= &ctrl
;
1277 ctrl
.value
= p
->value
;
1278 if (check_ext_ctrls(&ctrls
, 1)) {
1279 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, &ctrls
);
1281 p
->value
= ctrl
.value
;
1286 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1288 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1293 struct v4l2_control
*p
= arg
;
1294 struct v4l2_ext_controls ctrls
;
1295 struct v4l2_ext_control ctrl
;
1297 if (!ops
->vidioc_s_ctrl
&& !ops
->vidioc_s_ext_ctrls
)
1300 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1302 if (ops
->vidioc_s_ctrl
) {
1303 ret
= ops
->vidioc_s_ctrl(file
, fh
, p
);
1306 if (!ops
->vidioc_s_ext_ctrls
)
1309 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1311 ctrls
.controls
= &ctrl
;
1313 ctrl
.value
= p
->value
;
1314 if (check_ext_ctrls(&ctrls
, 1))
1315 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, &ctrls
);
1318 case VIDIOC_G_EXT_CTRLS
:
1320 struct v4l2_ext_controls
*p
= arg
;
1322 p
->error_idx
= p
->count
;
1323 if (!ops
->vidioc_g_ext_ctrls
)
1325 if (check_ext_ctrls(p
, 0))
1326 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, p
);
1327 v4l_print_ext_ctrls(cmd
, vfd
, p
, !ret
);
1330 case VIDIOC_S_EXT_CTRLS
:
1332 struct v4l2_ext_controls
*p
= arg
;
1334 p
->error_idx
= p
->count
;
1335 if (!ops
->vidioc_s_ext_ctrls
)
1337 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1338 if (check_ext_ctrls(p
, 0))
1339 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, p
);
1342 case VIDIOC_TRY_EXT_CTRLS
:
1344 struct v4l2_ext_controls
*p
= arg
;
1346 p
->error_idx
= p
->count
;
1347 if (!ops
->vidioc_try_ext_ctrls
)
1349 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1350 if (check_ext_ctrls(p
, 0))
1351 ret
= ops
->vidioc_try_ext_ctrls(file
, fh
, p
);
1354 case VIDIOC_QUERYMENU
:
1356 struct v4l2_querymenu
*p
= arg
;
1358 if (!ops
->vidioc_querymenu
)
1360 ret
= ops
->vidioc_querymenu(file
, fh
, p
);
1362 dbgarg(cmd
, "id=0x%x, index=%d, name=%s\n",
1363 p
->id
, p
->index
, p
->name
);
1365 dbgarg(cmd
, "id=0x%x, index=%d\n",
1369 /* --- audio ---------------------------------------------- */
1370 case VIDIOC_ENUMAUDIO
:
1372 struct v4l2_audio
*p
= arg
;
1374 if (!ops
->vidioc_enumaudio
)
1376 ret
= ops
->vidioc_enumaudio(file
, fh
, p
);
1378 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1379 "mode=0x%x\n", p
->index
, p
->name
,
1380 p
->capability
, p
->mode
);
1382 dbgarg(cmd
, "index=%d\n", p
->index
);
1385 case VIDIOC_G_AUDIO
:
1387 struct v4l2_audio
*p
= arg
;
1389 if (!ops
->vidioc_g_audio
)
1392 ret
= ops
->vidioc_g_audio(file
, fh
, p
);
1394 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1395 "mode=0x%x\n", p
->index
,
1396 p
->name
, p
->capability
, p
->mode
);
1398 dbgarg(cmd
, "index=%d\n", p
->index
);
1401 case VIDIOC_S_AUDIO
:
1403 struct v4l2_audio
*p
= arg
;
1405 if (!ops
->vidioc_s_audio
)
1407 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1408 "mode=0x%x\n", p
->index
, p
->name
,
1409 p
->capability
, p
->mode
);
1410 ret
= ops
->vidioc_s_audio(file
, fh
, p
);
1413 case VIDIOC_ENUMAUDOUT
:
1415 struct v4l2_audioout
*p
= arg
;
1417 if (!ops
->vidioc_enumaudout
)
1419 dbgarg(cmd
, "Enum for index=%d\n", p
->index
);
1420 ret
= ops
->vidioc_enumaudout(file
, fh
, p
);
1422 dbgarg2("index=%d, name=%s, capability=%d, "
1423 "mode=%d\n", p
->index
, p
->name
,
1424 p
->capability
, p
->mode
);
1427 case VIDIOC_G_AUDOUT
:
1429 struct v4l2_audioout
*p
= arg
;
1431 if (!ops
->vidioc_g_audout
)
1434 ret
= ops
->vidioc_g_audout(file
, fh
, p
);
1436 dbgarg2("index=%d, name=%s, capability=%d, "
1437 "mode=%d\n", p
->index
, p
->name
,
1438 p
->capability
, p
->mode
);
1441 case VIDIOC_S_AUDOUT
:
1443 struct v4l2_audioout
*p
= arg
;
1445 if (!ops
->vidioc_s_audout
)
1447 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1448 "mode=%d\n", p
->index
, p
->name
,
1449 p
->capability
, p
->mode
);
1451 ret
= ops
->vidioc_s_audout(file
, fh
, p
);
1454 case VIDIOC_G_MODULATOR
:
1456 struct v4l2_modulator
*p
= arg
;
1458 if (!ops
->vidioc_g_modulator
)
1460 ret
= ops
->vidioc_g_modulator(file
, fh
, p
);
1462 dbgarg(cmd
, "index=%d, name=%s, "
1463 "capability=%d, rangelow=%d,"
1464 " rangehigh=%d, txsubchans=%d\n",
1465 p
->index
, p
->name
, p
->capability
,
1466 p
->rangelow
, p
->rangehigh
,
1470 case VIDIOC_S_MODULATOR
:
1472 struct v4l2_modulator
*p
= arg
;
1474 if (!ops
->vidioc_s_modulator
)
1476 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1477 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1478 p
->index
, p
->name
, p
->capability
, p
->rangelow
,
1479 p
->rangehigh
, p
->txsubchans
);
1480 ret
= ops
->vidioc_s_modulator(file
, fh
, p
);
1485 struct v4l2_crop
*p
= arg
;
1487 if (!ops
->vidioc_g_crop
)
1490 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1491 ret
= ops
->vidioc_g_crop(file
, fh
, p
);
1493 dbgrect(vfd
, "", &p
->c
);
1498 struct v4l2_crop
*p
= arg
;
1500 if (!ops
->vidioc_s_crop
)
1502 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1503 dbgrect(vfd
, "", &p
->c
);
1504 ret
= ops
->vidioc_s_crop(file
, fh
, p
);
1507 case VIDIOC_CROPCAP
:
1509 struct v4l2_cropcap
*p
= arg
;
1511 /*FIXME: Should also show v4l2_fract pixelaspect */
1512 if (!ops
->vidioc_cropcap
)
1515 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1516 ret
= ops
->vidioc_cropcap(file
, fh
, p
);
1518 dbgrect(vfd
, "bounds ", &p
->bounds
);
1519 dbgrect(vfd
, "defrect ", &p
->defrect
);
1523 case VIDIOC_G_JPEGCOMP
:
1525 struct v4l2_jpegcompression
*p
= arg
;
1527 if (!ops
->vidioc_g_jpegcomp
)
1530 ret
= ops
->vidioc_g_jpegcomp(file
, fh
, p
);
1532 dbgarg(cmd
, "quality=%d, APPn=%d, "
1533 "APP_len=%d, COM_len=%d, "
1534 "jpeg_markers=%d\n",
1535 p
->quality
, p
->APPn
, p
->APP_len
,
1536 p
->COM_len
, p
->jpeg_markers
);
1539 case VIDIOC_S_JPEGCOMP
:
1541 struct v4l2_jpegcompression
*p
= arg
;
1543 if (!ops
->vidioc_g_jpegcomp
)
1545 dbgarg(cmd
, "quality=%d, APPn=%d, APP_len=%d, "
1546 "COM_len=%d, jpeg_markers=%d\n",
1547 p
->quality
, p
->APPn
, p
->APP_len
,
1548 p
->COM_len
, p
->jpeg_markers
);
1549 ret
= ops
->vidioc_s_jpegcomp(file
, fh
, p
);
1552 case VIDIOC_G_ENC_INDEX
:
1554 struct v4l2_enc_idx
*p
= arg
;
1556 if (!ops
->vidioc_g_enc_index
)
1558 ret
= ops
->vidioc_g_enc_index(file
, fh
, p
);
1560 dbgarg(cmd
, "entries=%d, entries_cap=%d\n",
1561 p
->entries
, p
->entries_cap
);
1564 case VIDIOC_ENCODER_CMD
:
1566 struct v4l2_encoder_cmd
*p
= arg
;
1568 if (!ops
->vidioc_encoder_cmd
)
1570 ret
= ops
->vidioc_encoder_cmd(file
, fh
, p
);
1572 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1575 case VIDIOC_TRY_ENCODER_CMD
:
1577 struct v4l2_encoder_cmd
*p
= arg
;
1579 if (!ops
->vidioc_try_encoder_cmd
)
1581 ret
= ops
->vidioc_try_encoder_cmd(file
, fh
, p
);
1583 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1588 struct v4l2_streamparm
*p
= arg
;
1590 if (ops
->vidioc_g_parm
) {
1591 ret
= check_fmt(ops
, p
->type
);
1594 ret
= ops
->vidioc_g_parm(file
, fh
, p
);
1596 v4l2_std_id std
= vfd
->current_norm
;
1598 if (p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1602 if (ops
->vidioc_g_std
)
1603 ret
= ops
->vidioc_g_std(file
, fh
, &std
);
1607 v4l2_video_std_frame_period(std
,
1608 &p
->parm
.capture
.timeperframe
);
1611 dbgarg(cmd
, "type=%d\n", p
->type
);
1616 struct v4l2_streamparm
*p
= arg
;
1618 if (!ops
->vidioc_s_parm
)
1620 ret
= check_fmt(ops
, p
->type
);
1624 dbgarg(cmd
, "type=%d\n", p
->type
);
1625 ret
= ops
->vidioc_s_parm(file
, fh
, p
);
1628 case VIDIOC_G_TUNER
:
1630 struct v4l2_tuner
*p
= arg
;
1632 if (!ops
->vidioc_g_tuner
)
1635 ret
= ops
->vidioc_g_tuner(file
, fh
, p
);
1637 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1638 "capability=0x%x, rangelow=%d, "
1639 "rangehigh=%d, signal=%d, afc=%d, "
1640 "rxsubchans=0x%x, audmode=%d\n",
1641 p
->index
, p
->name
, p
->type
,
1642 p
->capability
, p
->rangelow
,
1643 p
->rangehigh
, p
->signal
, p
->afc
,
1644 p
->rxsubchans
, p
->audmode
);
1647 case VIDIOC_S_TUNER
:
1649 struct v4l2_tuner
*p
= arg
;
1651 if (!ops
->vidioc_s_tuner
)
1653 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1654 "capability=0x%x, rangelow=%d, "
1655 "rangehigh=%d, signal=%d, afc=%d, "
1656 "rxsubchans=0x%x, audmode=%d\n",
1657 p
->index
, p
->name
, p
->type
,
1658 p
->capability
, p
->rangelow
,
1659 p
->rangehigh
, p
->signal
, p
->afc
,
1660 p
->rxsubchans
, p
->audmode
);
1661 ret
= ops
->vidioc_s_tuner(file
, fh
, p
);
1664 case VIDIOC_G_FREQUENCY
:
1666 struct v4l2_frequency
*p
= arg
;
1668 if (!ops
->vidioc_g_frequency
)
1671 ret
= ops
->vidioc_g_frequency(file
, fh
, p
);
1673 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1674 p
->tuner
, p
->type
, p
->frequency
);
1677 case VIDIOC_S_FREQUENCY
:
1679 struct v4l2_frequency
*p
= arg
;
1681 if (!ops
->vidioc_s_frequency
)
1683 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1684 p
->tuner
, p
->type
, p
->frequency
);
1685 ret
= ops
->vidioc_s_frequency(file
, fh
, p
);
1688 case VIDIOC_G_SLICED_VBI_CAP
:
1690 struct v4l2_sliced_vbi_cap
*p
= arg
;
1692 if (!ops
->vidioc_g_sliced_vbi_cap
)
1695 /* Clear up to type, everything after type is zerod already */
1696 memset(p
, 0, offsetof(struct v4l2_sliced_vbi_cap
, type
));
1698 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1699 ret
= ops
->vidioc_g_sliced_vbi_cap(file
, fh
, p
);
1701 dbgarg2("service_set=%d\n", p
->service_set
);
1704 case VIDIOC_LOG_STATUS
:
1706 if (!ops
->vidioc_log_status
)
1708 ret
= ops
->vidioc_log_status(file
, fh
);
1711 #ifdef CONFIG_VIDEO_ADV_DEBUG
1712 case VIDIOC_DBG_G_REGISTER
:
1714 struct v4l2_dbg_register
*p
= arg
;
1716 if (!capable(CAP_SYS_ADMIN
))
1718 else if (ops
->vidioc_g_register
)
1719 ret
= ops
->vidioc_g_register(file
, fh
, p
);
1722 case VIDIOC_DBG_S_REGISTER
:
1724 struct v4l2_dbg_register
*p
= arg
;
1726 if (!capable(CAP_SYS_ADMIN
))
1728 else if (ops
->vidioc_s_register
)
1729 ret
= ops
->vidioc_s_register(file
, fh
, p
);
1733 case VIDIOC_DBG_G_CHIP_IDENT
:
1735 struct v4l2_dbg_chip_ident
*p
= arg
;
1737 if (!ops
->vidioc_g_chip_ident
)
1739 p
->ident
= V4L2_IDENT_NONE
;
1741 ret
= ops
->vidioc_g_chip_ident(file
, fh
, p
);
1743 dbgarg(cmd
, "chip_ident=%u, revision=0x%x\n", p
->ident
, p
->revision
);
1746 case VIDIOC_S_HW_FREQ_SEEK
:
1748 struct v4l2_hw_freq_seek
*p
= arg
;
1750 if (!ops
->vidioc_s_hw_freq_seek
)
1753 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1754 p
->tuner
, p
->type
, p
->seek_upward
, p
->wrap_around
);
1755 ret
= ops
->vidioc_s_hw_freq_seek(file
, fh
, p
);
1758 case VIDIOC_ENUM_FRAMESIZES
:
1760 struct v4l2_frmsizeenum
*p
= arg
;
1762 if (!ops
->vidioc_enum_framesizes
)
1765 ret
= ops
->vidioc_enum_framesizes(file
, fh
, p
);
1767 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1769 (p
->pixel_format
& 0xff),
1770 (p
->pixel_format
>> 8) & 0xff,
1771 (p
->pixel_format
>> 16) & 0xff,
1772 (p
->pixel_format
>> 24) & 0xff,
1775 case V4L2_FRMSIZE_TYPE_DISCRETE
:
1776 dbgarg3("width = %d, height=%d\n",
1777 p
->discrete
.width
, p
->discrete
.height
);
1779 case V4L2_FRMSIZE_TYPE_STEPWISE
:
1780 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1781 p
->stepwise
.min_width
, p
->stepwise
.min_height
,
1782 p
->stepwise
.step_width
, p
->stepwise
.step_height
,
1783 p
->stepwise
.max_width
, p
->stepwise
.max_height
);
1785 case V4L2_FRMSIZE_TYPE_CONTINUOUS
:
1786 dbgarg3("continuous\n");
1789 dbgarg3("- Unknown type!\n");
1794 case VIDIOC_ENUM_FRAMEINTERVALS
:
1796 struct v4l2_frmivalenum
*p
= arg
;
1798 if (!ops
->vidioc_enum_frameintervals
)
1801 ret
= ops
->vidioc_enum_frameintervals(file
, fh
, p
);
1803 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1804 p
->index
, p
->pixel_format
,
1805 p
->width
, p
->height
, p
->type
);
1807 case V4L2_FRMIVAL_TYPE_DISCRETE
:
1808 dbgarg2("fps=%d/%d\n",
1809 p
->discrete
.numerator
,
1810 p
->discrete
.denominator
);
1812 case V4L2_FRMIVAL_TYPE_STEPWISE
:
1813 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1814 p
->stepwise
.min
.numerator
,
1815 p
->stepwise
.min
.denominator
,
1816 p
->stepwise
.max
.numerator
,
1817 p
->stepwise
.max
.denominator
,
1818 p
->stepwise
.step
.numerator
,
1819 p
->stepwise
.step
.denominator
);
1821 case V4L2_FRMIVAL_TYPE_CONTINUOUS
:
1822 dbgarg2("continuous\n");
1825 dbgarg2("- Unknown type!\n");
1829 case VIDIOC_ENUM_DV_PRESETS
:
1831 struct v4l2_dv_enum_preset
*p
= arg
;
1833 if (!ops
->vidioc_enum_dv_presets
)
1836 ret
= ops
->vidioc_enum_dv_presets(file
, fh
, p
);
1839 "index=%d, preset=%d, name=%s, width=%d,"
1841 p
->index
, p
->preset
, p
->name
, p
->width
,
1845 case VIDIOC_S_DV_PRESET
:
1847 struct v4l2_dv_preset
*p
= arg
;
1849 if (!ops
->vidioc_s_dv_preset
)
1852 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1853 ret
= ops
->vidioc_s_dv_preset(file
, fh
, p
);
1856 case VIDIOC_G_DV_PRESET
:
1858 struct v4l2_dv_preset
*p
= arg
;
1860 if (!ops
->vidioc_g_dv_preset
)
1863 ret
= ops
->vidioc_g_dv_preset(file
, fh
, p
);
1865 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1868 case VIDIOC_QUERY_DV_PRESET
:
1870 struct v4l2_dv_preset
*p
= arg
;
1872 if (!ops
->vidioc_query_dv_preset
)
1875 ret
= ops
->vidioc_query_dv_preset(file
, fh
, p
);
1877 dbgarg(cmd
, "preset=%d\n", p
->preset
);
1880 case VIDIOC_S_DV_TIMINGS
:
1882 struct v4l2_dv_timings
*p
= arg
;
1884 if (!ops
->vidioc_s_dv_timings
)
1888 case V4L2_DV_BT_656_1120
:
1889 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
1890 " width=%d, height=%d, polarities=%x,"
1891 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
1892 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
1893 " il_vfrontporch=%d, il_vsync=%d,"
1894 " il_vbackporch=%d\n",
1895 p
->bt
.interlaced
, p
->bt
.pixelclock
,
1896 p
->bt
.width
, p
->bt
.height
, p
->bt
.polarities
,
1897 p
->bt
.hfrontporch
, p
->bt
.hsync
,
1898 p
->bt
.hbackporch
, p
->bt
.vfrontporch
,
1899 p
->bt
.vsync
, p
->bt
.vbackporch
,
1900 p
->bt
.il_vfrontporch
, p
->bt
.il_vsync
,
1901 p
->bt
.il_vbackporch
);
1902 ret
= ops
->vidioc_s_dv_timings(file
, fh
, p
);
1905 dbgarg2("Unknown type %d!\n", p
->type
);
1910 case VIDIOC_G_DV_TIMINGS
:
1912 struct v4l2_dv_timings
*p
= arg
;
1914 if (!ops
->vidioc_g_dv_timings
)
1917 ret
= ops
->vidioc_g_dv_timings(file
, fh
, p
);
1920 case V4L2_DV_BT_656_1120
:
1921 dbgarg2("bt-656/1120:interlaced=%d,"
1923 " width=%d, height=%d, polarities=%x,"
1924 " hfrontporch=%d, hsync=%d,"
1925 " hbackporch=%d, vfrontporch=%d,"
1926 " vsync=%d, vbackporch=%d,"
1927 " il_vfrontporch=%d, il_vsync=%d,"
1928 " il_vbackporch=%d\n",
1929 p
->bt
.interlaced
, p
->bt
.pixelclock
,
1930 p
->bt
.width
, p
->bt
.height
,
1931 p
->bt
.polarities
, p
->bt
.hfrontporch
,
1932 p
->bt
.hsync
, p
->bt
.hbackporch
,
1933 p
->bt
.vfrontporch
, p
->bt
.vsync
,
1934 p
->bt
.vbackporch
, p
->bt
.il_vfrontporch
,
1935 p
->bt
.il_vsync
, p
->bt
.il_vbackporch
);
1938 dbgarg2("Unknown type %d!\n", p
->type
);
1947 if (!ops
->vidioc_default
)
1949 ret
= ops
->vidioc_default(file
, fh
, cmd
, arg
);
1954 if (vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
) {
1956 v4l_print_ioctl(vfd
->name
, cmd
);
1957 printk(KERN_CONT
" error %ld\n", ret
);
1964 /* In some cases, only a few fields are used as input, i.e. when the app sets
1965 * "index" and then the driver fills in the rest of the structure for the thing
1966 * with that index. We only need to copy up the first non-input field. */
1967 static unsigned long cmd_input_size(unsigned int cmd
)
1969 /* Size of structure up to and including 'field' */
1970 #define CMDINSIZE(cmd, type, field) \
1971 case VIDIOC_##cmd: \
1972 return offsetof(struct v4l2_##type, field) + \
1973 sizeof(((struct v4l2_##type *)0)->field);
1976 CMDINSIZE(ENUM_FMT
, fmtdesc
, type
);
1977 CMDINSIZE(G_FMT
, format
, type
);
1978 CMDINSIZE(QUERYBUF
, buffer
, type
);
1979 CMDINSIZE(G_PARM
, streamparm
, type
);
1980 CMDINSIZE(ENUMSTD
, standard
, index
);
1981 CMDINSIZE(ENUMINPUT
, input
, index
);
1982 CMDINSIZE(G_CTRL
, control
, id
);
1983 CMDINSIZE(G_TUNER
, tuner
, index
);
1984 CMDINSIZE(QUERYCTRL
, queryctrl
, id
);
1985 CMDINSIZE(QUERYMENU
, querymenu
, index
);
1986 CMDINSIZE(ENUMOUTPUT
, output
, index
);
1987 CMDINSIZE(G_MODULATOR
, modulator
, index
);
1988 CMDINSIZE(G_FREQUENCY
, frequency
, tuner
);
1989 CMDINSIZE(CROPCAP
, cropcap
, type
);
1990 CMDINSIZE(G_CROP
, crop
, type
);
1991 CMDINSIZE(ENUMAUDIO
, audio
, index
);
1992 CMDINSIZE(ENUMAUDOUT
, audioout
, index
);
1993 CMDINSIZE(ENCODER_CMD
, encoder_cmd
, flags
);
1994 CMDINSIZE(TRY_ENCODER_CMD
, encoder_cmd
, flags
);
1995 CMDINSIZE(G_SLICED_VBI_CAP
, sliced_vbi_cap
, type
);
1996 CMDINSIZE(ENUM_FRAMESIZES
, frmsizeenum
, pixel_format
);
1997 CMDINSIZE(ENUM_FRAMEINTERVALS
, frmivalenum
, height
);
1999 return _IOC_SIZE(cmd
);
2003 long video_ioctl2(struct file
*file
,
2004 unsigned int cmd
, unsigned long arg
)
2011 size_t ctrls_size
= 0;
2012 void __user
*user_ptr
= NULL
;
2014 #ifdef __OLD_VIDIOC_
2015 cmd
= video_fix_command(cmd
);
2017 is_ext_ctrl
= (cmd
== VIDIOC_S_EXT_CTRLS
|| cmd
== VIDIOC_G_EXT_CTRLS
||
2018 cmd
== VIDIOC_TRY_EXT_CTRLS
);
2020 /* Copy arguments into temp kernel buffer */
2021 if (_IOC_DIR(cmd
) != _IOC_NONE
) {
2022 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
2025 /* too big to allocate from stack */
2026 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
2033 if (_IOC_DIR(cmd
) & _IOC_WRITE
) {
2034 unsigned long n
= cmd_input_size(cmd
);
2036 if (copy_from_user(parg
, (void __user
*)arg
, n
))
2039 /* zero out anything we don't copy from userspace */
2040 if (n
< _IOC_SIZE(cmd
))
2041 memset((u8
*)parg
+ n
, 0, _IOC_SIZE(cmd
) - n
);
2043 /* read-only ioctl */
2044 memset(parg
, 0, _IOC_SIZE(cmd
));
2049 struct v4l2_ext_controls
*p
= parg
;
2051 /* In case of an error, tell the caller that it wasn't
2052 a specific control that caused it. */
2053 p
->error_idx
= p
->count
;
2054 user_ptr
= (void __user
*)p
->controls
;
2056 ctrls_size
= sizeof(struct v4l2_ext_control
) * p
->count
;
2057 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
2058 mbuf
= kmalloc(ctrls_size
, GFP_KERNEL
);
2063 if (copy_from_user(mbuf
, user_ptr
, ctrls_size
))
2070 err
= __video_do_ioctl(file
, cmd
, parg
);
2071 if (err
== -ENOIOCTLCMD
)
2074 struct v4l2_ext_controls
*p
= parg
;
2076 p
->controls
= (void *)user_ptr
;
2077 if (p
->count
&& err
== 0 && copy_to_user(user_ptr
, mbuf
, ctrls_size
))
2085 /* Copy results into user buffer */
2086 switch (_IOC_DIR(cmd
)) {
2088 case (_IOC_WRITE
| _IOC_READ
):
2089 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
2098 EXPORT_SYMBOL(video_ioctl2
);