blob: e2f77bc159545a422eb2dc18d2feba1aa51a8ab4 [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 Verkuil35ea11f2008-07-20 08:12:02 -030058struct std_descr {
59 v4l2_std_id std;
60 const char *descr;
61};
62
63static const struct std_descr standards[] = {
64 { V4L2_STD_NTSC, "NTSC" },
65 { V4L2_STD_NTSC_M, "NTSC-M" },
66 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
67 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
68 { V4L2_STD_NTSC_443, "NTSC-443" },
69 { V4L2_STD_PAL, "PAL" },
70 { V4L2_STD_PAL_BG, "PAL-BG" },
71 { V4L2_STD_PAL_B, "PAL-B" },
72 { V4L2_STD_PAL_B1, "PAL-B1" },
73 { V4L2_STD_PAL_G, "PAL-G" },
74 { V4L2_STD_PAL_H, "PAL-H" },
75 { V4L2_STD_PAL_I, "PAL-I" },
76 { V4L2_STD_PAL_DK, "PAL-DK" },
77 { V4L2_STD_PAL_D, "PAL-D" },
78 { V4L2_STD_PAL_D1, "PAL-D1" },
79 { V4L2_STD_PAL_K, "PAL-K" },
80 { V4L2_STD_PAL_M, "PAL-M" },
81 { V4L2_STD_PAL_N, "PAL-N" },
82 { V4L2_STD_PAL_Nc, "PAL-Nc" },
83 { V4L2_STD_PAL_60, "PAL-60" },
84 { V4L2_STD_SECAM, "SECAM" },
85 { V4L2_STD_SECAM_B, "SECAM-B" },
86 { V4L2_STD_SECAM_G, "SECAM-G" },
87 { V4L2_STD_SECAM_H, "SECAM-H" },
88 { V4L2_STD_SECAM_DK, "SECAM-DK" },
89 { V4L2_STD_SECAM_D, "SECAM-D" },
90 { V4L2_STD_SECAM_K, "SECAM-K" },
91 { V4L2_STD_SECAM_K1, "SECAM-K1" },
92 { V4L2_STD_SECAM_L, "SECAM-L" },
93 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
94 { 0, "Unknown" }
95};
96
97/* video4linux standard ID conversion to standard name
98 */
99const char *v4l2_norm_to_name(v4l2_std_id id)
100{
101 u32 myid = id;
102 int i;
103
104 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
105 64 bit comparations. So, on that architecture, with some gcc
106 variants, compilation fails. Currently, the max value is 30bit wide.
107 */
108 BUG_ON(myid != id);
109
110 for (i = 0; standards[i].std; i++)
111 if (myid == standards[i].std)
112 break;
113 return standards[i].descr;
114}
115EXPORT_SYMBOL(v4l2_norm_to_name);
116
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300117/* Returns frame period for the given standard */
118void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
119{
120 if (id & V4L2_STD_525_60) {
121 frameperiod->numerator = 1001;
122 frameperiod->denominator = 30000;
123 } else {
124 frameperiod->numerator = 1;
125 frameperiod->denominator = 25;
126 }
127}
128EXPORT_SYMBOL(v4l2_video_std_frame_period);
129
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300130/* Fill in the fields of a v4l2_standard structure according to the
131 'id' and 'transmission' parameters. Returns negative on error. */
132int v4l2_video_std_construct(struct v4l2_standard *vs,
133 int id, const char *name)
134{
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300135 vs->id = id;
136 v4l2_video_std_frame_period(id, &vs->frameperiod);
137 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300138 strlcpy(vs->name, name, sizeof(vs->name));
139 return 0;
140}
141EXPORT_SYMBOL(v4l2_video_std_construct);
142
143/* ----------------------------------------------------------------- */
144/* some arrays for pretty-printing debug messages of enum types */
145
146const char *v4l2_field_names[] = {
147 [V4L2_FIELD_ANY] = "any",
148 [V4L2_FIELD_NONE] = "none",
149 [V4L2_FIELD_TOP] = "top",
150 [V4L2_FIELD_BOTTOM] = "bottom",
151 [V4L2_FIELD_INTERLACED] = "interlaced",
152 [V4L2_FIELD_SEQ_TB] = "seq-tb",
153 [V4L2_FIELD_SEQ_BT] = "seq-bt",
154 [V4L2_FIELD_ALTERNATE] = "alternate",
155 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
156 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
157};
158EXPORT_SYMBOL(v4l2_field_names);
159
160const char *v4l2_type_names[] = {
161 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
162 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
163 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
164 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
165 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
166 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
167 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
168 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
Pawel Osciakf8f39142010-07-29 14:44:25 -0300169 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
170 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300171};
172EXPORT_SYMBOL(v4l2_type_names);
173
174static const char *v4l2_memory_names[] = {
175 [V4L2_MEMORY_MMAP] = "mmap",
176 [V4L2_MEMORY_USERPTR] = "userptr",
177 [V4L2_MEMORY_OVERLAY] = "overlay",
178};
179
180#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
181 arr[a] : "unknown")
182
183/* ------------------------------------------------------------------ */
184/* debug help functions */
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300185
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300186static void dbgbuf(unsigned int cmd, struct video_device *vfd,
187 struct v4l2_buffer *p)
188{
189 struct v4l2_timecode *tc = &p->timecode;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300190 struct v4l2_plane *plane;
191 int i;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300192
193 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300194 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300195 p->timestamp.tv_sec / 3600,
196 (int)(p->timestamp.tv_sec / 60) % 60,
197 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300198 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300199 p->index,
200 prt_names(p->type, v4l2_type_names),
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300201 p->flags, p->field, p->sequence,
202 prt_names(p->memory, v4l2_memory_names));
203
204 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
205 for (i = 0; i < p->length; ++i) {
206 plane = &p->m.planes[i];
207 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
208 "offset/userptr=0x%08lx, length=%d\n",
209 i, plane->bytesused, plane->data_offset,
210 plane->m.userptr, plane->length);
211 }
212 } else {
213 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
214 p->bytesused, p->m.userptr, p->length);
215 }
216
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300217 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
218 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
219 tc->hours, tc->minutes, tc->seconds,
220 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
221}
222
223static inline void dbgrect(struct video_device *vfd, char *s,
224 struct v4l2_rect *r)
225{
226 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
227 r->width, r->height);
228};
229
Hans Verkuil5d7758e2012-05-15 08:06:44 -0300230static void dbgtimings(struct video_device *vfd,
231 const struct v4l2_dv_timings *p)
232{
233 switch (p->type) {
234 case V4L2_DV_BT_656_1120:
235 dbgarg2("bt-656/1120:interlaced=%d,"
236 " pixelclock=%lld,"
237 " width=%d, height=%d, polarities=%x,"
238 " hfrontporch=%d, hsync=%d,"
239 " hbackporch=%d, vfrontporch=%d,"
240 " vsync=%d, vbackporch=%d,"
241 " il_vfrontporch=%d, il_vsync=%d,"
242 " il_vbackporch=%d, standards=%x, flags=%x\n",
243 p->bt.interlaced, p->bt.pixelclock,
244 p->bt.width, p->bt.height,
245 p->bt.polarities, p->bt.hfrontporch,
246 p->bt.hsync, p->bt.hbackporch,
247 p->bt.vfrontporch, p->bt.vsync,
248 p->bt.vbackporch, p->bt.il_vfrontporch,
249 p->bt.il_vsync, p->bt.il_vbackporch,
250 p->bt.standards, p->bt.flags);
251 break;
252 default:
253 dbgarg2("Unknown type %d!\n", p->type);
254 break;
255 }
256}
257
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300258static inline void v4l_print_pix_fmt(struct video_device *vfd,
259 struct v4l2_pix_format *fmt)
260{
261 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
262 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
263 fmt->width, fmt->height,
264 (fmt->pixelformat & 0xff),
265 (fmt->pixelformat >> 8) & 0xff,
266 (fmt->pixelformat >> 16) & 0xff,
267 (fmt->pixelformat >> 24) & 0xff,
268 prt_names(fmt->field, v4l2_field_names),
269 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
270};
271
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300272static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
273 struct v4l2_pix_format_mplane *fmt)
274{
275 int i;
276
277 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
278 "colorspace=%d, num_planes=%d\n",
279 fmt->width, fmt->height,
280 (fmt->pixelformat & 0xff),
281 (fmt->pixelformat >> 8) & 0xff,
282 (fmt->pixelformat >> 16) & 0xff,
283 (fmt->pixelformat >> 24) & 0xff,
284 prt_names(fmt->field, v4l2_field_names),
285 fmt->colorspace, fmt->num_planes);
286
287 for (i = 0; i < fmt->num_planes; ++i)
288 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
289 fmt->plane_fmt[i].bytesperline,
290 fmt->plane_fmt[i].sizeimage);
291}
292
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300293static inline void v4l_print_ext_ctrls(unsigned int cmd,
294 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
295{
296 __u32 i;
297
298 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
299 return;
300 dbgarg(cmd, "");
301 printk(KERN_CONT "class=0x%x", c->ctrl_class);
302 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300303 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300304 printk(KERN_CONT " id/val=0x%x/0x%x",
305 c->controls[i].id, c->controls[i].value);
306 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300307 printk(KERN_CONT " id=0x%x,size=%u",
308 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300309 }
310 printk(KERN_CONT "\n");
311};
312
313static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
314{
315 __u32 i;
316
317 /* zero the reserved fields */
318 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300319 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300320 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300321
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300322 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
323 when using extended controls.
324 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
325 is it allowed for backwards compatibility.
326 */
327 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
328 return 0;
329 /* Check that all controls are from the same control class. */
330 for (i = 0; i < c->count; i++) {
331 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
332 c->error_idx = i;
333 return 0;
334 }
335 }
336 return 1;
337}
338
Hans Verkuila3998102008-07-21 02:57:38 -0300339static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300340{
Hans Verkuila3998102008-07-21 02:57:38 -0300341 if (ops == NULL)
342 return -EINVAL;
343
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300344 switch (type) {
345 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300346 if (ops->vidioc_g_fmt_vid_cap ||
347 ops->vidioc_g_fmt_vid_cap_mplane)
348 return 0;
349 break;
350 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
351 if (ops->vidioc_g_fmt_vid_cap_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300352 return 0;
353 break;
354 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300355 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300356 return 0;
357 break;
358 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300359 if (ops->vidioc_g_fmt_vid_out ||
360 ops->vidioc_g_fmt_vid_out_mplane)
361 return 0;
362 break;
363 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
364 if (ops->vidioc_g_fmt_vid_out_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300365 return 0;
366 break;
367 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300368 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300369 return 0;
370 break;
371 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300372 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300373 return 0;
374 break;
375 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300376 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300377 return 0;
378 break;
379 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300380 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300381 return 0;
382 break;
383 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300384 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300385 return 0;
386 break;
387 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300388 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300389 return 0;
390 break;
391 }
392 return -EINVAL;
393}
394
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300395struct v4l2_ioctl_info {
396 unsigned int ioctl;
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300397 u32 flags;
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300398 const char * const name;
399};
400
401/* This control needs a priority check */
402#define INFO_FL_PRIO (1 << 0)
403/* This control can be valid if the filehandle passes a control handler. */
404#define INFO_FL_CTRL (1 << 1)
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300405/* Zero struct from after the field to the end */
406#define INFO_FL_CLEAR(v4l2_struct, field) \
407 ((offsetof(struct v4l2_struct, field) + \
408 sizeof(((struct v4l2_struct *)0)->field)) << 16)
409#define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300410
411#define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = { \
412 .ioctl = _ioctl, \
413 .flags = _flags, \
414 .name = #_ioctl, \
415}
416
417static struct v4l2_ioctl_info v4l2_ioctls[] = {
418 IOCTL_INFO(VIDIOC_QUERYCAP, 0),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300419 IOCTL_INFO(VIDIOC_ENUM_FMT, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
420 IOCTL_INFO(VIDIOC_G_FMT, INFO_FL_CLEAR(v4l2_format, type)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300421 IOCTL_INFO(VIDIOC_S_FMT, INFO_FL_PRIO),
422 IOCTL_INFO(VIDIOC_REQBUFS, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300423 IOCTL_INFO(VIDIOC_QUERYBUF, INFO_FL_CLEAR(v4l2_buffer, length)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300424 IOCTL_INFO(VIDIOC_G_FBUF, 0),
425 IOCTL_INFO(VIDIOC_S_FBUF, INFO_FL_PRIO),
426 IOCTL_INFO(VIDIOC_OVERLAY, INFO_FL_PRIO),
427 IOCTL_INFO(VIDIOC_QBUF, 0),
428 IOCTL_INFO(VIDIOC_DQBUF, 0),
429 IOCTL_INFO(VIDIOC_STREAMON, INFO_FL_PRIO),
430 IOCTL_INFO(VIDIOC_STREAMOFF, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300431 IOCTL_INFO(VIDIOC_G_PARM, INFO_FL_CLEAR(v4l2_streamparm, type)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300432 IOCTL_INFO(VIDIOC_S_PARM, INFO_FL_PRIO),
433 IOCTL_INFO(VIDIOC_G_STD, 0),
434 IOCTL_INFO(VIDIOC_S_STD, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300435 IOCTL_INFO(VIDIOC_ENUMSTD, INFO_FL_CLEAR(v4l2_standard, index)),
436 IOCTL_INFO(VIDIOC_ENUMINPUT, INFO_FL_CLEAR(v4l2_input, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300437 IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL),
438 IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_PRIO | INFO_FL_CTRL),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300439 IOCTL_INFO(VIDIOC_G_TUNER, INFO_FL_CLEAR(v4l2_tuner, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300440 IOCTL_INFO(VIDIOC_S_TUNER, INFO_FL_PRIO),
441 IOCTL_INFO(VIDIOC_G_AUDIO, 0),
442 IOCTL_INFO(VIDIOC_S_AUDIO, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300443 IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
444 IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300445 IOCTL_INFO(VIDIOC_G_INPUT, 0),
446 IOCTL_INFO(VIDIOC_S_INPUT, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300447 IOCTL_INFO(VIDIOC_G_OUTPUT, INFO_FL_CLEAR(v4l2_output, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300448 IOCTL_INFO(VIDIOC_S_OUTPUT, INFO_FL_PRIO),
449 IOCTL_INFO(VIDIOC_ENUMOUTPUT, 0),
450 IOCTL_INFO(VIDIOC_G_AUDOUT, 0),
451 IOCTL_INFO(VIDIOC_S_AUDOUT, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300452 IOCTL_INFO(VIDIOC_G_MODULATOR, INFO_FL_CLEAR(v4l2_modulator, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300453 IOCTL_INFO(VIDIOC_S_MODULATOR, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300454 IOCTL_INFO(VIDIOC_G_FREQUENCY, INFO_FL_CLEAR(v4l2_frequency, tuner)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300455 IOCTL_INFO(VIDIOC_S_FREQUENCY, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300456 IOCTL_INFO(VIDIOC_CROPCAP, INFO_FL_CLEAR(v4l2_cropcap, type)),
457 IOCTL_INFO(VIDIOC_G_CROP, INFO_FL_CLEAR(v4l2_crop, type)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300458 IOCTL_INFO(VIDIOC_S_CROP, INFO_FL_PRIO),
459 IOCTL_INFO(VIDIOC_G_SELECTION, 0),
460 IOCTL_INFO(VIDIOC_S_SELECTION, INFO_FL_PRIO),
461 IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
462 IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
463 IOCTL_INFO(VIDIOC_QUERYSTD, 0),
464 IOCTL_INFO(VIDIOC_TRY_FMT, 0),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300465 IOCTL_INFO(VIDIOC_ENUMAUDIO, INFO_FL_CLEAR(v4l2_audio, index)),
466 IOCTL_INFO(VIDIOC_ENUMAUDOUT, INFO_FL_CLEAR(v4l2_audioout, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300467 IOCTL_INFO(VIDIOC_G_PRIORITY, 0),
468 IOCTL_INFO(VIDIOC_S_PRIORITY, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300469 IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300470 IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
471 IOCTL_INFO(VIDIOC_G_EXT_CTRLS, INFO_FL_CTRL),
472 IOCTL_INFO(VIDIOC_S_EXT_CTRLS, INFO_FL_PRIO | INFO_FL_CTRL),
473 IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, 0),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300474 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
475 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300476 IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300477 IOCTL_INFO(VIDIOC_ENCODER_CMD, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
478 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300479 IOCTL_INFO(VIDIOC_DECODER_CMD, INFO_FL_PRIO),
480 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0),
481#ifdef CONFIG_VIDEO_ADV_DEBUG
482 IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
483 IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
484#endif
485 IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
486 IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, INFO_FL_PRIO),
487 IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
488 IOCTL_INFO(VIDIOC_S_DV_PRESET, INFO_FL_PRIO),
489 IOCTL_INFO(VIDIOC_G_DV_PRESET, 0),
490 IOCTL_INFO(VIDIOC_QUERY_DV_PRESET, 0),
491 IOCTL_INFO(VIDIOC_S_DV_TIMINGS, INFO_FL_PRIO),
492 IOCTL_INFO(VIDIOC_G_DV_TIMINGS, 0),
493 IOCTL_INFO(VIDIOC_DQEVENT, 0),
494 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0),
495 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
496 IOCTL_INFO(VIDIOC_CREATE_BUFS, INFO_FL_PRIO),
497 IOCTL_INFO(VIDIOC_PREPARE_BUF, 0),
498 IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, 0),
499 IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, 0),
500 IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, 0),
501};
502#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
503
504bool v4l2_is_known_ioctl(unsigned int cmd)
505{
506 if (_IOC_NR(cmd) >= V4L2_IOCTLS)
507 return false;
508 return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
509}
510
511/* Common ioctl debug function. This function can be used by
512 external ioctl messages as well as internal V4L ioctl */
513void v4l_printk_ioctl(unsigned int cmd)
514{
515 char *dir, *type;
516
517 switch (_IOC_TYPE(cmd)) {
518 case 'd':
519 type = "v4l2_int";
520 break;
521 case 'V':
522 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
523 type = "v4l2";
524 break;
525 }
526 printk("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
527 return;
528 default:
529 type = "unknown";
530 }
531
532 switch (_IOC_DIR(cmd)) {
533 case _IOC_NONE: dir = "--"; break;
534 case _IOC_READ: dir = "r-"; break;
535 case _IOC_WRITE: dir = "-w"; break;
536 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
537 default: dir = "*ERR*"; break;
538 }
539 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
540 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
541}
542EXPORT_SYMBOL(v4l_printk_ioctl);
543
Hans Verkuil069b7472008-12-30 07:04:34 -0300544static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300545 unsigned int cmd, void *arg)
546{
547 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300548 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300549 void *fh = file->private_data;
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300550 struct v4l2_fh *vfh = NULL;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300551 int use_fh_prio = 0;
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300552 long ret = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300553
Hans Verkuil6a717882010-04-06 15:56:08 -0300554 if (ops == NULL) {
555 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
556 vfd->name);
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300557 return ret;
Hans Verkuil6a717882010-04-06 15:56:08 -0300558 }
559
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300560 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
561 vfh = file->private_data;
562 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300563 }
564
565 if (v4l2_is_known_ioctl(cmd)) {
566 struct v4l2_ioctl_info *info = &v4l2_ioctls[_IOC_NR(cmd)];
567
568 if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
569 !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
570 return -ENOTTY;
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300571
572 if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
573 ret = v4l2_prio_check(vfd->prio, vfh->prio);
574 if (ret)
575 return ret;
576 }
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300577 }
578
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300579 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
580 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
581 v4l_print_ioctl(vfd->name, cmd);
582 printk(KERN_CONT "\n");
583 }
584
Hans Verkuil6a717882010-04-06 15:56:08 -0300585 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300586
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300587 /* --- capabilities ------------------------------------------ */
588 case VIDIOC_QUERYCAP:
589 {
590 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300591
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -0300592 cap->version = LINUX_VERSION_CODE;
Hans Verkuila3998102008-07-21 02:57:38 -0300593 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300594 if (!ret)
595 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
596 "version=0x%08x, "
Hans Verkuil583aa3a2012-01-11 06:45:05 -0300597 "capabilities=0x%08x, "
598 "device_caps=0x%08x\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300599 cap->driver, cap->card, cap->bus_info,
600 cap->version,
Hans Verkuil583aa3a2012-01-11 06:45:05 -0300601 cap->capabilities,
602 cap->device_caps);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300603 break;
604 }
605
606 /* --- priority ------------------------------------------ */
607 case VIDIOC_G_PRIORITY:
608 {
609 enum v4l2_priority *p = arg;
610
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300611 if (ops->vidioc_g_priority) {
612 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300613 } else if (use_fh_prio) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300614 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
615 ret = 0;
616 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300617 if (!ret)
618 dbgarg(cmd, "priority is %d\n", *p);
619 break;
620 }
621 case VIDIOC_S_PRIORITY:
622 {
623 enum v4l2_priority *p = arg;
624
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300625 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300626 if (ops->vidioc_s_priority)
627 ret = ops->vidioc_s_priority(file, fh, *p);
628 else
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300629 ret = v4l2_prio_change(&vfd->v4l2_dev->prio,
Hans Verkuil93d5a302011-08-09 09:32:06 -0300630 &vfh->prio, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300631 break;
632 }
633
634 /* --- capture ioctls ---------------------------------------- */
635 case VIDIOC_ENUM_FMT:
636 {
637 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300638
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300639 ret = -EINVAL;
Trent Piepho19c96e42009-03-04 01:21:02 -0300640 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300641 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300642 if (likely(ops->vidioc_enum_fmt_vid_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300643 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300644 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300645 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300646 if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300647 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
648 fh, f);
649 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300650 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300651 if (likely(ops->vidioc_enum_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300652 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300653 fh, f);
654 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300655 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300656 if (likely(ops->vidioc_enum_fmt_vid_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300657 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300658 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300659 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300660 if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300661 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
662 fh, f);
663 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300664 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300665 if (likely(ops->vidioc_enum_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300666 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300667 fh, f);
668 break;
669 default:
670 break;
671 }
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300672 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300673 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
674 "pixelformat=%c%c%c%c, description='%s'\n",
675 f->index, f->type, f->flags,
676 (f->pixelformat & 0xff),
677 (f->pixelformat >> 8) & 0xff,
678 (f->pixelformat >> 16) & 0xff,
679 (f->pixelformat >> 24) & 0xff,
680 f->description);
681 break;
682 }
683 case VIDIOC_G_FMT:
684 {
685 struct v4l2_format *f = (struct v4l2_format *)arg;
686
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300687 /* FIXME: Should be one dump per type */
688 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
689
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300690 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300691 switch (f->type) {
692 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300693 if (ops->vidioc_g_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300694 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300695 if (!ret)
696 v4l_print_pix_fmt(vfd, &f->fmt.pix);
697 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300698 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300699 if (ops->vidioc_g_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300700 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
701 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300702 if (!ret)
703 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
704 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300705 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300706 if (likely(ops->vidioc_g_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300707 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300708 fh, f);
709 break;
710 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300711 if (ops->vidioc_g_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300712 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300713 if (!ret)
714 v4l_print_pix_fmt(vfd, &f->fmt.pix);
715 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300716 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300717 if (ops->vidioc_g_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300718 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
719 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300720 if (!ret)
721 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
722 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300723 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300724 if (likely(ops->vidioc_g_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300725 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300726 fh, f);
727 break;
728 case V4L2_BUF_TYPE_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300729 if (likely(ops->vidioc_g_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300730 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300731 break;
732 case V4L2_BUF_TYPE_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300733 if (likely(ops->vidioc_g_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300734 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300735 break;
736 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300737 if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300738 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300739 fh, f);
740 break;
741 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300742 if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300743 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300744 fh, f);
745 break;
746 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300747 if (likely(ops->vidioc_g_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300748 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300749 fh, f);
750 break;
751 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300752 break;
753 }
754 case VIDIOC_S_FMT:
755 {
756 struct v4l2_format *f = (struct v4l2_format *)arg;
757
Hans Verkuil93d5a302011-08-09 09:32:06 -0300758 ret = -EINVAL;
759
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300760 /* FIXME: Should be one dump per type */
761 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
762
763 switch (f->type) {
764 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300765 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300766 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300767 if (ops->vidioc_s_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300768 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300769 break;
770 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
771 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
772 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300773 if (ops->vidioc_s_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300774 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
775 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300776 break;
777 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300778 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300779 if (ops->vidioc_s_fmt_vid_overlay)
780 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300781 fh, f);
782 break;
783 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300784 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300785 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300786 if (ops->vidioc_s_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300787 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300788 break;
789 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
790 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
791 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300792 if (ops->vidioc_s_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300793 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
794 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300795 break;
796 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300797 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300798 if (ops->vidioc_s_fmt_vid_out_overlay)
799 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300800 fh, f);
801 break;
802 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300803 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300804 if (likely(ops->vidioc_s_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300805 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300806 break;
807 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300808 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300809 if (likely(ops->vidioc_s_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300810 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300811 break;
812 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300813 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300814 if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300815 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300816 fh, f);
817 break;
818 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300819 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300820 if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300821 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300822 fh, f);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300823
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300824 break;
825 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300826 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300827 if (likely(ops->vidioc_s_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300828 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300829 fh, f);
830 break;
831 }
832 break;
833 }
834 case VIDIOC_TRY_FMT:
835 {
836 struct v4l2_format *f = (struct v4l2_format *)arg;
837
838 /* FIXME: Should be one dump per type */
839 dbgarg(cmd, "type=%s\n", prt_names(f->type,
840 v4l2_type_names));
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300841 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300842 switch (f->type) {
843 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300844 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300845 if (ops->vidioc_try_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300846 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300847 if (!ret)
848 v4l_print_pix_fmt(vfd, &f->fmt.pix);
849 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300850 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
851 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300852 if (ops->vidioc_try_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300853 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
854 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300855 if (!ret)
856 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
857 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300858 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300859 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300860 if (likely(ops->vidioc_try_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300861 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300862 fh, f);
863 break;
864 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300865 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300866 if (ops->vidioc_try_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300867 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300868 if (!ret)
869 v4l_print_pix_fmt(vfd, &f->fmt.pix);
870 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300871 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
872 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300873 if (ops->vidioc_try_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300874 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
875 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300876 if (!ret)
877 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
878 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300879 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300880 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300881 if (likely(ops->vidioc_try_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300882 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300883 fh, f);
884 break;
885 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300886 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300887 if (likely(ops->vidioc_try_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300888 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300889 break;
890 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300891 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300892 if (likely(ops->vidioc_try_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300893 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300894 break;
895 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300896 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300897 if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300898 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300899 fh, f);
900 break;
901 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300902 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300903 if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300904 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300905 fh, f);
906 break;
907 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300908 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300909 if (likely(ops->vidioc_try_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300910 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300911 fh, f);
912 break;
913 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300914 break;
915 }
916 /* FIXME: Those buf reqs could be handled here,
917 with some changes on videobuf to allow its header to be included at
918 videodev2.h or being merged at videodev2.
919 */
920 case VIDIOC_REQBUFS:
921 {
922 struct v4l2_requestbuffers *p = arg;
923
Hans Verkuila3998102008-07-21 02:57:38 -0300924 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300925 if (ret)
926 break;
927
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300928 if (p->type < V4L2_BUF_TYPE_PRIVATE)
929 CLEAR_AFTER_FIELD(p, memory);
930
Hans Verkuila3998102008-07-21 02:57:38 -0300931 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300932 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
933 p->count,
934 prt_names(p->type, v4l2_type_names),
935 prt_names(p->memory, v4l2_memory_names));
936 break;
937 }
938 case VIDIOC_QUERYBUF:
939 {
940 struct v4l2_buffer *p = arg;
941
Hans Verkuila3998102008-07-21 02:57:38 -0300942 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300943 if (ret)
944 break;
945
Hans Verkuila3998102008-07-21 02:57:38 -0300946 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300947 if (!ret)
948 dbgbuf(cmd, vfd, p);
949 break;
950 }
951 case VIDIOC_QBUF:
952 {
953 struct v4l2_buffer *p = arg;
954
Hans Verkuila3998102008-07-21 02:57:38 -0300955 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300956 if (ret)
957 break;
958
Hans Verkuila3998102008-07-21 02:57:38 -0300959 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300960 if (!ret)
961 dbgbuf(cmd, vfd, p);
962 break;
963 }
964 case VIDIOC_DQBUF:
965 {
966 struct v4l2_buffer *p = arg;
967
Hans Verkuila3998102008-07-21 02:57:38 -0300968 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300969 if (ret)
970 break;
971
Hans Verkuila3998102008-07-21 02:57:38 -0300972 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300973 if (!ret)
974 dbgbuf(cmd, vfd, p);
975 break;
976 }
977 case VIDIOC_OVERLAY:
978 {
979 int *i = arg;
980
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300981 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -0300982 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300983 break;
984 }
985 case VIDIOC_G_FBUF:
986 {
987 struct v4l2_framebuffer *p = arg;
988
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 Verkuil35ea11f2008-07-20 08:12:02 -03001002 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1003 p->capability, p->flags, (unsigned long)p->base);
1004 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -03001005 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001006 break;
1007 }
1008 case VIDIOC_STREAMON:
1009 {
1010 enum v4l2_buf_type i = *(int *)arg;
1011
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001012 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001013 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001014 break;
1015 }
1016 case VIDIOC_STREAMOFF:
1017 {
1018 enum v4l2_buf_type i = *(int *)arg;
1019
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001020 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001021 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001022 break;
1023 }
1024 /* ---------- tv norms ---------- */
1025 case VIDIOC_ENUMSTD:
1026 {
1027 struct v4l2_standard *p = arg;
1028 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1029 unsigned int index = p->index, i, j = 0;
1030 const char *descr = "";
1031
Hans Verkuil93d5a302011-08-09 09:32:06 -03001032 if (id == 0)
1033 break;
1034 ret = -EINVAL;
1035
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001036 /* Return norm array in a canonical way */
1037 for (i = 0; i <= index && id; i++) {
1038 /* last std value in the standards array is 0, so this
1039 while always ends there since (id & 0) == 0. */
1040 while ((id & standards[j].std) != standards[j].std)
1041 j++;
1042 curr_id = standards[j].std;
1043 descr = standards[j].descr;
1044 j++;
1045 if (curr_id == 0)
1046 break;
1047 if (curr_id != V4L2_STD_PAL &&
1048 curr_id != V4L2_STD_SECAM &&
1049 curr_id != V4L2_STD_NTSC)
1050 id &= ~curr_id;
1051 }
1052 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001053 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001054
1055 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001056
1057 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1058 "framelines=%d\n", p->index,
1059 (unsigned long long)p->id, p->name,
1060 p->frameperiod.numerator,
1061 p->frameperiod.denominator,
1062 p->framelines);
1063
1064 ret = 0;
1065 break;
1066 }
1067 case VIDIOC_G_STD:
1068 {
1069 v4l2_std_id *id = arg;
1070
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001071 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001072 if (ops->vidioc_g_std)
1073 ret = ops->vidioc_g_std(file, fh, id);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001074 else if (vfd->current_norm) {
1075 ret = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001076 *id = vfd->current_norm;
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001077 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001078
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001079 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001080 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1081 break;
1082 }
1083 case VIDIOC_S_STD:
1084 {
1085 v4l2_std_id *id = arg, norm;
1086
1087 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1088
Hans Verkuil93d5a302011-08-09 09:32:06 -03001089 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001090 norm = (*id) & vfd->tvnorms;
1091 if (vfd->tvnorms && !norm) /* Check if std is supported */
1092 break;
1093
1094 /* Calls the specific handler */
Hans Verkuil93d5a302011-08-09 09:32:06 -03001095 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001096
1097 /* Updates standard information */
1098 if (ret >= 0)
1099 vfd->current_norm = norm;
1100 break;
1101 }
1102 case VIDIOC_QUERYSTD:
1103 {
1104 v4l2_std_id *p = arg;
1105
Mauro Carvalho Chehab8715e6c2011-10-04 09:32:23 -03001106 /*
1107 * If nothing detected, it should return all supported
1108 * Drivers just need to mask the std argument, in order
1109 * to remove the standards that don't apply from the mask.
1110 * This means that tuners, audio and video decoders can join
1111 * their efforts to improve the standards detection
1112 */
1113 *p = vfd->tvnorms;
Hans Verkuila3998102008-07-21 02:57:38 -03001114 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001115 if (!ret)
1116 dbgarg(cmd, "detected std=%08Lx\n",
1117 (unsigned long long)*p);
1118 break;
1119 }
1120 /* ------ input switching ---------- */
1121 /* FIXME: Inputs can be handled inside videodev2 */
1122 case VIDIOC_ENUMINPUT:
1123 {
1124 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001125
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001126 /*
1127 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1128 * CAP_STD here based on ioctl handler provided by the
1129 * driver. If the driver doesn't support these
1130 * for a specific input, it must override these flags.
1131 */
1132 if (ops->vidioc_s_std)
1133 p->capabilities |= V4L2_IN_CAP_STD;
1134 if (ops->vidioc_s_dv_preset)
1135 p->capabilities |= V4L2_IN_CAP_PRESETS;
1136 if (ops->vidioc_s_dv_timings)
1137 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1138
Hans Verkuila3998102008-07-21 02:57:38 -03001139 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001140 if (!ret)
1141 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1142 "audioset=%d, "
1143 "tuner=%d, std=%08Lx, status=%d\n",
1144 p->index, p->name, p->type, p->audioset,
1145 p->tuner,
1146 (unsigned long long)p->std,
1147 p->status);
1148 break;
1149 }
1150 case VIDIOC_G_INPUT:
1151 {
1152 unsigned int *i = arg;
1153
Hans Verkuila3998102008-07-21 02:57:38 -03001154 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001155 if (!ret)
1156 dbgarg(cmd, "value=%d\n", *i);
1157 break;
1158 }
1159 case VIDIOC_S_INPUT:
1160 {
1161 unsigned int *i = arg;
1162
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001163 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001164 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001165 break;
1166 }
1167
1168 /* ------ output switching ---------- */
1169 case VIDIOC_ENUMOUTPUT:
1170 {
1171 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001172
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001173 /*
1174 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1175 * CAP_STD here based on ioctl handler provided by the
1176 * driver. If the driver doesn't support these
1177 * for a specific output, it must override these flags.
1178 */
1179 if (ops->vidioc_s_std)
1180 p->capabilities |= V4L2_OUT_CAP_STD;
1181 if (ops->vidioc_s_dv_preset)
1182 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1183 if (ops->vidioc_s_dv_timings)
1184 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1185
Hans Verkuila3998102008-07-21 02:57:38 -03001186 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001187 if (!ret)
1188 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1189 "audioset=0x%x, "
1190 "modulator=%d, std=0x%08Lx\n",
1191 p->index, p->name, p->type, p->audioset,
1192 p->modulator, (unsigned long long)p->std);
1193 break;
1194 }
1195 case VIDIOC_G_OUTPUT:
1196 {
1197 unsigned int *i = arg;
1198
Hans Verkuila3998102008-07-21 02:57:38 -03001199 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001200 if (!ret)
1201 dbgarg(cmd, "value=%d\n", *i);
1202 break;
1203 }
1204 case VIDIOC_S_OUTPUT:
1205 {
1206 unsigned int *i = arg;
1207
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001208 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001209 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001210 break;
1211 }
1212
1213 /* --- controls ---------------------------------------------- */
1214 case VIDIOC_QUERYCTRL:
1215 {
1216 struct v4l2_queryctrl *p = arg;
1217
Hans Verkuil2d28b682011-03-12 08:54:43 -03001218 if (vfh && vfh->ctrl_handler)
1219 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1220 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001221 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1222 else if (ops->vidioc_queryctrl)
1223 ret = ops->vidioc_queryctrl(file, fh, p);
1224 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001225 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001226 if (!ret)
1227 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1228 "step=%d, default=%d, flags=0x%08x\n",
1229 p->id, p->type, p->name,
1230 p->minimum, p->maximum,
1231 p->step, p->default_value, p->flags);
1232 else
1233 dbgarg(cmd, "id=0x%x\n", p->id);
1234 break;
1235 }
1236 case VIDIOC_G_CTRL:
1237 {
1238 struct v4l2_control *p = arg;
1239
Hans Verkuil2d28b682011-03-12 08:54:43 -03001240 if (vfh && vfh->ctrl_handler)
1241 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1242 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001243 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1244 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001245 ret = ops->vidioc_g_ctrl(file, fh, p);
1246 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001247 struct v4l2_ext_controls ctrls;
1248 struct v4l2_ext_control ctrl;
1249
1250 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1251 ctrls.count = 1;
1252 ctrls.controls = &ctrl;
1253 ctrl.id = p->id;
1254 ctrl.value = p->value;
1255 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001256 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001257 if (ret == 0)
1258 p->value = ctrl.value;
1259 }
1260 } else
1261 break;
1262 if (!ret)
1263 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1264 else
1265 dbgarg(cmd, "id=0x%x\n", p->id);
1266 break;
1267 }
1268 case VIDIOC_S_CTRL:
1269 {
1270 struct v4l2_control *p = arg;
1271 struct v4l2_ext_controls ctrls;
1272 struct v4l2_ext_control ctrl;
1273
Hans Verkuil2d28b682011-03-12 08:54:43 -03001274 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001275 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001276 break;
1277
1278 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1279
Hans Verkuil2d28b682011-03-12 08:54:43 -03001280 if (vfh && vfh->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001281 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001282 break;
1283 }
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001284 if (vfd->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001285 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001286 break;
1287 }
Hans Verkuila3998102008-07-21 02:57:38 -03001288 if (ops->vidioc_s_ctrl) {
1289 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001290 break;
1291 }
Hans Verkuila3998102008-07-21 02:57:38 -03001292 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001293 break;
1294
1295 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1296 ctrls.count = 1;
1297 ctrls.controls = &ctrl;
1298 ctrl.id = p->id;
1299 ctrl.value = p->value;
1300 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001301 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001302 else
1303 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001304 break;
1305 }
1306 case VIDIOC_G_EXT_CTRLS:
1307 {
1308 struct v4l2_ext_controls *p = arg;
1309
1310 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001311 if (vfh && vfh->ctrl_handler)
1312 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1313 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001314 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001315 else if (ops->vidioc_g_ext_ctrls)
1316 ret = check_ext_ctrls(p, 0) ?
1317 ops->vidioc_g_ext_ctrls(file, fh, p) :
1318 -EINVAL;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001319 else
1320 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001321 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1322 break;
1323 }
1324 case VIDIOC_S_EXT_CTRLS:
1325 {
1326 struct v4l2_ext_controls *p = arg;
1327
1328 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001329 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1330 !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001331 break;
1332 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001333 if (vfh && vfh->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001334 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001335 else if (vfd->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001336 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001337 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001338 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001339 else
1340 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001341 break;
1342 }
1343 case VIDIOC_TRY_EXT_CTRLS:
1344 {
1345 struct v4l2_ext_controls *p = arg;
1346
1347 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001348 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1349 !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001350 break;
1351 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001352 if (vfh && vfh->ctrl_handler)
1353 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1354 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001355 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1356 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001357 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001358 else
1359 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001360 break;
1361 }
1362 case VIDIOC_QUERYMENU:
1363 {
1364 struct v4l2_querymenu *p = arg;
1365
Hans Verkuil2d28b682011-03-12 08:54:43 -03001366 if (vfh && vfh->ctrl_handler)
1367 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1368 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001369 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1370 else if (ops->vidioc_querymenu)
1371 ret = ops->vidioc_querymenu(file, fh, p);
1372 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001373 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001374 if (!ret)
1375 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1376 p->id, p->index, p->name);
1377 else
1378 dbgarg(cmd, "id=0x%x, index=%d\n",
1379 p->id, p->index);
1380 break;
1381 }
1382 /* --- audio ---------------------------------------------- */
1383 case VIDIOC_ENUMAUDIO:
1384 {
1385 struct v4l2_audio *p = arg;
1386
Hans Verkuila3998102008-07-21 02:57:38 -03001387 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001388 if (!ret)
1389 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1390 "mode=0x%x\n", p->index, p->name,
1391 p->capability, p->mode);
1392 else
1393 dbgarg(cmd, "index=%d\n", p->index);
1394 break;
1395 }
1396 case VIDIOC_G_AUDIO:
1397 {
1398 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001399
Hans Verkuila3998102008-07-21 02:57:38 -03001400 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001401 if (!ret)
1402 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1403 "mode=0x%x\n", p->index,
1404 p->name, p->capability, p->mode);
1405 else
1406 dbgarg(cmd, "index=%d\n", p->index);
1407 break;
1408 }
1409 case VIDIOC_S_AUDIO:
1410 {
1411 struct v4l2_audio *p = arg;
1412
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001413 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1414 "mode=0x%x\n", p->index, p->name,
1415 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001416 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001417 break;
1418 }
1419 case VIDIOC_ENUMAUDOUT:
1420 {
1421 struct v4l2_audioout *p = arg;
1422
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001423 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001424 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001425 if (!ret)
1426 dbgarg2("index=%d, name=%s, capability=%d, "
1427 "mode=%d\n", p->index, p->name,
1428 p->capability, p->mode);
1429 break;
1430 }
1431 case VIDIOC_G_AUDOUT:
1432 {
1433 struct v4l2_audioout *p = arg;
1434
Hans Verkuila3998102008-07-21 02:57:38 -03001435 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001436 if (!ret)
1437 dbgarg2("index=%d, name=%s, capability=%d, "
1438 "mode=%d\n", p->index, p->name,
1439 p->capability, p->mode);
1440 break;
1441 }
1442 case VIDIOC_S_AUDOUT:
1443 {
1444 struct v4l2_audioout *p = arg;
1445
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001446 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1447 "mode=%d\n", p->index, p->name,
1448 p->capability, p->mode);
1449
Hans Verkuila3998102008-07-21 02:57:38 -03001450 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001451 break;
1452 }
1453 case VIDIOC_G_MODULATOR:
1454 {
1455 struct v4l2_modulator *p = arg;
1456
Hans Verkuila3998102008-07-21 02:57:38 -03001457 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001458 if (!ret)
1459 dbgarg(cmd, "index=%d, name=%s, "
1460 "capability=%d, rangelow=%d,"
1461 " rangehigh=%d, txsubchans=%d\n",
1462 p->index, p->name, p->capability,
1463 p->rangelow, p->rangehigh,
1464 p->txsubchans);
1465 break;
1466 }
1467 case VIDIOC_S_MODULATOR:
1468 {
1469 struct v4l2_modulator *p = arg;
1470
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001471 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1472 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1473 p->index, p->name, p->capability, p->rangelow,
1474 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001475 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001476 break;
1477 }
1478 case VIDIOC_G_CROP:
1479 {
1480 struct v4l2_crop *p = arg;
1481
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001482 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001483
1484 if (ops->vidioc_g_crop) {
1485 ret = ops->vidioc_g_crop(file, fh, p);
1486 } else {
1487 /* simulate capture crop using selection api */
1488 struct v4l2_selection s = {
1489 .type = p->type,
1490 };
1491
1492 /* crop means compose for output devices */
1493 if (V4L2_TYPE_IS_OUTPUT(p->type))
1494 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1495 else
1496 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1497
1498 ret = ops->vidioc_g_selection(file, fh, &s);
1499
1500 /* copying results to old structure on success */
1501 if (!ret)
1502 p->c = s.r;
1503 }
1504
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001505 if (!ret)
1506 dbgrect(vfd, "", &p->c);
1507 break;
1508 }
1509 case VIDIOC_S_CROP:
1510 {
1511 struct v4l2_crop *p = arg;
1512
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001513 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1514 dbgrect(vfd, "", &p->c);
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001515
1516 if (ops->vidioc_s_crop) {
1517 ret = ops->vidioc_s_crop(file, fh, p);
1518 } else {
1519 /* simulate capture crop using selection api */
1520 struct v4l2_selection s = {
1521 .type = p->type,
1522 .r = p->c,
1523 };
1524
1525 /* crop means compose for output devices */
1526 if (V4L2_TYPE_IS_OUTPUT(p->type))
1527 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1528 else
1529 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1530
1531 ret = ops->vidioc_s_selection(file, fh, &s);
1532 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001533 break;
1534 }
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001535 case VIDIOC_G_SELECTION:
1536 {
1537 struct v4l2_selection *p = arg;
1538
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001539 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1540
1541 ret = ops->vidioc_g_selection(file, fh, p);
1542 if (!ret)
1543 dbgrect(vfd, "", &p->r);
1544 break;
1545 }
1546 case VIDIOC_S_SELECTION:
1547 {
1548 struct v4l2_selection *p = arg;
1549
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001550
1551 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1552 dbgrect(vfd, "", &p->r);
1553
1554 ret = ops->vidioc_s_selection(file, fh, p);
1555 break;
1556 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001557 case VIDIOC_CROPCAP:
1558 {
1559 struct v4l2_cropcap *p = arg;
1560
1561 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001562 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001563 if (ops->vidioc_cropcap) {
1564 ret = ops->vidioc_cropcap(file, fh, p);
1565 } else {
1566 struct v4l2_selection s = { .type = p->type };
1567
1568 /* obtaining bounds */
1569 if (V4L2_TYPE_IS_OUTPUT(p->type))
1570 s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
1571 else
1572 s.target = V4L2_SEL_TGT_CROP_BOUNDS;
1573
1574 ret = ops->vidioc_g_selection(file, fh, &s);
1575 if (ret)
1576 break;
1577 p->bounds = s.r;
1578
1579 /* obtaining defrect */
1580 if (V4L2_TYPE_IS_OUTPUT(p->type))
1581 s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
1582 else
1583 s.target = V4L2_SEL_TGT_CROP_DEFAULT;
1584
1585 ret = ops->vidioc_g_selection(file, fh, &s);
1586 if (ret)
1587 break;
1588 p->defrect = s.r;
1589
1590 /* setting trivial pixelaspect */
1591 p->pixelaspect.numerator = 1;
1592 p->pixelaspect.denominator = 1;
1593 }
1594
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001595 if (!ret) {
1596 dbgrect(vfd, "bounds ", &p->bounds);
1597 dbgrect(vfd, "defrect ", &p->defrect);
1598 }
1599 break;
1600 }
1601 case VIDIOC_G_JPEGCOMP:
1602 {
1603 struct v4l2_jpegcompression *p = arg;
1604
Hans Verkuila3998102008-07-21 02:57:38 -03001605 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001606 if (!ret)
1607 dbgarg(cmd, "quality=%d, APPn=%d, "
1608 "APP_len=%d, COM_len=%d, "
1609 "jpeg_markers=%d\n",
1610 p->quality, p->APPn, p->APP_len,
1611 p->COM_len, p->jpeg_markers);
1612 break;
1613 }
1614 case VIDIOC_S_JPEGCOMP:
1615 {
1616 struct v4l2_jpegcompression *p = arg;
1617
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001618 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1619 "COM_len=%d, jpeg_markers=%d\n",
1620 p->quality, p->APPn, p->APP_len,
1621 p->COM_len, p->jpeg_markers);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001622 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001623 break;
1624 }
1625 case VIDIOC_G_ENC_INDEX:
1626 {
1627 struct v4l2_enc_idx *p = arg;
1628
Hans Verkuila3998102008-07-21 02:57:38 -03001629 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001630 if (!ret)
1631 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1632 p->entries, p->entries_cap);
1633 break;
1634 }
1635 case VIDIOC_ENCODER_CMD:
1636 {
1637 struct v4l2_encoder_cmd *p = arg;
1638
Hans Verkuila3998102008-07-21 02:57:38 -03001639 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001640 if (!ret)
1641 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1642 break;
1643 }
1644 case VIDIOC_TRY_ENCODER_CMD:
1645 {
1646 struct v4l2_encoder_cmd *p = arg;
1647
Hans Verkuila3998102008-07-21 02:57:38 -03001648 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001649 if (!ret)
1650 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1651 break;
1652 }
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001653 case VIDIOC_DECODER_CMD:
1654 {
1655 struct v4l2_decoder_cmd *p = arg;
1656
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001657 ret = ops->vidioc_decoder_cmd(file, fh, p);
1658 if (!ret)
1659 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1660 break;
1661 }
1662 case VIDIOC_TRY_DECODER_CMD:
1663 {
1664 struct v4l2_decoder_cmd *p = arg;
1665
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001666 ret = ops->vidioc_try_decoder_cmd(file, fh, p);
1667 if (!ret)
1668 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1669 break;
1670 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001671 case VIDIOC_G_PARM:
1672 {
1673 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001674
Hans Verkuila3998102008-07-21 02:57:38 -03001675 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001676 ret = check_fmt(ops, p->type);
1677 if (ret)
1678 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001679 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001680 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001681 v4l2_std_id std = vfd->current_norm;
1682
Hans Verkuil93d5a302011-08-09 09:32:06 -03001683 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001684 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001685 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001686
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001687 ret = 0;
Hans Verkuil0c142c82012-05-25 11:51:31 -03001688 p->parm.capture.readbuffers = 2;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001689 if (ops->vidioc_g_std)
1690 ret = ops->vidioc_g_std(file, fh, &std);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001691 if (ret == 0)
1692 v4l2_video_std_frame_period(std,
1693 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001694 }
1695
1696 dbgarg(cmd, "type=%d\n", p->type);
1697 break;
1698 }
1699 case VIDIOC_S_PARM:
1700 {
1701 struct v4l2_streamparm *p = arg;
1702
Trent Piepho34796bc2009-03-28 22:25:35 -03001703 ret = check_fmt(ops, p->type);
1704 if (ret)
1705 break;
1706
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001707 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001708 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001709 break;
1710 }
1711 case VIDIOC_G_TUNER:
1712 {
1713 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001714
Hans Verkuil227690d2011-06-12 06:36:41 -03001715 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1716 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001717 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001718 if (!ret)
1719 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1720 "capability=0x%x, rangelow=%d, "
1721 "rangehigh=%d, signal=%d, afc=%d, "
1722 "rxsubchans=0x%x, audmode=%d\n",
1723 p->index, p->name, p->type,
1724 p->capability, p->rangelow,
1725 p->rangehigh, p->signal, p->afc,
1726 p->rxsubchans, p->audmode);
1727 break;
1728 }
1729 case VIDIOC_S_TUNER:
1730 {
1731 struct v4l2_tuner *p = arg;
1732
Hans Verkuil227690d2011-06-12 06:36:41 -03001733 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1734 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001735 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1736 "capability=0x%x, rangelow=%d, "
1737 "rangehigh=%d, signal=%d, afc=%d, "
1738 "rxsubchans=0x%x, audmode=%d\n",
1739 p->index, p->name, p->type,
1740 p->capability, p->rangelow,
1741 p->rangehigh, p->signal, p->afc,
1742 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001743 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001744 break;
1745 }
1746 case VIDIOC_G_FREQUENCY:
1747 {
1748 struct v4l2_frequency *p = arg;
1749
Hans Verkuil227690d2011-06-12 06:36:41 -03001750 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1751 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001752 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001753 if (!ret)
1754 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1755 p->tuner, p->type, p->frequency);
1756 break;
1757 }
1758 case VIDIOC_S_FREQUENCY:
1759 {
1760 struct v4l2_frequency *p = arg;
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001761 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001762
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001763 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1764 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001765 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1766 p->tuner, p->type, p->frequency);
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001767 if (p->type != type)
1768 ret = -EINVAL;
1769 else
1770 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001771 break;
1772 }
1773 case VIDIOC_G_SLICED_VBI_CAP:
1774 {
1775 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001776
Trent Piepho19c96e42009-03-04 01:21:02 -03001777 /* Clear up to type, everything after type is zerod already */
1778 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1779
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001780 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001781 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001782 if (!ret)
1783 dbgarg2("service_set=%d\n", p->service_set);
1784 break;
1785 }
1786 case VIDIOC_LOG_STATUS:
1787 {
Hans Verkuile2ecb252012-02-02 08:20:53 -03001788 if (vfd->v4l2_dev)
1789 pr_info("%s: ================= START STATUS =================\n",
1790 vfd->v4l2_dev->name);
Hans Verkuila3998102008-07-21 02:57:38 -03001791 ret = ops->vidioc_log_status(file, fh);
Hans Verkuile2ecb252012-02-02 08:20:53 -03001792 if (vfd->v4l2_dev)
1793 pr_info("%s: ================== END STATUS ==================\n",
1794 vfd->v4l2_dev->name);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001795 break;
1796 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001797 case VIDIOC_DBG_G_REGISTER:
1798 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001799#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001800 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001801
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001802 if (!capable(CAP_SYS_ADMIN))
1803 ret = -EPERM;
1804 else
1805 ret = ops->vidioc_g_register(file, fh, p);
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001806#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001807 break;
1808 }
1809 case VIDIOC_DBG_S_REGISTER:
1810 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001811#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001812 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001813
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001814 if (!capable(CAP_SYS_ADMIN))
1815 ret = -EPERM;
1816 else
1817 ret = ops->vidioc_s_register(file, fh, p);
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001818#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001819 break;
1820 }
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001821 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001822 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001823 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001824
Hans Verkuil80b36e02009-02-07 11:00:02 -03001825 p->ident = V4L2_IDENT_NONE;
1826 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001827 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001828 if (!ret)
1829 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1830 break;
1831 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001832 case VIDIOC_S_HW_FREQ_SEEK:
1833 {
1834 struct v4l2_hw_freq_seek *p = arg;
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001835 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001836
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001837 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1838 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001839 dbgarg(cmd,
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001840 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1841 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1842 if (p->type != type)
1843 ret = -EINVAL;
1844 else
1845 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
Hans Verkuila3998102008-07-21 02:57:38 -03001846 break;
1847 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001848 case VIDIOC_ENUM_FRAMESIZES:
1849 {
1850 struct v4l2_frmsizeenum *p = arg;
1851
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001852 ret = ops->vidioc_enum_framesizes(file, fh, p);
1853 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001854 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1855 p->index,
1856 (p->pixel_format & 0xff),
1857 (p->pixel_format >> 8) & 0xff,
1858 (p->pixel_format >> 16) & 0xff,
1859 (p->pixel_format >> 24) & 0xff,
1860 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001861 switch (p->type) {
1862 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001863 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001864 p->discrete.width, p->discrete.height);
1865 break;
1866 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001867 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001868 p->stepwise.min_width, p->stepwise.min_height,
1869 p->stepwise.step_width, p->stepwise.step_height,
1870 p->stepwise.max_width, p->stepwise.max_height);
1871 break;
1872 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001873 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001874 break;
1875 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001876 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001877 }
1878
1879 break;
1880 }
1881 case VIDIOC_ENUM_FRAMEINTERVALS:
1882 {
1883 struct v4l2_frmivalenum *p = arg;
1884
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001885 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1886 dbgarg(cmd,
1887 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1888 p->index, p->pixel_format,
1889 p->width, p->height, p->type);
1890 switch (p->type) {
1891 case V4L2_FRMIVAL_TYPE_DISCRETE:
1892 dbgarg2("fps=%d/%d\n",
1893 p->discrete.numerator,
1894 p->discrete.denominator);
1895 break;
1896 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03001897 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1898 p->stepwise.min.numerator,
1899 p->stepwise.min.denominator,
1900 p->stepwise.max.numerator,
1901 p->stepwise.max.denominator,
1902 p->stepwise.step.numerator,
1903 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001904 break;
1905 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1906 dbgarg2("continuous\n");
1907 break;
1908 default:
1909 dbgarg2("- Unknown type!\n");
1910 }
1911 break;
1912 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001913 case VIDIOC_ENUM_DV_PRESETS:
1914 {
1915 struct v4l2_dv_enum_preset *p = arg;
1916
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001917 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1918 if (!ret)
1919 dbgarg(cmd,
1920 "index=%d, preset=%d, name=%s, width=%d,"
1921 " height=%d ",
1922 p->index, p->preset, p->name, p->width,
1923 p->height);
1924 break;
1925 }
1926 case VIDIOC_S_DV_PRESET:
1927 {
1928 struct v4l2_dv_preset *p = arg;
1929
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001930 dbgarg(cmd, "preset=%d\n", p->preset);
1931 ret = ops->vidioc_s_dv_preset(file, fh, p);
1932 break;
1933 }
1934 case VIDIOC_G_DV_PRESET:
1935 {
1936 struct v4l2_dv_preset *p = arg;
1937
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001938 ret = ops->vidioc_g_dv_preset(file, fh, p);
1939 if (!ret)
1940 dbgarg(cmd, "preset=%d\n", p->preset);
1941 break;
1942 }
1943 case VIDIOC_QUERY_DV_PRESET:
1944 {
1945 struct v4l2_dv_preset *p = arg;
1946
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001947 ret = ops->vidioc_query_dv_preset(file, fh, p);
1948 if (!ret)
1949 dbgarg(cmd, "preset=%d\n", p->preset);
1950 break;
1951 }
1952 case VIDIOC_S_DV_TIMINGS:
1953 {
1954 struct v4l2_dv_timings *p = arg;
1955
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001956 dbgtimings(vfd, p);
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001957 switch (p->type) {
1958 case V4L2_DV_BT_656_1120:
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001959 ret = ops->vidioc_s_dv_timings(file, fh, p);
1960 break;
1961 default:
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001962 ret = -EINVAL;
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001963 break;
1964 }
1965 break;
1966 }
1967 case VIDIOC_G_DV_TIMINGS:
1968 {
1969 struct v4l2_dv_timings *p = arg;
1970
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001971 ret = ops->vidioc_g_dv_timings(file, fh, p);
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001972 if (!ret)
1973 dbgtimings(vfd, p);
1974 break;
1975 }
1976 case VIDIOC_ENUM_DV_TIMINGS:
1977 {
1978 struct v4l2_enum_dv_timings *p = arg;
1979
1980 if (!ops->vidioc_enum_dv_timings)
1981 break;
1982
1983 ret = ops->vidioc_enum_dv_timings(file, fh, p);
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001984 if (!ret) {
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001985 dbgarg(cmd, "index=%d: ", p->index);
1986 dbgtimings(vfd, &p->timings);
1987 }
1988 break;
1989 }
1990 case VIDIOC_QUERY_DV_TIMINGS:
1991 {
1992 struct v4l2_dv_timings *p = arg;
1993
1994 if (!ops->vidioc_query_dv_timings)
1995 break;
1996
1997 ret = ops->vidioc_query_dv_timings(file, fh, p);
1998 if (!ret)
1999 dbgtimings(vfd, p);
2000 break;
2001 }
2002 case VIDIOC_DV_TIMINGS_CAP:
2003 {
2004 struct v4l2_dv_timings_cap *p = arg;
2005
2006 if (!ops->vidioc_dv_timings_cap)
2007 break;
2008
2009 ret = ops->vidioc_dv_timings_cap(file, fh, p);
2010 if (ret)
2011 break;
2012 switch (p->type) {
2013 case V4L2_DV_BT_656_1120:
2014 dbgarg(cmd,
2015 "type=%d, width=%u-%u, height=%u-%u, "
2016 "pixelclock=%llu-%llu, standards=%x, capabilities=%x ",
2017 p->type,
2018 p->bt.min_width, p->bt.max_width,
2019 p->bt.min_height, p->bt.max_height,
2020 p->bt.min_pixelclock, p->bt.max_pixelclock,
2021 p->bt.standards, p->bt.capabilities);
2022 break;
2023 default:
2024 dbgarg(cmd, "unknown type ");
2025 break;
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002026 }
2027 break;
2028 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002029 case VIDIOC_DQEVENT:
2030 {
2031 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002032
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002033 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2034 if (ret < 0) {
2035 dbgarg(cmd, "no pending events?");
2036 break;
2037 }
2038 dbgarg(cmd,
2039 "pending=%d, type=0x%8.8x, sequence=%d, "
2040 "timestamp=%lu.%9.9lu ",
2041 ev->pending, ev->type, ev->sequence,
2042 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2043 break;
2044 }
2045 case VIDIOC_SUBSCRIBE_EVENT:
2046 {
2047 struct v4l2_event_subscription *sub = arg;
2048
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002049 ret = ops->vidioc_subscribe_event(fh, sub);
2050 if (ret < 0) {
2051 dbgarg(cmd, "failed, ret=%ld", ret);
2052 break;
2053 }
2054 dbgarg(cmd, "type=0x%8.8x", sub->type);
2055 break;
2056 }
2057 case VIDIOC_UNSUBSCRIBE_EVENT:
2058 {
2059 struct v4l2_event_subscription *sub = arg;
2060
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002061 ret = ops->vidioc_unsubscribe_event(fh, sub);
2062 if (ret < 0) {
2063 dbgarg(cmd, "failed, ret=%ld", ret);
2064 break;
2065 }
2066 dbgarg(cmd, "type=0x%8.8x", sub->type);
2067 break;
2068 }
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002069 case VIDIOC_CREATE_BUFS:
2070 {
2071 struct v4l2_create_buffers *create = arg;
2072
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002073 ret = check_fmt(ops, create->format.type);
2074 if (ret)
2075 break;
2076
2077 ret = ops->vidioc_create_bufs(file, fh, create);
2078
2079 dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2080 break;
2081 }
2082 case VIDIOC_PREPARE_BUF:
2083 {
2084 struct v4l2_buffer *b = arg;
2085
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002086 ret = check_fmt(ops, b->type);
2087 if (ret)
2088 break;
2089
2090 ret = ops->vidioc_prepare_buf(file, fh, b);
2091
2092 dbgarg(cmd, "index=%d", b->index);
2093 break;
2094 }
Hans Verkuila3998102008-07-21 02:57:38 -03002095 default:
Hans Verkuila3998102008-07-21 02:57:38 -03002096 if (!ops->vidioc_default)
2097 break;
Hans Verkuil4b902fe2012-05-10 05:40:50 -03002098 ret = ops->vidioc_default(file, fh, use_fh_prio ?
2099 v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
2100 cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002101 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002102 } /* switch */
2103
2104 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2105 if (ret < 0) {
2106 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002107 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002108 }
2109 }
2110
2111 return ret;
2112}
2113
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002114static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2115 void * __user *user_ptr, void ***kernel_ptr)
2116{
2117 int ret = 0;
2118
2119 switch (cmd) {
2120 case VIDIOC_QUERYBUF:
2121 case VIDIOC_QBUF:
2122 case VIDIOC_DQBUF: {
2123 struct v4l2_buffer *buf = parg;
2124
2125 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2126 if (buf->length > VIDEO_MAX_PLANES) {
2127 ret = -EINVAL;
2128 break;
2129 }
2130 *user_ptr = (void __user *)buf->m.planes;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002131 *kernel_ptr = (void *)&buf->m.planes;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002132 *array_size = sizeof(struct v4l2_plane) * buf->length;
2133 ret = 1;
2134 }
2135 break;
2136 }
2137
2138 case VIDIOC_S_EXT_CTRLS:
2139 case VIDIOC_G_EXT_CTRLS:
2140 case VIDIOC_TRY_EXT_CTRLS: {
2141 struct v4l2_ext_controls *ctrls = parg;
2142
2143 if (ctrls->count != 0) {
Dan Carpenter6c061082012-01-05 02:27:57 -03002144 if (ctrls->count > V4L2_CID_MAX_CTRLS) {
2145 ret = -EINVAL;
2146 break;
2147 }
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002148 *user_ptr = (void __user *)ctrls->controls;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002149 *kernel_ptr = (void *)&ctrls->controls;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002150 *array_size = sizeof(struct v4l2_ext_control)
2151 * ctrls->count;
2152 ret = 1;
2153 }
2154 break;
2155 }
2156 }
2157
2158 return ret;
2159}
2160
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002161long
2162video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2163 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002164{
2165 char sbuf[128];
2166 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002167 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002168 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002169 bool has_array_args;
2170 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002171 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002172 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002173
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002174 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002175 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002176 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2177 parg = sbuf;
2178 } else {
2179 /* too big to allocate from stack */
2180 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2181 if (NULL == mbuf)
2182 return -ENOMEM;
2183 parg = mbuf;
2184 }
2185
2186 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002187 if (_IOC_DIR(cmd) & _IOC_WRITE) {
Hans Verkuil27cd2ab2012-06-09 08:55:31 -03002188 unsigned int n = _IOC_SIZE(cmd);
2189
2190 /*
2191 * In some cases, only a few fields are used as input,
2192 * i.e. when the app sets "index" and then the driver
2193 * fills in the rest of the structure for the thing
2194 * with that index. We only need to copy up the first
2195 * non-input field.
2196 */
2197 if (v4l2_is_known_ioctl(cmd)) {
2198 u32 flags = v4l2_ioctls[_IOC_NR(cmd)].flags;
2199 if (flags & INFO_FL_CLEAR_MASK)
2200 n = (flags & INFO_FL_CLEAR_MASK) >> 16;
2201 }
Trent Piepho19c96e42009-03-04 01:21:02 -03002202
2203 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002204 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002205
2206 /* zero out anything we don't copy from userspace */
2207 if (n < _IOC_SIZE(cmd))
2208 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002209 } else {
2210 /* read-only ioctl */
2211 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002212 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002213 }
2214
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002215 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2216 if (err < 0)
2217 goto out;
2218 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002219
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002220 if (has_array_args) {
2221 /*
2222 * When adding new types of array args, make sure that the
2223 * parent argument to ioctl (which contains the pointer to the
2224 * array) fits into sbuf (so that mbuf will still remain
2225 * unused up to here).
2226 */
2227 mbuf = kmalloc(array_size, GFP_KERNEL);
2228 err = -ENOMEM;
2229 if (NULL == mbuf)
2230 goto out_array_args;
2231 err = -EFAULT;
2232 if (copy_from_user(mbuf, user_ptr, array_size))
2233 goto out_array_args;
2234 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002235 }
2236
2237 /* Handles IOCTL */
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002238 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002239 if (err == -ENOIOCTLCMD)
Hans Verkuil02bbb812012-02-08 08:09:36 -03002240 err = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002241
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002242 if (has_array_args) {
2243 *kernel_ptr = user_ptr;
2244 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002245 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002246 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002247 }
Hans Verkuil5d7758e2012-05-15 08:06:44 -03002248 /* VIDIOC_QUERY_DV_TIMINGS can return an error, but still have valid
2249 results that must be returned. */
2250 if (err < 0 && cmd != VIDIOC_QUERY_DV_TIMINGS)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002251 goto out;
2252
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002253out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002254 /* Copy results into user buffer */
2255 switch (_IOC_DIR(cmd)) {
2256 case _IOC_READ:
2257 case (_IOC_WRITE | _IOC_READ):
2258 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2259 err = -EFAULT;
2260 break;
2261 }
2262
2263out:
2264 kfree(mbuf);
2265 return err;
2266}
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002267EXPORT_SYMBOL(video_usercopy);
2268
2269long video_ioctl2(struct file *file,
2270 unsigned int cmd, unsigned long arg)
2271{
2272 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2273}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002274EXPORT_SYMBOL(video_ioctl2);