blob: 7a15f351395f507f72ecc1ddab37306fbb9518e6 [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 Piepho51f0b8d2009-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 Piepho51f0b8d2009-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;
Hans Verkuil86748f32012-06-22 06:04:16 -0300399 union {
400 u32 offset;
401 int (*func)(const struct v4l2_ioctl_ops *ops,
402 struct file *file, void *fh, void *p);
403 };
404 void (*debug)(const void *arg, bool write_only);
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300405};
406
407/* This control needs a priority check */
408#define INFO_FL_PRIO (1 << 0)
409/* This control can be valid if the filehandle passes a control handler. */
410#define INFO_FL_CTRL (1 << 1)
Hans Verkuil86748f32012-06-22 06:04:16 -0300411/* This is a standard ioctl, no need for special code */
412#define INFO_FL_STD (1 << 2)
413/* This is ioctl has its own function */
414#define INFO_FL_FUNC (1 << 3)
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300415/* Zero struct from after the field to the end */
416#define INFO_FL_CLEAR(v4l2_struct, field) \
417 ((offsetof(struct v4l2_struct, field) + \
418 sizeof(((struct v4l2_struct *)0)->field)) << 16)
419#define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300420
421#define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = { \
422 .ioctl = _ioctl, \
423 .flags = _flags, \
424 .name = #_ioctl, \
425}
426
Hans Verkuil86748f32012-06-22 06:04:16 -0300427#define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags) \
428 [_IOC_NR(_ioctl)] = { \
429 .ioctl = _ioctl, \
430 .flags = _flags | INFO_FL_STD, \
431 .name = #_ioctl, \
432 .offset = offsetof(struct v4l2_ioctl_ops, _vidioc), \
433 .debug = _debug, \
434 }
435
436#define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags) \
437 [_IOC_NR(_ioctl)] = { \
438 .ioctl = _ioctl, \
439 .flags = _flags | INFO_FL_FUNC, \
440 .name = #_ioctl, \
441 .func = _func, \
442 .debug = _debug, \
443 }
444
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300445static struct v4l2_ioctl_info v4l2_ioctls[] = {
446 IOCTL_INFO(VIDIOC_QUERYCAP, 0),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300447 IOCTL_INFO(VIDIOC_ENUM_FMT, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
448 IOCTL_INFO(VIDIOC_G_FMT, INFO_FL_CLEAR(v4l2_format, type)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300449 IOCTL_INFO(VIDIOC_S_FMT, INFO_FL_PRIO),
450 IOCTL_INFO(VIDIOC_REQBUFS, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300451 IOCTL_INFO(VIDIOC_QUERYBUF, INFO_FL_CLEAR(v4l2_buffer, length)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300452 IOCTL_INFO(VIDIOC_G_FBUF, 0),
453 IOCTL_INFO(VIDIOC_S_FBUF, INFO_FL_PRIO),
454 IOCTL_INFO(VIDIOC_OVERLAY, INFO_FL_PRIO),
455 IOCTL_INFO(VIDIOC_QBUF, 0),
456 IOCTL_INFO(VIDIOC_DQBUF, 0),
457 IOCTL_INFO(VIDIOC_STREAMON, INFO_FL_PRIO),
458 IOCTL_INFO(VIDIOC_STREAMOFF, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300459 IOCTL_INFO(VIDIOC_G_PARM, INFO_FL_CLEAR(v4l2_streamparm, type)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300460 IOCTL_INFO(VIDIOC_S_PARM, INFO_FL_PRIO),
461 IOCTL_INFO(VIDIOC_G_STD, 0),
462 IOCTL_INFO(VIDIOC_S_STD, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300463 IOCTL_INFO(VIDIOC_ENUMSTD, INFO_FL_CLEAR(v4l2_standard, index)),
464 IOCTL_INFO(VIDIOC_ENUMINPUT, INFO_FL_CLEAR(v4l2_input, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300465 IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL),
466 IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_PRIO | INFO_FL_CTRL),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300467 IOCTL_INFO(VIDIOC_G_TUNER, INFO_FL_CLEAR(v4l2_tuner, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300468 IOCTL_INFO(VIDIOC_S_TUNER, INFO_FL_PRIO),
469 IOCTL_INFO(VIDIOC_G_AUDIO, 0),
470 IOCTL_INFO(VIDIOC_S_AUDIO, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300471 IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
472 IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300473 IOCTL_INFO(VIDIOC_G_INPUT, 0),
474 IOCTL_INFO(VIDIOC_S_INPUT, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300475 IOCTL_INFO(VIDIOC_G_OUTPUT, INFO_FL_CLEAR(v4l2_output, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300476 IOCTL_INFO(VIDIOC_S_OUTPUT, INFO_FL_PRIO),
477 IOCTL_INFO(VIDIOC_ENUMOUTPUT, 0),
478 IOCTL_INFO(VIDIOC_G_AUDOUT, 0),
479 IOCTL_INFO(VIDIOC_S_AUDOUT, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300480 IOCTL_INFO(VIDIOC_G_MODULATOR, INFO_FL_CLEAR(v4l2_modulator, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300481 IOCTL_INFO(VIDIOC_S_MODULATOR, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300482 IOCTL_INFO(VIDIOC_G_FREQUENCY, INFO_FL_CLEAR(v4l2_frequency, tuner)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300483 IOCTL_INFO(VIDIOC_S_FREQUENCY, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300484 IOCTL_INFO(VIDIOC_CROPCAP, INFO_FL_CLEAR(v4l2_cropcap, type)),
485 IOCTL_INFO(VIDIOC_G_CROP, INFO_FL_CLEAR(v4l2_crop, type)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300486 IOCTL_INFO(VIDIOC_S_CROP, INFO_FL_PRIO),
487 IOCTL_INFO(VIDIOC_G_SELECTION, 0),
488 IOCTL_INFO(VIDIOC_S_SELECTION, INFO_FL_PRIO),
489 IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
490 IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
491 IOCTL_INFO(VIDIOC_QUERYSTD, 0),
492 IOCTL_INFO(VIDIOC_TRY_FMT, 0),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300493 IOCTL_INFO(VIDIOC_ENUMAUDIO, INFO_FL_CLEAR(v4l2_audio, index)),
494 IOCTL_INFO(VIDIOC_ENUMAUDOUT, INFO_FL_CLEAR(v4l2_audioout, index)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300495 IOCTL_INFO(VIDIOC_G_PRIORITY, 0),
496 IOCTL_INFO(VIDIOC_S_PRIORITY, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300497 IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300498 IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
499 IOCTL_INFO(VIDIOC_G_EXT_CTRLS, INFO_FL_CTRL),
500 IOCTL_INFO(VIDIOC_S_EXT_CTRLS, INFO_FL_PRIO | INFO_FL_CTRL),
501 IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, 0),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300502 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
503 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300504 IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -0300505 IOCTL_INFO(VIDIOC_ENCODER_CMD, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
506 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300507 IOCTL_INFO(VIDIOC_DECODER_CMD, INFO_FL_PRIO),
508 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0),
509#ifdef CONFIG_VIDEO_ADV_DEBUG
510 IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
511 IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
512#endif
513 IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
514 IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, INFO_FL_PRIO),
515 IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
516 IOCTL_INFO(VIDIOC_S_DV_PRESET, INFO_FL_PRIO),
517 IOCTL_INFO(VIDIOC_G_DV_PRESET, 0),
518 IOCTL_INFO(VIDIOC_QUERY_DV_PRESET, 0),
519 IOCTL_INFO(VIDIOC_S_DV_TIMINGS, INFO_FL_PRIO),
520 IOCTL_INFO(VIDIOC_G_DV_TIMINGS, 0),
521 IOCTL_INFO(VIDIOC_DQEVENT, 0),
522 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0),
523 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
524 IOCTL_INFO(VIDIOC_CREATE_BUFS, INFO_FL_PRIO),
525 IOCTL_INFO(VIDIOC_PREPARE_BUF, 0),
526 IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, 0),
527 IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, 0),
528 IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, 0),
529};
530#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
531
532bool v4l2_is_known_ioctl(unsigned int cmd)
533{
534 if (_IOC_NR(cmd) >= V4L2_IOCTLS)
535 return false;
536 return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
537}
538
539/* Common ioctl debug function. This function can be used by
540 external ioctl messages as well as internal V4L ioctl */
541void v4l_printk_ioctl(unsigned int cmd)
542{
Hans Verkuil86748f32012-06-22 06:04:16 -0300543 const char *dir, *type;
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300544
545 switch (_IOC_TYPE(cmd)) {
546 case 'd':
547 type = "v4l2_int";
548 break;
549 case 'V':
550 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
551 type = "v4l2";
552 break;
553 }
Hans Verkuil86748f32012-06-22 06:04:16 -0300554 pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300555 return;
556 default:
557 type = "unknown";
Hans Verkuil86748f32012-06-22 06:04:16 -0300558 break;
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300559 }
560
561 switch (_IOC_DIR(cmd)) {
562 case _IOC_NONE: dir = "--"; break;
563 case _IOC_READ: dir = "r-"; break;
564 case _IOC_WRITE: dir = "-w"; break;
565 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
566 default: dir = "*ERR*"; break;
567 }
Hans Verkuil86748f32012-06-22 06:04:16 -0300568 pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)",
Hans Verkuil4839e6c2012-06-04 05:23:40 -0300569 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
570}
571EXPORT_SYMBOL(v4l_printk_ioctl);
572
Hans Verkuil069b7472008-12-30 07:04:34 -0300573static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300574 unsigned int cmd, void *arg)
575{
576 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300577 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuil86748f32012-06-22 06:04:16 -0300578 bool write_only = false;
579 struct v4l2_ioctl_info default_info;
580 const struct v4l2_ioctl_info *info;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300581 void *fh = file->private_data;
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300582 struct v4l2_fh *vfh = NULL;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300583 int use_fh_prio = 0;
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300584 long ret = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300585
Hans Verkuil6a717882010-04-06 15:56:08 -0300586 if (ops == NULL) {
587 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
588 vfd->name);
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300589 return ret;
Hans Verkuil6a717882010-04-06 15:56:08 -0300590 }
591
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300592 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
593 vfh = file->private_data;
594 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300595 }
596
597 if (v4l2_is_known_ioctl(cmd)) {
Hans Verkuil86748f32012-06-22 06:04:16 -0300598 info = &v4l2_ioctls[_IOC_NR(cmd)];
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300599
600 if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
601 !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
Hans Verkuil86748f32012-06-22 06:04:16 -0300602 goto done;
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300603
604 if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
605 ret = v4l2_prio_check(vfd->prio, vfh->prio);
606 if (ret)
Hans Verkuil86748f32012-06-22 06:04:16 -0300607 goto done;
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300608 }
Hans Verkuil86748f32012-06-22 06:04:16 -0300609 } else {
610 default_info.ioctl = cmd;
611 default_info.flags = 0;
612 default_info.debug = NULL;
613 info = &default_info;
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300614 }
615
Hans Verkuil86748f32012-06-22 06:04:16 -0300616 write_only = _IOC_DIR(cmd) == _IOC_WRITE;
617 if (info->debug && write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300618 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil86748f32012-06-22 06:04:16 -0300619 pr_cont(": ");
620 info->debug(arg, write_only);
621 }
622 if (info->flags & INFO_FL_STD) {
623 typedef int (*vidioc_op)(struct file *file, void *fh, void *p);
624 const void *p = vfd->ioctl_ops;
625 const vidioc_op *vidioc = p + info->offset;
626
627 ret = (*vidioc)(file, fh, arg);
628 goto done;
629 } else if (info->flags & INFO_FL_FUNC) {
630 ret = info->func(ops, file, fh, arg);
631 goto done;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300632 }
633
Hans Verkuil6a717882010-04-06 15:56:08 -0300634 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300635
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300636 /* --- capabilities ------------------------------------------ */
637 case VIDIOC_QUERYCAP:
638 {
639 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300640
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -0300641 cap->version = LINUX_VERSION_CODE;
Hans Verkuila3998102008-07-21 02:57:38 -0300642 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300643 if (!ret)
644 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
645 "version=0x%08x, "
Hans Verkuil583aa3a2012-01-11 06:45:05 -0300646 "capabilities=0x%08x, "
647 "device_caps=0x%08x\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300648 cap->driver, cap->card, cap->bus_info,
649 cap->version,
Hans Verkuil583aa3a2012-01-11 06:45:05 -0300650 cap->capabilities,
651 cap->device_caps);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300652 break;
653 }
654
655 /* --- priority ------------------------------------------ */
656 case VIDIOC_G_PRIORITY:
657 {
658 enum v4l2_priority *p = arg;
659
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300660 if (ops->vidioc_g_priority) {
661 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300662 } else if (use_fh_prio) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300663 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
664 ret = 0;
665 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300666 if (!ret)
667 dbgarg(cmd, "priority is %d\n", *p);
668 break;
669 }
670 case VIDIOC_S_PRIORITY:
671 {
672 enum v4l2_priority *p = arg;
673
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300674 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300675 if (ops->vidioc_s_priority)
676 ret = ops->vidioc_s_priority(file, fh, *p);
677 else
Hans Verkuil4b902fe2012-05-10 05:40:50 -0300678 ret = v4l2_prio_change(&vfd->v4l2_dev->prio,
Hans Verkuil93d5a302011-08-09 09:32:06 -0300679 &vfh->prio, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300680 break;
681 }
682
683 /* --- capture ioctls ---------------------------------------- */
684 case VIDIOC_ENUM_FMT:
685 {
686 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300687
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300688 ret = -EINVAL;
Trent Piepho19c96e42009-03-04 01:21:02 -0300689 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300690 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300691 if (likely(ops->vidioc_enum_fmt_vid_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300692 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300693 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300694 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300695 if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300696 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
697 fh, f);
698 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300699 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300700 if (likely(ops->vidioc_enum_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300701 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300702 fh, f);
703 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300704 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300705 if (likely(ops->vidioc_enum_fmt_vid_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300706 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300707 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300708 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300709 if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300710 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
711 fh, f);
712 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300713 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300714 if (likely(ops->vidioc_enum_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300715 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300716 fh, f);
717 break;
718 default:
719 break;
720 }
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300721 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300722 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
723 "pixelformat=%c%c%c%c, description='%s'\n",
724 f->index, f->type, f->flags,
725 (f->pixelformat & 0xff),
726 (f->pixelformat >> 8) & 0xff,
727 (f->pixelformat >> 16) & 0xff,
728 (f->pixelformat >> 24) & 0xff,
729 f->description);
730 break;
731 }
732 case VIDIOC_G_FMT:
733 {
734 struct v4l2_format *f = (struct v4l2_format *)arg;
735
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300736 /* FIXME: Should be one dump per type */
737 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
738
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300739 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300740 switch (f->type) {
741 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300742 if (ops->vidioc_g_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300743 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300744 if (!ret)
745 v4l_print_pix_fmt(vfd, &f->fmt.pix);
746 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300747 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300748 if (ops->vidioc_g_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300749 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
750 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300751 if (!ret)
752 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
753 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300754 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300755 if (likely(ops->vidioc_g_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300756 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300757 fh, f);
758 break;
759 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300760 if (ops->vidioc_g_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300761 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300762 if (!ret)
763 v4l_print_pix_fmt(vfd, &f->fmt.pix);
764 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300765 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300766 if (ops->vidioc_g_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300767 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
768 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300769 if (!ret)
770 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
771 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300772 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300773 if (likely(ops->vidioc_g_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300774 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300775 fh, f);
776 break;
777 case V4L2_BUF_TYPE_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300778 if (likely(ops->vidioc_g_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300779 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300780 break;
781 case V4L2_BUF_TYPE_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300782 if (likely(ops->vidioc_g_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300783 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300784 break;
785 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300786 if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300787 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300788 fh, f);
789 break;
790 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300791 if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300792 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300793 fh, f);
794 break;
795 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300796 if (likely(ops->vidioc_g_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300797 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300798 fh, f);
799 break;
800 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300801 break;
802 }
803 case VIDIOC_S_FMT:
804 {
805 struct v4l2_format *f = (struct v4l2_format *)arg;
806
Hans Verkuil93d5a302011-08-09 09:32:06 -0300807 ret = -EINVAL;
808
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300809 /* FIXME: Should be one dump per type */
810 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
811
812 switch (f->type) {
813 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300814 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300815 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300816 if (ops->vidioc_s_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300817 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300818 break;
819 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
820 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
821 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300822 if (ops->vidioc_s_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300823 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
824 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300825 break;
826 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300827 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300828 if (ops->vidioc_s_fmt_vid_overlay)
829 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300830 fh, f);
831 break;
832 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300833 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300834 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300835 if (ops->vidioc_s_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300836 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300837 break;
838 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
839 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
840 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300841 if (ops->vidioc_s_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300842 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
843 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300844 break;
845 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300846 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300847 if (ops->vidioc_s_fmt_vid_out_overlay)
848 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300849 fh, f);
850 break;
851 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300852 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300853 if (likely(ops->vidioc_s_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300854 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300855 break;
856 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300857 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300858 if (likely(ops->vidioc_s_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300859 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300860 break;
861 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300862 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300863 if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300864 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300865 fh, f);
866 break;
867 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300868 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300869 if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300870 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300871 fh, f);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300872
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300873 break;
874 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300875 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300876 if (likely(ops->vidioc_s_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300877 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300878 fh, f);
879 break;
880 }
881 break;
882 }
883 case VIDIOC_TRY_FMT:
884 {
885 struct v4l2_format *f = (struct v4l2_format *)arg;
886
887 /* FIXME: Should be one dump per type */
888 dbgarg(cmd, "type=%s\n", prt_names(f->type,
889 v4l2_type_names));
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300890 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300891 switch (f->type) {
892 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300893 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300894 if (ops->vidioc_try_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300895 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300896 if (!ret)
897 v4l_print_pix_fmt(vfd, &f->fmt.pix);
898 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300899 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
900 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300901 if (ops->vidioc_try_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300902 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
903 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300904 if (!ret)
905 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
906 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300907 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300908 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300909 if (likely(ops->vidioc_try_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300910 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300911 fh, f);
912 break;
913 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300914 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300915 if (ops->vidioc_try_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300916 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300917 if (!ret)
918 v4l_print_pix_fmt(vfd, &f->fmt.pix);
919 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300920 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
921 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300922 if (ops->vidioc_try_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300923 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
924 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300925 if (!ret)
926 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
927 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300928 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300929 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300930 if (likely(ops->vidioc_try_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300931 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300932 fh, f);
933 break;
934 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300935 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300936 if (likely(ops->vidioc_try_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300937 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300938 break;
939 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300940 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300941 if (likely(ops->vidioc_try_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300942 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300943 break;
944 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300945 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300946 if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300947 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300948 fh, f);
949 break;
950 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300951 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300952 if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300953 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300954 fh, f);
955 break;
956 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300957 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300958 if (likely(ops->vidioc_try_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300959 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300960 fh, f);
961 break;
962 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300963 break;
964 }
965 /* FIXME: Those buf reqs could be handled here,
966 with some changes on videobuf to allow its header to be included at
967 videodev2.h or being merged at videodev2.
968 */
969 case VIDIOC_REQBUFS:
970 {
971 struct v4l2_requestbuffers *p = arg;
972
Hans Verkuila3998102008-07-21 02:57:38 -0300973 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300974 if (ret)
975 break;
976
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300977 if (p->type < V4L2_BUF_TYPE_PRIVATE)
978 CLEAR_AFTER_FIELD(p, memory);
979
Hans Verkuila3998102008-07-21 02:57:38 -0300980 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300981 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
982 p->count,
983 prt_names(p->type, v4l2_type_names),
984 prt_names(p->memory, v4l2_memory_names));
985 break;
986 }
987 case VIDIOC_QUERYBUF:
988 {
989 struct v4l2_buffer *p = arg;
990
Hans Verkuila3998102008-07-21 02:57:38 -0300991 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300992 if (ret)
993 break;
994
Hans Verkuila3998102008-07-21 02:57:38 -0300995 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300996 if (!ret)
997 dbgbuf(cmd, vfd, p);
998 break;
999 }
1000 case VIDIOC_QBUF:
1001 {
1002 struct v4l2_buffer *p = arg;
1003
Hans Verkuila3998102008-07-21 02:57:38 -03001004 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001005 if (ret)
1006 break;
1007
Hans Verkuila3998102008-07-21 02:57:38 -03001008 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001009 if (!ret)
1010 dbgbuf(cmd, vfd, p);
1011 break;
1012 }
1013 case VIDIOC_DQBUF:
1014 {
1015 struct v4l2_buffer *p = arg;
1016
Hans Verkuila3998102008-07-21 02:57:38 -03001017 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001018 if (ret)
1019 break;
1020
Hans Verkuila3998102008-07-21 02:57:38 -03001021 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001022 if (!ret)
1023 dbgbuf(cmd, vfd, p);
1024 break;
1025 }
1026 case VIDIOC_OVERLAY:
1027 {
1028 int *i = arg;
1029
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001030 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001031 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001032 break;
1033 }
1034 case VIDIOC_G_FBUF:
1035 {
1036 struct v4l2_framebuffer *p = arg;
1037
Hans Verkuila3998102008-07-21 02:57:38 -03001038 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001039 if (!ret) {
1040 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1041 p->capability, p->flags,
1042 (unsigned long)p->base);
1043 v4l_print_pix_fmt(vfd, &p->fmt);
1044 }
1045 break;
1046 }
1047 case VIDIOC_S_FBUF:
1048 {
1049 struct v4l2_framebuffer *p = arg;
1050
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001051 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1052 p->capability, p->flags, (unsigned long)p->base);
1053 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -03001054 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001055 break;
1056 }
1057 case VIDIOC_STREAMON:
1058 {
1059 enum v4l2_buf_type i = *(int *)arg;
1060
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001061 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001062 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001063 break;
1064 }
1065 case VIDIOC_STREAMOFF:
1066 {
1067 enum v4l2_buf_type i = *(int *)arg;
1068
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001069 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001070 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001071 break;
1072 }
1073 /* ---------- tv norms ---------- */
1074 case VIDIOC_ENUMSTD:
1075 {
1076 struct v4l2_standard *p = arg;
1077 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1078 unsigned int index = p->index, i, j = 0;
1079 const char *descr = "";
1080
Hans Verkuil93d5a302011-08-09 09:32:06 -03001081 if (id == 0)
1082 break;
1083 ret = -EINVAL;
1084
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001085 /* Return norm array in a canonical way */
1086 for (i = 0; i <= index && id; i++) {
1087 /* last std value in the standards array is 0, so this
1088 while always ends there since (id & 0) == 0. */
1089 while ((id & standards[j].std) != standards[j].std)
1090 j++;
1091 curr_id = standards[j].std;
1092 descr = standards[j].descr;
1093 j++;
1094 if (curr_id == 0)
1095 break;
1096 if (curr_id != V4L2_STD_PAL &&
1097 curr_id != V4L2_STD_SECAM &&
1098 curr_id != V4L2_STD_NTSC)
1099 id &= ~curr_id;
1100 }
1101 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001102 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001103
1104 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001105
1106 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1107 "framelines=%d\n", p->index,
1108 (unsigned long long)p->id, p->name,
1109 p->frameperiod.numerator,
1110 p->frameperiod.denominator,
1111 p->framelines);
1112
1113 ret = 0;
1114 break;
1115 }
1116 case VIDIOC_G_STD:
1117 {
1118 v4l2_std_id *id = arg;
1119
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001120 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001121 if (ops->vidioc_g_std)
1122 ret = ops->vidioc_g_std(file, fh, id);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001123 else if (vfd->current_norm) {
1124 ret = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001125 *id = vfd->current_norm;
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001126 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001127
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001128 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001129 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1130 break;
1131 }
1132 case VIDIOC_S_STD:
1133 {
1134 v4l2_std_id *id = arg, norm;
1135
1136 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1137
Hans Verkuil93d5a302011-08-09 09:32:06 -03001138 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001139 norm = (*id) & vfd->tvnorms;
1140 if (vfd->tvnorms && !norm) /* Check if std is supported */
1141 break;
1142
1143 /* Calls the specific handler */
Hans Verkuil93d5a302011-08-09 09:32:06 -03001144 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001145
1146 /* Updates standard information */
1147 if (ret >= 0)
1148 vfd->current_norm = norm;
1149 break;
1150 }
1151 case VIDIOC_QUERYSTD:
1152 {
1153 v4l2_std_id *p = arg;
1154
Mauro Carvalho Chehab8715e6c2011-10-04 09:32:23 -03001155 /*
1156 * If nothing detected, it should return all supported
1157 * Drivers just need to mask the std argument, in order
1158 * to remove the standards that don't apply from the mask.
1159 * This means that tuners, audio and video decoders can join
1160 * their efforts to improve the standards detection
1161 */
1162 *p = vfd->tvnorms;
Hans Verkuila3998102008-07-21 02:57:38 -03001163 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001164 if (!ret)
1165 dbgarg(cmd, "detected std=%08Lx\n",
1166 (unsigned long long)*p);
1167 break;
1168 }
1169 /* ------ input switching ---------- */
1170 /* FIXME: Inputs can be handled inside videodev2 */
1171 case VIDIOC_ENUMINPUT:
1172 {
1173 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001174
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001175 /*
1176 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1177 * CAP_STD here based on ioctl handler provided by the
1178 * driver. If the driver doesn't support these
1179 * for a specific input, it must override these flags.
1180 */
1181 if (ops->vidioc_s_std)
1182 p->capabilities |= V4L2_IN_CAP_STD;
1183 if (ops->vidioc_s_dv_preset)
1184 p->capabilities |= V4L2_IN_CAP_PRESETS;
1185 if (ops->vidioc_s_dv_timings)
1186 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1187
Hans Verkuila3998102008-07-21 02:57:38 -03001188 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001189 if (!ret)
1190 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1191 "audioset=%d, "
1192 "tuner=%d, std=%08Lx, status=%d\n",
1193 p->index, p->name, p->type, p->audioset,
1194 p->tuner,
1195 (unsigned long long)p->std,
1196 p->status);
1197 break;
1198 }
1199 case VIDIOC_G_INPUT:
1200 {
1201 unsigned int *i = arg;
1202
Hans Verkuila3998102008-07-21 02:57:38 -03001203 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001204 if (!ret)
1205 dbgarg(cmd, "value=%d\n", *i);
1206 break;
1207 }
1208 case VIDIOC_S_INPUT:
1209 {
1210 unsigned int *i = arg;
1211
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001212 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001213 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001214 break;
1215 }
1216
1217 /* ------ output switching ---------- */
1218 case VIDIOC_ENUMOUTPUT:
1219 {
1220 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001221
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001222 /*
1223 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1224 * CAP_STD here based on ioctl handler provided by the
1225 * driver. If the driver doesn't support these
1226 * for a specific output, it must override these flags.
1227 */
1228 if (ops->vidioc_s_std)
1229 p->capabilities |= V4L2_OUT_CAP_STD;
1230 if (ops->vidioc_s_dv_preset)
1231 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1232 if (ops->vidioc_s_dv_timings)
1233 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1234
Hans Verkuila3998102008-07-21 02:57:38 -03001235 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001236 if (!ret)
1237 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1238 "audioset=0x%x, "
1239 "modulator=%d, std=0x%08Lx\n",
1240 p->index, p->name, p->type, p->audioset,
1241 p->modulator, (unsigned long long)p->std);
1242 break;
1243 }
1244 case VIDIOC_G_OUTPUT:
1245 {
1246 unsigned int *i = arg;
1247
Hans Verkuila3998102008-07-21 02:57:38 -03001248 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001249 if (!ret)
1250 dbgarg(cmd, "value=%d\n", *i);
1251 break;
1252 }
1253 case VIDIOC_S_OUTPUT:
1254 {
1255 unsigned int *i = arg;
1256
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001257 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001258 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001259 break;
1260 }
1261
1262 /* --- controls ---------------------------------------------- */
1263 case VIDIOC_QUERYCTRL:
1264 {
1265 struct v4l2_queryctrl *p = arg;
1266
Hans Verkuil2d28b682011-03-12 08:54:43 -03001267 if (vfh && vfh->ctrl_handler)
1268 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1269 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001270 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1271 else if (ops->vidioc_queryctrl)
1272 ret = ops->vidioc_queryctrl(file, fh, p);
1273 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001274 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001275 if (!ret)
1276 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1277 "step=%d, default=%d, flags=0x%08x\n",
1278 p->id, p->type, p->name,
1279 p->minimum, p->maximum,
1280 p->step, p->default_value, p->flags);
1281 else
1282 dbgarg(cmd, "id=0x%x\n", p->id);
1283 break;
1284 }
1285 case VIDIOC_G_CTRL:
1286 {
1287 struct v4l2_control *p = arg;
1288
Hans Verkuil2d28b682011-03-12 08:54:43 -03001289 if (vfh && vfh->ctrl_handler)
1290 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1291 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001292 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1293 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001294 ret = ops->vidioc_g_ctrl(file, fh, p);
1295 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001296 struct v4l2_ext_controls ctrls;
1297 struct v4l2_ext_control ctrl;
1298
1299 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1300 ctrls.count = 1;
1301 ctrls.controls = &ctrl;
1302 ctrl.id = p->id;
1303 ctrl.value = p->value;
1304 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001305 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001306 if (ret == 0)
1307 p->value = ctrl.value;
1308 }
1309 } else
1310 break;
1311 if (!ret)
1312 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1313 else
1314 dbgarg(cmd, "id=0x%x\n", p->id);
1315 break;
1316 }
1317 case VIDIOC_S_CTRL:
1318 {
1319 struct v4l2_control *p = arg;
1320 struct v4l2_ext_controls ctrls;
1321 struct v4l2_ext_control ctrl;
1322
Hans Verkuil2d28b682011-03-12 08:54:43 -03001323 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001324 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001325 break;
1326
1327 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1328
Hans Verkuil2d28b682011-03-12 08:54:43 -03001329 if (vfh && vfh->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001330 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001331 break;
1332 }
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001333 if (vfd->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001334 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001335 break;
1336 }
Hans Verkuila3998102008-07-21 02:57:38 -03001337 if (ops->vidioc_s_ctrl) {
1338 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001339 break;
1340 }
Hans Verkuila3998102008-07-21 02:57:38 -03001341 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001342 break;
1343
1344 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1345 ctrls.count = 1;
1346 ctrls.controls = &ctrl;
1347 ctrl.id = p->id;
1348 ctrl.value = p->value;
1349 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001350 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001351 else
1352 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001353 break;
1354 }
1355 case VIDIOC_G_EXT_CTRLS:
1356 {
1357 struct v4l2_ext_controls *p = arg;
1358
1359 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001360 if (vfh && vfh->ctrl_handler)
1361 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1362 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001363 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001364 else if (ops->vidioc_g_ext_ctrls)
1365 ret = check_ext_ctrls(p, 0) ?
1366 ops->vidioc_g_ext_ctrls(file, fh, p) :
1367 -EINVAL;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001368 else
1369 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001370 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1371 break;
1372 }
1373 case VIDIOC_S_EXT_CTRLS:
1374 {
1375 struct v4l2_ext_controls *p = arg;
1376
1377 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001378 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1379 !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001380 break;
1381 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001382 if (vfh && vfh->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001383 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001384 else if (vfd->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001385 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001386 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001387 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001388 else
1389 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001390 break;
1391 }
1392 case VIDIOC_TRY_EXT_CTRLS:
1393 {
1394 struct v4l2_ext_controls *p = arg;
1395
1396 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001397 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1398 !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001399 break;
1400 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001401 if (vfh && vfh->ctrl_handler)
1402 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1403 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001404 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1405 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001406 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001407 else
1408 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001409 break;
1410 }
1411 case VIDIOC_QUERYMENU:
1412 {
1413 struct v4l2_querymenu *p = arg;
1414
Hans Verkuil2d28b682011-03-12 08:54:43 -03001415 if (vfh && vfh->ctrl_handler)
1416 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1417 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001418 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1419 else if (ops->vidioc_querymenu)
1420 ret = ops->vidioc_querymenu(file, fh, p);
1421 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001422 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001423 if (!ret)
1424 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1425 p->id, p->index, p->name);
1426 else
1427 dbgarg(cmd, "id=0x%x, index=%d\n",
1428 p->id, p->index);
1429 break;
1430 }
1431 /* --- audio ---------------------------------------------- */
1432 case VIDIOC_ENUMAUDIO:
1433 {
1434 struct v4l2_audio *p = arg;
1435
Hans Verkuila3998102008-07-21 02:57:38 -03001436 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001437 if (!ret)
1438 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1439 "mode=0x%x\n", p->index, p->name,
1440 p->capability, p->mode);
1441 else
1442 dbgarg(cmd, "index=%d\n", p->index);
1443 break;
1444 }
1445 case VIDIOC_G_AUDIO:
1446 {
1447 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001448
Hans Verkuila3998102008-07-21 02:57:38 -03001449 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001450 if (!ret)
1451 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1452 "mode=0x%x\n", p->index,
1453 p->name, p->capability, p->mode);
1454 else
1455 dbgarg(cmd, "index=%d\n", p->index);
1456 break;
1457 }
1458 case VIDIOC_S_AUDIO:
1459 {
1460 struct v4l2_audio *p = arg;
1461
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001462 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1463 "mode=0x%x\n", p->index, p->name,
1464 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001465 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001466 break;
1467 }
1468 case VIDIOC_ENUMAUDOUT:
1469 {
1470 struct v4l2_audioout *p = arg;
1471
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001472 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001473 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001474 if (!ret)
1475 dbgarg2("index=%d, name=%s, capability=%d, "
1476 "mode=%d\n", p->index, p->name,
1477 p->capability, p->mode);
1478 break;
1479 }
1480 case VIDIOC_G_AUDOUT:
1481 {
1482 struct v4l2_audioout *p = arg;
1483
Hans Verkuila3998102008-07-21 02:57:38 -03001484 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001485 if (!ret)
1486 dbgarg2("index=%d, name=%s, capability=%d, "
1487 "mode=%d\n", p->index, p->name,
1488 p->capability, p->mode);
1489 break;
1490 }
1491 case VIDIOC_S_AUDOUT:
1492 {
1493 struct v4l2_audioout *p = arg;
1494
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001495 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1496 "mode=%d\n", p->index, p->name,
1497 p->capability, p->mode);
1498
Hans Verkuila3998102008-07-21 02:57:38 -03001499 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001500 break;
1501 }
1502 case VIDIOC_G_MODULATOR:
1503 {
1504 struct v4l2_modulator *p = arg;
1505
Hans Verkuila3998102008-07-21 02:57:38 -03001506 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001507 if (!ret)
1508 dbgarg(cmd, "index=%d, name=%s, "
1509 "capability=%d, rangelow=%d,"
1510 " rangehigh=%d, txsubchans=%d\n",
1511 p->index, p->name, p->capability,
1512 p->rangelow, p->rangehigh,
1513 p->txsubchans);
1514 break;
1515 }
1516 case VIDIOC_S_MODULATOR:
1517 {
1518 struct v4l2_modulator *p = arg;
1519
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001520 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1521 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1522 p->index, p->name, p->capability, p->rangelow,
1523 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001524 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001525 break;
1526 }
1527 case VIDIOC_G_CROP:
1528 {
1529 struct v4l2_crop *p = arg;
1530
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001531 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001532
1533 if (ops->vidioc_g_crop) {
1534 ret = ops->vidioc_g_crop(file, fh, p);
1535 } else {
1536 /* simulate capture crop using selection api */
1537 struct v4l2_selection s = {
1538 .type = p->type,
1539 };
1540
1541 /* crop means compose for output devices */
1542 if (V4L2_TYPE_IS_OUTPUT(p->type))
1543 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1544 else
1545 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1546
1547 ret = ops->vidioc_g_selection(file, fh, &s);
1548
1549 /* copying results to old structure on success */
1550 if (!ret)
1551 p->c = s.r;
1552 }
1553
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001554 if (!ret)
1555 dbgrect(vfd, "", &p->c);
1556 break;
1557 }
1558 case VIDIOC_S_CROP:
1559 {
1560 struct v4l2_crop *p = arg;
1561
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001562 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1563 dbgrect(vfd, "", &p->c);
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001564
1565 if (ops->vidioc_s_crop) {
1566 ret = ops->vidioc_s_crop(file, fh, p);
1567 } else {
1568 /* simulate capture crop using selection api */
1569 struct v4l2_selection s = {
1570 .type = p->type,
1571 .r = p->c,
1572 };
1573
1574 /* crop means compose for output devices */
1575 if (V4L2_TYPE_IS_OUTPUT(p->type))
1576 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1577 else
1578 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1579
1580 ret = ops->vidioc_s_selection(file, fh, &s);
1581 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001582 break;
1583 }
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001584 case VIDIOC_G_SELECTION:
1585 {
1586 struct v4l2_selection *p = arg;
1587
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001588 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1589
1590 ret = ops->vidioc_g_selection(file, fh, p);
1591 if (!ret)
1592 dbgrect(vfd, "", &p->r);
1593 break;
1594 }
1595 case VIDIOC_S_SELECTION:
1596 {
1597 struct v4l2_selection *p = arg;
1598
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001599
1600 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1601 dbgrect(vfd, "", &p->r);
1602
1603 ret = ops->vidioc_s_selection(file, fh, p);
1604 break;
1605 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001606 case VIDIOC_CROPCAP:
1607 {
1608 struct v4l2_cropcap *p = arg;
1609
1610 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001611 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001612 if (ops->vidioc_cropcap) {
1613 ret = ops->vidioc_cropcap(file, fh, p);
1614 } else {
1615 struct v4l2_selection s = { .type = p->type };
1616
1617 /* obtaining bounds */
1618 if (V4L2_TYPE_IS_OUTPUT(p->type))
1619 s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
1620 else
1621 s.target = V4L2_SEL_TGT_CROP_BOUNDS;
1622
1623 ret = ops->vidioc_g_selection(file, fh, &s);
1624 if (ret)
1625 break;
1626 p->bounds = s.r;
1627
1628 /* obtaining defrect */
1629 if (V4L2_TYPE_IS_OUTPUT(p->type))
1630 s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
1631 else
1632 s.target = V4L2_SEL_TGT_CROP_DEFAULT;
1633
1634 ret = ops->vidioc_g_selection(file, fh, &s);
1635 if (ret)
1636 break;
1637 p->defrect = s.r;
1638
1639 /* setting trivial pixelaspect */
1640 p->pixelaspect.numerator = 1;
1641 p->pixelaspect.denominator = 1;
1642 }
1643
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001644 if (!ret) {
1645 dbgrect(vfd, "bounds ", &p->bounds);
1646 dbgrect(vfd, "defrect ", &p->defrect);
1647 }
1648 break;
1649 }
1650 case VIDIOC_G_JPEGCOMP:
1651 {
1652 struct v4l2_jpegcompression *p = arg;
1653
Hans Verkuila3998102008-07-21 02:57:38 -03001654 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001655 if (!ret)
1656 dbgarg(cmd, "quality=%d, APPn=%d, "
1657 "APP_len=%d, COM_len=%d, "
1658 "jpeg_markers=%d\n",
1659 p->quality, p->APPn, p->APP_len,
1660 p->COM_len, p->jpeg_markers);
1661 break;
1662 }
1663 case VIDIOC_S_JPEGCOMP:
1664 {
1665 struct v4l2_jpegcompression *p = arg;
1666
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001667 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1668 "COM_len=%d, jpeg_markers=%d\n",
1669 p->quality, p->APPn, p->APP_len,
1670 p->COM_len, p->jpeg_markers);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001671 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001672 break;
1673 }
1674 case VIDIOC_G_ENC_INDEX:
1675 {
1676 struct v4l2_enc_idx *p = arg;
1677
Hans Verkuila3998102008-07-21 02:57:38 -03001678 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001679 if (!ret)
1680 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1681 p->entries, p->entries_cap);
1682 break;
1683 }
1684 case VIDIOC_ENCODER_CMD:
1685 {
1686 struct v4l2_encoder_cmd *p = arg;
1687
Hans Verkuila3998102008-07-21 02:57:38 -03001688 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001689 if (!ret)
1690 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1691 break;
1692 }
1693 case VIDIOC_TRY_ENCODER_CMD:
1694 {
1695 struct v4l2_encoder_cmd *p = arg;
1696
Hans Verkuila3998102008-07-21 02:57:38 -03001697 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001698 if (!ret)
1699 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1700 break;
1701 }
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001702 case VIDIOC_DECODER_CMD:
1703 {
1704 struct v4l2_decoder_cmd *p = arg;
1705
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001706 ret = ops->vidioc_decoder_cmd(file, fh, p);
1707 if (!ret)
1708 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1709 break;
1710 }
1711 case VIDIOC_TRY_DECODER_CMD:
1712 {
1713 struct v4l2_decoder_cmd *p = arg;
1714
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001715 ret = ops->vidioc_try_decoder_cmd(file, fh, p);
1716 if (!ret)
1717 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1718 break;
1719 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001720 case VIDIOC_G_PARM:
1721 {
1722 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001723
Hans Verkuila3998102008-07-21 02:57:38 -03001724 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001725 ret = check_fmt(ops, p->type);
1726 if (ret)
1727 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001728 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001729 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001730 v4l2_std_id std = vfd->current_norm;
1731
Hans Verkuil93d5a302011-08-09 09:32:06 -03001732 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001733 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001734 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001735
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001736 ret = 0;
Hans Verkuil0c142c82012-05-25 11:51:31 -03001737 p->parm.capture.readbuffers = 2;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001738 if (ops->vidioc_g_std)
1739 ret = ops->vidioc_g_std(file, fh, &std);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001740 if (ret == 0)
1741 v4l2_video_std_frame_period(std,
1742 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001743 }
1744
1745 dbgarg(cmd, "type=%d\n", p->type);
1746 break;
1747 }
1748 case VIDIOC_S_PARM:
1749 {
1750 struct v4l2_streamparm *p = arg;
1751
Trent Piepho34796bc2009-03-28 22:25:35 -03001752 ret = check_fmt(ops, p->type);
1753 if (ret)
1754 break;
1755
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001756 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001757 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001758 break;
1759 }
1760 case VIDIOC_G_TUNER:
1761 {
1762 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001763
Hans Verkuil227690d2011-06-12 06:36:41 -03001764 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1765 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001766 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001767 if (!ret)
1768 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1769 "capability=0x%x, rangelow=%d, "
1770 "rangehigh=%d, signal=%d, afc=%d, "
1771 "rxsubchans=0x%x, audmode=%d\n",
1772 p->index, p->name, p->type,
1773 p->capability, p->rangelow,
1774 p->rangehigh, p->signal, p->afc,
1775 p->rxsubchans, p->audmode);
1776 break;
1777 }
1778 case VIDIOC_S_TUNER:
1779 {
1780 struct v4l2_tuner *p = arg;
1781
Hans Verkuil227690d2011-06-12 06:36:41 -03001782 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1783 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001784 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1785 "capability=0x%x, rangelow=%d, "
1786 "rangehigh=%d, signal=%d, afc=%d, "
1787 "rxsubchans=0x%x, audmode=%d\n",
1788 p->index, p->name, p->type,
1789 p->capability, p->rangelow,
1790 p->rangehigh, p->signal, p->afc,
1791 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001792 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001793 break;
1794 }
1795 case VIDIOC_G_FREQUENCY:
1796 {
1797 struct v4l2_frequency *p = arg;
1798
Hans Verkuil227690d2011-06-12 06:36:41 -03001799 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1800 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001801 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001802 if (!ret)
1803 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1804 p->tuner, p->type, p->frequency);
1805 break;
1806 }
1807 case VIDIOC_S_FREQUENCY:
1808 {
1809 struct v4l2_frequency *p = arg;
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001810 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001811
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001812 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1813 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001814 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1815 p->tuner, p->type, p->frequency);
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001816 if (p->type != type)
1817 ret = -EINVAL;
1818 else
1819 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001820 break;
1821 }
1822 case VIDIOC_G_SLICED_VBI_CAP:
1823 {
1824 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001825
Trent Piepho19c96e42009-03-04 01:21:02 -03001826 /* Clear up to type, everything after type is zerod already */
1827 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1828
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001829 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001830 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001831 if (!ret)
1832 dbgarg2("service_set=%d\n", p->service_set);
1833 break;
1834 }
1835 case VIDIOC_LOG_STATUS:
1836 {
Hans Verkuile2ecb252012-02-02 08:20:53 -03001837 if (vfd->v4l2_dev)
1838 pr_info("%s: ================= START STATUS =================\n",
1839 vfd->v4l2_dev->name);
Hans Verkuila3998102008-07-21 02:57:38 -03001840 ret = ops->vidioc_log_status(file, fh);
Hans Verkuile2ecb252012-02-02 08:20:53 -03001841 if (vfd->v4l2_dev)
1842 pr_info("%s: ================== END STATUS ==================\n",
1843 vfd->v4l2_dev->name);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001844 break;
1845 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001846 case VIDIOC_DBG_G_REGISTER:
1847 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001848#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001849 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001850
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001851 if (!capable(CAP_SYS_ADMIN))
1852 ret = -EPERM;
1853 else
1854 ret = ops->vidioc_g_register(file, fh, p);
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001855#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001856 break;
1857 }
1858 case VIDIOC_DBG_S_REGISTER:
1859 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001860#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001861 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001862
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001863 if (!capable(CAP_SYS_ADMIN))
1864 ret = -EPERM;
1865 else
1866 ret = ops->vidioc_s_register(file, fh, p);
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001867#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001868 break;
1869 }
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001870 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001871 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001872 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001873
Hans Verkuil80b36e02009-02-07 11:00:02 -03001874 p->ident = V4L2_IDENT_NONE;
1875 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001876 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001877 if (!ret)
1878 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1879 break;
1880 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001881 case VIDIOC_S_HW_FREQ_SEEK:
1882 {
1883 struct v4l2_hw_freq_seek *p = arg;
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001884 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001885
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001886 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1887 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001888 dbgarg(cmd,
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001889 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1890 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1891 if (p->type != type)
1892 ret = -EINVAL;
1893 else
1894 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
Hans Verkuila3998102008-07-21 02:57:38 -03001895 break;
1896 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001897 case VIDIOC_ENUM_FRAMESIZES:
1898 {
1899 struct v4l2_frmsizeenum *p = arg;
1900
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001901 ret = ops->vidioc_enum_framesizes(file, fh, p);
1902 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001903 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1904 p->index,
1905 (p->pixel_format & 0xff),
1906 (p->pixel_format >> 8) & 0xff,
1907 (p->pixel_format >> 16) & 0xff,
1908 (p->pixel_format >> 24) & 0xff,
1909 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001910 switch (p->type) {
1911 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001912 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001913 p->discrete.width, p->discrete.height);
1914 break;
1915 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001916 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001917 p->stepwise.min_width, p->stepwise.min_height,
1918 p->stepwise.step_width, p->stepwise.step_height,
1919 p->stepwise.max_width, p->stepwise.max_height);
1920 break;
1921 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001922 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001923 break;
1924 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001925 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001926 }
1927
1928 break;
1929 }
1930 case VIDIOC_ENUM_FRAMEINTERVALS:
1931 {
1932 struct v4l2_frmivalenum *p = arg;
1933
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001934 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1935 dbgarg(cmd,
1936 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1937 p->index, p->pixel_format,
1938 p->width, p->height, p->type);
1939 switch (p->type) {
1940 case V4L2_FRMIVAL_TYPE_DISCRETE:
1941 dbgarg2("fps=%d/%d\n",
1942 p->discrete.numerator,
1943 p->discrete.denominator);
1944 break;
1945 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03001946 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1947 p->stepwise.min.numerator,
1948 p->stepwise.min.denominator,
1949 p->stepwise.max.numerator,
1950 p->stepwise.max.denominator,
1951 p->stepwise.step.numerator,
1952 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001953 break;
1954 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1955 dbgarg2("continuous\n");
1956 break;
1957 default:
1958 dbgarg2("- Unknown type!\n");
1959 }
1960 break;
1961 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001962 case VIDIOC_ENUM_DV_PRESETS:
1963 {
1964 struct v4l2_dv_enum_preset *p = arg;
1965
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001966 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1967 if (!ret)
1968 dbgarg(cmd,
1969 "index=%d, preset=%d, name=%s, width=%d,"
1970 " height=%d ",
1971 p->index, p->preset, p->name, p->width,
1972 p->height);
1973 break;
1974 }
1975 case VIDIOC_S_DV_PRESET:
1976 {
1977 struct v4l2_dv_preset *p = arg;
1978
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001979 dbgarg(cmd, "preset=%d\n", p->preset);
1980 ret = ops->vidioc_s_dv_preset(file, fh, p);
1981 break;
1982 }
1983 case VIDIOC_G_DV_PRESET:
1984 {
1985 struct v4l2_dv_preset *p = arg;
1986
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001987 ret = ops->vidioc_g_dv_preset(file, fh, p);
1988 if (!ret)
1989 dbgarg(cmd, "preset=%d\n", p->preset);
1990 break;
1991 }
1992 case VIDIOC_QUERY_DV_PRESET:
1993 {
1994 struct v4l2_dv_preset *p = arg;
1995
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001996 ret = ops->vidioc_query_dv_preset(file, fh, p);
1997 if (!ret)
1998 dbgarg(cmd, "preset=%d\n", p->preset);
1999 break;
2000 }
2001 case VIDIOC_S_DV_TIMINGS:
2002 {
2003 struct v4l2_dv_timings *p = arg;
2004
Hans Verkuil5d7758e2012-05-15 08:06:44 -03002005 dbgtimings(vfd, p);
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002006 switch (p->type) {
2007 case V4L2_DV_BT_656_1120:
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002008 ret = ops->vidioc_s_dv_timings(file, fh, p);
2009 break;
2010 default:
Hans Verkuil5d7758e2012-05-15 08:06:44 -03002011 ret = -EINVAL;
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002012 break;
2013 }
2014 break;
2015 }
2016 case VIDIOC_G_DV_TIMINGS:
2017 {
2018 struct v4l2_dv_timings *p = arg;
2019
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002020 ret = ops->vidioc_g_dv_timings(file, fh, p);
Hans Verkuil5d7758e2012-05-15 08:06:44 -03002021 if (!ret)
2022 dbgtimings(vfd, p);
2023 break;
2024 }
2025 case VIDIOC_ENUM_DV_TIMINGS:
2026 {
2027 struct v4l2_enum_dv_timings *p = arg;
2028
2029 if (!ops->vidioc_enum_dv_timings)
2030 break;
2031
2032 ret = ops->vidioc_enum_dv_timings(file, fh, p);
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002033 if (!ret) {
Hans Verkuil5d7758e2012-05-15 08:06:44 -03002034 dbgarg(cmd, "index=%d: ", p->index);
2035 dbgtimings(vfd, &p->timings);
2036 }
2037 break;
2038 }
2039 case VIDIOC_QUERY_DV_TIMINGS:
2040 {
2041 struct v4l2_dv_timings *p = arg;
2042
2043 if (!ops->vidioc_query_dv_timings)
2044 break;
2045
2046 ret = ops->vidioc_query_dv_timings(file, fh, p);
2047 if (!ret)
2048 dbgtimings(vfd, p);
2049 break;
2050 }
2051 case VIDIOC_DV_TIMINGS_CAP:
2052 {
2053 struct v4l2_dv_timings_cap *p = arg;
2054
2055 if (!ops->vidioc_dv_timings_cap)
2056 break;
2057
2058 ret = ops->vidioc_dv_timings_cap(file, fh, p);
2059 if (ret)
2060 break;
2061 switch (p->type) {
2062 case V4L2_DV_BT_656_1120:
2063 dbgarg(cmd,
2064 "type=%d, width=%u-%u, height=%u-%u, "
2065 "pixelclock=%llu-%llu, standards=%x, capabilities=%x ",
2066 p->type,
2067 p->bt.min_width, p->bt.max_width,
2068 p->bt.min_height, p->bt.max_height,
2069 p->bt.min_pixelclock, p->bt.max_pixelclock,
2070 p->bt.standards, p->bt.capabilities);
2071 break;
2072 default:
2073 dbgarg(cmd, "unknown type ");
2074 break;
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002075 }
2076 break;
2077 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002078 case VIDIOC_DQEVENT:
2079 {
2080 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002081
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002082 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2083 if (ret < 0) {
2084 dbgarg(cmd, "no pending events?");
2085 break;
2086 }
2087 dbgarg(cmd,
2088 "pending=%d, type=0x%8.8x, sequence=%d, "
2089 "timestamp=%lu.%9.9lu ",
2090 ev->pending, ev->type, ev->sequence,
2091 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2092 break;
2093 }
2094 case VIDIOC_SUBSCRIBE_EVENT:
2095 {
2096 struct v4l2_event_subscription *sub = arg;
2097
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002098 ret = ops->vidioc_subscribe_event(fh, sub);
2099 if (ret < 0) {
2100 dbgarg(cmd, "failed, ret=%ld", ret);
2101 break;
2102 }
2103 dbgarg(cmd, "type=0x%8.8x", sub->type);
2104 break;
2105 }
2106 case VIDIOC_UNSUBSCRIBE_EVENT:
2107 {
2108 struct v4l2_event_subscription *sub = arg;
2109
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002110 ret = ops->vidioc_unsubscribe_event(fh, sub);
2111 if (ret < 0) {
2112 dbgarg(cmd, "failed, ret=%ld", ret);
2113 break;
2114 }
2115 dbgarg(cmd, "type=0x%8.8x", sub->type);
2116 break;
2117 }
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002118 case VIDIOC_CREATE_BUFS:
2119 {
2120 struct v4l2_create_buffers *create = arg;
2121
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002122 ret = check_fmt(ops, create->format.type);
2123 if (ret)
2124 break;
2125
2126 ret = ops->vidioc_create_bufs(file, fh, create);
2127
2128 dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2129 break;
2130 }
2131 case VIDIOC_PREPARE_BUF:
2132 {
2133 struct v4l2_buffer *b = arg;
2134
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002135 ret = check_fmt(ops, b->type);
2136 if (ret)
2137 break;
2138
2139 ret = ops->vidioc_prepare_buf(file, fh, b);
2140
2141 dbgarg(cmd, "index=%d", b->index);
2142 break;
2143 }
Hans Verkuila3998102008-07-21 02:57:38 -03002144 default:
Hans Verkuila3998102008-07-21 02:57:38 -03002145 if (!ops->vidioc_default)
2146 break;
Hans Verkuil4b902fe2012-05-10 05:40:50 -03002147 ret = ops->vidioc_default(file, fh, use_fh_prio ?
2148 v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
2149 cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002150 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002151 } /* switch */
2152
Hans Verkuil86748f32012-06-22 06:04:16 -03002153done:
2154 if (vfd->debug) {
2155 if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
2156 if (ret < 0)
2157 printk(KERN_DEBUG "%s: error %ld\n",
2158 video_device_node_name(vfd), ret);
2159 return ret;
2160 }
2161 v4l_print_ioctl(vfd->name, cmd);
2162 if (ret < 0)
2163 pr_cont(": error %ld\n", ret);
2164 else if (vfd->debug == V4L2_DEBUG_IOCTL)
2165 pr_cont("\n");
2166 else if (!info->debug)
2167 return ret;
2168 else if (_IOC_DIR(cmd) == _IOC_NONE)
2169 info->debug(arg, write_only);
2170 else {
2171 pr_cont(": ");
2172 info->debug(arg, write_only);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002173 }
2174 }
2175
2176 return ret;
2177}
2178
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002179static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2180 void * __user *user_ptr, void ***kernel_ptr)
2181{
2182 int ret = 0;
2183
2184 switch (cmd) {
2185 case VIDIOC_QUERYBUF:
2186 case VIDIOC_QBUF:
2187 case VIDIOC_DQBUF: {
2188 struct v4l2_buffer *buf = parg;
2189
2190 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2191 if (buf->length > VIDEO_MAX_PLANES) {
2192 ret = -EINVAL;
2193 break;
2194 }
2195 *user_ptr = (void __user *)buf->m.planes;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002196 *kernel_ptr = (void *)&buf->m.planes;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002197 *array_size = sizeof(struct v4l2_plane) * buf->length;
2198 ret = 1;
2199 }
2200 break;
2201 }
2202
2203 case VIDIOC_S_EXT_CTRLS:
2204 case VIDIOC_G_EXT_CTRLS:
2205 case VIDIOC_TRY_EXT_CTRLS: {
2206 struct v4l2_ext_controls *ctrls = parg;
2207
2208 if (ctrls->count != 0) {
Dan Carpenter6c061082012-01-05 02:27:57 -03002209 if (ctrls->count > V4L2_CID_MAX_CTRLS) {
2210 ret = -EINVAL;
2211 break;
2212 }
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002213 *user_ptr = (void __user *)ctrls->controls;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002214 *kernel_ptr = (void *)&ctrls->controls;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002215 *array_size = sizeof(struct v4l2_ext_control)
2216 * ctrls->count;
2217 ret = 1;
2218 }
2219 break;
2220 }
2221 }
2222
2223 return ret;
2224}
2225
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002226long
2227video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2228 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002229{
2230 char sbuf[128];
2231 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002232 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002233 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002234 bool has_array_args;
2235 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002236 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002237 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002238
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002239 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002240 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002241 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2242 parg = sbuf;
2243 } else {
2244 /* too big to allocate from stack */
2245 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2246 if (NULL == mbuf)
2247 return -ENOMEM;
2248 parg = mbuf;
2249 }
2250
2251 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002252 if (_IOC_DIR(cmd) & _IOC_WRITE) {
Hans Verkuil27cd2ab2012-06-09 08:55:31 -03002253 unsigned int n = _IOC_SIZE(cmd);
2254
2255 /*
2256 * In some cases, only a few fields are used as input,
2257 * i.e. when the app sets "index" and then the driver
2258 * fills in the rest of the structure for the thing
2259 * with that index. We only need to copy up the first
2260 * non-input field.
2261 */
2262 if (v4l2_is_known_ioctl(cmd)) {
2263 u32 flags = v4l2_ioctls[_IOC_NR(cmd)].flags;
2264 if (flags & INFO_FL_CLEAR_MASK)
2265 n = (flags & INFO_FL_CLEAR_MASK) >> 16;
2266 }
Trent Piepho19c96e42009-03-04 01:21:02 -03002267
2268 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002269 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002270
2271 /* zero out anything we don't copy from userspace */
2272 if (n < _IOC_SIZE(cmd))
2273 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002274 } else {
2275 /* read-only ioctl */
2276 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002277 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002278 }
2279
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002280 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2281 if (err < 0)
2282 goto out;
2283 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002284
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002285 if (has_array_args) {
2286 /*
2287 * When adding new types of array args, make sure that the
2288 * parent argument to ioctl (which contains the pointer to the
2289 * array) fits into sbuf (so that mbuf will still remain
2290 * unused up to here).
2291 */
2292 mbuf = kmalloc(array_size, GFP_KERNEL);
2293 err = -ENOMEM;
2294 if (NULL == mbuf)
2295 goto out_array_args;
2296 err = -EFAULT;
2297 if (copy_from_user(mbuf, user_ptr, array_size))
2298 goto out_array_args;
2299 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002300 }
2301
2302 /* Handles IOCTL */
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002303 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002304 if (err == -ENOIOCTLCMD)
Hans Verkuil02bbb812012-02-08 08:09:36 -03002305 err = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002306
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002307 if (has_array_args) {
2308 *kernel_ptr = user_ptr;
2309 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002310 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002311 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002312 }
Hans Verkuil5d7758e2012-05-15 08:06:44 -03002313 /* VIDIOC_QUERY_DV_TIMINGS can return an error, but still have valid
2314 results that must be returned. */
2315 if (err < 0 && cmd != VIDIOC_QUERY_DV_TIMINGS)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002316 goto out;
2317
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002318out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002319 /* Copy results into user buffer */
2320 switch (_IOC_DIR(cmd)) {
2321 case _IOC_READ:
2322 case (_IOC_WRITE | _IOC_READ):
2323 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2324 err = -EFAULT;
2325 break;
2326 }
2327
2328out:
2329 kfree(mbuf);
2330 return err;
2331}
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002332EXPORT_SYMBOL(video_usercopy);
2333
2334long video_ioctl2(struct file *file,
2335 unsigned int cmd, unsigned long arg)
2336{
2337 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2338}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002339EXPORT_SYMBOL(video_ioctl2);