blob: 072cfc1a166f6c9fe33cc857d9c54e7d4365c55a [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 Verkuil99cd47b2011-03-11 19:00:56 -030028#include <media/v4l2-device.h>
Hans Verkuil80b36e02009-02-07 11:00:02 -030029#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030030
31#define dbgarg(cmd, fmt, arg...) \
32 do { \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
37 } \
38 } while (0)
39
40#define dbgarg2(fmt, arg...) \
41 do { \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
44 } while (0)
45
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030046#define dbgarg3(fmt, arg...) \
47 do { \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
50 } while (0)
51
Lucas De Marchi25985ed2011-03-30 22:57:33 -030052/* Zero out the end of the struct pointed to by p. Everything after, but
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030053 * not including, the specified field is cleared. */
54#define CLEAR_AFTER_FIELD(p, field) \
55 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
57
Hans Verkuil93d5a302011-08-09 09:32:06 -030058#define have_fmt_ops(foo) ( \
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -030059 ops->vidioc_##foo##_fmt_vid_cap || \
60 ops->vidioc_##foo##_fmt_vid_out || \
61 ops->vidioc_##foo##_fmt_vid_cap_mplane || \
62 ops->vidioc_##foo##_fmt_vid_out_mplane || \
63 ops->vidioc_##foo##_fmt_vid_overlay || \
Hans Verkuil93d5a302011-08-09 09:32:06 -030064 ops->vidioc_##foo##_fmt_vbi_cap || \
65 ops->vidioc_##foo##_fmt_vid_out_overlay || \
66 ops->vidioc_##foo##_fmt_vbi_out || \
67 ops->vidioc_##foo##_fmt_sliced_vbi_cap || \
68 ops->vidioc_##foo##_fmt_sliced_vbi_out || \
69 ops->vidioc_##foo##_fmt_type_private)
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -030070
Hans Verkuil35ea11f2008-07-20 08:12:02 -030071struct std_descr {
72 v4l2_std_id std;
73 const char *descr;
74};
75
76static const struct std_descr standards[] = {
77 { V4L2_STD_NTSC, "NTSC" },
78 { V4L2_STD_NTSC_M, "NTSC-M" },
79 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
80 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
81 { V4L2_STD_NTSC_443, "NTSC-443" },
82 { V4L2_STD_PAL, "PAL" },
83 { V4L2_STD_PAL_BG, "PAL-BG" },
84 { V4L2_STD_PAL_B, "PAL-B" },
85 { V4L2_STD_PAL_B1, "PAL-B1" },
86 { V4L2_STD_PAL_G, "PAL-G" },
87 { V4L2_STD_PAL_H, "PAL-H" },
88 { V4L2_STD_PAL_I, "PAL-I" },
89 { V4L2_STD_PAL_DK, "PAL-DK" },
90 { V4L2_STD_PAL_D, "PAL-D" },
91 { V4L2_STD_PAL_D1, "PAL-D1" },
92 { V4L2_STD_PAL_K, "PAL-K" },
93 { V4L2_STD_PAL_M, "PAL-M" },
94 { V4L2_STD_PAL_N, "PAL-N" },
95 { V4L2_STD_PAL_Nc, "PAL-Nc" },
96 { V4L2_STD_PAL_60, "PAL-60" },
97 { V4L2_STD_SECAM, "SECAM" },
98 { V4L2_STD_SECAM_B, "SECAM-B" },
99 { V4L2_STD_SECAM_G, "SECAM-G" },
100 { V4L2_STD_SECAM_H, "SECAM-H" },
101 { V4L2_STD_SECAM_DK, "SECAM-DK" },
102 { V4L2_STD_SECAM_D, "SECAM-D" },
103 { V4L2_STD_SECAM_K, "SECAM-K" },
104 { V4L2_STD_SECAM_K1, "SECAM-K1" },
105 { V4L2_STD_SECAM_L, "SECAM-L" },
106 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
107 { 0, "Unknown" }
108};
109
110/* video4linux standard ID conversion to standard name
111 */
112const char *v4l2_norm_to_name(v4l2_std_id id)
113{
114 u32 myid = id;
115 int i;
116
117 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
118 64 bit comparations. So, on that architecture, with some gcc
119 variants, compilation fails. Currently, the max value is 30bit wide.
120 */
121 BUG_ON(myid != id);
122
123 for (i = 0; standards[i].std; i++)
124 if (myid == standards[i].std)
125 break;
126 return standards[i].descr;
127}
128EXPORT_SYMBOL(v4l2_norm_to_name);
129
Trent Piepho51f0b8d2009-03-04 01:21:02 -0300130/* Returns frame period for the given standard */
131void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
132{
133 if (id & V4L2_STD_525_60) {
134 frameperiod->numerator = 1001;
135 frameperiod->denominator = 30000;
136 } else {
137 frameperiod->numerator = 1;
138 frameperiod->denominator = 25;
139 }
140}
141EXPORT_SYMBOL(v4l2_video_std_frame_period);
142
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300143/* Fill in the fields of a v4l2_standard structure according to the
144 'id' and 'transmission' parameters. Returns negative on error. */
145int v4l2_video_std_construct(struct v4l2_standard *vs,
146 int id, const char *name)
147{
Trent Piepho51f0b8d2009-03-04 01:21:02 -0300148 vs->id = id;
149 v4l2_video_std_frame_period(id, &vs->frameperiod);
150 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300151 strlcpy(vs->name, name, sizeof(vs->name));
152 return 0;
153}
154EXPORT_SYMBOL(v4l2_video_std_construct);
155
156/* ----------------------------------------------------------------- */
157/* some arrays for pretty-printing debug messages of enum types */
158
159const char *v4l2_field_names[] = {
160 [V4L2_FIELD_ANY] = "any",
161 [V4L2_FIELD_NONE] = "none",
162 [V4L2_FIELD_TOP] = "top",
163 [V4L2_FIELD_BOTTOM] = "bottom",
164 [V4L2_FIELD_INTERLACED] = "interlaced",
165 [V4L2_FIELD_SEQ_TB] = "seq-tb",
166 [V4L2_FIELD_SEQ_BT] = "seq-bt",
167 [V4L2_FIELD_ALTERNATE] = "alternate",
168 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
169 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
170};
171EXPORT_SYMBOL(v4l2_field_names);
172
173const char *v4l2_type_names[] = {
174 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
175 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
176 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
177 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
178 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
179 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
180 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
181 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
Pawel Osciakf8f39142010-07-29 14:44:25 -0300182 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
183 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300184};
185EXPORT_SYMBOL(v4l2_type_names);
186
187static const char *v4l2_memory_names[] = {
188 [V4L2_MEMORY_MMAP] = "mmap",
189 [V4L2_MEMORY_USERPTR] = "userptr",
190 [V4L2_MEMORY_OVERLAY] = "overlay",
191};
192
193#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
194 arr[a] : "unknown")
195
196/* ------------------------------------------------------------------ */
197/* debug help functions */
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300198static const char *v4l2_ioctls[] = {
199 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
200 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
201 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
202 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
203 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
204 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
205 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
206 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
207 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
208 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
209 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
210 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
211 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
212 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
213 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
214 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
215 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
216 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
217 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
218 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
219 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
220 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
221 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
222 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
223 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
224 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
225 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
226 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
227 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
228 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
229 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
230 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
231 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
232 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
233 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
234 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
235 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
236 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
237 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
238 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
239 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
240 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -0300241 [_IOC_NR(VIDIOC_G_SELECTION)] = "VIDIOC_G_SELECTION",
242 [_IOC_NR(VIDIOC_S_SELECTION)] = "VIDIOC_S_SELECTION",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300243 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
244 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
245 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
246 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
247 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
248 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
249 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
250 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
251 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
252 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
253 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
254 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
255 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
256#if 1
257 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
258 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
259 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
260 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
261 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
262
263 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
264 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
265
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300266 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300267 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
268#endif
Muralidharan Karicherib6456c02009-11-19 12:00:31 -0300269 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS)] = "VIDIOC_ENUM_DV_PRESETS",
270 [_IOC_NR(VIDIOC_S_DV_PRESET)] = "VIDIOC_S_DV_PRESET",
271 [_IOC_NR(VIDIOC_G_DV_PRESET)] = "VIDIOC_G_DV_PRESET",
272 [_IOC_NR(VIDIOC_QUERY_DV_PRESET)] = "VIDIOC_QUERY_DV_PRESET",
273 [_IOC_NR(VIDIOC_S_DV_TIMINGS)] = "VIDIOC_S_DV_TIMINGS",
274 [_IOC_NR(VIDIOC_G_DV_TIMINGS)] = "VIDIOC_G_DV_TIMINGS",
Sakari Ailusfda10212010-02-24 19:19:05 -0300275 [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
276 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
277 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300278 [_IOC_NR(VIDIOC_CREATE_BUFS)] = "VIDIOC_CREATE_BUFS",
279 [_IOC_NR(VIDIOC_PREPARE_BUF)] = "VIDIOC_PREPARE_BUF",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300280};
281#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
282
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300283/* Common ioctl debug function. This function can be used by
284 external ioctl messages as well as internal V4L ioctl */
285void v4l_printk_ioctl(unsigned int cmd)
286{
287 char *dir, *type;
288
289 switch (_IOC_TYPE(cmd)) {
290 case 'd':
Hans Verkuil78a3b4d2009-04-01 03:41:09 -0300291 type = "v4l2_int";
292 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300293 case 'V':
294 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
295 type = "v4l2";
296 break;
297 }
298 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
299 return;
300 default:
301 type = "unknown";
302 }
303
304 switch (_IOC_DIR(cmd)) {
305 case _IOC_NONE: dir = "--"; break;
306 case _IOC_READ: dir = "r-"; break;
307 case _IOC_WRITE: dir = "-w"; break;
308 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
309 default: dir = "*ERR*"; break;
310 }
311 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
312 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
313}
314EXPORT_SYMBOL(v4l_printk_ioctl);
315
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300316static void dbgbuf(unsigned int cmd, struct video_device *vfd,
317 struct v4l2_buffer *p)
318{
319 struct v4l2_timecode *tc = &p->timecode;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300320 struct v4l2_plane *plane;
321 int i;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300322
323 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300324 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300325 p->timestamp.tv_sec / 3600,
326 (int)(p->timestamp.tv_sec / 60) % 60,
327 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300328 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300329 p->index,
330 prt_names(p->type, v4l2_type_names),
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300331 p->flags, p->field, p->sequence,
332 prt_names(p->memory, v4l2_memory_names));
333
334 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
335 for (i = 0; i < p->length; ++i) {
336 plane = &p->m.planes[i];
337 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
338 "offset/userptr=0x%08lx, length=%d\n",
339 i, plane->bytesused, plane->data_offset,
340 plane->m.userptr, plane->length);
341 }
342 } else {
343 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
344 p->bytesused, p->m.userptr, p->length);
345 }
346
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300347 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
348 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
349 tc->hours, tc->minutes, tc->seconds,
350 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
351}
352
353static inline void dbgrect(struct video_device *vfd, char *s,
354 struct v4l2_rect *r)
355{
356 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
357 r->width, r->height);
358};
359
360static inline void v4l_print_pix_fmt(struct video_device *vfd,
361 struct v4l2_pix_format *fmt)
362{
363 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
364 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
365 fmt->width, fmt->height,
366 (fmt->pixelformat & 0xff),
367 (fmt->pixelformat >> 8) & 0xff,
368 (fmt->pixelformat >> 16) & 0xff,
369 (fmt->pixelformat >> 24) & 0xff,
370 prt_names(fmt->field, v4l2_field_names),
371 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
372};
373
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300374static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
375 struct v4l2_pix_format_mplane *fmt)
376{
377 int i;
378
379 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
380 "colorspace=%d, num_planes=%d\n",
381 fmt->width, fmt->height,
382 (fmt->pixelformat & 0xff),
383 (fmt->pixelformat >> 8) & 0xff,
384 (fmt->pixelformat >> 16) & 0xff,
385 (fmt->pixelformat >> 24) & 0xff,
386 prt_names(fmt->field, v4l2_field_names),
387 fmt->colorspace, fmt->num_planes);
388
389 for (i = 0; i < fmt->num_planes; ++i)
390 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
391 fmt->plane_fmt[i].bytesperline,
392 fmt->plane_fmt[i].sizeimage);
393}
394
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300395static inline void v4l_print_ext_ctrls(unsigned int cmd,
396 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
397{
398 __u32 i;
399
400 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
401 return;
402 dbgarg(cmd, "");
403 printk(KERN_CONT "class=0x%x", c->ctrl_class);
404 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300405 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300406 printk(KERN_CONT " id/val=0x%x/0x%x",
407 c->controls[i].id, c->controls[i].value);
408 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300409 printk(KERN_CONT " id=0x%x,size=%u",
410 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300411 }
412 printk(KERN_CONT "\n");
413};
414
415static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
416{
417 __u32 i;
418
419 /* zero the reserved fields */
420 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300421 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300422 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300423
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300424 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
425 when using extended controls.
426 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
427 is it allowed for backwards compatibility.
428 */
429 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
430 return 0;
431 /* Check that all controls are from the same control class. */
432 for (i = 0; i < c->count; i++) {
433 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
434 c->error_idx = i;
435 return 0;
436 }
437 }
438 return 1;
439}
440
Hans Verkuila3998102008-07-21 02:57:38 -0300441static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300442{
Hans Verkuila3998102008-07-21 02:57:38 -0300443 if (ops == NULL)
444 return -EINVAL;
445
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300446 switch (type) {
447 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300448 if (ops->vidioc_g_fmt_vid_cap ||
449 ops->vidioc_g_fmt_vid_cap_mplane)
450 return 0;
451 break;
452 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
453 if (ops->vidioc_g_fmt_vid_cap_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300454 return 0;
455 break;
456 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300457 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300458 return 0;
459 break;
460 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300461 if (ops->vidioc_g_fmt_vid_out ||
462 ops->vidioc_g_fmt_vid_out_mplane)
463 return 0;
464 break;
465 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
466 if (ops->vidioc_g_fmt_vid_out_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300467 return 0;
468 break;
469 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300470 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300471 return 0;
472 break;
473 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300474 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300475 return 0;
476 break;
477 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300478 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300479 return 0;
480 break;
481 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300482 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300483 return 0;
484 break;
485 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300486 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300487 return 0;
488 break;
489 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300490 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300491 return 0;
492 break;
493 }
494 return -EINVAL;
495}
496
Hans Verkuil069b7472008-12-30 07:04:34 -0300497static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300498 unsigned int cmd, void *arg)
499{
500 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300501 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300502 void *fh = file->private_data;
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300503 struct v4l2_fh *vfh = NULL;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300504 int use_fh_prio = 0;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300505 long ret_prio = 0;
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300506 long ret = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300507
Hans Verkuil6a717882010-04-06 15:56:08 -0300508 if (ops == NULL) {
509 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
510 vfd->name);
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300511 return ret;
Hans Verkuil6a717882010-04-06 15:56:08 -0300512 }
513
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300514 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
515 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
516 v4l_print_ioctl(vfd->name, cmd);
517 printk(KERN_CONT "\n");
518 }
519
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300520 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300521 vfh = file->private_data;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300522 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
523 }
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300524
Hans Verkuil93d5a302011-08-09 09:32:06 -0300525 if (use_fh_prio)
526 ret_prio = v4l2_prio_check(vfd->prio, vfh->prio);
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300527
Hans Verkuil6a717882010-04-06 15:56:08 -0300528 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300529
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300530 /* --- capabilities ------------------------------------------ */
531 case VIDIOC_QUERYCAP:
532 {
533 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300534
Hans Verkuila3998102008-07-21 02:57:38 -0300535 if (!ops->vidioc_querycap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300536 break;
537
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -0300538 cap->version = LINUX_VERSION_CODE;
Hans Verkuila3998102008-07-21 02:57:38 -0300539 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300540 if (!ret)
541 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
542 "version=0x%08x, "
543 "capabilities=0x%08x\n",
544 cap->driver, cap->card, cap->bus_info,
545 cap->version,
546 cap->capabilities);
547 break;
548 }
549
550 /* --- priority ------------------------------------------ */
551 case VIDIOC_G_PRIORITY:
552 {
553 enum v4l2_priority *p = arg;
554
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300555 if (ops->vidioc_g_priority) {
556 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300557 } else if (use_fh_prio) {
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300558 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
559 ret = 0;
560 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300561 if (!ret)
562 dbgarg(cmd, "priority is %d\n", *p);
563 break;
564 }
565 case VIDIOC_S_PRIORITY:
566 {
567 enum v4l2_priority *p = arg;
568
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300569 if (!ops->vidioc_s_priority && !use_fh_prio)
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300570 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300571 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300572 if (ops->vidioc_s_priority)
573 ret = ops->vidioc_s_priority(file, fh, *p);
574 else
Hans Verkuil93d5a302011-08-09 09:32:06 -0300575 ret = ret_prio ? ret_prio :
576 v4l2_prio_change(&vfd->v4l2_dev->prio,
577 &vfh->prio, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300578 break;
579 }
580
581 /* --- capture ioctls ---------------------------------------- */
582 case VIDIOC_ENUM_FMT:
583 {
584 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300585
Trent Piepho19c96e42009-03-04 01:21:02 -0300586 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300587 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300588 if (likely(ops->vidioc_enum_fmt_vid_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300589 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300590 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300591 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300592 if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300593 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
594 fh, f);
595 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300596 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300597 if (likely(ops->vidioc_enum_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300598 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300599 fh, f);
600 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300601 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300602 if (likely(ops->vidioc_enum_fmt_vid_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300603 ret = ops->vidioc_enum_fmt_vid_out(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_OUTPUT_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300606 if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300607 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
608 fh, f);
609 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300610 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300611 if (likely(ops->vidioc_enum_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300612 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300613 fh, f);
614 break;
615 default:
616 break;
617 }
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300618 if (likely (!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300619 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
620 "pixelformat=%c%c%c%c, description='%s'\n",
621 f->index, f->type, f->flags,
622 (f->pixelformat & 0xff),
623 (f->pixelformat >> 8) & 0xff,
624 (f->pixelformat >> 16) & 0xff,
625 (f->pixelformat >> 24) & 0xff,
626 f->description);
Hans Verkuil93d5a302011-08-09 09:32:06 -0300627 else if (ret == -ENOTTY &&
628 (ops->vidioc_enum_fmt_vid_cap ||
629 ops->vidioc_enum_fmt_vid_out ||
630 ops->vidioc_enum_fmt_vid_cap_mplane ||
631 ops->vidioc_enum_fmt_vid_out_mplane ||
632 ops->vidioc_enum_fmt_vid_overlay ||
633 ops->vidioc_enum_fmt_type_private))
634 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300635 break;
636 }
637 case VIDIOC_G_FMT:
638 {
639 struct v4l2_format *f = (struct v4l2_format *)arg;
640
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300641 /* FIXME: Should be one dump per type */
642 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
643
644 switch (f->type) {
645 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300646 if (ops->vidioc_g_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300647 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300648 if (!ret)
649 v4l_print_pix_fmt(vfd, &f->fmt.pix);
650 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300651 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300652 if (ops->vidioc_g_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300653 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
654 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300655 if (!ret)
656 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
657 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300658 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300659 if (likely(ops->vidioc_g_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300660 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300661 fh, f);
662 break;
663 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300664 if (ops->vidioc_g_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300665 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300666 if (!ret)
667 v4l_print_pix_fmt(vfd, &f->fmt.pix);
668 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300669 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300670 if (ops->vidioc_g_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300671 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
672 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300673 if (!ret)
674 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
675 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300676 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300677 if (likely(ops->vidioc_g_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300678 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300679 fh, f);
680 break;
681 case V4L2_BUF_TYPE_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300682 if (likely(ops->vidioc_g_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300683 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300684 break;
685 case V4L2_BUF_TYPE_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300686 if (likely(ops->vidioc_g_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300687 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300688 break;
689 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300690 if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300691 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300692 fh, f);
693 break;
694 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300695 if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300696 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300697 fh, f);
698 break;
699 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300700 if (likely(ops->vidioc_g_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300701 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300702 fh, f);
703 break;
704 }
Hans Verkuil93d5a302011-08-09 09:32:06 -0300705 if (unlikely(ret == -ENOTTY && have_fmt_ops(g)))
706 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300707
708 break;
709 }
710 case VIDIOC_S_FMT:
711 {
712 struct v4l2_format *f = (struct v4l2_format *)arg;
713
Hans Verkuil93d5a302011-08-09 09:32:06 -0300714 if (!have_fmt_ops(s))
715 break;
716 if (ret_prio) {
717 ret = ret_prio;
718 break;
719 }
720 ret = -EINVAL;
721
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300722 /* FIXME: Should be one dump per type */
723 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
724
725 switch (f->type) {
726 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300727 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300728 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300729 if (ops->vidioc_s_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300730 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300731 break;
732 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
733 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
734 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300735 if (ops->vidioc_s_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300736 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
737 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300738 break;
739 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300740 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300741 if (ops->vidioc_s_fmt_vid_overlay)
742 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300743 fh, f);
744 break;
745 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300746 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300747 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300748 if (ops->vidioc_s_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300749 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300750 break;
751 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
752 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
753 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300754 if (ops->vidioc_s_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300755 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
756 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300757 break;
758 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300759 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300760 if (ops->vidioc_s_fmt_vid_out_overlay)
761 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300762 fh, f);
763 break;
764 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300765 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300766 if (likely(ops->vidioc_s_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300767 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300768 break;
769 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300770 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300771 if (likely(ops->vidioc_s_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300772 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300773 break;
774 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300775 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300776 if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300777 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300778 fh, f);
779 break;
780 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300781 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300782 if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300783 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300784 fh, f);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300785
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300786 break;
787 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300788 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300789 if (likely(ops->vidioc_s_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300790 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300791 fh, f);
792 break;
793 }
794 break;
795 }
796 case VIDIOC_TRY_FMT:
797 {
798 struct v4l2_format *f = (struct v4l2_format *)arg;
799
800 /* FIXME: Should be one dump per type */
801 dbgarg(cmd, "type=%s\n", prt_names(f->type,
802 v4l2_type_names));
803 switch (f->type) {
804 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300805 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300806 if (ops->vidioc_try_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300807 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300808 if (!ret)
809 v4l_print_pix_fmt(vfd, &f->fmt.pix);
810 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300811 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
812 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300813 if (ops->vidioc_try_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300814 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
815 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300816 if (!ret)
817 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
818 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300819 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300820 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300821 if (likely(ops->vidioc_try_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300822 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300823 fh, f);
824 break;
825 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300826 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300827 if (ops->vidioc_try_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300828 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300829 if (!ret)
830 v4l_print_pix_fmt(vfd, &f->fmt.pix);
831 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300832 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
833 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300834 if (ops->vidioc_try_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300835 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
836 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300837 if (!ret)
838 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
839 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300840 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300841 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300842 if (likely(ops->vidioc_try_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300843 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300844 fh, f);
845 break;
846 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300847 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300848 if (likely(ops->vidioc_try_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300849 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300850 break;
851 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300852 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300853 if (likely(ops->vidioc_try_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300854 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300855 break;
856 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300857 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300858 if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300859 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300860 fh, f);
861 break;
862 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300863 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300864 if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300865 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300866 fh, f);
867 break;
868 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300869 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300870 if (likely(ops->vidioc_try_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300871 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300872 fh, f);
873 break;
874 }
Hans Verkuil93d5a302011-08-09 09:32:06 -0300875 if (unlikely(ret == -ENOTTY && have_fmt_ops(try)))
876 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300877 break;
878 }
879 /* FIXME: Those buf reqs could be handled here,
880 with some changes on videobuf to allow its header to be included at
881 videodev2.h or being merged at videodev2.
882 */
883 case VIDIOC_REQBUFS:
884 {
885 struct v4l2_requestbuffers *p = arg;
886
Hans Verkuila3998102008-07-21 02:57:38 -0300887 if (!ops->vidioc_reqbufs)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300888 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300889 if (ret_prio) {
890 ret = ret_prio;
891 break;
892 }
Hans Verkuila3998102008-07-21 02:57:38 -0300893 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300894 if (ret)
895 break;
896
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300897 if (p->type < V4L2_BUF_TYPE_PRIVATE)
898 CLEAR_AFTER_FIELD(p, memory);
899
Hans Verkuila3998102008-07-21 02:57:38 -0300900 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300901 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
902 p->count,
903 prt_names(p->type, v4l2_type_names),
904 prt_names(p->memory, v4l2_memory_names));
905 break;
906 }
907 case VIDIOC_QUERYBUF:
908 {
909 struct v4l2_buffer *p = arg;
910
Hans Verkuila3998102008-07-21 02:57:38 -0300911 if (!ops->vidioc_querybuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300912 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300913 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300914 if (ret)
915 break;
916
Hans Verkuila3998102008-07-21 02:57:38 -0300917 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300918 if (!ret)
919 dbgbuf(cmd, vfd, p);
920 break;
921 }
922 case VIDIOC_QBUF:
923 {
924 struct v4l2_buffer *p = arg;
925
Hans Verkuila3998102008-07-21 02:57:38 -0300926 if (!ops->vidioc_qbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300927 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300928 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300929 if (ret)
930 break;
931
Hans Verkuila3998102008-07-21 02:57:38 -0300932 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300933 if (!ret)
934 dbgbuf(cmd, vfd, p);
935 break;
936 }
937 case VIDIOC_DQBUF:
938 {
939 struct v4l2_buffer *p = arg;
940
Hans Verkuila3998102008-07-21 02:57:38 -0300941 if (!ops->vidioc_dqbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300942 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300943 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300944 if (ret)
945 break;
946
Hans Verkuila3998102008-07-21 02:57:38 -0300947 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300948 if (!ret)
949 dbgbuf(cmd, vfd, p);
950 break;
951 }
952 case VIDIOC_OVERLAY:
953 {
954 int *i = arg;
955
Hans Verkuila3998102008-07-21 02:57:38 -0300956 if (!ops->vidioc_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300957 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300958 if (ret_prio) {
959 ret = ret_prio;
960 break;
961 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300962 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -0300963 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300964 break;
965 }
966 case VIDIOC_G_FBUF:
967 {
968 struct v4l2_framebuffer *p = arg;
969
Hans Verkuila3998102008-07-21 02:57:38 -0300970 if (!ops->vidioc_g_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300971 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300972 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300973 if (!ret) {
974 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
975 p->capability, p->flags,
976 (unsigned long)p->base);
977 v4l_print_pix_fmt(vfd, &p->fmt);
978 }
979 break;
980 }
981 case VIDIOC_S_FBUF:
982 {
983 struct v4l2_framebuffer *p = arg;
984
Hans Verkuila3998102008-07-21 02:57:38 -0300985 if (!ops->vidioc_s_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300986 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300987 if (ret_prio) {
988 ret = ret_prio;
989 break;
990 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300991 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
992 p->capability, p->flags, (unsigned long)p->base);
993 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -0300994 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300995 break;
996 }
997 case VIDIOC_STREAMON:
998 {
999 enum v4l2_buf_type i = *(int *)arg;
1000
Hans Verkuila3998102008-07-21 02:57:38 -03001001 if (!ops->vidioc_streamon)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001002 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001003 if (ret_prio) {
1004 ret = ret_prio;
1005 break;
1006 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001007 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001008 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001009 break;
1010 }
1011 case VIDIOC_STREAMOFF:
1012 {
1013 enum v4l2_buf_type i = *(int *)arg;
1014
Hans Verkuila3998102008-07-21 02:57:38 -03001015 if (!ops->vidioc_streamoff)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001016 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001017 if (ret_prio) {
1018 ret = ret_prio;
1019 break;
1020 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001021 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001022 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001023 break;
1024 }
1025 /* ---------- tv norms ---------- */
1026 case VIDIOC_ENUMSTD:
1027 {
1028 struct v4l2_standard *p = arg;
1029 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1030 unsigned int index = p->index, i, j = 0;
1031 const char *descr = "";
1032
Hans Verkuil93d5a302011-08-09 09:32:06 -03001033 if (id == 0)
1034 break;
1035 ret = -EINVAL;
1036
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001037 /* Return norm array in a canonical way */
1038 for (i = 0; i <= index && id; i++) {
1039 /* last std value in the standards array is 0, so this
1040 while always ends there since (id & 0) == 0. */
1041 while ((id & standards[j].std) != standards[j].std)
1042 j++;
1043 curr_id = standards[j].std;
1044 descr = standards[j].descr;
1045 j++;
1046 if (curr_id == 0)
1047 break;
1048 if (curr_id != V4L2_STD_PAL &&
1049 curr_id != V4L2_STD_SECAM &&
1050 curr_id != V4L2_STD_NTSC)
1051 id &= ~curr_id;
1052 }
1053 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001054 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001055
1056 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001057
1058 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1059 "framelines=%d\n", p->index,
1060 (unsigned long long)p->id, p->name,
1061 p->frameperiod.numerator,
1062 p->frameperiod.denominator,
1063 p->framelines);
1064
1065 ret = 0;
1066 break;
1067 }
1068 case VIDIOC_G_STD:
1069 {
1070 v4l2_std_id *id = arg;
1071
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001072 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001073 if (ops->vidioc_g_std)
1074 ret = ops->vidioc_g_std(file, fh, id);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001075 else if (vfd->current_norm) {
1076 ret = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001077 *id = vfd->current_norm;
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001078 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001079
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001080 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001081 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1082 break;
1083 }
1084 case VIDIOC_S_STD:
1085 {
1086 v4l2_std_id *id = arg, norm;
1087
1088 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1089
Hans Verkuil93d5a302011-08-09 09:32:06 -03001090 if (!ops->vidioc_s_std)
1091 break;
1092
1093 if (ret_prio) {
1094 ret = ret_prio;
1095 break;
1096 }
1097 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001098 norm = (*id) & vfd->tvnorms;
1099 if (vfd->tvnorms && !norm) /* Check if std is supported */
1100 break;
1101
1102 /* Calls the specific handler */
Hans Verkuil93d5a302011-08-09 09:32:06 -03001103 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001104
1105 /* Updates standard information */
1106 if (ret >= 0)
1107 vfd->current_norm = norm;
1108 break;
1109 }
1110 case VIDIOC_QUERYSTD:
1111 {
1112 v4l2_std_id *p = arg;
1113
Hans Verkuila3998102008-07-21 02:57:38 -03001114 if (!ops->vidioc_querystd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001115 break;
Mauro Carvalho Chehab8715e6c2011-10-04 09:32:23 -03001116 /*
1117 * If nothing detected, it should return all supported
1118 * Drivers just need to mask the std argument, in order
1119 * to remove the standards that don't apply from the mask.
1120 * This means that tuners, audio and video decoders can join
1121 * their efforts to improve the standards detection
1122 */
1123 *p = vfd->tvnorms;
Hans Verkuila3998102008-07-21 02:57:38 -03001124 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001125 if (!ret)
1126 dbgarg(cmd, "detected std=%08Lx\n",
1127 (unsigned long long)*p);
1128 break;
1129 }
1130 /* ------ input switching ---------- */
1131 /* FIXME: Inputs can be handled inside videodev2 */
1132 case VIDIOC_ENUMINPUT:
1133 {
1134 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001135
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001136 /*
1137 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1138 * CAP_STD here based on ioctl handler provided by the
1139 * driver. If the driver doesn't support these
1140 * for a specific input, it must override these flags.
1141 */
1142 if (ops->vidioc_s_std)
1143 p->capabilities |= V4L2_IN_CAP_STD;
1144 if (ops->vidioc_s_dv_preset)
1145 p->capabilities |= V4L2_IN_CAP_PRESETS;
1146 if (ops->vidioc_s_dv_timings)
1147 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1148
Hans Verkuila3998102008-07-21 02:57:38 -03001149 if (!ops->vidioc_enum_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001150 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001151
Hans Verkuila3998102008-07-21 02:57:38 -03001152 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001153 if (!ret)
1154 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1155 "audioset=%d, "
1156 "tuner=%d, std=%08Lx, status=%d\n",
1157 p->index, p->name, p->type, p->audioset,
1158 p->tuner,
1159 (unsigned long long)p->std,
1160 p->status);
1161 break;
1162 }
1163 case VIDIOC_G_INPUT:
1164 {
1165 unsigned int *i = arg;
1166
Hans Verkuila3998102008-07-21 02:57:38 -03001167 if (!ops->vidioc_g_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001168 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001169 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001170 if (!ret)
1171 dbgarg(cmd, "value=%d\n", *i);
1172 break;
1173 }
1174 case VIDIOC_S_INPUT:
1175 {
1176 unsigned int *i = arg;
1177
Hans Verkuila3998102008-07-21 02:57:38 -03001178 if (!ops->vidioc_s_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001179 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001180 if (ret_prio) {
1181 ret = ret_prio;
1182 break;
1183 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001184 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001185 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001186 break;
1187 }
1188
1189 /* ------ output switching ---------- */
1190 case VIDIOC_ENUMOUTPUT:
1191 {
1192 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001193
Hans Verkuila3998102008-07-21 02:57:38 -03001194 if (!ops->vidioc_enum_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001195 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001196
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001197 /*
1198 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1199 * CAP_STD here based on ioctl handler provided by the
1200 * driver. If the driver doesn't support these
1201 * for a specific output, it must override these flags.
1202 */
1203 if (ops->vidioc_s_std)
1204 p->capabilities |= V4L2_OUT_CAP_STD;
1205 if (ops->vidioc_s_dv_preset)
1206 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1207 if (ops->vidioc_s_dv_timings)
1208 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1209
Hans Verkuila3998102008-07-21 02:57:38 -03001210 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001211 if (!ret)
1212 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1213 "audioset=0x%x, "
1214 "modulator=%d, std=0x%08Lx\n",
1215 p->index, p->name, p->type, p->audioset,
1216 p->modulator, (unsigned long long)p->std);
1217 break;
1218 }
1219 case VIDIOC_G_OUTPUT:
1220 {
1221 unsigned int *i = arg;
1222
Hans Verkuila3998102008-07-21 02:57:38 -03001223 if (!ops->vidioc_g_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001224 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001225 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001226 if (!ret)
1227 dbgarg(cmd, "value=%d\n", *i);
1228 break;
1229 }
1230 case VIDIOC_S_OUTPUT:
1231 {
1232 unsigned int *i = arg;
1233
Hans Verkuila3998102008-07-21 02:57:38 -03001234 if (!ops->vidioc_s_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001235 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001236 if (ret_prio) {
1237 ret = ret_prio;
1238 break;
1239 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001240 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001241 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001242 break;
1243 }
1244
1245 /* --- controls ---------------------------------------------- */
1246 case VIDIOC_QUERYCTRL:
1247 {
1248 struct v4l2_queryctrl *p = arg;
1249
Hans Verkuil2d28b682011-03-12 08:54:43 -03001250 if (vfh && vfh->ctrl_handler)
1251 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1252 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001253 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1254 else if (ops->vidioc_queryctrl)
1255 ret = ops->vidioc_queryctrl(file, fh, p);
1256 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001257 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001258 if (!ret)
1259 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1260 "step=%d, default=%d, flags=0x%08x\n",
1261 p->id, p->type, p->name,
1262 p->minimum, p->maximum,
1263 p->step, p->default_value, p->flags);
1264 else
1265 dbgarg(cmd, "id=0x%x\n", p->id);
1266 break;
1267 }
1268 case VIDIOC_G_CTRL:
1269 {
1270 struct v4l2_control *p = arg;
1271
Hans Verkuil2d28b682011-03-12 08:54:43 -03001272 if (vfh && vfh->ctrl_handler)
1273 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1274 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001275 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1276 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001277 ret = ops->vidioc_g_ctrl(file, fh, p);
1278 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001279 struct v4l2_ext_controls ctrls;
1280 struct v4l2_ext_control ctrl;
1281
1282 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1283 ctrls.count = 1;
1284 ctrls.controls = &ctrl;
1285 ctrl.id = p->id;
1286 ctrl.value = p->value;
1287 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001288 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001289 if (ret == 0)
1290 p->value = ctrl.value;
1291 }
1292 } else
1293 break;
1294 if (!ret)
1295 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1296 else
1297 dbgarg(cmd, "id=0x%x\n", p->id);
1298 break;
1299 }
1300 case VIDIOC_S_CTRL:
1301 {
1302 struct v4l2_control *p = arg;
1303 struct v4l2_ext_controls ctrls;
1304 struct v4l2_ext_control ctrl;
1305
Hans Verkuil2d28b682011-03-12 08:54:43 -03001306 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001307 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001308 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001309 if (ret_prio) {
1310 ret = ret_prio;
1311 break;
1312 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001313
1314 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1315
Hans Verkuil2d28b682011-03-12 08:54:43 -03001316 if (vfh && vfh->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001317 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001318 break;
1319 }
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001320 if (vfd->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001321 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001322 break;
1323 }
Hans Verkuila3998102008-07-21 02:57:38 -03001324 if (ops->vidioc_s_ctrl) {
1325 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001326 break;
1327 }
Hans Verkuila3998102008-07-21 02:57:38 -03001328 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001329 break;
1330
1331 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1332 ctrls.count = 1;
1333 ctrls.controls = &ctrl;
1334 ctrl.id = p->id;
1335 ctrl.value = p->value;
1336 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001337 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001338 else
1339 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001340 break;
1341 }
1342 case VIDIOC_G_EXT_CTRLS:
1343 {
1344 struct v4l2_ext_controls *p = arg;
1345
1346 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001347 if (vfh && vfh->ctrl_handler)
1348 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1349 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001350 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001351 else if (ops->vidioc_g_ext_ctrls)
1352 ret = check_ext_ctrls(p, 0) ?
1353 ops->vidioc_g_ext_ctrls(file, fh, p) :
1354 -EINVAL;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001355 else
1356 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001357 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1358 break;
1359 }
1360 case VIDIOC_S_EXT_CTRLS:
1361 {
1362 struct v4l2_ext_controls *p = arg;
1363
1364 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001365 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1366 !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001367 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001368 if (ret_prio) {
1369 ret = ret_prio;
1370 break;
1371 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001372 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001373 if (vfh && vfh->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001374 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001375 else if (vfd->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001376 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001377 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001378 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001379 else
1380 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001381 break;
1382 }
1383 case VIDIOC_TRY_EXT_CTRLS:
1384 {
1385 struct v4l2_ext_controls *p = arg;
1386
1387 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001388 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1389 !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001390 break;
1391 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001392 if (vfh && vfh->ctrl_handler)
1393 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1394 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001395 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1396 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001397 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001398 else
1399 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001400 break;
1401 }
1402 case VIDIOC_QUERYMENU:
1403 {
1404 struct v4l2_querymenu *p = arg;
1405
Hans Verkuil2d28b682011-03-12 08:54:43 -03001406 if (vfh && vfh->ctrl_handler)
1407 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1408 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001409 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1410 else if (ops->vidioc_querymenu)
1411 ret = ops->vidioc_querymenu(file, fh, p);
1412 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001413 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001414 if (!ret)
1415 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1416 p->id, p->index, p->name);
1417 else
1418 dbgarg(cmd, "id=0x%x, index=%d\n",
1419 p->id, p->index);
1420 break;
1421 }
1422 /* --- audio ---------------------------------------------- */
1423 case VIDIOC_ENUMAUDIO:
1424 {
1425 struct v4l2_audio *p = arg;
1426
Hans Verkuila3998102008-07-21 02:57:38 -03001427 if (!ops->vidioc_enumaudio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001428 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001429 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001430 if (!ret)
1431 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1432 "mode=0x%x\n", p->index, p->name,
1433 p->capability, p->mode);
1434 else
1435 dbgarg(cmd, "index=%d\n", p->index);
1436 break;
1437 }
1438 case VIDIOC_G_AUDIO:
1439 {
1440 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001441
Hans Verkuila3998102008-07-21 02:57:38 -03001442 if (!ops->vidioc_g_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001443 break;
1444
Hans Verkuila3998102008-07-21 02:57:38 -03001445 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001446 if (!ret)
1447 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1448 "mode=0x%x\n", p->index,
1449 p->name, p->capability, p->mode);
1450 else
1451 dbgarg(cmd, "index=%d\n", p->index);
1452 break;
1453 }
1454 case VIDIOC_S_AUDIO:
1455 {
1456 struct v4l2_audio *p = arg;
1457
Hans Verkuila3998102008-07-21 02:57:38 -03001458 if (!ops->vidioc_s_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001459 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001460 if (ret_prio) {
1461 ret = ret_prio;
1462 break;
1463 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001464 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1465 "mode=0x%x\n", p->index, p->name,
1466 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001467 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001468 break;
1469 }
1470 case VIDIOC_ENUMAUDOUT:
1471 {
1472 struct v4l2_audioout *p = arg;
1473
Hans Verkuila3998102008-07-21 02:57:38 -03001474 if (!ops->vidioc_enumaudout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001475 break;
1476 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001477 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001478 if (!ret)
1479 dbgarg2("index=%d, name=%s, capability=%d, "
1480 "mode=%d\n", p->index, p->name,
1481 p->capability, p->mode);
1482 break;
1483 }
1484 case VIDIOC_G_AUDOUT:
1485 {
1486 struct v4l2_audioout *p = arg;
1487
Hans Verkuila3998102008-07-21 02:57:38 -03001488 if (!ops->vidioc_g_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001489 break;
Trent Piepho337f9d22009-03-04 01:21:02 -03001490
Hans Verkuila3998102008-07-21 02:57:38 -03001491 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001492 if (!ret)
1493 dbgarg2("index=%d, name=%s, capability=%d, "
1494 "mode=%d\n", p->index, p->name,
1495 p->capability, p->mode);
1496 break;
1497 }
1498 case VIDIOC_S_AUDOUT:
1499 {
1500 struct v4l2_audioout *p = arg;
1501
Hans Verkuila3998102008-07-21 02:57:38 -03001502 if (!ops->vidioc_s_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001503 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001504 if (ret_prio) {
1505 ret = ret_prio;
1506 break;
1507 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001508 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1509 "mode=%d\n", p->index, p->name,
1510 p->capability, p->mode);
1511
Hans Verkuila3998102008-07-21 02:57:38 -03001512 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001513 break;
1514 }
1515 case VIDIOC_G_MODULATOR:
1516 {
1517 struct v4l2_modulator *p = arg;
1518
Hans Verkuila3998102008-07-21 02:57:38 -03001519 if (!ops->vidioc_g_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001520 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001521 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001522 if (!ret)
1523 dbgarg(cmd, "index=%d, name=%s, "
1524 "capability=%d, rangelow=%d,"
1525 " rangehigh=%d, txsubchans=%d\n",
1526 p->index, p->name, p->capability,
1527 p->rangelow, p->rangehigh,
1528 p->txsubchans);
1529 break;
1530 }
1531 case VIDIOC_S_MODULATOR:
1532 {
1533 struct v4l2_modulator *p = arg;
1534
Hans Verkuila3998102008-07-21 02:57:38 -03001535 if (!ops->vidioc_s_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001536 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001537 if (ret_prio) {
1538 ret = ret_prio;
1539 break;
1540 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001541 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1542 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1543 p->index, p->name, p->capability, p->rangelow,
1544 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001545 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001546 break;
1547 }
1548 case VIDIOC_G_CROP:
1549 {
1550 struct v4l2_crop *p = arg;
1551
Hans Verkuila3998102008-07-21 02:57:38 -03001552 if (!ops->vidioc_g_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001553 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001554
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001555 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001556 ret = ops->vidioc_g_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001557 if (!ret)
1558 dbgrect(vfd, "", &p->c);
1559 break;
1560 }
1561 case VIDIOC_S_CROP:
1562 {
1563 struct v4l2_crop *p = arg;
1564
Hans Verkuila3998102008-07-21 02:57:38 -03001565 if (!ops->vidioc_s_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001566 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001567 if (ret_prio) {
1568 ret = ret_prio;
1569 break;
1570 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001571 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1572 dbgrect(vfd, "", &p->c);
Hans Verkuila3998102008-07-21 02:57:38 -03001573 ret = ops->vidioc_s_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001574 break;
1575 }
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001576 case VIDIOC_G_SELECTION:
1577 {
1578 struct v4l2_selection *p = arg;
1579
1580 if (!ops->vidioc_g_selection)
1581 break;
1582
1583 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1584
1585 ret = ops->vidioc_g_selection(file, fh, p);
1586 if (!ret)
1587 dbgrect(vfd, "", &p->r);
1588 break;
1589 }
1590 case VIDIOC_S_SELECTION:
1591 {
1592 struct v4l2_selection *p = arg;
1593
1594 if (!ops->vidioc_s_selection)
1595 break;
1596
1597 if (ret_prio) {
1598 ret = ret_prio;
1599 break;
1600 }
1601
1602 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1603 dbgrect(vfd, "", &p->r);
1604
1605 ret = ops->vidioc_s_selection(file, fh, p);
1606 break;
1607 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001608 case VIDIOC_CROPCAP:
1609 {
1610 struct v4l2_cropcap *p = arg;
1611
1612 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuila3998102008-07-21 02:57:38 -03001613 if (!ops->vidioc_cropcap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001614 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001615
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001616 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001617 ret = ops->vidioc_cropcap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001618 if (!ret) {
1619 dbgrect(vfd, "bounds ", &p->bounds);
1620 dbgrect(vfd, "defrect ", &p->defrect);
1621 }
1622 break;
1623 }
1624 case VIDIOC_G_JPEGCOMP:
1625 {
1626 struct v4l2_jpegcompression *p = arg;
1627
Hans Verkuila3998102008-07-21 02:57:38 -03001628 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001629 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001630
Hans Verkuila3998102008-07-21 02:57:38 -03001631 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001632 if (!ret)
1633 dbgarg(cmd, "quality=%d, APPn=%d, "
1634 "APP_len=%d, COM_len=%d, "
1635 "jpeg_markers=%d\n",
1636 p->quality, p->APPn, p->APP_len,
1637 p->COM_len, p->jpeg_markers);
1638 break;
1639 }
1640 case VIDIOC_S_JPEGCOMP:
1641 {
1642 struct v4l2_jpegcompression *p = arg;
1643
Hans Verkuila3998102008-07-21 02:57:38 -03001644 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001645 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001646 if (ret_prio) {
1647 ret = ret_prio;
1648 break;
1649 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001650 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1651 "COM_len=%d, jpeg_markers=%d\n",
1652 p->quality, p->APPn, p->APP_len,
1653 p->COM_len, p->jpeg_markers);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001654 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001655 break;
1656 }
1657 case VIDIOC_G_ENC_INDEX:
1658 {
1659 struct v4l2_enc_idx *p = arg;
1660
Hans Verkuila3998102008-07-21 02:57:38 -03001661 if (!ops->vidioc_g_enc_index)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001662 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001663 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001664 if (!ret)
1665 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1666 p->entries, p->entries_cap);
1667 break;
1668 }
1669 case VIDIOC_ENCODER_CMD:
1670 {
1671 struct v4l2_encoder_cmd *p = arg;
1672
Hans Verkuila3998102008-07-21 02:57:38 -03001673 if (!ops->vidioc_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001674 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001675 if (ret_prio) {
1676 ret = ret_prio;
1677 break;
1678 }
Hans Verkuila3998102008-07-21 02:57:38 -03001679 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001680 if (!ret)
1681 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1682 break;
1683 }
1684 case VIDIOC_TRY_ENCODER_CMD:
1685 {
1686 struct v4l2_encoder_cmd *p = arg;
1687
Hans Verkuila3998102008-07-21 02:57:38 -03001688 if (!ops->vidioc_try_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001689 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001690 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001691 if (!ret)
1692 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1693 break;
1694 }
1695 case VIDIOC_G_PARM:
1696 {
1697 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001698
Hans Verkuil93d5a302011-08-09 09:32:06 -03001699 if (!ops->vidioc_g_parm && !vfd->current_norm)
1700 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001701 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001702 ret = check_fmt(ops, p->type);
1703 if (ret)
1704 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001705 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001706 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001707 v4l2_std_id std = vfd->current_norm;
1708
Hans Verkuil93d5a302011-08-09 09:32:06 -03001709 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001710 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001711 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001712
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001713 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001714 if (ops->vidioc_g_std)
1715 ret = ops->vidioc_g_std(file, fh, &std);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001716 if (ret == 0)
1717 v4l2_video_std_frame_period(std,
1718 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001719 }
1720
1721 dbgarg(cmd, "type=%d\n", p->type);
1722 break;
1723 }
1724 case VIDIOC_S_PARM:
1725 {
1726 struct v4l2_streamparm *p = arg;
1727
Hans Verkuila3998102008-07-21 02:57:38 -03001728 if (!ops->vidioc_s_parm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001729 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001730 if (ret_prio) {
1731 ret = ret_prio;
1732 break;
1733 }
Trent Piepho34796bc2009-03-28 22:25:35 -03001734 ret = check_fmt(ops, p->type);
1735 if (ret)
1736 break;
1737
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001738 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001739 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001740 break;
1741 }
1742 case VIDIOC_G_TUNER:
1743 {
1744 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001745
Hans Verkuila3998102008-07-21 02:57:38 -03001746 if (!ops->vidioc_g_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001747 break;
1748
Hans Verkuil227690d2011-06-12 06:36:41 -03001749 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1750 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001751 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001752 if (!ret)
1753 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1754 "capability=0x%x, rangelow=%d, "
1755 "rangehigh=%d, signal=%d, afc=%d, "
1756 "rxsubchans=0x%x, audmode=%d\n",
1757 p->index, p->name, p->type,
1758 p->capability, p->rangelow,
1759 p->rangehigh, p->signal, p->afc,
1760 p->rxsubchans, p->audmode);
1761 break;
1762 }
1763 case VIDIOC_S_TUNER:
1764 {
1765 struct v4l2_tuner *p = arg;
1766
Hans Verkuila3998102008-07-21 02:57:38 -03001767 if (!ops->vidioc_s_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001768 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001769 if (ret_prio) {
1770 ret = ret_prio;
1771 break;
1772 }
Hans Verkuil227690d2011-06-12 06:36:41 -03001773 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1774 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001775 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1776 "capability=0x%x, rangelow=%d, "
1777 "rangehigh=%d, signal=%d, afc=%d, "
1778 "rxsubchans=0x%x, audmode=%d\n",
1779 p->index, p->name, p->type,
1780 p->capability, p->rangelow,
1781 p->rangehigh, p->signal, p->afc,
1782 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001783 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001784 break;
1785 }
1786 case VIDIOC_G_FREQUENCY:
1787 {
1788 struct v4l2_frequency *p = arg;
1789
Hans Verkuila3998102008-07-21 02:57:38 -03001790 if (!ops->vidioc_g_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001791 break;
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;
1804
Hans Verkuila3998102008-07-21 02:57:38 -03001805 if (!ops->vidioc_s_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001806 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001807 if (ret_prio) {
1808 ret = ret_prio;
1809 break;
1810 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001811 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1812 p->tuner, p->type, p->frequency);
Hans Verkuila3998102008-07-21 02:57:38 -03001813 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001814 break;
1815 }
1816 case VIDIOC_G_SLICED_VBI_CAP:
1817 {
1818 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001819
Hans Verkuila3998102008-07-21 02:57:38 -03001820 if (!ops->vidioc_g_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001821 break;
Trent Piepho19c96e42009-03-04 01:21:02 -03001822
1823 /* Clear up to type, everything after type is zerod already */
1824 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1825
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001826 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001827 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001828 if (!ret)
1829 dbgarg2("service_set=%d\n", p->service_set);
1830 break;
1831 }
1832 case VIDIOC_LOG_STATUS:
1833 {
Hans Verkuila3998102008-07-21 02:57:38 -03001834 if (!ops->vidioc_log_status)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001835 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001836 ret = ops->vidioc_log_status(file, fh);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001837 break;
1838 }
1839#ifdef CONFIG_VIDEO_ADV_DEBUG
1840 case VIDIOC_DBG_G_REGISTER:
1841 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001842 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001843
Hans Verkuila1198cc2011-01-08 09:53:32 -03001844 if (ops->vidioc_g_register) {
1845 if (!capable(CAP_SYS_ADMIN))
1846 ret = -EPERM;
1847 else
1848 ret = ops->vidioc_g_register(file, fh, p);
1849 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001850 break;
1851 }
1852 case VIDIOC_DBG_S_REGISTER:
1853 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001854 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001855
Hans Verkuila1198cc2011-01-08 09:53:32 -03001856 if (ops->vidioc_s_register) {
1857 if (!capable(CAP_SYS_ADMIN))
1858 ret = -EPERM;
1859 else
1860 ret = ops->vidioc_s_register(file, fh, p);
1861 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001862 break;
1863 }
1864#endif
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001865 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001866 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001867 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001868
Hans Verkuila3998102008-07-21 02:57:38 -03001869 if (!ops->vidioc_g_chip_ident)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001870 break;
Hans Verkuil80b36e02009-02-07 11:00:02 -03001871 p->ident = V4L2_IDENT_NONE;
1872 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001873 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001874 if (!ret)
1875 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1876 break;
1877 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001878 case VIDIOC_S_HW_FREQ_SEEK:
1879 {
1880 struct v4l2_hw_freq_seek *p = arg;
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001881 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001882
Hans Verkuila3998102008-07-21 02:57:38 -03001883 if (!ops->vidioc_s_hw_freq_seek)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001884 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001885 if (ret_prio) {
1886 ret = ret_prio;
1887 break;
1888 }
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001889 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1890 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001891 dbgarg(cmd,
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001892 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1893 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1894 if (p->type != type)
1895 ret = -EINVAL;
1896 else
1897 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
Hans Verkuila3998102008-07-21 02:57:38 -03001898 break;
1899 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001900 case VIDIOC_ENUM_FRAMESIZES:
1901 {
1902 struct v4l2_frmsizeenum *p = arg;
1903
1904 if (!ops->vidioc_enum_framesizes)
1905 break;
1906
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001907 ret = ops->vidioc_enum_framesizes(file, fh, p);
1908 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001909 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1910 p->index,
1911 (p->pixel_format & 0xff),
1912 (p->pixel_format >> 8) & 0xff,
1913 (p->pixel_format >> 16) & 0xff,
1914 (p->pixel_format >> 24) & 0xff,
1915 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001916 switch (p->type) {
1917 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001918 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001919 p->discrete.width, p->discrete.height);
1920 break;
1921 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001922 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001923 p->stepwise.min_width, p->stepwise.min_height,
1924 p->stepwise.step_width, p->stepwise.step_height,
1925 p->stepwise.max_width, p->stepwise.max_height);
1926 break;
1927 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001928 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001929 break;
1930 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001931 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001932 }
1933
1934 break;
1935 }
1936 case VIDIOC_ENUM_FRAMEINTERVALS:
1937 {
1938 struct v4l2_frmivalenum *p = arg;
1939
1940 if (!ops->vidioc_enum_frameintervals)
1941 break;
1942
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001943 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1944 dbgarg(cmd,
1945 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1946 p->index, p->pixel_format,
1947 p->width, p->height, p->type);
1948 switch (p->type) {
1949 case V4L2_FRMIVAL_TYPE_DISCRETE:
1950 dbgarg2("fps=%d/%d\n",
1951 p->discrete.numerator,
1952 p->discrete.denominator);
1953 break;
1954 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03001955 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1956 p->stepwise.min.numerator,
1957 p->stepwise.min.denominator,
1958 p->stepwise.max.numerator,
1959 p->stepwise.max.denominator,
1960 p->stepwise.step.numerator,
1961 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001962 break;
1963 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1964 dbgarg2("continuous\n");
1965 break;
1966 default:
1967 dbgarg2("- Unknown type!\n");
1968 }
1969 break;
1970 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001971 case VIDIOC_ENUM_DV_PRESETS:
1972 {
1973 struct v4l2_dv_enum_preset *p = arg;
1974
1975 if (!ops->vidioc_enum_dv_presets)
1976 break;
1977
1978 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1979 if (!ret)
1980 dbgarg(cmd,
1981 "index=%d, preset=%d, name=%s, width=%d,"
1982 " height=%d ",
1983 p->index, p->preset, p->name, p->width,
1984 p->height);
1985 break;
1986 }
1987 case VIDIOC_S_DV_PRESET:
1988 {
1989 struct v4l2_dv_preset *p = arg;
1990
1991 if (!ops->vidioc_s_dv_preset)
1992 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001993 if (ret_prio) {
1994 ret = ret_prio;
1995 break;
1996 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001997
1998 dbgarg(cmd, "preset=%d\n", p->preset);
1999 ret = ops->vidioc_s_dv_preset(file, fh, p);
2000 break;
2001 }
2002 case VIDIOC_G_DV_PRESET:
2003 {
2004 struct v4l2_dv_preset *p = arg;
2005
2006 if (!ops->vidioc_g_dv_preset)
2007 break;
2008
2009 ret = ops->vidioc_g_dv_preset(file, fh, p);
2010 if (!ret)
2011 dbgarg(cmd, "preset=%d\n", p->preset);
2012 break;
2013 }
2014 case VIDIOC_QUERY_DV_PRESET:
2015 {
2016 struct v4l2_dv_preset *p = arg;
2017
2018 if (!ops->vidioc_query_dv_preset)
2019 break;
2020
2021 ret = ops->vidioc_query_dv_preset(file, fh, p);
2022 if (!ret)
2023 dbgarg(cmd, "preset=%d\n", p->preset);
2024 break;
2025 }
2026 case VIDIOC_S_DV_TIMINGS:
2027 {
2028 struct v4l2_dv_timings *p = arg;
2029
2030 if (!ops->vidioc_s_dv_timings)
2031 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002032 if (ret_prio) {
2033 ret = ret_prio;
2034 break;
2035 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002036
2037 switch (p->type) {
2038 case V4L2_DV_BT_656_1120:
2039 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2040 " width=%d, height=%d, polarities=%x,"
2041 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
2042 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
2043 " il_vfrontporch=%d, il_vsync=%d,"
2044 " il_vbackporch=%d\n",
2045 p->bt.interlaced, p->bt.pixelclock,
2046 p->bt.width, p->bt.height, p->bt.polarities,
2047 p->bt.hfrontporch, p->bt.hsync,
2048 p->bt.hbackporch, p->bt.vfrontporch,
2049 p->bt.vsync, p->bt.vbackporch,
2050 p->bt.il_vfrontporch, p->bt.il_vsync,
2051 p->bt.il_vbackporch);
2052 ret = ops->vidioc_s_dv_timings(file, fh, p);
2053 break;
2054 default:
2055 dbgarg2("Unknown type %d!\n", p->type);
2056 break;
2057 }
2058 break;
2059 }
2060 case VIDIOC_G_DV_TIMINGS:
2061 {
2062 struct v4l2_dv_timings *p = arg;
2063
2064 if (!ops->vidioc_g_dv_timings)
2065 break;
2066
2067 ret = ops->vidioc_g_dv_timings(file, fh, p);
2068 if (!ret) {
2069 switch (p->type) {
2070 case V4L2_DV_BT_656_1120:
2071 dbgarg2("bt-656/1120:interlaced=%d,"
2072 " pixelclock=%lld,"
2073 " width=%d, height=%d, polarities=%x,"
2074 " hfrontporch=%d, hsync=%d,"
2075 " hbackporch=%d, vfrontporch=%d,"
2076 " vsync=%d, vbackporch=%d,"
2077 " il_vfrontporch=%d, il_vsync=%d,"
2078 " il_vbackporch=%d\n",
2079 p->bt.interlaced, p->bt.pixelclock,
2080 p->bt.width, p->bt.height,
2081 p->bt.polarities, p->bt.hfrontporch,
2082 p->bt.hsync, p->bt.hbackporch,
2083 p->bt.vfrontporch, p->bt.vsync,
2084 p->bt.vbackporch, p->bt.il_vfrontporch,
2085 p->bt.il_vsync, p->bt.il_vbackporch);
2086 break;
2087 default:
2088 dbgarg2("Unknown type %d!\n", p->type);
2089 break;
2090 }
2091 }
2092 break;
2093 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002094 case VIDIOC_DQEVENT:
2095 {
2096 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002097
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002098 if (!ops->vidioc_subscribe_event)
2099 break;
2100
2101 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2102 if (ret < 0) {
2103 dbgarg(cmd, "no pending events?");
2104 break;
2105 }
2106 dbgarg(cmd,
2107 "pending=%d, type=0x%8.8x, sequence=%d, "
2108 "timestamp=%lu.%9.9lu ",
2109 ev->pending, ev->type, ev->sequence,
2110 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2111 break;
2112 }
2113 case VIDIOC_SUBSCRIBE_EVENT:
2114 {
2115 struct v4l2_event_subscription *sub = arg;
2116
2117 if (!ops->vidioc_subscribe_event)
2118 break;
2119
2120 ret = ops->vidioc_subscribe_event(fh, sub);
2121 if (ret < 0) {
2122 dbgarg(cmd, "failed, ret=%ld", ret);
2123 break;
2124 }
2125 dbgarg(cmd, "type=0x%8.8x", sub->type);
2126 break;
2127 }
2128 case VIDIOC_UNSUBSCRIBE_EVENT:
2129 {
2130 struct v4l2_event_subscription *sub = arg;
2131
2132 if (!ops->vidioc_unsubscribe_event)
2133 break;
2134
2135 ret = ops->vidioc_unsubscribe_event(fh, sub);
2136 if (ret < 0) {
2137 dbgarg(cmd, "failed, ret=%ld", ret);
2138 break;
2139 }
2140 dbgarg(cmd, "type=0x%8.8x", sub->type);
2141 break;
2142 }
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002143 case VIDIOC_CREATE_BUFS:
2144 {
2145 struct v4l2_create_buffers *create = arg;
2146
2147 if (!ops->vidioc_create_bufs)
2148 break;
2149 if (ret_prio) {
2150 ret = ret_prio;
2151 break;
2152 }
2153 ret = check_fmt(ops, create->format.type);
2154 if (ret)
2155 break;
2156
2157 ret = ops->vidioc_create_bufs(file, fh, create);
2158
2159 dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2160 break;
2161 }
2162 case VIDIOC_PREPARE_BUF:
2163 {
2164 struct v4l2_buffer *b = arg;
2165
2166 if (!ops->vidioc_prepare_buf)
2167 break;
2168 ret = check_fmt(ops, b->type);
2169 if (ret)
2170 break;
2171
2172 ret = ops->vidioc_prepare_buf(file, fh, b);
2173
2174 dbgarg(cmd, "index=%d", b->index);
2175 break;
2176 }
Hans Verkuila3998102008-07-21 02:57:38 -03002177 default:
Hans Verkuila3998102008-07-21 02:57:38 -03002178 if (!ops->vidioc_default)
2179 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002180 ret = ops->vidioc_default(file, fh, ret_prio >= 0, cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002181 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002182 } /* switch */
2183
2184 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2185 if (ret < 0) {
2186 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002187 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002188 }
2189 }
2190
2191 return ret;
2192}
2193
Trent Piepho19c96e42009-03-04 01:21:02 -03002194/* In some cases, only a few fields are used as input, i.e. when the app sets
2195 * "index" and then the driver fills in the rest of the structure for the thing
2196 * with that index. We only need to copy up the first non-input field. */
2197static unsigned long cmd_input_size(unsigned int cmd)
2198{
2199 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002200#define CMDINSIZE(cmd, type, field) \
2201 case VIDIOC_##cmd: \
2202 return offsetof(struct v4l2_##type, field) + \
2203 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03002204
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002205 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03002206 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2207 CMDINSIZE(G_FMT, format, type);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002208 CMDINSIZE(QUERYBUF, buffer, length);
Trent Piepho19c96e42009-03-04 01:21:02 -03002209 CMDINSIZE(G_PARM, streamparm, type);
2210 CMDINSIZE(ENUMSTD, standard, index);
2211 CMDINSIZE(ENUMINPUT, input, index);
2212 CMDINSIZE(G_CTRL, control, id);
2213 CMDINSIZE(G_TUNER, tuner, index);
2214 CMDINSIZE(QUERYCTRL, queryctrl, id);
2215 CMDINSIZE(QUERYMENU, querymenu, index);
2216 CMDINSIZE(ENUMOUTPUT, output, index);
2217 CMDINSIZE(G_MODULATOR, modulator, index);
2218 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2219 CMDINSIZE(CROPCAP, cropcap, type);
2220 CMDINSIZE(G_CROP, crop, type);
2221 CMDINSIZE(ENUMAUDIO, audio, index);
2222 CMDINSIZE(ENUMAUDOUT, audioout, index);
2223 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2224 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2225 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2226 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2227 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2228 default:
2229 return _IOC_SIZE(cmd);
2230 }
2231}
2232
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002233static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2234 void * __user *user_ptr, void ***kernel_ptr)
2235{
2236 int ret = 0;
2237
2238 switch (cmd) {
2239 case VIDIOC_QUERYBUF:
2240 case VIDIOC_QBUF:
2241 case VIDIOC_DQBUF: {
2242 struct v4l2_buffer *buf = parg;
2243
2244 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2245 if (buf->length > VIDEO_MAX_PLANES) {
2246 ret = -EINVAL;
2247 break;
2248 }
2249 *user_ptr = (void __user *)buf->m.planes;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002250 *kernel_ptr = (void *)&buf->m.planes;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002251 *array_size = sizeof(struct v4l2_plane) * buf->length;
2252 ret = 1;
2253 }
2254 break;
2255 }
2256
2257 case VIDIOC_S_EXT_CTRLS:
2258 case VIDIOC_G_EXT_CTRLS:
2259 case VIDIOC_TRY_EXT_CTRLS: {
2260 struct v4l2_ext_controls *ctrls = parg;
2261
2262 if (ctrls->count != 0) {
Dan Carpenter6c061082012-01-05 02:27:57 -03002263 if (ctrls->count > V4L2_CID_MAX_CTRLS) {
2264 ret = -EINVAL;
2265 break;
2266 }
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002267 *user_ptr = (void __user *)ctrls->controls;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002268 *kernel_ptr = (void *)&ctrls->controls;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002269 *array_size = sizeof(struct v4l2_ext_control)
2270 * ctrls->count;
2271 ret = 1;
2272 }
2273 break;
2274 }
2275 }
2276
2277 return ret;
2278}
2279
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002280long
2281video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2282 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002283{
2284 char sbuf[128];
2285 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002286 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002287 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002288 bool has_array_args;
2289 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002290 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002291 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002292
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002293 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002294 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002295 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2296 parg = sbuf;
2297 } else {
2298 /* too big to allocate from stack */
2299 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2300 if (NULL == mbuf)
2301 return -ENOMEM;
2302 parg = mbuf;
2303 }
2304
2305 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002306 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2307 unsigned long n = cmd_input_size(cmd);
2308
2309 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002310 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002311
2312 /* zero out anything we don't copy from userspace */
2313 if (n < _IOC_SIZE(cmd))
2314 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002315 } else {
2316 /* read-only ioctl */
2317 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002318 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002319 }
2320
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002321 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2322 if (err < 0)
2323 goto out;
2324 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002325
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002326 if (has_array_args) {
2327 /*
2328 * When adding new types of array args, make sure that the
2329 * parent argument to ioctl (which contains the pointer to the
2330 * array) fits into sbuf (so that mbuf will still remain
2331 * unused up to here).
2332 */
2333 mbuf = kmalloc(array_size, GFP_KERNEL);
2334 err = -ENOMEM;
2335 if (NULL == mbuf)
2336 goto out_array_args;
2337 err = -EFAULT;
2338 if (copy_from_user(mbuf, user_ptr, array_size))
2339 goto out_array_args;
2340 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002341 }
2342
2343 /* Handles IOCTL */
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002344 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002345 if (err == -ENOIOCTLCMD)
2346 err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002347
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002348 if (has_array_args) {
2349 *kernel_ptr = user_ptr;
2350 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002351 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002352 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002353 }
2354 if (err < 0)
2355 goto out;
2356
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002357out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002358 /* Copy results into user buffer */
2359 switch (_IOC_DIR(cmd)) {
2360 case _IOC_READ:
2361 case (_IOC_WRITE | _IOC_READ):
2362 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2363 err = -EFAULT;
2364 break;
2365 }
2366
2367out:
2368 kfree(mbuf);
2369 return err;
2370}
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002371EXPORT_SYMBOL(video_usercopy);
2372
2373long video_ioctl2(struct file *file,
2374 unsigned int cmd, unsigned long arg)
2375{
2376 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2377}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002378EXPORT_SYMBOL(video_ioctl2);