blob: e1da8fc9dd2f192e4451318bdc66a93fbea3279d [file] [log] [blame]
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001/*
2 * Video capture interface for Linux version 2
3 *
4 * A generic framework to process V4L2 ioctl commands.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
Alan Coxd9b01442008-10-27 15:13:47 -030011 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
Hans Verkuil35ea11f2008-07-20 08:12:02 -030012 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
13 */
14
15#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030017#include <linux/types.h>
18#include <linux/kernel.h>
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -030019#include <linux/version.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030020
Hans Verkuil35ea11f2008-07-20 08:12:02 -030021#include <linux/videodev2.h>
22
Hans Verkuil35ea11f2008-07-20 08:12:02 -030023#include <media/v4l2-common.h>
24#include <media/v4l2-ioctl.h>
Hans Verkuil11bbc1c2010-05-16 09:24:06 -030025#include <media/v4l2-ctrls.h>
Sakari Ailusd3d7c962010-03-27 11:02:10 -030026#include <media/v4l2-fh.h>
27#include <media/v4l2-event.h>
Hans Verkuil99cd47b2011-03-11 19:00:56 -030028#include <media/v4l2-device.h>
Hans Verkuil80b36e02009-02-07 11:00:02 -030029#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030030
31#define dbgarg(cmd, fmt, arg...) \
32 do { \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
37 } \
38 } while (0)
39
40#define dbgarg2(fmt, arg...) \
41 do { \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
44 } while (0)
45
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030046#define dbgarg3(fmt, arg...) \
47 do { \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
50 } while (0)
51
Lucas De Marchi25985ed2011-03-30 22:57:33 -030052/* Zero out the end of the struct pointed to by p. Everything after, but
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030053 * not including, the specified field is cleared. */
54#define CLEAR_AFTER_FIELD(p, field) \
55 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
57
Hans Verkuil93d5a302011-08-09 09:32:06 -030058#define have_fmt_ops(foo) ( \
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -030059 ops->vidioc_##foo##_fmt_vid_cap || \
60 ops->vidioc_##foo##_fmt_vid_out || \
61 ops->vidioc_##foo##_fmt_vid_cap_mplane || \
62 ops->vidioc_##foo##_fmt_vid_out_mplane || \
63 ops->vidioc_##foo##_fmt_vid_overlay || \
Hans Verkuil93d5a302011-08-09 09:32:06 -030064 ops->vidioc_##foo##_fmt_vbi_cap || \
65 ops->vidioc_##foo##_fmt_vid_out_overlay || \
66 ops->vidioc_##foo##_fmt_vbi_out || \
67 ops->vidioc_##foo##_fmt_sliced_vbi_cap || \
68 ops->vidioc_##foo##_fmt_sliced_vbi_out || \
69 ops->vidioc_##foo##_fmt_type_private)
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -030070
Hans Verkuil35ea11f2008-07-20 08:12:02 -030071struct std_descr {
72 v4l2_std_id std;
73 const char *descr;
74};
75
76static const struct std_descr standards[] = {
77 { V4L2_STD_NTSC, "NTSC" },
78 { V4L2_STD_NTSC_M, "NTSC-M" },
79 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
80 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
81 { V4L2_STD_NTSC_443, "NTSC-443" },
82 { V4L2_STD_PAL, "PAL" },
83 { V4L2_STD_PAL_BG, "PAL-BG" },
84 { V4L2_STD_PAL_B, "PAL-B" },
85 { V4L2_STD_PAL_B1, "PAL-B1" },
86 { V4L2_STD_PAL_G, "PAL-G" },
87 { V4L2_STD_PAL_H, "PAL-H" },
88 { V4L2_STD_PAL_I, "PAL-I" },
89 { V4L2_STD_PAL_DK, "PAL-DK" },
90 { V4L2_STD_PAL_D, "PAL-D" },
91 { V4L2_STD_PAL_D1, "PAL-D1" },
92 { V4L2_STD_PAL_K, "PAL-K" },
93 { V4L2_STD_PAL_M, "PAL-M" },
94 { V4L2_STD_PAL_N, "PAL-N" },
95 { V4L2_STD_PAL_Nc, "PAL-Nc" },
96 { V4L2_STD_PAL_60, "PAL-60" },
97 { V4L2_STD_SECAM, "SECAM" },
98 { V4L2_STD_SECAM_B, "SECAM-B" },
99 { V4L2_STD_SECAM_G, "SECAM-G" },
100 { V4L2_STD_SECAM_H, "SECAM-H" },
101 { V4L2_STD_SECAM_DK, "SECAM-DK" },
102 { V4L2_STD_SECAM_D, "SECAM-D" },
103 { V4L2_STD_SECAM_K, "SECAM-K" },
104 { V4L2_STD_SECAM_K1, "SECAM-K1" },
105 { V4L2_STD_SECAM_L, "SECAM-L" },
106 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
107 { 0, "Unknown" }
108};
109
110/* video4linux standard ID conversion to standard name
111 */
112const char *v4l2_norm_to_name(v4l2_std_id id)
113{
114 u32 myid = id;
115 int i;
116
117 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
118 64 bit comparations. So, on that architecture, with some gcc
119 variants, compilation fails. Currently, the max value is 30bit wide.
120 */
121 BUG_ON(myid != id);
122
123 for (i = 0; standards[i].std; i++)
124 if (myid == standards[i].std)
125 break;
126 return standards[i].descr;
127}
128EXPORT_SYMBOL(v4l2_norm_to_name);
129
Trent Piepho51f0b8d2009-03-04 01:21:02 -0300130/* Returns frame period for the given standard */
131void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
132{
133 if (id & V4L2_STD_525_60) {
134 frameperiod->numerator = 1001;
135 frameperiod->denominator = 30000;
136 } else {
137 frameperiod->numerator = 1;
138 frameperiod->denominator = 25;
139 }
140}
141EXPORT_SYMBOL(v4l2_video_std_frame_period);
142
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300143/* Fill in the fields of a v4l2_standard structure according to the
144 'id' and 'transmission' parameters. Returns negative on error. */
145int v4l2_video_std_construct(struct v4l2_standard *vs,
146 int id, const char *name)
147{
Trent Piepho51f0b8d2009-03-04 01:21:02 -0300148 vs->id = id;
149 v4l2_video_std_frame_period(id, &vs->frameperiod);
150 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300151 strlcpy(vs->name, name, sizeof(vs->name));
152 return 0;
153}
154EXPORT_SYMBOL(v4l2_video_std_construct);
155
156/* ----------------------------------------------------------------- */
157/* some arrays for pretty-printing debug messages of enum types */
158
159const char *v4l2_field_names[] = {
160 [V4L2_FIELD_ANY] = "any",
161 [V4L2_FIELD_NONE] = "none",
162 [V4L2_FIELD_TOP] = "top",
163 [V4L2_FIELD_BOTTOM] = "bottom",
164 [V4L2_FIELD_INTERLACED] = "interlaced",
165 [V4L2_FIELD_SEQ_TB] = "seq-tb",
166 [V4L2_FIELD_SEQ_BT] = "seq-bt",
167 [V4L2_FIELD_ALTERNATE] = "alternate",
168 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
169 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
170};
171EXPORT_SYMBOL(v4l2_field_names);
172
173const char *v4l2_type_names[] = {
174 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
175 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
176 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
177 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
178 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
179 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
180 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
181 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
Pawel Osciakf8f39142010-07-29 14:44:25 -0300182 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
183 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300184};
185EXPORT_SYMBOL(v4l2_type_names);
186
187static const char *v4l2_memory_names[] = {
188 [V4L2_MEMORY_MMAP] = "mmap",
189 [V4L2_MEMORY_USERPTR] = "userptr",
190 [V4L2_MEMORY_OVERLAY] = "overlay",
191};
192
193#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
194 arr[a] : "unknown")
195
196/* ------------------------------------------------------------------ */
197/* debug help functions */
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300198static const char *v4l2_ioctls[] = {
199 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
200 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
201 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
202 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
203 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
204 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
205 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
206 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
207 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
208 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
209 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
210 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
211 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
212 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
213 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
214 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
215 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
216 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
217 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
218 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
219 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
220 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
221 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
222 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
223 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
224 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
225 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
226 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
227 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
228 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
229 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
230 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
231 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
232 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
233 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
234 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
235 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
236 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
237 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
238 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
239 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
240 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
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 Verkuilaecde8b2008-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",
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300276 [_IOC_NR(VIDIOC_CREATE_BUFS)] = "VIDIOC_CREATE_BUFS",
277 [_IOC_NR(VIDIOC_PREPARE_BUF)] = "VIDIOC_PREPARE_BUF",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300278};
279#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
280
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300281/* Common ioctl debug function. This function can be used by
282 external ioctl messages as well as internal V4L ioctl */
283void v4l_printk_ioctl(unsigned int cmd)
284{
285 char *dir, *type;
286
287 switch (_IOC_TYPE(cmd)) {
288 case 'd':
Hans Verkuil78a3b4d2009-04-01 03:41:09 -0300289 type = "v4l2_int";
290 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300291 case 'V':
292 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
293 type = "v4l2";
294 break;
295 }
296 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
297 return;
298 default:
299 type = "unknown";
300 }
301
302 switch (_IOC_DIR(cmd)) {
303 case _IOC_NONE: dir = "--"; break;
304 case _IOC_READ: dir = "r-"; break;
305 case _IOC_WRITE: dir = "-w"; break;
306 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
307 default: dir = "*ERR*"; break;
308 }
309 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
310 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
311}
312EXPORT_SYMBOL(v4l_printk_ioctl);
313
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300314static void dbgbuf(unsigned int cmd, struct video_device *vfd,
315 struct v4l2_buffer *p)
316{
317 struct v4l2_timecode *tc = &p->timecode;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300318 struct v4l2_plane *plane;
319 int i;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300320
321 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300322 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300323 p->timestamp.tv_sec / 3600,
324 (int)(p->timestamp.tv_sec / 60) % 60,
325 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300326 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300327 p->index,
328 prt_names(p->type, v4l2_type_names),
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300329 p->flags, p->field, p->sequence,
330 prt_names(p->memory, v4l2_memory_names));
331
332 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
333 for (i = 0; i < p->length; ++i) {
334 plane = &p->m.planes[i];
335 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
336 "offset/userptr=0x%08lx, length=%d\n",
337 i, plane->bytesused, plane->data_offset,
338 plane->m.userptr, plane->length);
339 }
340 } else {
341 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
342 p->bytesused, p->m.userptr, p->length);
343 }
344
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300345 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
346 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
347 tc->hours, tc->minutes, tc->seconds,
348 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
349}
350
351static inline void dbgrect(struct video_device *vfd, char *s,
352 struct v4l2_rect *r)
353{
354 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
355 r->width, r->height);
356};
357
358static inline void v4l_print_pix_fmt(struct video_device *vfd,
359 struct v4l2_pix_format *fmt)
360{
361 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
362 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
363 fmt->width, fmt->height,
364 (fmt->pixelformat & 0xff),
365 (fmt->pixelformat >> 8) & 0xff,
366 (fmt->pixelformat >> 16) & 0xff,
367 (fmt->pixelformat >> 24) & 0xff,
368 prt_names(fmt->field, v4l2_field_names),
369 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
370};
371
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300372static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
373 struct v4l2_pix_format_mplane *fmt)
374{
375 int i;
376
377 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
378 "colorspace=%d, num_planes=%d\n",
379 fmt->width, fmt->height,
380 (fmt->pixelformat & 0xff),
381 (fmt->pixelformat >> 8) & 0xff,
382 (fmt->pixelformat >> 16) & 0xff,
383 (fmt->pixelformat >> 24) & 0xff,
384 prt_names(fmt->field, v4l2_field_names),
385 fmt->colorspace, fmt->num_planes);
386
387 for (i = 0; i < fmt->num_planes; ++i)
388 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
389 fmt->plane_fmt[i].bytesperline,
390 fmt->plane_fmt[i].sizeimage);
391}
392
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300393static inline void v4l_print_ext_ctrls(unsigned int cmd,
394 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
395{
396 __u32 i;
397
398 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
399 return;
400 dbgarg(cmd, "");
401 printk(KERN_CONT "class=0x%x", c->ctrl_class);
402 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300403 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300404 printk(KERN_CONT " id/val=0x%x/0x%x",
405 c->controls[i].id, c->controls[i].value);
406 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300407 printk(KERN_CONT " id=0x%x,size=%u",
408 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300409 }
410 printk(KERN_CONT "\n");
411};
412
413static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
414{
415 __u32 i;
416
417 /* zero the reserved fields */
418 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300419 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300420 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300421
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300422 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
423 when using extended controls.
424 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
425 is it allowed for backwards compatibility.
426 */
427 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
428 return 0;
429 /* Check that all controls are from the same control class. */
430 for (i = 0; i < c->count; i++) {
431 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
432 c->error_idx = i;
433 return 0;
434 }
435 }
436 return 1;
437}
438
Hans Verkuila3998102008-07-21 02:57:38 -0300439static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300440{
Hans Verkuila3998102008-07-21 02:57:38 -0300441 if (ops == NULL)
442 return -EINVAL;
443
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300444 switch (type) {
445 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300446 if (ops->vidioc_g_fmt_vid_cap ||
447 ops->vidioc_g_fmt_vid_cap_mplane)
448 return 0;
449 break;
450 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
451 if (ops->vidioc_g_fmt_vid_cap_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300452 return 0;
453 break;
454 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300455 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300456 return 0;
457 break;
458 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300459 if (ops->vidioc_g_fmt_vid_out ||
460 ops->vidioc_g_fmt_vid_out_mplane)
461 return 0;
462 break;
463 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
464 if (ops->vidioc_g_fmt_vid_out_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300465 return 0;
466 break;
467 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300468 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300469 return 0;
470 break;
471 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300472 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300473 return 0;
474 break;
475 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300476 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300477 return 0;
478 break;
479 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300480 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300481 return 0;
482 break;
483 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300484 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300485 return 0;
486 break;
487 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300488 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300489 return 0;
490 break;
491 }
492 return -EINVAL;
493}
494
Hans Verkuil069b7472008-12-30 07:04:34 -0300495static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300496 unsigned int cmd, void *arg)
497{
498 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300499 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300500 void *fh = file->private_data;
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300501 struct v4l2_fh *vfh = NULL;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300502 int use_fh_prio = 0;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300503 long ret_prio = 0;
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300504 long ret = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300505
Hans Verkuil6a717882010-04-06 15:56:08 -0300506 if (ops == NULL) {
507 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
508 vfd->name);
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -0300509 return ret;
Hans Verkuil6a717882010-04-06 15:56:08 -0300510 }
511
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300512 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
513 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
514 v4l_print_ioctl(vfd->name, cmd);
515 printk(KERN_CONT "\n");
516 }
517
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300518 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300519 vfh = file->private_data;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300520 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
521 }
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300522
Hans Verkuil93d5a302011-08-09 09:32:06 -0300523 if (use_fh_prio)
524 ret_prio = v4l2_prio_check(vfd->prio, vfh->prio);
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300525
Hans Verkuil6a717882010-04-06 15:56:08 -0300526 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300527
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300528 /* --- capabilities ------------------------------------------ */
529 case VIDIOC_QUERYCAP:
530 {
531 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300532
Hans Verkuila3998102008-07-21 02:57:38 -0300533 if (!ops->vidioc_querycap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300534 break;
535
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -0300536 cap->version = LINUX_VERSION_CODE;
Hans Verkuila3998102008-07-21 02:57:38 -0300537 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300538 if (!ret)
539 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
540 "version=0x%08x, "
541 "capabilities=0x%08x\n",
542 cap->driver, cap->card, cap->bus_info,
543 cap->version,
544 cap->capabilities);
545 break;
546 }
547
548 /* --- priority ------------------------------------------ */
549 case VIDIOC_G_PRIORITY:
550 {
551 enum v4l2_priority *p = arg;
552
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300553 if (ops->vidioc_g_priority) {
554 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300555 } else if (use_fh_prio) {
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300556 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
557 ret = 0;
558 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300559 if (!ret)
560 dbgarg(cmd, "priority is %d\n", *p);
561 break;
562 }
563 case VIDIOC_S_PRIORITY:
564 {
565 enum v4l2_priority *p = arg;
566
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300567 if (!ops->vidioc_s_priority && !use_fh_prio)
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300568 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300569 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuil99cd47b2011-03-11 19:00:56 -0300570 if (ops->vidioc_s_priority)
571 ret = ops->vidioc_s_priority(file, fh, *p);
572 else
Hans Verkuil93d5a302011-08-09 09:32:06 -0300573 ret = ret_prio ? ret_prio :
574 v4l2_prio_change(&vfd->v4l2_dev->prio,
575 &vfh->prio, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300576 break;
577 }
578
579 /* --- capture ioctls ---------------------------------------- */
580 case VIDIOC_ENUM_FMT:
581 {
582 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300583
Trent Piepho19c96e42009-03-04 01:21:02 -0300584 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300585 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300586 if (likely(ops->vidioc_enum_fmt_vid_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300587 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300588 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300589 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300590 if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300591 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
592 fh, f);
593 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300594 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300595 if (likely(ops->vidioc_enum_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300596 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300597 fh, f);
598 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300599 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300600 if (likely(ops->vidioc_enum_fmt_vid_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300601 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300602 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300603 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300604 if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300605 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
606 fh, f);
607 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300608 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300609 if (likely(ops->vidioc_enum_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300610 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300611 fh, f);
612 break;
613 default:
614 break;
615 }
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300616 if (likely (!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300617 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
618 "pixelformat=%c%c%c%c, description='%s'\n",
619 f->index, f->type, f->flags,
620 (f->pixelformat & 0xff),
621 (f->pixelformat >> 8) & 0xff,
622 (f->pixelformat >> 16) & 0xff,
623 (f->pixelformat >> 24) & 0xff,
624 f->description);
Hans Verkuil93d5a302011-08-09 09:32:06 -0300625 else if (ret == -ENOTTY &&
626 (ops->vidioc_enum_fmt_vid_cap ||
627 ops->vidioc_enum_fmt_vid_out ||
628 ops->vidioc_enum_fmt_vid_cap_mplane ||
629 ops->vidioc_enum_fmt_vid_out_mplane ||
630 ops->vidioc_enum_fmt_vid_overlay ||
631 ops->vidioc_enum_fmt_type_private))
632 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300633 break;
634 }
635 case VIDIOC_G_FMT:
636 {
637 struct v4l2_format *f = (struct v4l2_format *)arg;
638
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300639 /* FIXME: Should be one dump per type */
640 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
641
642 switch (f->type) {
643 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300644 if (ops->vidioc_g_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300645 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300646 if (!ret)
647 v4l_print_pix_fmt(vfd, &f->fmt.pix);
648 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300649 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300650 if (ops->vidioc_g_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300651 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
652 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300653 if (!ret)
654 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
655 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300656 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300657 if (likely(ops->vidioc_g_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300658 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300659 fh, f);
660 break;
661 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300662 if (ops->vidioc_g_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300663 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300664 if (!ret)
665 v4l_print_pix_fmt(vfd, &f->fmt.pix);
666 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300667 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300668 if (ops->vidioc_g_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300669 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
670 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300671 if (!ret)
672 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
673 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300674 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300675 if (likely(ops->vidioc_g_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300676 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300677 fh, f);
678 break;
679 case V4L2_BUF_TYPE_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300680 if (likely(ops->vidioc_g_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300681 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300682 break;
683 case V4L2_BUF_TYPE_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300684 if (likely(ops->vidioc_g_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300685 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300686 break;
687 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300688 if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300689 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300690 fh, f);
691 break;
692 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300693 if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300694 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300695 fh, f);
696 break;
697 case V4L2_BUF_TYPE_PRIVATE:
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300698 if (likely(ops->vidioc_g_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300699 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300700 fh, f);
701 break;
702 }
Hans Verkuil93d5a302011-08-09 09:32:06 -0300703 if (unlikely(ret == -ENOTTY && have_fmt_ops(g)))
704 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300705
706 break;
707 }
708 case VIDIOC_S_FMT:
709 {
710 struct v4l2_format *f = (struct v4l2_format *)arg;
711
Hans Verkuil93d5a302011-08-09 09:32:06 -0300712 if (!have_fmt_ops(s))
713 break;
714 if (ret_prio) {
715 ret = ret_prio;
716 break;
717 }
718 ret = -EINVAL;
719
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300720 /* FIXME: Should be one dump per type */
721 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
722
723 switch (f->type) {
724 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300725 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300726 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300727 if (ops->vidioc_s_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300728 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300729 break;
730 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
731 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
732 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300733 if (ops->vidioc_s_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300734 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
735 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300736 break;
737 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300738 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300739 if (ops->vidioc_s_fmt_vid_overlay)
740 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300741 fh, f);
742 break;
743 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300744 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300745 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300746 if (ops->vidioc_s_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300747 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300748 break;
749 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
750 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
751 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300752 if (ops->vidioc_s_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300753 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
754 fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300755 break;
756 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300757 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300758 if (ops->vidioc_s_fmt_vid_out_overlay)
759 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300760 fh, f);
761 break;
762 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300763 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300764 if (likely(ops->vidioc_s_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300765 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300766 break;
767 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300768 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300769 if (likely(ops->vidioc_s_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300770 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300771 break;
772 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300773 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300774 if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300775 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300776 fh, f);
777 break;
778 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300779 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300780 if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300781 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300782 fh, f);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300783
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300784 break;
785 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300786 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300787 if (likely(ops->vidioc_s_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300788 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300789 fh, f);
790 break;
791 }
792 break;
793 }
794 case VIDIOC_TRY_FMT:
795 {
796 struct v4l2_format *f = (struct v4l2_format *)arg;
797
798 /* FIXME: Should be one dump per type */
799 dbgarg(cmd, "type=%s\n", prt_names(f->type,
800 v4l2_type_names));
801 switch (f->type) {
802 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300803 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300804 if (ops->vidioc_try_fmt_vid_cap)
Hans Verkuila3998102008-07-21 02:57:38 -0300805 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300806 if (!ret)
807 v4l_print_pix_fmt(vfd, &f->fmt.pix);
808 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300809 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
810 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300811 if (ops->vidioc_try_fmt_vid_cap_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300812 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
813 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300814 if (!ret)
815 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
816 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300817 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300818 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300819 if (likely(ops->vidioc_try_fmt_vid_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300820 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300821 fh, f);
822 break;
823 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300824 CLEAR_AFTER_FIELD(f, fmt.pix);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300825 if (ops->vidioc_try_fmt_vid_out)
Hans Verkuila3998102008-07-21 02:57:38 -0300826 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300827 if (!ret)
828 v4l_print_pix_fmt(vfd, &f->fmt.pix);
829 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300830 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
831 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
Tomasz Stanislawski1d0c86c2011-07-01 06:25:46 -0300832 if (ops->vidioc_try_fmt_vid_out_mplane)
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300833 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
834 fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300835 if (!ret)
836 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
837 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300838 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300839 CLEAR_AFTER_FIELD(f, fmt.win);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300840 if (likely(ops->vidioc_try_fmt_vid_out_overlay))
Hans Verkuila3998102008-07-21 02:57:38 -0300841 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300842 fh, f);
843 break;
844 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300845 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300846 if (likely(ops->vidioc_try_fmt_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300847 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300848 break;
849 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300850 CLEAR_AFTER_FIELD(f, fmt.vbi);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300851 if (likely(ops->vidioc_try_fmt_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300852 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300853 break;
854 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300855 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300856 if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
Hans Verkuila3998102008-07-21 02:57:38 -0300857 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300858 fh, f);
859 break;
860 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300861 CLEAR_AFTER_FIELD(f, fmt.sliced);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300862 if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
Hans Verkuila3998102008-07-21 02:57:38 -0300863 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300864 fh, f);
865 break;
866 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300867 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -0300868 if (likely(ops->vidioc_try_fmt_type_private))
Hans Verkuila3998102008-07-21 02:57:38 -0300869 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300870 fh, f);
871 break;
872 }
Hans Verkuil93d5a302011-08-09 09:32:06 -0300873 if (unlikely(ret == -ENOTTY && have_fmt_ops(try)))
874 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300875 break;
876 }
877 /* FIXME: Those buf reqs could be handled here,
878 with some changes on videobuf to allow its header to be included at
879 videodev2.h or being merged at videodev2.
880 */
881 case VIDIOC_REQBUFS:
882 {
883 struct v4l2_requestbuffers *p = arg;
884
Hans Verkuila3998102008-07-21 02:57:38 -0300885 if (!ops->vidioc_reqbufs)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300886 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300887 if (ret_prio) {
888 ret = ret_prio;
889 break;
890 }
Hans Verkuila3998102008-07-21 02:57:38 -0300891 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300892 if (ret)
893 break;
894
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300895 if (p->type < V4L2_BUF_TYPE_PRIVATE)
896 CLEAR_AFTER_FIELD(p, memory);
897
Hans Verkuila3998102008-07-21 02:57:38 -0300898 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300899 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
900 p->count,
901 prt_names(p->type, v4l2_type_names),
902 prt_names(p->memory, v4l2_memory_names));
903 break;
904 }
905 case VIDIOC_QUERYBUF:
906 {
907 struct v4l2_buffer *p = arg;
908
Hans Verkuila3998102008-07-21 02:57:38 -0300909 if (!ops->vidioc_querybuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300910 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300911 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300912 if (ret)
913 break;
914
Hans Verkuila3998102008-07-21 02:57:38 -0300915 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300916 if (!ret)
917 dbgbuf(cmd, vfd, p);
918 break;
919 }
920 case VIDIOC_QBUF:
921 {
922 struct v4l2_buffer *p = arg;
923
Hans Verkuila3998102008-07-21 02:57:38 -0300924 if (!ops->vidioc_qbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300925 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300926 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300927 if (ret)
928 break;
929
Hans Verkuila3998102008-07-21 02:57:38 -0300930 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300931 if (!ret)
932 dbgbuf(cmd, vfd, p);
933 break;
934 }
935 case VIDIOC_DQBUF:
936 {
937 struct v4l2_buffer *p = arg;
938
Hans Verkuila3998102008-07-21 02:57:38 -0300939 if (!ops->vidioc_dqbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300940 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300941 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300942 if (ret)
943 break;
944
Hans Verkuila3998102008-07-21 02:57:38 -0300945 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300946 if (!ret)
947 dbgbuf(cmd, vfd, p);
948 break;
949 }
950 case VIDIOC_OVERLAY:
951 {
952 int *i = arg;
953
Hans Verkuila3998102008-07-21 02:57:38 -0300954 if (!ops->vidioc_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300955 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300956 if (ret_prio) {
957 ret = ret_prio;
958 break;
959 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300960 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -0300961 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300962 break;
963 }
964 case VIDIOC_G_FBUF:
965 {
966 struct v4l2_framebuffer *p = arg;
967
Hans Verkuila3998102008-07-21 02:57:38 -0300968 if (!ops->vidioc_g_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300969 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300970 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300971 if (!ret) {
972 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
973 p->capability, p->flags,
974 (unsigned long)p->base);
975 v4l_print_pix_fmt(vfd, &p->fmt);
976 }
977 break;
978 }
979 case VIDIOC_S_FBUF:
980 {
981 struct v4l2_framebuffer *p = arg;
982
Hans Verkuila3998102008-07-21 02:57:38 -0300983 if (!ops->vidioc_s_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300984 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -0300985 if (ret_prio) {
986 ret = ret_prio;
987 break;
988 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300989 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
990 p->capability, p->flags, (unsigned long)p->base);
991 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -0300992 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300993 break;
994 }
995 case VIDIOC_STREAMON:
996 {
997 enum v4l2_buf_type i = *(int *)arg;
998
Hans Verkuila3998102008-07-21 02:57:38 -0300999 if (!ops->vidioc_streamon)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001000 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001001 if (ret_prio) {
1002 ret = ret_prio;
1003 break;
1004 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001005 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001006 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001007 break;
1008 }
1009 case VIDIOC_STREAMOFF:
1010 {
1011 enum v4l2_buf_type i = *(int *)arg;
1012
Hans Verkuila3998102008-07-21 02:57:38 -03001013 if (!ops->vidioc_streamoff)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001014 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001015 if (ret_prio) {
1016 ret = ret_prio;
1017 break;
1018 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001019 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001020 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001021 break;
1022 }
1023 /* ---------- tv norms ---------- */
1024 case VIDIOC_ENUMSTD:
1025 {
1026 struct v4l2_standard *p = arg;
1027 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1028 unsigned int index = p->index, i, j = 0;
1029 const char *descr = "";
1030
Hans Verkuil93d5a302011-08-09 09:32:06 -03001031 if (id == 0)
1032 break;
1033 ret = -EINVAL;
1034
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001035 /* Return norm array in a canonical way */
1036 for (i = 0; i <= index && id; i++) {
1037 /* last std value in the standards array is 0, so this
1038 while always ends there since (id & 0) == 0. */
1039 while ((id & standards[j].std) != standards[j].std)
1040 j++;
1041 curr_id = standards[j].std;
1042 descr = standards[j].descr;
1043 j++;
1044 if (curr_id == 0)
1045 break;
1046 if (curr_id != V4L2_STD_PAL &&
1047 curr_id != V4L2_STD_SECAM &&
1048 curr_id != V4L2_STD_NTSC)
1049 id &= ~curr_id;
1050 }
1051 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001052 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001053
1054 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001055
1056 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1057 "framelines=%d\n", p->index,
1058 (unsigned long long)p->id, p->name,
1059 p->frameperiod.numerator,
1060 p->frameperiod.denominator,
1061 p->framelines);
1062
1063 ret = 0;
1064 break;
1065 }
1066 case VIDIOC_G_STD:
1067 {
1068 v4l2_std_id *id = arg;
1069
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001070 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001071 if (ops->vidioc_g_std)
1072 ret = ops->vidioc_g_std(file, fh, id);
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001073 else if (vfd->current_norm) {
1074 ret = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001075 *id = vfd->current_norm;
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001076 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001077
Mauro Carvalho Chehaba5f2db52011-07-31 09:37:56 -03001078 if (likely(!ret))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001079 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1080 break;
1081 }
1082 case VIDIOC_S_STD:
1083 {
1084 v4l2_std_id *id = arg, norm;
1085
1086 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1087
Hans Verkuil93d5a302011-08-09 09:32:06 -03001088 if (!ops->vidioc_s_std)
1089 break;
1090
1091 if (ret_prio) {
1092 ret = ret_prio;
1093 break;
1094 }
1095 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001096 norm = (*id) & vfd->tvnorms;
1097 if (vfd->tvnorms && !norm) /* Check if std is supported */
1098 break;
1099
1100 /* Calls the specific handler */
Hans Verkuil93d5a302011-08-09 09:32:06 -03001101 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001102
1103 /* Updates standard information */
1104 if (ret >= 0)
1105 vfd->current_norm = norm;
1106 break;
1107 }
1108 case VIDIOC_QUERYSTD:
1109 {
1110 v4l2_std_id *p = arg;
1111
Hans Verkuila3998102008-07-21 02:57:38 -03001112 if (!ops->vidioc_querystd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001113 break;
Mauro Carvalho Chehab8715e6c2011-10-04 09:32:23 -03001114 /*
1115 * If nothing detected, it should return all supported
1116 * Drivers just need to mask the std argument, in order
1117 * to remove the standards that don't apply from the mask.
1118 * This means that tuners, audio and video decoders can join
1119 * their efforts to improve the standards detection
1120 */
1121 *p = vfd->tvnorms;
Hans Verkuila3998102008-07-21 02:57:38 -03001122 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001123 if (!ret)
1124 dbgarg(cmd, "detected std=%08Lx\n",
1125 (unsigned long long)*p);
1126 break;
1127 }
1128 /* ------ input switching ---------- */
1129 /* FIXME: Inputs can be handled inside videodev2 */
1130 case VIDIOC_ENUMINPUT:
1131 {
1132 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001133
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001134 /*
1135 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1136 * CAP_STD here based on ioctl handler provided by the
1137 * driver. If the driver doesn't support these
1138 * for a specific input, it must override these flags.
1139 */
1140 if (ops->vidioc_s_std)
1141 p->capabilities |= V4L2_IN_CAP_STD;
1142 if (ops->vidioc_s_dv_preset)
1143 p->capabilities |= V4L2_IN_CAP_PRESETS;
1144 if (ops->vidioc_s_dv_timings)
1145 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1146
Hans Verkuila3998102008-07-21 02:57:38 -03001147 if (!ops->vidioc_enum_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001148 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001149
Hans Verkuila3998102008-07-21 02:57:38 -03001150 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001151 if (!ret)
1152 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1153 "audioset=%d, "
1154 "tuner=%d, std=%08Lx, status=%d\n",
1155 p->index, p->name, p->type, p->audioset,
1156 p->tuner,
1157 (unsigned long long)p->std,
1158 p->status);
1159 break;
1160 }
1161 case VIDIOC_G_INPUT:
1162 {
1163 unsigned int *i = arg;
1164
Hans Verkuila3998102008-07-21 02:57:38 -03001165 if (!ops->vidioc_g_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001166 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001167 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001168 if (!ret)
1169 dbgarg(cmd, "value=%d\n", *i);
1170 break;
1171 }
1172 case VIDIOC_S_INPUT:
1173 {
1174 unsigned int *i = arg;
1175
Hans Verkuila3998102008-07-21 02:57:38 -03001176 if (!ops->vidioc_s_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001177 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001178 if (ret_prio) {
1179 ret = ret_prio;
1180 break;
1181 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001182 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001183 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001184 break;
1185 }
1186
1187 /* ------ output switching ---------- */
1188 case VIDIOC_ENUMOUTPUT:
1189 {
1190 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001191
Hans Verkuila3998102008-07-21 02:57:38 -03001192 if (!ops->vidioc_enum_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001193 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001194
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001195 /*
1196 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1197 * CAP_STD here based on ioctl handler provided by the
1198 * driver. If the driver doesn't support these
1199 * for a specific output, it must override these flags.
1200 */
1201 if (ops->vidioc_s_std)
1202 p->capabilities |= V4L2_OUT_CAP_STD;
1203 if (ops->vidioc_s_dv_preset)
1204 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1205 if (ops->vidioc_s_dv_timings)
1206 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1207
Hans Verkuila3998102008-07-21 02:57:38 -03001208 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001209 if (!ret)
1210 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1211 "audioset=0x%x, "
1212 "modulator=%d, std=0x%08Lx\n",
1213 p->index, p->name, p->type, p->audioset,
1214 p->modulator, (unsigned long long)p->std);
1215 break;
1216 }
1217 case VIDIOC_G_OUTPUT:
1218 {
1219 unsigned int *i = arg;
1220
Hans Verkuila3998102008-07-21 02:57:38 -03001221 if (!ops->vidioc_g_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001222 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001223 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001224 if (!ret)
1225 dbgarg(cmd, "value=%d\n", *i);
1226 break;
1227 }
1228 case VIDIOC_S_OUTPUT:
1229 {
1230 unsigned int *i = arg;
1231
Hans Verkuila3998102008-07-21 02:57:38 -03001232 if (!ops->vidioc_s_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001233 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001234 if (ret_prio) {
1235 ret = ret_prio;
1236 break;
1237 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001238 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001239 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001240 break;
1241 }
1242
1243 /* --- controls ---------------------------------------------- */
1244 case VIDIOC_QUERYCTRL:
1245 {
1246 struct v4l2_queryctrl *p = arg;
1247
Hans Verkuil2d28b682011-03-12 08:54:43 -03001248 if (vfh && vfh->ctrl_handler)
1249 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1250 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001251 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1252 else if (ops->vidioc_queryctrl)
1253 ret = ops->vidioc_queryctrl(file, fh, p);
1254 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001255 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001256 if (!ret)
1257 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1258 "step=%d, default=%d, flags=0x%08x\n",
1259 p->id, p->type, p->name,
1260 p->minimum, p->maximum,
1261 p->step, p->default_value, p->flags);
1262 else
1263 dbgarg(cmd, "id=0x%x\n", p->id);
1264 break;
1265 }
1266 case VIDIOC_G_CTRL:
1267 {
1268 struct v4l2_control *p = arg;
1269
Hans Verkuil2d28b682011-03-12 08:54:43 -03001270 if (vfh && vfh->ctrl_handler)
1271 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1272 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001273 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1274 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001275 ret = ops->vidioc_g_ctrl(file, fh, p);
1276 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001277 struct v4l2_ext_controls ctrls;
1278 struct v4l2_ext_control ctrl;
1279
1280 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1281 ctrls.count = 1;
1282 ctrls.controls = &ctrl;
1283 ctrl.id = p->id;
1284 ctrl.value = p->value;
1285 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001286 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001287 if (ret == 0)
1288 p->value = ctrl.value;
1289 }
1290 } else
1291 break;
1292 if (!ret)
1293 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1294 else
1295 dbgarg(cmd, "id=0x%x\n", p->id);
1296 break;
1297 }
1298 case VIDIOC_S_CTRL:
1299 {
1300 struct v4l2_control *p = arg;
1301 struct v4l2_ext_controls ctrls;
1302 struct v4l2_ext_control ctrl;
1303
Hans Verkuil2d28b682011-03-12 08:54:43 -03001304 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001305 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001306 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001307 if (ret_prio) {
1308 ret = ret_prio;
1309 break;
1310 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001311
1312 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1313
Hans Verkuil2d28b682011-03-12 08:54:43 -03001314 if (vfh && vfh->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001315 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001316 break;
1317 }
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001318 if (vfd->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001319 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001320 break;
1321 }
Hans Verkuila3998102008-07-21 02:57:38 -03001322 if (ops->vidioc_s_ctrl) {
1323 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001324 break;
1325 }
Hans Verkuila3998102008-07-21 02:57:38 -03001326 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001327 break;
1328
1329 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1330 ctrls.count = 1;
1331 ctrls.controls = &ctrl;
1332 ctrl.id = p->id;
1333 ctrl.value = p->value;
1334 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001335 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001336 else
1337 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001338 break;
1339 }
1340 case VIDIOC_G_EXT_CTRLS:
1341 {
1342 struct v4l2_ext_controls *p = arg;
1343
1344 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001345 if (vfh && vfh->ctrl_handler)
1346 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1347 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001348 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001349 else if (ops->vidioc_g_ext_ctrls)
1350 ret = check_ext_ctrls(p, 0) ?
1351 ops->vidioc_g_ext_ctrls(file, fh, p) :
1352 -EINVAL;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001353 else
1354 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001355 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1356 break;
1357 }
1358 case VIDIOC_S_EXT_CTRLS:
1359 {
1360 struct v4l2_ext_controls *p = arg;
1361
1362 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001363 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1364 !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001365 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001366 if (ret_prio) {
1367 ret = ret_prio;
1368 break;
1369 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001370 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001371 if (vfh && vfh->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001372 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001373 else if (vfd->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001374 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001375 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001376 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001377 else
1378 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001379 break;
1380 }
1381 case VIDIOC_TRY_EXT_CTRLS:
1382 {
1383 struct v4l2_ext_controls *p = arg;
1384
1385 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001386 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1387 !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001388 break;
1389 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001390 if (vfh && vfh->ctrl_handler)
1391 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1392 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001393 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1394 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001395 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001396 else
1397 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001398 break;
1399 }
1400 case VIDIOC_QUERYMENU:
1401 {
1402 struct v4l2_querymenu *p = arg;
1403
Hans Verkuil2d28b682011-03-12 08:54:43 -03001404 if (vfh && vfh->ctrl_handler)
1405 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1406 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001407 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1408 else if (ops->vidioc_querymenu)
1409 ret = ops->vidioc_querymenu(file, fh, p);
1410 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001411 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001412 if (!ret)
1413 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1414 p->id, p->index, p->name);
1415 else
1416 dbgarg(cmd, "id=0x%x, index=%d\n",
1417 p->id, p->index);
1418 break;
1419 }
1420 /* --- audio ---------------------------------------------- */
1421 case VIDIOC_ENUMAUDIO:
1422 {
1423 struct v4l2_audio *p = arg;
1424
Hans Verkuila3998102008-07-21 02:57:38 -03001425 if (!ops->vidioc_enumaudio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001426 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001427 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001428 if (!ret)
1429 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1430 "mode=0x%x\n", p->index, p->name,
1431 p->capability, p->mode);
1432 else
1433 dbgarg(cmd, "index=%d\n", p->index);
1434 break;
1435 }
1436 case VIDIOC_G_AUDIO:
1437 {
1438 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001439
Hans Verkuila3998102008-07-21 02:57:38 -03001440 if (!ops->vidioc_g_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001441 break;
1442
Hans Verkuila3998102008-07-21 02:57:38 -03001443 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001444 if (!ret)
1445 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1446 "mode=0x%x\n", p->index,
1447 p->name, p->capability, p->mode);
1448 else
1449 dbgarg(cmd, "index=%d\n", p->index);
1450 break;
1451 }
1452 case VIDIOC_S_AUDIO:
1453 {
1454 struct v4l2_audio *p = arg;
1455
Hans Verkuila3998102008-07-21 02:57:38 -03001456 if (!ops->vidioc_s_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001457 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001458 if (ret_prio) {
1459 ret = ret_prio;
1460 break;
1461 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001462 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1463 "mode=0x%x\n", p->index, p->name,
1464 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001465 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001466 break;
1467 }
1468 case VIDIOC_ENUMAUDOUT:
1469 {
1470 struct v4l2_audioout *p = arg;
1471
Hans Verkuila3998102008-07-21 02:57:38 -03001472 if (!ops->vidioc_enumaudout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001473 break;
1474 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001475 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001476 if (!ret)
1477 dbgarg2("index=%d, name=%s, capability=%d, "
1478 "mode=%d\n", p->index, p->name,
1479 p->capability, p->mode);
1480 break;
1481 }
1482 case VIDIOC_G_AUDOUT:
1483 {
1484 struct v4l2_audioout *p = arg;
1485
Hans Verkuila3998102008-07-21 02:57:38 -03001486 if (!ops->vidioc_g_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001487 break;
Trent Piepho337f9d22009-03-04 01:21:02 -03001488
Hans Verkuila3998102008-07-21 02:57:38 -03001489 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001490 if (!ret)
1491 dbgarg2("index=%d, name=%s, capability=%d, "
1492 "mode=%d\n", p->index, p->name,
1493 p->capability, p->mode);
1494 break;
1495 }
1496 case VIDIOC_S_AUDOUT:
1497 {
1498 struct v4l2_audioout *p = arg;
1499
Hans Verkuila3998102008-07-21 02:57:38 -03001500 if (!ops->vidioc_s_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001501 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001502 if (ret_prio) {
1503 ret = ret_prio;
1504 break;
1505 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001506 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1507 "mode=%d\n", p->index, p->name,
1508 p->capability, p->mode);
1509
Hans Verkuila3998102008-07-21 02:57:38 -03001510 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001511 break;
1512 }
1513 case VIDIOC_G_MODULATOR:
1514 {
1515 struct v4l2_modulator *p = arg;
1516
Hans Verkuila3998102008-07-21 02:57:38 -03001517 if (!ops->vidioc_g_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001518 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001519 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001520 if (!ret)
1521 dbgarg(cmd, "index=%d, name=%s, "
1522 "capability=%d, rangelow=%d,"
1523 " rangehigh=%d, txsubchans=%d\n",
1524 p->index, p->name, p->capability,
1525 p->rangelow, p->rangehigh,
1526 p->txsubchans);
1527 break;
1528 }
1529 case VIDIOC_S_MODULATOR:
1530 {
1531 struct v4l2_modulator *p = arg;
1532
Hans Verkuila3998102008-07-21 02:57:38 -03001533 if (!ops->vidioc_s_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001534 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001535 if (ret_prio) {
1536 ret = ret_prio;
1537 break;
1538 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001539 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1540 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1541 p->index, p->name, p->capability, p->rangelow,
1542 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001543 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001544 break;
1545 }
1546 case VIDIOC_G_CROP:
1547 {
1548 struct v4l2_crop *p = arg;
1549
Hans Verkuila3998102008-07-21 02:57:38 -03001550 if (!ops->vidioc_g_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001551 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001552
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001553 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001554 ret = ops->vidioc_g_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001555 if (!ret)
1556 dbgrect(vfd, "", &p->c);
1557 break;
1558 }
1559 case VIDIOC_S_CROP:
1560 {
1561 struct v4l2_crop *p = arg;
1562
Hans Verkuila3998102008-07-21 02:57:38 -03001563 if (!ops->vidioc_s_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001564 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001565 if (ret_prio) {
1566 ret = ret_prio;
1567 break;
1568 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001569 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1570 dbgrect(vfd, "", &p->c);
Hans Verkuila3998102008-07-21 02:57:38 -03001571 ret = ops->vidioc_s_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001572 break;
1573 }
1574 case VIDIOC_CROPCAP:
1575 {
1576 struct v4l2_cropcap *p = arg;
1577
1578 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuila3998102008-07-21 02:57:38 -03001579 if (!ops->vidioc_cropcap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001580 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001581
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001582 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001583 ret = ops->vidioc_cropcap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001584 if (!ret) {
1585 dbgrect(vfd, "bounds ", &p->bounds);
1586 dbgrect(vfd, "defrect ", &p->defrect);
1587 }
1588 break;
1589 }
1590 case VIDIOC_G_JPEGCOMP:
1591 {
1592 struct v4l2_jpegcompression *p = arg;
1593
Hans Verkuila3998102008-07-21 02:57:38 -03001594 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001595 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001596
Hans Verkuila3998102008-07-21 02:57:38 -03001597 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001598 if (!ret)
1599 dbgarg(cmd, "quality=%d, APPn=%d, "
1600 "APP_len=%d, COM_len=%d, "
1601 "jpeg_markers=%d\n",
1602 p->quality, p->APPn, p->APP_len,
1603 p->COM_len, p->jpeg_markers);
1604 break;
1605 }
1606 case VIDIOC_S_JPEGCOMP:
1607 {
1608 struct v4l2_jpegcompression *p = arg;
1609
Hans Verkuila3998102008-07-21 02:57:38 -03001610 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001611 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001612 if (ret_prio) {
1613 ret = ret_prio;
1614 break;
1615 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001616 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1617 "COM_len=%d, jpeg_markers=%d\n",
1618 p->quality, p->APPn, p->APP_len,
1619 p->COM_len, p->jpeg_markers);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001620 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001621 break;
1622 }
1623 case VIDIOC_G_ENC_INDEX:
1624 {
1625 struct v4l2_enc_idx *p = arg;
1626
Hans Verkuila3998102008-07-21 02:57:38 -03001627 if (!ops->vidioc_g_enc_index)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001628 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001629 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001630 if (!ret)
1631 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1632 p->entries, p->entries_cap);
1633 break;
1634 }
1635 case VIDIOC_ENCODER_CMD:
1636 {
1637 struct v4l2_encoder_cmd *p = arg;
1638
Hans Verkuila3998102008-07-21 02:57:38 -03001639 if (!ops->vidioc_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001640 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001641 if (ret_prio) {
1642 ret = ret_prio;
1643 break;
1644 }
Hans Verkuila3998102008-07-21 02:57:38 -03001645 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001646 if (!ret)
1647 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1648 break;
1649 }
1650 case VIDIOC_TRY_ENCODER_CMD:
1651 {
1652 struct v4l2_encoder_cmd *p = arg;
1653
Hans Verkuila3998102008-07-21 02:57:38 -03001654 if (!ops->vidioc_try_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001655 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001656 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001657 if (!ret)
1658 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1659 break;
1660 }
1661 case VIDIOC_G_PARM:
1662 {
1663 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001664
Hans Verkuil93d5a302011-08-09 09:32:06 -03001665 if (!ops->vidioc_g_parm && !vfd->current_norm)
1666 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001667 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001668 ret = check_fmt(ops, p->type);
1669 if (ret)
1670 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001671 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001672 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001673 v4l2_std_id std = vfd->current_norm;
1674
Hans Verkuil93d5a302011-08-09 09:32:06 -03001675 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001676 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001677 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001678
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001679 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001680 if (ops->vidioc_g_std)
1681 ret = ops->vidioc_g_std(file, fh, &std);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001682 if (ret == 0)
1683 v4l2_video_std_frame_period(std,
1684 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001685 }
1686
1687 dbgarg(cmd, "type=%d\n", p->type);
1688 break;
1689 }
1690 case VIDIOC_S_PARM:
1691 {
1692 struct v4l2_streamparm *p = arg;
1693
Hans Verkuila3998102008-07-21 02:57:38 -03001694 if (!ops->vidioc_s_parm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001695 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001696 if (ret_prio) {
1697 ret = ret_prio;
1698 break;
1699 }
Trent Piepho34796bc2009-03-28 22:25:35 -03001700 ret = check_fmt(ops, p->type);
1701 if (ret)
1702 break;
1703
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001704 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001705 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001706 break;
1707 }
1708 case VIDIOC_G_TUNER:
1709 {
1710 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001711
Hans Verkuila3998102008-07-21 02:57:38 -03001712 if (!ops->vidioc_g_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001713 break;
1714
Hans Verkuil227690d2011-06-12 06:36:41 -03001715 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1716 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001717 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001718 if (!ret)
1719 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1720 "capability=0x%x, rangelow=%d, "
1721 "rangehigh=%d, signal=%d, afc=%d, "
1722 "rxsubchans=0x%x, audmode=%d\n",
1723 p->index, p->name, p->type,
1724 p->capability, p->rangelow,
1725 p->rangehigh, p->signal, p->afc,
1726 p->rxsubchans, p->audmode);
1727 break;
1728 }
1729 case VIDIOC_S_TUNER:
1730 {
1731 struct v4l2_tuner *p = arg;
1732
Hans Verkuila3998102008-07-21 02:57:38 -03001733 if (!ops->vidioc_s_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001734 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001735 if (ret_prio) {
1736 ret = ret_prio;
1737 break;
1738 }
Hans Verkuil227690d2011-06-12 06:36:41 -03001739 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1740 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001741 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1742 "capability=0x%x, rangelow=%d, "
1743 "rangehigh=%d, signal=%d, afc=%d, "
1744 "rxsubchans=0x%x, audmode=%d\n",
1745 p->index, p->name, p->type,
1746 p->capability, p->rangelow,
1747 p->rangehigh, p->signal, p->afc,
1748 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001749 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001750 break;
1751 }
1752 case VIDIOC_G_FREQUENCY:
1753 {
1754 struct v4l2_frequency *p = arg;
1755
Hans Verkuila3998102008-07-21 02:57:38 -03001756 if (!ops->vidioc_g_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001757 break;
1758
Hans Verkuil227690d2011-06-12 06:36:41 -03001759 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1760 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001761 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001762 if (!ret)
1763 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1764 p->tuner, p->type, p->frequency);
1765 break;
1766 }
1767 case VIDIOC_S_FREQUENCY:
1768 {
1769 struct v4l2_frequency *p = arg;
1770
Hans Verkuila3998102008-07-21 02:57:38 -03001771 if (!ops->vidioc_s_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001772 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001773 if (ret_prio) {
1774 ret = ret_prio;
1775 break;
1776 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001777 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1778 p->tuner, p->type, p->frequency);
Hans Verkuila3998102008-07-21 02:57:38 -03001779 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001780 break;
1781 }
1782 case VIDIOC_G_SLICED_VBI_CAP:
1783 {
1784 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001785
Hans Verkuila3998102008-07-21 02:57:38 -03001786 if (!ops->vidioc_g_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001787 break;
Trent Piepho19c96e42009-03-04 01:21:02 -03001788
1789 /* Clear up to type, everything after type is zerod already */
1790 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1791
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001792 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001793 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001794 if (!ret)
1795 dbgarg2("service_set=%d\n", p->service_set);
1796 break;
1797 }
1798 case VIDIOC_LOG_STATUS:
1799 {
Hans Verkuila3998102008-07-21 02:57:38 -03001800 if (!ops->vidioc_log_status)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001801 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001802 ret = ops->vidioc_log_status(file, fh);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001803 break;
1804 }
1805#ifdef CONFIG_VIDEO_ADV_DEBUG
1806 case VIDIOC_DBG_G_REGISTER:
1807 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001808 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001809
Hans Verkuila1198cc2011-01-08 09:53:32 -03001810 if (ops->vidioc_g_register) {
1811 if (!capable(CAP_SYS_ADMIN))
1812 ret = -EPERM;
1813 else
1814 ret = ops->vidioc_g_register(file, fh, p);
1815 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001816 break;
1817 }
1818 case VIDIOC_DBG_S_REGISTER:
1819 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001820 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001821
Hans Verkuila1198cc2011-01-08 09:53:32 -03001822 if (ops->vidioc_s_register) {
1823 if (!capable(CAP_SYS_ADMIN))
1824 ret = -EPERM;
1825 else
1826 ret = ops->vidioc_s_register(file, fh, p);
1827 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001828 break;
1829 }
1830#endif
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001831 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001832 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001833 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001834
Hans Verkuila3998102008-07-21 02:57:38 -03001835 if (!ops->vidioc_g_chip_ident)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001836 break;
Hans Verkuil80b36e02009-02-07 11:00:02 -03001837 p->ident = V4L2_IDENT_NONE;
1838 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001839 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001840 if (!ret)
1841 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1842 break;
1843 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001844 case VIDIOC_S_HW_FREQ_SEEK:
1845 {
1846 struct v4l2_hw_freq_seek *p = arg;
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001847 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001848
Hans Verkuila3998102008-07-21 02:57:38 -03001849 if (!ops->vidioc_s_hw_freq_seek)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001850 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001851 if (ret_prio) {
1852 ret = ret_prio;
1853 break;
1854 }
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001855 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1856 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001857 dbgarg(cmd,
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001858 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1859 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1860 if (p->type != type)
1861 ret = -EINVAL;
1862 else
1863 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
Hans Verkuila3998102008-07-21 02:57:38 -03001864 break;
1865 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001866 case VIDIOC_ENUM_FRAMESIZES:
1867 {
1868 struct v4l2_frmsizeenum *p = arg;
1869
1870 if (!ops->vidioc_enum_framesizes)
1871 break;
1872
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001873 ret = ops->vidioc_enum_framesizes(file, fh, p);
1874 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001875 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1876 p->index,
1877 (p->pixel_format & 0xff),
1878 (p->pixel_format >> 8) & 0xff,
1879 (p->pixel_format >> 16) & 0xff,
1880 (p->pixel_format >> 24) & 0xff,
1881 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001882 switch (p->type) {
1883 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001884 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001885 p->discrete.width, p->discrete.height);
1886 break;
1887 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001888 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001889 p->stepwise.min_width, p->stepwise.min_height,
1890 p->stepwise.step_width, p->stepwise.step_height,
1891 p->stepwise.max_width, p->stepwise.max_height);
1892 break;
1893 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001894 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001895 break;
1896 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001897 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001898 }
1899
1900 break;
1901 }
1902 case VIDIOC_ENUM_FRAMEINTERVALS:
1903 {
1904 struct v4l2_frmivalenum *p = arg;
1905
1906 if (!ops->vidioc_enum_frameintervals)
1907 break;
1908
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001909 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1910 dbgarg(cmd,
1911 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1912 p->index, p->pixel_format,
1913 p->width, p->height, p->type);
1914 switch (p->type) {
1915 case V4L2_FRMIVAL_TYPE_DISCRETE:
1916 dbgarg2("fps=%d/%d\n",
1917 p->discrete.numerator,
1918 p->discrete.denominator);
1919 break;
1920 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03001921 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1922 p->stepwise.min.numerator,
1923 p->stepwise.min.denominator,
1924 p->stepwise.max.numerator,
1925 p->stepwise.max.denominator,
1926 p->stepwise.step.numerator,
1927 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001928 break;
1929 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1930 dbgarg2("continuous\n");
1931 break;
1932 default:
1933 dbgarg2("- Unknown type!\n");
1934 }
1935 break;
1936 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001937 case VIDIOC_ENUM_DV_PRESETS:
1938 {
1939 struct v4l2_dv_enum_preset *p = arg;
1940
1941 if (!ops->vidioc_enum_dv_presets)
1942 break;
1943
1944 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1945 if (!ret)
1946 dbgarg(cmd,
1947 "index=%d, preset=%d, name=%s, width=%d,"
1948 " height=%d ",
1949 p->index, p->preset, p->name, p->width,
1950 p->height);
1951 break;
1952 }
1953 case VIDIOC_S_DV_PRESET:
1954 {
1955 struct v4l2_dv_preset *p = arg;
1956
1957 if (!ops->vidioc_s_dv_preset)
1958 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001959 if (ret_prio) {
1960 ret = ret_prio;
1961 break;
1962 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001963
1964 dbgarg(cmd, "preset=%d\n", p->preset);
1965 ret = ops->vidioc_s_dv_preset(file, fh, p);
1966 break;
1967 }
1968 case VIDIOC_G_DV_PRESET:
1969 {
1970 struct v4l2_dv_preset *p = arg;
1971
1972 if (!ops->vidioc_g_dv_preset)
1973 break;
1974
1975 ret = ops->vidioc_g_dv_preset(file, fh, p);
1976 if (!ret)
1977 dbgarg(cmd, "preset=%d\n", p->preset);
1978 break;
1979 }
1980 case VIDIOC_QUERY_DV_PRESET:
1981 {
1982 struct v4l2_dv_preset *p = arg;
1983
1984 if (!ops->vidioc_query_dv_preset)
1985 break;
1986
1987 ret = ops->vidioc_query_dv_preset(file, fh, p);
1988 if (!ret)
1989 dbgarg(cmd, "preset=%d\n", p->preset);
1990 break;
1991 }
1992 case VIDIOC_S_DV_TIMINGS:
1993 {
1994 struct v4l2_dv_timings *p = arg;
1995
1996 if (!ops->vidioc_s_dv_timings)
1997 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03001998 if (ret_prio) {
1999 ret = ret_prio;
2000 break;
2001 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002002
2003 switch (p->type) {
2004 case V4L2_DV_BT_656_1120:
2005 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2006 " width=%d, height=%d, polarities=%x,"
2007 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
2008 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
2009 " il_vfrontporch=%d, il_vsync=%d,"
2010 " il_vbackporch=%d\n",
2011 p->bt.interlaced, p->bt.pixelclock,
2012 p->bt.width, p->bt.height, p->bt.polarities,
2013 p->bt.hfrontporch, p->bt.hsync,
2014 p->bt.hbackporch, p->bt.vfrontporch,
2015 p->bt.vsync, p->bt.vbackporch,
2016 p->bt.il_vfrontporch, p->bt.il_vsync,
2017 p->bt.il_vbackporch);
2018 ret = ops->vidioc_s_dv_timings(file, fh, p);
2019 break;
2020 default:
2021 dbgarg2("Unknown type %d!\n", p->type);
2022 break;
2023 }
2024 break;
2025 }
2026 case VIDIOC_G_DV_TIMINGS:
2027 {
2028 struct v4l2_dv_timings *p = arg;
2029
2030 if (!ops->vidioc_g_dv_timings)
2031 break;
2032
2033 ret = ops->vidioc_g_dv_timings(file, fh, p);
2034 if (!ret) {
2035 switch (p->type) {
2036 case V4L2_DV_BT_656_1120:
2037 dbgarg2("bt-656/1120:interlaced=%d,"
2038 " pixelclock=%lld,"
2039 " width=%d, height=%d, polarities=%x,"
2040 " hfrontporch=%d, hsync=%d,"
2041 " hbackporch=%d, vfrontporch=%d,"
2042 " vsync=%d, vbackporch=%d,"
2043 " il_vfrontporch=%d, il_vsync=%d,"
2044 " il_vbackporch=%d\n",
2045 p->bt.interlaced, p->bt.pixelclock,
2046 p->bt.width, p->bt.height,
2047 p->bt.polarities, p->bt.hfrontporch,
2048 p->bt.hsync, p->bt.hbackporch,
2049 p->bt.vfrontporch, p->bt.vsync,
2050 p->bt.vbackporch, p->bt.il_vfrontporch,
2051 p->bt.il_vsync, p->bt.il_vbackporch);
2052 break;
2053 default:
2054 dbgarg2("Unknown type %d!\n", p->type);
2055 break;
2056 }
2057 }
2058 break;
2059 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002060 case VIDIOC_DQEVENT:
2061 {
2062 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002063
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002064 if (!ops->vidioc_subscribe_event)
2065 break;
2066
2067 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2068 if (ret < 0) {
2069 dbgarg(cmd, "no pending events?");
2070 break;
2071 }
2072 dbgarg(cmd,
2073 "pending=%d, type=0x%8.8x, sequence=%d, "
2074 "timestamp=%lu.%9.9lu ",
2075 ev->pending, ev->type, ev->sequence,
2076 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2077 break;
2078 }
2079 case VIDIOC_SUBSCRIBE_EVENT:
2080 {
2081 struct v4l2_event_subscription *sub = arg;
2082
2083 if (!ops->vidioc_subscribe_event)
2084 break;
2085
2086 ret = ops->vidioc_subscribe_event(fh, sub);
2087 if (ret < 0) {
2088 dbgarg(cmd, "failed, ret=%ld", ret);
2089 break;
2090 }
2091 dbgarg(cmd, "type=0x%8.8x", sub->type);
2092 break;
2093 }
2094 case VIDIOC_UNSUBSCRIBE_EVENT:
2095 {
2096 struct v4l2_event_subscription *sub = arg;
2097
2098 if (!ops->vidioc_unsubscribe_event)
2099 break;
2100
2101 ret = ops->vidioc_unsubscribe_event(fh, sub);
2102 if (ret < 0) {
2103 dbgarg(cmd, "failed, ret=%ld", ret);
2104 break;
2105 }
2106 dbgarg(cmd, "type=0x%8.8x", sub->type);
2107 break;
2108 }
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03002109 case VIDIOC_CREATE_BUFS:
2110 {
2111 struct v4l2_create_buffers *create = arg;
2112
2113 if (!ops->vidioc_create_bufs)
2114 break;
2115 if (ret_prio) {
2116 ret = ret_prio;
2117 break;
2118 }
2119 ret = check_fmt(ops, create->format.type);
2120 if (ret)
2121 break;
2122
2123 ret = ops->vidioc_create_bufs(file, fh, create);
2124
2125 dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2126 break;
2127 }
2128 case VIDIOC_PREPARE_BUF:
2129 {
2130 struct v4l2_buffer *b = arg;
2131
2132 if (!ops->vidioc_prepare_buf)
2133 break;
2134 ret = check_fmt(ops, b->type);
2135 if (ret)
2136 break;
2137
2138 ret = ops->vidioc_prepare_buf(file, fh, b);
2139
2140 dbgarg(cmd, "index=%d", b->index);
2141 break;
2142 }
Hans Verkuila3998102008-07-21 02:57:38 -03002143 default:
Hans Verkuila3998102008-07-21 02:57:38 -03002144 if (!ops->vidioc_default)
2145 break;
Hans Verkuil93d5a302011-08-09 09:32:06 -03002146 ret = ops->vidioc_default(file, fh, ret_prio >= 0, cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002147 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002148 } /* switch */
2149
2150 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2151 if (ret < 0) {
2152 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002153 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002154 }
2155 }
2156
2157 return ret;
2158}
2159
Trent Piepho19c96e42009-03-04 01:21:02 -03002160/* In some cases, only a few fields are used as input, i.e. when the app sets
2161 * "index" and then the driver fills in the rest of the structure for the thing
2162 * with that index. We only need to copy up the first non-input field. */
2163static unsigned long cmd_input_size(unsigned int cmd)
2164{
2165 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002166#define CMDINSIZE(cmd, type, field) \
2167 case VIDIOC_##cmd: \
2168 return offsetof(struct v4l2_##type, field) + \
2169 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03002170
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002171 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03002172 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2173 CMDINSIZE(G_FMT, format, type);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002174 CMDINSIZE(QUERYBUF, buffer, length);
Trent Piepho19c96e42009-03-04 01:21:02 -03002175 CMDINSIZE(G_PARM, streamparm, type);
2176 CMDINSIZE(ENUMSTD, standard, index);
2177 CMDINSIZE(ENUMINPUT, input, index);
2178 CMDINSIZE(G_CTRL, control, id);
2179 CMDINSIZE(G_TUNER, tuner, index);
2180 CMDINSIZE(QUERYCTRL, queryctrl, id);
2181 CMDINSIZE(QUERYMENU, querymenu, index);
2182 CMDINSIZE(ENUMOUTPUT, output, index);
2183 CMDINSIZE(G_MODULATOR, modulator, index);
2184 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2185 CMDINSIZE(CROPCAP, cropcap, type);
2186 CMDINSIZE(G_CROP, crop, type);
2187 CMDINSIZE(ENUMAUDIO, audio, index);
2188 CMDINSIZE(ENUMAUDOUT, audioout, index);
2189 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2190 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2191 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2192 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2193 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2194 default:
2195 return _IOC_SIZE(cmd);
2196 }
2197}
2198
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002199static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2200 void * __user *user_ptr, void ***kernel_ptr)
2201{
2202 int ret = 0;
2203
2204 switch (cmd) {
2205 case VIDIOC_QUERYBUF:
2206 case VIDIOC_QBUF:
2207 case VIDIOC_DQBUF: {
2208 struct v4l2_buffer *buf = parg;
2209
2210 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2211 if (buf->length > VIDEO_MAX_PLANES) {
2212 ret = -EINVAL;
2213 break;
2214 }
2215 *user_ptr = (void __user *)buf->m.planes;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002216 *kernel_ptr = (void *)&buf->m.planes;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002217 *array_size = sizeof(struct v4l2_plane) * buf->length;
2218 ret = 1;
2219 }
2220 break;
2221 }
2222
2223 case VIDIOC_S_EXT_CTRLS:
2224 case VIDIOC_G_EXT_CTRLS:
2225 case VIDIOC_TRY_EXT_CTRLS: {
2226 struct v4l2_ext_controls *ctrls = parg;
2227
2228 if (ctrls->count != 0) {
2229 *user_ptr = (void __user *)ctrls->controls;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002230 *kernel_ptr = (void *)&ctrls->controls;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002231 *array_size = sizeof(struct v4l2_ext_control)
2232 * ctrls->count;
2233 ret = 1;
2234 }
2235 break;
2236 }
2237 }
2238
2239 return ret;
2240}
2241
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002242long
2243video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2244 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002245{
2246 char sbuf[128];
2247 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002248 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002249 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002250 bool has_array_args;
2251 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002252 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002253 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002254
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002255 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002256 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002257 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2258 parg = sbuf;
2259 } else {
2260 /* too big to allocate from stack */
2261 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2262 if (NULL == mbuf)
2263 return -ENOMEM;
2264 parg = mbuf;
2265 }
2266
2267 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002268 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2269 unsigned long n = cmd_input_size(cmd);
2270
2271 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002272 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002273
2274 /* zero out anything we don't copy from userspace */
2275 if (n < _IOC_SIZE(cmd))
2276 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002277 } else {
2278 /* read-only ioctl */
2279 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002280 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002281 }
2282
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002283 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2284 if (err < 0)
2285 goto out;
2286 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002287
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002288 if (has_array_args) {
2289 /*
2290 * When adding new types of array args, make sure that the
2291 * parent argument to ioctl (which contains the pointer to the
2292 * array) fits into sbuf (so that mbuf will still remain
2293 * unused up to here).
2294 */
2295 mbuf = kmalloc(array_size, GFP_KERNEL);
2296 err = -ENOMEM;
2297 if (NULL == mbuf)
2298 goto out_array_args;
2299 err = -EFAULT;
2300 if (copy_from_user(mbuf, user_ptr, array_size))
2301 goto out_array_args;
2302 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002303 }
2304
2305 /* Handles IOCTL */
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002306 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002307 if (err == -ENOIOCTLCMD)
2308 err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002309
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002310 if (has_array_args) {
2311 *kernel_ptr = user_ptr;
2312 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002313 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002314 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002315 }
2316 if (err < 0)
2317 goto out;
2318
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002319out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002320 /* Copy results into user buffer */
2321 switch (_IOC_DIR(cmd)) {
2322 case _IOC_READ:
2323 case (_IOC_WRITE | _IOC_READ):
2324 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2325 err = -EFAULT;
2326 break;
2327 }
2328
2329out:
2330 kfree(mbuf);
2331 return err;
2332}
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002333EXPORT_SYMBOL(video_usercopy);
2334
2335long video_ioctl2(struct file *file,
2336 unsigned int cmd, unsigned long arg)
2337{
2338 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2339}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002340EXPORT_SYMBOL(video_ioctl2);