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/slab.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
20 #include <linux/videodev2.h>
22 #include <media/v4l2-common.h>
23 #include <media/v4l2-ioctl.h>
24 #include <media/v4l2-ctrls.h>
25 #include <media/v4l2-fh.h>
26 #include <media/v4l2-event.h>
27 #include <media/v4l2-device.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. Everything 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",
168 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
] = "vid-cap-mplane",
169 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
] = "vid-out-mplane",
171 EXPORT_SYMBOL(v4l2_type_names
);
173 static const char *v4l2_memory_names
[] = {
174 [V4L2_MEMORY_MMAP
] = "mmap",
175 [V4L2_MEMORY_USERPTR
] = "userptr",
176 [V4L2_MEMORY_OVERLAY
] = "overlay",
179 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
182 /* ------------------------------------------------------------------ */
183 /* debug help functions */
184 static const char *v4l2_ioctls
[] = {
185 [_IOC_NR(VIDIOC_QUERYCAP
)] = "VIDIOC_QUERYCAP",
186 [_IOC_NR(VIDIOC_RESERVED
)] = "VIDIOC_RESERVED",
187 [_IOC_NR(VIDIOC_ENUM_FMT
)] = "VIDIOC_ENUM_FMT",
188 [_IOC_NR(VIDIOC_G_FMT
)] = "VIDIOC_G_FMT",
189 [_IOC_NR(VIDIOC_S_FMT
)] = "VIDIOC_S_FMT",
190 [_IOC_NR(VIDIOC_REQBUFS
)] = "VIDIOC_REQBUFS",
191 [_IOC_NR(VIDIOC_QUERYBUF
)] = "VIDIOC_QUERYBUF",
192 [_IOC_NR(VIDIOC_G_FBUF
)] = "VIDIOC_G_FBUF",
193 [_IOC_NR(VIDIOC_S_FBUF
)] = "VIDIOC_S_FBUF",
194 [_IOC_NR(VIDIOC_OVERLAY
)] = "VIDIOC_OVERLAY",
195 [_IOC_NR(VIDIOC_QBUF
)] = "VIDIOC_QBUF",
196 [_IOC_NR(VIDIOC_DQBUF
)] = "VIDIOC_DQBUF",
197 [_IOC_NR(VIDIOC_STREAMON
)] = "VIDIOC_STREAMON",
198 [_IOC_NR(VIDIOC_STREAMOFF
)] = "VIDIOC_STREAMOFF",
199 [_IOC_NR(VIDIOC_G_PARM
)] = "VIDIOC_G_PARM",
200 [_IOC_NR(VIDIOC_S_PARM
)] = "VIDIOC_S_PARM",
201 [_IOC_NR(VIDIOC_G_STD
)] = "VIDIOC_G_STD",
202 [_IOC_NR(VIDIOC_S_STD
)] = "VIDIOC_S_STD",
203 [_IOC_NR(VIDIOC_ENUMSTD
)] = "VIDIOC_ENUMSTD",
204 [_IOC_NR(VIDIOC_ENUMINPUT
)] = "VIDIOC_ENUMINPUT",
205 [_IOC_NR(VIDIOC_G_CTRL
)] = "VIDIOC_G_CTRL",
206 [_IOC_NR(VIDIOC_S_CTRL
)] = "VIDIOC_S_CTRL",
207 [_IOC_NR(VIDIOC_G_TUNER
)] = "VIDIOC_G_TUNER",
208 [_IOC_NR(VIDIOC_S_TUNER
)] = "VIDIOC_S_TUNER",
209 [_IOC_NR(VIDIOC_G_AUDIO
)] = "VIDIOC_G_AUDIO",
210 [_IOC_NR(VIDIOC_S_AUDIO
)] = "VIDIOC_S_AUDIO",
211 [_IOC_NR(VIDIOC_QUERYCTRL
)] = "VIDIOC_QUERYCTRL",
212 [_IOC_NR(VIDIOC_QUERYMENU
)] = "VIDIOC_QUERYMENU",
213 [_IOC_NR(VIDIOC_G_INPUT
)] = "VIDIOC_G_INPUT",
214 [_IOC_NR(VIDIOC_S_INPUT
)] = "VIDIOC_S_INPUT",
215 [_IOC_NR(VIDIOC_G_OUTPUT
)] = "VIDIOC_G_OUTPUT",
216 [_IOC_NR(VIDIOC_S_OUTPUT
)] = "VIDIOC_S_OUTPUT",
217 [_IOC_NR(VIDIOC_ENUMOUTPUT
)] = "VIDIOC_ENUMOUTPUT",
218 [_IOC_NR(VIDIOC_G_AUDOUT
)] = "VIDIOC_G_AUDOUT",
219 [_IOC_NR(VIDIOC_S_AUDOUT
)] = "VIDIOC_S_AUDOUT",
220 [_IOC_NR(VIDIOC_G_MODULATOR
)] = "VIDIOC_G_MODULATOR",
221 [_IOC_NR(VIDIOC_S_MODULATOR
)] = "VIDIOC_S_MODULATOR",
222 [_IOC_NR(VIDIOC_G_FREQUENCY
)] = "VIDIOC_G_FREQUENCY",
223 [_IOC_NR(VIDIOC_S_FREQUENCY
)] = "VIDIOC_S_FREQUENCY",
224 [_IOC_NR(VIDIOC_CROPCAP
)] = "VIDIOC_CROPCAP",
225 [_IOC_NR(VIDIOC_G_CROP
)] = "VIDIOC_G_CROP",
226 [_IOC_NR(VIDIOC_S_CROP
)] = "VIDIOC_S_CROP",
227 [_IOC_NR(VIDIOC_G_JPEGCOMP
)] = "VIDIOC_G_JPEGCOMP",
228 [_IOC_NR(VIDIOC_S_JPEGCOMP
)] = "VIDIOC_S_JPEGCOMP",
229 [_IOC_NR(VIDIOC_QUERYSTD
)] = "VIDIOC_QUERYSTD",
230 [_IOC_NR(VIDIOC_TRY_FMT
)] = "VIDIOC_TRY_FMT",
231 [_IOC_NR(VIDIOC_ENUMAUDIO
)] = "VIDIOC_ENUMAUDIO",
232 [_IOC_NR(VIDIOC_ENUMAUDOUT
)] = "VIDIOC_ENUMAUDOUT",
233 [_IOC_NR(VIDIOC_G_PRIORITY
)] = "VIDIOC_G_PRIORITY",
234 [_IOC_NR(VIDIOC_S_PRIORITY
)] = "VIDIOC_S_PRIORITY",
235 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP
)] = "VIDIOC_G_SLICED_VBI_CAP",
236 [_IOC_NR(VIDIOC_LOG_STATUS
)] = "VIDIOC_LOG_STATUS",
237 [_IOC_NR(VIDIOC_G_EXT_CTRLS
)] = "VIDIOC_G_EXT_CTRLS",
238 [_IOC_NR(VIDIOC_S_EXT_CTRLS
)] = "VIDIOC_S_EXT_CTRLS",
239 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS
)] = "VIDIOC_TRY_EXT_CTRLS",
241 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES
)] = "VIDIOC_ENUM_FRAMESIZES",
242 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS
)] = "VIDIOC_ENUM_FRAMEINTERVALS",
243 [_IOC_NR(VIDIOC_G_ENC_INDEX
)] = "VIDIOC_G_ENC_INDEX",
244 [_IOC_NR(VIDIOC_ENCODER_CMD
)] = "VIDIOC_ENCODER_CMD",
245 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD
)] = "VIDIOC_TRY_ENCODER_CMD",
247 [_IOC_NR(VIDIOC_DBG_S_REGISTER
)] = "VIDIOC_DBG_S_REGISTER",
248 [_IOC_NR(VIDIOC_DBG_G_REGISTER
)] = "VIDIOC_DBG_G_REGISTER",
250 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT
)] = "VIDIOC_DBG_G_CHIP_IDENT",
251 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK
)] = "VIDIOC_S_HW_FREQ_SEEK",
253 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS
)] = "VIDIOC_ENUM_DV_PRESETS",
254 [_IOC_NR(VIDIOC_S_DV_PRESET
)] = "VIDIOC_S_DV_PRESET",
255 [_IOC_NR(VIDIOC_G_DV_PRESET
)] = "VIDIOC_G_DV_PRESET",
256 [_IOC_NR(VIDIOC_QUERY_DV_PRESET
)] = "VIDIOC_QUERY_DV_PRESET",
257 [_IOC_NR(VIDIOC_S_DV_TIMINGS
)] = "VIDIOC_S_DV_TIMINGS",
258 [_IOC_NR(VIDIOC_G_DV_TIMINGS
)] = "VIDIOC_G_DV_TIMINGS",
259 [_IOC_NR(VIDIOC_DQEVENT
)] = "VIDIOC_DQEVENT",
260 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT
)] = "VIDIOC_SUBSCRIBE_EVENT",
261 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT
)] = "VIDIOC_UNSUBSCRIBE_EVENT",
263 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
265 /* Common ioctl debug function. This function can be used by
266 external ioctl messages as well as internal V4L ioctl */
267 void v4l_printk_ioctl(unsigned int cmd
)
271 switch (_IOC_TYPE(cmd
)) {
276 if (_IOC_NR(cmd
) >= V4L2_IOCTLS
) {
280 printk("%s", v4l2_ioctls
[_IOC_NR(cmd
)]);
286 switch (_IOC_DIR(cmd
)) {
287 case _IOC_NONE
: dir
= "--"; break;
288 case _IOC_READ
: dir
= "r-"; break;
289 case _IOC_WRITE
: dir
= "-w"; break;
290 case _IOC_READ
| _IOC_WRITE
: dir
= "rw"; break;
291 default: dir
= "*ERR*"; break;
293 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
294 type
, _IOC_TYPE(cmd
), dir
, _IOC_NR(cmd
), cmd
);
296 EXPORT_SYMBOL(v4l_printk_ioctl
);
298 static void dbgbuf(unsigned int cmd
, struct video_device
*vfd
,
299 struct v4l2_buffer
*p
)
301 struct v4l2_timecode
*tc
= &p
->timecode
;
302 struct v4l2_plane
*plane
;
305 dbgarg(cmd
, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
306 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
307 p
->timestamp
.tv_sec
/ 3600,
308 (int)(p
->timestamp
.tv_sec
/ 60) % 60,
309 (int)(p
->timestamp
.tv_sec
% 60),
310 (long)p
->timestamp
.tv_usec
,
312 prt_names(p
->type
, v4l2_type_names
),
313 p
->flags
, p
->field
, p
->sequence
,
314 prt_names(p
->memory
, v4l2_memory_names
));
316 if (V4L2_TYPE_IS_MULTIPLANAR(p
->type
) && p
->m
.planes
) {
317 for (i
= 0; i
< p
->length
; ++i
) {
318 plane
= &p
->m
.planes
[i
];
319 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
320 "offset/userptr=0x%08lx, length=%d\n",
321 i
, plane
->bytesused
, plane
->data_offset
,
322 plane
->m
.userptr
, plane
->length
);
325 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
326 p
->bytesused
, p
->m
.userptr
, p
->length
);
329 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
330 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
331 tc
->hours
, tc
->minutes
, tc
->seconds
,
332 tc
->type
, tc
->flags
, tc
->frames
, *(__u32
*)tc
->userbits
);
335 static inline void dbgrect(struct video_device
*vfd
, char *s
,
338 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s
, r
->left
, r
->top
,
339 r
->width
, r
->height
);
342 static inline void v4l_print_pix_fmt(struct video_device
*vfd
,
343 struct v4l2_pix_format
*fmt
)
345 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
346 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
347 fmt
->width
, fmt
->height
,
348 (fmt
->pixelformat
& 0xff),
349 (fmt
->pixelformat
>> 8) & 0xff,
350 (fmt
->pixelformat
>> 16) & 0xff,
351 (fmt
->pixelformat
>> 24) & 0xff,
352 prt_names(fmt
->field
, v4l2_field_names
),
353 fmt
->bytesperline
, fmt
->sizeimage
, fmt
->colorspace
);
356 static inline void v4l_print_pix_fmt_mplane(struct video_device
*vfd
,
357 struct v4l2_pix_format_mplane
*fmt
)
361 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
362 "colorspace=%d, num_planes=%d\n",
363 fmt
->width
, fmt
->height
,
364 (fmt
->pixelformat
& 0xff),
365 (fmt
->pixelformat
>> 8) & 0xff,
366 (fmt
->pixelformat
>> 16) & 0xff,
367 (fmt
->pixelformat
>> 24) & 0xff,
368 prt_names(fmt
->field
, v4l2_field_names
),
369 fmt
->colorspace
, fmt
->num_planes
);
371 for (i
= 0; i
< fmt
->num_planes
; ++i
)
372 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i
,
373 fmt
->plane_fmt
[i
].bytesperline
,
374 fmt
->plane_fmt
[i
].sizeimage
);
377 static inline void v4l_print_ext_ctrls(unsigned int cmd
,
378 struct video_device
*vfd
, struct v4l2_ext_controls
*c
, int show_vals
)
382 if (!(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
))
385 printk(KERN_CONT
"class=0x%x", c
->ctrl_class
);
386 for (i
= 0; i
< c
->count
; i
++) {
387 if (show_vals
&& !c
->controls
[i
].size
)
388 printk(KERN_CONT
" id/val=0x%x/0x%x",
389 c
->controls
[i
].id
, c
->controls
[i
].value
);
391 printk(KERN_CONT
" id=0x%x,size=%u",
392 c
->controls
[i
].id
, c
->controls
[i
].size
);
394 printk(KERN_CONT
"\n");
397 static inline int check_ext_ctrls(struct v4l2_ext_controls
*c
, int allow_priv
)
401 /* zero the reserved fields */
402 c
->reserved
[0] = c
->reserved
[1] = 0;
403 for (i
= 0; i
< c
->count
; i
++)
404 c
->controls
[i
].reserved2
[0] = 0;
406 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
407 when using extended controls.
408 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
409 is it allowed for backwards compatibility.
411 if (!allow_priv
&& c
->ctrl_class
== V4L2_CID_PRIVATE_BASE
)
413 /* Check that all controls are from the same control class. */
414 for (i
= 0; i
< c
->count
; i
++) {
415 if (V4L2_CTRL_ID2CLASS(c
->controls
[i
].id
) != c
->ctrl_class
) {
423 static int check_fmt(const struct v4l2_ioctl_ops
*ops
, enum v4l2_buf_type type
)
429 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
430 if (ops
->vidioc_g_fmt_vid_cap
||
431 ops
->vidioc_g_fmt_vid_cap_mplane
)
434 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
435 if (ops
->vidioc_g_fmt_vid_cap_mplane
)
438 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
439 if (ops
->vidioc_g_fmt_vid_overlay
)
442 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
443 if (ops
->vidioc_g_fmt_vid_out
||
444 ops
->vidioc_g_fmt_vid_out_mplane
)
447 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
448 if (ops
->vidioc_g_fmt_vid_out_mplane
)
451 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
452 if (ops
->vidioc_g_fmt_vid_out_overlay
)
455 case V4L2_BUF_TYPE_VBI_CAPTURE
:
456 if (ops
->vidioc_g_fmt_vbi_cap
)
459 case V4L2_BUF_TYPE_VBI_OUTPUT
:
460 if (ops
->vidioc_g_fmt_vbi_out
)
463 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
464 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
467 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
468 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
471 case V4L2_BUF_TYPE_PRIVATE
:
472 if (ops
->vidioc_g_fmt_type_private
)
480 * fmt_sp_to_mp() - Convert a single-plane format to its multi-planar 1-plane
483 static int fmt_sp_to_mp(const struct v4l2_format
*f_sp
,
484 struct v4l2_format
*f_mp
)
486 struct v4l2_pix_format_mplane
*pix_mp
= &f_mp
->fmt
.pix_mp
;
487 const struct v4l2_pix_format
*pix
= &f_sp
->fmt
.pix
;
489 if (f_sp
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
490 f_mp
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
;
491 else if (f_sp
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
)
492 f_mp
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
;
496 pix_mp
->width
= pix
->width
;
497 pix_mp
->height
= pix
->height
;
498 pix_mp
->pixelformat
= pix
->pixelformat
;
499 pix_mp
->field
= pix
->field
;
500 pix_mp
->colorspace
= pix
->colorspace
;
501 pix_mp
->num_planes
= 1;
502 pix_mp
->plane_fmt
[0].sizeimage
= pix
->sizeimage
;
503 pix_mp
->plane_fmt
[0].bytesperline
= pix
->bytesperline
;
509 * fmt_mp_to_sp() - Convert a multi-planar 1-plane format to its single-planar
512 static int fmt_mp_to_sp(const struct v4l2_format
*f_mp
,
513 struct v4l2_format
*f_sp
)
515 const struct v4l2_pix_format_mplane
*pix_mp
= &f_mp
->fmt
.pix_mp
;
516 struct v4l2_pix_format
*pix
= &f_sp
->fmt
.pix
;
518 if (f_mp
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
519 f_sp
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
520 else if (f_mp
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
521 f_sp
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
525 pix
->width
= pix_mp
->width
;
526 pix
->height
= pix_mp
->height
;
527 pix
->pixelformat
= pix_mp
->pixelformat
;
528 pix
->field
= pix_mp
->field
;
529 pix
->colorspace
= pix_mp
->colorspace
;
530 pix
->sizeimage
= pix_mp
->plane_fmt
[0].sizeimage
;
531 pix
->bytesperline
= pix_mp
->plane_fmt
[0].bytesperline
;
536 static long __video_do_ioctl(struct file
*file
,
537 unsigned int cmd
, void *arg
)
539 struct video_device
*vfd
= video_devdata(file
);
540 const struct v4l2_ioctl_ops
*ops
= vfd
->ioctl_ops
;
541 void *fh
= file
->private_data
;
542 struct v4l2_fh
*vfh
= NULL
;
543 struct v4l2_format f_copy
;
548 printk(KERN_WARNING
"videodev: \"%s\" has no ioctl_ops.\n",
553 if ((vfd
->debug
& V4L2_DEBUG_IOCTL
) &&
554 !(vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
)) {
555 v4l_print_ioctl(vfd
->name
, cmd
);
556 printk(KERN_CONT
"\n");
559 if (test_bit(V4L2_FL_USES_V4L2_FH
, &vfd
->flags
)) {
560 vfh
= file
->private_data
;
561 use_fh_prio
= test_bit(V4L2_FL_USE_FH_PRIO
, &vfd
->flags
);
569 case VIDIOC_S_OUTPUT
:
571 case VIDIOC_S_FREQUENCY
:
575 case VIDIOC_S_AUDOUT
:
576 case VIDIOC_S_EXT_CTRLS
:
578 case VIDIOC_S_PRIORITY
:
579 case VIDIOC_S_DV_PRESET
:
580 case VIDIOC_S_DV_TIMINGS
:
581 case VIDIOC_S_JPEGCOMP
:
582 case VIDIOC_S_MODULATOR
:
584 case VIDIOC_S_HW_FREQ_SEEK
:
585 case VIDIOC_ENCODER_CMD
:
588 case VIDIOC_STREAMON
:
589 case VIDIOC_STREAMOFF
:
590 ret
= v4l2_prio_check(vfd
->prio
, vfh
->prio
);
600 /* --- capabilities ------------------------------------------ */
601 case VIDIOC_QUERYCAP
:
603 struct v4l2_capability
*cap
= (struct v4l2_capability
*)arg
;
605 if (!ops
->vidioc_querycap
)
608 ret
= ops
->vidioc_querycap(file
, fh
, cap
);
610 dbgarg(cmd
, "driver=%s, card=%s, bus=%s, "
612 "capabilities=0x%08x\n",
613 cap
->driver
, cap
->card
, cap
->bus_info
,
619 /* --- priority ------------------------------------------ */
620 case VIDIOC_G_PRIORITY
:
622 enum v4l2_priority
*p
= arg
;
624 if (ops
->vidioc_g_priority
) {
625 ret
= ops
->vidioc_g_priority(file
, fh
, p
);
626 } else if (use_fh_prio
) {
627 *p
= v4l2_prio_max(&vfd
->v4l2_dev
->prio
);
631 dbgarg(cmd
, "priority is %d\n", *p
);
634 case VIDIOC_S_PRIORITY
:
636 enum v4l2_priority
*p
= arg
;
638 if (!ops
->vidioc_s_priority
&& !use_fh_prio
)
640 dbgarg(cmd
, "setting priority to %d\n", *p
);
641 if (ops
->vidioc_s_priority
)
642 ret
= ops
->vidioc_s_priority(file
, fh
, *p
);
644 ret
= v4l2_prio_change(&vfd
->v4l2_dev
->prio
, &vfh
->prio
, *p
);
648 /* --- capture ioctls ---------------------------------------- */
649 case VIDIOC_ENUM_FMT
:
651 struct v4l2_fmtdesc
*f
= arg
;
654 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
655 if (ops
->vidioc_enum_fmt_vid_cap
)
656 ret
= ops
->vidioc_enum_fmt_vid_cap(file
, fh
, f
);
658 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
659 if (ops
->vidioc_enum_fmt_vid_cap_mplane
)
660 ret
= ops
->vidioc_enum_fmt_vid_cap_mplane(file
,
663 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
664 if (ops
->vidioc_enum_fmt_vid_overlay
)
665 ret
= ops
->vidioc_enum_fmt_vid_overlay(file
,
668 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
669 if (ops
->vidioc_enum_fmt_vid_out
)
670 ret
= ops
->vidioc_enum_fmt_vid_out(file
, fh
, f
);
672 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
673 if (ops
->vidioc_enum_fmt_vid_out_mplane
)
674 ret
= ops
->vidioc_enum_fmt_vid_out_mplane(file
,
677 case V4L2_BUF_TYPE_PRIVATE
:
678 if (ops
->vidioc_enum_fmt_type_private
)
679 ret
= ops
->vidioc_enum_fmt_type_private(file
,
686 dbgarg(cmd
, "index=%d, type=%d, flags=%d, "
687 "pixelformat=%c%c%c%c, description='%s'\n",
688 f
->index
, f
->type
, f
->flags
,
689 (f
->pixelformat
& 0xff),
690 (f
->pixelformat
>> 8) & 0xff,
691 (f
->pixelformat
>> 16) & 0xff,
692 (f
->pixelformat
>> 24) & 0xff,
698 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
700 /* FIXME: Should be one dump per type */
701 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
704 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
705 if (ops
->vidioc_g_fmt_vid_cap
) {
706 ret
= ops
->vidioc_g_fmt_vid_cap(file
, fh
, f
);
707 } else if (ops
->vidioc_g_fmt_vid_cap_mplane
) {
708 if (fmt_sp_to_mp(f
, &f_copy
))
710 ret
= ops
->vidioc_g_fmt_vid_cap_mplane(file
, fh
,
715 /* Driver is currently in multi-planar format,
716 * we can't return it in single-planar API*/
717 if (f_copy
.fmt
.pix_mp
.num_planes
> 1) {
722 ret
= fmt_mp_to_sp(&f_copy
, f
);
725 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
727 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
728 if (ops
->vidioc_g_fmt_vid_cap_mplane
) {
729 ret
= ops
->vidioc_g_fmt_vid_cap_mplane(file
,
731 } else if (ops
->vidioc_g_fmt_vid_cap
) {
732 if (fmt_mp_to_sp(f
, &f_copy
))
734 ret
= ops
->vidioc_g_fmt_vid_cap(file
,
739 ret
= fmt_sp_to_mp(&f_copy
, f
);
742 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
744 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
745 if (ops
->vidioc_g_fmt_vid_overlay
)
746 ret
= ops
->vidioc_g_fmt_vid_overlay(file
,
749 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
750 if (ops
->vidioc_g_fmt_vid_out
) {
751 ret
= ops
->vidioc_g_fmt_vid_out(file
, fh
, f
);
752 } else if (ops
->vidioc_g_fmt_vid_out_mplane
) {
753 if (fmt_sp_to_mp(f
, &f_copy
))
755 ret
= ops
->vidioc_g_fmt_vid_out_mplane(file
, fh
,
760 /* Driver is currently in multi-planar format,
761 * we can't return it in single-planar API*/
762 if (f_copy
.fmt
.pix_mp
.num_planes
> 1) {
767 ret
= fmt_mp_to_sp(&f_copy
, f
);
770 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
772 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
773 if (ops
->vidioc_g_fmt_vid_out_mplane
) {
774 ret
= ops
->vidioc_g_fmt_vid_out_mplane(file
,
776 } else if (ops
->vidioc_g_fmt_vid_out
) {
777 if (fmt_mp_to_sp(f
, &f_copy
))
779 ret
= ops
->vidioc_g_fmt_vid_out(file
,
784 ret
= fmt_sp_to_mp(&f_copy
, f
);
787 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
789 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
790 if (ops
->vidioc_g_fmt_vid_out_overlay
)
791 ret
= ops
->vidioc_g_fmt_vid_out_overlay(file
,
794 case V4L2_BUF_TYPE_VBI_CAPTURE
:
795 if (ops
->vidioc_g_fmt_vbi_cap
)
796 ret
= ops
->vidioc_g_fmt_vbi_cap(file
, fh
, f
);
798 case V4L2_BUF_TYPE_VBI_OUTPUT
:
799 if (ops
->vidioc_g_fmt_vbi_out
)
800 ret
= ops
->vidioc_g_fmt_vbi_out(file
, fh
, f
);
802 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
803 if (ops
->vidioc_g_fmt_sliced_vbi_cap
)
804 ret
= ops
->vidioc_g_fmt_sliced_vbi_cap(file
,
807 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
808 if (ops
->vidioc_g_fmt_sliced_vbi_out
)
809 ret
= ops
->vidioc_g_fmt_sliced_vbi_out(file
,
812 case V4L2_BUF_TYPE_PRIVATE
:
813 if (ops
->vidioc_g_fmt_type_private
)
814 ret
= ops
->vidioc_g_fmt_type_private(file
,
823 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
825 /* FIXME: Should be one dump per type */
826 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
, v4l2_type_names
));
829 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
830 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
831 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
832 if (ops
->vidioc_s_fmt_vid_cap
) {
833 ret
= ops
->vidioc_s_fmt_vid_cap(file
, fh
, f
);
834 } else if (ops
->vidioc_s_fmt_vid_cap_mplane
) {
835 if (fmt_sp_to_mp(f
, &f_copy
))
837 ret
= ops
->vidioc_s_fmt_vid_cap_mplane(file
, fh
,
842 if (f_copy
.fmt
.pix_mp
.num_planes
> 1) {
843 /* Drivers shouldn't adjust from 1-plane
844 * to more than 1-plane formats */
850 ret
= fmt_mp_to_sp(&f_copy
, f
);
853 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
854 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
855 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
856 if (ops
->vidioc_s_fmt_vid_cap_mplane
) {
857 ret
= ops
->vidioc_s_fmt_vid_cap_mplane(file
,
859 } else if (ops
->vidioc_s_fmt_vid_cap
&&
860 f
->fmt
.pix_mp
.num_planes
== 1) {
861 if (fmt_mp_to_sp(f
, &f_copy
))
863 ret
= ops
->vidioc_s_fmt_vid_cap(file
,
868 ret
= fmt_sp_to_mp(&f_copy
, f
);
871 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
872 CLEAR_AFTER_FIELD(f
, fmt
.win
);
873 if (ops
->vidioc_s_fmt_vid_overlay
)
874 ret
= ops
->vidioc_s_fmt_vid_overlay(file
,
877 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
878 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
879 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
880 if (ops
->vidioc_s_fmt_vid_out
) {
881 ret
= ops
->vidioc_s_fmt_vid_out(file
, fh
, f
);
882 } else if (ops
->vidioc_s_fmt_vid_out_mplane
) {
883 if (fmt_sp_to_mp(f
, &f_copy
))
885 ret
= ops
->vidioc_s_fmt_vid_out_mplane(file
, fh
,
890 if (f_copy
.fmt
.pix_mp
.num_planes
> 1) {
891 /* Drivers shouldn't adjust from 1-plane
892 * to more than 1-plane formats */
898 ret
= fmt_mp_to_sp(&f_copy
, f
);
901 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
902 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
903 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
904 if (ops
->vidioc_s_fmt_vid_out_mplane
) {
905 ret
= ops
->vidioc_s_fmt_vid_out_mplane(file
,
907 } else if (ops
->vidioc_s_fmt_vid_out
&&
908 f
->fmt
.pix_mp
.num_planes
== 1) {
909 if (fmt_mp_to_sp(f
, &f_copy
))
911 ret
= ops
->vidioc_s_fmt_vid_out(file
,
916 ret
= fmt_mp_to_sp(&f_copy
, f
);
919 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
920 CLEAR_AFTER_FIELD(f
, fmt
.win
);
921 if (ops
->vidioc_s_fmt_vid_out_overlay
)
922 ret
= ops
->vidioc_s_fmt_vid_out_overlay(file
,
925 case V4L2_BUF_TYPE_VBI_CAPTURE
:
926 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
927 if (ops
->vidioc_s_fmt_vbi_cap
)
928 ret
= ops
->vidioc_s_fmt_vbi_cap(file
, fh
, f
);
930 case V4L2_BUF_TYPE_VBI_OUTPUT
:
931 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
932 if (ops
->vidioc_s_fmt_vbi_out
)
933 ret
= ops
->vidioc_s_fmt_vbi_out(file
, fh
, f
);
935 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
936 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
937 if (ops
->vidioc_s_fmt_sliced_vbi_cap
)
938 ret
= ops
->vidioc_s_fmt_sliced_vbi_cap(file
,
941 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
942 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
943 if (ops
->vidioc_s_fmt_sliced_vbi_out
)
944 ret
= ops
->vidioc_s_fmt_sliced_vbi_out(file
,
947 case V4L2_BUF_TYPE_PRIVATE
:
948 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
949 if (ops
->vidioc_s_fmt_type_private
)
950 ret
= ops
->vidioc_s_fmt_type_private(file
,
958 struct v4l2_format
*f
= (struct v4l2_format
*)arg
;
960 /* FIXME: Should be one dump per type */
961 dbgarg(cmd
, "type=%s\n", prt_names(f
->type
,
964 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
965 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
966 if (ops
->vidioc_try_fmt_vid_cap
) {
967 ret
= ops
->vidioc_try_fmt_vid_cap(file
, fh
, f
);
968 } else if (ops
->vidioc_try_fmt_vid_cap_mplane
) {
969 if (fmt_sp_to_mp(f
, &f_copy
))
971 ret
= ops
->vidioc_try_fmt_vid_cap_mplane(file
,
976 if (f_copy
.fmt
.pix_mp
.num_planes
> 1) {
977 /* Drivers shouldn't adjust from 1-plane
978 * to more than 1-plane formats */
983 ret
= fmt_mp_to_sp(&f_copy
, f
);
986 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
988 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
989 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
990 if (ops
->vidioc_try_fmt_vid_cap_mplane
) {
991 ret
= ops
->vidioc_try_fmt_vid_cap_mplane(file
,
993 } else if (ops
->vidioc_try_fmt_vid_cap
&&
994 f
->fmt
.pix_mp
.num_planes
== 1) {
995 if (fmt_mp_to_sp(f
, &f_copy
))
997 ret
= ops
->vidioc_try_fmt_vid_cap(file
,
1002 ret
= fmt_sp_to_mp(&f_copy
, f
);
1005 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
1007 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1008 CLEAR_AFTER_FIELD(f
, fmt
.win
);
1009 if (ops
->vidioc_try_fmt_vid_overlay
)
1010 ret
= ops
->vidioc_try_fmt_vid_overlay(file
,
1013 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
1014 CLEAR_AFTER_FIELD(f
, fmt
.pix
);
1015 if (ops
->vidioc_try_fmt_vid_out
) {
1016 ret
= ops
->vidioc_try_fmt_vid_out(file
, fh
, f
);
1017 } else if (ops
->vidioc_try_fmt_vid_out_mplane
) {
1018 if (fmt_sp_to_mp(f
, &f_copy
))
1020 ret
= ops
->vidioc_try_fmt_vid_out_mplane(file
,
1025 if (f_copy
.fmt
.pix_mp
.num_planes
> 1) {
1026 /* Drivers shouldn't adjust from 1-plane
1027 * to more than 1-plane formats */
1032 ret
= fmt_mp_to_sp(&f_copy
, f
);
1035 v4l_print_pix_fmt(vfd
, &f
->fmt
.pix
);
1037 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1038 CLEAR_AFTER_FIELD(f
, fmt
.pix_mp
);
1039 if (ops
->vidioc_try_fmt_vid_out_mplane
) {
1040 ret
= ops
->vidioc_try_fmt_vid_out_mplane(file
,
1042 } else if (ops
->vidioc_try_fmt_vid_out
&&
1043 f
->fmt
.pix_mp
.num_planes
== 1) {
1044 if (fmt_mp_to_sp(f
, &f_copy
))
1046 ret
= ops
->vidioc_try_fmt_vid_out(file
,
1051 ret
= fmt_sp_to_mp(&f_copy
, f
);
1054 v4l_print_pix_fmt_mplane(vfd
, &f
->fmt
.pix_mp
);
1056 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
1057 CLEAR_AFTER_FIELD(f
, fmt
.win
);
1058 if (ops
->vidioc_try_fmt_vid_out_overlay
)
1059 ret
= ops
->vidioc_try_fmt_vid_out_overlay(file
,
1062 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1063 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
1064 if (ops
->vidioc_try_fmt_vbi_cap
)
1065 ret
= ops
->vidioc_try_fmt_vbi_cap(file
, fh
, f
);
1067 case V4L2_BUF_TYPE_VBI_OUTPUT
:
1068 CLEAR_AFTER_FIELD(f
, fmt
.vbi
);
1069 if (ops
->vidioc_try_fmt_vbi_out
)
1070 ret
= ops
->vidioc_try_fmt_vbi_out(file
, fh
, f
);
1072 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
1073 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
1074 if (ops
->vidioc_try_fmt_sliced_vbi_cap
)
1075 ret
= ops
->vidioc_try_fmt_sliced_vbi_cap(file
,
1078 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
1079 CLEAR_AFTER_FIELD(f
, fmt
.sliced
);
1080 if (ops
->vidioc_try_fmt_sliced_vbi_out
)
1081 ret
= ops
->vidioc_try_fmt_sliced_vbi_out(file
,
1084 case V4L2_BUF_TYPE_PRIVATE
:
1085 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
1086 if (ops
->vidioc_try_fmt_type_private
)
1087 ret
= ops
->vidioc_try_fmt_type_private(file
,
1094 /* FIXME: Those buf reqs could be handled here,
1095 with some changes on videobuf to allow its header to be included at
1096 videodev2.h or being merged at videodev2.
1098 case VIDIOC_REQBUFS
:
1100 struct v4l2_requestbuffers
*p
= arg
;
1102 if (!ops
->vidioc_reqbufs
)
1104 ret
= check_fmt(ops
, p
->type
);
1108 if (p
->type
< V4L2_BUF_TYPE_PRIVATE
)
1109 CLEAR_AFTER_FIELD(p
, memory
);
1111 ret
= ops
->vidioc_reqbufs(file
, fh
, p
);
1112 dbgarg(cmd
, "count=%d, type=%s, memory=%s\n",
1114 prt_names(p
->type
, v4l2_type_names
),
1115 prt_names(p
->memory
, v4l2_memory_names
));
1118 case VIDIOC_QUERYBUF
:
1120 struct v4l2_buffer
*p
= arg
;
1122 if (!ops
->vidioc_querybuf
)
1124 ret
= check_fmt(ops
, p
->type
);
1128 ret
= ops
->vidioc_querybuf(file
, fh
, p
);
1130 dbgbuf(cmd
, vfd
, p
);
1135 struct v4l2_buffer
*p
= arg
;
1137 if (!ops
->vidioc_qbuf
)
1139 ret
= check_fmt(ops
, p
->type
);
1143 ret
= ops
->vidioc_qbuf(file
, fh
, p
);
1145 dbgbuf(cmd
, vfd
, p
);
1150 struct v4l2_buffer
*p
= arg
;
1152 if (!ops
->vidioc_dqbuf
)
1154 ret
= check_fmt(ops
, p
->type
);
1158 ret
= ops
->vidioc_dqbuf(file
, fh
, p
);
1160 dbgbuf(cmd
, vfd
, p
);
1163 case VIDIOC_OVERLAY
:
1167 if (!ops
->vidioc_overlay
)
1169 dbgarg(cmd
, "value=%d\n", *i
);
1170 ret
= ops
->vidioc_overlay(file
, fh
, *i
);
1175 struct v4l2_framebuffer
*p
= arg
;
1177 if (!ops
->vidioc_g_fbuf
)
1179 ret
= ops
->vidioc_g_fbuf(file
, fh
, arg
);
1181 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
1182 p
->capability
, p
->flags
,
1183 (unsigned long)p
->base
);
1184 v4l_print_pix_fmt(vfd
, &p
->fmt
);
1190 struct v4l2_framebuffer
*p
= arg
;
1192 if (!ops
->vidioc_s_fbuf
)
1194 dbgarg(cmd
, "capability=0x%x, flags=%d, base=0x%08lx\n",
1195 p
->capability
, p
->flags
, (unsigned long)p
->base
);
1196 v4l_print_pix_fmt(vfd
, &p
->fmt
);
1197 ret
= ops
->vidioc_s_fbuf(file
, fh
, arg
);
1200 case VIDIOC_STREAMON
:
1202 enum v4l2_buf_type i
= *(int *)arg
;
1204 if (!ops
->vidioc_streamon
)
1206 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1207 ret
= ops
->vidioc_streamon(file
, fh
, i
);
1210 case VIDIOC_STREAMOFF
:
1212 enum v4l2_buf_type i
= *(int *)arg
;
1214 if (!ops
->vidioc_streamoff
)
1216 dbgarg(cmd
, "type=%s\n", prt_names(i
, v4l2_type_names
));
1217 ret
= ops
->vidioc_streamoff(file
, fh
, i
);
1220 /* ---------- tv norms ---------- */
1221 case VIDIOC_ENUMSTD
:
1223 struct v4l2_standard
*p
= arg
;
1224 v4l2_std_id id
= vfd
->tvnorms
, curr_id
= 0;
1225 unsigned int index
= p
->index
, i
, j
= 0;
1226 const char *descr
= "";
1228 /* Return norm array in a canonical way */
1229 for (i
= 0; i
<= index
&& id
; i
++) {
1230 /* last std value in the standards array is 0, so this
1231 while always ends there since (id & 0) == 0. */
1232 while ((id
& standards
[j
].std
) != standards
[j
].std
)
1234 curr_id
= standards
[j
].std
;
1235 descr
= standards
[j
].descr
;
1239 if (curr_id
!= V4L2_STD_PAL
&&
1240 curr_id
!= V4L2_STD_SECAM
&&
1241 curr_id
!= V4L2_STD_NTSC
)
1247 v4l2_video_std_construct(p
, curr_id
, descr
);
1249 dbgarg(cmd
, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1250 "framelines=%d\n", p
->index
,
1251 (unsigned long long)p
->id
, p
->name
,
1252 p
->frameperiod
.numerator
,
1253 p
->frameperiod
.denominator
,
1261 v4l2_std_id
*id
= arg
;
1264 /* Calls the specific handler */
1265 if (ops
->vidioc_g_std
)
1266 ret
= ops
->vidioc_g_std(file
, fh
, id
);
1267 else if (vfd
->current_norm
)
1268 *id
= vfd
->current_norm
;
1273 dbgarg(cmd
, "std=0x%08Lx\n", (long long unsigned)*id
);
1278 v4l2_std_id
*id
= arg
, norm
;
1280 dbgarg(cmd
, "std=%08Lx\n", (long long unsigned)*id
);
1282 norm
= (*id
) & vfd
->tvnorms
;
1283 if (vfd
->tvnorms
&& !norm
) /* Check if std is supported */
1286 /* Calls the specific handler */
1287 if (ops
->vidioc_s_std
)
1288 ret
= ops
->vidioc_s_std(file
, fh
, &norm
);
1292 /* Updates standard information */
1294 vfd
->current_norm
= norm
;
1297 case VIDIOC_QUERYSTD
:
1299 v4l2_std_id
*p
= arg
;
1301 if (!ops
->vidioc_querystd
)
1303 ret
= ops
->vidioc_querystd(file
, fh
, arg
);
1305 dbgarg(cmd
, "detected std=%08Lx\n",
1306 (unsigned long long)*p
);
1309 /* ------ input switching ---------- */
1310 /* FIXME: Inputs can be handled inside videodev2 */
1311 case VIDIOC_ENUMINPUT
:
1313 struct v4l2_input
*p
= arg
;
1316 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1317 * CAP_STD here based on ioctl handler provided by the
1318 * driver. If the driver doesn't support these
1319 * for a specific input, it must override these flags.
1321 if (ops
->vidioc_s_std
)
1322 p
->capabilities
|= V4L2_IN_CAP_STD
;
1323 if (ops
->vidioc_s_dv_preset
)
1324 p
->capabilities
|= V4L2_IN_CAP_PRESETS
;
1325 if (ops
->vidioc_s_dv_timings
)
1326 p
->capabilities
|= V4L2_IN_CAP_CUSTOM_TIMINGS
;
1328 if (!ops
->vidioc_enum_input
)
1331 ret
= ops
->vidioc_enum_input(file
, fh
, p
);
1333 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1335 "tuner=%d, std=%08Lx, status=%d\n",
1336 p
->index
, p
->name
, p
->type
, p
->audioset
,
1338 (unsigned long long)p
->std
,
1342 case VIDIOC_G_INPUT
:
1344 unsigned int *i
= arg
;
1346 if (!ops
->vidioc_g_input
)
1348 ret
= ops
->vidioc_g_input(file
, fh
, i
);
1350 dbgarg(cmd
, "value=%d\n", *i
);
1353 case VIDIOC_S_INPUT
:
1355 unsigned int *i
= arg
;
1357 if (!ops
->vidioc_s_input
)
1359 dbgarg(cmd
, "value=%d\n", *i
);
1360 ret
= ops
->vidioc_s_input(file
, fh
, *i
);
1364 /* ------ output switching ---------- */
1365 case VIDIOC_ENUMOUTPUT
:
1367 struct v4l2_output
*p
= arg
;
1369 if (!ops
->vidioc_enum_output
)
1373 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1374 * CAP_STD here based on ioctl handler provided by the
1375 * driver. If the driver doesn't support these
1376 * for a specific output, it must override these flags.
1378 if (ops
->vidioc_s_std
)
1379 p
->capabilities
|= V4L2_OUT_CAP_STD
;
1380 if (ops
->vidioc_s_dv_preset
)
1381 p
->capabilities
|= V4L2_OUT_CAP_PRESETS
;
1382 if (ops
->vidioc_s_dv_timings
)
1383 p
->capabilities
|= V4L2_OUT_CAP_CUSTOM_TIMINGS
;
1385 ret
= ops
->vidioc_enum_output(file
, fh
, p
);
1387 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1389 "modulator=%d, std=0x%08Lx\n",
1390 p
->index
, p
->name
, p
->type
, p
->audioset
,
1391 p
->modulator
, (unsigned long long)p
->std
);
1394 case VIDIOC_G_OUTPUT
:
1396 unsigned int *i
= arg
;
1398 if (!ops
->vidioc_g_output
)
1400 ret
= ops
->vidioc_g_output(file
, fh
, i
);
1402 dbgarg(cmd
, "value=%d\n", *i
);
1405 case VIDIOC_S_OUTPUT
:
1407 unsigned int *i
= arg
;
1409 if (!ops
->vidioc_s_output
)
1411 dbgarg(cmd
, "value=%d\n", *i
);
1412 ret
= ops
->vidioc_s_output(file
, fh
, *i
);
1416 /* --- controls ---------------------------------------------- */
1417 case VIDIOC_QUERYCTRL
:
1419 struct v4l2_queryctrl
*p
= arg
;
1421 if (vfd
->ctrl_handler
)
1422 ret
= v4l2_queryctrl(vfd
->ctrl_handler
, p
);
1423 else if (ops
->vidioc_queryctrl
)
1424 ret
= ops
->vidioc_queryctrl(file
, fh
, p
);
1428 dbgarg(cmd
, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1429 "step=%d, default=%d, flags=0x%08x\n",
1430 p
->id
, p
->type
, p
->name
,
1431 p
->minimum
, p
->maximum
,
1432 p
->step
, p
->default_value
, p
->flags
);
1434 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1439 struct v4l2_control
*p
= arg
;
1441 if (vfd
->ctrl_handler
)
1442 ret
= v4l2_g_ctrl(vfd
->ctrl_handler
, p
);
1443 else if (ops
->vidioc_g_ctrl
)
1444 ret
= ops
->vidioc_g_ctrl(file
, fh
, p
);
1445 else if (ops
->vidioc_g_ext_ctrls
) {
1446 struct v4l2_ext_controls ctrls
;
1447 struct v4l2_ext_control ctrl
;
1449 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1451 ctrls
.controls
= &ctrl
;
1453 ctrl
.value
= p
->value
;
1454 if (check_ext_ctrls(&ctrls
, 1)) {
1455 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, &ctrls
);
1457 p
->value
= ctrl
.value
;
1462 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1464 dbgarg(cmd
, "id=0x%x\n", p
->id
);
1469 struct v4l2_control
*p
= arg
;
1470 struct v4l2_ext_controls ctrls
;
1471 struct v4l2_ext_control ctrl
;
1473 if (!vfd
->ctrl_handler
&&
1474 !ops
->vidioc_s_ctrl
&& !ops
->vidioc_s_ext_ctrls
)
1477 dbgarg(cmd
, "id=0x%x, value=%d\n", p
->id
, p
->value
);
1479 if (vfd
->ctrl_handler
) {
1480 ret
= v4l2_s_ctrl(vfd
->ctrl_handler
, p
);
1483 if (ops
->vidioc_s_ctrl
) {
1484 ret
= ops
->vidioc_s_ctrl(file
, fh
, p
);
1487 if (!ops
->vidioc_s_ext_ctrls
)
1490 ctrls
.ctrl_class
= V4L2_CTRL_ID2CLASS(p
->id
);
1492 ctrls
.controls
= &ctrl
;
1494 ctrl
.value
= p
->value
;
1495 if (check_ext_ctrls(&ctrls
, 1))
1496 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, &ctrls
);
1499 case VIDIOC_G_EXT_CTRLS
:
1501 struct v4l2_ext_controls
*p
= arg
;
1503 p
->error_idx
= p
->count
;
1504 if (vfd
->ctrl_handler
)
1505 ret
= v4l2_g_ext_ctrls(vfd
->ctrl_handler
, p
);
1506 else if (ops
->vidioc_g_ext_ctrls
&& check_ext_ctrls(p
, 0))
1507 ret
= ops
->vidioc_g_ext_ctrls(file
, fh
, p
);
1510 v4l_print_ext_ctrls(cmd
, vfd
, p
, !ret
);
1513 case VIDIOC_S_EXT_CTRLS
:
1515 struct v4l2_ext_controls
*p
= arg
;
1517 p
->error_idx
= p
->count
;
1518 if (!vfd
->ctrl_handler
&& !ops
->vidioc_s_ext_ctrls
)
1520 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1521 if (vfd
->ctrl_handler
)
1522 ret
= v4l2_s_ext_ctrls(vfd
->ctrl_handler
, p
);
1523 else if (check_ext_ctrls(p
, 0))
1524 ret
= ops
->vidioc_s_ext_ctrls(file
, fh
, p
);
1527 case VIDIOC_TRY_EXT_CTRLS
:
1529 struct v4l2_ext_controls
*p
= arg
;
1531 p
->error_idx
= p
->count
;
1532 if (!vfd
->ctrl_handler
&& !ops
->vidioc_try_ext_ctrls
)
1534 v4l_print_ext_ctrls(cmd
, vfd
, p
, 1);
1535 if (vfd
->ctrl_handler
)
1536 ret
= v4l2_try_ext_ctrls(vfd
->ctrl_handler
, p
);
1537 else if (check_ext_ctrls(p
, 0))
1538 ret
= ops
->vidioc_try_ext_ctrls(file
, fh
, p
);
1541 case VIDIOC_QUERYMENU
:
1543 struct v4l2_querymenu
*p
= arg
;
1545 if (vfd
->ctrl_handler
)
1546 ret
= v4l2_querymenu(vfd
->ctrl_handler
, p
);
1547 else if (ops
->vidioc_querymenu
)
1548 ret
= ops
->vidioc_querymenu(file
, fh
, p
);
1552 dbgarg(cmd
, "id=0x%x, index=%d, name=%s\n",
1553 p
->id
, p
->index
, p
->name
);
1555 dbgarg(cmd
, "id=0x%x, index=%d\n",
1559 /* --- audio ---------------------------------------------- */
1560 case VIDIOC_ENUMAUDIO
:
1562 struct v4l2_audio
*p
= arg
;
1564 if (!ops
->vidioc_enumaudio
)
1566 ret
= ops
->vidioc_enumaudio(file
, fh
, p
);
1568 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1569 "mode=0x%x\n", p
->index
, p
->name
,
1570 p
->capability
, p
->mode
);
1572 dbgarg(cmd
, "index=%d\n", p
->index
);
1575 case VIDIOC_G_AUDIO
:
1577 struct v4l2_audio
*p
= arg
;
1579 if (!ops
->vidioc_g_audio
)
1582 ret
= ops
->vidioc_g_audio(file
, fh
, p
);
1584 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1585 "mode=0x%x\n", p
->index
,
1586 p
->name
, p
->capability
, p
->mode
);
1588 dbgarg(cmd
, "index=%d\n", p
->index
);
1591 case VIDIOC_S_AUDIO
:
1593 struct v4l2_audio
*p
= arg
;
1595 if (!ops
->vidioc_s_audio
)
1597 dbgarg(cmd
, "index=%d, name=%s, capability=0x%x, "
1598 "mode=0x%x\n", p
->index
, p
->name
,
1599 p
->capability
, p
->mode
);
1600 ret
= ops
->vidioc_s_audio(file
, fh
, p
);
1603 case VIDIOC_ENUMAUDOUT
:
1605 struct v4l2_audioout
*p
= arg
;
1607 if (!ops
->vidioc_enumaudout
)
1609 dbgarg(cmd
, "Enum for index=%d\n", p
->index
);
1610 ret
= ops
->vidioc_enumaudout(file
, fh
, p
);
1612 dbgarg2("index=%d, name=%s, capability=%d, "
1613 "mode=%d\n", p
->index
, p
->name
,
1614 p
->capability
, p
->mode
);
1617 case VIDIOC_G_AUDOUT
:
1619 struct v4l2_audioout
*p
= arg
;
1621 if (!ops
->vidioc_g_audout
)
1624 ret
= ops
->vidioc_g_audout(file
, fh
, p
);
1626 dbgarg2("index=%d, name=%s, capability=%d, "
1627 "mode=%d\n", p
->index
, p
->name
,
1628 p
->capability
, p
->mode
);
1631 case VIDIOC_S_AUDOUT
:
1633 struct v4l2_audioout
*p
= arg
;
1635 if (!ops
->vidioc_s_audout
)
1637 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1638 "mode=%d\n", p
->index
, p
->name
,
1639 p
->capability
, p
->mode
);
1641 ret
= ops
->vidioc_s_audout(file
, fh
, p
);
1644 case VIDIOC_G_MODULATOR
:
1646 struct v4l2_modulator
*p
= arg
;
1648 if (!ops
->vidioc_g_modulator
)
1650 ret
= ops
->vidioc_g_modulator(file
, fh
, p
);
1652 dbgarg(cmd
, "index=%d, name=%s, "
1653 "capability=%d, rangelow=%d,"
1654 " rangehigh=%d, txsubchans=%d\n",
1655 p
->index
, p
->name
, p
->capability
,
1656 p
->rangelow
, p
->rangehigh
,
1660 case VIDIOC_S_MODULATOR
:
1662 struct v4l2_modulator
*p
= arg
;
1664 if (!ops
->vidioc_s_modulator
)
1666 dbgarg(cmd
, "index=%d, name=%s, capability=%d, "
1667 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1668 p
->index
, p
->name
, p
->capability
, p
->rangelow
,
1669 p
->rangehigh
, p
->txsubchans
);
1670 ret
= ops
->vidioc_s_modulator(file
, fh
, p
);
1675 struct v4l2_crop
*p
= arg
;
1677 if (!ops
->vidioc_g_crop
)
1680 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1681 ret
= ops
->vidioc_g_crop(file
, fh
, p
);
1683 dbgrect(vfd
, "", &p
->c
);
1688 struct v4l2_crop
*p
= arg
;
1690 if (!ops
->vidioc_s_crop
)
1692 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1693 dbgrect(vfd
, "", &p
->c
);
1694 ret
= ops
->vidioc_s_crop(file
, fh
, p
);
1697 case VIDIOC_CROPCAP
:
1699 struct v4l2_cropcap
*p
= arg
;
1701 /*FIXME: Should also show v4l2_fract pixelaspect */
1702 if (!ops
->vidioc_cropcap
)
1705 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1706 ret
= ops
->vidioc_cropcap(file
, fh
, p
);
1708 dbgrect(vfd
, "bounds ", &p
->bounds
);
1709 dbgrect(vfd
, "defrect ", &p
->defrect
);
1713 case VIDIOC_G_JPEGCOMP
:
1715 struct v4l2_jpegcompression
*p
= arg
;
1717 if (!ops
->vidioc_g_jpegcomp
)
1720 ret
= ops
->vidioc_g_jpegcomp(file
, fh
, p
);
1722 dbgarg(cmd
, "quality=%d, APPn=%d, "
1723 "APP_len=%d, COM_len=%d, "
1724 "jpeg_markers=%d\n",
1725 p
->quality
, p
->APPn
, p
->APP_len
,
1726 p
->COM_len
, p
->jpeg_markers
);
1729 case VIDIOC_S_JPEGCOMP
:
1731 struct v4l2_jpegcompression
*p
= arg
;
1733 if (!ops
->vidioc_g_jpegcomp
)
1735 dbgarg(cmd
, "quality=%d, APPn=%d, APP_len=%d, "
1736 "COM_len=%d, jpeg_markers=%d\n",
1737 p
->quality
, p
->APPn
, p
->APP_len
,
1738 p
->COM_len
, p
->jpeg_markers
);
1739 ret
= ops
->vidioc_s_jpegcomp(file
, fh
, p
);
1742 case VIDIOC_G_ENC_INDEX
:
1744 struct v4l2_enc_idx
*p
= arg
;
1746 if (!ops
->vidioc_g_enc_index
)
1748 ret
= ops
->vidioc_g_enc_index(file
, fh
, p
);
1750 dbgarg(cmd
, "entries=%d, entries_cap=%d\n",
1751 p
->entries
, p
->entries_cap
);
1754 case VIDIOC_ENCODER_CMD
:
1756 struct v4l2_encoder_cmd
*p
= arg
;
1758 if (!ops
->vidioc_encoder_cmd
)
1760 ret
= ops
->vidioc_encoder_cmd(file
, fh
, p
);
1762 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1765 case VIDIOC_TRY_ENCODER_CMD
:
1767 struct v4l2_encoder_cmd
*p
= arg
;
1769 if (!ops
->vidioc_try_encoder_cmd
)
1771 ret
= ops
->vidioc_try_encoder_cmd(file
, fh
, p
);
1773 dbgarg(cmd
, "cmd=%d, flags=%x\n", p
->cmd
, p
->flags
);
1778 struct v4l2_streamparm
*p
= arg
;
1780 if (ops
->vidioc_g_parm
) {
1781 ret
= check_fmt(ops
, p
->type
);
1784 ret
= ops
->vidioc_g_parm(file
, fh
, p
);
1786 v4l2_std_id std
= vfd
->current_norm
;
1788 if (p
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1792 if (ops
->vidioc_g_std
)
1793 ret
= ops
->vidioc_g_std(file
, fh
, &std
);
1797 v4l2_video_std_frame_period(std
,
1798 &p
->parm
.capture
.timeperframe
);
1801 dbgarg(cmd
, "type=%d\n", p
->type
);
1806 struct v4l2_streamparm
*p
= arg
;
1808 if (!ops
->vidioc_s_parm
)
1810 ret
= check_fmt(ops
, p
->type
);
1814 dbgarg(cmd
, "type=%d\n", p
->type
);
1815 ret
= ops
->vidioc_s_parm(file
, fh
, p
);
1818 case VIDIOC_G_TUNER
:
1820 struct v4l2_tuner
*p
= arg
;
1822 if (!ops
->vidioc_g_tuner
)
1825 ret
= ops
->vidioc_g_tuner(file
, fh
, p
);
1827 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1828 "capability=0x%x, rangelow=%d, "
1829 "rangehigh=%d, signal=%d, afc=%d, "
1830 "rxsubchans=0x%x, audmode=%d\n",
1831 p
->index
, p
->name
, p
->type
,
1832 p
->capability
, p
->rangelow
,
1833 p
->rangehigh
, p
->signal
, p
->afc
,
1834 p
->rxsubchans
, p
->audmode
);
1837 case VIDIOC_S_TUNER
:
1839 struct v4l2_tuner
*p
= arg
;
1841 if (!ops
->vidioc_s_tuner
)
1843 dbgarg(cmd
, "index=%d, name=%s, type=%d, "
1844 "capability=0x%x, rangelow=%d, "
1845 "rangehigh=%d, signal=%d, afc=%d, "
1846 "rxsubchans=0x%x, audmode=%d\n",
1847 p
->index
, p
->name
, p
->type
,
1848 p
->capability
, p
->rangelow
,
1849 p
->rangehigh
, p
->signal
, p
->afc
,
1850 p
->rxsubchans
, p
->audmode
);
1851 ret
= ops
->vidioc_s_tuner(file
, fh
, p
);
1854 case VIDIOC_G_FREQUENCY
:
1856 struct v4l2_frequency
*p
= arg
;
1858 if (!ops
->vidioc_g_frequency
)
1861 ret
= ops
->vidioc_g_frequency(file
, fh
, p
);
1863 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1864 p
->tuner
, p
->type
, p
->frequency
);
1867 case VIDIOC_S_FREQUENCY
:
1869 struct v4l2_frequency
*p
= arg
;
1871 if (!ops
->vidioc_s_frequency
)
1873 dbgarg(cmd
, "tuner=%d, type=%d, frequency=%d\n",
1874 p
->tuner
, p
->type
, p
->frequency
);
1875 ret
= ops
->vidioc_s_frequency(file
, fh
, p
);
1878 case VIDIOC_G_SLICED_VBI_CAP
:
1880 struct v4l2_sliced_vbi_cap
*p
= arg
;
1882 if (!ops
->vidioc_g_sliced_vbi_cap
)
1885 /* Clear up to type, everything after type is zerod already */
1886 memset(p
, 0, offsetof(struct v4l2_sliced_vbi_cap
, type
));
1888 dbgarg(cmd
, "type=%s\n", prt_names(p
->type
, v4l2_type_names
));
1889 ret
= ops
->vidioc_g_sliced_vbi_cap(file
, fh
, p
);
1891 dbgarg2("service_set=%d\n", p
->service_set
);
1894 case VIDIOC_LOG_STATUS
:
1896 if (!ops
->vidioc_log_status
)
1898 ret
= ops
->vidioc_log_status(file
, fh
);
1901 #ifdef CONFIG_VIDEO_ADV_DEBUG
1902 case VIDIOC_DBG_G_REGISTER
:
1904 struct v4l2_dbg_register
*p
= arg
;
1906 if (ops
->vidioc_g_register
) {
1907 if (!capable(CAP_SYS_ADMIN
))
1910 ret
= ops
->vidioc_g_register(file
, fh
, p
);
1914 case VIDIOC_DBG_S_REGISTER
:
1916 struct v4l2_dbg_register
*p
= arg
;
1918 if (ops
->vidioc_s_register
) {
1919 if (!capable(CAP_SYS_ADMIN
))
1922 ret
= ops
->vidioc_s_register(file
, fh
, p
);
1927 case VIDIOC_DBG_G_CHIP_IDENT
:
1929 struct v4l2_dbg_chip_ident
*p
= arg
;
1931 if (!ops
->vidioc_g_chip_ident
)
1933 p
->ident
= V4L2_IDENT_NONE
;
1935 ret
= ops
->vidioc_g_chip_ident(file
, fh
, p
);
1937 dbgarg(cmd
, "chip_ident=%u, revision=0x%x\n", p
->ident
, p
->revision
);
1940 case VIDIOC_S_HW_FREQ_SEEK
:
1942 struct v4l2_hw_freq_seek
*p
= arg
;
1944 if (!ops
->vidioc_s_hw_freq_seek
)
1947 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1948 p
->tuner
, p
->type
, p
->seek_upward
, p
->wrap_around
);
1949 ret
= ops
->vidioc_s_hw_freq_seek(file
, fh
, p
);
1952 case VIDIOC_ENUM_FRAMESIZES
:
1954 struct v4l2_frmsizeenum
*p
= arg
;
1956 if (!ops
->vidioc_enum_framesizes
)
1959 ret
= ops
->vidioc_enum_framesizes(file
, fh
, p
);
1961 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1963 (p
->pixel_format
& 0xff),
1964 (p
->pixel_format
>> 8) & 0xff,
1965 (p
->pixel_format
>> 16) & 0xff,
1966 (p
->pixel_format
>> 24) & 0xff,
1969 case V4L2_FRMSIZE_TYPE_DISCRETE
:
1970 dbgarg3("width = %d, height=%d\n",
1971 p
->discrete
.width
, p
->discrete
.height
);
1973 case V4L2_FRMSIZE_TYPE_STEPWISE
:
1974 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1975 p
->stepwise
.min_width
, p
->stepwise
.min_height
,
1976 p
->stepwise
.step_width
, p
->stepwise
.step_height
,
1977 p
->stepwise
.max_width
, p
->stepwise
.max_height
);
1979 case V4L2_FRMSIZE_TYPE_CONTINUOUS
:
1980 dbgarg3("continuous\n");
1983 dbgarg3("- Unknown type!\n");
1988 case VIDIOC_ENUM_FRAMEINTERVALS
:
1990 struct v4l2_frmivalenum
*p
= arg
;
1992 if (!ops
->vidioc_enum_frameintervals
)
1995 ret
= ops
->vidioc_enum_frameintervals(file
, fh
, p
);
1997 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1998 p
->index
, p
->pixel_format
,
1999 p
->width
, p
->height
, p
->type
);
2001 case V4L2_FRMIVAL_TYPE_DISCRETE
:
2002 dbgarg2("fps=%d/%d\n",
2003 p
->discrete
.numerator
,
2004 p
->discrete
.denominator
);
2006 case V4L2_FRMIVAL_TYPE_STEPWISE
:
2007 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
2008 p
->stepwise
.min
.numerator
,
2009 p
->stepwise
.min
.denominator
,
2010 p
->stepwise
.max
.numerator
,
2011 p
->stepwise
.max
.denominator
,
2012 p
->stepwise
.step
.numerator
,
2013 p
->stepwise
.step
.denominator
);
2015 case V4L2_FRMIVAL_TYPE_CONTINUOUS
:
2016 dbgarg2("continuous\n");
2019 dbgarg2("- Unknown type!\n");
2023 case VIDIOC_ENUM_DV_PRESETS
:
2025 struct v4l2_dv_enum_preset
*p
= arg
;
2027 if (!ops
->vidioc_enum_dv_presets
)
2030 ret
= ops
->vidioc_enum_dv_presets(file
, fh
, p
);
2033 "index=%d, preset=%d, name=%s, width=%d,"
2035 p
->index
, p
->preset
, p
->name
, p
->width
,
2039 case VIDIOC_S_DV_PRESET
:
2041 struct v4l2_dv_preset
*p
= arg
;
2043 if (!ops
->vidioc_s_dv_preset
)
2046 dbgarg(cmd
, "preset=%d\n", p
->preset
);
2047 ret
= ops
->vidioc_s_dv_preset(file
, fh
, p
);
2050 case VIDIOC_G_DV_PRESET
:
2052 struct v4l2_dv_preset
*p
= arg
;
2054 if (!ops
->vidioc_g_dv_preset
)
2057 ret
= ops
->vidioc_g_dv_preset(file
, fh
, p
);
2059 dbgarg(cmd
, "preset=%d\n", p
->preset
);
2062 case VIDIOC_QUERY_DV_PRESET
:
2064 struct v4l2_dv_preset
*p
= arg
;
2066 if (!ops
->vidioc_query_dv_preset
)
2069 ret
= ops
->vidioc_query_dv_preset(file
, fh
, p
);
2071 dbgarg(cmd
, "preset=%d\n", p
->preset
);
2074 case VIDIOC_S_DV_TIMINGS
:
2076 struct v4l2_dv_timings
*p
= arg
;
2078 if (!ops
->vidioc_s_dv_timings
)
2082 case V4L2_DV_BT_656_1120
:
2083 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2084 " width=%d, height=%d, polarities=%x,"
2085 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
2086 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
2087 " il_vfrontporch=%d, il_vsync=%d,"
2088 " il_vbackporch=%d\n",
2089 p
->bt
.interlaced
, p
->bt
.pixelclock
,
2090 p
->bt
.width
, p
->bt
.height
, p
->bt
.polarities
,
2091 p
->bt
.hfrontporch
, p
->bt
.hsync
,
2092 p
->bt
.hbackporch
, p
->bt
.vfrontporch
,
2093 p
->bt
.vsync
, p
->bt
.vbackporch
,
2094 p
->bt
.il_vfrontporch
, p
->bt
.il_vsync
,
2095 p
->bt
.il_vbackporch
);
2096 ret
= ops
->vidioc_s_dv_timings(file
, fh
, p
);
2099 dbgarg2("Unknown type %d!\n", p
->type
);
2104 case VIDIOC_G_DV_TIMINGS
:
2106 struct v4l2_dv_timings
*p
= arg
;
2108 if (!ops
->vidioc_g_dv_timings
)
2111 ret
= ops
->vidioc_g_dv_timings(file
, fh
, p
);
2114 case V4L2_DV_BT_656_1120
:
2115 dbgarg2("bt-656/1120:interlaced=%d,"
2117 " width=%d, height=%d, polarities=%x,"
2118 " hfrontporch=%d, hsync=%d,"
2119 " hbackporch=%d, vfrontporch=%d,"
2120 " vsync=%d, vbackporch=%d,"
2121 " il_vfrontporch=%d, il_vsync=%d,"
2122 " il_vbackporch=%d\n",
2123 p
->bt
.interlaced
, p
->bt
.pixelclock
,
2124 p
->bt
.width
, p
->bt
.height
,
2125 p
->bt
.polarities
, p
->bt
.hfrontporch
,
2126 p
->bt
.hsync
, p
->bt
.hbackporch
,
2127 p
->bt
.vfrontporch
, p
->bt
.vsync
,
2128 p
->bt
.vbackporch
, p
->bt
.il_vfrontporch
,
2129 p
->bt
.il_vsync
, p
->bt
.il_vbackporch
);
2132 dbgarg2("Unknown type %d!\n", p
->type
);
2138 case VIDIOC_DQEVENT
:
2140 struct v4l2_event
*ev
= arg
;
2142 if (!ops
->vidioc_subscribe_event
)
2145 ret
= v4l2_event_dequeue(fh
, ev
, file
->f_flags
& O_NONBLOCK
);
2147 dbgarg(cmd
, "no pending events?");
2151 "pending=%d, type=0x%8.8x, sequence=%d, "
2152 "timestamp=%lu.%9.9lu ",
2153 ev
->pending
, ev
->type
, ev
->sequence
,
2154 ev
->timestamp
.tv_sec
, ev
->timestamp
.tv_nsec
);
2157 case VIDIOC_SUBSCRIBE_EVENT
:
2159 struct v4l2_event_subscription
*sub
= arg
;
2161 if (!ops
->vidioc_subscribe_event
)
2164 ret
= ops
->vidioc_subscribe_event(fh
, sub
);
2166 dbgarg(cmd
, "failed, ret=%ld", ret
);
2169 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
2172 case VIDIOC_UNSUBSCRIBE_EVENT
:
2174 struct v4l2_event_subscription
*sub
= arg
;
2176 if (!ops
->vidioc_unsubscribe_event
)
2179 ret
= ops
->vidioc_unsubscribe_event(fh
, sub
);
2181 dbgarg(cmd
, "failed, ret=%ld", ret
);
2184 dbgarg(cmd
, "type=0x%8.8x", sub
->type
);
2189 bool valid_prio
= true;
2191 if (!ops
->vidioc_default
)
2194 valid_prio
= v4l2_prio_check(vfd
->prio
, vfh
->prio
) >= 0;
2195 ret
= ops
->vidioc_default(file
, fh
, valid_prio
, cmd
, arg
);
2201 if (vfd
->debug
& V4L2_DEBUG_IOCTL_ARG
) {
2203 v4l_print_ioctl(vfd
->name
, cmd
);
2204 printk(KERN_CONT
" error %ld\n", ret
);
2211 /* In some cases, only a few fields are used as input, i.e. when the app sets
2212 * "index" and then the driver fills in the rest of the structure for the thing
2213 * with that index. We only need to copy up the first non-input field. */
2214 static unsigned long cmd_input_size(unsigned int cmd
)
2216 /* Size of structure up to and including 'field' */
2217 #define CMDINSIZE(cmd, type, field) \
2218 case VIDIOC_##cmd: \
2219 return offsetof(struct v4l2_##type, field) + \
2220 sizeof(((struct v4l2_##type *)0)->field);
2223 CMDINSIZE(ENUM_FMT
, fmtdesc
, type
);
2224 CMDINSIZE(G_FMT
, format
, type
);
2225 CMDINSIZE(QUERYBUF
, buffer
, length
);
2226 CMDINSIZE(G_PARM
, streamparm
, type
);
2227 CMDINSIZE(ENUMSTD
, standard
, index
);
2228 CMDINSIZE(ENUMINPUT
, input
, index
);
2229 CMDINSIZE(G_CTRL
, control
, id
);
2230 CMDINSIZE(G_TUNER
, tuner
, index
);
2231 CMDINSIZE(QUERYCTRL
, queryctrl
, id
);
2232 CMDINSIZE(QUERYMENU
, querymenu
, index
);
2233 CMDINSIZE(ENUMOUTPUT
, output
, index
);
2234 CMDINSIZE(G_MODULATOR
, modulator
, index
);
2235 CMDINSIZE(G_FREQUENCY
, frequency
, tuner
);
2236 CMDINSIZE(CROPCAP
, cropcap
, type
);
2237 CMDINSIZE(G_CROP
, crop
, type
);
2238 CMDINSIZE(ENUMAUDIO
, audio
, index
);
2239 CMDINSIZE(ENUMAUDOUT
, audioout
, index
);
2240 CMDINSIZE(ENCODER_CMD
, encoder_cmd
, flags
);
2241 CMDINSIZE(TRY_ENCODER_CMD
, encoder_cmd
, flags
);
2242 CMDINSIZE(G_SLICED_VBI_CAP
, sliced_vbi_cap
, type
);
2243 CMDINSIZE(ENUM_FRAMESIZES
, frmsizeenum
, pixel_format
);
2244 CMDINSIZE(ENUM_FRAMEINTERVALS
, frmivalenum
, height
);
2246 return _IOC_SIZE(cmd
);
2250 static int check_array_args(unsigned int cmd
, void *parg
, size_t *array_size
,
2251 void * __user
*user_ptr
, void ***kernel_ptr
)
2256 case VIDIOC_QUERYBUF
:
2258 case VIDIOC_DQBUF
: {
2259 struct v4l2_buffer
*buf
= parg
;
2261 if (V4L2_TYPE_IS_MULTIPLANAR(buf
->type
) && buf
->length
> 0) {
2262 if (buf
->length
> VIDEO_MAX_PLANES
) {
2266 *user_ptr
= (void __user
*)buf
->m
.planes
;
2267 *kernel_ptr
= (void **)&buf
->m
.planes
;
2268 *array_size
= sizeof(struct v4l2_plane
) * buf
->length
;
2274 case VIDIOC_S_EXT_CTRLS
:
2275 case VIDIOC_G_EXT_CTRLS
:
2276 case VIDIOC_TRY_EXT_CTRLS
: {
2277 struct v4l2_ext_controls
*ctrls
= parg
;
2279 if (ctrls
->count
!= 0) {
2280 *user_ptr
= (void __user
*)ctrls
->controls
;
2281 *kernel_ptr
= (void **)&ctrls
->controls
;
2282 *array_size
= sizeof(struct v4l2_ext_control
)
2294 video_usercopy(struct file
*file
, unsigned int cmd
, unsigned long arg
,
2299 void *parg
= (void *)arg
;
2301 bool has_array_args
;
2302 size_t array_size
= 0;
2303 void __user
*user_ptr
= NULL
;
2304 void **kernel_ptr
= NULL
;
2306 /* Copy arguments into temp kernel buffer */
2307 if (_IOC_DIR(cmd
) != _IOC_NONE
) {
2308 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
2311 /* too big to allocate from stack */
2312 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
2319 if (_IOC_DIR(cmd
) & _IOC_WRITE
) {
2320 unsigned long n
= cmd_input_size(cmd
);
2322 if (copy_from_user(parg
, (void __user
*)arg
, n
))
2325 /* zero out anything we don't copy from userspace */
2326 if (n
< _IOC_SIZE(cmd
))
2327 memset((u8
*)parg
+ n
, 0, _IOC_SIZE(cmd
) - n
);
2329 /* read-only ioctl */
2330 memset(parg
, 0, _IOC_SIZE(cmd
));
2334 err
= check_array_args(cmd
, parg
, &array_size
, &user_ptr
, &kernel_ptr
);
2337 has_array_args
= err
;
2339 if (has_array_args
) {
2341 * When adding new types of array args, make sure that the
2342 * parent argument to ioctl (which contains the pointer to the
2343 * array) fits into sbuf (so that mbuf will still remain
2344 * unused up to here).
2346 mbuf
= kmalloc(array_size
, GFP_KERNEL
);
2349 goto out_array_args
;
2351 if (copy_from_user(mbuf
, user_ptr
, array_size
))
2352 goto out_array_args
;
2357 err
= func(file
, cmd
, parg
);
2358 if (err
== -ENOIOCTLCMD
)
2361 if (has_array_args
) {
2362 *kernel_ptr
= user_ptr
;
2363 if (copy_to_user(user_ptr
, mbuf
, array_size
))
2365 goto out_array_args
;
2371 /* Copy results into user buffer */
2372 switch (_IOC_DIR(cmd
)) {
2374 case (_IOC_WRITE
| _IOC_READ
):
2375 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
2384 EXPORT_SYMBOL(video_usercopy
);
2386 long video_ioctl2(struct file
*file
,
2387 unsigned int cmd
, unsigned long arg
)
2389 return video_usercopy(file
, cmd
, arg
, __video_do_ioctl
);
2391 EXPORT_SYMBOL(video_ioctl2
);