blob: 3df1f80f1c5c6990aff63ac14fb93b13ec41e276 [file] [log] [blame]
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001/*
2 * Video capture interface for Linux version 2
3 *
4 * A generic framework to process V4L2 ioctl commands.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
Alan Coxd9b01442008-10-27 15:13:47 -030011 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
Hans Verkuil35ea11f2008-07-20 08:12:02 -030012 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
13 */
14
15#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030017#include <linux/types.h>
18#include <linux/kernel.h>
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -030019#include <linux/version.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030020
Hans Verkuil35ea11f2008-07-20 08:12:02 -030021#include <linux/videodev2.h>
22
Hans Verkuil35ea11f2008-07-20 08:12:02 -030023#include <media/v4l2-common.h>
24#include <media/v4l2-ioctl.h>
Hans Verkuil11bbc1c2010-05-16 09:24:06 -030025#include <media/v4l2-ctrls.h>
Sakari Ailusd3d7c962010-03-27 11:02:10 -030026#include <media/v4l2-fh.h>
27#include <media/v4l2-event.h>
Hans Verkuil99cd47bc2011-03-11 19:00:56 -030028#include <media/v4l2-device.h>
Hans Verkuil80b36e02009-02-07 11:00:02 -030029#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030030
31#define dbgarg(cmd, fmt, arg...) \
32 do { \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
37 } \
38 } while (0)
39
40#define dbgarg2(fmt, arg...) \
41 do { \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
44 } while (0)
45
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030046#define dbgarg3(fmt, arg...) \
47 do { \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
50 } while (0)
51
Lucas De Marchi25985ed2011-03-30 22:57:33 -030052/* Zero out the end of the struct pointed to by p. Everything after, but
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030053 * not including, the specified field is cleared. */
54#define CLEAR_AFTER_FIELD(p, field) \
55 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
57
Hans Verkuil35ea11f2008-07-20 08:12:02 -030058struct std_descr {
59 v4l2_std_id std;
60 const char *descr;
61};
62
63static const struct std_descr standards[] = {
64 { V4L2_STD_NTSC, "NTSC" },
65 { V4L2_STD_NTSC_M, "NTSC-M" },
66 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
67 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
68 { V4L2_STD_NTSC_443, "NTSC-443" },
69 { V4L2_STD_PAL, "PAL" },
70 { V4L2_STD_PAL_BG, "PAL-BG" },
71 { V4L2_STD_PAL_B, "PAL-B" },
72 { V4L2_STD_PAL_B1, "PAL-B1" },
73 { V4L2_STD_PAL_G, "PAL-G" },
74 { V4L2_STD_PAL_H, "PAL-H" },
75 { V4L2_STD_PAL_I, "PAL-I" },
76 { V4L2_STD_PAL_DK, "PAL-DK" },
77 { V4L2_STD_PAL_D, "PAL-D" },
78 { V4L2_STD_PAL_D1, "PAL-D1" },
79 { V4L2_STD_PAL_K, "PAL-K" },
80 { V4L2_STD_PAL_M, "PAL-M" },
81 { V4L2_STD_PAL_N, "PAL-N" },
82 { V4L2_STD_PAL_Nc, "PAL-Nc" },
83 { V4L2_STD_PAL_60, "PAL-60" },
84 { V4L2_STD_SECAM, "SECAM" },
85 { V4L2_STD_SECAM_B, "SECAM-B" },
86 { V4L2_STD_SECAM_G, "SECAM-G" },
87 { V4L2_STD_SECAM_H, "SECAM-H" },
88 { V4L2_STD_SECAM_DK, "SECAM-DK" },
89 { V4L2_STD_SECAM_D, "SECAM-D" },
90 { V4L2_STD_SECAM_K, "SECAM-K" },
91 { V4L2_STD_SECAM_K1, "SECAM-K1" },
92 { V4L2_STD_SECAM_L, "SECAM-L" },
93 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
94 { 0, "Unknown" }
95};
96
97/* video4linux standard ID conversion to standard name
98 */
99const char *v4l2_norm_to_name(v4l2_std_id id)
100{
101 u32 myid = id;
102 int i;
103
104 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
105 64 bit comparations. So, on that architecture, with some gcc
106 variants, compilation fails. Currently, the max value is 30bit wide.
107 */
108 BUG_ON(myid != id);
109
110 for (i = 0; standards[i].std; i++)
111 if (myid == standards[i].std)
112 break;
113 return standards[i].descr;
114}
115EXPORT_SYMBOL(v4l2_norm_to_name);
116
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300117/* Returns frame period for the given standard */
118void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
119{
120 if (id & V4L2_STD_525_60) {
121 frameperiod->numerator = 1001;
122 frameperiod->denominator = 30000;
123 } else {
124 frameperiod->numerator = 1;
125 frameperiod->denominator = 25;
126 }
127}
128EXPORT_SYMBOL(v4l2_video_std_frame_period);
129
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300130/* Fill in the fields of a v4l2_standard structure according to the
131 'id' and 'transmission' parameters. Returns negative on error. */
132int v4l2_video_std_construct(struct v4l2_standard *vs,
133 int id, const char *name)
134{
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300135 vs->id = id;
136 v4l2_video_std_frame_period(id, &vs->frameperiod);
137 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300138 strlcpy(vs->name, name, sizeof(vs->name));
139 return 0;
140}
141EXPORT_SYMBOL(v4l2_video_std_construct);
142
143/* ----------------------------------------------------------------- */
144/* some arrays for pretty-printing debug messages of enum types */
145
146const char *v4l2_field_names[] = {
147 [V4L2_FIELD_ANY] = "any",
148 [V4L2_FIELD_NONE] = "none",
149 [V4L2_FIELD_TOP] = "top",
150 [V4L2_FIELD_BOTTOM] = "bottom",
151 [V4L2_FIELD_INTERLACED] = "interlaced",
152 [V4L2_FIELD_SEQ_TB] = "seq-tb",
153 [V4L2_FIELD_SEQ_BT] = "seq-bt",
154 [V4L2_FIELD_ALTERNATE] = "alternate",
155 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
156 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
157};
158EXPORT_SYMBOL(v4l2_field_names);
159
160const char *v4l2_type_names[] = {
161 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
162 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
163 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
164 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
165 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
166 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
167 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
168 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
Pawel Osciakf8f39142010-07-29 14:44:25 -0300169 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
170 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300171};
172EXPORT_SYMBOL(v4l2_type_names);
173
174static const char *v4l2_memory_names[] = {
175 [V4L2_MEMORY_MMAP] = "mmap",
176 [V4L2_MEMORY_USERPTR] = "userptr",
177 [V4L2_MEMORY_OVERLAY] = "overlay",
178};
179
180#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
181 arr[a] : "unknown")
182
183/* ------------------------------------------------------------------ */
184/* debug help functions */
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300185
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300186struct v4l2_ioctl_info {
187 unsigned int ioctl;
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300188 u16 flags;
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300189 const char * const name;
190};
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300191
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300192/* This control can be valid if the filehandle passes a control handler. */
193#define INFO_FL_CTRL (1 << 1)
194
195#define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = { \
196 .ioctl = _ioctl, \
197 .flags = _flags, \
198 .name = #_ioctl, \
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300199}
200
201static struct v4l2_ioctl_info v4l2_ioctls[] = {
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300202 IOCTL_INFO(VIDIOC_QUERYCAP, 0),
203 IOCTL_INFO(VIDIOC_ENUM_FMT, 0),
204 IOCTL_INFO(VIDIOC_G_FMT, 0),
205 IOCTL_INFO(VIDIOC_S_FMT, 0),
206 IOCTL_INFO(VIDIOC_REQBUFS, 0),
207 IOCTL_INFO(VIDIOC_QUERYBUF, 0),
208 IOCTL_INFO(VIDIOC_G_FBUF, 0),
209 IOCTL_INFO(VIDIOC_S_FBUF, 0),
210 IOCTL_INFO(VIDIOC_OVERLAY, 0),
211 IOCTL_INFO(VIDIOC_QBUF, 0),
212 IOCTL_INFO(VIDIOC_DQBUF, 0),
213 IOCTL_INFO(VIDIOC_STREAMON, 0),
214 IOCTL_INFO(VIDIOC_STREAMOFF, 0),
215 IOCTL_INFO(VIDIOC_G_PARM, 0),
216 IOCTL_INFO(VIDIOC_S_PARM, 0),
217 IOCTL_INFO(VIDIOC_G_STD, 0),
218 IOCTL_INFO(VIDIOC_S_STD, 0),
219 IOCTL_INFO(VIDIOC_ENUMSTD, 0),
220 IOCTL_INFO(VIDIOC_ENUMINPUT, 0),
221 IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL),
222 IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_CTRL),
223 IOCTL_INFO(VIDIOC_G_TUNER, 0),
224 IOCTL_INFO(VIDIOC_S_TUNER, 0),
225 IOCTL_INFO(VIDIOC_G_AUDIO, 0),
226 IOCTL_INFO(VIDIOC_S_AUDIO, 0),
227 IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL),
228 IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL),
229 IOCTL_INFO(VIDIOC_G_INPUT, 0),
230 IOCTL_INFO(VIDIOC_S_INPUT, 0),
231 IOCTL_INFO(VIDIOC_G_OUTPUT, 0),
232 IOCTL_INFO(VIDIOC_S_OUTPUT, 0),
233 IOCTL_INFO(VIDIOC_ENUMOUTPUT, 0),
234 IOCTL_INFO(VIDIOC_G_AUDOUT, 0),
235 IOCTL_INFO(VIDIOC_S_AUDOUT, 0),
236 IOCTL_INFO(VIDIOC_G_MODULATOR, 0),
237 IOCTL_INFO(VIDIOC_S_MODULATOR, 0),
238 IOCTL_INFO(VIDIOC_G_FREQUENCY, 0),
239 IOCTL_INFO(VIDIOC_S_FREQUENCY, 0),
240 IOCTL_INFO(VIDIOC_CROPCAP, 0),
241 IOCTL_INFO(VIDIOC_G_CROP, 0),
242 IOCTL_INFO(VIDIOC_S_CROP, 0),
243 IOCTL_INFO(VIDIOC_G_SELECTION, 0),
244 IOCTL_INFO(VIDIOC_S_SELECTION, 0),
245 IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
246 IOCTL_INFO(VIDIOC_S_JPEGCOMP, 0),
247 IOCTL_INFO(VIDIOC_QUERYSTD, 0),
248 IOCTL_INFO(VIDIOC_TRY_FMT, 0),
249 IOCTL_INFO(VIDIOC_ENUMAUDIO, 0),
250 IOCTL_INFO(VIDIOC_ENUMAUDOUT, 0),
251 IOCTL_INFO(VIDIOC_G_PRIORITY, 0),
252 IOCTL_INFO(VIDIOC_S_PRIORITY, 0),
253 IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, 0),
254 IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
255 IOCTL_INFO(VIDIOC_G_EXT_CTRLS, INFO_FL_CTRL),
256 IOCTL_INFO(VIDIOC_S_EXT_CTRLS, INFO_FL_CTRL),
257 IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, 0),
258 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, 0),
259 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, 0),
260 IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0),
261 IOCTL_INFO(VIDIOC_ENCODER_CMD, 0),
262 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, 0),
263 IOCTL_INFO(VIDIOC_DECODER_CMD, 0),
264 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0),
265 IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
266 IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
267 IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
268 IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, 0),
269 IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
270 IOCTL_INFO(VIDIOC_S_DV_PRESET, 0),
271 IOCTL_INFO(VIDIOC_G_DV_PRESET, 0),
272 IOCTL_INFO(VIDIOC_QUERY_DV_PRESET, 0),
273 IOCTL_INFO(VIDIOC_S_DV_TIMINGS, 0),
274 IOCTL_INFO(VIDIOC_G_DV_TIMINGS, 0),
275 IOCTL_INFO(VIDIOC_DQEVENT, 0),
276 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0),
277 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
278 IOCTL_INFO(VIDIOC_CREATE_BUFS, 0),
279 IOCTL_INFO(VIDIOC_PREPARE_BUF, 0),
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300280};
281#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
282
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300283bool v4l2_is_known_ioctl(unsigned int cmd)
284{
285 if (_IOC_NR(cmd) >= V4L2_IOCTLS)
286 return false;
287 return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
288}
289
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300290/* Common ioctl debug function. This function can be used by
291 external ioctl messages as well as internal V4L ioctl */
292void v4l_printk_ioctl(unsigned int cmd)
293{
294 char *dir, *type;
295
296 switch (_IOC_TYPE(cmd)) {
297 case 'd':
Hans Verkuil78a3b4d2009-04-01 03:41:09 -0300298 type = "v4l2_int";
299 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300300 case 'V':
301 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
302 type = "v4l2";
303 break;
304 }
Hans Verkuil8ab75e32012-05-10 02:51:31 -0300305 printk("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300306 return;
307 default:
308 type = "unknown";
309 }
310
311 switch (_IOC_DIR(cmd)) {
312 case _IOC_NONE: dir = "--"; break;
313 case _IOC_READ: dir = "r-"; break;
314 case _IOC_WRITE: dir = "-w"; break;
315 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
316 default: dir = "*ERR*"; break;
317 }
318 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
319 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
320}
321EXPORT_SYMBOL(v4l_printk_ioctl);
322
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300323static void dbgbuf(unsigned int cmd, struct video_device *vfd,
324 struct v4l2_buffer *p)
325{
326 struct v4l2_timecode *tc = &p->timecode;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300327 struct v4l2_plane *plane;
328 int i;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300329
330 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300331 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300332 p->timestamp.tv_sec / 3600,
333 (int)(p->timestamp.tv_sec / 60) % 60,
334 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300335 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300336 p->index,
337 prt_names(p->type, v4l2_type_names),
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300338 p->flags, p->field, p->sequence,
339 prt_names(p->memory, v4l2_memory_names));
340
341 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
342 for (i = 0; i < p->length; ++i) {
343 plane = &p->m.planes[i];
344 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
345 "offset/userptr=0x%08lx, length=%d\n",
346 i, plane->bytesused, plane->data_offset,
347 plane->m.userptr, plane->length);
348 }
349 } else {
350 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
351 p->bytesused, p->m.userptr, p->length);
352 }
353
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300354 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
355 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
356 tc->hours, tc->minutes, tc->seconds,
357 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
358}
359
360static inline void dbgrect(struct video_device *vfd, char *s,
361 struct v4l2_rect *r)
362{
363 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
364 r->width, r->height);
365};
366
367static inline void v4l_print_pix_fmt(struct video_device *vfd,
368 struct v4l2_pix_format *fmt)
369{
370 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
371 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
372 fmt->width, fmt->height,
373 (fmt->pixelformat & 0xff),
374 (fmt->pixelformat >> 8) & 0xff,
375 (fmt->pixelformat >> 16) & 0xff,
376 (fmt->pixelformat >> 24) & 0xff,
377 prt_names(fmt->field, v4l2_field_names),
378 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
379};
380
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300381static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
382 struct v4l2_pix_format_mplane *fmt)
383{
384 int i;
385
386 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
387 "colorspace=%d, num_planes=%d\n",
388 fmt->width, fmt->height,
389 (fmt->pixelformat & 0xff),
390 (fmt->pixelformat >> 8) & 0xff,
391 (fmt->pixelformat >> 16) & 0xff,
392 (fmt->pixelformat >> 24) & 0xff,
393 prt_names(fmt->field, v4l2_field_names),
394 fmt->colorspace, fmt->num_planes);
395
396 for (i = 0; i < fmt->num_planes; ++i)
397 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
398 fmt->plane_fmt[i].bytesperline,
399 fmt->plane_fmt[i].sizeimage);
400}
401
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300402static inline void v4l_print_ext_ctrls(unsigned int cmd,
403 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
404{
405 __u32 i;
406
407 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
408 return;
409 dbgarg(cmd, "");
410 printk(KERN_CONT "class=0x%x", c->ctrl_class);
411 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300412 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300413 printk(KERN_CONT " id/val=0x%x/0x%x",
414 c->controls[i].id, c->controls[i].value);
415 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300416 printk(KERN_CONT " id=0x%x,size=%u",
417 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300418 }
419 printk(KERN_CONT "\n");
420};
421
422static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
423{
424 __u32 i;
425
426 /* zero the reserved fields */
427 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300428 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300429 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300430
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300431 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
432 when using extended controls.
433 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
434 is it allowed for backwards compatibility.
435 */
436 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
437 return 0;
438 /* Check that all controls are from the same control class. */
439 for (i = 0; i < c->count; i++) {
440 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
441 c->error_idx = i;
442 return 0;
443 }
444 }
445 return 1;
446}
447
Hans Verkuila3998102008-07-21 02:57:38 -0300448static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300449{
Hans Verkuila3998102008-07-21 02:57:38 -0300450 if (ops == NULL)
451 return -EINVAL;
452
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300453 switch (type) {
454 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300455 if (ops->vidioc_g_fmt_vid_cap ||
456 ops->vidioc_g_fmt_vid_cap_mplane)
457 return 0;
458 break;
459 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
460 if (ops->vidioc_g_fmt_vid_cap_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300461 return 0;
462 break;
463 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300464 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300465 return 0;
466 break;
467 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300468 if (ops->vidioc_g_fmt_vid_out ||
469 ops->vidioc_g_fmt_vid_out_mplane)
470 return 0;
471 break;
472 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
473 if (ops->vidioc_g_fmt_vid_out_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300474 return 0;
475 break;
476 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300477 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300478 return 0;
479 break;
480 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300481 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300482 return 0;
483 break;
484 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300485 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300486 return 0;
487 break;
488 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300489 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300490 return 0;
491 break;
492 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300493 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300494 return 0;
495 break;
496 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300497 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300498 return 0;
499 break;
500 }
501 return -EINVAL;
502}
503
Hans Verkuil069b7472008-12-30 07:04:34 -0300504static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300505 unsigned int cmd, void *arg)
506{
507 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300508 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300509 void *fh = file->private_data;
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300510 struct v4l2_fh *vfh = NULL;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300511 int use_fh_prio = 0;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300512 long ret_prio = 0;
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300513 long ret = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300514
Hans Verkuil6a717882010-04-06 15:56:08 -0300515 if (ops == NULL) {
516 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
517 vfd->name);
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300518 return ret;
Hans Verkuil6a717882010-04-06 15:56:08 -0300519 }
520
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300521 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
522 vfh = file->private_data;
523 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
524 if (use_fh_prio)
525 ret_prio = v4l2_prio_check(vfd->prio, vfh->prio);
526 }
527
528 if (v4l2_is_known_ioctl(cmd)) {
529 struct v4l2_ioctl_info *info = &v4l2_ioctls[_IOC_NR(cmd)];
530
531 if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
532 !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
533 return -ENOTTY;
534 }
535
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300536 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
537 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
538 v4l_print_ioctl(vfd->name, cmd);
539 printk(KERN_CONT "\n");
540 }
541
Hans Verkuil6a717882010-04-06 15:56:08 -0300542 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300543
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300544 /* --- capabilities ------------------------------------------ */
545 case VIDIOC_QUERYCAP:
546 {
547 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300548
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -0300549 cap->version = LINUX_VERSION_CODE;
Hans Verkuila3998102008-07-21 02:57:38 -0300550 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300551 if (!ret)
552 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
553 "version=0x%08x, "
Hans Verkuil583aa3a2012-01-11 06:45:05 -0300554 "capabilities=0x%08x, "
555 "device_caps=0x%08x\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300556 cap->driver, cap->card, cap->bus_info,
557 cap->version,
Hans Verkuil583aa3a2012-01-11 06:45:05 -0300558 cap->capabilities,
559 cap->device_caps);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300560 break;
561 }
562
563 /* --- priority ------------------------------------------ */
564 case VIDIOC_G_PRIORITY:
565 {
566 enum v4l2_priority *p = arg;
567
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300568 if (ops->vidioc_g_priority) {
569 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300570 } else if (use_fh_prio) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300571 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
572 ret = 0;
573 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300574 if (!ret)
575 dbgarg(cmd, "priority is %d\n", *p);
576 break;
577 }
578 case VIDIOC_S_PRIORITY:
579 {
580 enum v4l2_priority *p = arg;
581
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300582 if (!ops->vidioc_s_priority && !use_fh_prio)
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300583 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300584 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300585 if (ops->vidioc_s_priority)
586 ret = ops->vidioc_s_priority(file, fh, *p);
587 else
Hans Verkuil93d5a302011-08-09 09:32:06 -0300588 ret = ret_prio ? ret_prio :
589 v4l2_prio_change(&vfd->v4l2_dev->prio,
590 &vfh->prio, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300591 break;
592 }
593
594 /* --- capture ioctls ---------------------------------------- */
595 case VIDIOC_ENUM_FMT:
596 {
597 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300598
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300599 ret = -EINVAL;
Trent Piepho19c96e42009-03-04 01:21:02 -0300600 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300601 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300602 if (likely(ops->vidioc_enum_fmt_vid_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300603 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300604 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300605 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300606 if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300607 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
608 fh, f);
609 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300610 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300611 if (likely(ops->vidioc_enum_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300612 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300613 fh, f);
614 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300615 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300616 if (likely(ops->vidioc_enum_fmt_vid_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300617 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300618 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300619 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300620 if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300621 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
622 fh, f);
623 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300624 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300625 if (likely(ops->vidioc_enum_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300626 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300627 fh, f);
628 break;
629 default:
630 break;
631 }
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300632 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300633 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
634 "pixelformat=%c%c%c%c, description='%s'\n",
635 f->index, f->type, f->flags,
636 (f->pixelformat & 0xff),
637 (f->pixelformat >> 8) & 0xff,
638 (f->pixelformat >> 16) & 0xff,
639 (f->pixelformat >> 24) & 0xff,
640 f->description);
641 break;
642 }
643 case VIDIOC_G_FMT:
644 {
645 struct v4l2_format *f = (struct v4l2_format *)arg;
646
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300647 /* FIXME: Should be one dump per type */
648 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
649
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300650 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300651 switch (f->type) {
652 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300653 if (ops->vidioc_g_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300654 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300655 if (!ret)
656 v4l_print_pix_fmt(vfd, &f->fmt.pix);
657 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300658 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300659 if (ops->vidioc_g_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300660 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
661 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300662 if (!ret)
663 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
664 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300665 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300666 if (likely(ops->vidioc_g_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300667 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300668 fh, f);
669 break;
670 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300671 if (ops->vidioc_g_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300672 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300673 if (!ret)
674 v4l_print_pix_fmt(vfd, &f->fmt.pix);
675 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300676 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300677 if (ops->vidioc_g_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300678 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
679 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300680 if (!ret)
681 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
682 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300683 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300684 if (likely(ops->vidioc_g_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300685 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300686 fh, f);
687 break;
688 case V4L2_BUF_TYPE_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300689 if (likely(ops->vidioc_g_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300690 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300691 break;
692 case V4L2_BUF_TYPE_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300693 if (likely(ops->vidioc_g_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300694 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300695 break;
696 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300697 if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300698 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300699 fh, f);
700 break;
701 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300702 if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300703 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300704 fh, f);
705 break;
706 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300707 if (likely(ops->vidioc_g_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300708 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300709 fh, f);
710 break;
711 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300712 break;
713 }
714 case VIDIOC_S_FMT:
715 {
716 struct v4l2_format *f = (struct v4l2_format *)arg;
717
Hans Verkuil93d5a302011-08-09 09:32:06 -0300718 if (ret_prio) {
719 ret = ret_prio;
720 break;
721 }
722 ret = -EINVAL;
723
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300724 /* FIXME: Should be one dump per type */
725 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
726
727 switch (f->type) {
728 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300729 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300730 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300731 if (ops->vidioc_s_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300732 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300733 break;
734 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
735 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
736 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300737 if (ops->vidioc_s_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300738 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
739 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300740 break;
741 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300742 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300743 if (ops->vidioc_s_fmt_vid_overlay)
744 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300745 fh, f);
746 break;
747 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300748 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300749 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300750 if (ops->vidioc_s_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300751 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300752 break;
753 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
754 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
755 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300756 if (ops->vidioc_s_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300757 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
758 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300759 break;
760 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300761 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300762 if (ops->vidioc_s_fmt_vid_out_overlay)
763 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300764 fh, f);
765 break;
766 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300767 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300768 if (likely(ops->vidioc_s_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300769 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300770 break;
771 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300772 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300773 if (likely(ops->vidioc_s_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300774 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300775 break;
776 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300777 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300778 if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300779 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300780 fh, f);
781 break;
782 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300783 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300784 if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300785 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300786 fh, f);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300787
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300788 break;
789 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300790 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300791 if (likely(ops->vidioc_s_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300792 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300793 fh, f);
794 break;
795 }
796 break;
797 }
798 case VIDIOC_TRY_FMT:
799 {
800 struct v4l2_format *f = (struct v4l2_format *)arg;
801
802 /* FIXME: Should be one dump per type */
803 dbgarg(cmd, "type=%s\n", prt_names(f->type,
804 v4l2_type_names));
Hans Verkuil48ea0be2012-05-10 05:36:00 -0300805 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300806 switch (f->type) {
807 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300808 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300809 if (ops->vidioc_try_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300810 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300811 if (!ret)
812 v4l_print_pix_fmt(vfd, &f->fmt.pix);
813 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300814 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
815 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300816 if (ops->vidioc_try_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300817 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
818 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300819 if (!ret)
820 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
821 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300822 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300823 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300824 if (likely(ops->vidioc_try_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300825 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300826 fh, f);
827 break;
828 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300829 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300830 if (ops->vidioc_try_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300831 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300832 if (!ret)
833 v4l_print_pix_fmt(vfd, &f->fmt.pix);
834 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300835 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
836 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300837 if (ops->vidioc_try_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300838 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
839 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300840 if (!ret)
841 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
842 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300843 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300844 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300845 if (likely(ops->vidioc_try_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300846 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300847 fh, f);
848 break;
849 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300850 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300851 if (likely(ops->vidioc_try_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300852 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300853 break;
854 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300855 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300856 if (likely(ops->vidioc_try_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300857 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300858 break;
859 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300860 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300861 if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300862 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300863 fh, f);
864 break;
865 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300866 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300867 if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300868 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300869 fh, f);
870 break;
871 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300872 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300873 if (likely(ops->vidioc_try_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300874 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300875 fh, f);
876 break;
877 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300878 break;
879 }
880 /* FIXME: Those buf reqs could be handled here,
881 with some changes on videobuf to allow its header to be included at
882 videodev2.h or being merged at videodev2.
883 */
884 case VIDIOC_REQBUFS:
885 {
886 struct v4l2_requestbuffers *p = arg;
887
Hans Verkuil93d5a302011-08-09 09:32:06 -0300888 if (ret_prio) {
889 ret = ret_prio;
890 break;
891 }
Hans Verkuila3998102008-07-21 02:57:38 -0300892 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300893 if (ret)
894 break;
895
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300896 if (p->type < V4L2_BUF_TYPE_PRIVATE)
897 CLEAR_AFTER_FIELD(p, memory);
898
Hans Verkuila3998102008-07-21 02:57:38 -0300899 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300900 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
901 p->count,
902 prt_names(p->type, v4l2_type_names),
903 prt_names(p->memory, v4l2_memory_names));
904 break;
905 }
906 case VIDIOC_QUERYBUF:
907 {
908 struct v4l2_buffer *p = arg;
909
Hans Verkuila3998102008-07-21 02:57:38 -0300910 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300911 if (ret)
912 break;
913
Hans Verkuila3998102008-07-21 02:57:38 -0300914 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300915 if (!ret)
916 dbgbuf(cmd, vfd, p);
917 break;
918 }
919 case VIDIOC_QBUF:
920 {
921 struct v4l2_buffer *p = arg;
922
Hans Verkuila3998102008-07-21 02:57:38 -0300923 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300924 if (ret)
925 break;
926
Hans Verkuila3998102008-07-21 02:57:38 -0300927 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300928 if (!ret)
929 dbgbuf(cmd, vfd, p);
930 break;
931 }
932 case VIDIOC_DQBUF:
933 {
934 struct v4l2_buffer *p = arg;
935
Hans Verkuila3998102008-07-21 02:57:38 -0300936 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300937 if (ret)
938 break;
939
Hans Verkuila3998102008-07-21 02:57:38 -0300940 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300941 if (!ret)
942 dbgbuf(cmd, vfd, p);
943 break;
944 }
945 case VIDIOC_OVERLAY:
946 {
947 int *i = arg;
948
Hans Verkuil93d5a302011-08-09 09:32:06 -0300949 if (ret_prio) {
950 ret = ret_prio;
951 break;
952 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300953 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -0300954 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300955 break;
956 }
957 case VIDIOC_G_FBUF:
958 {
959 struct v4l2_framebuffer *p = arg;
960
Hans Verkuila3998102008-07-21 02:57:38 -0300961 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300962 if (!ret) {
963 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
964 p->capability, p->flags,
965 (unsigned long)p->base);
966 v4l_print_pix_fmt(vfd, &p->fmt);
967 }
968 break;
969 }
970 case VIDIOC_S_FBUF:
971 {
972 struct v4l2_framebuffer *p = arg;
973
Hans Verkuil93d5a302011-08-09 09:32:06 -0300974 if (ret_prio) {
975 ret = ret_prio;
976 break;
977 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300978 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
979 p->capability, p->flags, (unsigned long)p->base);
980 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -0300981 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300982 break;
983 }
984 case VIDIOC_STREAMON:
985 {
986 enum v4l2_buf_type i = *(int *)arg;
987
Hans Verkuil93d5a302011-08-09 09:32:06 -0300988 if (ret_prio) {
989 ret = ret_prio;
990 break;
991 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300992 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -0300993 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300994 break;
995 }
996 case VIDIOC_STREAMOFF:
997 {
998 enum v4l2_buf_type i = *(int *)arg;
999
Hans Verkuil93d5a302011-08-09 09:32:06 -03001000 if (ret_prio) {
1001 ret = ret_prio;
1002 break;
1003 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001004 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001005 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001006 break;
1007 }
1008 /* ---------- tv norms ---------- */
1009 case VIDIOC_ENUMSTD:
1010 {
1011 struct v4l2_standard *p = arg;
1012 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1013 unsigned int index = p->index, i, j = 0;
1014 const char *descr = "";
1015
Hans Verkuil93d5a302011-08-09 09:32:06 -03001016 if (id == 0)
1017 break;
1018 ret = -EINVAL;
1019
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001020 /* Return norm array in a canonical way */
1021 for (i = 0; i <= index && id; i++) {
1022 /* last std value in the standards array is 0, so this
1023 while always ends there since (id & 0) == 0. */
1024 while ((id & standards[j].std) != standards[j].std)
1025 j++;
1026 curr_id = standards[j].std;
1027 descr = standards[j].descr;
1028 j++;
1029 if (curr_id == 0)
1030 break;
1031 if (curr_id != V4L2_STD_PAL &&
1032 curr_id != V4L2_STD_SECAM &&
1033 curr_id != V4L2_STD_NTSC)
1034 id &= ~curr_id;
1035 }
1036 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001037 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001038
1039 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001040
1041 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1042 "framelines=%d\n", p->index,
1043 (unsigned long long)p->id, p->name,
1044 p->frameperiod.numerator,
1045 p->frameperiod.denominator,
1046 p->framelines);
1047
1048 ret = 0;
1049 break;
1050 }
1051 case VIDIOC_G_STD:
1052 {
1053 v4l2_std_id *id = arg;
1054
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001055 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001056 if (ops->vidioc_g_std)
1057 ret = ops->vidioc_g_std(file, fh, id);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001058 else if (vfd->current_norm) {
1059 ret = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001060 *id = vfd->current_norm;
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001061 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001062
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001063 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001064 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1065 break;
1066 }
1067 case VIDIOC_S_STD:
1068 {
1069 v4l2_std_id *id = arg, norm;
1070
1071 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1072
Hans Verkuil93d5a302011-08-09 09:32:06 -03001073 if (ret_prio) {
1074 ret = ret_prio;
1075 break;
1076 }
1077 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001078 norm = (*id) & vfd->tvnorms;
1079 if (vfd->tvnorms && !norm) /* Check if std is supported */
1080 break;
1081
1082 /* Calls the specific handler */
Hans Verkuil93d5a302011-08-09 09:32:06 -03001083 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001084
1085 /* Updates standard information */
1086 if (ret >= 0)
1087 vfd->current_norm = norm;
1088 break;
1089 }
1090 case VIDIOC_QUERYSTD:
1091 {
1092 v4l2_std_id *p = arg;
1093
Mauro Carvalho Chehab8715e6c2011-10-04 09:32:23 -03001094 /*
1095 * If nothing detected, it should return all supported
1096 * Drivers just need to mask the std argument, in order
1097 * to remove the standards that don't apply from the mask.
1098 * This means that tuners, audio and video decoders can join
1099 * their efforts to improve the standards detection
1100 */
1101 *p = vfd->tvnorms;
Hans Verkuila3998102008-07-21 02:57:38 -03001102 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001103 if (!ret)
1104 dbgarg(cmd, "detected std=%08Lx\n",
1105 (unsigned long long)*p);
1106 break;
1107 }
1108 /* ------ input switching ---------- */
1109 /* FIXME: Inputs can be handled inside videodev2 */
1110 case VIDIOC_ENUMINPUT:
1111 {
1112 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001113
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001114 /*
1115 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1116 * CAP_STD here based on ioctl handler provided by the
1117 * driver. If the driver doesn't support these
1118 * for a specific input, it must override these flags.
1119 */
1120 if (ops->vidioc_s_std)
1121 p->capabilities |= V4L2_IN_CAP_STD;
1122 if (ops->vidioc_s_dv_preset)
1123 p->capabilities |= V4L2_IN_CAP_PRESETS;
1124 if (ops->vidioc_s_dv_timings)
1125 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1126
Hans Verkuila3998102008-07-21 02:57:38 -03001127 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001128 if (!ret)
1129 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1130 "audioset=%d, "
1131 "tuner=%d, std=%08Lx, status=%d\n",
1132 p->index, p->name, p->type, p->audioset,
1133 p->tuner,
1134 (unsigned long long)p->std,
1135 p->status);
1136 break;
1137 }
1138 case VIDIOC_G_INPUT:
1139 {
1140 unsigned int *i = arg;
1141
Hans Verkuila3998102008-07-21 02:57:38 -03001142 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001143 if (!ret)
1144 dbgarg(cmd, "value=%d\n", *i);
1145 break;
1146 }
1147 case VIDIOC_S_INPUT:
1148 {
1149 unsigned int *i = arg;
1150
Hans Verkuil93d5a302011-08-09 09:32:06 -03001151 if (ret_prio) {
1152 ret = ret_prio;
1153 break;
1154 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001155 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001156 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001157 break;
1158 }
1159
1160 /* ------ output switching ---------- */
1161 case VIDIOC_ENUMOUTPUT:
1162 {
1163 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001164
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001165 /*
1166 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1167 * CAP_STD here based on ioctl handler provided by the
1168 * driver. If the driver doesn't support these
1169 * for a specific output, it must override these flags.
1170 */
1171 if (ops->vidioc_s_std)
1172 p->capabilities |= V4L2_OUT_CAP_STD;
1173 if (ops->vidioc_s_dv_preset)
1174 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1175 if (ops->vidioc_s_dv_timings)
1176 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1177
Hans Verkuila3998102008-07-21 02:57:38 -03001178 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001179 if (!ret)
1180 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1181 "audioset=0x%x, "
1182 "modulator=%d, std=0x%08Lx\n",
1183 p->index, p->name, p->type, p->audioset,
1184 p->modulator, (unsigned long long)p->std);
1185 break;
1186 }
1187 case VIDIOC_G_OUTPUT:
1188 {
1189 unsigned int *i = arg;
1190
Hans Verkuila3998102008-07-21 02:57:38 -03001191 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001192 if (!ret)
1193 dbgarg(cmd, "value=%d\n", *i);
1194 break;
1195 }
1196 case VIDIOC_S_OUTPUT:
1197 {
1198 unsigned int *i = arg;
1199
Hans Verkuil93d5a302011-08-09 09:32:06 -03001200 if (ret_prio) {
1201 ret = ret_prio;
1202 break;
1203 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001204 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001205 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001206 break;
1207 }
1208
1209 /* --- controls ---------------------------------------------- */
1210 case VIDIOC_QUERYCTRL:
1211 {
1212 struct v4l2_queryctrl *p = arg;
1213
Hans Verkuil2d28b682011-03-12 08:54:43 -03001214 if (vfh && vfh->ctrl_handler)
1215 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1216 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001217 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1218 else if (ops->vidioc_queryctrl)
1219 ret = ops->vidioc_queryctrl(file, fh, p);
1220 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001221 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001222 if (!ret)
1223 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1224 "step=%d, default=%d, flags=0x%08x\n",
1225 p->id, p->type, p->name,
1226 p->minimum, p->maximum,
1227 p->step, p->default_value, p->flags);
1228 else
1229 dbgarg(cmd, "id=0x%x\n", p->id);
1230 break;
1231 }
1232 case VIDIOC_G_CTRL:
1233 {
1234 struct v4l2_control *p = arg;
1235
Hans Verkuil2d28b682011-03-12 08:54:43 -03001236 if (vfh && vfh->ctrl_handler)
1237 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1238 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001239 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1240 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001241 ret = ops->vidioc_g_ctrl(file, fh, p);
1242 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001243 struct v4l2_ext_controls ctrls;
1244 struct v4l2_ext_control ctrl;
1245
1246 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1247 ctrls.count = 1;
1248 ctrls.controls = &ctrl;
1249 ctrl.id = p->id;
1250 ctrl.value = p->value;
1251 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001252 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001253 if (ret == 0)
1254 p->value = ctrl.value;
1255 }
1256 } else
1257 break;
1258 if (!ret)
1259 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1260 else
1261 dbgarg(cmd, "id=0x%x\n", p->id);
1262 break;
1263 }
1264 case VIDIOC_S_CTRL:
1265 {
1266 struct v4l2_control *p = arg;
1267 struct v4l2_ext_controls ctrls;
1268 struct v4l2_ext_control ctrl;
1269
Hans Verkuil2d28b682011-03-12 08:54:43 -03001270 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001271 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001272 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001273 if (ret_prio) {
1274 ret = ret_prio;
1275 break;
1276 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001277
1278 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1279
Hans Verkuil2d28b682011-03-12 08:54:43 -03001280 if (vfh && vfh->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001281 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001282 break;
1283 }
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001284 if (vfd->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001285 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001286 break;
1287 }
Hans Verkuila3998102008-07-21 02:57:38 -03001288 if (ops->vidioc_s_ctrl) {
1289 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001290 break;
1291 }
Hans Verkuila3998102008-07-21 02:57:38 -03001292 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001293 break;
1294
1295 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1296 ctrls.count = 1;
1297 ctrls.controls = &ctrl;
1298 ctrl.id = p->id;
1299 ctrl.value = p->value;
1300 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001301 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001302 else
1303 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001304 break;
1305 }
1306 case VIDIOC_G_EXT_CTRLS:
1307 {
1308 struct v4l2_ext_controls *p = arg;
1309
1310 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001311 if (vfh && vfh->ctrl_handler)
1312 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1313 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001314 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001315 else if (ops->vidioc_g_ext_ctrls)
1316 ret = check_ext_ctrls(p, 0) ?
1317 ops->vidioc_g_ext_ctrls(file, fh, p) :
1318 -EINVAL;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001319 else
1320 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001321 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1322 break;
1323 }
1324 case VIDIOC_S_EXT_CTRLS:
1325 {
1326 struct v4l2_ext_controls *p = arg;
1327
1328 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001329 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1330 !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001331 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001332 if (ret_prio) {
1333 ret = ret_prio;
1334 break;
1335 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001336 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001337 if (vfh && vfh->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001338 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001339 else if (vfd->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001340 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001341 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001342 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001343 else
1344 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001345 break;
1346 }
1347 case VIDIOC_TRY_EXT_CTRLS:
1348 {
1349 struct v4l2_ext_controls *p = arg;
1350
1351 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001352 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1353 !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001354 break;
1355 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001356 if (vfh && vfh->ctrl_handler)
1357 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1358 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001359 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1360 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001361 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001362 else
1363 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001364 break;
1365 }
1366 case VIDIOC_QUERYMENU:
1367 {
1368 struct v4l2_querymenu *p = arg;
1369
Hans Verkuil2d28b682011-03-12 08:54:43 -03001370 if (vfh && vfh->ctrl_handler)
1371 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1372 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001373 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1374 else if (ops->vidioc_querymenu)
1375 ret = ops->vidioc_querymenu(file, fh, p);
1376 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001377 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001378 if (!ret)
1379 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1380 p->id, p->index, p->name);
1381 else
1382 dbgarg(cmd, "id=0x%x, index=%d\n",
1383 p->id, p->index);
1384 break;
1385 }
1386 /* --- audio ---------------------------------------------- */
1387 case VIDIOC_ENUMAUDIO:
1388 {
1389 struct v4l2_audio *p = arg;
1390
Hans Verkuila3998102008-07-21 02:57:38 -03001391 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001392 if (!ret)
1393 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1394 "mode=0x%x\n", p->index, p->name,
1395 p->capability, p->mode);
1396 else
1397 dbgarg(cmd, "index=%d\n", p->index);
1398 break;
1399 }
1400 case VIDIOC_G_AUDIO:
1401 {
1402 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001403
Hans Verkuila3998102008-07-21 02:57:38 -03001404 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001405 if (!ret)
1406 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1407 "mode=0x%x\n", p->index,
1408 p->name, p->capability, p->mode);
1409 else
1410 dbgarg(cmd, "index=%d\n", p->index);
1411 break;
1412 }
1413 case VIDIOC_S_AUDIO:
1414 {
1415 struct v4l2_audio *p = arg;
1416
Hans Verkuil93d5a302011-08-09 09:32:06 -03001417 if (ret_prio) {
1418 ret = ret_prio;
1419 break;
1420 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001421 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1422 "mode=0x%x\n", p->index, p->name,
1423 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001424 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001425 break;
1426 }
1427 case VIDIOC_ENUMAUDOUT:
1428 {
1429 struct v4l2_audioout *p = arg;
1430
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001431 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001432 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001433 if (!ret)
1434 dbgarg2("index=%d, name=%s, capability=%d, "
1435 "mode=%d\n", p->index, p->name,
1436 p->capability, p->mode);
1437 break;
1438 }
1439 case VIDIOC_G_AUDOUT:
1440 {
1441 struct v4l2_audioout *p = arg;
1442
Hans Verkuila3998102008-07-21 02:57:38 -03001443 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001444 if (!ret)
1445 dbgarg2("index=%d, name=%s, capability=%d, "
1446 "mode=%d\n", p->index, p->name,
1447 p->capability, p->mode);
1448 break;
1449 }
1450 case VIDIOC_S_AUDOUT:
1451 {
1452 struct v4l2_audioout *p = arg;
1453
Hans Verkuil93d5a302011-08-09 09:32:06 -03001454 if (ret_prio) {
1455 ret = ret_prio;
1456 break;
1457 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001458 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1459 "mode=%d\n", p->index, p->name,
1460 p->capability, p->mode);
1461
Hans Verkuila3998102008-07-21 02:57:38 -03001462 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001463 break;
1464 }
1465 case VIDIOC_G_MODULATOR:
1466 {
1467 struct v4l2_modulator *p = arg;
1468
Hans Verkuila3998102008-07-21 02:57:38 -03001469 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001470 if (!ret)
1471 dbgarg(cmd, "index=%d, name=%s, "
1472 "capability=%d, rangelow=%d,"
1473 " rangehigh=%d, txsubchans=%d\n",
1474 p->index, p->name, p->capability,
1475 p->rangelow, p->rangehigh,
1476 p->txsubchans);
1477 break;
1478 }
1479 case VIDIOC_S_MODULATOR:
1480 {
1481 struct v4l2_modulator *p = arg;
1482
Hans Verkuil93d5a302011-08-09 09:32:06 -03001483 if (ret_prio) {
1484 ret = ret_prio;
1485 break;
1486 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001487 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1488 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1489 p->index, p->name, p->capability, p->rangelow,
1490 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001491 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001492 break;
1493 }
1494 case VIDIOC_G_CROP:
1495 {
1496 struct v4l2_crop *p = arg;
1497
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001498 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001499
1500 if (ops->vidioc_g_crop) {
1501 ret = ops->vidioc_g_crop(file, fh, p);
1502 } else {
1503 /* simulate capture crop using selection api */
1504 struct v4l2_selection s = {
1505 .type = p->type,
1506 };
1507
1508 /* crop means compose for output devices */
1509 if (V4L2_TYPE_IS_OUTPUT(p->type))
1510 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1511 else
1512 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1513
1514 ret = ops->vidioc_g_selection(file, fh, &s);
1515
1516 /* copying results to old structure on success */
1517 if (!ret)
1518 p->c = s.r;
1519 }
1520
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001521 if (!ret)
1522 dbgrect(vfd, "", &p->c);
1523 break;
1524 }
1525 case VIDIOC_S_CROP:
1526 {
1527 struct v4l2_crop *p = arg;
1528
Hans Verkuil93d5a302011-08-09 09:32:06 -03001529 if (ret_prio) {
1530 ret = ret_prio;
1531 break;
1532 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001533 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1534 dbgrect(vfd, "", &p->c);
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001535
1536 if (ops->vidioc_s_crop) {
1537 ret = ops->vidioc_s_crop(file, fh, p);
1538 } else {
1539 /* simulate capture crop using selection api */
1540 struct v4l2_selection s = {
1541 .type = p->type,
1542 .r = p->c,
1543 };
1544
1545 /* crop means compose for output devices */
1546 if (V4L2_TYPE_IS_OUTPUT(p->type))
1547 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1548 else
1549 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1550
1551 ret = ops->vidioc_s_selection(file, fh, &s);
1552 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001553 break;
1554 }
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001555 case VIDIOC_G_SELECTION:
1556 {
1557 struct v4l2_selection *p = arg;
1558
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001559 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1560
1561 ret = ops->vidioc_g_selection(file, fh, p);
1562 if (!ret)
1563 dbgrect(vfd, "", &p->r);
1564 break;
1565 }
1566 case VIDIOC_S_SELECTION:
1567 {
1568 struct v4l2_selection *p = arg;
1569
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001570 if (ret_prio) {
1571 ret = ret_prio;
1572 break;
1573 }
1574
1575 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1576 dbgrect(vfd, "", &p->r);
1577
1578 ret = ops->vidioc_s_selection(file, fh, p);
1579 break;
1580 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001581 case VIDIOC_CROPCAP:
1582 {
1583 struct v4l2_cropcap *p = arg;
1584
1585 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001586 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Tomasz Stanislawski992efeff2011-03-22 14:04:47 -03001587 if (ops->vidioc_cropcap) {
1588 ret = ops->vidioc_cropcap(file, fh, p);
1589 } else {
1590 struct v4l2_selection s = { .type = p->type };
1591
1592 /* obtaining bounds */
1593 if (V4L2_TYPE_IS_OUTPUT(p->type))
1594 s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
1595 else
1596 s.target = V4L2_SEL_TGT_CROP_BOUNDS;
1597
1598 ret = ops->vidioc_g_selection(file, fh, &s);
1599 if (ret)
1600 break;
1601 p->bounds = s.r;
1602
1603 /* obtaining defrect */
1604 if (V4L2_TYPE_IS_OUTPUT(p->type))
1605 s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
1606 else
1607 s.target = V4L2_SEL_TGT_CROP_DEFAULT;
1608
1609 ret = ops->vidioc_g_selection(file, fh, &s);
1610 if (ret)
1611 break;
1612 p->defrect = s.r;
1613
1614 /* setting trivial pixelaspect */
1615 p->pixelaspect.numerator = 1;
1616 p->pixelaspect.denominator = 1;
1617 }
1618
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001619 if (!ret) {
1620 dbgrect(vfd, "bounds ", &p->bounds);
1621 dbgrect(vfd, "defrect ", &p->defrect);
1622 }
1623 break;
1624 }
1625 case VIDIOC_G_JPEGCOMP:
1626 {
1627 struct v4l2_jpegcompression *p = arg;
1628
Hans Verkuila3998102008-07-21 02:57:38 -03001629 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001630 if (!ret)
1631 dbgarg(cmd, "quality=%d, APPn=%d, "
1632 "APP_len=%d, COM_len=%d, "
1633 "jpeg_markers=%d\n",
1634 p->quality, p->APPn, p->APP_len,
1635 p->COM_len, p->jpeg_markers);
1636 break;
1637 }
1638 case VIDIOC_S_JPEGCOMP:
1639 {
1640 struct v4l2_jpegcompression *p = arg;
1641
Hans Verkuil93d5a302011-08-09 09:32:06 -03001642 if (ret_prio) {
1643 ret = ret_prio;
1644 break;
1645 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001646 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1647 "COM_len=%d, jpeg_markers=%d\n",
1648 p->quality, p->APPn, p->APP_len,
1649 p->COM_len, p->jpeg_markers);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001650 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001651 break;
1652 }
1653 case VIDIOC_G_ENC_INDEX:
1654 {
1655 struct v4l2_enc_idx *p = arg;
1656
Hans Verkuila3998102008-07-21 02:57:38 -03001657 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001658 if (!ret)
1659 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1660 p->entries, p->entries_cap);
1661 break;
1662 }
1663 case VIDIOC_ENCODER_CMD:
1664 {
1665 struct v4l2_encoder_cmd *p = arg;
1666
Hans Verkuil93d5a302011-08-09 09:32:06 -03001667 if (ret_prio) {
1668 ret = ret_prio;
1669 break;
1670 }
Hans Verkuila3998102008-07-21 02:57:38 -03001671 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001672 if (!ret)
1673 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1674 break;
1675 }
1676 case VIDIOC_TRY_ENCODER_CMD:
1677 {
1678 struct v4l2_encoder_cmd *p = arg;
1679
Hans Verkuila3998102008-07-21 02:57:38 -03001680 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001681 if (!ret)
1682 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1683 break;
1684 }
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001685 case VIDIOC_DECODER_CMD:
1686 {
1687 struct v4l2_decoder_cmd *p = arg;
1688
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001689 if (ret_prio) {
1690 ret = ret_prio;
1691 break;
1692 }
1693 ret = ops->vidioc_decoder_cmd(file, fh, p);
1694 if (!ret)
1695 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1696 break;
1697 }
1698 case VIDIOC_TRY_DECODER_CMD:
1699 {
1700 struct v4l2_decoder_cmd *p = arg;
1701
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001702 ret = ops->vidioc_try_decoder_cmd(file, fh, p);
1703 if (!ret)
1704 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1705 break;
1706 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001707 case VIDIOC_G_PARM:
1708 {
1709 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001710
Hans Verkuila3998102008-07-21 02:57:38 -03001711 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001712 ret = check_fmt(ops, p->type);
1713 if (ret)
1714 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001715 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001716 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001717 v4l2_std_id std = vfd->current_norm;
1718
Hans Verkuil93d5a302011-08-09 09:32:06 -03001719 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001720 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001721 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001722
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001723 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001724 if (ops->vidioc_g_std)
1725 ret = ops->vidioc_g_std(file, fh, &std);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001726 if (ret == 0)
1727 v4l2_video_std_frame_period(std,
1728 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001729 }
1730
1731 dbgarg(cmd, "type=%d\n", p->type);
1732 break;
1733 }
1734 case VIDIOC_S_PARM:
1735 {
1736 struct v4l2_streamparm *p = arg;
1737
Hans Verkuil93d5a302011-08-09 09:32:06 -03001738 if (ret_prio) {
1739 ret = ret_prio;
1740 break;
1741 }
Trent Piepho34796bc2009-03-28 22:25:35 -03001742 ret = check_fmt(ops, p->type);
1743 if (ret)
1744 break;
1745
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001746 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001747 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001748 break;
1749 }
1750 case VIDIOC_G_TUNER:
1751 {
1752 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001753
Hans Verkuil227690d2011-06-12 06:36:41 -03001754 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1755 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001756 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001757 if (!ret)
1758 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1759 "capability=0x%x, rangelow=%d, "
1760 "rangehigh=%d, signal=%d, afc=%d, "
1761 "rxsubchans=0x%x, audmode=%d\n",
1762 p->index, p->name, p->type,
1763 p->capability, p->rangelow,
1764 p->rangehigh, p->signal, p->afc,
1765 p->rxsubchans, p->audmode);
1766 break;
1767 }
1768 case VIDIOC_S_TUNER:
1769 {
1770 struct v4l2_tuner *p = arg;
1771
Hans Verkuil93d5a302011-08-09 09:32:06 -03001772 if (ret_prio) {
1773 ret = ret_prio;
1774 break;
1775 }
Hans Verkuil227690d2011-06-12 06:36:41 -03001776 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1777 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001778 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1779 "capability=0x%x, rangelow=%d, "
1780 "rangehigh=%d, signal=%d, afc=%d, "
1781 "rxsubchans=0x%x, audmode=%d\n",
1782 p->index, p->name, p->type,
1783 p->capability, p->rangelow,
1784 p->rangehigh, p->signal, p->afc,
1785 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001786 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001787 break;
1788 }
1789 case VIDIOC_G_FREQUENCY:
1790 {
1791 struct v4l2_frequency *p = arg;
1792
Hans Verkuil227690d2011-06-12 06:36:41 -03001793 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1794 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001795 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001796 if (!ret)
1797 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1798 p->tuner, p->type, p->frequency);
1799 break;
1800 }
1801 case VIDIOC_S_FREQUENCY:
1802 {
1803 struct v4l2_frequency *p = arg;
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001804 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001805
Hans Verkuil93d5a302011-08-09 09:32:06 -03001806 if (ret_prio) {
1807 ret = ret_prio;
1808 break;
1809 }
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001810 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1811 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001812 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1813 p->tuner, p->type, p->frequency);
Hans Verkuilaa07eec2011-10-11 05:12:52 -03001814 if (p->type != type)
1815 ret = -EINVAL;
1816 else
1817 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001818 break;
1819 }
1820 case VIDIOC_G_SLICED_VBI_CAP:
1821 {
1822 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001823
Trent Piepho19c96e42009-03-04 01:21:02 -03001824 /* Clear up to type, everything after type is zerod already */
1825 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1826
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001827 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001828 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001829 if (!ret)
1830 dbgarg2("service_set=%d\n", p->service_set);
1831 break;
1832 }
1833 case VIDIOC_LOG_STATUS:
1834 {
Hans Verkuile2ecb252012-02-02 08:20:53 -03001835 if (vfd->v4l2_dev)
1836 pr_info("%s: ================= START STATUS =================\n",
1837 vfd->v4l2_dev->name);
Hans Verkuila3998102008-07-21 02:57:38 -03001838 ret = ops->vidioc_log_status(file, fh);
Hans Verkuile2ecb252012-02-02 08:20:53 -03001839 if (vfd->v4l2_dev)
1840 pr_info("%s: ================== END STATUS ==================\n",
1841 vfd->v4l2_dev->name);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001842 break;
1843 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001844 case VIDIOC_DBG_G_REGISTER:
1845 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001846#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001847 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001848
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001849 if (!capable(CAP_SYS_ADMIN))
1850 ret = -EPERM;
1851 else
1852 ret = ops->vidioc_g_register(file, fh, p);
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001853#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001854 break;
1855 }
1856 case VIDIOC_DBG_S_REGISTER:
1857 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001858#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001859 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001860
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001861 if (!capable(CAP_SYS_ADMIN))
1862 ret = -EPERM;
1863 else
1864 ret = ops->vidioc_s_register(file, fh, p);
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001865#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001866 break;
1867 }
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001868 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001869 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001870 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001871
Hans Verkuil80b36e02009-02-07 11:00:02 -03001872 p->ident = V4L2_IDENT_NONE;
1873 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001874 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001875 if (!ret)
1876 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1877 break;
1878 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001879 case VIDIOC_S_HW_FREQ_SEEK:
1880 {
1881 struct v4l2_hw_freq_seek *p = arg;
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001882 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001883
Hans Verkuil93d5a302011-08-09 09:32:06 -03001884 if (ret_prio) {
1885 ret = ret_prio;
1886 break;
1887 }
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001888 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1889 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001890 dbgarg(cmd,
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001891 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1892 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1893 if (p->type != type)
1894 ret = -EINVAL;
1895 else
1896 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
Hans Verkuila3998102008-07-21 02:57:38 -03001897 break;
1898 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001899 case VIDIOC_ENUM_FRAMESIZES:
1900 {
1901 struct v4l2_frmsizeenum *p = arg;
1902
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001903 ret = ops->vidioc_enum_framesizes(file, fh, p);
1904 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001905 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1906 p->index,
1907 (p->pixel_format & 0xff),
1908 (p->pixel_format >> 8) & 0xff,
1909 (p->pixel_format >> 16) & 0xff,
1910 (p->pixel_format >> 24) & 0xff,
1911 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001912 switch (p->type) {
1913 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001914 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001915 p->discrete.width, p->discrete.height);
1916 break;
1917 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001918 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001919 p->stepwise.min_width, p->stepwise.min_height,
1920 p->stepwise.step_width, p->stepwise.step_height,
1921 p->stepwise.max_width, p->stepwise.max_height);
1922 break;
1923 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001924 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001925 break;
1926 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001927 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001928 }
1929
1930 break;
1931 }
1932 case VIDIOC_ENUM_FRAMEINTERVALS:
1933 {
1934 struct v4l2_frmivalenum *p = arg;
1935
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001936 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1937 dbgarg(cmd,
1938 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1939 p->index, p->pixel_format,
1940 p->width, p->height, p->type);
1941 switch (p->type) {
1942 case V4L2_FRMIVAL_TYPE_DISCRETE:
1943 dbgarg2("fps=%d/%d\n",
1944 p->discrete.numerator,
1945 p->discrete.denominator);
1946 break;
1947 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03001948 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1949 p->stepwise.min.numerator,
1950 p->stepwise.min.denominator,
1951 p->stepwise.max.numerator,
1952 p->stepwise.max.denominator,
1953 p->stepwise.step.numerator,
1954 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001955 break;
1956 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1957 dbgarg2("continuous\n");
1958 break;
1959 default:
1960 dbgarg2("- Unknown type!\n");
1961 }
1962 break;
1963 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001964 case VIDIOC_ENUM_DV_PRESETS:
1965 {
1966 struct v4l2_dv_enum_preset *p = arg;
1967
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001968 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1969 if (!ret)
1970 dbgarg(cmd,
1971 "index=%d, preset=%d, name=%s, width=%d,"
1972 " height=%d ",
1973 p->index, p->preset, p->name, p->width,
1974 p->height);
1975 break;
1976 }
1977 case VIDIOC_S_DV_PRESET:
1978 {
1979 struct v4l2_dv_preset *p = arg;
1980
Hans Verkuil93d5a302011-08-09 09:32:06 -03001981 if (ret_prio) {
1982 ret = ret_prio;
1983 break;
1984 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001985
1986 dbgarg(cmd, "preset=%d\n", p->preset);
1987 ret = ops->vidioc_s_dv_preset(file, fh, p);
1988 break;
1989 }
1990 case VIDIOC_G_DV_PRESET:
1991 {
1992 struct v4l2_dv_preset *p = arg;
1993
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001994 ret = ops->vidioc_g_dv_preset(file, fh, p);
1995 if (!ret)
1996 dbgarg(cmd, "preset=%d\n", p->preset);
1997 break;
1998 }
1999 case VIDIOC_QUERY_DV_PRESET:
2000 {
2001 struct v4l2_dv_preset *p = arg;
2002
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002003 ret = ops->vidioc_query_dv_preset(file, fh, p);
2004 if (!ret)
2005 dbgarg(cmd, "preset=%d\n", p->preset);
2006 break;
2007 }
2008 case VIDIOC_S_DV_TIMINGS:
2009 {
2010 struct v4l2_dv_timings *p = arg;
2011
Hans Verkuil93d5a302011-08-09 09:32:06 -03002012 if (ret_prio) {
2013 ret = ret_prio;
2014 break;
2015 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002016
2017 switch (p->type) {
2018 case V4L2_DV_BT_656_1120:
2019 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2020 " width=%d, height=%d, polarities=%x,"
2021 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
2022 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
2023 " il_vfrontporch=%d, il_vsync=%d,"
2024 " il_vbackporch=%d\n",
2025 p->bt.interlaced, p->bt.pixelclock,
2026 p->bt.width, p->bt.height, p->bt.polarities,
2027 p->bt.hfrontporch, p->bt.hsync,
2028 p->bt.hbackporch, p->bt.vfrontporch,
2029 p->bt.vsync, p->bt.vbackporch,
2030 p->bt.il_vfrontporch, p->bt.il_vsync,
2031 p->bt.il_vbackporch);
2032 ret = ops->vidioc_s_dv_timings(file, fh, p);
2033 break;
2034 default:
2035 dbgarg2("Unknown type %d!\n", p->type);
2036 break;
2037 }
2038 break;
2039 }
2040 case VIDIOC_G_DV_TIMINGS:
2041 {
2042 struct v4l2_dv_timings *p = arg;
2043
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002044 ret = ops->vidioc_g_dv_timings(file, fh, p);
2045 if (!ret) {
2046 switch (p->type) {
2047 case V4L2_DV_BT_656_1120:
2048 dbgarg2("bt-656/1120:interlaced=%d,"
2049 " pixelclock=%lld,"
2050 " width=%d, height=%d, polarities=%x,"
2051 " hfrontporch=%d, hsync=%d,"
2052 " hbackporch=%d, vfrontporch=%d,"
2053 " vsync=%d, vbackporch=%d,"
2054 " il_vfrontporch=%d, il_vsync=%d,"
2055 " il_vbackporch=%d\n",
2056 p->bt.interlaced, p->bt.pixelclock,
2057 p->bt.width, p->bt.height,
2058 p->bt.polarities, p->bt.hfrontporch,
2059 p->bt.hsync, p->bt.hbackporch,
2060 p->bt.vfrontporch, p->bt.vsync,
2061 p->bt.vbackporch, p->bt.il_vfrontporch,
2062 p->bt.il_vsync, p->bt.il_vbackporch);
2063 break;
2064 default:
2065 dbgarg2("Unknown type %d!\n", p->type);
2066 break;
2067 }
2068 }
2069 break;
2070 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002071 case VIDIOC_DQEVENT:
2072 {
2073 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002074
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002075 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2076 if (ret < 0) {
2077 dbgarg(cmd, "no pending events?");
2078 break;
2079 }
2080 dbgarg(cmd,
2081 "pending=%d, type=0x%8.8x, sequence=%d, "
2082 "timestamp=%lu.%9.9lu ",
2083 ev->pending, ev->type, ev->sequence,
2084 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2085 break;
2086 }
2087 case VIDIOC_SUBSCRIBE_EVENT:
2088 {
2089 struct v4l2_event_subscription *sub = arg;
2090
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002091 ret = ops->vidioc_subscribe_event(fh, sub);
2092 if (ret < 0) {
2093 dbgarg(cmd, "failed, ret=%ld", ret);
2094 break;
2095 }
2096 dbgarg(cmd, "type=0x%8.8x", sub->type);
2097 break;
2098 }
2099 case VIDIOC_UNSUBSCRIBE_EVENT:
2100 {
2101 struct v4l2_event_subscription *sub = arg;
2102
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002103 ret = ops->vidioc_unsubscribe_event(fh, sub);
2104 if (ret < 0) {
2105 dbgarg(cmd, "failed, ret=%ld", ret);
2106 break;
2107 }
2108 dbgarg(cmd, "type=0x%8.8x", sub->type);
2109 break;
2110 }
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002111 case VIDIOC_CREATE_BUFS:
2112 {
2113 struct v4l2_create_buffers *create = arg;
2114
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002115 if (ret_prio) {
2116 ret = ret_prio;
2117 break;
2118 }
2119 ret = check_fmt(ops, create->format.type);
2120 if (ret)
2121 break;
2122
2123 ret = ops->vidioc_create_bufs(file, fh, create);
2124
2125 dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2126 break;
2127 }
2128 case VIDIOC_PREPARE_BUF:
2129 {
2130 struct v4l2_buffer *b = arg;
2131
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002132 ret = check_fmt(ops, b->type);
2133 if (ret)
2134 break;
2135
2136 ret = ops->vidioc_prepare_buf(file, fh, b);
2137
2138 dbgarg(cmd, "index=%d", b->index);
2139 break;
2140 }
Hans Verkuila3998102008-07-21 02:57:38 -03002141 default:
Hans Verkuila3998102008-07-21 02:57:38 -03002142 if (!ops->vidioc_default)
2143 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002144 ret = ops->vidioc_default(file, fh, ret_prio >= 0, cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002145 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002146 } /* switch */
2147
2148 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2149 if (ret < 0) {
2150 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002151 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002152 }
2153 }
2154
2155 return ret;
2156}
2157
Trent Piepho19c96e42009-03-04 01:21:02 -03002158/* In some cases, only a few fields are used as input, i.e. when the app sets
2159 * "index" and then the driver fills in the rest of the structure for the thing
2160 * with that index. We only need to copy up the first non-input field. */
2161static unsigned long cmd_input_size(unsigned int cmd)
2162{
2163 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002164#define CMDINSIZE(cmd, type, field) \
2165 case VIDIOC_##cmd: \
2166 return offsetof(struct v4l2_##type, field) + \
2167 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03002168
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002169 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03002170 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2171 CMDINSIZE(G_FMT, format, type);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002172 CMDINSIZE(QUERYBUF, buffer, length);
Trent Piepho19c96e42009-03-04 01:21:02 -03002173 CMDINSIZE(G_PARM, streamparm, type);
2174 CMDINSIZE(ENUMSTD, standard, index);
2175 CMDINSIZE(ENUMINPUT, input, index);
2176 CMDINSIZE(G_CTRL, control, id);
2177 CMDINSIZE(G_TUNER, tuner, index);
2178 CMDINSIZE(QUERYCTRL, queryctrl, id);
2179 CMDINSIZE(QUERYMENU, querymenu, index);
2180 CMDINSIZE(ENUMOUTPUT, output, index);
2181 CMDINSIZE(G_MODULATOR, modulator, index);
2182 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2183 CMDINSIZE(CROPCAP, cropcap, type);
2184 CMDINSIZE(G_CROP, crop, type);
2185 CMDINSIZE(ENUMAUDIO, audio, index);
2186 CMDINSIZE(ENUMAUDOUT, audioout, index);
2187 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2188 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2189 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2190 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2191 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2192 default:
2193 return _IOC_SIZE(cmd);
2194 }
2195}
2196
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002197static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2198 void * __user *user_ptr, void ***kernel_ptr)
2199{
2200 int ret = 0;
2201
2202 switch (cmd) {
2203 case VIDIOC_QUERYBUF:
2204 case VIDIOC_QBUF:
2205 case VIDIOC_DQBUF: {
2206 struct v4l2_buffer *buf = parg;
2207
2208 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2209 if (buf->length > VIDEO_MAX_PLANES) {
2210 ret = -EINVAL;
2211 break;
2212 }
2213 *user_ptr = (void __user *)buf->m.planes;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002214 *kernel_ptr = (void *)&buf->m.planes;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002215 *array_size = sizeof(struct v4l2_plane) * buf->length;
2216 ret = 1;
2217 }
2218 break;
2219 }
2220
2221 case VIDIOC_S_EXT_CTRLS:
2222 case VIDIOC_G_EXT_CTRLS:
2223 case VIDIOC_TRY_EXT_CTRLS: {
2224 struct v4l2_ext_controls *ctrls = parg;
2225
2226 if (ctrls->count != 0) {
Dan Carpenter6c061082012-01-05 02:27:57 -03002227 if (ctrls->count > V4L2_CID_MAX_CTRLS) {
2228 ret = -EINVAL;
2229 break;
2230 }
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002231 *user_ptr = (void __user *)ctrls->controls;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002232 *kernel_ptr = (void *)&ctrls->controls;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002233 *array_size = sizeof(struct v4l2_ext_control)
2234 * ctrls->count;
2235 ret = 1;
2236 }
2237 break;
2238 }
2239 }
2240
2241 return ret;
2242}
2243
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002244long
2245video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2246 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002247{
2248 char sbuf[128];
2249 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002250 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002251 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002252 bool has_array_args;
2253 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002254 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002255 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002256
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002257 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002258 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002259 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2260 parg = sbuf;
2261 } else {
2262 /* too big to allocate from stack */
2263 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2264 if (NULL == mbuf)
2265 return -ENOMEM;
2266 parg = mbuf;
2267 }
2268
2269 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002270 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2271 unsigned long n = cmd_input_size(cmd);
2272
2273 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002274 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002275
2276 /* zero out anything we don't copy from userspace */
2277 if (n < _IOC_SIZE(cmd))
2278 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002279 } else {
2280 /* read-only ioctl */
2281 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002282 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002283 }
2284
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002285 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2286 if (err < 0)
2287 goto out;
2288 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002289
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002290 if (has_array_args) {
2291 /*
2292 * When adding new types of array args, make sure that the
2293 * parent argument to ioctl (which contains the pointer to the
2294 * array) fits into sbuf (so that mbuf will still remain
2295 * unused up to here).
2296 */
2297 mbuf = kmalloc(array_size, GFP_KERNEL);
2298 err = -ENOMEM;
2299 if (NULL == mbuf)
2300 goto out_array_args;
2301 err = -EFAULT;
2302 if (copy_from_user(mbuf, user_ptr, array_size))
2303 goto out_array_args;
2304 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002305 }
2306
2307 /* Handles IOCTL */
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002308 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002309 if (err == -ENOIOCTLCMD)
Hans Verkuil02bbb812012-02-08 08:09:36 -03002310 err = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002311
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002312 if (has_array_args) {
2313 *kernel_ptr = user_ptr;
2314 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002315 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002316 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002317 }
2318 if (err < 0)
2319 goto out;
2320
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002321out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002322 /* Copy results into user buffer */
2323 switch (_IOC_DIR(cmd)) {
2324 case _IOC_READ:
2325 case (_IOC_WRITE | _IOC_READ):
2326 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2327 err = -EFAULT;
2328 break;
2329 }
2330
2331out:
2332 kfree(mbuf);
2333 return err;
2334}
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002335EXPORT_SYMBOL(video_usercopy);
2336
2337long video_ioctl2(struct file *file,
2338 unsigned int cmd, unsigned long arg)
2339{
2340 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2341}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002342EXPORT_SYMBOL(video_ioctl2);