blob: 21c49dc064e2372cb037792a1ff4691ccdf0b3e6 [file] [log] [blame]
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001/*
2 * Video capture interface for Linux version 2
3 *
4 * A generic framework to process V4L2 ioctl commands.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
Alan Coxd9b01442008-10-27 15:13:47 -030011 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
Hans Verkuil35ea11f2008-07-20 08:12:02 -030012 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
13 */
14
15#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030017#include <linux/types.h>
18#include <linux/kernel.h>
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -030019#include <linux/version.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030020
Hans Verkuil35ea11f2008-07-20 08:12:02 -030021#include <linux/videodev2.h>
22
Hans Verkuil35ea11f2008-07-20 08:12:02 -030023#include <media/v4l2-common.h>
24#include <media/v4l2-ioctl.h>
Hans Verkuil11bbc1c2010-05-16 09:24:06 -030025#include <media/v4l2-ctrls.h>
Sakari Ailusd3d7c962010-03-27 11:02:10 -030026#include <media/v4l2-fh.h>
27#include <media/v4l2-event.h>
Hans Verkuil99cd47bc2011-03-11 19:00:56 -030028#include <media/v4l2-device.h>
Hans Verkuil80b36e02009-02-07 11:00:02 -030029#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030030
31#define dbgarg(cmd, fmt, arg...) \
32 do { \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
37 } \
38 } while (0)
39
40#define dbgarg2(fmt, arg...) \
41 do { \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
44 } while (0)
45
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030046#define dbgarg3(fmt, arg...) \
47 do { \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
50 } while (0)
51
Lucas De Marchi25985ed2011-03-30 22:57:33 -030052/* Zero out the end of the struct pointed to by p. Everything after, but
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030053 * not including, the specified field is cleared. */
54#define CLEAR_AFTER_FIELD(p, field) \
55 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
57
Hans Verkuil93d5a302011-08-09 09:32:06 -030058#define have_fmt_ops(foo) ( \
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -030059 ops->vidioc_##foo##_fmt_vid_cap || \
60 ops->vidioc_##foo##_fmt_vid_out || \
61 ops->vidioc_##foo##_fmt_vid_cap_mplane || \
62 ops->vidioc_##foo##_fmt_vid_out_mplane || \
63 ops->vidioc_##foo##_fmt_vid_overlay || \
Hans Verkuil93d5a302011-08-09 09:32:06 -030064 ops->vidioc_##foo##_fmt_vbi_cap || \
65 ops->vidioc_##foo##_fmt_vid_out_overlay || \
66 ops->vidioc_##foo##_fmt_vbi_out || \
67 ops->vidioc_##foo##_fmt_sliced_vbi_cap || \
68 ops->vidioc_##foo##_fmt_sliced_vbi_out || \
69 ops->vidioc_##foo##_fmt_type_private)
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -030070
Hans Verkuil35ea11f2008-07-20 08:12:02 -030071struct std_descr {
72 v4l2_std_id std;
73 const char *descr;
74};
75
76static const struct std_descr standards[] = {
77 { V4L2_STD_NTSC, "NTSC" },
78 { V4L2_STD_NTSC_M, "NTSC-M" },
79 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
80 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
81 { V4L2_STD_NTSC_443, "NTSC-443" },
82 { V4L2_STD_PAL, "PAL" },
83 { V4L2_STD_PAL_BG, "PAL-BG" },
84 { V4L2_STD_PAL_B, "PAL-B" },
85 { V4L2_STD_PAL_B1, "PAL-B1" },
86 { V4L2_STD_PAL_G, "PAL-G" },
87 { V4L2_STD_PAL_H, "PAL-H" },
88 { V4L2_STD_PAL_I, "PAL-I" },
89 { V4L2_STD_PAL_DK, "PAL-DK" },
90 { V4L2_STD_PAL_D, "PAL-D" },
91 { V4L2_STD_PAL_D1, "PAL-D1" },
92 { V4L2_STD_PAL_K, "PAL-K" },
93 { V4L2_STD_PAL_M, "PAL-M" },
94 { V4L2_STD_PAL_N, "PAL-N" },
95 { V4L2_STD_PAL_Nc, "PAL-Nc" },
96 { V4L2_STD_PAL_60, "PAL-60" },
97 { V4L2_STD_SECAM, "SECAM" },
98 { V4L2_STD_SECAM_B, "SECAM-B" },
99 { V4L2_STD_SECAM_G, "SECAM-G" },
100 { V4L2_STD_SECAM_H, "SECAM-H" },
101 { V4L2_STD_SECAM_DK, "SECAM-DK" },
102 { V4L2_STD_SECAM_D, "SECAM-D" },
103 { V4L2_STD_SECAM_K, "SECAM-K" },
104 { V4L2_STD_SECAM_K1, "SECAM-K1" },
105 { V4L2_STD_SECAM_L, "SECAM-L" },
106 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
107 { 0, "Unknown" }
108};
109
110/* video4linux standard ID conversion to standard name
111 */
112const char *v4l2_norm_to_name(v4l2_std_id id)
113{
114 u32 myid = id;
115 int i;
116
117 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
118 64 bit comparations. So, on that architecture, with some gcc
119 variants, compilation fails. Currently, the max value is 30bit wide.
120 */
121 BUG_ON(myid != id);
122
123 for (i = 0; standards[i].std; i++)
124 if (myid == standards[i].std)
125 break;
126 return standards[i].descr;
127}
128EXPORT_SYMBOL(v4l2_norm_to_name);
129
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300130/* Returns frame period for the given standard */
131void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
132{
133 if (id & V4L2_STD_525_60) {
134 frameperiod->numerator = 1001;
135 frameperiod->denominator = 30000;
136 } else {
137 frameperiod->numerator = 1;
138 frameperiod->denominator = 25;
139 }
140}
141EXPORT_SYMBOL(v4l2_video_std_frame_period);
142
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300143/* Fill in the fields of a v4l2_standard structure according to the
144 'id' and 'transmission' parameters. Returns negative on error. */
145int v4l2_video_std_construct(struct v4l2_standard *vs,
146 int id, const char *name)
147{
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300148 vs->id = id;
149 v4l2_video_std_frame_period(id, &vs->frameperiod);
150 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300151 strlcpy(vs->name, name, sizeof(vs->name));
152 return 0;
153}
154EXPORT_SYMBOL(v4l2_video_std_construct);
155
156/* ----------------------------------------------------------------- */
157/* some arrays for pretty-printing debug messages of enum types */
158
159const char *v4l2_field_names[] = {
160 [V4L2_FIELD_ANY] = "any",
161 [V4L2_FIELD_NONE] = "none",
162 [V4L2_FIELD_TOP] = "top",
163 [V4L2_FIELD_BOTTOM] = "bottom",
164 [V4L2_FIELD_INTERLACED] = "interlaced",
165 [V4L2_FIELD_SEQ_TB] = "seq-tb",
166 [V4L2_FIELD_SEQ_BT] = "seq-bt",
167 [V4L2_FIELD_ALTERNATE] = "alternate",
168 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
169 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
170};
171EXPORT_SYMBOL(v4l2_field_names);
172
173const char *v4l2_type_names[] = {
174 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
175 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
176 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
177 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
178 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
179 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
180 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
181 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
Pawel Osciakf8f39142010-07-29 14:44:25 -0300182 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
183 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300184};
185EXPORT_SYMBOL(v4l2_type_names);
186
187static const char *v4l2_memory_names[] = {
188 [V4L2_MEMORY_MMAP] = "mmap",
189 [V4L2_MEMORY_USERPTR] = "userptr",
190 [V4L2_MEMORY_OVERLAY] = "overlay",
191};
192
193#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
194 arr[a] : "unknown")
195
196/* ------------------------------------------------------------------ */
197/* debug help functions */
Hans Verkuil35ea11f2008-07-20 08:12:02 -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",
241 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
242 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
243 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
244 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
245 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
246 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
247 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
248 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
249 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
250 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
251 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
252 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
253 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
254#if 1
255 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
256 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
257 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
258 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
259 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
260
261 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
262 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
263
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300264 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300265 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
266#endif
Muralidharan Karicherib6456c02009-11-19 12:00:31 -0300267 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS)] = "VIDIOC_ENUM_DV_PRESETS",
268 [_IOC_NR(VIDIOC_S_DV_PRESET)] = "VIDIOC_S_DV_PRESET",
269 [_IOC_NR(VIDIOC_G_DV_PRESET)] = "VIDIOC_G_DV_PRESET",
270 [_IOC_NR(VIDIOC_QUERY_DV_PRESET)] = "VIDIOC_QUERY_DV_PRESET",
271 [_IOC_NR(VIDIOC_S_DV_TIMINGS)] = "VIDIOC_S_DV_TIMINGS",
272 [_IOC_NR(VIDIOC_G_DV_TIMINGS)] = "VIDIOC_G_DV_TIMINGS",
Sakari Ailusfda10212010-02-24 19:19:05 -0300273 [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
274 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
275 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300276};
277#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
278
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300279/* Common ioctl debug function. This function can be used by
280 external ioctl messages as well as internal V4L ioctl */
281void v4l_printk_ioctl(unsigned int cmd)
282{
283 char *dir, *type;
284
285 switch (_IOC_TYPE(cmd)) {
286 case 'd':
Hans Verkuil78a3b4d2009-04-01 03:41:09 -0300287 type = "v4l2_int";
288 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300289 case 'V':
290 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
291 type = "v4l2";
292 break;
293 }
294 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
295 return;
296 default:
297 type = "unknown";
298 }
299
300 switch (_IOC_DIR(cmd)) {
301 case _IOC_NONE: dir = "--"; break;
302 case _IOC_READ: dir = "r-"; break;
303 case _IOC_WRITE: dir = "-w"; break;
304 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
305 default: dir = "*ERR*"; break;
306 }
307 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
308 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
309}
310EXPORT_SYMBOL(v4l_printk_ioctl);
311
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300312static void dbgbuf(unsigned int cmd, struct video_device *vfd,
313 struct v4l2_buffer *p)
314{
315 struct v4l2_timecode *tc = &p->timecode;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300316 struct v4l2_plane *plane;
317 int i;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300318
319 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300320 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300321 p->timestamp.tv_sec / 3600,
322 (int)(p->timestamp.tv_sec / 60) % 60,
323 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300324 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300325 p->index,
326 prt_names(p->type, v4l2_type_names),
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300327 p->flags, p->field, p->sequence,
328 prt_names(p->memory, v4l2_memory_names));
329
330 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
331 for (i = 0; i < p->length; ++i) {
332 plane = &p->m.planes[i];
333 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
334 "offset/userptr=0x%08lx, length=%d\n",
335 i, plane->bytesused, plane->data_offset,
336 plane->m.userptr, plane->length);
337 }
338 } else {
339 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
340 p->bytesused, p->m.userptr, p->length);
341 }
342
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300343 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
344 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
345 tc->hours, tc->minutes, tc->seconds,
346 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
347}
348
349static inline void dbgrect(struct video_device *vfd, char *s,
350 struct v4l2_rect *r)
351{
352 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
353 r->width, r->height);
354};
355
356static inline void v4l_print_pix_fmt(struct video_device *vfd,
357 struct v4l2_pix_format *fmt)
358{
359 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
360 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
361 fmt->width, fmt->height,
362 (fmt->pixelformat & 0xff),
363 (fmt->pixelformat >> 8) & 0xff,
364 (fmt->pixelformat >> 16) & 0xff,
365 (fmt->pixelformat >> 24) & 0xff,
366 prt_names(fmt->field, v4l2_field_names),
367 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
368};
369
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300370static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
371 struct v4l2_pix_format_mplane *fmt)
372{
373 int i;
374
375 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
376 "colorspace=%d, num_planes=%d\n",
377 fmt->width, fmt->height,
378 (fmt->pixelformat & 0xff),
379 (fmt->pixelformat >> 8) & 0xff,
380 (fmt->pixelformat >> 16) & 0xff,
381 (fmt->pixelformat >> 24) & 0xff,
382 prt_names(fmt->field, v4l2_field_names),
383 fmt->colorspace, fmt->num_planes);
384
385 for (i = 0; i < fmt->num_planes; ++i)
386 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
387 fmt->plane_fmt[i].bytesperline,
388 fmt->plane_fmt[i].sizeimage);
389}
390
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300391static inline void v4l_print_ext_ctrls(unsigned int cmd,
392 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
393{
394 __u32 i;
395
396 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
397 return;
398 dbgarg(cmd, "");
399 printk(KERN_CONT "class=0x%x", c->ctrl_class);
400 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300401 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300402 printk(KERN_CONT " id/val=0x%x/0x%x",
403 c->controls[i].id, c->controls[i].value);
404 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300405 printk(KERN_CONT " id=0x%x,size=%u",
406 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300407 }
408 printk(KERN_CONT "\n");
409};
410
411static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
412{
413 __u32 i;
414
415 /* zero the reserved fields */
416 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300417 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300418 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300419
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300420 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
421 when using extended controls.
422 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
423 is it allowed for backwards compatibility.
424 */
425 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
426 return 0;
427 /* Check that all controls are from the same control class. */
428 for (i = 0; i < c->count; i++) {
429 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
430 c->error_idx = i;
431 return 0;
432 }
433 }
434 return 1;
435}
436
Hans Verkuila3998102008-07-21 02:57:38 -0300437static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300438{
Hans Verkuila3998102008-07-21 02:57:38 -0300439 if (ops == NULL)
440 return -EINVAL;
441
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300442 switch (type) {
443 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300444 if (ops->vidioc_g_fmt_vid_cap ||
445 ops->vidioc_g_fmt_vid_cap_mplane)
446 return 0;
447 break;
448 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
449 if (ops->vidioc_g_fmt_vid_cap_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300450 return 0;
451 break;
452 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300453 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300454 return 0;
455 break;
456 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300457 if (ops->vidioc_g_fmt_vid_out ||
458 ops->vidioc_g_fmt_vid_out_mplane)
459 return 0;
460 break;
461 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
462 if (ops->vidioc_g_fmt_vid_out_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300463 return 0;
464 break;
465 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300466 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300467 return 0;
468 break;
469 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300470 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300471 return 0;
472 break;
473 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300474 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300475 return 0;
476 break;
477 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300478 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300479 return 0;
480 break;
481 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300482 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300483 return 0;
484 break;
485 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300486 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300487 return 0;
488 break;
489 }
490 return -EINVAL;
491}
492
Hans Verkuil069b7472008-12-30 07:04:34 -0300493static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300494 unsigned int cmd, void *arg)
495{
496 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300497 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300498 void *fh = file->private_data;
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300499 struct v4l2_fh *vfh = NULL;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300500 int use_fh_prio = 0;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300501 long ret_prio = 0;
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300502 long ret = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300503
Hans Verkuil6a717882010-04-06 15:56:08 -0300504 if (ops == NULL) {
505 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
506 vfd->name);
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300507 return ret;
Hans Verkuil6a717882010-04-06 15:56:08 -0300508 }
509
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300510 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
511 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
512 v4l_print_ioctl(vfd->name, cmd);
513 printk(KERN_CONT "\n");
514 }
515
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300516 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300517 vfh = file->private_data;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300518 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
519 }
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300520
Hans Verkuil93d5a302011-08-09 09:32:06 -0300521 if (use_fh_prio)
522 ret_prio = v4l2_prio_check(vfd->prio, vfh->prio);
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300523
Hans Verkuil6a717882010-04-06 15:56:08 -0300524 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300525
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300526 /* --- capabilities ------------------------------------------ */
527 case VIDIOC_QUERYCAP:
528 {
529 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300530
Hans Verkuila3998102008-07-21 02:57:38 -0300531 if (!ops->vidioc_querycap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300532 break;
533
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -0300534 cap->version = LINUX_VERSION_CODE;
Hans Verkuila3998102008-07-21 02:57:38 -0300535 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300536 if (!ret)
537 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
538 "version=0x%08x, "
539 "capabilities=0x%08x\n",
540 cap->driver, cap->card, cap->bus_info,
541 cap->version,
542 cap->capabilities);
543 break;
544 }
545
546 /* --- priority ------------------------------------------ */
547 case VIDIOC_G_PRIORITY:
548 {
549 enum v4l2_priority *p = arg;
550
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300551 if (ops->vidioc_g_priority) {
552 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300553 } else if (use_fh_prio) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300554 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
555 ret = 0;
556 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300557 if (!ret)
558 dbgarg(cmd, "priority is %d\n", *p);
559 break;
560 }
561 case VIDIOC_S_PRIORITY:
562 {
563 enum v4l2_priority *p = arg;
564
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300565 if (!ops->vidioc_s_priority && !use_fh_prio)
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300566 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300567 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300568 if (ops->vidioc_s_priority)
569 ret = ops->vidioc_s_priority(file, fh, *p);
570 else
Hans Verkuil93d5a302011-08-09 09:32:06 -0300571 ret = ret_prio ? ret_prio :
572 v4l2_prio_change(&vfd->v4l2_dev->prio,
573 &vfh->prio, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300574 break;
575 }
576
577 /* --- capture ioctls ---------------------------------------- */
578 case VIDIOC_ENUM_FMT:
579 {
580 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300581
Trent Piepho19c96e42009-03-04 01:21:02 -0300582 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300583 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300584 if (likely(ops->vidioc_enum_fmt_vid_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300585 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300586 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300587 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300588 if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300589 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
590 fh, f);
591 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300592 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300593 if (likely(ops->vidioc_enum_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300594 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300595 fh, f);
596 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300597 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300598 if (likely(ops->vidioc_enum_fmt_vid_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300599 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300600 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300601 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300602 if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300603 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
604 fh, f);
605 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300606 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300607 if (likely(ops->vidioc_enum_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300608 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300609 fh, f);
610 break;
611 default:
612 break;
613 }
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300614 if (likely (!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300615 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
616 "pixelformat=%c%c%c%c, description='%s'\n",
617 f->index, f->type, f->flags,
618 (f->pixelformat & 0xff),
619 (f->pixelformat >> 8) & 0xff,
620 (f->pixelformat >> 16) & 0xff,
621 (f->pixelformat >> 24) & 0xff,
622 f->description);
Hans Verkuil93d5a302011-08-09 09:32:06 -0300623 else if (ret == -ENOTTY &&
624 (ops->vidioc_enum_fmt_vid_cap ||
625 ops->vidioc_enum_fmt_vid_out ||
626 ops->vidioc_enum_fmt_vid_cap_mplane ||
627 ops->vidioc_enum_fmt_vid_out_mplane ||
628 ops->vidioc_enum_fmt_vid_overlay ||
629 ops->vidioc_enum_fmt_type_private))
630 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300631 break;
632 }
633 case VIDIOC_G_FMT:
634 {
635 struct v4l2_format *f = (struct v4l2_format *)arg;
636
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300637 /* FIXME: Should be one dump per type */
638 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
639
640 switch (f->type) {
641 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300642 if (ops->vidioc_g_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300643 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300644 if (!ret)
645 v4l_print_pix_fmt(vfd, &f->fmt.pix);
646 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300647 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300648 if (ops->vidioc_g_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300649 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
650 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300651 if (!ret)
652 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
653 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300654 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300655 if (likely(ops->vidioc_g_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300656 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300657 fh, f);
658 break;
659 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300660 if (ops->vidioc_g_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300661 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300662 if (!ret)
663 v4l_print_pix_fmt(vfd, &f->fmt.pix);
664 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300665 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300666 if (ops->vidioc_g_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300667 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
668 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300669 if (!ret)
670 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
671 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300672 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300673 if (likely(ops->vidioc_g_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300674 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300675 fh, f);
676 break;
677 case V4L2_BUF_TYPE_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300678 if (likely(ops->vidioc_g_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300679 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300680 break;
681 case V4L2_BUF_TYPE_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300682 if (likely(ops->vidioc_g_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300683 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300684 break;
685 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300686 if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300687 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300688 fh, f);
689 break;
690 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300691 if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300692 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300693 fh, f);
694 break;
695 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300696 if (likely(ops->vidioc_g_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300697 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300698 fh, f);
699 break;
700 }
Hans Verkuil93d5a302011-08-09 09:32:06 -0300701 if (unlikely(ret == -ENOTTY && have_fmt_ops(g)))
702 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300703
704 break;
705 }
706 case VIDIOC_S_FMT:
707 {
708 struct v4l2_format *f = (struct v4l2_format *)arg;
709
Hans Verkuil93d5a302011-08-09 09:32:06 -0300710 if (!have_fmt_ops(s))
711 break;
712 if (ret_prio) {
713 ret = ret_prio;
714 break;
715 }
716 ret = -EINVAL;
717
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300718 /* FIXME: Should be one dump per type */
719 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
720
721 switch (f->type) {
722 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300723 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300724 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300725 if (ops->vidioc_s_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300726 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300727 break;
728 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
729 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
730 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300731 if (ops->vidioc_s_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300732 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
733 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300734 break;
735 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300736 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300737 if (ops->vidioc_s_fmt_vid_overlay)
738 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300739 fh, f);
740 break;
741 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300742 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300743 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300744 if (ops->vidioc_s_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300745 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300746 break;
747 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
748 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
749 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300750 if (ops->vidioc_s_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300751 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
752 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300753 break;
754 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300755 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300756 if (ops->vidioc_s_fmt_vid_out_overlay)
757 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300758 fh, f);
759 break;
760 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300761 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300762 if (likely(ops->vidioc_s_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300763 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300764 break;
765 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300766 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300767 if (likely(ops->vidioc_s_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300768 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300769 break;
770 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300771 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300772 if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300773 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300774 fh, f);
775 break;
776 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300777 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300778 if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300779 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300780 fh, f);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300781
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300782 break;
783 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300784 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300785 if (likely(ops->vidioc_s_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300786 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300787 fh, f);
788 break;
789 }
790 break;
791 }
792 case VIDIOC_TRY_FMT:
793 {
794 struct v4l2_format *f = (struct v4l2_format *)arg;
795
796 /* FIXME: Should be one dump per type */
797 dbgarg(cmd, "type=%s\n", prt_names(f->type,
798 v4l2_type_names));
799 switch (f->type) {
800 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300801 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300802 if (ops->vidioc_try_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300803 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300804 if (!ret)
805 v4l_print_pix_fmt(vfd, &f->fmt.pix);
806 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300807 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
808 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300809 if (ops->vidioc_try_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300810 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
811 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300812 if (!ret)
813 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
814 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300815 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300816 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300817 if (likely(ops->vidioc_try_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300818 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300819 fh, f);
820 break;
821 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300822 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300823 if (ops->vidioc_try_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300824 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300825 if (!ret)
826 v4l_print_pix_fmt(vfd, &f->fmt.pix);
827 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300828 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
829 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300830 if (ops->vidioc_try_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300831 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
832 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300833 if (!ret)
834 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
835 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300836 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300837 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300838 if (likely(ops->vidioc_try_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300839 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300840 fh, f);
841 break;
842 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300843 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300844 if (likely(ops->vidioc_try_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300845 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300846 break;
847 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300848 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300849 if (likely(ops->vidioc_try_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300850 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300851 break;
852 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300853 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300854 if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300855 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300856 fh, f);
857 break;
858 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300859 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300860 if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300861 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300862 fh, f);
863 break;
864 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300865 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300866 if (likely(ops->vidioc_try_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300867 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300868 fh, f);
869 break;
870 }
Hans Verkuil93d5a302011-08-09 09:32:06 -0300871 if (unlikely(ret == -ENOTTY && have_fmt_ops(try)))
872 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300873 break;
874 }
875 /* FIXME: Those buf reqs could be handled here,
876 with some changes on videobuf to allow its header to be included at
877 videodev2.h or being merged at videodev2.
878 */
879 case VIDIOC_REQBUFS:
880 {
881 struct v4l2_requestbuffers *p = arg;
882
Hans Verkuila3998102008-07-21 02:57:38 -0300883 if (!ops->vidioc_reqbufs)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300884 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300885 if (ret_prio) {
886 ret = ret_prio;
887 break;
888 }
Hans Verkuila3998102008-07-21 02:57:38 -0300889 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300890 if (ret)
891 break;
892
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300893 if (p->type < V4L2_BUF_TYPE_PRIVATE)
894 CLEAR_AFTER_FIELD(p, memory);
895
Hans Verkuila3998102008-07-21 02:57:38 -0300896 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300897 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
898 p->count,
899 prt_names(p->type, v4l2_type_names),
900 prt_names(p->memory, v4l2_memory_names));
901 break;
902 }
903 case VIDIOC_QUERYBUF:
904 {
905 struct v4l2_buffer *p = arg;
906
Hans Verkuila3998102008-07-21 02:57:38 -0300907 if (!ops->vidioc_querybuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300908 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300909 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300910 if (ret)
911 break;
912
Hans Verkuila3998102008-07-21 02:57:38 -0300913 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300914 if (!ret)
915 dbgbuf(cmd, vfd, p);
916 break;
917 }
918 case VIDIOC_QBUF:
919 {
920 struct v4l2_buffer *p = arg;
921
Hans Verkuila3998102008-07-21 02:57:38 -0300922 if (!ops->vidioc_qbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300923 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300924 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300925 if (ret)
926 break;
927
Hans Verkuila3998102008-07-21 02:57:38 -0300928 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300929 if (!ret)
930 dbgbuf(cmd, vfd, p);
931 break;
932 }
933 case VIDIOC_DQBUF:
934 {
935 struct v4l2_buffer *p = arg;
936
Hans Verkuila3998102008-07-21 02:57:38 -0300937 if (!ops->vidioc_dqbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300938 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300939 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300940 if (ret)
941 break;
942
Hans Verkuila3998102008-07-21 02:57:38 -0300943 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300944 if (!ret)
945 dbgbuf(cmd, vfd, p);
946 break;
947 }
948 case VIDIOC_OVERLAY:
949 {
950 int *i = arg;
951
Hans Verkuila3998102008-07-21 02:57:38 -0300952 if (!ops->vidioc_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300953 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300954 if (ret_prio) {
955 ret = ret_prio;
956 break;
957 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300958 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -0300959 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300960 break;
961 }
962 case VIDIOC_G_FBUF:
963 {
964 struct v4l2_framebuffer *p = arg;
965
Hans Verkuila3998102008-07-21 02:57:38 -0300966 if (!ops->vidioc_g_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300967 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300968 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300969 if (!ret) {
970 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
971 p->capability, p->flags,
972 (unsigned long)p->base);
973 v4l_print_pix_fmt(vfd, &p->fmt);
974 }
975 break;
976 }
977 case VIDIOC_S_FBUF:
978 {
979 struct v4l2_framebuffer *p = arg;
980
Hans Verkuila3998102008-07-21 02:57:38 -0300981 if (!ops->vidioc_s_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300982 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300983 if (ret_prio) {
984 ret = ret_prio;
985 break;
986 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300987 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
988 p->capability, p->flags, (unsigned long)p->base);
989 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -0300990 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300991 break;
992 }
993 case VIDIOC_STREAMON:
994 {
995 enum v4l2_buf_type i = *(int *)arg;
996
Hans Verkuila3998102008-07-21 02:57:38 -0300997 if (!ops->vidioc_streamon)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300998 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300999 if (ret_prio) {
1000 ret = ret_prio;
1001 break;
1002 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001003 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001004 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001005 break;
1006 }
1007 case VIDIOC_STREAMOFF:
1008 {
1009 enum v4l2_buf_type i = *(int *)arg;
1010
Hans Verkuila3998102008-07-21 02:57:38 -03001011 if (!ops->vidioc_streamoff)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001012 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001013 if (ret_prio) {
1014 ret = ret_prio;
1015 break;
1016 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001017 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001018 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001019 break;
1020 }
1021 /* ---------- tv norms ---------- */
1022 case VIDIOC_ENUMSTD:
1023 {
1024 struct v4l2_standard *p = arg;
1025 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1026 unsigned int index = p->index, i, j = 0;
1027 const char *descr = "";
1028
Hans Verkuil93d5a302011-08-09 09:32:06 -03001029 if (id == 0)
1030 break;
1031 ret = -EINVAL;
1032
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001033 /* Return norm array in a canonical way */
1034 for (i = 0; i <= index && id; i++) {
1035 /* last std value in the standards array is 0, so this
1036 while always ends there since (id & 0) == 0. */
1037 while ((id & standards[j].std) != standards[j].std)
1038 j++;
1039 curr_id = standards[j].std;
1040 descr = standards[j].descr;
1041 j++;
1042 if (curr_id == 0)
1043 break;
1044 if (curr_id != V4L2_STD_PAL &&
1045 curr_id != V4L2_STD_SECAM &&
1046 curr_id != V4L2_STD_NTSC)
1047 id &= ~curr_id;
1048 }
1049 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001050 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001051
1052 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001053
1054 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1055 "framelines=%d\n", p->index,
1056 (unsigned long long)p->id, p->name,
1057 p->frameperiod.numerator,
1058 p->frameperiod.denominator,
1059 p->framelines);
1060
1061 ret = 0;
1062 break;
1063 }
1064 case VIDIOC_G_STD:
1065 {
1066 v4l2_std_id *id = arg;
1067
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001068 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001069 if (ops->vidioc_g_std)
1070 ret = ops->vidioc_g_std(file, fh, id);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001071 else if (vfd->current_norm) {
1072 ret = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001073 *id = vfd->current_norm;
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001074 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001075
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001076 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001077 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1078 break;
1079 }
1080 case VIDIOC_S_STD:
1081 {
1082 v4l2_std_id *id = arg, norm;
1083
1084 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1085
Hans Verkuil93d5a302011-08-09 09:32:06 -03001086 if (!ops->vidioc_s_std)
1087 break;
1088
1089 if (ret_prio) {
1090 ret = ret_prio;
1091 break;
1092 }
1093 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001094 norm = (*id) & vfd->tvnorms;
1095 if (vfd->tvnorms && !norm) /* Check if std is supported */
1096 break;
1097
1098 /* Calls the specific handler */
Hans Verkuil93d5a302011-08-09 09:32:06 -03001099 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001100
1101 /* Updates standard information */
1102 if (ret >= 0)
1103 vfd->current_norm = norm;
1104 break;
1105 }
1106 case VIDIOC_QUERYSTD:
1107 {
1108 v4l2_std_id *p = arg;
1109
Hans Verkuila3998102008-07-21 02:57:38 -03001110 if (!ops->vidioc_querystd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001111 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001112 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001113 if (!ret)
1114 dbgarg(cmd, "detected std=%08Lx\n",
1115 (unsigned long long)*p);
1116 break;
1117 }
1118 /* ------ input switching ---------- */
1119 /* FIXME: Inputs can be handled inside videodev2 */
1120 case VIDIOC_ENUMINPUT:
1121 {
1122 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001123
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001124 /*
1125 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1126 * CAP_STD here based on ioctl handler provided by the
1127 * driver. If the driver doesn't support these
1128 * for a specific input, it must override these flags.
1129 */
1130 if (ops->vidioc_s_std)
1131 p->capabilities |= V4L2_IN_CAP_STD;
1132 if (ops->vidioc_s_dv_preset)
1133 p->capabilities |= V4L2_IN_CAP_PRESETS;
1134 if (ops->vidioc_s_dv_timings)
1135 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1136
Hans Verkuila3998102008-07-21 02:57:38 -03001137 if (!ops->vidioc_enum_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001138 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001139
Hans Verkuila3998102008-07-21 02:57:38 -03001140 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001141 if (!ret)
1142 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1143 "audioset=%d, "
1144 "tuner=%d, std=%08Lx, status=%d\n",
1145 p->index, p->name, p->type, p->audioset,
1146 p->tuner,
1147 (unsigned long long)p->std,
1148 p->status);
1149 break;
1150 }
1151 case VIDIOC_G_INPUT:
1152 {
1153 unsigned int *i = arg;
1154
Hans Verkuila3998102008-07-21 02:57:38 -03001155 if (!ops->vidioc_g_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001156 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001157 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001158 if (!ret)
1159 dbgarg(cmd, "value=%d\n", *i);
1160 break;
1161 }
1162 case VIDIOC_S_INPUT:
1163 {
1164 unsigned int *i = arg;
1165
Hans Verkuila3998102008-07-21 02:57:38 -03001166 if (!ops->vidioc_s_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001167 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001168 if (ret_prio) {
1169 ret = ret_prio;
1170 break;
1171 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001172 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001173 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001174 break;
1175 }
1176
1177 /* ------ output switching ---------- */
1178 case VIDIOC_ENUMOUTPUT:
1179 {
1180 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001181
Hans Verkuila3998102008-07-21 02:57:38 -03001182 if (!ops->vidioc_enum_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001183 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001184
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001185 /*
1186 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1187 * CAP_STD here based on ioctl handler provided by the
1188 * driver. If the driver doesn't support these
1189 * for a specific output, it must override these flags.
1190 */
1191 if (ops->vidioc_s_std)
1192 p->capabilities |= V4L2_OUT_CAP_STD;
1193 if (ops->vidioc_s_dv_preset)
1194 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1195 if (ops->vidioc_s_dv_timings)
1196 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1197
Hans Verkuila3998102008-07-21 02:57:38 -03001198 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001199 if (!ret)
1200 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1201 "audioset=0x%x, "
1202 "modulator=%d, std=0x%08Lx\n",
1203 p->index, p->name, p->type, p->audioset,
1204 p->modulator, (unsigned long long)p->std);
1205 break;
1206 }
1207 case VIDIOC_G_OUTPUT:
1208 {
1209 unsigned int *i = arg;
1210
Hans Verkuila3998102008-07-21 02:57:38 -03001211 if (!ops->vidioc_g_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001212 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001213 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001214 if (!ret)
1215 dbgarg(cmd, "value=%d\n", *i);
1216 break;
1217 }
1218 case VIDIOC_S_OUTPUT:
1219 {
1220 unsigned int *i = arg;
1221
Hans Verkuila3998102008-07-21 02:57:38 -03001222 if (!ops->vidioc_s_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001223 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001224 if (ret_prio) {
1225 ret = ret_prio;
1226 break;
1227 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001228 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001229 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001230 break;
1231 }
1232
1233 /* --- controls ---------------------------------------------- */
1234 case VIDIOC_QUERYCTRL:
1235 {
1236 struct v4l2_queryctrl *p = arg;
1237
Hans Verkuil2d28b682011-03-12 08:54:43 -03001238 if (vfh && vfh->ctrl_handler)
1239 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1240 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001241 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1242 else if (ops->vidioc_queryctrl)
1243 ret = ops->vidioc_queryctrl(file, fh, p);
1244 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001245 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001246 if (!ret)
1247 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1248 "step=%d, default=%d, flags=0x%08x\n",
1249 p->id, p->type, p->name,
1250 p->minimum, p->maximum,
1251 p->step, p->default_value, p->flags);
1252 else
1253 dbgarg(cmd, "id=0x%x\n", p->id);
1254 break;
1255 }
1256 case VIDIOC_G_CTRL:
1257 {
1258 struct v4l2_control *p = arg;
1259
Hans Verkuil2d28b682011-03-12 08:54:43 -03001260 if (vfh && vfh->ctrl_handler)
1261 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1262 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001263 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1264 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001265 ret = ops->vidioc_g_ctrl(file, fh, p);
1266 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001267 struct v4l2_ext_controls ctrls;
1268 struct v4l2_ext_control ctrl;
1269
1270 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1271 ctrls.count = 1;
1272 ctrls.controls = &ctrl;
1273 ctrl.id = p->id;
1274 ctrl.value = p->value;
1275 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001276 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001277 if (ret == 0)
1278 p->value = ctrl.value;
1279 }
1280 } else
1281 break;
1282 if (!ret)
1283 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1284 else
1285 dbgarg(cmd, "id=0x%x\n", p->id);
1286 break;
1287 }
1288 case VIDIOC_S_CTRL:
1289 {
1290 struct v4l2_control *p = arg;
1291 struct v4l2_ext_controls ctrls;
1292 struct v4l2_ext_control ctrl;
1293
Hans Verkuil2d28b682011-03-12 08:54:43 -03001294 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001295 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001296 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001297 if (ret_prio) {
1298 ret = ret_prio;
1299 break;
1300 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001301
1302 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1303
Hans Verkuil2d28b682011-03-12 08:54:43 -03001304 if (vfh && vfh->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001305 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001306 break;
1307 }
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001308 if (vfd->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001309 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001310 break;
1311 }
Hans Verkuila3998102008-07-21 02:57:38 -03001312 if (ops->vidioc_s_ctrl) {
1313 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001314 break;
1315 }
Hans Verkuila3998102008-07-21 02:57:38 -03001316 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001317 break;
1318
1319 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1320 ctrls.count = 1;
1321 ctrls.controls = &ctrl;
1322 ctrl.id = p->id;
1323 ctrl.value = p->value;
1324 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001325 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001326 else
1327 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001328 break;
1329 }
1330 case VIDIOC_G_EXT_CTRLS:
1331 {
1332 struct v4l2_ext_controls *p = arg;
1333
1334 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001335 if (vfh && vfh->ctrl_handler)
1336 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1337 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001338 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001339 else if (ops->vidioc_g_ext_ctrls)
1340 ret = check_ext_ctrls(p, 0) ?
1341 ops->vidioc_g_ext_ctrls(file, fh, p) :
1342 -EINVAL;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001343 else
1344 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001345 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1346 break;
1347 }
1348 case VIDIOC_S_EXT_CTRLS:
1349 {
1350 struct v4l2_ext_controls *p = arg;
1351
1352 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001353 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1354 !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001355 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001356 if (ret_prio) {
1357 ret = ret_prio;
1358 break;
1359 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001360 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001361 if (vfh && vfh->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001362 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001363 else if (vfd->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001364 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001365 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001366 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001367 else
1368 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001369 break;
1370 }
1371 case VIDIOC_TRY_EXT_CTRLS:
1372 {
1373 struct v4l2_ext_controls *p = arg;
1374
1375 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001376 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1377 !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001378 break;
1379 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001380 if (vfh && vfh->ctrl_handler)
1381 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1382 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001383 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1384 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001385 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001386 else
1387 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001388 break;
1389 }
1390 case VIDIOC_QUERYMENU:
1391 {
1392 struct v4l2_querymenu *p = arg;
1393
Hans Verkuil2d28b682011-03-12 08:54:43 -03001394 if (vfh && vfh->ctrl_handler)
1395 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1396 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001397 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1398 else if (ops->vidioc_querymenu)
1399 ret = ops->vidioc_querymenu(file, fh, p);
1400 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001401 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001402 if (!ret)
1403 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1404 p->id, p->index, p->name);
1405 else
1406 dbgarg(cmd, "id=0x%x, index=%d\n",
1407 p->id, p->index);
1408 break;
1409 }
1410 /* --- audio ---------------------------------------------- */
1411 case VIDIOC_ENUMAUDIO:
1412 {
1413 struct v4l2_audio *p = arg;
1414
Hans Verkuila3998102008-07-21 02:57:38 -03001415 if (!ops->vidioc_enumaudio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001416 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001417 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001418 if (!ret)
1419 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1420 "mode=0x%x\n", p->index, p->name,
1421 p->capability, p->mode);
1422 else
1423 dbgarg(cmd, "index=%d\n", p->index);
1424 break;
1425 }
1426 case VIDIOC_G_AUDIO:
1427 {
1428 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001429
Hans Verkuila3998102008-07-21 02:57:38 -03001430 if (!ops->vidioc_g_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001431 break;
1432
Hans Verkuila3998102008-07-21 02:57:38 -03001433 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001434 if (!ret)
1435 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1436 "mode=0x%x\n", p->index,
1437 p->name, p->capability, p->mode);
1438 else
1439 dbgarg(cmd, "index=%d\n", p->index);
1440 break;
1441 }
1442 case VIDIOC_S_AUDIO:
1443 {
1444 struct v4l2_audio *p = arg;
1445
Hans Verkuila3998102008-07-21 02:57:38 -03001446 if (!ops->vidioc_s_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001447 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001448 if (ret_prio) {
1449 ret = ret_prio;
1450 break;
1451 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001452 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1453 "mode=0x%x\n", p->index, p->name,
1454 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001455 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001456 break;
1457 }
1458 case VIDIOC_ENUMAUDOUT:
1459 {
1460 struct v4l2_audioout *p = arg;
1461
Hans Verkuila3998102008-07-21 02:57:38 -03001462 if (!ops->vidioc_enumaudout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001463 break;
1464 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001465 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001466 if (!ret)
1467 dbgarg2("index=%d, name=%s, capability=%d, "
1468 "mode=%d\n", p->index, p->name,
1469 p->capability, p->mode);
1470 break;
1471 }
1472 case VIDIOC_G_AUDOUT:
1473 {
1474 struct v4l2_audioout *p = arg;
1475
Hans Verkuila3998102008-07-21 02:57:38 -03001476 if (!ops->vidioc_g_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001477 break;
Trent Piepho337f9d22009-03-04 01:21:02 -03001478
Hans Verkuila3998102008-07-21 02:57:38 -03001479 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001480 if (!ret)
1481 dbgarg2("index=%d, name=%s, capability=%d, "
1482 "mode=%d\n", p->index, p->name,
1483 p->capability, p->mode);
1484 break;
1485 }
1486 case VIDIOC_S_AUDOUT:
1487 {
1488 struct v4l2_audioout *p = arg;
1489
Hans Verkuila3998102008-07-21 02:57:38 -03001490 if (!ops->vidioc_s_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001491 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001492 if (ret_prio) {
1493 ret = ret_prio;
1494 break;
1495 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001496 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1497 "mode=%d\n", p->index, p->name,
1498 p->capability, p->mode);
1499
Hans Verkuila3998102008-07-21 02:57:38 -03001500 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001501 break;
1502 }
1503 case VIDIOC_G_MODULATOR:
1504 {
1505 struct v4l2_modulator *p = arg;
1506
Hans Verkuila3998102008-07-21 02:57:38 -03001507 if (!ops->vidioc_g_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001508 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001509 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001510 if (!ret)
1511 dbgarg(cmd, "index=%d, name=%s, "
1512 "capability=%d, rangelow=%d,"
1513 " rangehigh=%d, txsubchans=%d\n",
1514 p->index, p->name, p->capability,
1515 p->rangelow, p->rangehigh,
1516 p->txsubchans);
1517 break;
1518 }
1519 case VIDIOC_S_MODULATOR:
1520 {
1521 struct v4l2_modulator *p = arg;
1522
Hans Verkuila3998102008-07-21 02:57:38 -03001523 if (!ops->vidioc_s_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001524 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001525 if (ret_prio) {
1526 ret = ret_prio;
1527 break;
1528 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001529 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1530 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1531 p->index, p->name, p->capability, p->rangelow,
1532 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001533 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001534 break;
1535 }
1536 case VIDIOC_G_CROP:
1537 {
1538 struct v4l2_crop *p = arg;
1539
Hans Verkuila3998102008-07-21 02:57:38 -03001540 if (!ops->vidioc_g_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001541 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001542
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001543 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001544 ret = ops->vidioc_g_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001545 if (!ret)
1546 dbgrect(vfd, "", &p->c);
1547 break;
1548 }
1549 case VIDIOC_S_CROP:
1550 {
1551 struct v4l2_crop *p = arg;
1552
Hans Verkuila3998102008-07-21 02:57:38 -03001553 if (!ops->vidioc_s_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001554 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001555 if (ret_prio) {
1556 ret = ret_prio;
1557 break;
1558 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001559 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1560 dbgrect(vfd, "", &p->c);
Hans Verkuila3998102008-07-21 02:57:38 -03001561 ret = ops->vidioc_s_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001562 break;
1563 }
1564 case VIDIOC_CROPCAP:
1565 {
1566 struct v4l2_cropcap *p = arg;
1567
1568 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuila3998102008-07-21 02:57:38 -03001569 if (!ops->vidioc_cropcap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001570 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001571
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001572 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001573 ret = ops->vidioc_cropcap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001574 if (!ret) {
1575 dbgrect(vfd, "bounds ", &p->bounds);
1576 dbgrect(vfd, "defrect ", &p->defrect);
1577 }
1578 break;
1579 }
1580 case VIDIOC_G_JPEGCOMP:
1581 {
1582 struct v4l2_jpegcompression *p = arg;
1583
Hans Verkuila3998102008-07-21 02:57:38 -03001584 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001585 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001586
Hans Verkuila3998102008-07-21 02:57:38 -03001587 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001588 if (!ret)
1589 dbgarg(cmd, "quality=%d, APPn=%d, "
1590 "APP_len=%d, COM_len=%d, "
1591 "jpeg_markers=%d\n",
1592 p->quality, p->APPn, p->APP_len,
1593 p->COM_len, p->jpeg_markers);
1594 break;
1595 }
1596 case VIDIOC_S_JPEGCOMP:
1597 {
1598 struct v4l2_jpegcompression *p = arg;
1599
Hans Verkuila3998102008-07-21 02:57:38 -03001600 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001601 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001602 if (ret_prio) {
1603 ret = ret_prio;
1604 break;
1605 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001606 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1607 "COM_len=%d, jpeg_markers=%d\n",
1608 p->quality, p->APPn, p->APP_len,
1609 p->COM_len, p->jpeg_markers);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001610 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001611 break;
1612 }
1613 case VIDIOC_G_ENC_INDEX:
1614 {
1615 struct v4l2_enc_idx *p = arg;
1616
Hans Verkuila3998102008-07-21 02:57:38 -03001617 if (!ops->vidioc_g_enc_index)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001618 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001619 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001620 if (!ret)
1621 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1622 p->entries, p->entries_cap);
1623 break;
1624 }
1625 case VIDIOC_ENCODER_CMD:
1626 {
1627 struct v4l2_encoder_cmd *p = arg;
1628
Hans Verkuila3998102008-07-21 02:57:38 -03001629 if (!ops->vidioc_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001630 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001631 if (ret_prio) {
1632 ret = ret_prio;
1633 break;
1634 }
Hans Verkuila3998102008-07-21 02:57:38 -03001635 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001636 if (!ret)
1637 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1638 break;
1639 }
1640 case VIDIOC_TRY_ENCODER_CMD:
1641 {
1642 struct v4l2_encoder_cmd *p = arg;
1643
Hans Verkuila3998102008-07-21 02:57:38 -03001644 if (!ops->vidioc_try_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001645 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001646 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001647 if (!ret)
1648 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1649 break;
1650 }
1651 case VIDIOC_G_PARM:
1652 {
1653 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001654
Hans Verkuil93d5a302011-08-09 09:32:06 -03001655 if (!ops->vidioc_g_parm && !vfd->current_norm)
1656 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001657 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001658 ret = check_fmt(ops, p->type);
1659 if (ret)
1660 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001661 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001662 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001663 v4l2_std_id std = vfd->current_norm;
1664
Hans Verkuil93d5a302011-08-09 09:32:06 -03001665 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001666 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001667 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001668
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001669 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001670 if (ops->vidioc_g_std)
1671 ret = ops->vidioc_g_std(file, fh, &std);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001672 if (ret == 0)
1673 v4l2_video_std_frame_period(std,
1674 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001675 }
1676
1677 dbgarg(cmd, "type=%d\n", p->type);
1678 break;
1679 }
1680 case VIDIOC_S_PARM:
1681 {
1682 struct v4l2_streamparm *p = arg;
1683
Hans Verkuila3998102008-07-21 02:57:38 -03001684 if (!ops->vidioc_s_parm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001685 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001686 if (ret_prio) {
1687 ret = ret_prio;
1688 break;
1689 }
Trent Piepho34796bc2009-03-28 22:25:35 -03001690 ret = check_fmt(ops, p->type);
1691 if (ret)
1692 break;
1693
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001694 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001695 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001696 break;
1697 }
1698 case VIDIOC_G_TUNER:
1699 {
1700 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001701
Hans Verkuila3998102008-07-21 02:57:38 -03001702 if (!ops->vidioc_g_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001703 break;
1704
Hans Verkuil227690d2011-06-12 06:36:41 -03001705 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1706 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001707 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001708 if (!ret)
1709 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1710 "capability=0x%x, rangelow=%d, "
1711 "rangehigh=%d, signal=%d, afc=%d, "
1712 "rxsubchans=0x%x, audmode=%d\n",
1713 p->index, p->name, p->type,
1714 p->capability, p->rangelow,
1715 p->rangehigh, p->signal, p->afc,
1716 p->rxsubchans, p->audmode);
1717 break;
1718 }
1719 case VIDIOC_S_TUNER:
1720 {
1721 struct v4l2_tuner *p = arg;
1722
Hans Verkuila3998102008-07-21 02:57:38 -03001723 if (!ops->vidioc_s_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001724 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001725 if (ret_prio) {
1726 ret = ret_prio;
1727 break;
1728 }
Hans Verkuil227690d2011-06-12 06:36:41 -03001729 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1730 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001731 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1732 "capability=0x%x, rangelow=%d, "
1733 "rangehigh=%d, signal=%d, afc=%d, "
1734 "rxsubchans=0x%x, audmode=%d\n",
1735 p->index, p->name, p->type,
1736 p->capability, p->rangelow,
1737 p->rangehigh, p->signal, p->afc,
1738 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001739 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001740 break;
1741 }
1742 case VIDIOC_G_FREQUENCY:
1743 {
1744 struct v4l2_frequency *p = arg;
1745
Hans Verkuila3998102008-07-21 02:57:38 -03001746 if (!ops->vidioc_g_frequency)
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_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001752 if (!ret)
1753 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1754 p->tuner, p->type, p->frequency);
1755 break;
1756 }
1757 case VIDIOC_S_FREQUENCY:
1758 {
1759 struct v4l2_frequency *p = arg;
1760
Hans Verkuila3998102008-07-21 02:57:38 -03001761 if (!ops->vidioc_s_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001762 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001763 if (ret_prio) {
1764 ret = ret_prio;
1765 break;
1766 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001767 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1768 p->tuner, p->type, p->frequency);
Hans Verkuila3998102008-07-21 02:57:38 -03001769 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001770 break;
1771 }
1772 case VIDIOC_G_SLICED_VBI_CAP:
1773 {
1774 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001775
Hans Verkuila3998102008-07-21 02:57:38 -03001776 if (!ops->vidioc_g_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001777 break;
Trent Piepho19c96e42009-03-04 01:21:02 -03001778
1779 /* Clear up to type, everything after type is zerod already */
1780 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1781
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001782 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001783 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001784 if (!ret)
1785 dbgarg2("service_set=%d\n", p->service_set);
1786 break;
1787 }
1788 case VIDIOC_LOG_STATUS:
1789 {
Hans Verkuila3998102008-07-21 02:57:38 -03001790 if (!ops->vidioc_log_status)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001791 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001792 ret = ops->vidioc_log_status(file, fh);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001793 break;
1794 }
1795#ifdef CONFIG_VIDEO_ADV_DEBUG
1796 case VIDIOC_DBG_G_REGISTER:
1797 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001798 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001799
Hans Verkuila1198cc2011-01-08 09:53:32 -03001800 if (ops->vidioc_g_register) {
1801 if (!capable(CAP_SYS_ADMIN))
1802 ret = -EPERM;
1803 else
1804 ret = ops->vidioc_g_register(file, fh, p);
1805 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001806 break;
1807 }
1808 case VIDIOC_DBG_S_REGISTER:
1809 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001810 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001811
Hans Verkuila1198cc2011-01-08 09:53:32 -03001812 if (ops->vidioc_s_register) {
1813 if (!capable(CAP_SYS_ADMIN))
1814 ret = -EPERM;
1815 else
1816 ret = ops->vidioc_s_register(file, fh, p);
1817 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001818 break;
1819 }
1820#endif
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001821 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001822 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001823 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001824
Hans Verkuila3998102008-07-21 02:57:38 -03001825 if (!ops->vidioc_g_chip_ident)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001826 break;
Hans Verkuil80b36e02009-02-07 11:00:02 -03001827 p->ident = V4L2_IDENT_NONE;
1828 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001829 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001830 if (!ret)
1831 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1832 break;
1833 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001834 case VIDIOC_S_HW_FREQ_SEEK:
1835 {
1836 struct v4l2_hw_freq_seek *p = arg;
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001837 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001838
Hans Verkuila3998102008-07-21 02:57:38 -03001839 if (!ops->vidioc_s_hw_freq_seek)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001840 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001841 if (ret_prio) {
1842 ret = ret_prio;
1843 break;
1844 }
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001845 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1846 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001847 dbgarg(cmd,
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001848 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1849 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1850 if (p->type != type)
1851 ret = -EINVAL;
1852 else
1853 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
Hans Verkuila3998102008-07-21 02:57:38 -03001854 break;
1855 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001856 case VIDIOC_ENUM_FRAMESIZES:
1857 {
1858 struct v4l2_frmsizeenum *p = arg;
1859
1860 if (!ops->vidioc_enum_framesizes)
1861 break;
1862
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001863 ret = ops->vidioc_enum_framesizes(file, fh, p);
1864 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001865 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1866 p->index,
1867 (p->pixel_format & 0xff),
1868 (p->pixel_format >> 8) & 0xff,
1869 (p->pixel_format >> 16) & 0xff,
1870 (p->pixel_format >> 24) & 0xff,
1871 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001872 switch (p->type) {
1873 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001874 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001875 p->discrete.width, p->discrete.height);
1876 break;
1877 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001878 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001879 p->stepwise.min_width, p->stepwise.min_height,
1880 p->stepwise.step_width, p->stepwise.step_height,
1881 p->stepwise.max_width, p->stepwise.max_height);
1882 break;
1883 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001884 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001885 break;
1886 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001887 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001888 }
1889
1890 break;
1891 }
1892 case VIDIOC_ENUM_FRAMEINTERVALS:
1893 {
1894 struct v4l2_frmivalenum *p = arg;
1895
1896 if (!ops->vidioc_enum_frameintervals)
1897 break;
1898
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001899 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1900 dbgarg(cmd,
1901 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1902 p->index, p->pixel_format,
1903 p->width, p->height, p->type);
1904 switch (p->type) {
1905 case V4L2_FRMIVAL_TYPE_DISCRETE:
1906 dbgarg2("fps=%d/%d\n",
1907 p->discrete.numerator,
1908 p->discrete.denominator);
1909 break;
1910 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03001911 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1912 p->stepwise.min.numerator,
1913 p->stepwise.min.denominator,
1914 p->stepwise.max.numerator,
1915 p->stepwise.max.denominator,
1916 p->stepwise.step.numerator,
1917 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001918 break;
1919 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1920 dbgarg2("continuous\n");
1921 break;
1922 default:
1923 dbgarg2("- Unknown type!\n");
1924 }
1925 break;
1926 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001927 case VIDIOC_ENUM_DV_PRESETS:
1928 {
1929 struct v4l2_dv_enum_preset *p = arg;
1930
1931 if (!ops->vidioc_enum_dv_presets)
1932 break;
1933
1934 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1935 if (!ret)
1936 dbgarg(cmd,
1937 "index=%d, preset=%d, name=%s, width=%d,"
1938 " height=%d ",
1939 p->index, p->preset, p->name, p->width,
1940 p->height);
1941 break;
1942 }
1943 case VIDIOC_S_DV_PRESET:
1944 {
1945 struct v4l2_dv_preset *p = arg;
1946
1947 if (!ops->vidioc_s_dv_preset)
1948 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001949 if (ret_prio) {
1950 ret = ret_prio;
1951 break;
1952 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001953
1954 dbgarg(cmd, "preset=%d\n", p->preset);
1955 ret = ops->vidioc_s_dv_preset(file, fh, p);
1956 break;
1957 }
1958 case VIDIOC_G_DV_PRESET:
1959 {
1960 struct v4l2_dv_preset *p = arg;
1961
1962 if (!ops->vidioc_g_dv_preset)
1963 break;
1964
1965 ret = ops->vidioc_g_dv_preset(file, fh, p);
1966 if (!ret)
1967 dbgarg(cmd, "preset=%d\n", p->preset);
1968 break;
1969 }
1970 case VIDIOC_QUERY_DV_PRESET:
1971 {
1972 struct v4l2_dv_preset *p = arg;
1973
1974 if (!ops->vidioc_query_dv_preset)
1975 break;
1976
1977 ret = ops->vidioc_query_dv_preset(file, fh, p);
1978 if (!ret)
1979 dbgarg(cmd, "preset=%d\n", p->preset);
1980 break;
1981 }
1982 case VIDIOC_S_DV_TIMINGS:
1983 {
1984 struct v4l2_dv_timings *p = arg;
1985
1986 if (!ops->vidioc_s_dv_timings)
1987 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001988 if (ret_prio) {
1989 ret = ret_prio;
1990 break;
1991 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001992
1993 switch (p->type) {
1994 case V4L2_DV_BT_656_1120:
1995 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
1996 " width=%d, height=%d, polarities=%x,"
1997 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
1998 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
1999 " il_vfrontporch=%d, il_vsync=%d,"
2000 " il_vbackporch=%d\n",
2001 p->bt.interlaced, p->bt.pixelclock,
2002 p->bt.width, p->bt.height, p->bt.polarities,
2003 p->bt.hfrontporch, p->bt.hsync,
2004 p->bt.hbackporch, p->bt.vfrontporch,
2005 p->bt.vsync, p->bt.vbackporch,
2006 p->bt.il_vfrontporch, p->bt.il_vsync,
2007 p->bt.il_vbackporch);
2008 ret = ops->vidioc_s_dv_timings(file, fh, p);
2009 break;
2010 default:
2011 dbgarg2("Unknown type %d!\n", p->type);
2012 break;
2013 }
2014 break;
2015 }
2016 case VIDIOC_G_DV_TIMINGS:
2017 {
2018 struct v4l2_dv_timings *p = arg;
2019
2020 if (!ops->vidioc_g_dv_timings)
2021 break;
2022
2023 ret = ops->vidioc_g_dv_timings(file, fh, p);
2024 if (!ret) {
2025 switch (p->type) {
2026 case V4L2_DV_BT_656_1120:
2027 dbgarg2("bt-656/1120:interlaced=%d,"
2028 " pixelclock=%lld,"
2029 " width=%d, height=%d, polarities=%x,"
2030 " hfrontporch=%d, hsync=%d,"
2031 " hbackporch=%d, vfrontporch=%d,"
2032 " vsync=%d, vbackporch=%d,"
2033 " il_vfrontporch=%d, il_vsync=%d,"
2034 " il_vbackporch=%d\n",
2035 p->bt.interlaced, p->bt.pixelclock,
2036 p->bt.width, p->bt.height,
2037 p->bt.polarities, p->bt.hfrontporch,
2038 p->bt.hsync, p->bt.hbackporch,
2039 p->bt.vfrontporch, p->bt.vsync,
2040 p->bt.vbackporch, p->bt.il_vfrontporch,
2041 p->bt.il_vsync, p->bt.il_vbackporch);
2042 break;
2043 default:
2044 dbgarg2("Unknown type %d!\n", p->type);
2045 break;
2046 }
2047 }
2048 break;
2049 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002050 case VIDIOC_DQEVENT:
2051 {
2052 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002053
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002054 if (!ops->vidioc_subscribe_event)
2055 break;
2056
2057 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2058 if (ret < 0) {
2059 dbgarg(cmd, "no pending events?");
2060 break;
2061 }
2062 dbgarg(cmd,
2063 "pending=%d, type=0x%8.8x, sequence=%d, "
2064 "timestamp=%lu.%9.9lu ",
2065 ev->pending, ev->type, ev->sequence,
2066 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2067 break;
2068 }
2069 case VIDIOC_SUBSCRIBE_EVENT:
2070 {
2071 struct v4l2_event_subscription *sub = arg;
2072
2073 if (!ops->vidioc_subscribe_event)
2074 break;
2075
2076 ret = ops->vidioc_subscribe_event(fh, sub);
2077 if (ret < 0) {
2078 dbgarg(cmd, "failed, ret=%ld", ret);
2079 break;
2080 }
2081 dbgarg(cmd, "type=0x%8.8x", sub->type);
2082 break;
2083 }
2084 case VIDIOC_UNSUBSCRIBE_EVENT:
2085 {
2086 struct v4l2_event_subscription *sub = arg;
2087
2088 if (!ops->vidioc_unsubscribe_event)
2089 break;
2090
2091 ret = ops->vidioc_unsubscribe_event(fh, sub);
2092 if (ret < 0) {
2093 dbgarg(cmd, "failed, ret=%ld", ret);
2094 break;
2095 }
2096 dbgarg(cmd, "type=0x%8.8x", sub->type);
2097 break;
2098 }
Hans Verkuila3998102008-07-21 02:57:38 -03002099 default:
Hans Verkuila3998102008-07-21 02:57:38 -03002100 if (!ops->vidioc_default)
2101 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002102 ret = ops->vidioc_default(file, fh, ret_prio >= 0, cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002103 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002104 } /* switch */
2105
2106 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2107 if (ret < 0) {
2108 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002109 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002110 }
2111 }
2112
2113 return ret;
2114}
2115
Trent Piepho19c96e42009-03-04 01:21:02 -03002116/* In some cases, only a few fields are used as input, i.e. when the app sets
2117 * "index" and then the driver fills in the rest of the structure for the thing
2118 * with that index. We only need to copy up the first non-input field. */
2119static unsigned long cmd_input_size(unsigned int cmd)
2120{
2121 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002122#define CMDINSIZE(cmd, type, field) \
2123 case VIDIOC_##cmd: \
2124 return offsetof(struct v4l2_##type, field) + \
2125 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03002126
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002127 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03002128 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2129 CMDINSIZE(G_FMT, format, type);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002130 CMDINSIZE(QUERYBUF, buffer, length);
Trent Piepho19c96e42009-03-04 01:21:02 -03002131 CMDINSIZE(G_PARM, streamparm, type);
2132 CMDINSIZE(ENUMSTD, standard, index);
2133 CMDINSIZE(ENUMINPUT, input, index);
2134 CMDINSIZE(G_CTRL, control, id);
2135 CMDINSIZE(G_TUNER, tuner, index);
2136 CMDINSIZE(QUERYCTRL, queryctrl, id);
2137 CMDINSIZE(QUERYMENU, querymenu, index);
2138 CMDINSIZE(ENUMOUTPUT, output, index);
2139 CMDINSIZE(G_MODULATOR, modulator, index);
2140 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2141 CMDINSIZE(CROPCAP, cropcap, type);
2142 CMDINSIZE(G_CROP, crop, type);
2143 CMDINSIZE(ENUMAUDIO, audio, index);
2144 CMDINSIZE(ENUMAUDOUT, audioout, index);
2145 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2146 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2147 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2148 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2149 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2150 default:
2151 return _IOC_SIZE(cmd);
2152 }
2153}
2154
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002155static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2156 void * __user *user_ptr, void ***kernel_ptr)
2157{
2158 int ret = 0;
2159
2160 switch (cmd) {
2161 case VIDIOC_QUERYBUF:
2162 case VIDIOC_QBUF:
2163 case VIDIOC_DQBUF: {
2164 struct v4l2_buffer *buf = parg;
2165
2166 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2167 if (buf->length > VIDEO_MAX_PLANES) {
2168 ret = -EINVAL;
2169 break;
2170 }
2171 *user_ptr = (void __user *)buf->m.planes;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002172 *kernel_ptr = (void *)&buf->m.planes;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002173 *array_size = sizeof(struct v4l2_plane) * buf->length;
2174 ret = 1;
2175 }
2176 break;
2177 }
2178
2179 case VIDIOC_S_EXT_CTRLS:
2180 case VIDIOC_G_EXT_CTRLS:
2181 case VIDIOC_TRY_EXT_CTRLS: {
2182 struct v4l2_ext_controls *ctrls = parg;
2183
2184 if (ctrls->count != 0) {
2185 *user_ptr = (void __user *)ctrls->controls;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002186 *kernel_ptr = (void *)&ctrls->controls;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002187 *array_size = sizeof(struct v4l2_ext_control)
2188 * ctrls->count;
2189 ret = 1;
2190 }
2191 break;
2192 }
2193 }
2194
2195 return ret;
2196}
2197
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002198long
2199video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2200 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002201{
2202 char sbuf[128];
2203 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002204 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002205 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002206 bool has_array_args;
2207 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002208 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002209 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002210
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002211 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002212 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002213 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2214 parg = sbuf;
2215 } else {
2216 /* too big to allocate from stack */
2217 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2218 if (NULL == mbuf)
2219 return -ENOMEM;
2220 parg = mbuf;
2221 }
2222
2223 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002224 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2225 unsigned long n = cmd_input_size(cmd);
2226
2227 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002228 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002229
2230 /* zero out anything we don't copy from userspace */
2231 if (n < _IOC_SIZE(cmd))
2232 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002233 } else {
2234 /* read-only ioctl */
2235 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002236 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002237 }
2238
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002239 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2240 if (err < 0)
2241 goto out;
2242 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002243
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002244 if (has_array_args) {
2245 /*
2246 * When adding new types of array args, make sure that the
2247 * parent argument to ioctl (which contains the pointer to the
2248 * array) fits into sbuf (so that mbuf will still remain
2249 * unused up to here).
2250 */
2251 mbuf = kmalloc(array_size, GFP_KERNEL);
2252 err = -ENOMEM;
2253 if (NULL == mbuf)
2254 goto out_array_args;
2255 err = -EFAULT;
2256 if (copy_from_user(mbuf, user_ptr, array_size))
2257 goto out_array_args;
2258 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002259 }
2260
2261 /* Handles IOCTL */
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002262 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002263 if (err == -ENOIOCTLCMD)
2264 err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002265
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002266 if (has_array_args) {
2267 *kernel_ptr = user_ptr;
2268 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002269 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002270 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002271 }
2272 if (err < 0)
2273 goto out;
2274
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002275out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002276 /* Copy results into user buffer */
2277 switch (_IOC_DIR(cmd)) {
2278 case _IOC_READ:
2279 case (_IOC_WRITE | _IOC_READ):
2280 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2281 err = -EFAULT;
2282 break;
2283 }
2284
2285out:
2286 kfree(mbuf);
2287 return err;
2288}
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002289EXPORT_SYMBOL(video_usercopy);
2290
2291long video_ioctl2(struct file *file,
2292 unsigned int cmd, unsigned long arg)
2293{
2294 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2295}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002296EXPORT_SYMBOL(video_ioctl2);