blob: 8360ed2d933af69bc01aac94babe94556c2714e4 [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>
19
20#define __OLD_VIDIOC_ /* To allow fixing old calls */
21#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 Verkuil80b36e02009-02-07 11:00:02 -030028#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030029
30#define dbgarg(cmd, fmt, arg...) \
31 do { \
32 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
33 printk(KERN_DEBUG "%s: ", vfd->name); \
34 v4l_printk_ioctl(cmd); \
35 printk(" " fmt, ## arg); \
36 } \
37 } while (0)
38
39#define dbgarg2(fmt, arg...) \
40 do { \
41 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
42 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
43 } while (0)
44
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030045#define dbgarg3(fmt, arg...) \
46 do { \
47 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
48 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
49 } while (0)
50
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030051/* Zero out the end of the struct pointed to by p. Everthing after, but
52 * not including, the specified field is cleared. */
53#define CLEAR_AFTER_FIELD(p, field) \
54 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
55 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
56
Hans Verkuil35ea11f2008-07-20 08:12:02 -030057struct std_descr {
58 v4l2_std_id std;
59 const char *descr;
60};
61
62static const struct std_descr standards[] = {
63 { V4L2_STD_NTSC, "NTSC" },
64 { V4L2_STD_NTSC_M, "NTSC-M" },
65 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
66 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
67 { V4L2_STD_NTSC_443, "NTSC-443" },
68 { V4L2_STD_PAL, "PAL" },
69 { V4L2_STD_PAL_BG, "PAL-BG" },
70 { V4L2_STD_PAL_B, "PAL-B" },
71 { V4L2_STD_PAL_B1, "PAL-B1" },
72 { V4L2_STD_PAL_G, "PAL-G" },
73 { V4L2_STD_PAL_H, "PAL-H" },
74 { V4L2_STD_PAL_I, "PAL-I" },
75 { V4L2_STD_PAL_DK, "PAL-DK" },
76 { V4L2_STD_PAL_D, "PAL-D" },
77 { V4L2_STD_PAL_D1, "PAL-D1" },
78 { V4L2_STD_PAL_K, "PAL-K" },
79 { V4L2_STD_PAL_M, "PAL-M" },
80 { V4L2_STD_PAL_N, "PAL-N" },
81 { V4L2_STD_PAL_Nc, "PAL-Nc" },
82 { V4L2_STD_PAL_60, "PAL-60" },
83 { V4L2_STD_SECAM, "SECAM" },
84 { V4L2_STD_SECAM_B, "SECAM-B" },
85 { V4L2_STD_SECAM_G, "SECAM-G" },
86 { V4L2_STD_SECAM_H, "SECAM-H" },
87 { V4L2_STD_SECAM_DK, "SECAM-DK" },
88 { V4L2_STD_SECAM_D, "SECAM-D" },
89 { V4L2_STD_SECAM_K, "SECAM-K" },
90 { V4L2_STD_SECAM_K1, "SECAM-K1" },
91 { V4L2_STD_SECAM_L, "SECAM-L" },
92 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
93 { 0, "Unknown" }
94};
95
96/* video4linux standard ID conversion to standard name
97 */
98const char *v4l2_norm_to_name(v4l2_std_id id)
99{
100 u32 myid = id;
101 int i;
102
103 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
104 64 bit comparations. So, on that architecture, with some gcc
105 variants, compilation fails. Currently, the max value is 30bit wide.
106 */
107 BUG_ON(myid != id);
108
109 for (i = 0; standards[i].std; i++)
110 if (myid == standards[i].std)
111 break;
112 return standards[i].descr;
113}
114EXPORT_SYMBOL(v4l2_norm_to_name);
115
Trent Piepho51f0b8d2009-03-04 01:21:02 -0300116/* Returns frame period for the given standard */
117void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
118{
119 if (id & V4L2_STD_525_60) {
120 frameperiod->numerator = 1001;
121 frameperiod->denominator = 30000;
122 } else {
123 frameperiod->numerator = 1;
124 frameperiod->denominator = 25;
125 }
126}
127EXPORT_SYMBOL(v4l2_video_std_frame_period);
128
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300129/* Fill in the fields of a v4l2_standard structure according to the
130 'id' and 'transmission' parameters. Returns negative on error. */
131int v4l2_video_std_construct(struct v4l2_standard *vs,
132 int id, const char *name)
133{
Trent Piepho51f0b8d2009-03-04 01:21:02 -0300134 vs->id = id;
135 v4l2_video_std_frame_period(id, &vs->frameperiod);
136 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300137 strlcpy(vs->name, name, sizeof(vs->name));
138 return 0;
139}
140EXPORT_SYMBOL(v4l2_video_std_construct);
141
142/* ----------------------------------------------------------------- */
143/* some arrays for pretty-printing debug messages of enum types */
144
145const char *v4l2_field_names[] = {
146 [V4L2_FIELD_ANY] = "any",
147 [V4L2_FIELD_NONE] = "none",
148 [V4L2_FIELD_TOP] = "top",
149 [V4L2_FIELD_BOTTOM] = "bottom",
150 [V4L2_FIELD_INTERLACED] = "interlaced",
151 [V4L2_FIELD_SEQ_TB] = "seq-tb",
152 [V4L2_FIELD_SEQ_BT] = "seq-bt",
153 [V4L2_FIELD_ALTERNATE] = "alternate",
154 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
155 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
156};
157EXPORT_SYMBOL(v4l2_field_names);
158
159const char *v4l2_type_names[] = {
160 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
161 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
162 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
163 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
164 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
165 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
166 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
167 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
Pawel Osciakf8f39142010-07-29 14:44:25 -0300168 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
169 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300170};
171EXPORT_SYMBOL(v4l2_type_names);
172
173static const char *v4l2_memory_names[] = {
174 [V4L2_MEMORY_MMAP] = "mmap",
175 [V4L2_MEMORY_USERPTR] = "userptr",
176 [V4L2_MEMORY_OVERLAY] = "overlay",
177};
178
179#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
180 arr[a] : "unknown")
181
182/* ------------------------------------------------------------------ */
183/* debug help functions */
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300184static const char *v4l2_ioctls[] = {
185 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
186 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
187 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
188 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
189 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
190 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
191 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
192 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
193 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
194 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
195 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
196 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
197 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
198 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
199 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
200 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
201 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
202 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
203 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
204 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
205 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
206 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
207 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
208 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
209 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
210 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
211 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
212 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
213 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
214 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
215 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
216 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
217 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
218 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
219 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
220 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
221 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
222 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
223 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
224 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
225 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
226 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
227 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
228 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
229 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
230 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
231 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
232 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
233 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
234 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
235 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
236 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
237 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
238 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
239 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
240#if 1
241 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
242 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
243 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
244 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
245 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
246
247 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
248 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
249
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300250 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300251 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
252#endif
Muralidharan Karicherib6456c02009-11-19 12:00:31 -0300253 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS)] = "VIDIOC_ENUM_DV_PRESETS",
254 [_IOC_NR(VIDIOC_S_DV_PRESET)] = "VIDIOC_S_DV_PRESET",
255 [_IOC_NR(VIDIOC_G_DV_PRESET)] = "VIDIOC_G_DV_PRESET",
256 [_IOC_NR(VIDIOC_QUERY_DV_PRESET)] = "VIDIOC_QUERY_DV_PRESET",
257 [_IOC_NR(VIDIOC_S_DV_TIMINGS)] = "VIDIOC_S_DV_TIMINGS",
258 [_IOC_NR(VIDIOC_G_DV_TIMINGS)] = "VIDIOC_G_DV_TIMINGS",
Sakari Ailusfda10212010-02-24 19:19:05 -0300259 [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
260 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
261 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300262};
263#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
264
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300265/* Common ioctl debug function. This function can be used by
266 external ioctl messages as well as internal V4L ioctl */
267void v4l_printk_ioctl(unsigned int cmd)
268{
269 char *dir, *type;
270
271 switch (_IOC_TYPE(cmd)) {
272 case 'd':
Hans Verkuil78a3b4d2009-04-01 03:41:09 -0300273 type = "v4l2_int";
274 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300275 case 'V':
276 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
277 type = "v4l2";
278 break;
279 }
280 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
281 return;
282 default:
283 type = "unknown";
284 }
285
286 switch (_IOC_DIR(cmd)) {
287 case _IOC_NONE: dir = "--"; break;
288 case _IOC_READ: dir = "r-"; break;
289 case _IOC_WRITE: dir = "-w"; break;
290 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
291 default: dir = "*ERR*"; break;
292 }
293 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
294 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
295}
296EXPORT_SYMBOL(v4l_printk_ioctl);
297
298/*
299 * helper function -- handles userspace copying for ioctl arguments
300 */
301
302#ifdef __OLD_VIDIOC_
303static unsigned int
304video_fix_command(unsigned int cmd)
305{
306 switch (cmd) {
307 case VIDIOC_OVERLAY_OLD:
308 cmd = VIDIOC_OVERLAY;
309 break;
310 case VIDIOC_S_PARM_OLD:
311 cmd = VIDIOC_S_PARM;
312 break;
313 case VIDIOC_S_CTRL_OLD:
314 cmd = VIDIOC_S_CTRL;
315 break;
316 case VIDIOC_G_AUDIO_OLD:
317 cmd = VIDIOC_G_AUDIO;
318 break;
319 case VIDIOC_G_AUDOUT_OLD:
320 cmd = VIDIOC_G_AUDOUT;
321 break;
322 case VIDIOC_CROPCAP_OLD:
323 cmd = VIDIOC_CROPCAP;
324 break;
325 }
326 return cmd;
327}
328#endif
329
330/*
331 * Obsolete usercopy function - Should be removed soon
332 */
Hans Verkuil069b7472008-12-30 07:04:34 -0300333long
Hans Verkuilf473bf72008-11-01 08:25:11 -0300334video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
335 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300336{
337 char sbuf[128];
338 void *mbuf = NULL;
339 void *parg = NULL;
Hans Verkuil069b7472008-12-30 07:04:34 -0300340 long err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300341 int is_ext_ctrl;
342 size_t ctrls_size = 0;
343 void __user *user_ptr = NULL;
344
345#ifdef __OLD_VIDIOC_
346 cmd = video_fix_command(cmd);
347#endif
348 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
349 cmd == VIDIOC_TRY_EXT_CTRLS);
350
351 /* Copy arguments into temp kernel buffer */
352 switch (_IOC_DIR(cmd)) {
353 case _IOC_NONE:
354 parg = NULL;
355 break;
356 case _IOC_READ:
357 case _IOC_WRITE:
358 case (_IOC_WRITE | _IOC_READ):
359 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
360 parg = sbuf;
361 } else {
362 /* too big to allocate from stack */
363 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
364 if (NULL == mbuf)
365 return -ENOMEM;
366 parg = mbuf;
367 }
368
369 err = -EFAULT;
370 if (_IOC_DIR(cmd) & _IOC_WRITE)
371 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
372 goto out;
373 break;
374 }
375 if (is_ext_ctrl) {
376 struct v4l2_ext_controls *p = parg;
377
378 /* In case of an error, tell the caller that it wasn't
379 a specific control that caused it. */
380 p->error_idx = p->count;
381 user_ptr = (void __user *)p->controls;
382 if (p->count) {
383 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
384 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
385 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
386 err = -ENOMEM;
387 if (NULL == mbuf)
388 goto out_ext_ctrl;
389 err = -EFAULT;
390 if (copy_from_user(mbuf, user_ptr, ctrls_size))
391 goto out_ext_ctrl;
392 p->controls = mbuf;
393 }
394 }
395
396 /* call driver */
Hans Verkuilf473bf72008-11-01 08:25:11 -0300397 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300398 if (err == -ENOIOCTLCMD)
399 err = -EINVAL;
400 if (is_ext_ctrl) {
401 struct v4l2_ext_controls *p = parg;
402
403 p->controls = (void *)user_ptr;
404 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
405 err = -EFAULT;
406 goto out_ext_ctrl;
407 }
408 if (err < 0)
409 goto out;
410
411out_ext_ctrl:
412 /* Copy results into user buffer */
413 switch (_IOC_DIR(cmd)) {
414 case _IOC_READ:
415 case (_IOC_WRITE | _IOC_READ):
416 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
417 err = -EFAULT;
418 break;
419 }
420
421out:
422 kfree(mbuf);
423 return err;
424}
425EXPORT_SYMBOL(video_usercopy);
426
427static void dbgbuf(unsigned int cmd, struct video_device *vfd,
428 struct v4l2_buffer *p)
429{
430 struct v4l2_timecode *tc = &p->timecode;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300431 struct v4l2_plane *plane;
432 int i;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300433
434 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300435 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300436 p->timestamp.tv_sec / 3600,
437 (int)(p->timestamp.tv_sec / 60) % 60,
438 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300439 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300440 p->index,
441 prt_names(p->type, v4l2_type_names),
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300442 p->flags, p->field, p->sequence,
443 prt_names(p->memory, v4l2_memory_names));
444
445 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
446 for (i = 0; i < p->length; ++i) {
447 plane = &p->m.planes[i];
448 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
449 "offset/userptr=0x%08lx, length=%d\n",
450 i, plane->bytesused, plane->data_offset,
451 plane->m.userptr, plane->length);
452 }
453 } else {
454 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
455 p->bytesused, p->m.userptr, p->length);
456 }
457
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300458 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
459 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
460 tc->hours, tc->minutes, tc->seconds,
461 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
462}
463
464static inline void dbgrect(struct video_device *vfd, char *s,
465 struct v4l2_rect *r)
466{
467 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
468 r->width, r->height);
469};
470
471static inline void v4l_print_pix_fmt(struct video_device *vfd,
472 struct v4l2_pix_format *fmt)
473{
474 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
475 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
476 fmt->width, fmt->height,
477 (fmt->pixelformat & 0xff),
478 (fmt->pixelformat >> 8) & 0xff,
479 (fmt->pixelformat >> 16) & 0xff,
480 (fmt->pixelformat >> 24) & 0xff,
481 prt_names(fmt->field, v4l2_field_names),
482 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
483};
484
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300485static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
486 struct v4l2_pix_format_mplane *fmt)
487{
488 int i;
489
490 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
491 "colorspace=%d, num_planes=%d\n",
492 fmt->width, fmt->height,
493 (fmt->pixelformat & 0xff),
494 (fmt->pixelformat >> 8) & 0xff,
495 (fmt->pixelformat >> 16) & 0xff,
496 (fmt->pixelformat >> 24) & 0xff,
497 prt_names(fmt->field, v4l2_field_names),
498 fmt->colorspace, fmt->num_planes);
499
500 for (i = 0; i < fmt->num_planes; ++i)
501 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
502 fmt->plane_fmt[i].bytesperline,
503 fmt->plane_fmt[i].sizeimage);
504}
505
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300506static inline void v4l_print_ext_ctrls(unsigned int cmd,
507 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
508{
509 __u32 i;
510
511 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
512 return;
513 dbgarg(cmd, "");
514 printk(KERN_CONT "class=0x%x", c->ctrl_class);
515 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300516 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300517 printk(KERN_CONT " id/val=0x%x/0x%x",
518 c->controls[i].id, c->controls[i].value);
519 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300520 printk(KERN_CONT " id=0x%x,size=%u",
521 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300522 }
523 printk(KERN_CONT "\n");
524};
525
526static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
527{
528 __u32 i;
529
530 /* zero the reserved fields */
531 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300532 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300533 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300534
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300535 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
536 when using extended controls.
537 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
538 is it allowed for backwards compatibility.
539 */
540 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
541 return 0;
542 /* Check that all controls are from the same control class. */
543 for (i = 0; i < c->count; i++) {
544 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
545 c->error_idx = i;
546 return 0;
547 }
548 }
549 return 1;
550}
551
Hans Verkuila3998102008-07-21 02:57:38 -0300552static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300553{
Hans Verkuila3998102008-07-21 02:57:38 -0300554 if (ops == NULL)
555 return -EINVAL;
556
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300557 switch (type) {
558 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300559 if (ops->vidioc_g_fmt_vid_cap ||
560 ops->vidioc_g_fmt_vid_cap_mplane)
561 return 0;
562 break;
563 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
564 if (ops->vidioc_g_fmt_vid_cap_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300565 return 0;
566 break;
567 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300568 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300569 return 0;
570 break;
571 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300572 if (ops->vidioc_g_fmt_vid_out ||
573 ops->vidioc_g_fmt_vid_out_mplane)
574 return 0;
575 break;
576 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
577 if (ops->vidioc_g_fmt_vid_out_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300578 return 0;
579 break;
580 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300581 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300582 return 0;
583 break;
584 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300585 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300586 return 0;
587 break;
588 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300589 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300590 return 0;
591 break;
592 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300593 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300594 return 0;
595 break;
596 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300597 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300598 return 0;
599 break;
600 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300601 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300602 return 0;
603 break;
604 }
605 return -EINVAL;
606}
607
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300608/**
609 * fmt_sp_to_mp() - Convert a single-plane format to its multi-planar 1-plane
610 * equivalent
611 */
612static int fmt_sp_to_mp(const struct v4l2_format *f_sp,
613 struct v4l2_format *f_mp)
614{
615 struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
616 const struct v4l2_pix_format *pix = &f_sp->fmt.pix;
617
618 if (f_sp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
619 f_mp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
620 else if (f_sp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
621 f_mp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
622 else
623 return -EINVAL;
624
625 pix_mp->width = pix->width;
626 pix_mp->height = pix->height;
627 pix_mp->pixelformat = pix->pixelformat;
628 pix_mp->field = pix->field;
629 pix_mp->colorspace = pix->colorspace;
630 pix_mp->num_planes = 1;
631 pix_mp->plane_fmt[0].sizeimage = pix->sizeimage;
632 pix_mp->plane_fmt[0].bytesperline = pix->bytesperline;
633
634 return 0;
635}
636
637/**
638 * fmt_mp_to_sp() - Convert a multi-planar 1-plane format to its single-planar
639 * equivalent
640 */
641static int fmt_mp_to_sp(const struct v4l2_format *f_mp,
642 struct v4l2_format *f_sp)
643{
644 const struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
645 struct v4l2_pix_format *pix = &f_sp->fmt.pix;
646
647 if (f_mp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
648 f_sp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
649 else if (f_mp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
650 f_sp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
651 else
652 return -EINVAL;
653
654 pix->width = pix_mp->width;
655 pix->height = pix_mp->height;
656 pix->pixelformat = pix_mp->pixelformat;
657 pix->field = pix_mp->field;
658 pix->colorspace = pix_mp->colorspace;
659 pix->sizeimage = pix_mp->plane_fmt[0].sizeimage;
660 pix->bytesperline = pix_mp->plane_fmt[0].bytesperline;
661
662 return 0;
663}
664
Hans Verkuil069b7472008-12-30 07:04:34 -0300665static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300666 unsigned int cmd, void *arg)
667{
668 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300669 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300670 void *fh = file->private_data;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300671 struct v4l2_format f_copy;
Hans Verkuil069b7472008-12-30 07:04:34 -0300672 long ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300673
Hans Verkuil6a717882010-04-06 15:56:08 -0300674 if (ops == NULL) {
675 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
676 vfd->name);
677 return -EINVAL;
678 }
679
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300680 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
681 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
682 v4l_print_ioctl(vfd->name, cmd);
683 printk(KERN_CONT "\n");
684 }
685
Hans Verkuil6a717882010-04-06 15:56:08 -0300686 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300687
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300688 /* --- capabilities ------------------------------------------ */
689 case VIDIOC_QUERYCAP:
690 {
691 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300692
Hans Verkuila3998102008-07-21 02:57:38 -0300693 if (!ops->vidioc_querycap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300694 break;
695
Hans Verkuila3998102008-07-21 02:57:38 -0300696 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300697 if (!ret)
698 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
699 "version=0x%08x, "
700 "capabilities=0x%08x\n",
701 cap->driver, cap->card, cap->bus_info,
702 cap->version,
703 cap->capabilities);
704 break;
705 }
706
707 /* --- priority ------------------------------------------ */
708 case VIDIOC_G_PRIORITY:
709 {
710 enum v4l2_priority *p = arg;
711
Hans Verkuila3998102008-07-21 02:57:38 -0300712 if (!ops->vidioc_g_priority)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300713 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300714 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300715 if (!ret)
716 dbgarg(cmd, "priority is %d\n", *p);
717 break;
718 }
719 case VIDIOC_S_PRIORITY:
720 {
721 enum v4l2_priority *p = arg;
722
Hans Verkuila3998102008-07-21 02:57:38 -0300723 if (!ops->vidioc_s_priority)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300724 break;
725 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuila3998102008-07-21 02:57:38 -0300726 ret = ops->vidioc_s_priority(file, fh, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300727 break;
728 }
729
730 /* --- capture ioctls ---------------------------------------- */
731 case VIDIOC_ENUM_FMT:
732 {
733 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300734
Trent Piepho19c96e42009-03-04 01:21:02 -0300735 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300736 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300737 if (ops->vidioc_enum_fmt_vid_cap)
738 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300739 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300740 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
741 if (ops->vidioc_enum_fmt_vid_cap_mplane)
742 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
743 fh, f);
744 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300745 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300746 if (ops->vidioc_enum_fmt_vid_overlay)
747 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300748 fh, f);
749 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300750 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300751 if (ops->vidioc_enum_fmt_vid_out)
752 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300753 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300754 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
755 if (ops->vidioc_enum_fmt_vid_out_mplane)
756 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
757 fh, f);
758 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300759 case V4L2_BUF_TYPE_PRIVATE:
Hans Verkuila3998102008-07-21 02:57:38 -0300760 if (ops->vidioc_enum_fmt_type_private)
761 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300762 fh, f);
763 break;
764 default:
765 break;
766 }
767 if (!ret)
768 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
769 "pixelformat=%c%c%c%c, description='%s'\n",
770 f->index, f->type, f->flags,
771 (f->pixelformat & 0xff),
772 (f->pixelformat >> 8) & 0xff,
773 (f->pixelformat >> 16) & 0xff,
774 (f->pixelformat >> 24) & 0xff,
775 f->description);
776 break;
777 }
778 case VIDIOC_G_FMT:
779 {
780 struct v4l2_format *f = (struct v4l2_format *)arg;
781
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300782 /* FIXME: Should be one dump per type */
783 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
784
785 switch (f->type) {
786 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300787 if (ops->vidioc_g_fmt_vid_cap) {
Hans Verkuila3998102008-07-21 02:57:38 -0300788 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300789 } else if (ops->vidioc_g_fmt_vid_cap_mplane) {
790 if (fmt_sp_to_mp(f, &f_copy))
791 break;
792 ret = ops->vidioc_g_fmt_vid_cap_mplane(file, fh,
793 &f_copy);
794 if (ret)
795 break;
796
797 /* Driver is currently in multi-planar format,
798 * we can't return it in single-planar API*/
799 if (f_copy.fmt.pix_mp.num_planes > 1) {
800 ret = -EBUSY;
801 break;
802 }
803
804 ret = fmt_mp_to_sp(&f_copy, f);
805 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300806 if (!ret)
807 v4l_print_pix_fmt(vfd, &f->fmt.pix);
808 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300809 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
810 if (ops->vidioc_g_fmt_vid_cap_mplane) {
811 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
812 fh, f);
813 } else if (ops->vidioc_g_fmt_vid_cap) {
814 if (fmt_mp_to_sp(f, &f_copy))
815 break;
816 ret = ops->vidioc_g_fmt_vid_cap(file,
817 fh, &f_copy);
818 if (ret)
819 break;
820
821 ret = fmt_sp_to_mp(&f_copy, f);
822 }
823 if (!ret)
824 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
825 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300826 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300827 if (ops->vidioc_g_fmt_vid_overlay)
828 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300829 fh, f);
830 break;
831 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300832 if (ops->vidioc_g_fmt_vid_out) {
Hans Verkuila3998102008-07-21 02:57:38 -0300833 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300834 } else if (ops->vidioc_g_fmt_vid_out_mplane) {
835 if (fmt_sp_to_mp(f, &f_copy))
836 break;
837 ret = ops->vidioc_g_fmt_vid_out_mplane(file, fh,
838 &f_copy);
839 if (ret)
840 break;
841
842 /* Driver is currently in multi-planar format,
843 * we can't return it in single-planar API*/
844 if (f_copy.fmt.pix_mp.num_planes > 1) {
845 ret = -EBUSY;
846 break;
847 }
848
849 ret = fmt_mp_to_sp(&f_copy, f);
850 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300851 if (!ret)
852 v4l_print_pix_fmt(vfd, &f->fmt.pix);
853 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300854 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
855 if (ops->vidioc_g_fmt_vid_out_mplane) {
856 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
857 fh, f);
858 } else if (ops->vidioc_g_fmt_vid_out) {
859 if (fmt_mp_to_sp(f, &f_copy))
860 break;
861 ret = ops->vidioc_g_fmt_vid_out(file,
862 fh, &f_copy);
863 if (ret)
864 break;
865
866 ret = fmt_sp_to_mp(&f_copy, f);
867 }
868 if (!ret)
869 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
870 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300871 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300872 if (ops->vidioc_g_fmt_vid_out_overlay)
873 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300874 fh, f);
875 break;
876 case V4L2_BUF_TYPE_VBI_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300877 if (ops->vidioc_g_fmt_vbi_cap)
878 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300879 break;
880 case V4L2_BUF_TYPE_VBI_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300881 if (ops->vidioc_g_fmt_vbi_out)
882 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300883 break;
884 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300885 if (ops->vidioc_g_fmt_sliced_vbi_cap)
886 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300887 fh, f);
888 break;
889 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300890 if (ops->vidioc_g_fmt_sliced_vbi_out)
891 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300892 fh, f);
893 break;
894 case V4L2_BUF_TYPE_PRIVATE:
Hans Verkuila3998102008-07-21 02:57:38 -0300895 if (ops->vidioc_g_fmt_type_private)
896 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300897 fh, f);
898 break;
899 }
900
901 break;
902 }
903 case VIDIOC_S_FMT:
904 {
905 struct v4l2_format *f = (struct v4l2_format *)arg;
906
907 /* FIXME: Should be one dump per type */
908 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
909
910 switch (f->type) {
911 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300912 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300913 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300914 if (ops->vidioc_s_fmt_vid_cap) {
Hans Verkuila3998102008-07-21 02:57:38 -0300915 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300916 } else if (ops->vidioc_s_fmt_vid_cap_mplane) {
917 if (fmt_sp_to_mp(f, &f_copy))
918 break;
919 ret = ops->vidioc_s_fmt_vid_cap_mplane(file, fh,
920 &f_copy);
921 if (ret)
922 break;
923
924 if (f_copy.fmt.pix_mp.num_planes > 1) {
925 /* Drivers shouldn't adjust from 1-plane
926 * to more than 1-plane formats */
927 ret = -EBUSY;
928 WARN_ON(1);
929 break;
930 }
931
932 ret = fmt_mp_to_sp(&f_copy, f);
933 }
934 break;
935 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
936 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
937 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
938 if (ops->vidioc_s_fmt_vid_cap_mplane) {
939 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
940 fh, f);
941 } else if (ops->vidioc_s_fmt_vid_cap &&
942 f->fmt.pix_mp.num_planes == 1) {
943 if (fmt_mp_to_sp(f, &f_copy))
944 break;
945 ret = ops->vidioc_s_fmt_vid_cap(file,
946 fh, &f_copy);
947 if (ret)
948 break;
949
950 ret = fmt_sp_to_mp(&f_copy, f);
951 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300952 break;
953 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300954 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300955 if (ops->vidioc_s_fmt_vid_overlay)
956 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300957 fh, f);
958 break;
959 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300960 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300961 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300962 if (ops->vidioc_s_fmt_vid_out) {
Hans Verkuila3998102008-07-21 02:57:38 -0300963 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300964 } else if (ops->vidioc_s_fmt_vid_out_mplane) {
965 if (fmt_sp_to_mp(f, &f_copy))
966 break;
967 ret = ops->vidioc_s_fmt_vid_out_mplane(file, fh,
968 &f_copy);
969 if (ret)
970 break;
971
972 if (f_copy.fmt.pix_mp.num_planes > 1) {
973 /* Drivers shouldn't adjust from 1-plane
974 * to more than 1-plane formats */
975 ret = -EBUSY;
976 WARN_ON(1);
977 break;
978 }
979
980 ret = fmt_mp_to_sp(&f_copy, f);
981 }
982 break;
983 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
984 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
985 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
986 if (ops->vidioc_s_fmt_vid_out_mplane) {
987 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
988 fh, f);
989 } else if (ops->vidioc_s_fmt_vid_out &&
990 f->fmt.pix_mp.num_planes == 1) {
991 if (fmt_mp_to_sp(f, &f_copy))
992 break;
993 ret = ops->vidioc_s_fmt_vid_out(file,
994 fh, &f_copy);
995 if (ret)
996 break;
997
998 ret = fmt_mp_to_sp(&f_copy, f);
999 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001000 break;
1001 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001002 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -03001003 if (ops->vidioc_s_fmt_vid_out_overlay)
1004 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001005 fh, f);
1006 break;
1007 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001008 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -03001009 if (ops->vidioc_s_fmt_vbi_cap)
1010 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001011 break;
1012 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001013 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -03001014 if (ops->vidioc_s_fmt_vbi_out)
1015 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001016 break;
1017 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001018 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -03001019 if (ops->vidioc_s_fmt_sliced_vbi_cap)
1020 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001021 fh, f);
1022 break;
1023 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001024 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -03001025 if (ops->vidioc_s_fmt_sliced_vbi_out)
1026 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001027 fh, f);
1028 break;
1029 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001030 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Hans Verkuila3998102008-07-21 02:57:38 -03001031 if (ops->vidioc_s_fmt_type_private)
1032 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001033 fh, f);
1034 break;
1035 }
1036 break;
1037 }
1038 case VIDIOC_TRY_FMT:
1039 {
1040 struct v4l2_format *f = (struct v4l2_format *)arg;
1041
1042 /* FIXME: Should be one dump per type */
1043 dbgarg(cmd, "type=%s\n", prt_names(f->type,
1044 v4l2_type_names));
1045 switch (f->type) {
1046 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001047 CLEAR_AFTER_FIELD(f, fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001048 if (ops->vidioc_try_fmt_vid_cap) {
Hans Verkuila3998102008-07-21 02:57:38 -03001049 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001050 } else if (ops->vidioc_try_fmt_vid_cap_mplane) {
1051 if (fmt_sp_to_mp(f, &f_copy))
1052 break;
1053 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
1054 fh, &f_copy);
1055 if (ret)
1056 break;
1057
1058 if (f_copy.fmt.pix_mp.num_planes > 1) {
1059 /* Drivers shouldn't adjust from 1-plane
1060 * to more than 1-plane formats */
1061 ret = -EBUSY;
1062 WARN_ON(1);
1063 break;
1064 }
1065 ret = fmt_mp_to_sp(&f_copy, f);
1066 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001067 if (!ret)
1068 v4l_print_pix_fmt(vfd, &f->fmt.pix);
1069 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001070 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1071 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
1072 if (ops->vidioc_try_fmt_vid_cap_mplane) {
1073 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
1074 fh, f);
1075 } else if (ops->vidioc_try_fmt_vid_cap &&
1076 f->fmt.pix_mp.num_planes == 1) {
1077 if (fmt_mp_to_sp(f, &f_copy))
1078 break;
1079 ret = ops->vidioc_try_fmt_vid_cap(file,
1080 fh, &f_copy);
1081 if (ret)
1082 break;
1083
1084 ret = fmt_sp_to_mp(&f_copy, f);
1085 }
1086 if (!ret)
1087 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
1088 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001089 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001090 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -03001091 if (ops->vidioc_try_fmt_vid_overlay)
1092 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001093 fh, f);
1094 break;
1095 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001096 CLEAR_AFTER_FIELD(f, fmt.pix);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001097 if (ops->vidioc_try_fmt_vid_out) {
Hans Verkuila3998102008-07-21 02:57:38 -03001098 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001099 } else if (ops->vidioc_try_fmt_vid_out_mplane) {
1100 if (fmt_sp_to_mp(f, &f_copy))
1101 break;
1102 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
1103 fh, &f_copy);
1104 if (ret)
1105 break;
1106
1107 if (f_copy.fmt.pix_mp.num_planes > 1) {
1108 /* Drivers shouldn't adjust from 1-plane
1109 * to more than 1-plane formats */
1110 ret = -EBUSY;
1111 WARN_ON(1);
1112 break;
1113 }
1114 ret = fmt_mp_to_sp(&f_copy, f);
1115 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001116 if (!ret)
1117 v4l_print_pix_fmt(vfd, &f->fmt.pix);
1118 break;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03001119 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1120 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
1121 if (ops->vidioc_try_fmt_vid_out_mplane) {
1122 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
1123 fh, f);
1124 } else if (ops->vidioc_try_fmt_vid_out &&
1125 f->fmt.pix_mp.num_planes == 1) {
1126 if (fmt_mp_to_sp(f, &f_copy))
1127 break;
1128 ret = ops->vidioc_try_fmt_vid_out(file,
1129 fh, &f_copy);
1130 if (ret)
1131 break;
1132
1133 ret = fmt_sp_to_mp(&f_copy, f);
1134 }
1135 if (!ret)
1136 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
1137 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001138 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001139 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -03001140 if (ops->vidioc_try_fmt_vid_out_overlay)
1141 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001142 fh, f);
1143 break;
1144 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001145 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -03001146 if (ops->vidioc_try_fmt_vbi_cap)
1147 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001148 break;
1149 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001150 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -03001151 if (ops->vidioc_try_fmt_vbi_out)
1152 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001153 break;
1154 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001155 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -03001156 if (ops->vidioc_try_fmt_sliced_vbi_cap)
1157 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001158 fh, f);
1159 break;
1160 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001161 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -03001162 if (ops->vidioc_try_fmt_sliced_vbi_out)
1163 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001164 fh, f);
1165 break;
1166 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001167 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Hans Verkuila3998102008-07-21 02:57:38 -03001168 if (ops->vidioc_try_fmt_type_private)
1169 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001170 fh, f);
1171 break;
1172 }
1173
1174 break;
1175 }
1176 /* FIXME: Those buf reqs could be handled here,
1177 with some changes on videobuf to allow its header to be included at
1178 videodev2.h or being merged at videodev2.
1179 */
1180 case VIDIOC_REQBUFS:
1181 {
1182 struct v4l2_requestbuffers *p = arg;
1183
Hans Verkuila3998102008-07-21 02:57:38 -03001184 if (!ops->vidioc_reqbufs)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001185 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001186 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001187 if (ret)
1188 break;
1189
Trent Piepho7ecc0cf2009-04-30 21:03:34 -03001190 if (p->type < V4L2_BUF_TYPE_PRIVATE)
1191 CLEAR_AFTER_FIELD(p, memory);
1192
Hans Verkuila3998102008-07-21 02:57:38 -03001193 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001194 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
1195 p->count,
1196 prt_names(p->type, v4l2_type_names),
1197 prt_names(p->memory, v4l2_memory_names));
1198 break;
1199 }
1200 case VIDIOC_QUERYBUF:
1201 {
1202 struct v4l2_buffer *p = arg;
1203
Hans Verkuila3998102008-07-21 02:57:38 -03001204 if (!ops->vidioc_querybuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001205 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001206 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001207 if (ret)
1208 break;
1209
Hans Verkuila3998102008-07-21 02:57:38 -03001210 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001211 if (!ret)
1212 dbgbuf(cmd, vfd, p);
1213 break;
1214 }
1215 case VIDIOC_QBUF:
1216 {
1217 struct v4l2_buffer *p = arg;
1218
Hans Verkuila3998102008-07-21 02:57:38 -03001219 if (!ops->vidioc_qbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001220 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001221 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001222 if (ret)
1223 break;
1224
Hans Verkuila3998102008-07-21 02:57:38 -03001225 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001226 if (!ret)
1227 dbgbuf(cmd, vfd, p);
1228 break;
1229 }
1230 case VIDIOC_DQBUF:
1231 {
1232 struct v4l2_buffer *p = arg;
1233
Hans Verkuila3998102008-07-21 02:57:38 -03001234 if (!ops->vidioc_dqbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001235 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001236 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001237 if (ret)
1238 break;
1239
Hans Verkuila3998102008-07-21 02:57:38 -03001240 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001241 if (!ret)
1242 dbgbuf(cmd, vfd, p);
1243 break;
1244 }
1245 case VIDIOC_OVERLAY:
1246 {
1247 int *i = arg;
1248
Hans Verkuila3998102008-07-21 02:57:38 -03001249 if (!ops->vidioc_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001250 break;
1251 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001252 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001253 break;
1254 }
1255 case VIDIOC_G_FBUF:
1256 {
1257 struct v4l2_framebuffer *p = arg;
1258
Hans Verkuila3998102008-07-21 02:57:38 -03001259 if (!ops->vidioc_g_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001260 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001261 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001262 if (!ret) {
1263 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1264 p->capability, p->flags,
1265 (unsigned long)p->base);
1266 v4l_print_pix_fmt(vfd, &p->fmt);
1267 }
1268 break;
1269 }
1270 case VIDIOC_S_FBUF:
1271 {
1272 struct v4l2_framebuffer *p = arg;
1273
Hans Verkuila3998102008-07-21 02:57:38 -03001274 if (!ops->vidioc_s_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001275 break;
1276 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1277 p->capability, p->flags, (unsigned long)p->base);
1278 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -03001279 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001280 break;
1281 }
1282 case VIDIOC_STREAMON:
1283 {
1284 enum v4l2_buf_type i = *(int *)arg;
1285
Hans Verkuila3998102008-07-21 02:57:38 -03001286 if (!ops->vidioc_streamon)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001287 break;
1288 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001289 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001290 break;
1291 }
1292 case VIDIOC_STREAMOFF:
1293 {
1294 enum v4l2_buf_type i = *(int *)arg;
1295
Hans Verkuila3998102008-07-21 02:57:38 -03001296 if (!ops->vidioc_streamoff)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001297 break;
1298 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001299 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001300 break;
1301 }
1302 /* ---------- tv norms ---------- */
1303 case VIDIOC_ENUMSTD:
1304 {
1305 struct v4l2_standard *p = arg;
1306 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1307 unsigned int index = p->index, i, j = 0;
1308 const char *descr = "";
1309
1310 /* Return norm array in a canonical way */
1311 for (i = 0; i <= index && id; i++) {
1312 /* last std value in the standards array is 0, so this
1313 while always ends there since (id & 0) == 0. */
1314 while ((id & standards[j].std) != standards[j].std)
1315 j++;
1316 curr_id = standards[j].std;
1317 descr = standards[j].descr;
1318 j++;
1319 if (curr_id == 0)
1320 break;
1321 if (curr_id != V4L2_STD_PAL &&
1322 curr_id != V4L2_STD_SECAM &&
1323 curr_id != V4L2_STD_NTSC)
1324 id &= ~curr_id;
1325 }
1326 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001327 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001328
1329 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001330
1331 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1332 "framelines=%d\n", p->index,
1333 (unsigned long long)p->id, p->name,
1334 p->frameperiod.numerator,
1335 p->frameperiod.denominator,
1336 p->framelines);
1337
1338 ret = 0;
1339 break;
1340 }
1341 case VIDIOC_G_STD:
1342 {
1343 v4l2_std_id *id = arg;
1344
1345 ret = 0;
1346 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001347 if (ops->vidioc_g_std)
1348 ret = ops->vidioc_g_std(file, fh, id);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001349 else if (vfd->current_norm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001350 *id = vfd->current_norm;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001351 else
1352 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001353
1354 if (!ret)
1355 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1356 break;
1357 }
1358 case VIDIOC_S_STD:
1359 {
1360 v4l2_std_id *id = arg, norm;
1361
1362 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1363
1364 norm = (*id) & vfd->tvnorms;
1365 if (vfd->tvnorms && !norm) /* Check if std is supported */
1366 break;
1367
1368 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001369 if (ops->vidioc_s_std)
1370 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001371 else
1372 ret = -EINVAL;
1373
1374 /* Updates standard information */
1375 if (ret >= 0)
1376 vfd->current_norm = norm;
1377 break;
1378 }
1379 case VIDIOC_QUERYSTD:
1380 {
1381 v4l2_std_id *p = arg;
1382
Hans Verkuila3998102008-07-21 02:57:38 -03001383 if (!ops->vidioc_querystd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001384 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001385 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001386 if (!ret)
1387 dbgarg(cmd, "detected std=%08Lx\n",
1388 (unsigned long long)*p);
1389 break;
1390 }
1391 /* ------ input switching ---------- */
1392 /* FIXME: Inputs can be handled inside videodev2 */
1393 case VIDIOC_ENUMINPUT:
1394 {
1395 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001396
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001397 /*
1398 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1399 * CAP_STD here based on ioctl handler provided by the
1400 * driver. If the driver doesn't support these
1401 * for a specific input, it must override these flags.
1402 */
1403 if (ops->vidioc_s_std)
1404 p->capabilities |= V4L2_IN_CAP_STD;
1405 if (ops->vidioc_s_dv_preset)
1406 p->capabilities |= V4L2_IN_CAP_PRESETS;
1407 if (ops->vidioc_s_dv_timings)
1408 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1409
Hans Verkuila3998102008-07-21 02:57:38 -03001410 if (!ops->vidioc_enum_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001411 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001412
Hans Verkuila3998102008-07-21 02:57:38 -03001413 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001414 if (!ret)
1415 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1416 "audioset=%d, "
1417 "tuner=%d, std=%08Lx, status=%d\n",
1418 p->index, p->name, p->type, p->audioset,
1419 p->tuner,
1420 (unsigned long long)p->std,
1421 p->status);
1422 break;
1423 }
1424 case VIDIOC_G_INPUT:
1425 {
1426 unsigned int *i = arg;
1427
Hans Verkuila3998102008-07-21 02:57:38 -03001428 if (!ops->vidioc_g_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001429 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001430 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001431 if (!ret)
1432 dbgarg(cmd, "value=%d\n", *i);
1433 break;
1434 }
1435 case VIDIOC_S_INPUT:
1436 {
1437 unsigned int *i = arg;
1438
Hans Verkuila3998102008-07-21 02:57:38 -03001439 if (!ops->vidioc_s_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001440 break;
1441 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001442 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001443 break;
1444 }
1445
1446 /* ------ output switching ---------- */
1447 case VIDIOC_ENUMOUTPUT:
1448 {
1449 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001450
Hans Verkuila3998102008-07-21 02:57:38 -03001451 if (!ops->vidioc_enum_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001452 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001453
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001454 /*
1455 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1456 * CAP_STD here based on ioctl handler provided by the
1457 * driver. If the driver doesn't support these
1458 * for a specific output, it must override these flags.
1459 */
1460 if (ops->vidioc_s_std)
1461 p->capabilities |= V4L2_OUT_CAP_STD;
1462 if (ops->vidioc_s_dv_preset)
1463 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1464 if (ops->vidioc_s_dv_timings)
1465 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1466
Hans Verkuila3998102008-07-21 02:57:38 -03001467 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001468 if (!ret)
1469 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1470 "audioset=0x%x, "
1471 "modulator=%d, std=0x%08Lx\n",
1472 p->index, p->name, p->type, p->audioset,
1473 p->modulator, (unsigned long long)p->std);
1474 break;
1475 }
1476 case VIDIOC_G_OUTPUT:
1477 {
1478 unsigned int *i = arg;
1479
Hans Verkuila3998102008-07-21 02:57:38 -03001480 if (!ops->vidioc_g_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001481 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001482 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001483 if (!ret)
1484 dbgarg(cmd, "value=%d\n", *i);
1485 break;
1486 }
1487 case VIDIOC_S_OUTPUT:
1488 {
1489 unsigned int *i = arg;
1490
Hans Verkuila3998102008-07-21 02:57:38 -03001491 if (!ops->vidioc_s_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001492 break;
1493 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001494 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001495 break;
1496 }
1497
1498 /* --- controls ---------------------------------------------- */
1499 case VIDIOC_QUERYCTRL:
1500 {
1501 struct v4l2_queryctrl *p = arg;
1502
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001503 if (vfd->ctrl_handler)
1504 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1505 else if (ops->vidioc_queryctrl)
1506 ret = ops->vidioc_queryctrl(file, fh, p);
1507 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001508 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001509 if (!ret)
1510 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1511 "step=%d, default=%d, flags=0x%08x\n",
1512 p->id, p->type, p->name,
1513 p->minimum, p->maximum,
1514 p->step, p->default_value, p->flags);
1515 else
1516 dbgarg(cmd, "id=0x%x\n", p->id);
1517 break;
1518 }
1519 case VIDIOC_G_CTRL:
1520 {
1521 struct v4l2_control *p = arg;
1522
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001523 if (vfd->ctrl_handler)
1524 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1525 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001526 ret = ops->vidioc_g_ctrl(file, fh, p);
1527 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001528 struct v4l2_ext_controls ctrls;
1529 struct v4l2_ext_control ctrl;
1530
1531 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1532 ctrls.count = 1;
1533 ctrls.controls = &ctrl;
1534 ctrl.id = p->id;
1535 ctrl.value = p->value;
1536 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001537 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001538 if (ret == 0)
1539 p->value = ctrl.value;
1540 }
1541 } else
1542 break;
1543 if (!ret)
1544 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1545 else
1546 dbgarg(cmd, "id=0x%x\n", p->id);
1547 break;
1548 }
1549 case VIDIOC_S_CTRL:
1550 {
1551 struct v4l2_control *p = arg;
1552 struct v4l2_ext_controls ctrls;
1553 struct v4l2_ext_control ctrl;
1554
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001555 if (!vfd->ctrl_handler &&
1556 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001557 break;
1558
1559 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1560
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001561 if (vfd->ctrl_handler) {
1562 ret = v4l2_s_ctrl(vfd->ctrl_handler, p);
1563 break;
1564 }
Hans Verkuila3998102008-07-21 02:57:38 -03001565 if (ops->vidioc_s_ctrl) {
1566 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001567 break;
1568 }
Hans Verkuila3998102008-07-21 02:57:38 -03001569 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001570 break;
1571
1572 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1573 ctrls.count = 1;
1574 ctrls.controls = &ctrl;
1575 ctrl.id = p->id;
1576 ctrl.value = p->value;
1577 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001578 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001579 break;
1580 }
1581 case VIDIOC_G_EXT_CTRLS:
1582 {
1583 struct v4l2_ext_controls *p = arg;
1584
1585 p->error_idx = p->count;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001586 if (vfd->ctrl_handler)
1587 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
1588 else if (ops->vidioc_g_ext_ctrls && check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001589 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001590 else
1591 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001592 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1593 break;
1594 }
1595 case VIDIOC_S_EXT_CTRLS:
1596 {
1597 struct v4l2_ext_controls *p = arg;
1598
1599 p->error_idx = p->count;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001600 if (!vfd->ctrl_handler && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001601 break;
1602 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001603 if (vfd->ctrl_handler)
1604 ret = v4l2_s_ext_ctrls(vfd->ctrl_handler, p);
1605 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001606 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001607 break;
1608 }
1609 case VIDIOC_TRY_EXT_CTRLS:
1610 {
1611 struct v4l2_ext_controls *p = arg;
1612
1613 p->error_idx = p->count;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001614 if (!vfd->ctrl_handler && !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001615 break;
1616 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001617 if (vfd->ctrl_handler)
1618 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1619 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001620 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001621 break;
1622 }
1623 case VIDIOC_QUERYMENU:
1624 {
1625 struct v4l2_querymenu *p = arg;
1626
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001627 if (vfd->ctrl_handler)
1628 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1629 else if (ops->vidioc_querymenu)
1630 ret = ops->vidioc_querymenu(file, fh, p);
1631 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001632 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001633 if (!ret)
1634 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1635 p->id, p->index, p->name);
1636 else
1637 dbgarg(cmd, "id=0x%x, index=%d\n",
1638 p->id, p->index);
1639 break;
1640 }
1641 /* --- audio ---------------------------------------------- */
1642 case VIDIOC_ENUMAUDIO:
1643 {
1644 struct v4l2_audio *p = arg;
1645
Hans Verkuila3998102008-07-21 02:57:38 -03001646 if (!ops->vidioc_enumaudio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001647 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001648 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001649 if (!ret)
1650 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1651 "mode=0x%x\n", p->index, p->name,
1652 p->capability, p->mode);
1653 else
1654 dbgarg(cmd, "index=%d\n", p->index);
1655 break;
1656 }
1657 case VIDIOC_G_AUDIO:
1658 {
1659 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001660
Hans Verkuila3998102008-07-21 02:57:38 -03001661 if (!ops->vidioc_g_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001662 break;
1663
Hans Verkuila3998102008-07-21 02:57:38 -03001664 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001665 if (!ret)
1666 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1667 "mode=0x%x\n", p->index,
1668 p->name, p->capability, p->mode);
1669 else
1670 dbgarg(cmd, "index=%d\n", p->index);
1671 break;
1672 }
1673 case VIDIOC_S_AUDIO:
1674 {
1675 struct v4l2_audio *p = arg;
1676
Hans Verkuila3998102008-07-21 02:57:38 -03001677 if (!ops->vidioc_s_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001678 break;
1679 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1680 "mode=0x%x\n", p->index, p->name,
1681 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001682 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001683 break;
1684 }
1685 case VIDIOC_ENUMAUDOUT:
1686 {
1687 struct v4l2_audioout *p = arg;
1688
Hans Verkuila3998102008-07-21 02:57:38 -03001689 if (!ops->vidioc_enumaudout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001690 break;
1691 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001692 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001693 if (!ret)
1694 dbgarg2("index=%d, name=%s, capability=%d, "
1695 "mode=%d\n", p->index, p->name,
1696 p->capability, p->mode);
1697 break;
1698 }
1699 case VIDIOC_G_AUDOUT:
1700 {
1701 struct v4l2_audioout *p = arg;
1702
Hans Verkuila3998102008-07-21 02:57:38 -03001703 if (!ops->vidioc_g_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001704 break;
Trent Piepho337f9d22009-03-04 01:21:02 -03001705
Hans Verkuila3998102008-07-21 02:57:38 -03001706 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001707 if (!ret)
1708 dbgarg2("index=%d, name=%s, capability=%d, "
1709 "mode=%d\n", p->index, p->name,
1710 p->capability, p->mode);
1711 break;
1712 }
1713 case VIDIOC_S_AUDOUT:
1714 {
1715 struct v4l2_audioout *p = arg;
1716
Hans Verkuila3998102008-07-21 02:57:38 -03001717 if (!ops->vidioc_s_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001718 break;
1719 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1720 "mode=%d\n", p->index, p->name,
1721 p->capability, p->mode);
1722
Hans Verkuila3998102008-07-21 02:57:38 -03001723 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001724 break;
1725 }
1726 case VIDIOC_G_MODULATOR:
1727 {
1728 struct v4l2_modulator *p = arg;
1729
Hans Verkuila3998102008-07-21 02:57:38 -03001730 if (!ops->vidioc_g_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001731 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001732 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001733 if (!ret)
1734 dbgarg(cmd, "index=%d, name=%s, "
1735 "capability=%d, rangelow=%d,"
1736 " rangehigh=%d, txsubchans=%d\n",
1737 p->index, p->name, p->capability,
1738 p->rangelow, p->rangehigh,
1739 p->txsubchans);
1740 break;
1741 }
1742 case VIDIOC_S_MODULATOR:
1743 {
1744 struct v4l2_modulator *p = arg;
1745
Hans Verkuila3998102008-07-21 02:57:38 -03001746 if (!ops->vidioc_s_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001747 break;
1748 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1749 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1750 p->index, p->name, p->capability, p->rangelow,
1751 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001752 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001753 break;
1754 }
1755 case VIDIOC_G_CROP:
1756 {
1757 struct v4l2_crop *p = arg;
1758
Hans Verkuila3998102008-07-21 02:57:38 -03001759 if (!ops->vidioc_g_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001760 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001761
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001762 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001763 ret = ops->vidioc_g_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001764 if (!ret)
1765 dbgrect(vfd, "", &p->c);
1766 break;
1767 }
1768 case VIDIOC_S_CROP:
1769 {
1770 struct v4l2_crop *p = arg;
1771
Hans Verkuila3998102008-07-21 02:57:38 -03001772 if (!ops->vidioc_s_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001773 break;
1774 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1775 dbgrect(vfd, "", &p->c);
Hans Verkuila3998102008-07-21 02:57:38 -03001776 ret = ops->vidioc_s_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001777 break;
1778 }
1779 case VIDIOC_CROPCAP:
1780 {
1781 struct v4l2_cropcap *p = arg;
1782
1783 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuila3998102008-07-21 02:57:38 -03001784 if (!ops->vidioc_cropcap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001785 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001786
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001787 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001788 ret = ops->vidioc_cropcap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001789 if (!ret) {
1790 dbgrect(vfd, "bounds ", &p->bounds);
1791 dbgrect(vfd, "defrect ", &p->defrect);
1792 }
1793 break;
1794 }
1795 case VIDIOC_G_JPEGCOMP:
1796 {
1797 struct v4l2_jpegcompression *p = arg;
1798
Hans Verkuila3998102008-07-21 02:57:38 -03001799 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001800 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001801
Hans Verkuila3998102008-07-21 02:57:38 -03001802 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001803 if (!ret)
1804 dbgarg(cmd, "quality=%d, APPn=%d, "
1805 "APP_len=%d, COM_len=%d, "
1806 "jpeg_markers=%d\n",
1807 p->quality, p->APPn, p->APP_len,
1808 p->COM_len, p->jpeg_markers);
1809 break;
1810 }
1811 case VIDIOC_S_JPEGCOMP:
1812 {
1813 struct v4l2_jpegcompression *p = arg;
1814
Hans Verkuila3998102008-07-21 02:57:38 -03001815 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001816 break;
1817 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1818 "COM_len=%d, jpeg_markers=%d\n",
1819 p->quality, p->APPn, p->APP_len,
1820 p->COM_len, p->jpeg_markers);
Hans Verkuila3998102008-07-21 02:57:38 -03001821 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001822 break;
1823 }
1824 case VIDIOC_G_ENC_INDEX:
1825 {
1826 struct v4l2_enc_idx *p = arg;
1827
Hans Verkuila3998102008-07-21 02:57:38 -03001828 if (!ops->vidioc_g_enc_index)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001829 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001830 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001831 if (!ret)
1832 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1833 p->entries, p->entries_cap);
1834 break;
1835 }
1836 case VIDIOC_ENCODER_CMD:
1837 {
1838 struct v4l2_encoder_cmd *p = arg;
1839
Hans Verkuila3998102008-07-21 02:57:38 -03001840 if (!ops->vidioc_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001841 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001842 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001843 if (!ret)
1844 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1845 break;
1846 }
1847 case VIDIOC_TRY_ENCODER_CMD:
1848 {
1849 struct v4l2_encoder_cmd *p = arg;
1850
Hans Verkuila3998102008-07-21 02:57:38 -03001851 if (!ops->vidioc_try_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001852 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001853 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001854 if (!ret)
1855 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1856 break;
1857 }
1858 case VIDIOC_G_PARM:
1859 {
1860 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001861
Hans Verkuila3998102008-07-21 02:57:38 -03001862 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001863 ret = check_fmt(ops, p->type);
1864 if (ret)
1865 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001866 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001867 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001868 v4l2_std_id std = vfd->current_norm;
1869
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001870 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001871 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001872
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001873 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001874 if (ops->vidioc_g_std)
1875 ret = ops->vidioc_g_std(file, fh, &std);
1876 else if (std == 0)
1877 ret = -EINVAL;
1878 if (ret == 0)
1879 v4l2_video_std_frame_period(std,
1880 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001881 }
1882
1883 dbgarg(cmd, "type=%d\n", p->type);
1884 break;
1885 }
1886 case VIDIOC_S_PARM:
1887 {
1888 struct v4l2_streamparm *p = arg;
1889
Hans Verkuila3998102008-07-21 02:57:38 -03001890 if (!ops->vidioc_s_parm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001891 break;
Trent Piepho34796bc2009-03-28 22:25:35 -03001892 ret = check_fmt(ops, p->type);
1893 if (ret)
1894 break;
1895
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001896 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001897 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001898 break;
1899 }
1900 case VIDIOC_G_TUNER:
1901 {
1902 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001903
Hans Verkuila3998102008-07-21 02:57:38 -03001904 if (!ops->vidioc_g_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001905 break;
1906
Hans Verkuila3998102008-07-21 02:57:38 -03001907 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001908 if (!ret)
1909 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1910 "capability=0x%x, rangelow=%d, "
1911 "rangehigh=%d, signal=%d, afc=%d, "
1912 "rxsubchans=0x%x, audmode=%d\n",
1913 p->index, p->name, p->type,
1914 p->capability, p->rangelow,
1915 p->rangehigh, p->signal, p->afc,
1916 p->rxsubchans, p->audmode);
1917 break;
1918 }
1919 case VIDIOC_S_TUNER:
1920 {
1921 struct v4l2_tuner *p = arg;
1922
Hans Verkuila3998102008-07-21 02:57:38 -03001923 if (!ops->vidioc_s_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001924 break;
1925 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1926 "capability=0x%x, rangelow=%d, "
1927 "rangehigh=%d, signal=%d, afc=%d, "
1928 "rxsubchans=0x%x, audmode=%d\n",
1929 p->index, p->name, p->type,
1930 p->capability, p->rangelow,
1931 p->rangehigh, p->signal, p->afc,
1932 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001933 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001934 break;
1935 }
1936 case VIDIOC_G_FREQUENCY:
1937 {
1938 struct v4l2_frequency *p = arg;
1939
Hans Verkuila3998102008-07-21 02:57:38 -03001940 if (!ops->vidioc_g_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001941 break;
1942
Hans Verkuila3998102008-07-21 02:57:38 -03001943 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001944 if (!ret)
1945 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1946 p->tuner, p->type, p->frequency);
1947 break;
1948 }
1949 case VIDIOC_S_FREQUENCY:
1950 {
1951 struct v4l2_frequency *p = arg;
1952
Hans Verkuila3998102008-07-21 02:57:38 -03001953 if (!ops->vidioc_s_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001954 break;
1955 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1956 p->tuner, p->type, p->frequency);
Hans Verkuila3998102008-07-21 02:57:38 -03001957 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001958 break;
1959 }
1960 case VIDIOC_G_SLICED_VBI_CAP:
1961 {
1962 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001963
Hans Verkuila3998102008-07-21 02:57:38 -03001964 if (!ops->vidioc_g_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001965 break;
Trent Piepho19c96e42009-03-04 01:21:02 -03001966
1967 /* Clear up to type, everything after type is zerod already */
1968 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1969
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001970 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001971 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001972 if (!ret)
1973 dbgarg2("service_set=%d\n", p->service_set);
1974 break;
1975 }
1976 case VIDIOC_LOG_STATUS:
1977 {
Hans Verkuila3998102008-07-21 02:57:38 -03001978 if (!ops->vidioc_log_status)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001979 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001980 ret = ops->vidioc_log_status(file, fh);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001981 break;
1982 }
1983#ifdef CONFIG_VIDEO_ADV_DEBUG
1984 case VIDIOC_DBG_G_REGISTER:
1985 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001986 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001987
Hans Verkuila1198cc2011-01-08 09:53:32 -03001988 if (ops->vidioc_g_register) {
1989 if (!capable(CAP_SYS_ADMIN))
1990 ret = -EPERM;
1991 else
1992 ret = ops->vidioc_g_register(file, fh, p);
1993 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001994 break;
1995 }
1996 case VIDIOC_DBG_S_REGISTER:
1997 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001998 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001999
Hans Verkuila1198cc2011-01-08 09:53:32 -03002000 if (ops->vidioc_s_register) {
2001 if (!capable(CAP_SYS_ADMIN))
2002 ret = -EPERM;
2003 else
2004 ret = ops->vidioc_s_register(file, fh, p);
2005 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002006 break;
2007 }
2008#endif
Hans Verkuilaecde8b2008-12-30 07:14:19 -03002009 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002010 {
Hans Verkuilaecde8b2008-12-30 07:14:19 -03002011 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002012
Hans Verkuila3998102008-07-21 02:57:38 -03002013 if (!ops->vidioc_g_chip_ident)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002014 break;
Hans Verkuil80b36e02009-02-07 11:00:02 -03002015 p->ident = V4L2_IDENT_NONE;
2016 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03002017 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002018 if (!ret)
2019 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
2020 break;
2021 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002022 case VIDIOC_S_HW_FREQ_SEEK:
2023 {
2024 struct v4l2_hw_freq_seek *p = arg;
2025
Hans Verkuila3998102008-07-21 02:57:38 -03002026 if (!ops->vidioc_s_hw_freq_seek)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002027 break;
2028 dbgarg(cmd,
2029 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
2030 p->tuner, p->type, p->seek_upward, p->wrap_around);
Hans Verkuila3998102008-07-21 02:57:38 -03002031 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
2032 break;
2033 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002034 case VIDIOC_ENUM_FRAMESIZES:
2035 {
2036 struct v4l2_frmsizeenum *p = arg;
2037
2038 if (!ops->vidioc_enum_framesizes)
2039 break;
2040
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002041 ret = ops->vidioc_enum_framesizes(file, fh, p);
2042 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03002043 "index=%d, pixelformat=%c%c%c%c, type=%d ",
2044 p->index,
2045 (p->pixel_format & 0xff),
2046 (p->pixel_format >> 8) & 0xff,
2047 (p->pixel_format >> 16) & 0xff,
2048 (p->pixel_format >> 24) & 0xff,
2049 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002050 switch (p->type) {
2051 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002052 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002053 p->discrete.width, p->discrete.height);
2054 break;
2055 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002056 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002057 p->stepwise.min_width, p->stepwise.min_height,
2058 p->stepwise.step_width, p->stepwise.step_height,
2059 p->stepwise.max_width, p->stepwise.max_height);
2060 break;
2061 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002062 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002063 break;
2064 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03002065 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002066 }
2067
2068 break;
2069 }
2070 case VIDIOC_ENUM_FRAMEINTERVALS:
2071 {
2072 struct v4l2_frmivalenum *p = arg;
2073
2074 if (!ops->vidioc_enum_frameintervals)
2075 break;
2076
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002077 ret = ops->vidioc_enum_frameintervals(file, fh, p);
2078 dbgarg(cmd,
2079 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
2080 p->index, p->pixel_format,
2081 p->width, p->height, p->type);
2082 switch (p->type) {
2083 case V4L2_FRMIVAL_TYPE_DISCRETE:
2084 dbgarg2("fps=%d/%d\n",
2085 p->discrete.numerator,
2086 p->discrete.denominator);
2087 break;
2088 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03002089 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
2090 p->stepwise.min.numerator,
2091 p->stepwise.min.denominator,
2092 p->stepwise.max.numerator,
2093 p->stepwise.max.denominator,
2094 p->stepwise.step.numerator,
2095 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002096 break;
2097 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
2098 dbgarg2("continuous\n");
2099 break;
2100 default:
2101 dbgarg2("- Unknown type!\n");
2102 }
2103 break;
2104 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002105 case VIDIOC_ENUM_DV_PRESETS:
2106 {
2107 struct v4l2_dv_enum_preset *p = arg;
2108
2109 if (!ops->vidioc_enum_dv_presets)
2110 break;
2111
2112 ret = ops->vidioc_enum_dv_presets(file, fh, p);
2113 if (!ret)
2114 dbgarg(cmd,
2115 "index=%d, preset=%d, name=%s, width=%d,"
2116 " height=%d ",
2117 p->index, p->preset, p->name, p->width,
2118 p->height);
2119 break;
2120 }
2121 case VIDIOC_S_DV_PRESET:
2122 {
2123 struct v4l2_dv_preset *p = arg;
2124
2125 if (!ops->vidioc_s_dv_preset)
2126 break;
2127
2128 dbgarg(cmd, "preset=%d\n", p->preset);
2129 ret = ops->vidioc_s_dv_preset(file, fh, p);
2130 break;
2131 }
2132 case VIDIOC_G_DV_PRESET:
2133 {
2134 struct v4l2_dv_preset *p = arg;
2135
2136 if (!ops->vidioc_g_dv_preset)
2137 break;
2138
2139 ret = ops->vidioc_g_dv_preset(file, fh, p);
2140 if (!ret)
2141 dbgarg(cmd, "preset=%d\n", p->preset);
2142 break;
2143 }
2144 case VIDIOC_QUERY_DV_PRESET:
2145 {
2146 struct v4l2_dv_preset *p = arg;
2147
2148 if (!ops->vidioc_query_dv_preset)
2149 break;
2150
2151 ret = ops->vidioc_query_dv_preset(file, fh, p);
2152 if (!ret)
2153 dbgarg(cmd, "preset=%d\n", p->preset);
2154 break;
2155 }
2156 case VIDIOC_S_DV_TIMINGS:
2157 {
2158 struct v4l2_dv_timings *p = arg;
2159
2160 if (!ops->vidioc_s_dv_timings)
2161 break;
2162
2163 switch (p->type) {
2164 case V4L2_DV_BT_656_1120:
2165 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2166 " width=%d, height=%d, polarities=%x,"
2167 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
2168 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
2169 " il_vfrontporch=%d, il_vsync=%d,"
2170 " il_vbackporch=%d\n",
2171 p->bt.interlaced, p->bt.pixelclock,
2172 p->bt.width, p->bt.height, p->bt.polarities,
2173 p->bt.hfrontporch, p->bt.hsync,
2174 p->bt.hbackporch, p->bt.vfrontporch,
2175 p->bt.vsync, p->bt.vbackporch,
2176 p->bt.il_vfrontporch, p->bt.il_vsync,
2177 p->bt.il_vbackporch);
2178 ret = ops->vidioc_s_dv_timings(file, fh, p);
2179 break;
2180 default:
2181 dbgarg2("Unknown type %d!\n", p->type);
2182 break;
2183 }
2184 break;
2185 }
2186 case VIDIOC_G_DV_TIMINGS:
2187 {
2188 struct v4l2_dv_timings *p = arg;
2189
2190 if (!ops->vidioc_g_dv_timings)
2191 break;
2192
2193 ret = ops->vidioc_g_dv_timings(file, fh, p);
2194 if (!ret) {
2195 switch (p->type) {
2196 case V4L2_DV_BT_656_1120:
2197 dbgarg2("bt-656/1120:interlaced=%d,"
2198 " pixelclock=%lld,"
2199 " width=%d, height=%d, polarities=%x,"
2200 " hfrontporch=%d, hsync=%d,"
2201 " hbackporch=%d, vfrontporch=%d,"
2202 " vsync=%d, vbackporch=%d,"
2203 " il_vfrontporch=%d, il_vsync=%d,"
2204 " il_vbackporch=%d\n",
2205 p->bt.interlaced, p->bt.pixelclock,
2206 p->bt.width, p->bt.height,
2207 p->bt.polarities, p->bt.hfrontporch,
2208 p->bt.hsync, p->bt.hbackporch,
2209 p->bt.vfrontporch, p->bt.vsync,
2210 p->bt.vbackporch, p->bt.il_vfrontporch,
2211 p->bt.il_vsync, p->bt.il_vbackporch);
2212 break;
2213 default:
2214 dbgarg2("Unknown type %d!\n", p->type);
2215 break;
2216 }
2217 }
2218 break;
2219 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002220 case VIDIOC_DQEVENT:
2221 {
2222 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002223
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002224 if (!ops->vidioc_subscribe_event)
2225 break;
2226
2227 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2228 if (ret < 0) {
2229 dbgarg(cmd, "no pending events?");
2230 break;
2231 }
2232 dbgarg(cmd,
2233 "pending=%d, type=0x%8.8x, sequence=%d, "
2234 "timestamp=%lu.%9.9lu ",
2235 ev->pending, ev->type, ev->sequence,
2236 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2237 break;
2238 }
2239 case VIDIOC_SUBSCRIBE_EVENT:
2240 {
2241 struct v4l2_event_subscription *sub = arg;
2242
2243 if (!ops->vidioc_subscribe_event)
2244 break;
2245
2246 ret = ops->vidioc_subscribe_event(fh, sub);
2247 if (ret < 0) {
2248 dbgarg(cmd, "failed, ret=%ld", ret);
2249 break;
2250 }
2251 dbgarg(cmd, "type=0x%8.8x", sub->type);
2252 break;
2253 }
2254 case VIDIOC_UNSUBSCRIBE_EVENT:
2255 {
2256 struct v4l2_event_subscription *sub = arg;
2257
2258 if (!ops->vidioc_unsubscribe_event)
2259 break;
2260
2261 ret = ops->vidioc_unsubscribe_event(fh, sub);
2262 if (ret < 0) {
2263 dbgarg(cmd, "failed, ret=%ld", ret);
2264 break;
2265 }
2266 dbgarg(cmd, "type=0x%8.8x", sub->type);
2267 break;
2268 }
Hans Verkuila3998102008-07-21 02:57:38 -03002269 default:
2270 {
2271 if (!ops->vidioc_default)
2272 break;
2273 ret = ops->vidioc_default(file, fh, cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002274 break;
2275 }
2276 } /* switch */
2277
2278 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2279 if (ret < 0) {
2280 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002281 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002282 }
2283 }
2284
2285 return ret;
2286}
2287
Trent Piepho19c96e42009-03-04 01:21:02 -03002288/* In some cases, only a few fields are used as input, i.e. when the app sets
2289 * "index" and then the driver fills in the rest of the structure for the thing
2290 * with that index. We only need to copy up the first non-input field. */
2291static unsigned long cmd_input_size(unsigned int cmd)
2292{
2293 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002294#define CMDINSIZE(cmd, type, field) \
2295 case VIDIOC_##cmd: \
2296 return offsetof(struct v4l2_##type, field) + \
2297 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03002298
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002299 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03002300 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2301 CMDINSIZE(G_FMT, format, type);
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002302 CMDINSIZE(QUERYBUF, buffer, length);
Trent Piepho19c96e42009-03-04 01:21:02 -03002303 CMDINSIZE(G_PARM, streamparm, type);
2304 CMDINSIZE(ENUMSTD, standard, index);
2305 CMDINSIZE(ENUMINPUT, input, index);
2306 CMDINSIZE(G_CTRL, control, id);
2307 CMDINSIZE(G_TUNER, tuner, index);
2308 CMDINSIZE(QUERYCTRL, queryctrl, id);
2309 CMDINSIZE(QUERYMENU, querymenu, index);
2310 CMDINSIZE(ENUMOUTPUT, output, index);
2311 CMDINSIZE(G_MODULATOR, modulator, index);
2312 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2313 CMDINSIZE(CROPCAP, cropcap, type);
2314 CMDINSIZE(G_CROP, crop, type);
2315 CMDINSIZE(ENUMAUDIO, audio, index);
2316 CMDINSIZE(ENUMAUDOUT, audioout, index);
2317 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2318 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2319 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2320 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2321 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2322 default:
2323 return _IOC_SIZE(cmd);
2324 }
2325}
2326
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002327static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2328 void * __user *user_ptr, void ***kernel_ptr)
2329{
2330 int ret = 0;
2331
2332 switch (cmd) {
2333 case VIDIOC_QUERYBUF:
2334 case VIDIOC_QBUF:
2335 case VIDIOC_DQBUF: {
2336 struct v4l2_buffer *buf = parg;
2337
2338 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2339 if (buf->length > VIDEO_MAX_PLANES) {
2340 ret = -EINVAL;
2341 break;
2342 }
2343 *user_ptr = (void __user *)buf->m.planes;
2344 *kernel_ptr = (void **)&buf->m.planes;
2345 *array_size = sizeof(struct v4l2_plane) * buf->length;
2346 ret = 1;
2347 }
2348 break;
2349 }
2350
2351 case VIDIOC_S_EXT_CTRLS:
2352 case VIDIOC_G_EXT_CTRLS:
2353 case VIDIOC_TRY_EXT_CTRLS: {
2354 struct v4l2_ext_controls *ctrls = parg;
2355
2356 if (ctrls->count != 0) {
2357 *user_ptr = (void __user *)ctrls->controls;
2358 *kernel_ptr = (void **)&ctrls->controls;
2359 *array_size = sizeof(struct v4l2_ext_control)
2360 * ctrls->count;
2361 ret = 1;
2362 }
2363 break;
2364 }
2365 }
2366
2367 return ret;
2368}
2369
Hans Verkuil069b7472008-12-30 07:04:34 -03002370long video_ioctl2(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002371 unsigned int cmd, unsigned long arg)
2372{
2373 char sbuf[128];
2374 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002375 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002376 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002377 bool has_array_args;
2378 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002379 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002380 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002381
2382#ifdef __OLD_VIDIOC_
2383 cmd = video_fix_command(cmd);
2384#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002385 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002386 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002387 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2388 parg = sbuf;
2389 } else {
2390 /* too big to allocate from stack */
2391 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2392 if (NULL == mbuf)
2393 return -ENOMEM;
2394 parg = mbuf;
2395 }
2396
2397 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002398 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2399 unsigned long n = cmd_input_size(cmd);
2400
2401 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002402 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002403
2404 /* zero out anything we don't copy from userspace */
2405 if (n < _IOC_SIZE(cmd))
2406 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002407 } else {
2408 /* read-only ioctl */
2409 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002410 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002411 }
2412
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002413 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2414 if (err < 0)
2415 goto out;
2416 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002417
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002418 if (has_array_args) {
2419 /*
2420 * When adding new types of array args, make sure that the
2421 * parent argument to ioctl (which contains the pointer to the
2422 * array) fits into sbuf (so that mbuf will still remain
2423 * unused up to here).
2424 */
2425 mbuf = kmalloc(array_size, GFP_KERNEL);
2426 err = -ENOMEM;
2427 if (NULL == mbuf)
2428 goto out_array_args;
2429 err = -EFAULT;
2430 if (copy_from_user(mbuf, user_ptr, array_size))
2431 goto out_array_args;
2432 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002433 }
2434
2435 /* Handles IOCTL */
Mauro Carvalho Chehabb1f88402008-10-21 11:27:20 -03002436 err = __video_do_ioctl(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002437 if (err == -ENOIOCTLCMD)
2438 err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002439
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002440 if (has_array_args) {
2441 *kernel_ptr = user_ptr;
2442 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002443 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002444 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002445 }
2446 if (err < 0)
2447 goto out;
2448
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002449out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002450 /* Copy results into user buffer */
2451 switch (_IOC_DIR(cmd)) {
2452 case _IOC_READ:
2453 case (_IOC_WRITE | _IOC_READ):
2454 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2455 err = -EFAULT;
2456 break;
2457 }
2458
2459out:
2460 kfree(mbuf);
2461 return err;
2462}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002463EXPORT_SYMBOL(video_ioctl2);