blob: 29f7a7df34c35ec18ebf0e7e762af073ec2bbe8c [file] [log] [blame]
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001/*
2 * Video capture interface for Linux version 2
3 *
4 * A generic framework to process V4L2 ioctl commands.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
Alan Coxd9b01442008-10-27 15:13:47 -030011 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
Hans Verkuil35ea11f2008-07-20 08:12:02 -030012 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
13 */
14
15#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030017#include <linux/types.h>
18#include <linux/kernel.h>
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -030019#include <linux/version.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030020
Hans Verkuil35ea11f2008-07-20 08:12:02 -030021#include <linux/videodev2.h>
22
Hans Verkuil35ea11f2008-07-20 08:12:02 -030023#include <media/v4l2-common.h>
24#include <media/v4l2-ioctl.h>
Hans Verkuil11bbc1c2010-05-16 09:24:06 -030025#include <media/v4l2-ctrls.h>
Sakari Ailusd3d7c962010-03-27 11:02:10 -030026#include <media/v4l2-fh.h>
27#include <media/v4l2-event.h>
Hans Verkuil99cd47bc2011-03-11 19:00:56 -030028#include <media/v4l2-device.h>
Hans Verkuil80b36e02009-02-07 11:00:02 -030029#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030030
31#define dbgarg(cmd, fmt, arg...) \
32 do { \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
37 } \
38 } while (0)
39
40#define dbgarg2(fmt, arg...) \
41 do { \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
44 } while (0)
45
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030046#define dbgarg3(fmt, arg...) \
47 do { \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
50 } while (0)
51
Lucas De Marchi25985ed2011-03-30 22:57:33 -030052/* Zero out the end of the struct pointed to by p. Everything after, but
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030053 * not including, the specified field is cleared. */
54#define CLEAR_AFTER_FIELD(p, field) \
55 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
57
Hans Verkuil35ea11f2008-07-20 08:12:02 -030058struct std_descr {
59 v4l2_std_id std;
60 const char *descr;
61};
62
63static const struct std_descr standards[] = {
64 { V4L2_STD_NTSC, "NTSC" },
65 { V4L2_STD_NTSC_M, "NTSC-M" },
66 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
67 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
68 { V4L2_STD_NTSC_443, "NTSC-443" },
69 { V4L2_STD_PAL, "PAL" },
70 { V4L2_STD_PAL_BG, "PAL-BG" },
71 { V4L2_STD_PAL_B, "PAL-B" },
72 { V4L2_STD_PAL_B1, "PAL-B1" },
73 { V4L2_STD_PAL_G, "PAL-G" },
74 { V4L2_STD_PAL_H, "PAL-H" },
75 { V4L2_STD_PAL_I, "PAL-I" },
76 { V4L2_STD_PAL_DK, "PAL-DK" },
77 { V4L2_STD_PAL_D, "PAL-D" },
78 { V4L2_STD_PAL_D1, "PAL-D1" },
79 { V4L2_STD_PAL_K, "PAL-K" },
80 { V4L2_STD_PAL_M, "PAL-M" },
81 { V4L2_STD_PAL_N, "PAL-N" },
82 { V4L2_STD_PAL_Nc, "PAL-Nc" },
83 { V4L2_STD_PAL_60, "PAL-60" },
84 { V4L2_STD_SECAM, "SECAM" },
85 { V4L2_STD_SECAM_B, "SECAM-B" },
86 { V4L2_STD_SECAM_G, "SECAM-G" },
87 { V4L2_STD_SECAM_H, "SECAM-H" },
88 { V4L2_STD_SECAM_DK, "SECAM-DK" },
89 { V4L2_STD_SECAM_D, "SECAM-D" },
90 { V4L2_STD_SECAM_K, "SECAM-K" },
91 { V4L2_STD_SECAM_K1, "SECAM-K1" },
92 { V4L2_STD_SECAM_L, "SECAM-L" },
93 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
94 { 0, "Unknown" }
95};
96
97/* video4linux standard ID conversion to standard name
98 */
99const char *v4l2_norm_to_name(v4l2_std_id id)
100{
101 u32 myid = id;
102 int i;
103
104 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
105 64 bit comparations. So, on that architecture, with some gcc
106 variants, compilation fails. Currently, the max value is 30bit wide.
107 */
108 BUG_ON(myid != id);
109
110 for (i = 0; standards[i].std; i++)
111 if (myid == standards[i].std)
112 break;
113 return standards[i].descr;
114}
115EXPORT_SYMBOL(v4l2_norm_to_name);
116
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300117/* Returns frame period for the given standard */
118void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
119{
120 if (id & V4L2_STD_525_60) {
121 frameperiod->numerator = 1001;
122 frameperiod->denominator = 30000;
123 } else {
124 frameperiod->numerator = 1;
125 frameperiod->denominator = 25;
126 }
127}
128EXPORT_SYMBOL(v4l2_video_std_frame_period);
129
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300130/* Fill in the fields of a v4l2_standard structure according to the
131 'id' and 'transmission' parameters. Returns negative on error. */
132int v4l2_video_std_construct(struct v4l2_standard *vs,
133 int id, const char *name)
134{
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300135 vs->id = id;
136 v4l2_video_std_frame_period(id, &vs->frameperiod);
137 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300138 strlcpy(vs->name, name, sizeof(vs->name));
139 return 0;
140}
141EXPORT_SYMBOL(v4l2_video_std_construct);
142
143/* ----------------------------------------------------------------- */
144/* some arrays for pretty-printing debug messages of enum types */
145
146const char *v4l2_field_names[] = {
147 [V4L2_FIELD_ANY] = "any",
148 [V4L2_FIELD_NONE] = "none",
149 [V4L2_FIELD_TOP] = "top",
150 [V4L2_FIELD_BOTTOM] = "bottom",
151 [V4L2_FIELD_INTERLACED] = "interlaced",
152 [V4L2_FIELD_SEQ_TB] = "seq-tb",
153 [V4L2_FIELD_SEQ_BT] = "seq-bt",
154 [V4L2_FIELD_ALTERNATE] = "alternate",
155 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
156 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
157};
158EXPORT_SYMBOL(v4l2_field_names);
159
160const char *v4l2_type_names[] = {
161 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
162 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
163 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
164 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
165 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
166 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
167 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
168 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
Pawel Osciakf8f39142010-07-29 14:44:25 -0300169 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
170 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300171};
172EXPORT_SYMBOL(v4l2_type_names);
173
174static const char *v4l2_memory_names[] = {
175 [V4L2_MEMORY_MMAP] = "mmap",
176 [V4L2_MEMORY_USERPTR] = "userptr",
177 [V4L2_MEMORY_OVERLAY] = "overlay",
178};
179
180#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
181 arr[a] : "unknown")
182
183/* ------------------------------------------------------------------ */
184/* debug help functions */
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300185static const char *v4l2_ioctls[] = {
186 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
187 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
188 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
189 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
190 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
191 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
192 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
193 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
194 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
195 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
196 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
197 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
198 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
199 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
200 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
201 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
202 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
203 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
204 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
205 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
206 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
207 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
208 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
209 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
210 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
211 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
212 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
213 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
214 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
215 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
216 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
217 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
218 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
219 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
220 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
221 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
222 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
223 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
224 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
225 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
226 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
227 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
228 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
229 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
230 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
231 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
232 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
233 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
234 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
235 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
236 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
237 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
238 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
239 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
240 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
241#if 1
242 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
243 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
244 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
245 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
246 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
247
248 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
249 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
250
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300251 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300252 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
253#endif
Muralidharan Karicherib6456c02009-11-19 12:00:31 -0300254 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS)] = "VIDIOC_ENUM_DV_PRESETS",
255 [_IOC_NR(VIDIOC_S_DV_PRESET)] = "VIDIOC_S_DV_PRESET",
256 [_IOC_NR(VIDIOC_G_DV_PRESET)] = "VIDIOC_G_DV_PRESET",
257 [_IOC_NR(VIDIOC_QUERY_DV_PRESET)] = "VIDIOC_QUERY_DV_PRESET",
258 [_IOC_NR(VIDIOC_S_DV_TIMINGS)] = "VIDIOC_S_DV_TIMINGS",
259 [_IOC_NR(VIDIOC_G_DV_TIMINGS)] = "VIDIOC_G_DV_TIMINGS",
Sakari Ailusfda10212010-02-24 19:19:05 -0300260 [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
261 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
262 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300263};
264#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
265
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300266/* Common ioctl debug function. This function can be used by
267 external ioctl messages as well as internal V4L ioctl */
268void v4l_printk_ioctl(unsigned int cmd)
269{
270 char *dir, *type;
271
272 switch (_IOC_TYPE(cmd)) {
273 case 'd':
Hans Verkuil78a3b4d2009-04-01 03:41:09 -0300274 type = "v4l2_int";
275 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300276 case 'V':
277 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
278 type = "v4l2";
279 break;
280 }
281 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
282 return;
283 default:
284 type = "unknown";
285 }
286
287 switch (_IOC_DIR(cmd)) {
288 case _IOC_NONE: dir = "--"; break;
289 case _IOC_READ: dir = "r-"; break;
290 case _IOC_WRITE: dir = "-w"; break;
291 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
292 default: dir = "*ERR*"; break;
293 }
294 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
295 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
296}
297EXPORT_SYMBOL(v4l_printk_ioctl);
298
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300299static void dbgbuf(unsigned int cmd, struct video_device *vfd,
300 struct v4l2_buffer *p)
301{
302 struct v4l2_timecode *tc = &p->timecode;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300303 struct v4l2_plane *plane;
304 int i;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300305
306 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300307 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300308 p->timestamp.tv_sec / 3600,
309 (int)(p->timestamp.tv_sec / 60) % 60,
310 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300311 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300312 p->index,
313 prt_names(p->type, v4l2_type_names),
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300314 p->flags, p->field, p->sequence,
315 prt_names(p->memory, v4l2_memory_names));
316
317 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
318 for (i = 0; i < p->length; ++i) {
319 plane = &p->m.planes[i];
320 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
321 "offset/userptr=0x%08lx, length=%d\n",
322 i, plane->bytesused, plane->data_offset,
323 plane->m.userptr, plane->length);
324 }
325 } else {
326 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
327 p->bytesused, p->m.userptr, p->length);
328 }
329
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300330 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
331 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
332 tc->hours, tc->minutes, tc->seconds,
333 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
334}
335
336static inline void dbgrect(struct video_device *vfd, char *s,
337 struct v4l2_rect *r)
338{
339 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
340 r->width, r->height);
341};
342
343static inline void v4l_print_pix_fmt(struct video_device *vfd,
344 struct v4l2_pix_format *fmt)
345{
346 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
347 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
348 fmt->width, fmt->height,
349 (fmt->pixelformat & 0xff),
350 (fmt->pixelformat >> 8) & 0xff,
351 (fmt->pixelformat >> 16) & 0xff,
352 (fmt->pixelformat >> 24) & 0xff,
353 prt_names(fmt->field, v4l2_field_names),
354 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
355};
356
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300357static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
358 struct v4l2_pix_format_mplane *fmt)
359{
360 int i;
361
362 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
363 "colorspace=%d, num_planes=%d\n",
364 fmt->width, fmt->height,
365 (fmt->pixelformat & 0xff),
366 (fmt->pixelformat >> 8) & 0xff,
367 (fmt->pixelformat >> 16) & 0xff,
368 (fmt->pixelformat >> 24) & 0xff,
369 prt_names(fmt->field, v4l2_field_names),
370 fmt->colorspace, fmt->num_planes);
371
372 for (i = 0; i < fmt->num_planes; ++i)
373 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
374 fmt->plane_fmt[i].bytesperline,
375 fmt->plane_fmt[i].sizeimage);
376}
377
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300378static inline void v4l_print_ext_ctrls(unsigned int cmd,
379 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
380{
381 __u32 i;
382
383 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
384 return;
385 dbgarg(cmd, "");
386 printk(KERN_CONT "class=0x%x", c->ctrl_class);
387 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300388 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300389 printk(KERN_CONT " id/val=0x%x/0x%x",
390 c->controls[i].id, c->controls[i].value);
391 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300392 printk(KERN_CONT " id=0x%x,size=%u",
393 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300394 }
395 printk(KERN_CONT "\n");
396};
397
398static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
399{
400 __u32 i;
401
402 /* zero the reserved fields */
403 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300404 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300405 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300406
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300407 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
408 when using extended controls.
409 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
410 is it allowed for backwards compatibility.
411 */
412 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
413 return 0;
414 /* Check that all controls are from the same control class. */
415 for (i = 0; i < c->count; i++) {
416 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
417 c->error_idx = i;
418 return 0;
419 }
420 }
421 return 1;
422}
423
Hans Verkuila3998102008-07-21 02:57:38 -0300424static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300425{
Hans Verkuila3998102008-07-21 02:57:38 -0300426 if (ops == NULL)
427 return -EINVAL;
428
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300429 switch (type) {
430 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300431 if (ops->vidioc_g_fmt_vid_cap ||
432 ops->vidioc_g_fmt_vid_cap_mplane)
433 return 0;
434 break;
435 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
436 if (ops->vidioc_g_fmt_vid_cap_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300437 return 0;
438 break;
439 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300440 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300441 return 0;
442 break;
443 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300444 if (ops->vidioc_g_fmt_vid_out ||
445 ops->vidioc_g_fmt_vid_out_mplane)
446 return 0;
447 break;
448 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
449 if (ops->vidioc_g_fmt_vid_out_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300450 return 0;
451 break;
452 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300453 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300454 return 0;
455 break;
456 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300457 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300458 return 0;
459 break;
460 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300461 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300462 return 0;
463 break;
464 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300465 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300466 return 0;
467 break;
468 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300469 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300470 return 0;
471 break;
472 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300473 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300474 return 0;
475 break;
476 }
477 return -EINVAL;
478}
479
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300480/**
481 * fmt_sp_to_mp() - Convert a single-plane format to its multi-planar 1-plane
482 * equivalent
483 */
484static int fmt_sp_to_mp(const struct v4l2_format *f_sp,
485 struct v4l2_format *f_mp)
486{
487 struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
488 const struct v4l2_pix_format *pix = &f_sp->fmt.pix;
489
490 if (f_sp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
491 f_mp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
492 else if (f_sp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
493 f_mp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
494 else
495 return -EINVAL;
496
497 pix_mp->width = pix->width;
498 pix_mp->height = pix->height;
499 pix_mp->pixelformat = pix->pixelformat;
500 pix_mp->field = pix->field;
501 pix_mp->colorspace = pix->colorspace;
502 pix_mp->num_planes = 1;
503 pix_mp->plane_fmt[0].sizeimage = pix->sizeimage;
504 pix_mp->plane_fmt[0].bytesperline = pix->bytesperline;
505
506 return 0;
507}
508
509/**
510 * fmt_mp_to_sp() - Convert a multi-planar 1-plane format to its single-planar
511 * equivalent
512 */
513static int fmt_mp_to_sp(const struct v4l2_format *f_mp,
514 struct v4l2_format *f_sp)
515{
516 const struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
517 struct v4l2_pix_format *pix = &f_sp->fmt.pix;
518
519 if (f_mp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
520 f_sp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
521 else if (f_mp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
522 f_sp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
523 else
524 return -EINVAL;
525
526 pix->width = pix_mp->width;
527 pix->height = pix_mp->height;
528 pix->pixelformat = pix_mp->pixelformat;
529 pix->field = pix_mp->field;
530 pix->colorspace = pix_mp->colorspace;
531 pix->sizeimage = pix_mp->plane_fmt[0].sizeimage;
532 pix->bytesperline = pix_mp->plane_fmt[0].bytesperline;
533
534 return 0;
535}
536
Hans Verkuil069b7472008-12-30 07:04:34 -0300537static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300538 unsigned int cmd, void *arg)
539{
540 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300541 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300542 void *fh = file->private_data;
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300543 struct v4l2_fh *vfh = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300544 struct v4l2_format f_copy;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300545 int use_fh_prio = 0;
Hans Verkuil069b7472008-12-30 07:04:34 -0300546 long ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300547
Hans Verkuil6a717882010-04-06 15:56:08 -0300548 if (ops == NULL) {
549 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
550 vfd->name);
551 return -EINVAL;
552 }
553
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300554 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
555 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
556 v4l_print_ioctl(vfd->name, cmd);
557 printk(KERN_CONT "\n");
558 }
559
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300560 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300561 vfh = file->private_data;
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300562 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
563 }
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300564
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300565 if (use_fh_prio) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300566 switch (cmd) {
567 case VIDIOC_S_CTRL:
568 case VIDIOC_S_STD:
569 case VIDIOC_S_INPUT:
570 case VIDIOC_S_OUTPUT:
571 case VIDIOC_S_TUNER:
572 case VIDIOC_S_FREQUENCY:
573 case VIDIOC_S_FMT:
574 case VIDIOC_S_CROP:
575 case VIDIOC_S_AUDIO:
576 case VIDIOC_S_AUDOUT:
577 case VIDIOC_S_EXT_CTRLS:
578 case VIDIOC_S_FBUF:
579 case VIDIOC_S_PRIORITY:
580 case VIDIOC_S_DV_PRESET:
581 case VIDIOC_S_DV_TIMINGS:
582 case VIDIOC_S_JPEGCOMP:
583 case VIDIOC_S_MODULATOR:
584 case VIDIOC_S_PARM:
585 case VIDIOC_S_HW_FREQ_SEEK:
586 case VIDIOC_ENCODER_CMD:
587 case VIDIOC_OVERLAY:
588 case VIDIOC_REQBUFS:
589 case VIDIOC_STREAMON:
590 case VIDIOC_STREAMOFF:
591 ret = v4l2_prio_check(vfd->prio, vfh->prio);
592 if (ret)
593 goto exit_prio;
594 ret = -EINVAL;
595 break;
596 }
597 }
598
Hans Verkuil6a717882010-04-06 15:56:08 -0300599 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300600
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300601 /* --- capabilities ------------------------------------------ */
602 case VIDIOC_QUERYCAP:
603 {
604 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300605
Hans Verkuila3998102008-07-21 02:57:38 -0300606 if (!ops->vidioc_querycap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300607 break;
608
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -0300609 cap->version = LINUX_VERSION_CODE;
Hans Verkuila3998102008-07-21 02:57:38 -0300610 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300611 if (!ret)
612 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
613 "version=0x%08x, "
614 "capabilities=0x%08x\n",
615 cap->driver, cap->card, cap->bus_info,
616 cap->version,
617 cap->capabilities);
618 break;
619 }
620
621 /* --- priority ------------------------------------------ */
622 case VIDIOC_G_PRIORITY:
623 {
624 enum v4l2_priority *p = arg;
625
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300626 if (ops->vidioc_g_priority) {
627 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300628 } else if (use_fh_prio) {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300629 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
630 ret = 0;
631 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300632 if (!ret)
633 dbgarg(cmd, "priority is %d\n", *p);
634 break;
635 }
636 case VIDIOC_S_PRIORITY:
637 {
638 enum v4l2_priority *p = arg;
639
Hans Verkuilb1a873a2011-03-22 10:14:07 -0300640 if (!ops->vidioc_s_priority && !use_fh_prio)
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300641 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300642 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuil99cd47bc2011-03-11 19:00:56 -0300643 if (ops->vidioc_s_priority)
644 ret = ops->vidioc_s_priority(file, fh, *p);
645 else
646 ret = v4l2_prio_change(&vfd->v4l2_dev->prio, &vfh->prio, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300647 break;
648 }
649
650 /* --- capture ioctls ---------------------------------------- */
651 case VIDIOC_ENUM_FMT:
652 {
653 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300654
Trent Piepho19c96e42009-03-04 01:21:02 -0300655 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300656 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300657 if (ops->vidioc_enum_fmt_vid_cap)
658 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300659 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300660 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
661 if (ops->vidioc_enum_fmt_vid_cap_mplane)
662 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
663 fh, f);
664 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300665 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300666 if (ops->vidioc_enum_fmt_vid_overlay)
667 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300668 fh, f);
669 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300670 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300671 if (ops->vidioc_enum_fmt_vid_out)
672 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300673 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300674 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
675 if (ops->vidioc_enum_fmt_vid_out_mplane)
676 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
677 fh, f);
678 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300679 case V4L2_BUF_TYPE_PRIVATE:
Hans Verkuila3998102008-07-21 02:57:38 -0300680 if (ops->vidioc_enum_fmt_type_private)
681 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300682 fh, f);
683 break;
684 default:
685 break;
686 }
687 if (!ret)
688 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
689 "pixelformat=%c%c%c%c, description='%s'\n",
690 f->index, f->type, f->flags,
691 (f->pixelformat & 0xff),
692 (f->pixelformat >> 8) & 0xff,
693 (f->pixelformat >> 16) & 0xff,
694 (f->pixelformat >> 24) & 0xff,
695 f->description);
696 break;
697 }
698 case VIDIOC_G_FMT:
699 {
700 struct v4l2_format *f = (struct v4l2_format *)arg;
701
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300702 /* FIXME: Should be one dump per type */
703 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
704
705 switch (f->type) {
706 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300707 if (ops->vidioc_g_fmt_vid_cap) {
Hans Verkuila3998102008-07-21 02:57:38 -0300708 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300709 } else if (ops->vidioc_g_fmt_vid_cap_mplane) {
710 if (fmt_sp_to_mp(f, &f_copy))
711 break;
712 ret = ops->vidioc_g_fmt_vid_cap_mplane(file, fh,
713 &f_copy);
714 if (ret)
715 break;
716
717 /* Driver is currently in multi-planar format,
718 * we can't return it in single-planar API*/
719 if (f_copy.fmt.pix_mp.num_planes > 1) {
720 ret = -EBUSY;
721 break;
722 }
723
724 ret = fmt_mp_to_sp(&f_copy, f);
725 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300726 if (!ret)
727 v4l_print_pix_fmt(vfd, &f->fmt.pix);
728 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300729 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
730 if (ops->vidioc_g_fmt_vid_cap_mplane) {
731 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
732 fh, f);
733 } else if (ops->vidioc_g_fmt_vid_cap) {
734 if (fmt_mp_to_sp(f, &f_copy))
735 break;
736 ret = ops->vidioc_g_fmt_vid_cap(file,
737 fh, &f_copy);
738 if (ret)
739 break;
740
741 ret = fmt_sp_to_mp(&f_copy, f);
742 }
743 if (!ret)
744 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
745 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300746 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300747 if (ops->vidioc_g_fmt_vid_overlay)
748 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300749 fh, f);
750 break;
751 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300752 if (ops->vidioc_g_fmt_vid_out) {
Hans Verkuila3998102008-07-21 02:57:38 -0300753 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300754 } else if (ops->vidioc_g_fmt_vid_out_mplane) {
755 if (fmt_sp_to_mp(f, &f_copy))
756 break;
757 ret = ops->vidioc_g_fmt_vid_out_mplane(file, fh,
758 &f_copy);
759 if (ret)
760 break;
761
762 /* Driver is currently in multi-planar format,
763 * we can't return it in single-planar API*/
764 if (f_copy.fmt.pix_mp.num_planes > 1) {
765 ret = -EBUSY;
766 break;
767 }
768
769 ret = fmt_mp_to_sp(&f_copy, f);
770 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300771 if (!ret)
772 v4l_print_pix_fmt(vfd, &f->fmt.pix);
773 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300774 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
775 if (ops->vidioc_g_fmt_vid_out_mplane) {
776 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
777 fh, f);
778 } else if (ops->vidioc_g_fmt_vid_out) {
779 if (fmt_mp_to_sp(f, &f_copy))
780 break;
781 ret = ops->vidioc_g_fmt_vid_out(file,
782 fh, &f_copy);
783 if (ret)
784 break;
785
786 ret = fmt_sp_to_mp(&f_copy, f);
787 }
788 if (!ret)
789 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
790 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300791 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300792 if (ops->vidioc_g_fmt_vid_out_overlay)
793 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300794 fh, f);
795 break;
796 case V4L2_BUF_TYPE_VBI_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300797 if (ops->vidioc_g_fmt_vbi_cap)
798 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300799 break;
800 case V4L2_BUF_TYPE_VBI_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300801 if (ops->vidioc_g_fmt_vbi_out)
802 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300803 break;
804 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300805 if (ops->vidioc_g_fmt_sliced_vbi_cap)
806 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300807 fh, f);
808 break;
809 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300810 if (ops->vidioc_g_fmt_sliced_vbi_out)
811 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300812 fh, f);
813 break;
814 case V4L2_BUF_TYPE_PRIVATE:
Hans Verkuila3998102008-07-21 02:57:38 -0300815 if (ops->vidioc_g_fmt_type_private)
816 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300817 fh, f);
818 break;
819 }
820
821 break;
822 }
823 case VIDIOC_S_FMT:
824 {
825 struct v4l2_format *f = (struct v4l2_format *)arg;
826
827 /* FIXME: Should be one dump per type */
828 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
829
830 switch (f->type) {
831 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300832 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300833 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300834 if (ops->vidioc_s_fmt_vid_cap) {
Hans Verkuila3998102008-07-21 02:57:38 -0300835 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300836 } else if (ops->vidioc_s_fmt_vid_cap_mplane) {
837 if (fmt_sp_to_mp(f, &f_copy))
838 break;
839 ret = ops->vidioc_s_fmt_vid_cap_mplane(file, fh,
840 &f_copy);
841 if (ret)
842 break;
843
844 if (f_copy.fmt.pix_mp.num_planes > 1) {
845 /* Drivers shouldn't adjust from 1-plane
846 * to more than 1-plane formats */
847 ret = -EBUSY;
848 WARN_ON(1);
849 break;
850 }
851
852 ret = fmt_mp_to_sp(&f_copy, f);
853 }
854 break;
855 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
856 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
857 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
858 if (ops->vidioc_s_fmt_vid_cap_mplane) {
859 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
860 fh, f);
861 } else if (ops->vidioc_s_fmt_vid_cap &&
862 f->fmt.pix_mp.num_planes == 1) {
863 if (fmt_mp_to_sp(f, &f_copy))
864 break;
865 ret = ops->vidioc_s_fmt_vid_cap(file,
866 fh, &f_copy);
867 if (ret)
868 break;
869
870 ret = fmt_sp_to_mp(&f_copy, f);
871 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300872 break;
873 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300874 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300875 if (ops->vidioc_s_fmt_vid_overlay)
876 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300877 fh, f);
878 break;
879 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300880 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300881 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300882 if (ops->vidioc_s_fmt_vid_out) {
Hans Verkuila3998102008-07-21 02:57:38 -0300883 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300884 } else if (ops->vidioc_s_fmt_vid_out_mplane) {
885 if (fmt_sp_to_mp(f, &f_copy))
886 break;
887 ret = ops->vidioc_s_fmt_vid_out_mplane(file, fh,
888 &f_copy);
889 if (ret)
890 break;
891
892 if (f_copy.fmt.pix_mp.num_planes > 1) {
893 /* Drivers shouldn't adjust from 1-plane
894 * to more than 1-plane formats */
895 ret = -EBUSY;
896 WARN_ON(1);
897 break;
898 }
899
900 ret = fmt_mp_to_sp(&f_copy, f);
901 }
902 break;
903 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
904 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
905 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
906 if (ops->vidioc_s_fmt_vid_out_mplane) {
907 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
908 fh, f);
909 } else if (ops->vidioc_s_fmt_vid_out &&
910 f->fmt.pix_mp.num_planes == 1) {
911 if (fmt_mp_to_sp(f, &f_copy))
912 break;
913 ret = ops->vidioc_s_fmt_vid_out(file,
914 fh, &f_copy);
915 if (ret)
916 break;
917
918 ret = fmt_mp_to_sp(&f_copy, f);
919 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300920 break;
921 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300922 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300923 if (ops->vidioc_s_fmt_vid_out_overlay)
924 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300925 fh, f);
926 break;
927 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300928 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300929 if (ops->vidioc_s_fmt_vbi_cap)
930 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300931 break;
932 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300933 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300934 if (ops->vidioc_s_fmt_vbi_out)
935 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300936 break;
937 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300938 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300939 if (ops->vidioc_s_fmt_sliced_vbi_cap)
940 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300941 fh, f);
942 break;
943 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300944 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300945 if (ops->vidioc_s_fmt_sliced_vbi_out)
946 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300947 fh, f);
948 break;
949 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300950 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Hans Verkuila3998102008-07-21 02:57:38 -0300951 if (ops->vidioc_s_fmt_type_private)
952 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300953 fh, f);
954 break;
955 }
956 break;
957 }
958 case VIDIOC_TRY_FMT:
959 {
960 struct v4l2_format *f = (struct v4l2_format *)arg;
961
962 /* FIXME: Should be one dump per type */
963 dbgarg(cmd, "type=%s\n", prt_names(f->type,
964 v4l2_type_names));
965 switch (f->type) {
966 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300967 CLEAR_AFTER_FIELD(f, fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300968 if (ops->vidioc_try_fmt_vid_cap) {
Hans Verkuila3998102008-07-21 02:57:38 -0300969 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300970 } else if (ops->vidioc_try_fmt_vid_cap_mplane) {
971 if (fmt_sp_to_mp(f, &f_copy))
972 break;
973 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
974 fh, &f_copy);
975 if (ret)
976 break;
977
978 if (f_copy.fmt.pix_mp.num_planes > 1) {
979 /* Drivers shouldn't adjust from 1-plane
980 * to more than 1-plane formats */
981 ret = -EBUSY;
982 WARN_ON(1);
983 break;
984 }
985 ret = fmt_mp_to_sp(&f_copy, f);
986 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300987 if (!ret)
988 v4l_print_pix_fmt(vfd, &f->fmt.pix);
989 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300990 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
991 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
992 if (ops->vidioc_try_fmt_vid_cap_mplane) {
993 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
994 fh, f);
995 } else if (ops->vidioc_try_fmt_vid_cap &&
996 f->fmt.pix_mp.num_planes == 1) {
997 if (fmt_mp_to_sp(f, &f_copy))
998 break;
999 ret = ops->vidioc_try_fmt_vid_cap(file,
1000 fh, &f_copy);
1001 if (ret)
1002 break;
1003
1004 ret = fmt_sp_to_mp(&f_copy, f);
1005 }
1006 if (!ret)
1007 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
1008 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001009 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001010 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -03001011 if (ops->vidioc_try_fmt_vid_overlay)
1012 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001013 fh, f);
1014 break;
1015 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001016 CLEAR_AFTER_FIELD(f, fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001017 if (ops->vidioc_try_fmt_vid_out) {
Hans Verkuila3998102008-07-21 02:57:38 -03001018 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001019 } else if (ops->vidioc_try_fmt_vid_out_mplane) {
1020 if (fmt_sp_to_mp(f, &f_copy))
1021 break;
1022 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
1023 fh, &f_copy);
1024 if (ret)
1025 break;
1026
1027 if (f_copy.fmt.pix_mp.num_planes > 1) {
1028 /* Drivers shouldn't adjust from 1-plane
1029 * to more than 1-plane formats */
1030 ret = -EBUSY;
1031 WARN_ON(1);
1032 break;
1033 }
1034 ret = fmt_mp_to_sp(&f_copy, f);
1035 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001036 if (!ret)
1037 v4l_print_pix_fmt(vfd, &f->fmt.pix);
1038 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001039 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1040 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
1041 if (ops->vidioc_try_fmt_vid_out_mplane) {
1042 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
1043 fh, f);
1044 } else if (ops->vidioc_try_fmt_vid_out &&
1045 f->fmt.pix_mp.num_planes == 1) {
1046 if (fmt_mp_to_sp(f, &f_copy))
1047 break;
1048 ret = ops->vidioc_try_fmt_vid_out(file,
1049 fh, &f_copy);
1050 if (ret)
1051 break;
1052
1053 ret = fmt_sp_to_mp(&f_copy, f);
1054 }
1055 if (!ret)
1056 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
1057 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001058 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001059 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -03001060 if (ops->vidioc_try_fmt_vid_out_overlay)
1061 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001062 fh, f);
1063 break;
1064 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001065 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -03001066 if (ops->vidioc_try_fmt_vbi_cap)
1067 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001068 break;
1069 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001070 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -03001071 if (ops->vidioc_try_fmt_vbi_out)
1072 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001073 break;
1074 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001075 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -03001076 if (ops->vidioc_try_fmt_sliced_vbi_cap)
1077 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001078 fh, f);
1079 break;
1080 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001081 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -03001082 if (ops->vidioc_try_fmt_sliced_vbi_out)
1083 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001084 fh, f);
1085 break;
1086 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001087 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Hans Verkuila3998102008-07-21 02:57:38 -03001088 if (ops->vidioc_try_fmt_type_private)
1089 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001090 fh, f);
1091 break;
1092 }
1093
1094 break;
1095 }
1096 /* FIXME: Those buf reqs could be handled here,
1097 with some changes on videobuf to allow its header to be included at
1098 videodev2.h or being merged at videodev2.
1099 */
1100 case VIDIOC_REQBUFS:
1101 {
1102 struct v4l2_requestbuffers *p = arg;
1103
Hans Verkuila3998102008-07-21 02:57:38 -03001104 if (!ops->vidioc_reqbufs)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001105 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001106 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001107 if (ret)
1108 break;
1109
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001110 if (p->type < V4L2_BUF_TYPE_PRIVATE)
1111 CLEAR_AFTER_FIELD(p, memory);
1112
Hans Verkuila3998102008-07-21 02:57:38 -03001113 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001114 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
1115 p->count,
1116 prt_names(p->type, v4l2_type_names),
1117 prt_names(p->memory, v4l2_memory_names));
1118 break;
1119 }
1120 case VIDIOC_QUERYBUF:
1121 {
1122 struct v4l2_buffer *p = arg;
1123
Hans Verkuila3998102008-07-21 02:57:38 -03001124 if (!ops->vidioc_querybuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001125 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001126 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001127 if (ret)
1128 break;
1129
Hans Verkuila3998102008-07-21 02:57:38 -03001130 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001131 if (!ret)
1132 dbgbuf(cmd, vfd, p);
1133 break;
1134 }
1135 case VIDIOC_QBUF:
1136 {
1137 struct v4l2_buffer *p = arg;
1138
Hans Verkuila3998102008-07-21 02:57:38 -03001139 if (!ops->vidioc_qbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001140 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001141 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001142 if (ret)
1143 break;
1144
Hans Verkuila3998102008-07-21 02:57:38 -03001145 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001146 if (!ret)
1147 dbgbuf(cmd, vfd, p);
1148 break;
1149 }
1150 case VIDIOC_DQBUF:
1151 {
1152 struct v4l2_buffer *p = arg;
1153
Hans Verkuila3998102008-07-21 02:57:38 -03001154 if (!ops->vidioc_dqbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001155 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001156 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001157 if (ret)
1158 break;
1159
Hans Verkuila3998102008-07-21 02:57:38 -03001160 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001161 if (!ret)
1162 dbgbuf(cmd, vfd, p);
1163 break;
1164 }
1165 case VIDIOC_OVERLAY:
1166 {
1167 int *i = arg;
1168
Hans Verkuila3998102008-07-21 02:57:38 -03001169 if (!ops->vidioc_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001170 break;
1171 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001172 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001173 break;
1174 }
1175 case VIDIOC_G_FBUF:
1176 {
1177 struct v4l2_framebuffer *p = arg;
1178
Hans Verkuila3998102008-07-21 02:57:38 -03001179 if (!ops->vidioc_g_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001180 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001181 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001182 if (!ret) {
1183 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1184 p->capability, p->flags,
1185 (unsigned long)p->base);
1186 v4l_print_pix_fmt(vfd, &p->fmt);
1187 }
1188 break;
1189 }
1190 case VIDIOC_S_FBUF:
1191 {
1192 struct v4l2_framebuffer *p = arg;
1193
Hans Verkuila3998102008-07-21 02:57:38 -03001194 if (!ops->vidioc_s_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001195 break;
1196 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1197 p->capability, p->flags, (unsigned long)p->base);
1198 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -03001199 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001200 break;
1201 }
1202 case VIDIOC_STREAMON:
1203 {
1204 enum v4l2_buf_type i = *(int *)arg;
1205
Hans Verkuila3998102008-07-21 02:57:38 -03001206 if (!ops->vidioc_streamon)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001207 break;
1208 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001209 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001210 break;
1211 }
1212 case VIDIOC_STREAMOFF:
1213 {
1214 enum v4l2_buf_type i = *(int *)arg;
1215
Hans Verkuila3998102008-07-21 02:57:38 -03001216 if (!ops->vidioc_streamoff)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001217 break;
1218 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001219 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001220 break;
1221 }
1222 /* ---------- tv norms ---------- */
1223 case VIDIOC_ENUMSTD:
1224 {
1225 struct v4l2_standard *p = arg;
1226 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1227 unsigned int index = p->index, i, j = 0;
1228 const char *descr = "";
1229
1230 /* Return norm array in a canonical way */
1231 for (i = 0; i <= index && id; i++) {
1232 /* last std value in the standards array is 0, so this
1233 while always ends there since (id & 0) == 0. */
1234 while ((id & standards[j].std) != standards[j].std)
1235 j++;
1236 curr_id = standards[j].std;
1237 descr = standards[j].descr;
1238 j++;
1239 if (curr_id == 0)
1240 break;
1241 if (curr_id != V4L2_STD_PAL &&
1242 curr_id != V4L2_STD_SECAM &&
1243 curr_id != V4L2_STD_NTSC)
1244 id &= ~curr_id;
1245 }
1246 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001247 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001248
1249 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001250
1251 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1252 "framelines=%d\n", p->index,
1253 (unsigned long long)p->id, p->name,
1254 p->frameperiod.numerator,
1255 p->frameperiod.denominator,
1256 p->framelines);
1257
1258 ret = 0;
1259 break;
1260 }
1261 case VIDIOC_G_STD:
1262 {
1263 v4l2_std_id *id = arg;
1264
1265 ret = 0;
1266 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001267 if (ops->vidioc_g_std)
1268 ret = ops->vidioc_g_std(file, fh, id);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001269 else if (vfd->current_norm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001270 *id = vfd->current_norm;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001271 else
1272 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001273
1274 if (!ret)
1275 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1276 break;
1277 }
1278 case VIDIOC_S_STD:
1279 {
1280 v4l2_std_id *id = arg, norm;
1281
1282 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1283
1284 norm = (*id) & vfd->tvnorms;
1285 if (vfd->tvnorms && !norm) /* Check if std is supported */
1286 break;
1287
1288 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001289 if (ops->vidioc_s_std)
1290 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001291 else
1292 ret = -EINVAL;
1293
1294 /* Updates standard information */
1295 if (ret >= 0)
1296 vfd->current_norm = norm;
1297 break;
1298 }
1299 case VIDIOC_QUERYSTD:
1300 {
1301 v4l2_std_id *p = arg;
1302
Hans Verkuila3998102008-07-21 02:57:38 -03001303 if (!ops->vidioc_querystd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001304 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001305 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001306 if (!ret)
1307 dbgarg(cmd, "detected std=%08Lx\n",
1308 (unsigned long long)*p);
1309 break;
1310 }
1311 /* ------ input switching ---------- */
1312 /* FIXME: Inputs can be handled inside videodev2 */
1313 case VIDIOC_ENUMINPUT:
1314 {
1315 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001316
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001317 /*
1318 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1319 * CAP_STD here based on ioctl handler provided by the
1320 * driver. If the driver doesn't support these
1321 * for a specific input, it must override these flags.
1322 */
1323 if (ops->vidioc_s_std)
1324 p->capabilities |= V4L2_IN_CAP_STD;
1325 if (ops->vidioc_s_dv_preset)
1326 p->capabilities |= V4L2_IN_CAP_PRESETS;
1327 if (ops->vidioc_s_dv_timings)
1328 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1329
Hans Verkuila3998102008-07-21 02:57:38 -03001330 if (!ops->vidioc_enum_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001331 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001332
Hans Verkuila3998102008-07-21 02:57:38 -03001333 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001334 if (!ret)
1335 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1336 "audioset=%d, "
1337 "tuner=%d, std=%08Lx, status=%d\n",
1338 p->index, p->name, p->type, p->audioset,
1339 p->tuner,
1340 (unsigned long long)p->std,
1341 p->status);
1342 break;
1343 }
1344 case VIDIOC_G_INPUT:
1345 {
1346 unsigned int *i = arg;
1347
Hans Verkuila3998102008-07-21 02:57:38 -03001348 if (!ops->vidioc_g_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001349 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001350 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001351 if (!ret)
1352 dbgarg(cmd, "value=%d\n", *i);
1353 break;
1354 }
1355 case VIDIOC_S_INPUT:
1356 {
1357 unsigned int *i = arg;
1358
Hans Verkuila3998102008-07-21 02:57:38 -03001359 if (!ops->vidioc_s_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001360 break;
1361 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001362 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001363 break;
1364 }
1365
1366 /* ------ output switching ---------- */
1367 case VIDIOC_ENUMOUTPUT:
1368 {
1369 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001370
Hans Verkuila3998102008-07-21 02:57:38 -03001371 if (!ops->vidioc_enum_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001372 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001373
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001374 /*
1375 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1376 * CAP_STD here based on ioctl handler provided by the
1377 * driver. If the driver doesn't support these
1378 * for a specific output, it must override these flags.
1379 */
1380 if (ops->vidioc_s_std)
1381 p->capabilities |= V4L2_OUT_CAP_STD;
1382 if (ops->vidioc_s_dv_preset)
1383 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1384 if (ops->vidioc_s_dv_timings)
1385 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1386
Hans Verkuila3998102008-07-21 02:57:38 -03001387 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001388 if (!ret)
1389 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1390 "audioset=0x%x, "
1391 "modulator=%d, std=0x%08Lx\n",
1392 p->index, p->name, p->type, p->audioset,
1393 p->modulator, (unsigned long long)p->std);
1394 break;
1395 }
1396 case VIDIOC_G_OUTPUT:
1397 {
1398 unsigned int *i = arg;
1399
Hans Verkuila3998102008-07-21 02:57:38 -03001400 if (!ops->vidioc_g_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001401 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001402 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001403 if (!ret)
1404 dbgarg(cmd, "value=%d\n", *i);
1405 break;
1406 }
1407 case VIDIOC_S_OUTPUT:
1408 {
1409 unsigned int *i = arg;
1410
Hans Verkuila3998102008-07-21 02:57:38 -03001411 if (!ops->vidioc_s_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001412 break;
1413 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001414 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001415 break;
1416 }
1417
1418 /* --- controls ---------------------------------------------- */
1419 case VIDIOC_QUERYCTRL:
1420 {
1421 struct v4l2_queryctrl *p = arg;
1422
Hans Verkuil2d28b682011-03-12 08:54:43 -03001423 if (vfh && vfh->ctrl_handler)
1424 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1425 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001426 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1427 else if (ops->vidioc_queryctrl)
1428 ret = ops->vidioc_queryctrl(file, fh, p);
1429 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001430 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001431 if (!ret)
1432 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1433 "step=%d, default=%d, flags=0x%08x\n",
1434 p->id, p->type, p->name,
1435 p->minimum, p->maximum,
1436 p->step, p->default_value, p->flags);
1437 else
1438 dbgarg(cmd, "id=0x%x\n", p->id);
1439 break;
1440 }
1441 case VIDIOC_G_CTRL:
1442 {
1443 struct v4l2_control *p = arg;
1444
Hans Verkuil2d28b682011-03-12 08:54:43 -03001445 if (vfh && vfh->ctrl_handler)
1446 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1447 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001448 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1449 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001450 ret = ops->vidioc_g_ctrl(file, fh, p);
1451 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001452 struct v4l2_ext_controls ctrls;
1453 struct v4l2_ext_control ctrl;
1454
1455 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1456 ctrls.count = 1;
1457 ctrls.controls = &ctrl;
1458 ctrl.id = p->id;
1459 ctrl.value = p->value;
1460 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001461 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001462 if (ret == 0)
1463 p->value = ctrl.value;
1464 }
1465 } else
1466 break;
1467 if (!ret)
1468 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1469 else
1470 dbgarg(cmd, "id=0x%x\n", p->id);
1471 break;
1472 }
1473 case VIDIOC_S_CTRL:
1474 {
1475 struct v4l2_control *p = arg;
1476 struct v4l2_ext_controls ctrls;
1477 struct v4l2_ext_control ctrl;
1478
Hans Verkuil2d28b682011-03-12 08:54:43 -03001479 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001480 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001481 break;
1482
1483 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1484
Hans Verkuil2d28b682011-03-12 08:54:43 -03001485 if (vfh && vfh->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001486 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001487 break;
1488 }
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001489 if (vfd->ctrl_handler) {
Hans Verkuilab892ba2011-06-07 06:47:18 -03001490 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001491 break;
1492 }
Hans Verkuila3998102008-07-21 02:57:38 -03001493 if (ops->vidioc_s_ctrl) {
1494 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001495 break;
1496 }
Hans Verkuila3998102008-07-21 02:57:38 -03001497 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001498 break;
1499
1500 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1501 ctrls.count = 1;
1502 ctrls.controls = &ctrl;
1503 ctrl.id = p->id;
1504 ctrl.value = p->value;
1505 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001506 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001507 break;
1508 }
1509 case VIDIOC_G_EXT_CTRLS:
1510 {
1511 struct v4l2_ext_controls *p = arg;
1512
1513 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001514 if (vfh && vfh->ctrl_handler)
1515 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1516 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001517 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
1518 else if (ops->vidioc_g_ext_ctrls && check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001519 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001520 else
1521 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001522 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1523 break;
1524 }
1525 case VIDIOC_S_EXT_CTRLS:
1526 {
1527 struct v4l2_ext_controls *p = arg;
1528
1529 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001530 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1531 !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001532 break;
1533 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001534 if (vfh && vfh->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001535 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001536 else if (vfd->ctrl_handler)
Hans Verkuilab892ba2011-06-07 06:47:18 -03001537 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001538 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001539 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001540 break;
1541 }
1542 case VIDIOC_TRY_EXT_CTRLS:
1543 {
1544 struct v4l2_ext_controls *p = arg;
1545
1546 p->error_idx = p->count;
Hans Verkuil2d28b682011-03-12 08:54:43 -03001547 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1548 !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001549 break;
1550 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil2d28b682011-03-12 08:54:43 -03001551 if (vfh && vfh->ctrl_handler)
1552 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1553 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001554 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1555 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001556 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001557 break;
1558 }
1559 case VIDIOC_QUERYMENU:
1560 {
1561 struct v4l2_querymenu *p = arg;
1562
Hans Verkuil2d28b682011-03-12 08:54:43 -03001563 if (vfh && vfh->ctrl_handler)
1564 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1565 else if (vfd->ctrl_handler)
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001566 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1567 else if (ops->vidioc_querymenu)
1568 ret = ops->vidioc_querymenu(file, fh, p);
1569 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001570 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001571 if (!ret)
1572 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1573 p->id, p->index, p->name);
1574 else
1575 dbgarg(cmd, "id=0x%x, index=%d\n",
1576 p->id, p->index);
1577 break;
1578 }
1579 /* --- audio ---------------------------------------------- */
1580 case VIDIOC_ENUMAUDIO:
1581 {
1582 struct v4l2_audio *p = arg;
1583
Hans Verkuila3998102008-07-21 02:57:38 -03001584 if (!ops->vidioc_enumaudio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001585 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001586 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001587 if (!ret)
1588 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1589 "mode=0x%x\n", p->index, p->name,
1590 p->capability, p->mode);
1591 else
1592 dbgarg(cmd, "index=%d\n", p->index);
1593 break;
1594 }
1595 case VIDIOC_G_AUDIO:
1596 {
1597 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001598
Hans Verkuila3998102008-07-21 02:57:38 -03001599 if (!ops->vidioc_g_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001600 break;
1601
Hans Verkuila3998102008-07-21 02:57:38 -03001602 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001603 if (!ret)
1604 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1605 "mode=0x%x\n", p->index,
1606 p->name, p->capability, p->mode);
1607 else
1608 dbgarg(cmd, "index=%d\n", p->index);
1609 break;
1610 }
1611 case VIDIOC_S_AUDIO:
1612 {
1613 struct v4l2_audio *p = arg;
1614
Hans Verkuila3998102008-07-21 02:57:38 -03001615 if (!ops->vidioc_s_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001616 break;
1617 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1618 "mode=0x%x\n", p->index, p->name,
1619 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001620 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001621 break;
1622 }
1623 case VIDIOC_ENUMAUDOUT:
1624 {
1625 struct v4l2_audioout *p = arg;
1626
Hans Verkuila3998102008-07-21 02:57:38 -03001627 if (!ops->vidioc_enumaudout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001628 break;
1629 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001630 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001631 if (!ret)
1632 dbgarg2("index=%d, name=%s, capability=%d, "
1633 "mode=%d\n", p->index, p->name,
1634 p->capability, p->mode);
1635 break;
1636 }
1637 case VIDIOC_G_AUDOUT:
1638 {
1639 struct v4l2_audioout *p = arg;
1640
Hans Verkuila3998102008-07-21 02:57:38 -03001641 if (!ops->vidioc_g_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001642 break;
Trent Piepho337f9d22009-03-04 01:21:02 -03001643
Hans Verkuila3998102008-07-21 02:57:38 -03001644 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001645 if (!ret)
1646 dbgarg2("index=%d, name=%s, capability=%d, "
1647 "mode=%d\n", p->index, p->name,
1648 p->capability, p->mode);
1649 break;
1650 }
1651 case VIDIOC_S_AUDOUT:
1652 {
1653 struct v4l2_audioout *p = arg;
1654
Hans Verkuila3998102008-07-21 02:57:38 -03001655 if (!ops->vidioc_s_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001656 break;
1657 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1658 "mode=%d\n", p->index, p->name,
1659 p->capability, p->mode);
1660
Hans Verkuila3998102008-07-21 02:57:38 -03001661 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001662 break;
1663 }
1664 case VIDIOC_G_MODULATOR:
1665 {
1666 struct v4l2_modulator *p = arg;
1667
Hans Verkuila3998102008-07-21 02:57:38 -03001668 if (!ops->vidioc_g_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001669 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001670 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001671 if (!ret)
1672 dbgarg(cmd, "index=%d, name=%s, "
1673 "capability=%d, rangelow=%d,"
1674 " rangehigh=%d, txsubchans=%d\n",
1675 p->index, p->name, p->capability,
1676 p->rangelow, p->rangehigh,
1677 p->txsubchans);
1678 break;
1679 }
1680 case VIDIOC_S_MODULATOR:
1681 {
1682 struct v4l2_modulator *p = arg;
1683
Hans Verkuila3998102008-07-21 02:57:38 -03001684 if (!ops->vidioc_s_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001685 break;
1686 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1687 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1688 p->index, p->name, p->capability, p->rangelow,
1689 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001690 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001691 break;
1692 }
1693 case VIDIOC_G_CROP:
1694 {
1695 struct v4l2_crop *p = arg;
1696
Hans Verkuila3998102008-07-21 02:57:38 -03001697 if (!ops->vidioc_g_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001698 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001699
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001700 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001701 ret = ops->vidioc_g_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001702 if (!ret)
1703 dbgrect(vfd, "", &p->c);
1704 break;
1705 }
1706 case VIDIOC_S_CROP:
1707 {
1708 struct v4l2_crop *p = arg;
1709
Hans Verkuila3998102008-07-21 02:57:38 -03001710 if (!ops->vidioc_s_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001711 break;
1712 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1713 dbgrect(vfd, "", &p->c);
Hans Verkuila3998102008-07-21 02:57:38 -03001714 ret = ops->vidioc_s_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001715 break;
1716 }
1717 case VIDIOC_CROPCAP:
1718 {
1719 struct v4l2_cropcap *p = arg;
1720
1721 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuila3998102008-07-21 02:57:38 -03001722 if (!ops->vidioc_cropcap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001723 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001724
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001725 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001726 ret = ops->vidioc_cropcap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001727 if (!ret) {
1728 dbgrect(vfd, "bounds ", &p->bounds);
1729 dbgrect(vfd, "defrect ", &p->defrect);
1730 }
1731 break;
1732 }
1733 case VIDIOC_G_JPEGCOMP:
1734 {
1735 struct v4l2_jpegcompression *p = arg;
1736
Hans Verkuila3998102008-07-21 02:57:38 -03001737 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001738 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001739
Hans Verkuila3998102008-07-21 02:57:38 -03001740 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001741 if (!ret)
1742 dbgarg(cmd, "quality=%d, APPn=%d, "
1743 "APP_len=%d, COM_len=%d, "
1744 "jpeg_markers=%d\n",
1745 p->quality, p->APPn, p->APP_len,
1746 p->COM_len, p->jpeg_markers);
1747 break;
1748 }
1749 case VIDIOC_S_JPEGCOMP:
1750 {
1751 struct v4l2_jpegcompression *p = arg;
1752
Hans Verkuila3998102008-07-21 02:57:38 -03001753 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001754 break;
1755 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1756 "COM_len=%d, jpeg_markers=%d\n",
1757 p->quality, p->APPn, p->APP_len,
1758 p->COM_len, p->jpeg_markers);
Hans Verkuila3998102008-07-21 02:57:38 -03001759 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001760 break;
1761 }
1762 case VIDIOC_G_ENC_INDEX:
1763 {
1764 struct v4l2_enc_idx *p = arg;
1765
Hans Verkuila3998102008-07-21 02:57:38 -03001766 if (!ops->vidioc_g_enc_index)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001767 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001768 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001769 if (!ret)
1770 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1771 p->entries, p->entries_cap);
1772 break;
1773 }
1774 case VIDIOC_ENCODER_CMD:
1775 {
1776 struct v4l2_encoder_cmd *p = arg;
1777
Hans Verkuila3998102008-07-21 02:57:38 -03001778 if (!ops->vidioc_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001779 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001780 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001781 if (!ret)
1782 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1783 break;
1784 }
1785 case VIDIOC_TRY_ENCODER_CMD:
1786 {
1787 struct v4l2_encoder_cmd *p = arg;
1788
Hans Verkuila3998102008-07-21 02:57:38 -03001789 if (!ops->vidioc_try_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001790 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001791 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001792 if (!ret)
1793 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1794 break;
1795 }
1796 case VIDIOC_G_PARM:
1797 {
1798 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001799
Hans Verkuila3998102008-07-21 02:57:38 -03001800 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001801 ret = check_fmt(ops, p->type);
1802 if (ret)
1803 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001804 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001805 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001806 v4l2_std_id std = vfd->current_norm;
1807
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001808 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001809 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001810
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001811 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001812 if (ops->vidioc_g_std)
1813 ret = ops->vidioc_g_std(file, fh, &std);
1814 else if (std == 0)
1815 ret = -EINVAL;
1816 if (ret == 0)
1817 v4l2_video_std_frame_period(std,
1818 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001819 }
1820
1821 dbgarg(cmd, "type=%d\n", p->type);
1822 break;
1823 }
1824 case VIDIOC_S_PARM:
1825 {
1826 struct v4l2_streamparm *p = arg;
1827
Hans Verkuila3998102008-07-21 02:57:38 -03001828 if (!ops->vidioc_s_parm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001829 break;
Trent Piepho34796bc2009-03-28 22:25:35 -03001830 ret = check_fmt(ops, p->type);
1831 if (ret)
1832 break;
1833
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001834 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001835 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001836 break;
1837 }
1838 case VIDIOC_G_TUNER:
1839 {
1840 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001841
Hans Verkuila3998102008-07-21 02:57:38 -03001842 if (!ops->vidioc_g_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001843 break;
1844
Hans Verkuil227690d2011-06-12 06:36:41 -03001845 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1846 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001847 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001848 if (!ret)
1849 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1850 "capability=0x%x, rangelow=%d, "
1851 "rangehigh=%d, signal=%d, afc=%d, "
1852 "rxsubchans=0x%x, audmode=%d\n",
1853 p->index, p->name, p->type,
1854 p->capability, p->rangelow,
1855 p->rangehigh, p->signal, p->afc,
1856 p->rxsubchans, p->audmode);
1857 break;
1858 }
1859 case VIDIOC_S_TUNER:
1860 {
1861 struct v4l2_tuner *p = arg;
1862
Hans Verkuila3998102008-07-21 02:57:38 -03001863 if (!ops->vidioc_s_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001864 break;
Hans Verkuil227690d2011-06-12 06:36:41 -03001865 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1866 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001867 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1868 "capability=0x%x, rangelow=%d, "
1869 "rangehigh=%d, signal=%d, afc=%d, "
1870 "rxsubchans=0x%x, audmode=%d\n",
1871 p->index, p->name, p->type,
1872 p->capability, p->rangelow,
1873 p->rangehigh, p->signal, p->afc,
1874 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001875 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001876 break;
1877 }
1878 case VIDIOC_G_FREQUENCY:
1879 {
1880 struct v4l2_frequency *p = arg;
1881
Hans Verkuila3998102008-07-21 02:57:38 -03001882 if (!ops->vidioc_g_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001883 break;
1884
Hans Verkuil227690d2011-06-12 06:36:41 -03001885 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1886 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuila3998102008-07-21 02:57:38 -03001887 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001888 if (!ret)
1889 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1890 p->tuner, p->type, p->frequency);
1891 break;
1892 }
1893 case VIDIOC_S_FREQUENCY:
1894 {
1895 struct v4l2_frequency *p = arg;
1896
Hans Verkuila3998102008-07-21 02:57:38 -03001897 if (!ops->vidioc_s_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001898 break;
1899 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1900 p->tuner, p->type, p->frequency);
Hans Verkuila3998102008-07-21 02:57:38 -03001901 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001902 break;
1903 }
1904 case VIDIOC_G_SLICED_VBI_CAP:
1905 {
1906 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001907
Hans Verkuila3998102008-07-21 02:57:38 -03001908 if (!ops->vidioc_g_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001909 break;
Trent Piepho19c96e42009-03-04 01:21:02 -03001910
1911 /* Clear up to type, everything after type is zerod already */
1912 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1913
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001914 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001915 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001916 if (!ret)
1917 dbgarg2("service_set=%d\n", p->service_set);
1918 break;
1919 }
1920 case VIDIOC_LOG_STATUS:
1921 {
Hans Verkuila3998102008-07-21 02:57:38 -03001922 if (!ops->vidioc_log_status)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001923 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001924 ret = ops->vidioc_log_status(file, fh);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001925 break;
1926 }
1927#ifdef CONFIG_VIDEO_ADV_DEBUG
1928 case VIDIOC_DBG_G_REGISTER:
1929 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001930 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001931
Hans Verkuila1198cc2011-01-08 09:53:32 -03001932 if (ops->vidioc_g_register) {
1933 if (!capable(CAP_SYS_ADMIN))
1934 ret = -EPERM;
1935 else
1936 ret = ops->vidioc_g_register(file, fh, p);
1937 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001938 break;
1939 }
1940 case VIDIOC_DBG_S_REGISTER:
1941 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001942 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001943
Hans Verkuila1198cc2011-01-08 09:53:32 -03001944 if (ops->vidioc_s_register) {
1945 if (!capable(CAP_SYS_ADMIN))
1946 ret = -EPERM;
1947 else
1948 ret = ops->vidioc_s_register(file, fh, p);
1949 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001950 break;
1951 }
1952#endif
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001953 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001954 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001955 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001956
Hans Verkuila3998102008-07-21 02:57:38 -03001957 if (!ops->vidioc_g_chip_ident)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001958 break;
Hans Verkuil80b36e02009-02-07 11:00:02 -03001959 p->ident = V4L2_IDENT_NONE;
1960 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001961 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001962 if (!ret)
1963 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1964 break;
1965 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001966 case VIDIOC_S_HW_FREQ_SEEK:
1967 {
1968 struct v4l2_hw_freq_seek *p = arg;
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001969 enum v4l2_tuner_type type;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001970
Hans Verkuila3998102008-07-21 02:57:38 -03001971 if (!ops->vidioc_s_hw_freq_seek)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001972 break;
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001973 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1974 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001975 dbgarg(cmd,
Hans Verkuila6cf90a2011-06-14 04:03:26 -03001976 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1977 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1978 if (p->type != type)
1979 ret = -EINVAL;
1980 else
1981 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
Hans Verkuila3998102008-07-21 02:57:38 -03001982 break;
1983 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001984 case VIDIOC_ENUM_FRAMESIZES:
1985 {
1986 struct v4l2_frmsizeenum *p = arg;
1987
1988 if (!ops->vidioc_enum_framesizes)
1989 break;
1990
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001991 ret = ops->vidioc_enum_framesizes(file, fh, p);
1992 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001993 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1994 p->index,
1995 (p->pixel_format & 0xff),
1996 (p->pixel_format >> 8) & 0xff,
1997 (p->pixel_format >> 16) & 0xff,
1998 (p->pixel_format >> 24) & 0xff,
1999 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002000 switch (p->type) {
2001 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002002 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002003 p->discrete.width, p->discrete.height);
2004 break;
2005 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002006 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002007 p->stepwise.min_width, p->stepwise.min_height,
2008 p->stepwise.step_width, p->stepwise.step_height,
2009 p->stepwise.max_width, p->stepwise.max_height);
2010 break;
2011 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002012 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002013 break;
2014 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002015 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002016 }
2017
2018 break;
2019 }
2020 case VIDIOC_ENUM_FRAMEINTERVALS:
2021 {
2022 struct v4l2_frmivalenum *p = arg;
2023
2024 if (!ops->vidioc_enum_frameintervals)
2025 break;
2026
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002027 ret = ops->vidioc_enum_frameintervals(file, fh, p);
2028 dbgarg(cmd,
2029 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
2030 p->index, p->pixel_format,
2031 p->width, p->height, p->type);
2032 switch (p->type) {
2033 case V4L2_FRMIVAL_TYPE_DISCRETE:
2034 dbgarg2("fps=%d/%d\n",
2035 p->discrete.numerator,
2036 p->discrete.denominator);
2037 break;
2038 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03002039 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
2040 p->stepwise.min.numerator,
2041 p->stepwise.min.denominator,
2042 p->stepwise.max.numerator,
2043 p->stepwise.max.denominator,
2044 p->stepwise.step.numerator,
2045 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002046 break;
2047 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
2048 dbgarg2("continuous\n");
2049 break;
2050 default:
2051 dbgarg2("- Unknown type!\n");
2052 }
2053 break;
2054 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002055 case VIDIOC_ENUM_DV_PRESETS:
2056 {
2057 struct v4l2_dv_enum_preset *p = arg;
2058
2059 if (!ops->vidioc_enum_dv_presets)
2060 break;
2061
2062 ret = ops->vidioc_enum_dv_presets(file, fh, p);
2063 if (!ret)
2064 dbgarg(cmd,
2065 "index=%d, preset=%d, name=%s, width=%d,"
2066 " height=%d ",
2067 p->index, p->preset, p->name, p->width,
2068 p->height);
2069 break;
2070 }
2071 case VIDIOC_S_DV_PRESET:
2072 {
2073 struct v4l2_dv_preset *p = arg;
2074
2075 if (!ops->vidioc_s_dv_preset)
2076 break;
2077
2078 dbgarg(cmd, "preset=%d\n", p->preset);
2079 ret = ops->vidioc_s_dv_preset(file, fh, p);
2080 break;
2081 }
2082 case VIDIOC_G_DV_PRESET:
2083 {
2084 struct v4l2_dv_preset *p = arg;
2085
2086 if (!ops->vidioc_g_dv_preset)
2087 break;
2088
2089 ret = ops->vidioc_g_dv_preset(file, fh, p);
2090 if (!ret)
2091 dbgarg(cmd, "preset=%d\n", p->preset);
2092 break;
2093 }
2094 case VIDIOC_QUERY_DV_PRESET:
2095 {
2096 struct v4l2_dv_preset *p = arg;
2097
2098 if (!ops->vidioc_query_dv_preset)
2099 break;
2100
2101 ret = ops->vidioc_query_dv_preset(file, fh, p);
2102 if (!ret)
2103 dbgarg(cmd, "preset=%d\n", p->preset);
2104 break;
2105 }
2106 case VIDIOC_S_DV_TIMINGS:
2107 {
2108 struct v4l2_dv_timings *p = arg;
2109
2110 if (!ops->vidioc_s_dv_timings)
2111 break;
2112
2113 switch (p->type) {
2114 case V4L2_DV_BT_656_1120:
2115 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2116 " width=%d, height=%d, polarities=%x,"
2117 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
2118 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
2119 " il_vfrontporch=%d, il_vsync=%d,"
2120 " il_vbackporch=%d\n",
2121 p->bt.interlaced, p->bt.pixelclock,
2122 p->bt.width, p->bt.height, p->bt.polarities,
2123 p->bt.hfrontporch, p->bt.hsync,
2124 p->bt.hbackporch, p->bt.vfrontporch,
2125 p->bt.vsync, p->bt.vbackporch,
2126 p->bt.il_vfrontporch, p->bt.il_vsync,
2127 p->bt.il_vbackporch);
2128 ret = ops->vidioc_s_dv_timings(file, fh, p);
2129 break;
2130 default:
2131 dbgarg2("Unknown type %d!\n", p->type);
2132 break;
2133 }
2134 break;
2135 }
2136 case VIDIOC_G_DV_TIMINGS:
2137 {
2138 struct v4l2_dv_timings *p = arg;
2139
2140 if (!ops->vidioc_g_dv_timings)
2141 break;
2142
2143 ret = ops->vidioc_g_dv_timings(file, fh, p);
2144 if (!ret) {
2145 switch (p->type) {
2146 case V4L2_DV_BT_656_1120:
2147 dbgarg2("bt-656/1120:interlaced=%d,"
2148 " pixelclock=%lld,"
2149 " width=%d, height=%d, polarities=%x,"
2150 " hfrontporch=%d, hsync=%d,"
2151 " hbackporch=%d, vfrontporch=%d,"
2152 " vsync=%d, vbackporch=%d,"
2153 " il_vfrontporch=%d, il_vsync=%d,"
2154 " il_vbackporch=%d\n",
2155 p->bt.interlaced, p->bt.pixelclock,
2156 p->bt.width, p->bt.height,
2157 p->bt.polarities, p->bt.hfrontporch,
2158 p->bt.hsync, p->bt.hbackporch,
2159 p->bt.vfrontporch, p->bt.vsync,
2160 p->bt.vbackporch, p->bt.il_vfrontporch,
2161 p->bt.il_vsync, p->bt.il_vbackporch);
2162 break;
2163 default:
2164 dbgarg2("Unknown type %d!\n", p->type);
2165 break;
2166 }
2167 }
2168 break;
2169 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002170 case VIDIOC_DQEVENT:
2171 {
2172 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002173
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002174 if (!ops->vidioc_subscribe_event)
2175 break;
2176
2177 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2178 if (ret < 0) {
2179 dbgarg(cmd, "no pending events?");
2180 break;
2181 }
2182 dbgarg(cmd,
2183 "pending=%d, type=0x%8.8x, sequence=%d, "
2184 "timestamp=%lu.%9.9lu ",
2185 ev->pending, ev->type, ev->sequence,
2186 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2187 break;
2188 }
2189 case VIDIOC_SUBSCRIBE_EVENT:
2190 {
2191 struct v4l2_event_subscription *sub = arg;
2192
2193 if (!ops->vidioc_subscribe_event)
2194 break;
2195
2196 ret = ops->vidioc_subscribe_event(fh, sub);
2197 if (ret < 0) {
2198 dbgarg(cmd, "failed, ret=%ld", ret);
2199 break;
2200 }
2201 dbgarg(cmd, "type=0x%8.8x", sub->type);
2202 break;
2203 }
2204 case VIDIOC_UNSUBSCRIBE_EVENT:
2205 {
2206 struct v4l2_event_subscription *sub = arg;
2207
2208 if (!ops->vidioc_unsubscribe_event)
2209 break;
2210
2211 ret = ops->vidioc_unsubscribe_event(fh, sub);
2212 if (ret < 0) {
2213 dbgarg(cmd, "failed, ret=%ld", ret);
2214 break;
2215 }
2216 dbgarg(cmd, "type=0x%8.8x", sub->type);
2217 break;
2218 }
Hans Verkuila3998102008-07-21 02:57:38 -03002219 default:
2220 {
Hans Verkuil99cd47bc2011-03-11 19:00:56 -03002221 bool valid_prio = true;
2222
Hans Verkuila3998102008-07-21 02:57:38 -03002223 if (!ops->vidioc_default)
2224 break;
Hans Verkuilb1a873a2011-03-22 10:14:07 -03002225 if (use_fh_prio)
Hans Verkuil99cd47bc2011-03-11 19:00:56 -03002226 valid_prio = v4l2_prio_check(vfd->prio, vfh->prio) >= 0;
2227 ret = ops->vidioc_default(file, fh, valid_prio, cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002228 break;
2229 }
2230 } /* switch */
2231
Hans Verkuil99cd47bc2011-03-11 19:00:56 -03002232exit_prio:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002233 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2234 if (ret < 0) {
2235 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002236 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002237 }
2238 }
2239
2240 return ret;
2241}
2242
Trent Piepho19c96e42009-03-04 01:21:02 -03002243/* In some cases, only a few fields are used as input, i.e. when the app sets
2244 * "index" and then the driver fills in the rest of the structure for the thing
2245 * with that index. We only need to copy up the first non-input field. */
2246static unsigned long cmd_input_size(unsigned int cmd)
2247{
2248 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002249#define CMDINSIZE(cmd, type, field) \
2250 case VIDIOC_##cmd: \
2251 return offsetof(struct v4l2_##type, field) + \
2252 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03002253
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002254 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03002255 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2256 CMDINSIZE(G_FMT, format, type);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002257 CMDINSIZE(QUERYBUF, buffer, length);
Trent Piepho19c96e42009-03-04 01:21:02 -03002258 CMDINSIZE(G_PARM, streamparm, type);
2259 CMDINSIZE(ENUMSTD, standard, index);
2260 CMDINSIZE(ENUMINPUT, input, index);
2261 CMDINSIZE(G_CTRL, control, id);
2262 CMDINSIZE(G_TUNER, tuner, index);
2263 CMDINSIZE(QUERYCTRL, queryctrl, id);
2264 CMDINSIZE(QUERYMENU, querymenu, index);
2265 CMDINSIZE(ENUMOUTPUT, output, index);
2266 CMDINSIZE(G_MODULATOR, modulator, index);
2267 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2268 CMDINSIZE(CROPCAP, cropcap, type);
2269 CMDINSIZE(G_CROP, crop, type);
2270 CMDINSIZE(ENUMAUDIO, audio, index);
2271 CMDINSIZE(ENUMAUDOUT, audioout, index);
2272 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2273 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2274 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2275 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2276 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2277 default:
2278 return _IOC_SIZE(cmd);
2279 }
2280}
2281
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002282static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2283 void * __user *user_ptr, void ***kernel_ptr)
2284{
2285 int ret = 0;
2286
2287 switch (cmd) {
2288 case VIDIOC_QUERYBUF:
2289 case VIDIOC_QBUF:
2290 case VIDIOC_DQBUF: {
2291 struct v4l2_buffer *buf = parg;
2292
2293 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2294 if (buf->length > VIDEO_MAX_PLANES) {
2295 ret = -EINVAL;
2296 break;
2297 }
2298 *user_ptr = (void __user *)buf->m.planes;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002299 *kernel_ptr = (void *)&buf->m.planes;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002300 *array_size = sizeof(struct v4l2_plane) * buf->length;
2301 ret = 1;
2302 }
2303 break;
2304 }
2305
2306 case VIDIOC_S_EXT_CTRLS:
2307 case VIDIOC_G_EXT_CTRLS:
2308 case VIDIOC_TRY_EXT_CTRLS: {
2309 struct v4l2_ext_controls *ctrls = parg;
2310
2311 if (ctrls->count != 0) {
2312 *user_ptr = (void __user *)ctrls->controls;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002313 *kernel_ptr = (void *)&ctrls->controls;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002314 *array_size = sizeof(struct v4l2_ext_control)
2315 * ctrls->count;
2316 ret = 1;
2317 }
2318 break;
2319 }
2320 }
2321
2322 return ret;
2323}
2324
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002325long
2326video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2327 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002328{
2329 char sbuf[128];
2330 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002331 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002332 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002333 bool has_array_args;
2334 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002335 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002336 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002337
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002338 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002339 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002340 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2341 parg = sbuf;
2342 } else {
2343 /* too big to allocate from stack */
2344 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2345 if (NULL == mbuf)
2346 return -ENOMEM;
2347 parg = mbuf;
2348 }
2349
2350 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002351 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2352 unsigned long n = cmd_input_size(cmd);
2353
2354 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002355 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002356
2357 /* zero out anything we don't copy from userspace */
2358 if (n < _IOC_SIZE(cmd))
2359 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002360 } else {
2361 /* read-only ioctl */
2362 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002363 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002364 }
2365
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002366 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2367 if (err < 0)
2368 goto out;
2369 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002370
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002371 if (has_array_args) {
2372 /*
2373 * When adding new types of array args, make sure that the
2374 * parent argument to ioctl (which contains the pointer to the
2375 * array) fits into sbuf (so that mbuf will still remain
2376 * unused up to here).
2377 */
2378 mbuf = kmalloc(array_size, GFP_KERNEL);
2379 err = -ENOMEM;
2380 if (NULL == mbuf)
2381 goto out_array_args;
2382 err = -EFAULT;
2383 if (copy_from_user(mbuf, user_ptr, array_size))
2384 goto out_array_args;
2385 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002386 }
2387
2388 /* Handles IOCTL */
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002389 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002390 if (err == -ENOIOCTLCMD)
2391 err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002392
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002393 if (has_array_args) {
2394 *kernel_ptr = user_ptr;
2395 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002396 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002397 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002398 }
2399 if (err < 0)
2400 goto out;
2401
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002402out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002403 /* Copy results into user buffer */
2404 switch (_IOC_DIR(cmd)) {
2405 case _IOC_READ:
2406 case (_IOC_WRITE | _IOC_READ):
2407 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2408 err = -EFAULT;
2409 break;
2410 }
2411
2412out:
2413 kfree(mbuf);
2414 return err;
2415}
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002416EXPORT_SYMBOL(video_usercopy);
2417
2418long video_ioctl2(struct file *file,
2419 unsigned int cmd, unsigned long arg)
2420{
2421 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2422}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002423EXPORT_SYMBOL(video_ioctl2);