blob: ef44b084132ada012184994267cab07341a6eadc [file] [log] [blame]
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001/*
2 * Video capture interface for Linux version 2
3 *
4 * A generic framework to process V4L2 ioctl commands.
5 *
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.
10 *
Alan Coxd9b01442008-10-27 15:13:47 -030011 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
Hans Verkuil35ea11f2008-07-20 08:12:02 -030012 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
13 */
14
15#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030017#include <linux/types.h>
18#include <linux/kernel.h>
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -030019#include <linux/version.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030020
Hans Verkuil35ea11f2008-07-20 08:12:02 -030021#include <linux/videodev2.h>
22
Hans Verkuil35ea11f2008-07-20 08:12:02 -030023#include <media/v4l2-common.h>
24#include <media/v4l2-ioctl.h>
Hans Verkuil11bbc1c2010-05-16 09:24:06 -030025#include <media/v4l2-ctrls.h>
Sakari Ailusd3d7c962010-03-27 11:02:10 -030026#include <media/v4l2-fh.h>
27#include <media/v4l2-event.h>
Hans Verkuil99cd47bc2011-03-11 19:00:56 -030028#include <media/v4l2-device.h>
Hans Verkuil80b36e02009-02-07 11:00:02 -030029#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030030
31#define dbgarg(cmd, fmt, arg...) \
32 do { \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
37 } \
38 } while (0)
39
40#define dbgarg2(fmt, arg...) \
41 do { \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
44 } while (0)
45
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030046#define dbgarg3(fmt, arg...) \
47 do { \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
50 } while (0)
51
Lucas De Marchi25985ed2011-03-30 22:57:33 -030052/* Zero out the end of the struct pointed to by p. Everything after, but
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030053 * not including, the specified field is cleared. */
54#define CLEAR_AFTER_FIELD(p, field) \
55 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
57
Hans Verkuil93d5a302011-08-09 09:32:06 -030058#define have_fmt_ops(foo) ( \
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -030059 ops->vidioc_##foo##_fmt_vid_cap || \
60 ops->vidioc_##foo##_fmt_vid_out || \
61 ops->vidioc_##foo##_fmt_vid_cap_mplane || \
62 ops->vidioc_##foo##_fmt_vid_out_mplane || \
63 ops->vidioc_##foo##_fmt_vid_overlay || \
Hans Verkuil93d5a302011-08-09 09:32:06 -030064 ops->vidioc_##foo##_fmt_vbi_cap || \
65 ops->vidioc_##foo##_fmt_vid_out_overlay || \
66 ops->vidioc_##foo##_fmt_vbi_out || \
67 ops->vidioc_##foo##_fmt_sliced_vbi_cap || \
68 ops->vidioc_##foo##_fmt_sliced_vbi_out || \
69 ops->vidioc_##foo##_fmt_type_private)
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -030070
Hans Verkuil35ea11f2008-07-20 08:12:02 -030071struct std_descr {
72 v4l2_std_id std;
73 const char *descr;
74};
75
76static const struct std_descr standards[] = {
77 { V4L2_STD_NTSC, "NTSC" },
78 { V4L2_STD_NTSC_M, "NTSC-M" },
79 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
80 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
81 { V4L2_STD_NTSC_443, "NTSC-443" },
82 { V4L2_STD_PAL, "PAL" },
83 { V4L2_STD_PAL_BG, "PAL-BG" },
84 { V4L2_STD_PAL_B, "PAL-B" },
85 { V4L2_STD_PAL_B1, "PAL-B1" },
86 { V4L2_STD_PAL_G, "PAL-G" },
87 { V4L2_STD_PAL_H, "PAL-H" },
88 { V4L2_STD_PAL_I, "PAL-I" },
89 { V4L2_STD_PAL_DK, "PAL-DK" },
90 { V4L2_STD_PAL_D, "PAL-D" },
91 { V4L2_STD_PAL_D1, "PAL-D1" },
92 { V4L2_STD_PAL_K, "PAL-K" },
93 { V4L2_STD_PAL_M, "PAL-M" },
94 { V4L2_STD_PAL_N, "PAL-N" },
95 { V4L2_STD_PAL_Nc, "PAL-Nc" },
96 { V4L2_STD_PAL_60, "PAL-60" },
97 { V4L2_STD_SECAM, "SECAM" },
98 { V4L2_STD_SECAM_B, "SECAM-B" },
99 { V4L2_STD_SECAM_G, "SECAM-G" },
100 { V4L2_STD_SECAM_H, "SECAM-H" },
101 { V4L2_STD_SECAM_DK, "SECAM-DK" },
102 { V4L2_STD_SECAM_D, "SECAM-D" },
103 { V4L2_STD_SECAM_K, "SECAM-K" },
104 { V4L2_STD_SECAM_K1, "SECAM-K1" },
105 { V4L2_STD_SECAM_L, "SECAM-L" },
106 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
107 { 0, "Unknown" }
108};
109
110/* video4linux standard ID conversion to standard name
111 */
112const char *v4l2_norm_to_name(v4l2_std_id id)
113{
114 u32 myid = id;
115 int i;
116
117 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
118 64 bit comparations. So, on that architecture, with some gcc
119 variants, compilation fails. Currently, the max value is 30bit wide.
120 */
121 BUG_ON(myid != id);
122
123 for (i = 0; standards[i].std; i++)
124 if (myid == standards[i].std)
125 break;
126 return standards[i].descr;
127}
128EXPORT_SYMBOL(v4l2_norm_to_name);
129
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300130/* Returns frame period for the given standard */
131void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
132{
133 if (id & V4L2_STD_525_60) {
134 frameperiod->numerator = 1001;
135 frameperiod->denominator = 30000;
136 } else {
137 frameperiod->numerator = 1;
138 frameperiod->denominator = 25;
139 }
140}
141EXPORT_SYMBOL(v4l2_video_std_frame_period);
142
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300143/* Fill in the fields of a v4l2_standard structure according to the
144 'id' and 'transmission' parameters. Returns negative on error. */
145int v4l2_video_std_construct(struct v4l2_standard *vs,
146 int id, const char *name)
147{
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300148 vs->id = id;
149 v4l2_video_std_frame_period(id, &vs->frameperiod);
150 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300151 strlcpy(vs->name, name, sizeof(vs->name));
152 return 0;
153}
154EXPORT_SYMBOL(v4l2_video_std_construct);
155
156/* ----------------------------------------------------------------- */
157/* some arrays for pretty-printing debug messages of enum types */
158
159const char *v4l2_field_names[] = {
160 [V4L2_FIELD_ANY] = "any",
161 [V4L2_FIELD_NONE] = "none",
162 [V4L2_FIELD_TOP] = "top",
163 [V4L2_FIELD_BOTTOM] = "bottom",
164 [V4L2_FIELD_INTERLACED] = "interlaced",
165 [V4L2_FIELD_SEQ_TB] = "seq-tb",
166 [V4L2_FIELD_SEQ_BT] = "seq-bt",
167 [V4L2_FIELD_ALTERNATE] = "alternate",
168 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
169 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
170};
171EXPORT_SYMBOL(v4l2_field_names);
172
173const char *v4l2_type_names[] = {
174 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
175 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
176 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
177 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
178 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
179 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
180 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
181 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
Pawel Osciakf8f39142010-07-29 14:44:25 -0300182 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
183 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300184};
185EXPORT_SYMBOL(v4l2_type_names);
186
187static const char *v4l2_memory_names[] = {
188 [V4L2_MEMORY_MMAP] = "mmap",
189 [V4L2_MEMORY_USERPTR] = "userptr",
190 [V4L2_MEMORY_OVERLAY] = "overlay",
191};
192
193#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
194 arr[a] : "unknown")
195
196/* ------------------------------------------------------------------ */
197/* debug help functions */
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300198
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300199struct v4l2_ioctl_info {
200 unsigned int ioctl;
201 const char * const name;
202};
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300203
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300204#define IOCTL_INFO(_ioctl) [_IOC_NR(_ioctl)] = { \
205 .ioctl = _ioctl, \
206 .name = #_ioctl, \
207}
208
209static struct v4l2_ioctl_info v4l2_ioctls[] = {
210 IOCTL_INFO(VIDIOC_QUERYCAP),
211 IOCTL_INFO(VIDIOC_ENUM_FMT),
212 IOCTL_INFO(VIDIOC_G_FMT),
213 IOCTL_INFO(VIDIOC_S_FMT),
214 IOCTL_INFO(VIDIOC_REQBUFS),
215 IOCTL_INFO(VIDIOC_QUERYBUF),
216 IOCTL_INFO(VIDIOC_G_FBUF),
217 IOCTL_INFO(VIDIOC_S_FBUF),
218 IOCTL_INFO(VIDIOC_OVERLAY),
219 IOCTL_INFO(VIDIOC_QBUF),
220 IOCTL_INFO(VIDIOC_DQBUF),
221 IOCTL_INFO(VIDIOC_STREAMON),
222 IOCTL_INFO(VIDIOC_STREAMOFF),
223 IOCTL_INFO(VIDIOC_G_PARM),
224 IOCTL_INFO(VIDIOC_S_PARM),
225 IOCTL_INFO(VIDIOC_G_STD),
226 IOCTL_INFO(VIDIOC_S_STD),
227 IOCTL_INFO(VIDIOC_ENUMSTD),
228 IOCTL_INFO(VIDIOC_ENUMINPUT),
229 IOCTL_INFO(VIDIOC_G_CTRL),
230 IOCTL_INFO(VIDIOC_S_CTRL),
231 IOCTL_INFO(VIDIOC_G_TUNER),
232 IOCTL_INFO(VIDIOC_S_TUNER),
233 IOCTL_INFO(VIDIOC_G_AUDIO),
234 IOCTL_INFO(VIDIOC_S_AUDIO),
235 IOCTL_INFO(VIDIOC_QUERYCTRL),
236 IOCTL_INFO(VIDIOC_QUERYMENU),
237 IOCTL_INFO(VIDIOC_G_INPUT),
238 IOCTL_INFO(VIDIOC_S_INPUT),
239 IOCTL_INFO(VIDIOC_G_OUTPUT),
240 IOCTL_INFO(VIDIOC_S_OUTPUT),
241 IOCTL_INFO(VIDIOC_ENUMOUTPUT),
242 IOCTL_INFO(VIDIOC_G_AUDOUT),
243 IOCTL_INFO(VIDIOC_S_AUDOUT),
244 IOCTL_INFO(VIDIOC_G_MODULATOR),
245 IOCTL_INFO(VIDIOC_S_MODULATOR),
246 IOCTL_INFO(VIDIOC_G_FREQUENCY),
247 IOCTL_INFO(VIDIOC_S_FREQUENCY),
248 IOCTL_INFO(VIDIOC_CROPCAP),
249 IOCTL_INFO(VIDIOC_G_CROP),
250 IOCTL_INFO(VIDIOC_S_CROP),
251 IOCTL_INFO(VIDIOC_G_SELECTION),
252 IOCTL_INFO(VIDIOC_S_SELECTION),
253 IOCTL_INFO(VIDIOC_G_JPEGCOMP),
254 IOCTL_INFO(VIDIOC_S_JPEGCOMP),
255 IOCTL_INFO(VIDIOC_QUERYSTD),
256 IOCTL_INFO(VIDIOC_TRY_FMT),
257 IOCTL_INFO(VIDIOC_ENUMAUDIO),
258 IOCTL_INFO(VIDIOC_ENUMAUDOUT),
259 IOCTL_INFO(VIDIOC_G_PRIORITY),
260 IOCTL_INFO(VIDIOC_S_PRIORITY),
261 IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP),
262 IOCTL_INFO(VIDIOC_LOG_STATUS),
263 IOCTL_INFO(VIDIOC_G_EXT_CTRLS),
264 IOCTL_INFO(VIDIOC_S_EXT_CTRLS),
265 IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS),
266 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES),
267 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS),
268 IOCTL_INFO(VIDIOC_G_ENC_INDEX),
269 IOCTL_INFO(VIDIOC_ENCODER_CMD),
270 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD),
271 IOCTL_INFO(VIDIOC_DECODER_CMD),
272 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD),
273 IOCTL_INFO(VIDIOC_DBG_S_REGISTER),
274 IOCTL_INFO(VIDIOC_DBG_G_REGISTER),
275 IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT),
276 IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK),
277 IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS),
278 IOCTL_INFO(VIDIOC_S_DV_PRESET),
279 IOCTL_INFO(VIDIOC_G_DV_PRESET),
280 IOCTL_INFO(VIDIOC_QUERY_DV_PRESET),
281 IOCTL_INFO(VIDIOC_S_DV_TIMINGS),
282 IOCTL_INFO(VIDIOC_G_DV_TIMINGS),
283 IOCTL_INFO(VIDIOC_DQEVENT),
284 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT),
285 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT),
286 IOCTL_INFO(VIDIOC_CREATE_BUFS),
287 IOCTL_INFO(VIDIOC_PREPARE_BUF),
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300288};
289#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
290
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300291bool v4l2_is_known_ioctl(unsigned int cmd)
292{
293 if (_IOC_NR(cmd) >= V4L2_IOCTLS)
294 return false;
295 return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
296}
297
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300298/* Common ioctl debug function. This function can be used by
299 external ioctl messages as well as internal V4L ioctl */
300void v4l_printk_ioctl(unsigned int cmd)
301{
302 char *dir, *type;
303
304 switch (_IOC_TYPE(cmd)) {
305 case 'd':
Hans Verkuil78a3b4d2009-04-01 03:41:09 -0300306 type = "v4l2_int";
307 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300308 case 'V':
309 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
310 type = "v4l2";
311 break;
312 }
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300313 printk("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300314 return;
315 default:
316 type = "unknown";
317 }
318
319 switch (_IOC_DIR(cmd)) {
320 case _IOC_NONE: dir = "--"; break;
321 case _IOC_READ: dir = "r-"; break;
322 case _IOC_WRITE: dir = "-w"; break;
323 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
324 default: dir = "*ERR*"; break;
325 }
326 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
327 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
328}
329EXPORT_SYMBOL(v4l_printk_ioctl);
330
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300331static void dbgbuf(unsigned int cmd, struct video_device *vfd,
332 struct v4l2_buffer *p)
333{
334 struct v4l2_timecode *tc = &p->timecode;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300335 struct v4l2_plane *plane;
336 int i;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300337
338 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300339 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300340 p->timestamp.tv_sec / 3600,
341 (int)(p->timestamp.tv_sec / 60) % 60,
342 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300343 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300344 p->index,
345 prt_names(p->type, v4l2_type_names),
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300346 p->flags, p->field, p->sequence,
347 prt_names(p->memory, v4l2_memory_names));
348
349 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
350 for (i = 0; i < p->length; ++i) {
351 plane = &p->m.planes[i];
352 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
353 "offset/userptr=0x%08lx, length=%d\n",
354 i, plane->bytesused, plane->data_offset,
355 plane->m.userptr, plane->length);
356 }
357 } else {
358 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
359 p->bytesused, p->m.userptr, p->length);
360 }
361
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300362 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
363 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
364 tc->hours, tc->minutes, tc->seconds,
365 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
366}
367
368static inline void dbgrect(struct video_device *vfd, char *s,
369 struct v4l2_rect *r)
370{
371 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
372 r->width, r->height);
373};
374
375static inline void v4l_print_pix_fmt(struct video_device *vfd,
376 struct v4l2_pix_format *fmt)
377{
378 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
379 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
380 fmt->width, fmt->height,
381 (fmt->pixelformat & 0xff),
382 (fmt->pixelformat >> 8) & 0xff,
383 (fmt->pixelformat >> 16) & 0xff,
384 (fmt->pixelformat >> 24) & 0xff,
385 prt_names(fmt->field, v4l2_field_names),
386 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
387};
388
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300389static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
390 struct v4l2_pix_format_mplane *fmt)
391{
392 int i;
393
394 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
395 "colorspace=%d, num_planes=%d\n",
396 fmt->width, fmt->height,
397 (fmt->pixelformat & 0xff),
398 (fmt->pixelformat >> 8) & 0xff,
399 (fmt->pixelformat >> 16) & 0xff,
400 (fmt->pixelformat >> 24) & 0xff,
401 prt_names(fmt->field, v4l2_field_names),
402 fmt->colorspace, fmt->num_planes);
403
404 for (i = 0; i < fmt->num_planes; ++i)
405 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
406 fmt->plane_fmt[i].bytesperline,
407 fmt->plane_fmt[i].sizeimage);
408}
409
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300410static inline void v4l_print_ext_ctrls(unsigned int cmd,
411 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
412{
413 __u32 i;
414
415 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
416 return;
417 dbgarg(cmd, "");
418 printk(KERN_CONT "class=0x%x", c->ctrl_class);
419 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300420 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300421 printk(KERN_CONT " id/val=0x%x/0x%x",
422 c->controls[i].id, c->controls[i].value);
423 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300424 printk(KERN_CONT " id=0x%x,size=%u",
425 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300426 }
427 printk(KERN_CONT "\n");
428};
429
430static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
431{
432 __u32 i;
433
434 /* zero the reserved fields */
435 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300436 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300437 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300438
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300439 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
440 when using extended controls.
441 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
442 is it allowed for backwards compatibility.
443 */
444 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
445 return 0;
446 /* Check that all controls are from the same control class. */
447 for (i = 0; i < c->count; i++) {
448 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
449 c->error_idx = i;
450 return 0;
451 }
452 }
453 return 1;
454}
455
Hans Verkuila3998102008-07-21 02:57:38 -0300456static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300457{
Hans Verkuila3998102008-07-21 02:57:38 -0300458 if (ops == NULL)
459 return -EINVAL;
460
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300461 switch (type) {
462 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300463 if (ops->vidioc_g_fmt_vid_cap ||
464 ops->vidioc_g_fmt_vid_cap_mplane)
465 return 0;
466 break;
467 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
468 if (ops->vidioc_g_fmt_vid_cap_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300469 return 0;
470 break;
471 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300472 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300473 return 0;
474 break;
475 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300476 if (ops->vidioc_g_fmt_vid_out ||
477 ops->vidioc_g_fmt_vid_out_mplane)
478 return 0;
479 break;
480 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
481 if (ops->vidioc_g_fmt_vid_out_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300482 return 0;
483 break;
484 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300485 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300486 return 0;
487 break;
488 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300489 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300490 return 0;
491 break;
492 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300493 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300494 return 0;
495 break;
496 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300497 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300498 return 0;
499 break;
500 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300501 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300502 return 0;
503 break;
504 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300505 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300506 return 0;
507 break;
508 }
509 return -EINVAL;
510}
511
Hans Verkuil069b7472008-12-30 07:04:34 -0300512static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300513 unsigned int cmd, void *arg)
514{
515 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300516 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300517 void *fh = file->private_data;
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300518 struct v4l2_fh *vfh = NULL;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300519 int use_fh_prio = 0;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300520 long ret_prio = 0;
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300521 long ret = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300522
Hans Verkuil6a717882010-04-06 15:56:08 -0300523 if (ops == NULL) {
524 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
525 vfd->name);
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300526 return ret;
Hans Verkuil6a717882010-04-06 15:56:08 -0300527 }
528
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300529 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
530 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
531 v4l_print_ioctl(vfd->name, cmd);
532 printk(KERN_CONT "\n");
533 }
534
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300535 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300536 vfh = file->private_data;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300537 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
538 }
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300539
Hans Verkuil93d5a302011-08-09 09:32:06 -0300540 if (use_fh_prio)
541 ret_prio = v4l2_prio_check(vfd->prio, vfh->prio);
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300542
Hans Verkuil6a717882010-04-06 15:56:08 -0300543 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300544
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300545 /* --- capabilities ------------------------------------------ */
546 case VIDIOC_QUERYCAP:
547 {
548 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300549
Hans Verkuila3998102008-07-21 02:57:38 -0300550 if (!ops->vidioc_querycap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300551 break;
552
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -0300553 cap->version = LINUX_VERSION_CODE;
Hans Verkuila3998102008-07-21 02:57:38 -0300554 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300555 if (!ret)
556 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
557 "version=0x%08x, "
Hans Verkuil583aa3a2012-01-11 06:45:05 -0300558 "capabilities=0x%08x, "
559 "device_caps=0x%08x\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300560 cap->driver, cap->card, cap->bus_info,
561 cap->version,
Hans Verkuil583aa3a2012-01-11 06:45:05 -0300562 cap->capabilities,
563 cap->device_caps);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300564 break;
565 }
566
567 /* --- priority ------------------------------------------ */
568 case VIDIOC_G_PRIORITY:
569 {
570 enum v4l2_priority *p = arg;
571
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300572 if (ops->vidioc_g_priority) {
573 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300574 } else if (use_fh_prio) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300575 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
576 ret = 0;
577 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300578 if (!ret)
579 dbgarg(cmd, "priority is %d\n", *p);
580 break;
581 }
582 case VIDIOC_S_PRIORITY:
583 {
584 enum v4l2_priority *p = arg;
585
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300586 if (!ops->vidioc_s_priority && !use_fh_prio)
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300587 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300588 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300589 if (ops->vidioc_s_priority)
590 ret = ops->vidioc_s_priority(file, fh, *p);
591 else
Hans Verkuil93d5a302011-08-09 09:32:06 -0300592 ret = ret_prio ? ret_prio :
593 v4l2_prio_change(&vfd->v4l2_dev->prio,
594 &vfh->prio, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300595 break;
596 }
597
598 /* --- capture ioctls ---------------------------------------- */
599 case VIDIOC_ENUM_FMT:
600 {
601 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300602
Trent Piepho19c96e42009-03-04 01:21:02 -0300603 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300604 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300605 if (likely(ops->vidioc_enum_fmt_vid_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300606 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300607 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300608 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300609 if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300610 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
611 fh, f);
612 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300613 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300614 if (likely(ops->vidioc_enum_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300615 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300616 fh, f);
617 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300618 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300619 if (likely(ops->vidioc_enum_fmt_vid_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300620 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300621 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300622 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300623 if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300624 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
625 fh, f);
626 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300627 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300628 if (likely(ops->vidioc_enum_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300629 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300630 fh, f);
631 break;
632 default:
633 break;
634 }
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300635 if (likely (!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300636 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
637 "pixelformat=%c%c%c%c, description='%s'\n",
638 f->index, f->type, f->flags,
639 (f->pixelformat & 0xff),
640 (f->pixelformat >> 8) & 0xff,
641 (f->pixelformat >> 16) & 0xff,
642 (f->pixelformat >> 24) & 0xff,
643 f->description);
Hans Verkuil93d5a302011-08-09 09:32:06 -0300644 else if (ret == -ENOTTY &&
645 (ops->vidioc_enum_fmt_vid_cap ||
646 ops->vidioc_enum_fmt_vid_out ||
647 ops->vidioc_enum_fmt_vid_cap_mplane ||
648 ops->vidioc_enum_fmt_vid_out_mplane ||
649 ops->vidioc_enum_fmt_vid_overlay ||
650 ops->vidioc_enum_fmt_type_private))
651 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300652 break;
653 }
654 case VIDIOC_G_FMT:
655 {
656 struct v4l2_format *f = (struct v4l2_format *)arg;
657
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300658 /* FIXME: Should be one dump per type */
659 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
660
661 switch (f->type) {
662 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300663 if (ops->vidioc_g_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300664 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300665 if (!ret)
666 v4l_print_pix_fmt(vfd, &f->fmt.pix);
667 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300668 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300669 if (ops->vidioc_g_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300670 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
671 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300672 if (!ret)
673 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
674 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300675 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300676 if (likely(ops->vidioc_g_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300677 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300678 fh, f);
679 break;
680 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300681 if (ops->vidioc_g_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300682 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300683 if (!ret)
684 v4l_print_pix_fmt(vfd, &f->fmt.pix);
685 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300686 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300687 if (ops->vidioc_g_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300688 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
689 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300690 if (!ret)
691 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
692 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300693 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300694 if (likely(ops->vidioc_g_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300695 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300696 fh, f);
697 break;
698 case V4L2_BUF_TYPE_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300699 if (likely(ops->vidioc_g_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300700 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300701 break;
702 case V4L2_BUF_TYPE_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300703 if (likely(ops->vidioc_g_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300704 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300705 break;
706 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300707 if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300708 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300709 fh, f);
710 break;
711 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300712 if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300713 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300714 fh, f);
715 break;
716 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300717 if (likely(ops->vidioc_g_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300718 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300719 fh, f);
720 break;
721 }
Hans Verkuil93d5a302011-08-09 09:32:06 -0300722 if (unlikely(ret == -ENOTTY && have_fmt_ops(g)))
723 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300724
725 break;
726 }
727 case VIDIOC_S_FMT:
728 {
729 struct v4l2_format *f = (struct v4l2_format *)arg;
730
Hans Verkuil93d5a302011-08-09 09:32:06 -0300731 if (!have_fmt_ops(s))
732 break;
733 if (ret_prio) {
734 ret = ret_prio;
735 break;
736 }
737 ret = -EINVAL;
738
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300739 /* FIXME: Should be one dump per type */
740 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
741
742 switch (f->type) {
743 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300744 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300745 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300746 if (ops->vidioc_s_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300747 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300748 break;
749 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
750 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
751 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300752 if (ops->vidioc_s_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300753 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
754 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300755 break;
756 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300757 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300758 if (ops->vidioc_s_fmt_vid_overlay)
759 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300760 fh, f);
761 break;
762 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300763 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300764 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300765 if (ops->vidioc_s_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300766 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300767 break;
768 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
769 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
770 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300771 if (ops->vidioc_s_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300772 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
773 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300774 break;
775 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300776 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300777 if (ops->vidioc_s_fmt_vid_out_overlay)
778 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300779 fh, f);
780 break;
781 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300782 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300783 if (likely(ops->vidioc_s_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300784 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300785 break;
786 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300787 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300788 if (likely(ops->vidioc_s_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300789 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300790 break;
791 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300792 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300793 if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300794 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300795 fh, f);
796 break;
797 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300798 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300799 if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300800 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300801 fh, f);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300802
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300803 break;
804 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300805 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300806 if (likely(ops->vidioc_s_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300807 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300808 fh, f);
809 break;
810 }
811 break;
812 }
813 case VIDIOC_TRY_FMT:
814 {
815 struct v4l2_format *f = (struct v4l2_format *)arg;
816
817 /* FIXME: Should be one dump per type */
818 dbgarg(cmd, "type=%s\n", prt_names(f->type,
819 v4l2_type_names));
820 switch (f->type) {
821 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300822 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300823 if (ops->vidioc_try_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300824 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300825 if (!ret)
826 v4l_print_pix_fmt(vfd, &f->fmt.pix);
827 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300828 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
829 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300830 if (ops->vidioc_try_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300831 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
832 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300833 if (!ret)
834 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
835 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300836 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300837 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300838 if (likely(ops->vidioc_try_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300839 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300840 fh, f);
841 break;
842 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300843 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300844 if (ops->vidioc_try_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300845 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300846 if (!ret)
847 v4l_print_pix_fmt(vfd, &f->fmt.pix);
848 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300849 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
850 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300851 if (ops->vidioc_try_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300852 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
853 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300854 if (!ret)
855 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
856 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300857 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300858 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300859 if (likely(ops->vidioc_try_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300860 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300861 fh, f);
862 break;
863 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300864 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300865 if (likely(ops->vidioc_try_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300866 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300867 break;
868 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300869 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300870 if (likely(ops->vidioc_try_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300871 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300872 break;
873 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300874 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300875 if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300876 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300877 fh, f);
878 break;
879 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300880 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300881 if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300882 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300883 fh, f);
884 break;
885 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300886 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300887 if (likely(ops->vidioc_try_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300888 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300889 fh, f);
890 break;
891 }
Hans Verkuil93d5a302011-08-09 09:32:06 -0300892 if (unlikely(ret == -ENOTTY && have_fmt_ops(try)))
893 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300894 break;
895 }
896 /* FIXME: Those buf reqs could be handled here,
897 with some changes on videobuf to allow its header to be included at
898 videodev2.h or being merged at videodev2.
899 */
900 case VIDIOC_REQBUFS:
901 {
902 struct v4l2_requestbuffers *p = arg;
903
Hans Verkuila3998102008-07-21 02:57:38 -0300904 if (!ops->vidioc_reqbufs)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300905 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300906 if (ret_prio) {
907 ret = ret_prio;
908 break;
909 }
Hans Verkuila3998102008-07-21 02:57:38 -0300910 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300911 if (ret)
912 break;
913
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300914 if (p->type < V4L2_BUF_TYPE_PRIVATE)
915 CLEAR_AFTER_FIELD(p, memory);
916
Hans Verkuila3998102008-07-21 02:57:38 -0300917 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300918 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
919 p->count,
920 prt_names(p->type, v4l2_type_names),
921 prt_names(p->memory, v4l2_memory_names));
922 break;
923 }
924 case VIDIOC_QUERYBUF:
925 {
926 struct v4l2_buffer *p = arg;
927
Hans Verkuila3998102008-07-21 02:57:38 -0300928 if (!ops->vidioc_querybuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300929 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300930 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300931 if (ret)
932 break;
933
Hans Verkuila3998102008-07-21 02:57:38 -0300934 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300935 if (!ret)
936 dbgbuf(cmd, vfd, p);
937 break;
938 }
939 case VIDIOC_QBUF:
940 {
941 struct v4l2_buffer *p = arg;
942
Hans Verkuila3998102008-07-21 02:57:38 -0300943 if (!ops->vidioc_qbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300944 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300945 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300946 if (ret)
947 break;
948
Hans Verkuila3998102008-07-21 02:57:38 -0300949 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300950 if (!ret)
951 dbgbuf(cmd, vfd, p);
952 break;
953 }
954 case VIDIOC_DQBUF:
955 {
956 struct v4l2_buffer *p = arg;
957
Hans Verkuila3998102008-07-21 02:57:38 -0300958 if (!ops->vidioc_dqbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300959 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300960 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300961 if (ret)
962 break;
963
Hans Verkuila3998102008-07-21 02:57:38 -0300964 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300965 if (!ret)
966 dbgbuf(cmd, vfd, p);
967 break;
968 }
969 case VIDIOC_OVERLAY:
970 {
971 int *i = arg;
972
Hans Verkuila3998102008-07-21 02:57:38 -0300973 if (!ops->vidioc_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300974 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300975 if (ret_prio) {
976 ret = ret_prio;
977 break;
978 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300979 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -0300980 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300981 break;
982 }
983 case VIDIOC_G_FBUF:
984 {
985 struct v4l2_framebuffer *p = arg;
986
Hans Verkuila3998102008-07-21 02:57:38 -0300987 if (!ops->vidioc_g_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300988 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300989 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300990 if (!ret) {
991 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
992 p->capability, p->flags,
993 (unsigned long)p->base);
994 v4l_print_pix_fmt(vfd, &p->fmt);
995 }
996 break;
997 }
998 case VIDIOC_S_FBUF:
999 {
1000 struct v4l2_framebuffer *p = arg;
1001
Hans Verkuila3998102008-07-21 02:57:38 -03001002 if (!ops->vidioc_s_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001003 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001004 if (ret_prio) {
1005 ret = ret_prio;
1006 break;
1007 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001008 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1009 p->capability, p->flags, (unsigned long)p->base);
1010 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -03001011 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001012 break;
1013 }
1014 case VIDIOC_STREAMON:
1015 {
1016 enum v4l2_buf_type i = *(int *)arg;
1017
Hans Verkuila3998102008-07-21 02:57:38 -03001018 if (!ops->vidioc_streamon)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001019 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001020 if (ret_prio) {
1021 ret = ret_prio;
1022 break;
1023 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001024 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001025 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001026 break;
1027 }
1028 case VIDIOC_STREAMOFF:
1029 {
1030 enum v4l2_buf_type i = *(int *)arg;
1031
Hans Verkuila3998102008-07-21 02:57:38 -03001032 if (!ops->vidioc_streamoff)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001033 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001034 if (ret_prio) {
1035 ret = ret_prio;
1036 break;
1037 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001038 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001039 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001040 break;
1041 }
1042 /* ---------- tv norms ---------- */
1043 case VIDIOC_ENUMSTD:
1044 {
1045 struct v4l2_standard *p = arg;
1046 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1047 unsigned int index = p->index, i, j = 0;
1048 const char *descr = "";
1049
Hans Verkuil93d5a302011-08-09 09:32:06 -03001050 if (id == 0)
1051 break;
1052 ret = -EINVAL;
1053
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001054 /* Return norm array in a canonical way */
1055 for (i = 0; i <= index && id; i++) {
1056 /* last std value in the standards array is 0, so this
1057 while always ends there since (id & 0) == 0. */
1058 while ((id & standards[j].std) != standards[j].std)
1059 j++;
1060 curr_id = standards[j].std;
1061 descr = standards[j].descr;
1062 j++;
1063 if (curr_id == 0)
1064 break;
1065 if (curr_id != V4L2_STD_PAL &&
1066 curr_id != V4L2_STD_SECAM &&
1067 curr_id != V4L2_STD_NTSC)
1068 id &= ~curr_id;
1069 }
1070 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001071 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001072
1073 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001074
1075 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1076 "framelines=%d\n", p->index,
1077 (unsigned long long)p->id, p->name,
1078 p->frameperiod.numerator,
1079 p->frameperiod.denominator,
1080 p->framelines);
1081
1082 ret = 0;
1083 break;
1084 }
1085 case VIDIOC_G_STD:
1086 {
1087 v4l2_std_id *id = arg;
1088
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001089 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001090 if (ops->vidioc_g_std)
1091 ret = ops->vidioc_g_std(file, fh, id);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001092 else if (vfd->current_norm) {
1093 ret = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001094 *id = vfd->current_norm;
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001095 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001096
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001097 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001098 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1099 break;
1100 }
1101 case VIDIOC_S_STD:
1102 {
1103 v4l2_std_id *id = arg, norm;
1104
1105 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1106
Hans Verkuil93d5a302011-08-09 09:32:06 -03001107 if (!ops->vidioc_s_std)
1108 break;
1109
1110 if (ret_prio) {
1111 ret = ret_prio;
1112 break;
1113 }
1114 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001115 norm = (*id) & vfd->tvnorms;
1116 if (vfd->tvnorms && !norm) /* Check if std is supported */
1117 break;
1118
1119 /* Calls the specific handler */
Hans Verkuil93d5a302011-08-09 09:32:06 -03001120 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001121
1122 /* Updates standard information */
1123 if (ret >= 0)
1124 vfd->current_norm = norm;
1125 break;
1126 }
1127 case VIDIOC_QUERYSTD:
1128 {
1129 v4l2_std_id *p = arg;
1130
Hans Verkuila3998102008-07-21 02:57:38 -03001131 if (!ops->vidioc_querystd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001132 break;
Mauro Carvalho Chehab8715e6c2011-10-04 09:32:23 -03001133 /*
1134 * If nothing detected, it should return all supported
1135 * Drivers just need to mask the std argument, in order
1136 * to remove the standards that don't apply from the mask.
1137 * This means that tuners, audio and video decoders can join
1138 * their efforts to improve the standards detection
1139 */
1140 *p = vfd->tvnorms;
Hans Verkuila3998102008-07-21 02:57:38 -03001141 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001142 if (!ret)
1143 dbgarg(cmd, "detected std=%08Lx\n",
1144 (unsigned long long)*p);
1145 break;
1146 }
1147 /* ------ input switching ---------- */
1148 /* FIXME: Inputs can be handled inside videodev2 */
1149 case VIDIOC_ENUMINPUT:
1150 {
1151 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001152
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001153 /*
1154 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1155 * CAP_STD here based on ioctl handler provided by the
1156 * driver. If the driver doesn't support these
1157 * for a specific input, it must override these flags.
1158 */
1159 if (ops->vidioc_s_std)
1160 p->capabilities |= V4L2_IN_CAP_STD;
1161 if (ops->vidioc_s_dv_preset)
1162 p->capabilities |= V4L2_IN_CAP_PRESETS;
1163 if (ops->vidioc_s_dv_timings)
1164 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1165
Hans Verkuila3998102008-07-21 02:57:38 -03001166 if (!ops->vidioc_enum_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001167 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001168
Hans Verkuila3998102008-07-21 02:57:38 -03001169 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001170 if (!ret)
1171 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1172 "audioset=%d, "
1173 "tuner=%d, std=%08Lx, status=%d\n",
1174 p->index, p->name, p->type, p->audioset,
1175 p->tuner,
1176 (unsigned long long)p->std,
1177 p->status);
1178 break;
1179 }
1180 case VIDIOC_G_INPUT:
1181 {
1182 unsigned int *i = arg;
1183
Hans Verkuila3998102008-07-21 02:57:38 -03001184 if (!ops->vidioc_g_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001185 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001186 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001187 if (!ret)
1188 dbgarg(cmd, "value=%d\n", *i);
1189 break;
1190 }
1191 case VIDIOC_S_INPUT:
1192 {
1193 unsigned int *i = arg;
1194
Hans Verkuila3998102008-07-21 02:57:38 -03001195 if (!ops->vidioc_s_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001196 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001197 if (ret_prio) {
1198 ret = ret_prio;
1199 break;
1200 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001201 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001202 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001203 break;
1204 }
1205
1206 /* ------ output switching ---------- */
1207 case VIDIOC_ENUMOUTPUT:
1208 {
1209 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001210
Hans Verkuila3998102008-07-21 02:57:38 -03001211 if (!ops->vidioc_enum_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001212 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001213
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001214 /*
1215 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1216 * CAP_STD here based on ioctl handler provided by the
1217 * driver. If the driver doesn't support these
1218 * for a specific output, it must override these flags.
1219 */
1220 if (ops->vidioc_s_std)
1221 p->capabilities |= V4L2_OUT_CAP_STD;
1222 if (ops->vidioc_s_dv_preset)
1223 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1224 if (ops->vidioc_s_dv_timings)
1225 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1226
Hans Verkuila3998102008-07-21 02:57:38 -03001227 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001228 if (!ret)
1229 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1230 "audioset=0x%x, "
1231 "modulator=%d, std=0x%08Lx\n",
1232 p->index, p->name, p->type, p->audioset,
1233 p->modulator, (unsigned long long)p->std);
1234 break;
1235 }
1236 case VIDIOC_G_OUTPUT:
1237 {
1238 unsigned int *i = arg;
1239
Hans Verkuila3998102008-07-21 02:57:38 -03001240 if (!ops->vidioc_g_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001241 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001242 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001243 if (!ret)
1244 dbgarg(cmd, "value=%d\n", *i);
1245 break;
1246 }
1247 case VIDIOC_S_OUTPUT:
1248 {
1249 unsigned int *i = arg;
1250
Hans Verkuila3998102008-07-21 02:57:38 -03001251 if (!ops->vidioc_s_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001252 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001253 if (ret_prio) {
1254 ret = ret_prio;
1255 break;
1256 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001257 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001258 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001259 break;
1260 }
1261
1262 /* --- controls ---------------------------------------------- */
1263 case VIDIOC_QUERYCTRL:
1264 {
1265 struct v4l2_queryctrl *p = arg;
1266
Hans Verkuil2d28b682011-03-12 08:54:43 -03001267 if (vfh && vfh->ctrl_handler)
1268 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1269 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001270 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1271 else if (ops->vidioc_queryctrl)
1272 ret = ops->vidioc_queryctrl(file, fh, p);
1273 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001274 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001275 if (!ret)
1276 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1277 "step=%d, default=%d, flags=0x%08x\n",
1278 p->id, p->type, p->name,
1279 p->minimum, p->maximum,
1280 p->step, p->default_value, p->flags);
1281 else
1282 dbgarg(cmd, "id=0x%x\n", p->id);
1283 break;
1284 }
1285 case VIDIOC_G_CTRL:
1286 {
1287 struct v4l2_control *p = arg;
1288
Hans Verkuil2d28b682011-03-12 08:54:43 -03001289 if (vfh && vfh->ctrl_handler)
1290 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1291 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001292 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1293 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001294 ret = ops->vidioc_g_ctrl(file, fh, p);
1295 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001296 struct v4l2_ext_controls ctrls;
1297 struct v4l2_ext_control ctrl;
1298
1299 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1300 ctrls.count = 1;
1301 ctrls.controls = &ctrl;
1302 ctrl.id = p->id;
1303 ctrl.value = p->value;
1304 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001305 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001306 if (ret == 0)
1307 p->value = ctrl.value;
1308 }
1309 } else
1310 break;
1311 if (!ret)
1312 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1313 else
1314 dbgarg(cmd, "id=0x%x\n", p->id);
1315 break;
1316 }
1317 case VIDIOC_S_CTRL:
1318 {
1319 struct v4l2_control *p = arg;
1320 struct v4l2_ext_controls ctrls;
1321 struct v4l2_ext_control ctrl;
1322
Hans Verkuil2d28b682011-03-12 08:54:43 -03001323 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001324 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001325 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001326 if (ret_prio) {
1327 ret = ret_prio;
1328 break;
1329 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001330
1331 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1332
Hans Verkuil2d28b682011-03-12 08:54:43 -03001333 if (vfh && vfh->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001334 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001335 break;
1336 }
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001337 if (vfd->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001338 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001339 break;
1340 }
Hans Verkuila3998102008-07-21 02:57:38 -03001341 if (ops->vidioc_s_ctrl) {
1342 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001343 break;
1344 }
Hans Verkuila3998102008-07-21 02:57:38 -03001345 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001346 break;
1347
1348 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1349 ctrls.count = 1;
1350 ctrls.controls = &ctrl;
1351 ctrl.id = p->id;
1352 ctrl.value = p->value;
1353 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001354 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001355 else
1356 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001357 break;
1358 }
1359 case VIDIOC_G_EXT_CTRLS:
1360 {
1361 struct v4l2_ext_controls *p = arg;
1362
1363 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001364 if (vfh && vfh->ctrl_handler)
1365 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1366 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001367 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001368 else if (ops->vidioc_g_ext_ctrls)
1369 ret = check_ext_ctrls(p, 0) ?
1370 ops->vidioc_g_ext_ctrls(file, fh, p) :
1371 -EINVAL;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001372 else
1373 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001374 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1375 break;
1376 }
1377 case VIDIOC_S_EXT_CTRLS:
1378 {
1379 struct v4l2_ext_controls *p = arg;
1380
1381 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001382 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1383 !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001384 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001385 if (ret_prio) {
1386 ret = ret_prio;
1387 break;
1388 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001389 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001390 if (vfh && vfh->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001391 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001392 else if (vfd->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001393 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001394 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001395 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001396 else
1397 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001398 break;
1399 }
1400 case VIDIOC_TRY_EXT_CTRLS:
1401 {
1402 struct v4l2_ext_controls *p = arg;
1403
1404 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001405 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1406 !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001407 break;
1408 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001409 if (vfh && vfh->ctrl_handler)
1410 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1411 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001412 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1413 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001414 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001415 else
1416 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001417 break;
1418 }
1419 case VIDIOC_QUERYMENU:
1420 {
1421 struct v4l2_querymenu *p = arg;
1422
Hans Verkuil2d28b682011-03-12 08:54:43 -03001423 if (vfh && vfh->ctrl_handler)
1424 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1425 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001426 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1427 else if (ops->vidioc_querymenu)
1428 ret = ops->vidioc_querymenu(file, fh, p);
1429 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001430 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001431 if (!ret)
1432 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1433 p->id, p->index, p->name);
1434 else
1435 dbgarg(cmd, "id=0x%x, index=%d\n",
1436 p->id, p->index);
1437 break;
1438 }
1439 /* --- audio ---------------------------------------------- */
1440 case VIDIOC_ENUMAUDIO:
1441 {
1442 struct v4l2_audio *p = arg;
1443
Hans Verkuila3998102008-07-21 02:57:38 -03001444 if (!ops->vidioc_enumaudio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001445 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001446 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001447 if (!ret)
1448 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1449 "mode=0x%x\n", p->index, p->name,
1450 p->capability, p->mode);
1451 else
1452 dbgarg(cmd, "index=%d\n", p->index);
1453 break;
1454 }
1455 case VIDIOC_G_AUDIO:
1456 {
1457 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001458
Hans Verkuila3998102008-07-21 02:57:38 -03001459 if (!ops->vidioc_g_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001460 break;
1461
Hans Verkuila3998102008-07-21 02:57:38 -03001462 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001463 if (!ret)
1464 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1465 "mode=0x%x\n", p->index,
1466 p->name, p->capability, p->mode);
1467 else
1468 dbgarg(cmd, "index=%d\n", p->index);
1469 break;
1470 }
1471 case VIDIOC_S_AUDIO:
1472 {
1473 struct v4l2_audio *p = arg;
1474
Hans Verkuila3998102008-07-21 02:57:38 -03001475 if (!ops->vidioc_s_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001476 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001477 if (ret_prio) {
1478 ret = ret_prio;
1479 break;
1480 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001481 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1482 "mode=0x%x\n", p->index, p->name,
1483 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001484 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001485 break;
1486 }
1487 case VIDIOC_ENUMAUDOUT:
1488 {
1489 struct v4l2_audioout *p = arg;
1490
Hans Verkuila3998102008-07-21 02:57:38 -03001491 if (!ops->vidioc_enumaudout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001492 break;
1493 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001494 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001495 if (!ret)
1496 dbgarg2("index=%d, name=%s, capability=%d, "
1497 "mode=%d\n", p->index, p->name,
1498 p->capability, p->mode);
1499 break;
1500 }
1501 case VIDIOC_G_AUDOUT:
1502 {
1503 struct v4l2_audioout *p = arg;
1504
Hans Verkuila3998102008-07-21 02:57:38 -03001505 if (!ops->vidioc_g_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001506 break;
Trent Piepho337f9d22009-03-04 01:21:02 -03001507
Hans Verkuila3998102008-07-21 02:57:38 -03001508 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001509 if (!ret)
1510 dbgarg2("index=%d, name=%s, capability=%d, "
1511 "mode=%d\n", p->index, p->name,
1512 p->capability, p->mode);
1513 break;
1514 }
1515 case VIDIOC_S_AUDOUT:
1516 {
1517 struct v4l2_audioout *p = arg;
1518
Hans Verkuila3998102008-07-21 02:57:38 -03001519 if (!ops->vidioc_s_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001520 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001521 if (ret_prio) {
1522 ret = ret_prio;
1523 break;
1524 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001525 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1526 "mode=%d\n", p->index, p->name,
1527 p->capability, p->mode);
1528
Hans Verkuila3998102008-07-21 02:57:38 -03001529 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001530 break;
1531 }
1532 case VIDIOC_G_MODULATOR:
1533 {
1534 struct v4l2_modulator *p = arg;
1535
Hans Verkuila3998102008-07-21 02:57:38 -03001536 if (!ops->vidioc_g_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001537 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001538 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001539 if (!ret)
1540 dbgarg(cmd, "index=%d, name=%s, "
1541 "capability=%d, rangelow=%d,"
1542 " rangehigh=%d, txsubchans=%d\n",
1543 p->index, p->name, p->capability,
1544 p->rangelow, p->rangehigh,
1545 p->txsubchans);
1546 break;
1547 }
1548 case VIDIOC_S_MODULATOR:
1549 {
1550 struct v4l2_modulator *p = arg;
1551
Hans Verkuila3998102008-07-21 02:57:38 -03001552 if (!ops->vidioc_s_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001553 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001554 if (ret_prio) {
1555 ret = ret_prio;
1556 break;
1557 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001558 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1559 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1560 p->index, p->name, p->capability, p->rangelow,
1561 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001562 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001563 break;
1564 }
1565 case VIDIOC_G_CROP:
1566 {
1567 struct v4l2_crop *p = arg;
1568
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001569 if (!ops->vidioc_g_crop && !ops->vidioc_g_selection)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001570 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001571
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001572 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001573
1574 if (ops->vidioc_g_crop) {
1575 ret = ops->vidioc_g_crop(file, fh, p);
1576 } else {
1577 /* simulate capture crop using selection api */
1578 struct v4l2_selection s = {
1579 .type = p->type,
1580 };
1581
1582 /* crop means compose for output devices */
1583 if (V4L2_TYPE_IS_OUTPUT(p->type))
1584 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1585 else
1586 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1587
1588 ret = ops->vidioc_g_selection(file, fh, &s);
1589
1590 /* copying results to old structure on success */
1591 if (!ret)
1592 p->c = s.r;
1593 }
1594
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001595 if (!ret)
1596 dbgrect(vfd, "", &p->c);
1597 break;
1598 }
1599 case VIDIOC_S_CROP:
1600 {
1601 struct v4l2_crop *p = arg;
1602
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001603 if (!ops->vidioc_s_crop && !ops->vidioc_s_selection)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001604 break;
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001605
Hans Verkuil93d5a302011-08-09 09:32:06 -03001606 if (ret_prio) {
1607 ret = ret_prio;
1608 break;
1609 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001610 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1611 dbgrect(vfd, "", &p->c);
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001612
1613 if (ops->vidioc_s_crop) {
1614 ret = ops->vidioc_s_crop(file, fh, p);
1615 } else {
1616 /* simulate capture crop using selection api */
1617 struct v4l2_selection s = {
1618 .type = p->type,
1619 .r = p->c,
1620 };
1621
1622 /* crop means compose for output devices */
1623 if (V4L2_TYPE_IS_OUTPUT(p->type))
1624 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1625 else
1626 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1627
1628 ret = ops->vidioc_s_selection(file, fh, &s);
1629 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001630 break;
1631 }
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001632 case VIDIOC_G_SELECTION:
1633 {
1634 struct v4l2_selection *p = arg;
1635
1636 if (!ops->vidioc_g_selection)
1637 break;
1638
1639 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1640
1641 ret = ops->vidioc_g_selection(file, fh, p);
1642 if (!ret)
1643 dbgrect(vfd, "", &p->r);
1644 break;
1645 }
1646 case VIDIOC_S_SELECTION:
1647 {
1648 struct v4l2_selection *p = arg;
1649
1650 if (!ops->vidioc_s_selection)
1651 break;
1652
1653 if (ret_prio) {
1654 ret = ret_prio;
1655 break;
1656 }
1657
1658 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1659 dbgrect(vfd, "", &p->r);
1660
1661 ret = ops->vidioc_s_selection(file, fh, p);
1662 break;
1663 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001664 case VIDIOC_CROPCAP:
1665 {
1666 struct v4l2_cropcap *p = arg;
1667
1668 /*FIXME: Should also show v4l2_fract pixelaspect */
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001669 if (!ops->vidioc_cropcap && !ops->vidioc_g_selection)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001670 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001671
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001672 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001673 if (ops->vidioc_cropcap) {
1674 ret = ops->vidioc_cropcap(file, fh, p);
1675 } else {
1676 struct v4l2_selection s = { .type = p->type };
1677
1678 /* obtaining bounds */
1679 if (V4L2_TYPE_IS_OUTPUT(p->type))
1680 s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
1681 else
1682 s.target = V4L2_SEL_TGT_CROP_BOUNDS;
1683
1684 ret = ops->vidioc_g_selection(file, fh, &s);
1685 if (ret)
1686 break;
1687 p->bounds = s.r;
1688
1689 /* obtaining defrect */
1690 if (V4L2_TYPE_IS_OUTPUT(p->type))
1691 s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
1692 else
1693 s.target = V4L2_SEL_TGT_CROP_DEFAULT;
1694
1695 ret = ops->vidioc_g_selection(file, fh, &s);
1696 if (ret)
1697 break;
1698 p->defrect = s.r;
1699
1700 /* setting trivial pixelaspect */
1701 p->pixelaspect.numerator = 1;
1702 p->pixelaspect.denominator = 1;
1703 }
1704
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001705 if (!ret) {
1706 dbgrect(vfd, "bounds ", &p->bounds);
1707 dbgrect(vfd, "defrect ", &p->defrect);
1708 }
1709 break;
1710 }
1711 case VIDIOC_G_JPEGCOMP:
1712 {
1713 struct v4l2_jpegcompression *p = arg;
1714
Hans Verkuila3998102008-07-21 02:57:38 -03001715 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001716 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001717
Hans Verkuila3998102008-07-21 02:57:38 -03001718 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001719 if (!ret)
1720 dbgarg(cmd, "quality=%d, APPn=%d, "
1721 "APP_len=%d, COM_len=%d, "
1722 "jpeg_markers=%d\n",
1723 p->quality, p->APPn, p->APP_len,
1724 p->COM_len, p->jpeg_markers);
1725 break;
1726 }
1727 case VIDIOC_S_JPEGCOMP:
1728 {
1729 struct v4l2_jpegcompression *p = arg;
1730
Hans Verkuila3998102008-07-21 02:57:38 -03001731 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001732 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001733 if (ret_prio) {
1734 ret = ret_prio;
1735 break;
1736 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001737 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1738 "COM_len=%d, jpeg_markers=%d\n",
1739 p->quality, p->APPn, p->APP_len,
1740 p->COM_len, p->jpeg_markers);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001741 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001742 break;
1743 }
1744 case VIDIOC_G_ENC_INDEX:
1745 {
1746 struct v4l2_enc_idx *p = arg;
1747
Hans Verkuila3998102008-07-21 02:57:38 -03001748 if (!ops->vidioc_g_enc_index)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001749 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001750 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001751 if (!ret)
1752 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1753 p->entries, p->entries_cap);
1754 break;
1755 }
1756 case VIDIOC_ENCODER_CMD:
1757 {
1758 struct v4l2_encoder_cmd *p = arg;
1759
Hans Verkuila3998102008-07-21 02:57:38 -03001760 if (!ops->vidioc_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001761 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001762 if (ret_prio) {
1763 ret = ret_prio;
1764 break;
1765 }
Hans Verkuila3998102008-07-21 02:57:38 -03001766 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001767 if (!ret)
1768 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1769 break;
1770 }
1771 case VIDIOC_TRY_ENCODER_CMD:
1772 {
1773 struct v4l2_encoder_cmd *p = arg;
1774
Hans Verkuila3998102008-07-21 02:57:38 -03001775 if (!ops->vidioc_try_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001776 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001777 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001778 if (!ret)
1779 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1780 break;
1781 }
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001782 case VIDIOC_DECODER_CMD:
1783 {
1784 struct v4l2_decoder_cmd *p = arg;
1785
1786 if (!ops->vidioc_decoder_cmd)
1787 break;
1788 if (ret_prio) {
1789 ret = ret_prio;
1790 break;
1791 }
1792 ret = ops->vidioc_decoder_cmd(file, fh, p);
1793 if (!ret)
1794 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1795 break;
1796 }
1797 case VIDIOC_TRY_DECODER_CMD:
1798 {
1799 struct v4l2_decoder_cmd *p = arg;
1800
1801 if (!ops->vidioc_try_decoder_cmd)
1802 break;
1803 ret = ops->vidioc_try_decoder_cmd(file, fh, p);
1804 if (!ret)
1805 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1806 break;
1807 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001808 case VIDIOC_G_PARM:
1809 {
1810 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001811
Hans Verkuil93d5a302011-08-09 09:32:06 -03001812 if (!ops->vidioc_g_parm && !vfd->current_norm)
1813 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001814 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001815 ret = check_fmt(ops, p->type);
1816 if (ret)
1817 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001818 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001819 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001820 v4l2_std_id std = vfd->current_norm;
1821
Hans Verkuil93d5a302011-08-09 09:32:06 -03001822 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001823 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001824 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001825
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001826 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001827 if (ops->vidioc_g_std)
1828 ret = ops->vidioc_g_std(file, fh, &std);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001829 if (ret == 0)
1830 v4l2_video_std_frame_period(std,
1831 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001832 }
1833
1834 dbgarg(cmd, "type=%d\n", p->type);
1835 break;
1836 }
1837 case VIDIOC_S_PARM:
1838 {
1839 struct v4l2_streamparm *p = arg;
1840
Hans Verkuila3998102008-07-21 02:57:38 -03001841 if (!ops->vidioc_s_parm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001842 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001843 if (ret_prio) {
1844 ret = ret_prio;
1845 break;
1846 }
Trent Piepho34796bc2009-03-28 22:25:35 -03001847 ret = check_fmt(ops, p->type);
1848 if (ret)
1849 break;
1850
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001851 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001852 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001853 break;
1854 }
1855 case VIDIOC_G_TUNER:
1856 {
1857 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001858
Hans Verkuila3998102008-07-21 02:57:38 -03001859 if (!ops->vidioc_g_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001860 break;
1861
Hans Verkuil227690d2011-06-12 06:36:41 -03001862 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1863 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001864 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001865 if (!ret)
1866 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1867 "capability=0x%x, rangelow=%d, "
1868 "rangehigh=%d, signal=%d, afc=%d, "
1869 "rxsubchans=0x%x, audmode=%d\n",
1870 p->index, p->name, p->type,
1871 p->capability, p->rangelow,
1872 p->rangehigh, p->signal, p->afc,
1873 p->rxsubchans, p->audmode);
1874 break;
1875 }
1876 case VIDIOC_S_TUNER:
1877 {
1878 struct v4l2_tuner *p = arg;
1879
Hans Verkuila3998102008-07-21 02:57:38 -03001880 if (!ops->vidioc_s_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001881 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001882 if (ret_prio) {
1883 ret = ret_prio;
1884 break;
1885 }
Hans Verkuil227690d2011-06-12 06:36:41 -03001886 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1887 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001888 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1889 "capability=0x%x, rangelow=%d, "
1890 "rangehigh=%d, signal=%d, afc=%d, "
1891 "rxsubchans=0x%x, audmode=%d\n",
1892 p->index, p->name, p->type,
1893 p->capability, p->rangelow,
1894 p->rangehigh, p->signal, p->afc,
1895 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001896 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001897 break;
1898 }
1899 case VIDIOC_G_FREQUENCY:
1900 {
1901 struct v4l2_frequency *p = arg;
1902
Hans Verkuila3998102008-07-21 02:57:38 -03001903 if (!ops->vidioc_g_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001904 break;
1905
Hans Verkuil227690d2011-06-12 06:36:41 -03001906 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1907 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001908 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001909 if (!ret)
1910 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1911 p->tuner, p->type, p->frequency);
1912 break;
1913 }
1914 case VIDIOC_S_FREQUENCY:
1915 {
1916 struct v4l2_frequency *p = arg;
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001917 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001918
Hans Verkuila3998102008-07-21 02:57:38 -03001919 if (!ops->vidioc_s_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001920 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001921 if (ret_prio) {
1922 ret = ret_prio;
1923 break;
1924 }
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001925 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1926 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001927 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1928 p->tuner, p->type, p->frequency);
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001929 if (p->type != type)
1930 ret = -EINVAL;
1931 else
1932 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001933 break;
1934 }
1935 case VIDIOC_G_SLICED_VBI_CAP:
1936 {
1937 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001938
Hans Verkuila3998102008-07-21 02:57:38 -03001939 if (!ops->vidioc_g_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001940 break;
Trent Piepho19c96e42009-03-04 01:21:02 -03001941
1942 /* Clear up to type, everything after type is zerod already */
1943 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1944
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001945 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001946 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001947 if (!ret)
1948 dbgarg2("service_set=%d\n", p->service_set);
1949 break;
1950 }
1951 case VIDIOC_LOG_STATUS:
1952 {
Hans Verkuila3998102008-07-21 02:57:38 -03001953 if (!ops->vidioc_log_status)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001954 break;
Hans Verkuile2ecb252012-02-02 08:20:53 -03001955 if (vfd->v4l2_dev)
1956 pr_info("%s: ================= START STATUS =================\n",
1957 vfd->v4l2_dev->name);
Hans Verkuila3998102008-07-21 02:57:38 -03001958 ret = ops->vidioc_log_status(file, fh);
Hans Verkuile2ecb252012-02-02 08:20:53 -03001959 if (vfd->v4l2_dev)
1960 pr_info("%s: ================== END STATUS ==================\n",
1961 vfd->v4l2_dev->name);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001962 break;
1963 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001964 case VIDIOC_DBG_G_REGISTER:
1965 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001966#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001967 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001968
Hans Verkuila1198cc2011-01-08 09:53:32 -03001969 if (ops->vidioc_g_register) {
1970 if (!capable(CAP_SYS_ADMIN))
1971 ret = -EPERM;
1972 else
1973 ret = ops->vidioc_g_register(file, fh, p);
1974 }
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001975#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001976 break;
1977 }
1978 case VIDIOC_DBG_S_REGISTER:
1979 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001980#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001981 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001982
Hans Verkuila1198cc2011-01-08 09:53:32 -03001983 if (ops->vidioc_s_register) {
1984 if (!capable(CAP_SYS_ADMIN))
1985 ret = -EPERM;
1986 else
1987 ret = ops->vidioc_s_register(file, fh, p);
1988 }
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001989#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001990 break;
1991 }
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001992 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001993 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001994 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001995
Hans Verkuila3998102008-07-21 02:57:38 -03001996 if (!ops->vidioc_g_chip_ident)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001997 break;
Hans Verkuil80b36e02009-02-07 11:00:02 -03001998 p->ident = V4L2_IDENT_NONE;
1999 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03002000 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002001 if (!ret)
2002 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
2003 break;
2004 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002005 case VIDIOC_S_HW_FREQ_SEEK:
2006 {
2007 struct v4l2_hw_freq_seek *p = arg;
Hans Verkuila6cf90a2011-06-14 04:03:26 -03002008 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002009
Hans Verkuila3998102008-07-21 02:57:38 -03002010 if (!ops->vidioc_s_hw_freq_seek)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002011 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002012 if (ret_prio) {
2013 ret = ret_prio;
2014 break;
2015 }
Hans Verkuila6cf90a2011-06-14 04:03:26 -03002016 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
2017 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002018 dbgarg(cmd,
Hans Verkuila6cf90a2011-06-14 04:03:26 -03002019 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
2020 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
2021 if (p->type != type)
2022 ret = -EINVAL;
2023 else
2024 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
Hans Verkuila3998102008-07-21 02:57:38 -03002025 break;
2026 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002027 case VIDIOC_ENUM_FRAMESIZES:
2028 {
2029 struct v4l2_frmsizeenum *p = arg;
2030
2031 if (!ops->vidioc_enum_framesizes)
2032 break;
2033
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002034 ret = ops->vidioc_enum_framesizes(file, fh, p);
2035 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03002036 "index=%d, pixelformat=%c%c%c%c, type=%d ",
2037 p->index,
2038 (p->pixel_format & 0xff),
2039 (p->pixel_format >> 8) & 0xff,
2040 (p->pixel_format >> 16) & 0xff,
2041 (p->pixel_format >> 24) & 0xff,
2042 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002043 switch (p->type) {
2044 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002045 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002046 p->discrete.width, p->discrete.height);
2047 break;
2048 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002049 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002050 p->stepwise.min_width, p->stepwise.min_height,
2051 p->stepwise.step_width, p->stepwise.step_height,
2052 p->stepwise.max_width, p->stepwise.max_height);
2053 break;
2054 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002055 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002056 break;
2057 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002058 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002059 }
2060
2061 break;
2062 }
2063 case VIDIOC_ENUM_FRAMEINTERVALS:
2064 {
2065 struct v4l2_frmivalenum *p = arg;
2066
2067 if (!ops->vidioc_enum_frameintervals)
2068 break;
2069
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002070 ret = ops->vidioc_enum_frameintervals(file, fh, p);
2071 dbgarg(cmd,
2072 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
2073 p->index, p->pixel_format,
2074 p->width, p->height, p->type);
2075 switch (p->type) {
2076 case V4L2_FRMIVAL_TYPE_DISCRETE:
2077 dbgarg2("fps=%d/%d\n",
2078 p->discrete.numerator,
2079 p->discrete.denominator);
2080 break;
2081 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03002082 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
2083 p->stepwise.min.numerator,
2084 p->stepwise.min.denominator,
2085 p->stepwise.max.numerator,
2086 p->stepwise.max.denominator,
2087 p->stepwise.step.numerator,
2088 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002089 break;
2090 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
2091 dbgarg2("continuous\n");
2092 break;
2093 default:
2094 dbgarg2("- Unknown type!\n");
2095 }
2096 break;
2097 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002098 case VIDIOC_ENUM_DV_PRESETS:
2099 {
2100 struct v4l2_dv_enum_preset *p = arg;
2101
2102 if (!ops->vidioc_enum_dv_presets)
2103 break;
2104
2105 ret = ops->vidioc_enum_dv_presets(file, fh, p);
2106 if (!ret)
2107 dbgarg(cmd,
2108 "index=%d, preset=%d, name=%s, width=%d,"
2109 " height=%d ",
2110 p->index, p->preset, p->name, p->width,
2111 p->height);
2112 break;
2113 }
2114 case VIDIOC_S_DV_PRESET:
2115 {
2116 struct v4l2_dv_preset *p = arg;
2117
2118 if (!ops->vidioc_s_dv_preset)
2119 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002120 if (ret_prio) {
2121 ret = ret_prio;
2122 break;
2123 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002124
2125 dbgarg(cmd, "preset=%d\n", p->preset);
2126 ret = ops->vidioc_s_dv_preset(file, fh, p);
2127 break;
2128 }
2129 case VIDIOC_G_DV_PRESET:
2130 {
2131 struct v4l2_dv_preset *p = arg;
2132
2133 if (!ops->vidioc_g_dv_preset)
2134 break;
2135
2136 ret = ops->vidioc_g_dv_preset(file, fh, p);
2137 if (!ret)
2138 dbgarg(cmd, "preset=%d\n", p->preset);
2139 break;
2140 }
2141 case VIDIOC_QUERY_DV_PRESET:
2142 {
2143 struct v4l2_dv_preset *p = arg;
2144
2145 if (!ops->vidioc_query_dv_preset)
2146 break;
2147
2148 ret = ops->vidioc_query_dv_preset(file, fh, p);
2149 if (!ret)
2150 dbgarg(cmd, "preset=%d\n", p->preset);
2151 break;
2152 }
2153 case VIDIOC_S_DV_TIMINGS:
2154 {
2155 struct v4l2_dv_timings *p = arg;
2156
2157 if (!ops->vidioc_s_dv_timings)
2158 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002159 if (ret_prio) {
2160 ret = ret_prio;
2161 break;
2162 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002163
2164 switch (p->type) {
2165 case V4L2_DV_BT_656_1120:
2166 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2167 " width=%d, height=%d, polarities=%x,"
2168 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
2169 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
2170 " il_vfrontporch=%d, il_vsync=%d,"
2171 " il_vbackporch=%d\n",
2172 p->bt.interlaced, p->bt.pixelclock,
2173 p->bt.width, p->bt.height, p->bt.polarities,
2174 p->bt.hfrontporch, p->bt.hsync,
2175 p->bt.hbackporch, p->bt.vfrontporch,
2176 p->bt.vsync, p->bt.vbackporch,
2177 p->bt.il_vfrontporch, p->bt.il_vsync,
2178 p->bt.il_vbackporch);
2179 ret = ops->vidioc_s_dv_timings(file, fh, p);
2180 break;
2181 default:
2182 dbgarg2("Unknown type %d!\n", p->type);
2183 break;
2184 }
2185 break;
2186 }
2187 case VIDIOC_G_DV_TIMINGS:
2188 {
2189 struct v4l2_dv_timings *p = arg;
2190
2191 if (!ops->vidioc_g_dv_timings)
2192 break;
2193
2194 ret = ops->vidioc_g_dv_timings(file, fh, p);
2195 if (!ret) {
2196 switch (p->type) {
2197 case V4L2_DV_BT_656_1120:
2198 dbgarg2("bt-656/1120:interlaced=%d,"
2199 " pixelclock=%lld,"
2200 " width=%d, height=%d, polarities=%x,"
2201 " hfrontporch=%d, hsync=%d,"
2202 " hbackporch=%d, vfrontporch=%d,"
2203 " vsync=%d, vbackporch=%d,"
2204 " il_vfrontporch=%d, il_vsync=%d,"
2205 " il_vbackporch=%d\n",
2206 p->bt.interlaced, p->bt.pixelclock,
2207 p->bt.width, p->bt.height,
2208 p->bt.polarities, p->bt.hfrontporch,
2209 p->bt.hsync, p->bt.hbackporch,
2210 p->bt.vfrontporch, p->bt.vsync,
2211 p->bt.vbackporch, p->bt.il_vfrontporch,
2212 p->bt.il_vsync, p->bt.il_vbackporch);
2213 break;
2214 default:
2215 dbgarg2("Unknown type %d!\n", p->type);
2216 break;
2217 }
2218 }
2219 break;
2220 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002221 case VIDIOC_DQEVENT:
2222 {
2223 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002224
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002225 if (!ops->vidioc_subscribe_event)
2226 break;
2227
2228 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2229 if (ret < 0) {
2230 dbgarg(cmd, "no pending events?");
2231 break;
2232 }
2233 dbgarg(cmd,
2234 "pending=%d, type=0x%8.8x, sequence=%d, "
2235 "timestamp=%lu.%9.9lu ",
2236 ev->pending, ev->type, ev->sequence,
2237 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2238 break;
2239 }
2240 case VIDIOC_SUBSCRIBE_EVENT:
2241 {
2242 struct v4l2_event_subscription *sub = arg;
2243
2244 if (!ops->vidioc_subscribe_event)
2245 break;
2246
2247 ret = ops->vidioc_subscribe_event(fh, sub);
2248 if (ret < 0) {
2249 dbgarg(cmd, "failed, ret=%ld", ret);
2250 break;
2251 }
2252 dbgarg(cmd, "type=0x%8.8x", sub->type);
2253 break;
2254 }
2255 case VIDIOC_UNSUBSCRIBE_EVENT:
2256 {
2257 struct v4l2_event_subscription *sub = arg;
2258
2259 if (!ops->vidioc_unsubscribe_event)
2260 break;
2261
2262 ret = ops->vidioc_unsubscribe_event(fh, sub);
2263 if (ret < 0) {
2264 dbgarg(cmd, "failed, ret=%ld", ret);
2265 break;
2266 }
2267 dbgarg(cmd, "type=0x%8.8x", sub->type);
2268 break;
2269 }
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002270 case VIDIOC_CREATE_BUFS:
2271 {
2272 struct v4l2_create_buffers *create = arg;
2273
2274 if (!ops->vidioc_create_bufs)
2275 break;
2276 if (ret_prio) {
2277 ret = ret_prio;
2278 break;
2279 }
2280 ret = check_fmt(ops, create->format.type);
2281 if (ret)
2282 break;
2283
2284 ret = ops->vidioc_create_bufs(file, fh, create);
2285
2286 dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2287 break;
2288 }
2289 case VIDIOC_PREPARE_BUF:
2290 {
2291 struct v4l2_buffer *b = arg;
2292
2293 if (!ops->vidioc_prepare_buf)
2294 break;
2295 ret = check_fmt(ops, b->type);
2296 if (ret)
2297 break;
2298
2299 ret = ops->vidioc_prepare_buf(file, fh, b);
2300
2301 dbgarg(cmd, "index=%d", b->index);
2302 break;
2303 }
Hans Verkuila3998102008-07-21 02:57:38 -03002304 default:
Hans Verkuila3998102008-07-21 02:57:38 -03002305 if (!ops->vidioc_default)
2306 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002307 ret = ops->vidioc_default(file, fh, ret_prio >= 0, cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002308 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002309 } /* switch */
2310
2311 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2312 if (ret < 0) {
2313 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002314 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002315 }
2316 }
2317
2318 return ret;
2319}
2320
Trent Piepho19c96e42009-03-04 01:21:02 -03002321/* In some cases, only a few fields are used as input, i.e. when the app sets
2322 * "index" and then the driver fills in the rest of the structure for the thing
2323 * with that index. We only need to copy up the first non-input field. */
2324static unsigned long cmd_input_size(unsigned int cmd)
2325{
2326 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002327#define CMDINSIZE(cmd, type, field) \
2328 case VIDIOC_##cmd: \
2329 return offsetof(struct v4l2_##type, field) + \
2330 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03002331
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002332 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03002333 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2334 CMDINSIZE(G_FMT, format, type);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002335 CMDINSIZE(QUERYBUF, buffer, length);
Trent Piepho19c96e42009-03-04 01:21:02 -03002336 CMDINSIZE(G_PARM, streamparm, type);
2337 CMDINSIZE(ENUMSTD, standard, index);
2338 CMDINSIZE(ENUMINPUT, input, index);
2339 CMDINSIZE(G_CTRL, control, id);
2340 CMDINSIZE(G_TUNER, tuner, index);
2341 CMDINSIZE(QUERYCTRL, queryctrl, id);
2342 CMDINSIZE(QUERYMENU, querymenu, index);
2343 CMDINSIZE(ENUMOUTPUT, output, index);
2344 CMDINSIZE(G_MODULATOR, modulator, index);
2345 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2346 CMDINSIZE(CROPCAP, cropcap, type);
2347 CMDINSIZE(G_CROP, crop, type);
2348 CMDINSIZE(ENUMAUDIO, audio, index);
2349 CMDINSIZE(ENUMAUDOUT, audioout, index);
2350 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2351 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2352 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2353 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2354 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2355 default:
2356 return _IOC_SIZE(cmd);
2357 }
2358}
2359
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002360static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2361 void * __user *user_ptr, void ***kernel_ptr)
2362{
2363 int ret = 0;
2364
2365 switch (cmd) {
2366 case VIDIOC_QUERYBUF:
2367 case VIDIOC_QBUF:
2368 case VIDIOC_DQBUF: {
2369 struct v4l2_buffer *buf = parg;
2370
2371 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2372 if (buf->length > VIDEO_MAX_PLANES) {
2373 ret = -EINVAL;
2374 break;
2375 }
2376 *user_ptr = (void __user *)buf->m.planes;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002377 *kernel_ptr = (void *)&buf->m.planes;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002378 *array_size = sizeof(struct v4l2_plane) * buf->length;
2379 ret = 1;
2380 }
2381 break;
2382 }
2383
2384 case VIDIOC_S_EXT_CTRLS:
2385 case VIDIOC_G_EXT_CTRLS:
2386 case VIDIOC_TRY_EXT_CTRLS: {
2387 struct v4l2_ext_controls *ctrls = parg;
2388
2389 if (ctrls->count != 0) {
Dan Carpenter6c061082012-01-05 02:27:57 -03002390 if (ctrls->count > V4L2_CID_MAX_CTRLS) {
2391 ret = -EINVAL;
2392 break;
2393 }
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002394 *user_ptr = (void __user *)ctrls->controls;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002395 *kernel_ptr = (void *)&ctrls->controls;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002396 *array_size = sizeof(struct v4l2_ext_control)
2397 * ctrls->count;
2398 ret = 1;
2399 }
2400 break;
2401 }
2402 }
2403
2404 return ret;
2405}
2406
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002407long
2408video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2409 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002410{
2411 char sbuf[128];
2412 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002413 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002414 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002415 bool has_array_args;
2416 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002417 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002418 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002419
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002420 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002421 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002422 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2423 parg = sbuf;
2424 } else {
2425 /* too big to allocate from stack */
2426 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2427 if (NULL == mbuf)
2428 return -ENOMEM;
2429 parg = mbuf;
2430 }
2431
2432 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002433 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2434 unsigned long n = cmd_input_size(cmd);
2435
2436 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002437 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002438
2439 /* zero out anything we don't copy from userspace */
2440 if (n < _IOC_SIZE(cmd))
2441 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002442 } else {
2443 /* read-only ioctl */
2444 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002445 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002446 }
2447
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002448 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2449 if (err < 0)
2450 goto out;
2451 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002452
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002453 if (has_array_args) {
2454 /*
2455 * When adding new types of array args, make sure that the
2456 * parent argument to ioctl (which contains the pointer to the
2457 * array) fits into sbuf (so that mbuf will still remain
2458 * unused up to here).
2459 */
2460 mbuf = kmalloc(array_size, GFP_KERNEL);
2461 err = -ENOMEM;
2462 if (NULL == mbuf)
2463 goto out_array_args;
2464 err = -EFAULT;
2465 if (copy_from_user(mbuf, user_ptr, array_size))
2466 goto out_array_args;
2467 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002468 }
2469
2470 /* Handles IOCTL */
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002471 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002472 if (err == -ENOIOCTLCMD)
Hans Verkuil02bbb812012-02-08 08:09:36 -03002473 err = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002474
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002475 if (has_array_args) {
2476 *kernel_ptr = user_ptr;
2477 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002478 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002479 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002480 }
2481 if (err < 0)
2482 goto out;
2483
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002484out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002485 /* Copy results into user buffer */
2486 switch (_IOC_DIR(cmd)) {
2487 case _IOC_READ:
2488 case (_IOC_WRITE | _IOC_READ):
2489 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2490 err = -EFAULT;
2491 break;
2492 }
2493
2494out:
2495 kfree(mbuf);
2496 return err;
2497}
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002498EXPORT_SYMBOL(video_usercopy);
2499
2500long video_ioctl2(struct file *file,
2501 unsigned int cmd, unsigned long arg)
2502{
2503 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2504}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002505EXPORT_SYMBOL(video_ioctl2);